@@ -174,7 +174,8 @@ def read_input(filename):
174174
175175
176176def run (phases , domain , verbose = False , restart = True , directory = '.' ,
177- filetypes = {}, rng_seeds = {}, plot_axes = True , rtol = 'fit' ,
177+ filetypes = {}, rng_seeds = {}, plot_axes = True , rtol = 'fit' , edge_opt = False ,
178+ edge_opt_n_iter = 100 ,
178179 mesh_max_volume = float ('inf' ), mesh_min_angle = 0 ,
179180 mesh_max_edge_length = float ('inf' ), verify = False , color_by = 'material' ,
180181 colormap = 'viridis' , seeds_kwargs = {}, poly_kwargs = {}, tri_kwargs = {}):
@@ -243,10 +244,18 @@ def run(phases, domain, verbose=False, restart=True, directory='.',
243244
244245 The default value is ``'fit'``, which uses the mean and variance
245246 of the size distribution to estimate a value for rtol.
247+ edge_opt (bool): *(optional)* This option will maximize the minimum
248+ edge length in the PolyMesh. The seeds associated with the
249+ shortest edge are displaced randomly to find improvement and
250+ this process iterates until `n_iter` attempts have been made
251+ for a given edge. Defaults to False.
252+ edge_opt_n_iter (int): *(optional)* Maximum number of iterations per
253+ edge during optimization. Ignored if `edge_opt` set to False.
254+ Defaults to 100.
246255 mesh_max_volume (float): *(optional)* The maximum volume (area in 2D)
247256 of a mesh cell in the triangular mesh. Default is infinity,
248257 which turns off the maximum volume quality setting.
249- Value should be stritly positive.
258+ Value should be strictly positive.
250259 mesh_min_angle (float): *(optional)* The minimum interior angle,
251260 in degrees, of a cell in the triangular mesh. For 3D meshes,
252261 this is the dihedral angle between faces of the tetrahedron.
@@ -384,7 +393,8 @@ def run(phases, domain, verbose=False, restart=True, directory='.',
384393 if verbose :
385394 print ('Creating polygon mesh.' )
386395
387- pmesh = PolyMesh .from_seeds (seeds , domain )
396+ pmesh = PolyMesh .from_seeds (seeds , domain , edge_opt , edge_opt_n_iter ,
397+ verbose )
388398
389399 # Write polymesh
390400 poly_types = filetypes .get ('poly' , [])
@@ -614,7 +624,6 @@ def plot_seeds(seeds, phases, domain, plot_files=[], plot_axes=True,
614624 ax .get_yaxis ().set_visible (False )
615625 else :
616626 ax ._axis3don = False
617- fig .add_axes (ax )
618627
619628 # Plot seeds
620629 edge_kwargs .setdefault ('edgecolors' , {2 : 'k' , 3 : 'none' }[n_dim ])
@@ -624,9 +633,26 @@ def plot_seeds(seeds, phases, domain, plot_files=[], plot_axes=True,
624633 else :
625634 seeds .plot (facecolors = seed_colors , ** edge_kwargs )
626635
636+ # Crop to Domain
637+ d_lims = domain .limits
638+ if n_dim == 2 :
639+ plt .axis ('square' )
640+ plt .xlim (d_lims [0 ])
641+ plt .ylim (d_lims [1 ])
642+ elif n_dim == 3 :
643+ plt .gca ().set_xlim (d_lims [0 ])
644+ plt .gca ().set_ylim (d_lims [1 ])
645+ plt .gca ().set_zlim (d_lims [2 ])
646+
647+ _misc .axisEqual3D (plt .gca ())
648+
627649 # Save plot
628650 for fname in plot_files :
629- plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
651+ if n_dim == 3 :
652+ fig .subplots_adjust (** _misc .plt_3d_adj )
653+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0.15 )
654+ else :
655+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
630656
631657 plt .close ('all' )
632658
@@ -747,7 +773,11 @@ def plot_poly(pmesh, phases, plot_files=['polymesh.png'], plot_axes=True,
747773
748774 # save plot
749775 for fname in plot_files :
750- plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
776+ if n_dim == 3 :
777+ fig .subplots_adjust (** _misc .plt_3d_adj )
778+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0.15 )
779+ else :
780+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
751781 plt .close ('all' )
752782
753783
@@ -848,7 +878,6 @@ def plot_tri(tmesh, phases, seeds, pmesh, plot_files=[], plot_axes=True,
848878 ax .get_yaxis ().set_visible (False )
849879 else :
850880 ax ._axis3don = False
851- fig .add_axes (ax )
852881
853882 # Determine which facets are visible
854883 vis_regions = set ()
@@ -888,18 +917,27 @@ def plot_tri(tmesh, phases, seeds, pmesh, plot_files=[], plot_axes=True,
888917 # plot triangle mesh
889918 edge_kwargs .setdefault ('linewidths' , {2 : 0.5 , 3 : 0.1 }[n_dim ])
890919 edge_kwargs .setdefault ('edgecolors' , 'k' )
891- if given_names and color_by in ('material' , 'material number' ):
920+ if color_by in ('material' , 'material number' ):
892921 n = len (phases )
922+ if n_dim == 2 :
923+ cs = seed_colors
924+ else :
925+ cs = facet_colors
926+ cs .append ('none' )
927+
893928 cs = [_phase_color_by (i , phases , color_by , colormap ) for i in range (n )]
894929 cs .append ('none' )
895930
896931 old_e_att = np .copy (tmesh .element_attributes )
897932 old_f_att = np .copy (tmesh .facet_attributes )
898933 tmesh .element_attributes = [seeds [i ].phase for i in old_e_att ]
899- tmesh .facet_attributes = facet_phases
934+ tmesh .facet_attributes = [ facet_phases [ a ] for a in old_f_att ]
900935
901- tmesh .plot (facecolors = cs , index_by = 'attribute' , material = phase_names ,
902- ** edge_kwargs )
936+ if given_names :
937+ tmesh .plot (facecolors = cs , index_by = 'attribute' ,
938+ material = phase_names , ** edge_kwargs )
939+ else :
940+ tmesh .plot (facecolors = cs , index_by = 'attribute' , ** edge_kwargs )
903941
904942 tmesh .element_attributes = old_e_att
905943 tmesh .facet_attributes = old_f_att
@@ -909,7 +947,11 @@ def plot_tri(tmesh, phases, seeds, pmesh, plot_files=[], plot_axes=True,
909947
910948 # save plot
911949 for fname in plot_files :
912- plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
950+ if n_dim == 3 :
951+ fig .subplots_adjust (** _misc .plt_3d_adj )
952+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0.15 )
953+ else :
954+ plt .savefig (fname , bbox_inches = 'tight' , pad_inches = 0 )
913955
914956 plt .close ('all' )
915957
@@ -943,8 +985,8 @@ def dict_convert(dictionary, filepath='.'):
943985 Second, if the value of ``dist_type`` is ``histogram``, then the remaining
944986 key should also be ``filename`` and its value should be the path to a CSV
945987 file.
946- For the histogram, the first row of this CDF should be the *n+1 * bin
947- locations and the second row should be the *n* bin heights .
988+ For the histogram, the first row of this CDF should be the *n* bin heights
989+ and the second row should be the *n+1 * bin locations .
948990
949991 Additionally, if a key in the dictionary contains ``filename`` or
950992 ``directory`` and the value associated with that key is a relative path,
0 commit comments