pyoomph.meshes package

Submodules

Module contents

class pyoomph.meshes.AxisymmetryBC(verbose=True, recurse=True)[source]

Bases: InterfaceEquations

Add this to the axis of symmetry to automatically enforce the boundary condition required by symmetry. Also automatically sets the correct boundary conditions for azimuthal eigenvalue problems.

For normal solving, it sets radial (and azimuthal) components of vector fields (also mesh_x) to zero. For azimuthal eigenvalue problems, it depends on the azimuthal mode m:

\(m=0\): As for normal solving. \(|m|=1\): scalar fields and axial vector components are set to zero, radial and azimuthal components are not. \(|m|\geq 2\): scalar fields and all vector components are set to zero

If you write an equation, where you want to change this behavior, you can manually change the conditions by obtaining the (writeable) field information via get_azimuthal_r0_info() after the definition via define_scalar_field() or define_vector_field().

Notes

Must be also added to intersections of other boundaries with the axis of symmetry, when the other boundaries define additional fields, e.g.

bulk=NavierStokesEquations(…) bulk+=AxisymmetryBC()@”axis” bulk+=NavierStokesFreeSurface()@”interface” bulk+=AxisymmetryBC()@”interface/axis” # This is important, since the free surface introduces new fields at the interface

This is, however, done automatically if the recurse flag is set to True.

class pyoomph.meshes.DirichletBC(*, prefer_weak_for_DG=True, **kwargs)[source]

Bases: BaseEquations

Class to impose one or more Dirichlet boundary condition.

Parameters:
  • prefer_weak_for_DG (bool, optional) – Flag indicating whether to prefer weak contributions for Discontinuous Galerkin (DG) methods. If set and the bulk equations provide a specific implementation of get_weak_dirichlet_terms_for_DG, these terms are used to enforce the condition in a weak sense. Otherwise, just stronly. Defaults to True.

  • **kwargs (ExpressionOrNum) – Keyword arguments representing the Dirichlet conditions, where the keys are the variable names and the values are the corresponding expressions or numbers. Expressions for strong DirichletBCs may not depend on unknowns.

class pyoomph.meshes.EnforcedBC(*, only_for_stationary_solve=False, set_zero_on_normal_mode_eigensolve=False, **constraints)[source]

Bases: InterfaceEquations

Enforce rather arbitrary boundary conditions by a field of Lagrange multipliers. As an example,

EnforcedBC(u=var(“u”)-var(“v”)) @ “boundary”

will set u=v on the boundary by adjusting u. The rhs must be a constraint in residual formulation, here u-v=0.

Parameters:
  • only_for_stationary_solve (bool, optional) – Flag indicating if the enforced boundary conditions should only be applied during stationary solves. Defaults to False.

  • set_zero_on_normal_mode_eigensolve (bool, optional) – Flag indicating if the enforced boundary conditions should be set to zero during azimuthal eigensolves. Defaults to False.

  • **constraints (Expression) – Keyword arguments representing the enforced boundary conditions as pair of variable name to adjust and constraint expression to fulfill in residual form.

class pyoomph.meshes.EnforcedDirichlet(*, only_for_stationary_solve=False, set_zero_on_normal_mode_eigensolve=False, **constraints)[source]

Bases: EnforcedBC

Enforces a DirichletBC by Lagrange multipliers. As an example,

EnforcedDirichlet(u=var("v")) @ "boundary"

will just be the same as EnforcedBC (u=var("u")-var("v")) @ "boundary"

Parameters:
  • only_for_stationary_solve (bool, optional) – Flag indicating if the enforced boundary conditions should only be applied during stationary solves. Defaults to False.

  • set_zero_on_normal_mode_eigensolve (bool, optional) – Flag indicating if the enforced boundary conditions should be set to zero during azimuthal eigensolves. Defaults to False.

  • **constraints (Expression) – Keyword arguments representing the enforced boundary conditions as pair of variable name to adjust and constraint expression to fulfill in residual form.

