Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
AHartmaier committed Feb 9, 2024
1 parent 314e10a commit 88c69d7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/kanapy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class Microstructure(object):
List of particle objects of class entities containing information object particle geometries
rve : object of class RVE_creator
Contains information about the RVE
Attributes: dim, size, nphases, nparticles, periodic, units, packing_steps, particle_data,
Attributes: dim, size, nparticles, periodic, units, packing_steps, particle_data,
phase_names, phase_vf, ialloy
simbox : Object of class Simulation_Box
Contains information about geometry of simulation box for particle simulation
mesh : object of class mesh_creator
Attributes: dim, grain_dict, grain_ori_dict, grain_phase_dict, grains, ngrains_phase. nodes, nodes_smooth,
nphases, nvox, phases, prec_vf_voxels, vox_center_dict, voxel_dict
nvox, phases, prec_vf_voxels, vox_center_dict, voxel_dict
geometry : dict
Dictionary of grain geometries;
Dict keys: "Ngrains", "Vertices", "Points", "Simplices", "Facets", "Grains", "GBnodes", GBarea" "GBfaces"
Expand Down Expand Up @@ -196,7 +196,7 @@ def voxelize(self, particles=None, dim=None):
self.mesh.create_voxels(self.simbox)

self.mesh = \
voxelizationRoutine(particles, self.mesh, prec_vf=self.precipit)
voxelizationRoutine(particles, self.mesh, self.nphases, prec_vf=self.precipit)
if np.any(self.nparticles != self.mesh.ngrains_phase):
logging.info(f'Number of grains per phase changed from {self.nparticles} to ' +
f'{list(self.mesh.ngrains_phase)} during voxelization.')
Expand Down Expand Up @@ -243,11 +243,11 @@ def generate_grains(self):
# in case of precipit, remove irregular grain 0 from analysis
empty_vox = self.mesh.grain_dict.pop(0)
grain_store = self.mesh.grain_phase_dict.pop(0)
nphases = self.rve.nphases - 1
nphases = self.nphases - 1
else:
empty_vox = None
grain_store = None
nphases = self.rve.nphases
nphases = self.nphases

self.geometry: dict = \
calc_polygons(self.rve, self.mesh) # updates RVE_data
Expand Down
2 changes: 0 additions & 2 deletions src/kanapy/initializations.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def __init__(self, stats_dicts, nsteps=1000, from_voxels=False):
Attributes
----------
self.nphases = len(stats_dicts) # number of phases in RVE
self.packing_steps = nsteps # max number of steps for packing simulation
self.size = None # tuple of lengths along Cartesian axes
self.dim = None # tuple of number of voxels along Cartesian axes
Expand Down Expand Up @@ -263,7 +262,6 @@ def gen_data_elong(pdict):
else:
print('Creating an RVE based on user defined statistics')
# Extract grain diameter statistics info
self.nphases = len(stats_dicts) # number of phases in RVE
self.packing_steps = nsteps # max number of steps for packing simulation
self.size = None # tuple of lengths along Cartesian axes
self.dim = None # tuple of number of voxels along Cartesian axes
Expand Down
1 change: 0 additions & 1 deletion src/kanapy/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ def import_voxels(file, path='./'):
ms.simbox = Simulation_Box(size)
# initialize voxel structure (= mesh)
ms.mesh = mesh_creator(sh)
ms.mesh.nphases = nphases
ms.mesh.grains = grains
ms.mesh.grain_dict = grain_dict
ms.mesh.grain_ori_dict = grain_ori_dict
Expand Down
4 changes: 2 additions & 2 deletions src/kanapy/voxelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def reassign_shared_voxels(cooDict, Ellipsoids, voxel_dict):
return


def voxelizationRoutine(Ellipsoids, mesh, prec_vf=None):
def voxelizationRoutine(Ellipsoids, mesh, nphases, prec_vf=None):
"""
The main function that controls the voxelization routine using: :meth:`kanapy.input_output.read_dump`,
:meth:`create_voxels`, :meth:`assign_voxels_to_ellipsoid`, :meth:`reassign_shared_voxels`
Expand Down Expand Up @@ -374,7 +374,7 @@ def voxelizationRoutine(Ellipsoids, mesh, prec_vf=None):
# empty voxels will get phase number 1 and be assigned to grain with key 0
ph_arr = -np.ones(mesh.nvox, dtype=int)
mesh.grain_phase_dict = dict()
mesh.ngrains_phase = np.zeros(mesh.nphases, dtype=int)
mesh.ngrains_phase = np.zeros(nphases, dtype=int)
for ih, il in mesh.grain_dict.items():
il = np.array(il) - 1
ip = Ellipsoids[ih - 1].phasenum
Expand Down
4 changes: 2 additions & 2 deletions tests/test_voxelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ def test_voxelizationRoutine():
sim_box = Simulation_Box(rve.size)
sim_box.sim_ts = 500
mesh = mesh_creator(rve.dim)
mesh.nphases = 1
nphases = 1
mesh.create_voxels(sim_box)
Particles = particle_generator([parDict], sim_box, False)
mesh = voxelizationRoutine(Particles, mesh)
mesh = voxelizationRoutine(Particles, mesh, nphases)
assert mesh.vox_center_dict[5][0] == 0.9
assert mesh.voxel_dict[7] == [29, 30, 26, 25, 31, 32, 28, 27]
assert mesh.grains.shape == (15, 15, 15)
Expand Down

0 comments on commit 88c69d7

Please sign in to comment.