flow.t 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. use Test::More tests => 6;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use local::lib "$FindBin::Bin/../local-lib";
  8. }
  9. use List::Util qw(first sum);
  10. use Slic3r;
  11. use Slic3r::Geometry qw(scale PI);
  12. use Slic3r::Test;
  13. {
  14. my $config = Slic3r::Config::new_from_defaults;
  15. $config->set('skirts', 1);
  16. $config->set('brim_width', 2);
  17. $config->set('perimeters', 3);
  18. $config->set('fill_density', 0.4);
  19. $config->set('bottom_solid_layers', 1);
  20. $config->set('first_layer_extrusion_width', 2);
  21. $config->set('first_layer_height', $config->layer_height);
  22. $config->set('filament_diameter', [ 3.0 ]);
  23. $config->set('nozzle_diameter', [ 0.5 ]);
  24. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  25. my @E_per_mm = ();
  26. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  27. my ($self, $cmd, $args, $info) = @_;
  28. if ($self->Z == $config->layer_height) { # only consider first layer
  29. if ($info->{extruding} && $info->{dist_XY} > 0) {
  30. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  31. }
  32. }
  33. });
  34. my $E_per_mm_avg = sum(@E_per_mm) / @E_per_mm;
  35. # allow some tolerance because solid rectilinear infill might be adjusted/stretched
  36. ok !(defined first { abs($_ - $E_per_mm_avg) > 0.015 } @E_per_mm),
  37. 'first_layer_extrusion_width applies to everything on first layer';
  38. }
  39. {
  40. my $config = Slic3r::Config::new_from_defaults;
  41. $config->set('bridge_speed', 99);
  42. $config->set('bridge_flow_ratio', 1);
  43. $config->set('cooling', [ 0 ]); # to prevent speeds from being altered
  44. $config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
  45. my $test = sub {
  46. my $print = Slic3r::Test::init_print('overhang', config => $config);
  47. my @E_per_mm = ();
  48. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  49. my ($self, $cmd, $args, $info) = @_;
  50. if ($info->{extruding} && $info->{dist_XY} > 0) {
  51. if (($args->{F} // $self->F) == $config->bridge_speed*60) {
  52. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  53. }
  54. }
  55. });
  56. my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio;
  57. my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI);
  58. ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm),
  59. 'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio;
  60. };
  61. $config->set('bridge_flow_ratio', 0.5);
  62. $test->();
  63. $config->set('bridge_flow_ratio', 2);
  64. $test->();
  65. $config->set('extrusion_width', 0.4);
  66. $config->set('bridge_flow_ratio', 1);
  67. $test->();
  68. $config->set('bridge_flow_ratio', 0.5);
  69. $test->();
  70. $config->set('bridge_flow_ratio', 2);
  71. $test->();
  72. }
  73. __END__