fish2eod.mesh package

Submodules

fish2eod.mesh.boundary module

Functions for creating and labeling finite element boundaries.

class fish2eod.mesh.boundary.External

Bases: SubDomain

Label external boundaries.

static inside(_, *on_boundary)

Is the point inside the domain.

In this case the inside method is only considering if the point is a on a boundary between 2 domains.

Parameters:
  • _ – Ignored

  • on_boundary – List from dolfin index 0 is used to determine boundary state

fish2eod.mesh.boundary.boundary_iterator(domains)

Get every facet (edge) with at least 2 things touching it i.e. not an external edge.

Parameters:

domains (MeshFunctionSizet) – The labeled domains

Return type:

Iterable[Tuple[Facet, Tuple[int, ...]]]

Returns:

Iterable of tuples of an edge and its touching domains

fish2eod.mesh.boundary.mark_boundaries(domains, model_geometry, *boundary_markers, external_boundary)

Top level function to mark boundaries.

Parameters:
  • domains (MeshFunctionSizet) – Model domains

  • model_geometry (ModelGeometry) – Model geometry

  • boundary_markers (Callable[[int, int], Tuple[bool, int]]) – List of BoundaryMarkers

  • external_boundary – ID of the external boundary

Return type:

Tuple[MeshFunctionSizet, MeshFunctionSizet]

Returns:

Boundary and Outline MeshFunctions

fish2eod.mesh.boundary.mark_boundary(model_geometry, neighbouring_domains, *boundary_markers)

Mark a boundary given its neighbours and boundary markers.

Parameters:
  • model_geometry (ModelGeometry) – ModelGeometry containing the geometry

  • neighbouring_domains (Sequence[int]) – Domains touching the edge

  • boundary_markers (Callable[[int, int], Tuple[bool, int]]) – List

Return type:

int

Returns:

fish2eod.mesh.boundary.mark_edge_by_rules(neighbouring_domains, *boundary_markers)

Use rules specified in BoundaryCondition to mark complex edges.

Gets the edge label from the rule if it should be marked, otherwise returns -1

Markers are applied sequentially: so if a boundary is defined and is then crossed by another. The second boundary takes precedence

Parameters:
  • neighbouring_domains (Sequence[int]) – Domains touching the edges

  • boundary_markers (Callable[[int, int], Tuple[bool, int]]) – BoundaryMarkers to use

Return type:

Optional[int]

Returns:

Label of the edge

fish2eod.mesh.domain module

Functions for working with finite element domains.

fish2eod.mesh.domain.iterate_domains(model_geometry)

Iterate over objects in a model geometry and inform if the object is primitive.

Parameters:

model_geometry (ModelGeometry) – ModelGeometry to iterate

Return type:

Iterable[PreDomain]

Returns:

Domain label, if the objects are primitive, and list of geometry_primitives or a polygon

fish2eod.mesh.domain.mark_domains(mesh, model_geometry)

Create a meshfunction marked with the domain ids.

Parameters:
  • mesh (Mesh) – Created dolfin mesh

  • model_geometry (ModelGeometry) – ModelGeometry containing the added geometry

Return type:

MeshFunctionInt

Returns:

Domain meshfunction

fish2eod.mesh.domain.mark_polygon(domain_label, domains, obj)

Extremely inefficient marker for polygons.

Try to create complex shapes out of rectangles instead of resorting to this

Parameters:
  • domain_label (int) – Label (int) of the domain

  • domains (MeshFunction) – Domain meshfunction to update

  • obj (Polygon) – Polygon to mark (only one at a time)

Return type:

None

Returns:

None

fish2eod.mesh.domain.mark_primitives(domain_label, domains, objs)

Efficient marker for geometry_primitives.

Each primitive has an inside(x, …) which returns some boolean string expression

I.e. there will be a list of [“a==b”, “c==d”, …]

Reduce opperation convers that to (a==b) || (c==d) ||

The [:-3] strips off the ” ||”

Parameters:
  • domain_label (int) – Label (int) of the domain

  • domains (MeshFunction) – Domain meshfunction to update

  • objs (List[Union[Circle, Rectangle]]) – Objects to mark

Return type:

None

Returns:

None

fish2eod.mesh.mesh module

Functions for creating and finite element meshes from geometry_primitives.

class fish2eod.mesh.mesh.Mesher

Bases: object

add_circle(circle)
add_line(p1, p2)
add_line_loop(*lines)
add_polygon(poly)
add_surface(loop)
make_mesh()
Return type:

Mesh

