7
Flow::new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio) {
8
// we need layer height unless it's a bridge
9
if (height <= 0 && bridge_flow_ratio == 0) CONFESS("Invalid flow height supplied to new_from_config_width()");
12
// use automatic extrusion width if user left 0 or we need a bridge flow
13
if ((!width.percent && width.value == 0) || bridge_flow_ratio > 0) {
14
w = Flow::_width(role, nozzle_diameter, height, bridge_flow_ratio);
16
w = width.get_abs_value(height);
19
Flow flow(w, Flow::_spacing(w, nozzle_diameter, height, bridge_flow_ratio), nozzle_diameter);
20
if (bridge_flow_ratio > 0) flow.bridge = true;
25
Flow::new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge) {
26
// we need layer height unless it's a bridge
27
if (height <= 0 && !bridge) CONFESS("Invalid flow height supplied to new_from_spacing()");
29
float w = Flow::_width_from_spacing(spacing, nozzle_diameter, height, bridge);
30
Flow flow(w, spacing, nozzle_diameter);
36
Flow::mm3_per_mm(float h) {
38
return (this->width * this->width) * PI/4.0;
39
} else if (this->width >= (this->nozzle_diameter + h)) {
40
// rectangle with semicircles at the ends
41
return this->width * h + (h*h) / 4.0 * (PI-4.0);
43
// rectangle with shrunk semicircles at the ends
44
return this->nozzle_diameter * h * (1 - PI/4.0) + h * this->width * PI/4.0;
49
Flow::_width(FlowRole role, float nozzle_diameter, float height, float bridge_flow_ratio) {
50
if (bridge_flow_ratio > 0) {
51
return sqrt(bridge_flow_ratio * (nozzle_diameter*nozzle_diameter));
54
// here we calculate a sane default by matching the flow speed (at the nozzle) and the feed rate
55
float volume = (nozzle_diameter*nozzle_diameter) * PI/4.0;
56
float shape_threshold = nozzle_diameter * height + (height*height) * PI/4.0;
58
if (volume >= shape_threshold) {
59
// rectangle with semicircles at the ends
60
width = ((nozzle_diameter*nozzle_diameter) * PI + (height*height) * (4.0 - PI)) / (4.0 * height);
62
// rectangle with squished semicircles at the ends
63
width = nozzle_diameter * (nozzle_diameter/height - 4.0/PI + 1);
66
float min = nozzle_diameter * 1.05;
68
if (role == frPerimeter || role == frSupportMaterial) {
69
min = max = nozzle_diameter;
70
} else if (role != frInfill) {
71
// do not limit width for sparse infill so that we use full native flow for it
72
max = nozzle_diameter * 1.7;
74
if (max != -1 && width > max) width = max;
75
if (width < min) width = min;
82
Flow::_width_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge) {
84
return spacing - BRIDGE_EXTRA_SPACING;
87
float w_threshold = height + nozzle_diameter;
88
float s_threshold = w_threshold - OVERLAP_FACTOR * (w_threshold - (w_threshold - height * (1 - PI/4.0)));
90
if (spacing >= s_threshold) {
91
// rectangle with semicircles at the ends
92
return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0);
94
// rectangle with shrunk semicircles at the ends
95
return (spacing + nozzle_diameter * OVERLAP_FACTOR * (PI/4.0 - 1)) / (1 + OVERLAP_FACTOR * (PI/4.0 - 1));
100
Flow::_spacing(float width, float nozzle_diameter, float height, float bridge_flow_ratio) {
101
if (bridge_flow_ratio > 0) {
102
return width + BRIDGE_EXTRA_SPACING;
105
float min_flow_spacing;
106
if (width >= (nozzle_diameter + height)) {
107
// rectangle with semicircles at the ends
108
min_flow_spacing = width - height * (1 - PI/4.0);
110
// rectangle with shrunk semicircles at the ends
111
min_flow_spacing = nozzle_diameter * (1 - PI/4.0) + width * PI/4.0;
113
return width - OVERLAP_FACTOR * (width - min_flow_spacing);
117
REGISTER_CLASS(Flow, "Flow");