Meshing¶
meshing.meshing module¶
This module handles the new meshing system.
Currently only designed for BFDTD simulations, i.e. for a final heterogeneous rectilinear grid. But it is completely independent of BFDTDobject or any other FDTD related code. VTK-related code will be added to it later eventually.
The class design is as follows:
- Mesh3D: Consists of 3 MultiMesh1D, for the X, Y and Z directions.
- MultiMesh1D: Contains a list of Mesh1D or MultiMesh1D objects.
- Mesh1D: A generic parent class for 1D meshes.
- HeterogeneousMesh1D: A heterogeneous mesh defined by its attribute coordinates.
- HomogeneousMesh1D: A homogeneous mesh defined by its attributes pos_min, pos_max, spacing_max. spacing_max is used to determine the number of points/cells.
- HomogeneousMeshParameters1D: A subclass of HomogeneousMesh1D, but for which the MultiMesh1D::getLocalCoordinates() function will take spacing_max into account to merge multiple HomogeneousMeshParameters1D in a smart way.
- Mesh1D: A generic parent class for 1D meshes.
- MultiMesh1D: Contains a list of Mesh1D or MultiMesh1D objects.
![digraph meshing_system_diagram {
edge [style=dashed,color=red, dir=back];
"Mesh3D" -> "MultiMesh1D" -> "Mesh1D";
edge [style=solid,color=black, dir=back];
"Mesh1D" -> {"HomogeneousMesh1D","HeterogeneousMesh1D"};
"HomogeneousMesh1D" -> "HomogeneousMeshParameters1D"
}](_images/graphviz-9b8e9303e84a8b5adbe04fad4d89b29504cd1dda.png)
idea: Make various meshing algorithms available and allow user-created ones (ex: structure-specific meshing algorithms, tests of meshing on simulation results).
Mesh objects¶
Mesh3D¶
-
class
meshing.meshing.
Mesh3D
[source] Bases:
object
A rectilinear structured 3D mesh/grid.
-
PrintSelf
(indent='')[source] printing function with indent
-
getGlobalLocation
()[source]
-
getGlobalXCoordinates
()[source] get the grid coordinates in the x-direction.
-
getGlobalYCoordinates
()[source] get the grid coordinates in the y-direction.
-
getGlobalZCoordinates
()[source] get the grid coordinates in the z-direction.
-
name
= None a name for easier debugging
-
setAllowResolutionScaling
(bool_value)[source] Set the allowResolutionScaling attribute to bool_value for xmesh, ymesh and zmesh.
-
setResolutionScalingFactor
(float_value)[source] Set the resolutionScalingFactor attribute to bool_value for xmesh, ymesh and zmesh.
-
setUseForMeshing
(bool_value)[source] Set the useForMeshing attribute to bool_value for xmesh, ymesh and zmesh.
-
xmesh
= None the 1D mesh in the X direction
-
ymesh
= None the 1D mesh in the Y direction
-
zmesh
= None the 1D mesh in the Z direction
-
MultiMesh1D¶
-
class
meshing.meshing.
MultiMesh1D
[source] Bases:
object
An object consisting of multiple Mesh1D or MultiMesh1D objects.
The idea is to for example create one main mesh for the FDTD simulation consisiting of multiple submeshes for each FDTD object in the simulation. Each of these object submeshes can then also consist of multiple submeshes, again being either Mesh1D or MultiMesh1D.
getLocalCoordinates() will go through all those meshes recursively and return a single merged one.
The extension of that system to 3 or more or less dimensions is then straightforward and done via the Mesh3D class.
-
PrintSelf
(indent='')[source] printing function with indent
-
addChild
(m)[source]
-
getGlobalCoordinates
()[source]
-
getGlobalLocation
()[source]
-
getLocalCoordinates
()[source] Returns the list of merged and sorted coordinates from all submeshes.
Note
Meshes of type HomogeneousMesh1D are handled in a special way, in the sense that their spacing_max values are compared to choose the smallest one in case of overlap.
-
getMesh1DList
()[source] Converts the submesh list into one containing only Mesh1D objects by iterating through the submeshes recursively.
-
makeAllSubMeshesChildren
()[source]
-
maximum_mesh_delta_ratio
= None For creating a smooth mesh. Neighboring cell sizes should not exceed a factor of maximum_mesh_delta_ratio. Default: 2. Set to
None
to disable.
-
maximum_mesh_delta_vacuum
= None If set, the mesh will be checked for any cells larger than
maximum_mesh_delta_vacuum * spacing_max
(spacing_max set to 1 if the Mesh1D object does not provide it). Default: None. Set toNone
to disable.
-
mesh_list
= None The list of Mesh1D or MultiMesh1D objects.
-
minimum_mesh_delta
= None The minimum cell size allowed. This is used when merging the various submeshes. Default: 1e-3. Set to
None
to disable.
-
name
= None a name for easier debugging
-
renderInBlender
(location=None, group='meshes')[source]
-
renderXMesh1D
(location=None, group='meshes')[source]
-
renderYMesh1D
(location=None, group='meshes')[source]
-
renderZMesh1D
(location=None, group='meshes')[source]
-
setAllowResolutionScaling
(bool_value)[source] Set the allowResolutionScaling attribute to bool_value for all submeshes.
-
setResolutionScalingFactor
(float_value)[source] Set the resolutionScalingFactor attribute to float_value for all submeshes.
-
setUseForMeshing
(bool_value)[source] Set the useForMeshing attribute to bool_value for all submeshes.
-
Mesh1D¶
-
class
meshing.meshing.
Mesh1D
[source] Bases:
object
Generic parent class for 1D meshes. It is used for HeterogeneousMesh1D and HomogeneousMesh1D. Other mesh types like a logarithmic mesh for example, could be added later.
Subclasses must all re-implement the following functions:
- getLocalCoordinates()
Variables: - useForMeshing (bool) – If true, it will be used to create the final mesh. Default: True.
- allowResolutionScaling (bool) – If true, changing the resolution settings to increase or decrease the number of cells will be allowed. Default: True.
- resolutionScalingFactor (float) – Allows increasing or decreasing the number of total cells in the mesh (if the mesh class supports it). Default: 1.
-
PrintSelf
(indent='')[source] printing function with indent
-
allowResolutionScaling
= None If true, changing the resolution settings to increase or decrease the number of cells will be allowed. Default: True.
-
getBounds
()[source] Returns the minimum and maximum values of the coordinates in the form (pos_min, pos_max).
-
getGlobalCoordinates
()[source]
-
getGlobalLocation
()[source]
-
getLocalCoordinates
()[source] Returns the list of coordinates. Must be re-implemented.
Note
Do not forget to take into account the Mesh1D attributes when implementing getLocalCoordinates().
-
getThicknessList
()[source] Returns a list of the thicknesses of each section.
-
name
= None a name for easier debugging
-
resolutionScalingFactor
= None Allows increasing or decreasing the number of total cells in the mesh (if the mesh class supports it). Default: 1.
-
setAllowResolutionScaling
(bool_value)[source] Set the allowResolutionScaling attribute to bool_value.
-
setResolutionScalingFactor
(float_value)[source] Set the resolutionScalingFactor attribute to float_value.
-
setUseForMeshing
(bool_value)[source] Set the useForMeshing attribute to bool_value.
-
useForMeshing
= None If true, it will be used to create the final mesh. Default: True.
HeterogeneousMesh1D¶
-
class
meshing.meshing.
HeterogeneousMesh1D
(coordinates=None)[source] Bases:
meshing.meshing.Mesh1D
Very basic class storing parameters for a heterogeneous 1D mesh.
-
PrintSelf
(indent='')[source] printing function with indent
-
coordinates
= None list of the position of mesh lines. Type: List of floats. Default: [0, 1]
-
createFromThicknessList
(pos_min, ThicknessList)[source] Creates a list of coordinates of the form:
- pos_min
- pos_min + ThicknessList[0]
- pos_min + ThicknessList[0] + ThicknessList[1]
- …
-
getLocalCoordinates
()[source] Returns the list of coordinates.
-
HomogeneousMesh1D¶
-
class
meshing.meshing.
HomogeneousMesh1D
(pos_min=None, pos_max=None, spacing_max=None)[source] Bases:
meshing.meshing.Mesh1D
Class storing parameters for a homogeneous 1D mesh.
This class uses spacing_max as main attribute instead of a given number of cells for more flexibility. This is useful when merging meshes (cf:
HomogeneousMeshParameters1D
). But when a thickness or position list is requested, we simply switch to “N” as main, i.e. we create a homogeneous mesh.In general, for FDTD, we want:
spacing_max < F*lambda*1/n
, withn=sqrt(epsilon_r)
.Since the factor F (usually around 1/15) and lambda are the only “geometry independent” settings, we bind them together into the resolutionScalingFactor.
So we use the remaining “geometry dependent” terms n (refractive index) and epsilon_r (relative permittivity) to define spacing_max.
Thus we define the following “terms” for use in this class and the meshing system:
- refractive index n:
1/spacing_max
- relative permittivity epsilon_r:
(1/spacing_max)^2
- resolutionScalingFactor:
1/(F*lambda)
(so that increasing it, decreases spacing_max and therefore increases NcellsMin) - Minimum number of cells NcellsMin :
ceil( abs(pos_max-pos_min)/spacing_max )
spacing_max can then be set via:
- setSpacingMax(spacing_max)
- setRefractiveIndexMin(n)
- setRelativePermittivityMin(epsilon_r)
- setNcellsMin(NcellsMin)
Corresponding get functions are also available.
Note
resolutionScalingFactor is only used when getLocalCoordinates() is called!
Parameters: - pos_min (float) – minimum position
- pos_max (float) – maximum position
- spacing_max (float) – maximum delta, i.e. cell thickness.
-
PrintSelf
(indent='')[source] printing function with indent
-
getLocalCoordinates
()[source] Returns the list of coordinates. It takes into account Mesh1D::resolutionScalingFactor.
-
getNcellsMin
()[source] get the minimum number of “cells” in the mesh (NOT the number of “positions”, which is
NcellsMin + 1
)
-
getRefractiveIndexMin
()[source] get the minimum “refractive index” defined as
1/spacing_max
-
getRelativePermittivityMin
()[source] get the minimum “relative permittivity” defined as
(1/spacing_max)^2
-
getSpacingMax
()[source] get the maximum spacing
-
renderInBlender
(location=None, group='meshes')[source]
-
renderXMesh1D
(location=None, group='meshes')[source]
-
renderYMesh1D
(location=None, group='meshes')[source]
-
renderZMesh1D
(location=None, group='meshes')[source]
-
setExtension
(pos_min, pos_max)[source] set the extension
-
setNcellsMin
(NcellsMin)[source] set the minimum number of “cells” in the mesh (NOT the number of “positions”, which is
NcellsMin + 1
)
-
setRefractiveIndexMin
(RefractiveIndexMin)[source] set the minimum “refractive index” defined as
1/spacing_max
-
setRelativePermittivityMin
(epsilon_r)[source] set the minimum “relative permittivity” defined as
(1/spacing_max)^2
-
setSpacingMax
(spacing_max)[source] set the maximum spacing
- refractive index n:
HomogeneousMeshParameters1D¶
-
class
meshing.meshing.
HomogeneousMeshParameters1D
(pos_min=None, pos_max=None, spacing_max=None)[source] Bases:
meshing.meshing.HomogeneousMesh1D
A subclass of HomogeneousMesh1D, but for which the MultiMesh1D::getLocalCoordinates() function will take spacing_max into account to merge multiple HomogeneousMeshParameters1D in a smart way.