write(file_handle)
fish2eod.mesh.mesh.add_circle(obj, mesh_geometry)

Add circle objects to the mesh_geometry.

Parameters:
  • obj (Polygon) – Circle to add

  • mesh_geometry (Mesher) – Mesher Geometry to add the circle to

Returns:

None

fish2eod.mesh.mesh.add_poly(obj, mesh_geometry)

Add polygonal objects to the mesh_geometry.

Parameters:
  • obj (Polygon) – Polygon (rectangle or generic) to add

  • mesh_geometry (Mesher) – Mesher to add the polygon to

Returns:

None

fish2eod.mesh.mesh.create_dolfin_mesh(points, cells)

Convert the mesh to a dolfin representation.

https://bitbucket.org/fenics-project/dolfin/issues/845/initialize-mesh-from-vertices

Parameters:
  • points (ndarray) – Mesh vertex coordinates

  • cells (ndarray) – Mesh topology

Return type:

Mesh

Returns:

dolfin mesh

fish2eod.mesh.mesh.create_mesh(model_geometry, verbose=True)

Create the mesh from the model geometry.

Parameters:
  • model_geometry (ModelGeometry) – The model geometry to mesh

  • verbose (bool) – Should gmsh output be printed

Return type:

Mesh

Returns:

The computed mesh

fish2eod.mesh.mesh.create_mesh_function(name, mesh, dimension)

Create boilerplate mesh function.

Parameters:
  • name (str) – Meshfunction name

  • mesh (Mesh) – Model mesh

  • dimension (int) – dimension of the function

Return type:

MeshFunctionSizet

Returns:

Empty MeshFunction

fish2eod.mesh.mesh.mesh_add(obj, mesh_geometry)

Add an object to the mesh.

Adds as a circle or polygon depending on the obj type

Parameters:
  • obj (Polygon) – Circle to add

  • mesh_geometry (Mesher) – Mesher to add the circle to

Returns:

None

fish2eod.mesh.model_geometry module

Container for geometry objects which can perform sanity checks and iterate sequentially.

class fish2eod.mesh.model_geometry.ModelGeometry(allow_overlaps=False)

Bases: object

Holding class for all model geometry.

Validates domains and manages domain names and labels

Behaves like a DB/dictionary with foreign keys
  • geometry[label: str] -> domain_id: str

  • geometry[id: int] -> domain_label: int

Parameters:

allow_overlaps (bool) – If overlaps cause an error or a warning

BACKGROUND_LABEL = 0
add_domain(name, *geometry_objects, **_)

Add a domain to the existing model geometry.

Parameters:
  • geometry_objects (Polygon) – Geometry objects to add

  • name (str) – Name of the new domain (can be omitted for no name)

  • _ – Any optional settings/params a subclass may want to set

Return type:

int

Returns:

Label of newly added domain

check_intersection(domain_name, g1, g2)

Check if the two geometries overlap and raise an error if so.

Parameters:
  • domain_name (Optional[str]) – Name of the existing domain or

  • g1 (Polygon) – First Geometry

  • g2 (Polygon) – Second Geometry

Return type:

bool

Returns:

None

clear()

Reset the model geometry.

draw(color='Dark2', legend=False)

Draw the model geometry as a line drawing.

Parameters:
  • color – Color or colormap name to use

  • legend – Whether to use the legend or not

Return type:

None

Returns:

None

intersects_background(g)

Ensure the new domain intersects with the background.

Parameters:

g (Polygon) – Geometry to check

Return type:

bool

Returns:

None

is_background(domain_name)

Check if domain name is background.

Parameters:

domain_name (Optional[str]) – Either the domain_name or None

Return type:

bool

Returns:

IF the domain is background

property next_valid_label: int

Determine the next valid domain label my incrementing current max.

Return type:

int

Returns:

Next valid label

validate_intersections(geometry_objects)

Validate intersections between objects on the new domain and between the new domain and old domain.

Parameters:

geometry_objects (Sequence[Polygon]) – Geometry objects on new domain to validate

Return type:

None

Returns:

None

class fish2eod.mesh.model_geometry.QESGeometry(allow_overlaps=False)

Bases: ModelGeometry

Extended model geometry which takes an additional argument ‘sigma’ when adding domain do define conductance.

add_domain(name, *geometry_objects, sigma=None, **_)

Add domain in a QES model.

Parameters:
  • name (str) – Name of the domain

  • geometry_objects (Polygon) – Arbitrary number of geometry objects

  • sigma (Union[float, Callable, None]) – Conductance of the domain (must be set as a kwarg)

Return type:

None