simudo.mesh package¶
Submodules¶
simudo.mesh.construction_helper module¶
- class simudo.mesh.construction_helper.BaseConstructionHelper[source]¶
Bases:
objectboilerplate
- dim¶
- classmethod from_existing_mesh_cf(mesh, cf, cell_regions, run=True, params=None, mesh_unit=None)[source]¶
- gdim¶
- mesh_data¶
- p¶
- robjs¶
- used_cell_values¶
- user_mark_external_boundary_facets(mesh, boundary_facet_function)[source]¶
override me (maybe)
this function is allowed to add new definitions and cell values to self.cell_regions
by default this uses facet.facet2d_angle and defines new regions right/top/left/bottom
this function MUST add an ‘exterior’ key for all external boundary facets
- class simudo.mesh.construction_helper.ConstructionHelperIntervalProduct2DMesh[source]¶
Bases:
BaseConstructionHelper- class Interval1DTag(intervals)¶
Bases:
Product2DMeshMixin,MinimumCoordinateDistanceMixin,BaseInterval1DTag
- interval_1d_tag¶
- product2d_Ys = (0.0, 1.0)¶
- class simudo.mesh.construction_helper.ConstructionHelperLayeredStructure[source]¶
Bases:
ConstructionHelperIntervalProduct2DMeshMesh-construction helper for 1-D layered device structures (optionally extruded to 2-D).
Layers are specified as a list of dicts, each containing at minimum
'name'(str),'material'(str), and'thickness'(float, in mesh units). Pass the list asparams['layers']. Additional mesh refinement regions can be supplied asparams['extra_regions'].See
ConstructionHelperIntervalProduct2DMeshfor the underlying mesh-generation machinery, andProblemDatafor the solver object that consumes the resulting mesh.- Variables:
material_to_region (dict) – Mapping from material name (str) to the union
CellRegioncovering all layers with that material.layers (list of dict) – The layer definitions as supplied in
params['layers'].extra_regions (list) – Extra refinement regions, from
params['extra_regions'](formerlyparams['simple_overmesh_regions']).
- extra_regions¶
- layers¶
- material_to_region¶
- class simudo.mesh.construction_helper.ConstructionHelperManualCellTagging[source]¶
Bases:
BaseConstructionHelper
- class simudo.mesh.construction_helper.ConstructionHelperMshr[source]¶
Bases:
BaseConstructionHelper
- class simudo.mesh.construction_helper.ConstructionHelperPygmsh2[source]¶
Bases:
BaseConstructionHelperExample:
from simudo.mesh import ConstructionHelperPygmsh2 from simudo.mesh.gmsh import AnisotropicPygmshGeneratorHelper class MyMeshConstructor(ConstructionHelperPygmsh2): my_custom_r2_height = 1.5 class GeneratorHelper(AnisotropicPygmshGeneratorHelper): def user_generate(self): geo = self.geometry tt = self.tag_tracker # yuo can reference attributes of the ConstructionHelper constructor = self.user_data r2h = constructor.my_custom_r2_height # construct three overlapping rectangles r0 = tt(geo.add_rectangle([0.0, 0.0, 0.0], 1.0, 1.0)) r1 = tt(geo.add_rectangle([0.5, 0.5, 0.0], 1.0, 1.0)) r2 = tt(geo.add_rectangle([0.7, 0.2, 0.0], 0.1, r2h)) # no need to wait until the end to define physical tags! self.regions["r0"] = r0 self.regions["core"] = r0 & r1 & r2 # merge the shapes together tt.merge(r0, r1, r2) # finish defining regions self.regions["r1"] = r1 self.regions["r2"] = r2 # poke a hole in the mesh! tt.remove((r2 & r0) - r1) def user_density_function(self, mesh, cell_function, tag_values): cf = cell_function r = tag_values dx = dolfin.dx() element = dolfin.VectorElement("DG", mesh.ufl_cell(), 1, 9) space = dolfin.FunctionSpace(mesh, element) u = dolfin.Function(space) v = dolfin.TestFunction(space) expr = -dolfin.inner(v, u) * dx a = r["r0"] - r["r1"] - r["r2"] b = r["r1"] - r["r0"] - r["r2"] c = (r["r0"] | r["r1"] | r["r2"]) - a - b A = 2000 B = 20 for cvs, vec in [ [a, [A, 0.0, 0.0, 0.0, B, 0.0, 0.0, 0.0, 1.0]], [b, [B, 0.0, 0.0, 0.0, A, 0.0, 0.0, 0.0, 1.0]], [c, [B, A, 0.0, A, B, 0.0, 0.0, 0.0, 1.0]], ]: dx1 = dolfin.dx(subdomain_data=cf, subdomain_id=tuple(cvs)) expr += dolfin.inner(v, dolfin.Constant(vec)) * dx1 solver = NewtonSolver(F=expr, u_=u, bcs=[]) solver.solve() return u
- GeneratorHelper: type = Ellipsis¶
- user_density_function(mesh, cell_function, tag_values)[source]¶
override me
- Parameters:
mesh (FEM mesh) – Initial generated mesh.
cell_function – Cell function with region information.
tag_values – Dictionary mapping region names to sets of cell values.
- Returns:
Vector 9-component FEM function representing a 3x3 anisotropic metric matrix.
- Return type:
function
- xdmf_output: str = None¶
- class simudo.mesh.construction_helper.InvertibleTransform[source]¶
Bases:
objectFIXME: make PlazaRefinementND use alternate definition of longest_edge
This hack is instead used to temporarily modify the mesh coordinates temporarily to alter PlazaRefinementND’s length metric
v[i, j] is vertex i’s jth coordinate
- class simudo.mesh.construction_helper.LinearTransform(matrix)[source]¶
Bases:
InvertibleTransform
simudo.mesh.construction_helper_example module¶
- class simudo.mesh.construction_helper_example.Bob[source]¶
Bases:
ConstructionHelperMshr
simudo.mesh.domaintag_mshr module¶
- class simudo.mesh.domaintag_mshr.DomainTag[source]¶
Bases:
object- first_cell_value = 1¶
- generate_intersection_regions(tagitems)[source]¶
returns frozenset of tagset
region described by tagset is intersection(tagset) - union(all_tags - tagset)
simudo.mesh.facet module¶
- class simudo.mesh.facet.FacetsManager(mesh, cell_function, boundary_facet_function)[source]¶
Bases:
objectKeep track of boundaries between subdomains (cell function values).
- boundary(X, Y, intersection=None)[source]¶
Get signed boundary between X and Y.
If the intersection between X and Y is nonempty, you must pass the intersection argument. This function will pretend that the intersection is actually part of X or Y (depending on the value of intersection). In other words,
boundary(X, Y, 0) == boundary(X, Y-X), andboundary(X, Y, 1) == boundary(X-Y, Y).
- Parameters:
X (set) – X and Y must be sets of cell marker values (representing subdomains). X and Y must be disjoint unless the intersection argument is used.
Y (set) – See X.
intersection (int, optional) – Must be 0 or 1, if specified.
- Returns:
fvs – Set of tuples
(facet_value, sign)representing facets between X and Y.- Return type:
set
- cell_value_internal(X)[source]¶
Get internal facets excluding boundaries across cell values (subdomains).
- Parameters:
X (set) – Set of cell values (representing subdomains).
- Returns:
fvs – Set of (facet_value, sign) representing facets contained within X and not on the boundary between two cell values.
- Return type:
set
- fix_undefined_facets_after_subdivision(mesh, cell_function, facet_function)[source]¶
Assign markers to facets created by mesh subdivision.
Upon subdivision, cells get split and new facets are created to separate them. The subdivision algorithm cannot know what facet value to assign to these new facets, so it leaves them with a large undefined value.
These facets must be fully internal to a subdomain, so the cells on either side must have the same cell value. That cell value corresponds to a facet value for internal facets, which is precisely the information stored in the internal_facets_dict attribute.
- Parameters:
mesh (dolfin.Mesh) – Mesh on which to operate.
cell_function (dolfin.CellFunction) – Cell function on mesh representing subdomains.
facet_function (dolfin.FacetFunction) – Facet function to fix up after subdivision. This will be modified in place.
- simudo.mesh.facet.facet2d_angle(facet)[source]¶
right_value=0, up_value=1, left_value=2, down_value=3
simudo.mesh.interval1dtag module¶
- class simudo.mesh.interval1dtag.BaseInterval1DTag(intervals)[source]¶
Bases:
objectClass that turns a bunch of arbitrary overlapping intervals into a mesh.
- coordinates¶
- first_cell_value = 1¶
- make_interval_coordinates(x0, x1, local_edge_length_function)[source]¶
Note: this excludes second endpoint
- subdomains¶
- tag_to_cell_values¶
Mapping from a tag to a set of cell values (e.g. values inside self.product2d_mesh.cell_function).
- class simudo.mesh.interval1dtag.CInterval(x0, x1, tags=(), edge_length=inf)[source]¶
Bases:
IntervalRepresents an interval with constant edge length (in the x direction).
Note: you do not need to derive from this class to implement a custom edge length. Instead, you can subclass from
Intervaland implement a customlocal_edge_lengthmethod.
- class simudo.mesh.interval1dtag.GeometricallyExpandingMeshInterval(*, edge_length_start, edge_length_expansion_factor, **kw)[source]¶
Bases:
IntervalInterval of 1D mesh where the edge lengths start at
startand increase geometrically away from the region bounds.See
doc/mesh.lyxfor more information.(Local edge length: minimum distance between two mesh vertices.)
- Parameters:
bounds (tuple) – Tuple defining the region.
edge_length_start (float or tuple) – The initial edge length at the bounds. To have different initial edge lengths at the two ends of the region, pass in a tuple.
edge_length_expansion_factor (float or tuple) – Geometric expansion factor. Pass in a tuple to use different factors on the two ends of the region.
- class simudo.mesh.interval1dtag.Interval(x0, x1, tags=())[source]¶
Bases:
objectRepresents a single interval, possibly with tags.
- class simudo.mesh.interval1dtag.Interval1DTag(intervals)[source]¶
Bases:
Product2DMeshMixin,MinimumCoordinateDistanceMixin,BaseInterval1DTag
- class simudo.mesh.interval1dtag.MinimumCoordinateDistanceMixin[source]¶
Bases:
object- minimum_coordinate_distance = 1e-10¶
- class simudo.mesh.interval1dtag.Product2DMeshMixin[source]¶
Bases:
object- class Product2DMesh(Xs, Ys=None)¶
Bases:
object- cells_at_ix(ix)¶
- copy()¶
note: does not deepcopy Xs and Ys
- create_function_from_x_values(values)¶
- element¶
- ix_from_vertex(v)¶
- iy_from_vertex(v)¶
- mesh¶
- nX¶
- nY¶
- space¶
- vertices_at_ix(ix)¶
- vertices_at_iy(iy)¶
- make_product2d_mesh(coordinates, subdomain_to_coordinate_range, subdomain_to_cell_value, Ys)[source]¶
- product2d_Ys = (0.0, 1.0)¶
- product2d_mesh¶
Use this to get a readily-constructed Product2D object. Note that an attribute cell_function has been added to it.
simudo.mesh.mesh1d module¶
simudo.mesh.mesh_entity_predicate module¶
- class simudo.mesh.mesh_entity_predicate.AlwaysTruePredicate(dim)[source]¶
Bases:
BaseMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.AndMeshEntityPredicate(*predicates)[source]¶
Bases:
CombiningMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.CombiningMeshEntityPredicate(*predicates)[source]¶
Bases:
BaseMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.DimensionAdapterPredicate(predicate, dim)[source]¶
Bases:
BaseMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.DirectionalEdgeLengthPredicate(direction, threshold=None)[source]¶
Bases:
BaseMeshEntityPredicate- dim = 1¶
- class simudo.mesh.mesh_entity_predicate.InRadiusCellPredicate(threshold, dim)[source]¶
Bases:
BaseMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.MaxEdgeLengthCellPredicate(threshold, dim)[source]¶
Bases:
BaseMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.NandMeshEntityPredicate(*predicates)[source]¶
Bases:
CombiningMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.OrMeshEntityPredicate(*predicates)[source]¶
Bases:
CombiningMeshEntityPredicate
- class simudo.mesh.mesh_entity_predicate.SubdomainCellPredicate(cell_function, subdomains)[source]¶
Bases:
BaseMeshEntityPredicate
simudo.mesh.product2d module¶
simudo.mesh.pygmsh module¶
- class simudo.mesh.pygmsh.PygmshMakeRegions[source]¶
Bases:
objectWe want overlapping regions. gmsh and pygmsh make that difficult. gmsh supports overlapping physical surfaces/volumes, but it returns duplicate mesh cells (see meshio issue 175). We can fix this by postprocessing pygmsh’s output, which thankfully contains all the necessarily info. At least for now.
simudo.mesh.refine module¶
simudo.mesh.topology module¶
- class simudo.mesh.topology.CellRegion(*args, **kwargs)[source]¶
Abstract cell region.
Can be evaluated down to a set of subdomain markers using
MeshData.evaluate_topology().To access a cell region predefined (named) in the mesh generator, instantiate this class directly with a
nameargument.
- class simudo.mesh.topology.FacetRegion(*args, **kwargs)[source]¶
Abstract facet region.
Can be evaluated down to a set of
(facet_marker_value, facet_sign)usingMeshData.evaluate_topology().To access a facet region predefined (named) in the mesh generator, instantiate this class directly with a
nameargument.
- class simudo.mesh.topology.CellRegions(mapping=None)[source]¶
Convenient container for cell region objects.
- Variables:
_mapping_ (dict) – Dictionary of cell regions.
- \_\_getitem\_\_(name)
I.e.
obj[name]. Ifnameis already in_mapping_, it is retrieved from there; otherwise aCellRegionis created with that name, stored inside_mapping_, and returned.If
nameis aset, then a subset of the_mapping_dictionary is returned with those keys.
- \_\_getattr\_\_(name)
I.e.
obj.$name. Redirected toobj[name].
- class simudo.mesh.topology.FacetRegions(mapping=None)[source]¶
Convenient container for facet region objects.
See
CellRegions.