flow.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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('over_bridge_flow_ratio', 1);
  44. $config->set('cooling', [ 0 ]); # to prevent speeds from being altered
  45. $config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
  46. my $test = sub {
  47. my $print = Slic3r::Test::init_print('overhang', config => $config);
  48. my @E_per_mm = ();
  49. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  50. my ($self, $cmd, $args, $info) = @_;
  51. if ($info->{extruding} && $info->{dist_XY} > 0) {
  52. if (($args->{F} // $self->F) == $config->bridge_speed*60) {
  53. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  54. }
  55. }
  56. });
  57. my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio;
  58. my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI);
  59. ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm),
  60. 'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio;
  61. };
  62. $config->set('bridge_flow_ratio', 0.5);
  63. $test->();
  64. $config->set('bridge_flow_ratio', 2);
  65. $test->();
  66. $config->set('extrusion_width', 0.4);
  67. $config->set('bridge_flow_ratio', 1);
  68. $test->();
  69. $config->set('bridge_flow_ratio', 0.5);
  70. $test->();
  71. $config->set('bridge_flow_ratio', 2);
  72. $test->();
  73. }
  74. __END__