class pyoomph.meshes.InactiveDirichletBC(**kwargs)[source]

Bases: DirichletBC

Same as ‘DirichletBC’, but it starts deactivated, i.e. the Neumann term will be active by default.

To activate the Dirichlet condition, you must call the set_dirichlet_active(…) method of the Mesh class, which you can obtain by problem.get_mesh(…). Afterwards, it is important to call Problem.reapply_boundary_conditions(), e.g.

problem.get_mesh(“domain/interface”).set_dirichlet_active(u=True) # activate the BC problem.reapply_boundary_conditions() # Renumber the equations and apply BCs problem.solve() # solve with active DirichletBC

class pyoomph.meshes.InteriorBoundaryOrientation(indicator)[source]

Bases: InterfaceEquations

Named interior boundaries within a domain are by default double-layered, i.e. interface elements are added from both sides. This can usually cause problems. In order to avoid this, we have to specify the orientation of the boundary, i.e. only interface elements are added from one side, namely where the indicator function is positive. For a unit circle "circle" embedded in a domain, you could e.g. add InteriorBoundaryOrientation(dot(var("coordinate"),var("normal)))@"circle" to only add interface elements with an outward pointing normal.

Parameters:

InterfaceEquations (_type_) – _description_

class pyoomph.meshes.LineMesh(N=10, size=1.0, minimum=0.0, name='domain', left_name='left', right_name='right', nodal_dimension=None, periodic=False)[source]

Bases: MeshTemplate

A class representing a line mesh.

Parameters:
  • N (int) – The number of elements in the mesh.

  • size (Union[Expression, int, float]) – The size of the mesh, i.e. the length of the line.

  • minimum (Union[Expression, int, float]) – The position of the left boundary, i.e. the line ranges from minimum to minimum + size.

  • name (Union[str, Callable[[float], str]]) – The name of the domain or a function that returns the name based on the center of each element. This allows to create multiple domains in the same mesh, where the interfaces in between are automatically created and named based on the domain names separated with an underscore.

  • left_name (str) – The name of the left boundary.

  • right_name (str) – The name of the right boundary.

  • nodal_dimension (Optional[int]) – The nodal dimension of the mesh, can be used to curve the mesh later on.

  • periodic (bool) – Whether the mesh is periodic.

define_geometry()[source]

Define the geometry of the line mesh.

class pyoomph.meshes.MeshTemplate[source]

Bases: MeshTemplate

A class to construct meshes by defining nodes with the add_node() or add_node_unique() method. Elements must be specified by first creating one or multiple domains with the new_domain() method and adding elements on each domain. Nodes can be also marked to be on particular boundaries with the add_node_on_boundary() method.

available_domains()[source]

Returns a list of all available domains constructed with new_domain().

Return type:

Set[str]

create_curved_entity(typ, *args, **kwargs)[source]

Creates a curved entity on the mesh. Currently only the type "circle_arc" is supported, which requires the start and end point as positional arguments and either the center or through_point as keyword argument.

Parameters:
  • typ (str) – Type of the curved entity. Currently only "circle_arc" is supported.

  • args (Any) – Positional arguments for the curved entity.

  • kwargs (Any) – Keyword arguments for the curved entity.

Return type:

MeshTemplateCurvedEntityBase

Returns:

The created curved entity to be used in add_facet_to_curve_entity().

define_geometry()[source]

This method must be specialized in a derived class to define the geometry, i.e. the nodes, domains and elements of the mesh.

Return type:

None

get_domain(name)[source]

Get a domain by name constructed with the method new_domain() before.

Return type:

MeshTemplateElementCollection

has_domain(name)[source]

Test if a domain with the given name is available, i.e. constructed with new_domain() before.

Return type:

bool

max_permitted_error

The maximum permitted error for the spatial error estimator. If None, we use the value from the Problem object.

max_refinement_level

The maximum refinement level for spatial adaptivity. If None, we use the value from the Problem object.

min_permitted_error

The minimum permitted error for the spatial error estimator. If None, we use the value from the Problem object.

min_refinement_level

The minimum refinement level for spatial adaptivity. If None, we use the value from the Problem object.

new_domain(name, nodal_dimension=None)[source]

Create a new domain with the given name. With the help of this domain, elements can be added to the mesh.

Return type:

MeshTemplateElementCollection

nondim_size(a)[source]

Nondimensionalize a coordinate or a length scale by dividing by the spatial scale of the problem.

Parameters:

a (Union[Expression, int, float, List[Union[Expression, int, float]]]) – The coordinate or length scale to nondimensionalize.

Return type:

Union[float, List[float]]

Returns:

The arguments divided by the spatial scale of the problem.

remesher: Optional[RemesherBase]

Must be set to allow for remeshing.

class pyoomph.meshes.NeumannBC(**fluxes)[source]

Bases: InterfaceEquations

Class to impose Neumann boundary condition. The particular meaning of the Neumann flux depends on the bulk equations, i.e. how the integration by parts was performed for the weak formulation of the bulk equations. For a Poisson equation implemented by the residual weak(grad(u),grad(utest)), the Neumann condition

NeumannBC(u=1) @ "boundary"

does not neither mean setting u=1, but rather dot(grad(u),var(“normal”))=-1, where normal vector is pointing outward the domain at the boundary.

Parameters:

**fluxes (Union[Expression, int, float]) – Dictionary of fluxes, where the keys are the names of the fluxes and the values are expressions or numbers.

class pyoomph.meshes.PeriodicBC(other_interface, offset=None)[source]

Bases: InterfaceEquations

Introduces a periodic boundary condition between two interfaces. It will hold for all continuous fields! The mesh must be generated that way that for each node on this interface, there is a corresponding node on the other interface when adding offset to the position.

other_interface

The name of the other interface to which this boundary is periodic.

Type:

str

offset

The offset to find the corresponding nodes on the other interface.

Type:

Optional[List[ExpressionOrNum]]

class pyoomph.meshes.RectangularQuadMesh(*, name='domain', size=1.0, N=10, lower_left=[0, 0], periodic=False, split_in_tris=False, split_scott_vogelius=False, boundary_names={}, nodal_dimension=None)[source]

Bases: MeshTemplate

A class representing a rectangular mesh consisting of quadrilateral elements by default.

Parameters:
  • name (Union[str, Callable[[float, float], str]]) – The name of the domain or a function that returns the name based on the center coordinates of each element. The interfaces in between are automatically generated and named based on the domain names separated with an underscore.

  • size (Union[Expression, int, float, List[Union[Expression, int, float]]]) – The size of the mesh, either by a single value (for both directions) or by two values (for x and y directions).

  • N (Union[int, List[int]]) – The number of elements in each dimension.. Can be a single value or a list of two values for x and y dimensions respectively.

  • lower_left (Union[Expression, int, float, List[Union[Expression, int, float]]]) – The coordinates of the lower-left corner of the mesh, i.e. the mesh ranges from lower_left[0] to lower_left[0] + size[0] in x-direction and lower_left[1] to lower_left[1] + size[1]] in y-direction.

  • periodic (Union[bool, List[bool]]) – Whether the mesh is periodic, either in both directions or in x and y directions separately.

  • split_in_tris (Literal[False, 'alternate_left', 'alternate_right', 'left', 'right', 'crossed']) – Split the quadrilateral elements into triangles.

  • split_scott_vogelius (bool) – Whether to use splitting into Scott-Vogelius elements.

  • boundary_names (Dict[str, Union[str, Callable[[float], str]]]) – A dictionary mapping boundary names "left", "right", "top", "bottom" to their corresponding names. Alternatively a function, which also takes the center coordinates of each element as input, can be used to define the boundary names.

  • nodal_dimension (Optional[int]) – The nodal dimension of the mesh, can be used to curve the mesh later on.