Meshes#
mammos_mumag
has the possibility to use pre-calculated meshes. Some are shipped with the package, while some other are stored elsewhere (e.g., on Zenodo) and will require an internet connection to access.
At the moment, the package only works with meshes that fulfil certain properties.
The mesh must be in
.fly
format.The mesh must be consistent with the shell-transformation method, where tags would divide the mesh in different regions:
one or more regions represent the material (a single grain cube in this notebook case) and material parameters need to be assigned for each region;
a free space (non magnetic) is present around the material;
the last region is a shell sourrounding everything else (to map the outer region to infinity).
[1]:
from mammos_mumag.mesh import Mesh, find_mesh
List all available meshes#
The function find_mesh
can be used to find a specific mesh (filtering by name) or, if run without arguments, it will list all the available meshes.
[2]:
find_mesh()
[2]:
['cube20_singlegrain_msize1',
'cube20_singlegrain_msize2',
'cube50_singlegrain_msize1',
'cube50_singlegrain_msize2',
'cube40_equi_grains8_gsize20',
'cube80_equi_grains8_gsize40',
'cube160_equi_grains8_gsize80',
'cube40_colu_grains8_gsize20',
'cube80_colu_grains8_gsize40',
'cube160_colu_grains8_gsize80',
'cube40_3plat_grains12_gsize20',
'cube80_3plat_grains12_gsize40',
'cube160_3plat_grains12_gsize80']
[3]:
find_mesh("cube40")
[3]:
['cube40_equi_grains8_gsize20',
'cube40_colu_grains8_gsize20',
'cube40_3plat_grains12_gsize20']
[4]:
find_mesh("3plat")
[4]:
['cube40_3plat_grains12_gsize20',
'cube80_3plat_grains12_gsize40',
'cube160_3plat_grains12_gsize80']
These meshes are stored on Zenodo: .
The package mammos_mumag
also includes the mesh cube20_singlegrain_msize2
stored locally. Its loading time will be faster and it can work without internet connection.
[5]:
mesh = Mesh("cube80_3plat_grains12_gsize40")
[6]:
mesh
[6]:
Mesh('cube80_3plat_grains12_gsize40')
We can see more detailed information when we print the object:
[7]:
print(mesh)
Mesh: cube80_3plat_grains12_gsize40
description: Cube of side length 80 with 12 grains of size 40 generated as regular parallelepipeda on three layers.
geometry: cube
length: 80
ngrains: 12
grain_size: 40
Write the mesh#
The write
method downloads the mesh from Zenodo and saves it under the given name (which can be a relative or absolute path to save the mesh in a different directory than the current working directory) or it copies it to the requested location if the mesh is available locally as part of the package:
[8]:
mesh.write("mesh.fly")
The next command gives and error because this mesh is not available in MED format.
[9]:
mesh.write("mesh.med")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[9], line 1
----> 1 mesh.write("mesh.med")
File ~/repo/mammos/mammos-mumag/src/mammos_mumag/mesh.py:79, in Mesh.write(self, dest)
77 dest = pathlib.Path(dest).resolve()
78 if dest.suffix != ".fly":
---> 79 raise ValueError("Only `.fly` meshes are available.")
80 if self._local:
81 shutil.copy(self._path, dest)
ValueError: Only `.fly` meshes are available.
Using local user-defined meshes#
The Mesh
class can also be used to read already existing local meshes.
[10]:
m2 = Mesh("./mesh.fly")
[11]:
m2
[11]:
Mesh('mesh.fly')
In this case, we do not infer any information.
[12]:
print(m2)
Mesh: mesh.fly
description: User defined mesh.
If needed, it is possible to create a dictionary of information to be showed with the print
function.
[13]:
m2.info = {
"description": "Local mesh I created.",
"geometry": "cube",
}
print(m2)
Mesh: mesh.fly
description: Local mesh I created.
geometry: cube
The write
method will create copies of this mesh (in the same format).
[14]:
m2.write("copy.fly")