dolfinx_mpc#
Main module for DOLFINX_MPC
- class dolfinx_mpc.BCData(bcs: Sequence[DirichletBC] | None = None)[source]#
Dof markers, diagonal rows and lifting values for a set of Dirichlet conditions.
Markers and rows depend only on a function space and the conditions, not on the condition values. We cache these computations so that multiple assembly calls inside {py:class}`dolfinx_mpc.LinearProblem` or {py:class}`dolfinx_mpc.NonlinearProblem` do not repeat them.
- lifting(V: FunctionSpace, dtype: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None) tuple[ndarray[tuple[Any, ...], dtype[int8]], ndarray[tuple[Any, ...], dtype[generic]]][source]#
Constrained dof markers and Dirichlet values on the trial space V.
The markers are cached; the values are re-read from the conditions on every call, so a time-dependent condition is picked up. Both are empty when no condition applies to V.
- markers(V0: FunctionSpace, V1: FunctionSpace) tuple[ndarray[tuple[Any, ...], dtype[int8]], ndarray[tuple[Any, ...], dtype[int8]]][source]#
Constrained dof markers for the test and trial spaces of a form.
- class dolfinx_mpc.LinearProblem(a: Form | Sequence[Sequence[Form]], L: Form | Sequence[Form], mpc: MultiPointConstraint | Sequence[MultiPointConstraint], bcs: list[DirichletBC] | None = None, u: Function | Sequence[Function] | None = None, petsc_options_prefix: str = 'dolfinx_mpc_linear_problem_', petsc_options: dict | None = None, form_compiler_options: dict | None = None, jit_options: dict | None = None, P: Form | Sequence[Sequence[Form]] | None = None, entity_maps: Sequence[EntityMap] | None = None, kind: str | Sequence[Sequence[str | None]] | None = None)[source]#
Class for solving a linear variational problem with multi point constraints of the form a(u, v) = L(v) for all v using PETSc as a linear algebra backend.
- Parameters:
a – A bilinear UFL form, the left hand side of the variational problem.
L – A linear UFL form, the right hand side of the variational problem.
mpc – The multi point constraint.
bcs – A list of Dirichlet boundary conditions.
u –
The solution function. It will be created if not provided. The function has to be based on the functionspace in the mpc, i.e.
u = dolfinx.fem.Function(mpc.function_space)
petsc_options – Parameters that is passed to the linear algebra backend PETSc. #type: ignore For available choices for the ‘petsc_options’ kwarg, see the PETSc-documentation https://www.mcs.anl.gov/petsc/documentation/index.html.
form_compiler_options – Parameters used in FFCx compilation of this form. Run ffcx –help at the commandline to see all available options. Takes priority over all other parameter values, except for scalar_type which is determined by DOLFINx.
jit_options – Parameters used in CFFI JIT compilation of C code generated by FFCx. See FEniCS/dolfinx for all available parameters. Takes priority over all other parameter values.
P – A preconditioner UFL form.
entity_maps – If any trial functions, test functions, or coefficients in the form are not defined over the same mesh as the integration domain,
entity_mapsmust be supplied. For each key (a mesh, different to the integration domain mesh) a map should be provided relating the entities in the integration domain mesh to the entities in the key mesh e.g. for a key-value pair(msh, emap)inentity_maps,emap[i]is the entity inmshcorresponding to entityiin the integration domain mesh.kind – The kind of matrix, as in
dolfinx.fem.petsc.LinearProblem(). For a single constraint, a PETSc matrix type, withNonethe default. Whenmpcis a sequence, one constraint per block,"nest"or a nested sequence of matrix types assembles a PETScnestmatrix and vector, whose blocks have those types, and any other kind, such as"mpi", a single monolithic matrix and vector with the blocks one after another.None, the default, is"nest", which is what a problem with one constraint per block has always used.
Examples
Example usage:
problem = LinearProblem(a, L, mpc, [bc0, bc1], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
- class dolfinx_mpc.MultiPointConstraint(V: FunctionSpace, dtype: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None = None, bcs: List[DirichletBC] | None = None, rhs_coeffs: Function | None = None)[source]#
Hold data for multi point constraint relation ships, including new index maps for local assembly of matrices and vectors.
The constraint is affine, \(x = K x_{red} + g\), where \(g\) is supplied through rhs_coeffs and through the Dirichlet conditions in bcs. With neither, \(g=0\) and the constraint is the usual linear one.
- Parameters:
V – The function space
dtype – The scalar type of the coefficients, used by everything built from this constraint. Defaults to the default scalar type of DOLFINx, real or complex, at the precision of the mesh of V. Its precision must be that of the mesh.
bcs – Dirichlet boundary conditions for the problem. A master degree of freedom that is constrained by one of these is removed from the equation of its slave, and its contribution folded into the constraint offset \(g\). As the offset is recomputed from the current values of the conditions by
update_constants(), time dependent boundary data is supported.rhs_coeffs – Function holding an additional inhomogeneity \(g_s\) for the slave degrees of freedom, i.e. \(u_s = \sum_j c_j u_{m_j} + g_s\).
- add_constraint(V: FunctionSpace, slaves: ndarray[tuple[Any, ...], dtype[int32]], masters: ndarray[tuple[Any, ...], dtype[int64]], coeffs: ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]], owners: ndarray[tuple[Any, ...], dtype[int32]], offsets: ndarray[tuple[Any, ...], dtype[int32]], master_space: FunctionSpace | None = None, master_blocks: ndarray[tuple[Any, ...], dtype[int32]] | None = None)[source]#
Add new constraint given by numpy arrays.
- Parameters:
V – The function space for the constraint
slaves – List of all slave dofs (using local dof numbering) on this process
masters – List of all master dofs (using global dof numbering) on this process
coeffs – The coefficients corresponding to each master.
owners – The process each master is owned by.
offsets –
Array indicating the location in the masters array for the i-th slave in the slaves arrays, i.e.
masters_of_owned_slave[i] = masters[offsets[i]:offsets[i+1]]
master_space – The function space all masters belong to, if not V. It must be the space of another constraint finalized together with this one by
finalize_multipointconstraints(), or an uncollapsed subspace of it, and masters is in the global numbering of that constraint’s space. The masters of a slave may then be in another block of a blocked problem.master_blocks – The block of each master, for masters from several spaces: its position in the list of constraints given to
finalize_multipointconstraints(). Each master is in the global numbering of its block. Exclusive with master_space.
Note
Collective when master_space or master_blocks is given: every process must call it with the same master_space, or with master_blocks (possibly empty).
- add_constraint_from_mpc_data(V: FunctionSpace, mpc_data: mpc_data_double | mpc_data_float | mpc_data_complex_double | mpc_data_complex_float | MPCData, master_space: FunctionSpace | None = None)[source]#
Add new constraint given by an dolfinc_mpc.cpp.mpc.mpc_data-object. See
add_constraint()for master_space. The master_blocks of mpc_data, if any, are the master_blocks ofadd_constraint(), and exclusive with master_space.
- add_integral_constraint(weight_form, value, bcs: List[DirichletBC] | None = None, rtol: floating | float | None = None, *, coefficient_tol: float | None = None)[source]#
Constrain a scalar integral of the solution, \(L(u) = \gamma\).
The functional is given as a linear form, and turned into a constraint with a single slave by
dolfinx_mpc.create_integral_constraint(); see there for the derivation and the cost. The inhomogeneity \(\gamma/w_s\) is written into therhs_coeffsfunction of this constraint, which is created here if none was supplied to the constructor.- Parameters:
weight_form – A linear form in
ufl.TestFunction(V)defining the functional, for instancev * ufl.dx. Its test function must be in the function space of this constraint.value – The prescribed value \(\gamma\) of the functional.
bcs – Dirichlet conditions on the space. A constrained degree of freedom is never chosen as the slave. Pass the same conditions to the constructor to have a constrained master folded into the constraint offset. Defaults to the conditions given to the constructor.
rtol – Deprecated, use coefficient_tol.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest one is dropped. Defaults to 500 machine epsilon of the real type of the constraint.
Note
Collective. Must be called by every process.
- add_master_from_point(V: FunctionSpace, slave_marker: Callable[[ndarray], ndarray], coefficient: Callable[[ndarray], ndarray] | float | complex, point: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], distance_tol: float | None = None)[source]#
Add the dofs at a point as a master of the rows of marked slaves.
Each slave of V at a coordinate \(x\) marked by slave_marker gets the term \(k(x)\, u(p)\) added to the right-hand side of its row, by
extend_masters(), with \(p\) = point and \(k\) = coefficient. For a blocked V, component \(b\) of a slave gets component \(b\) of the dofs at \(p\); for a single component pass the uncollapsed subspace, for instance V.sub(1).For instance, the periodic cell of the homogenization demos ties the right edge to the left edge plus the corner \(B\), \(u(L, y) = u(0, y) + u^B\): the periodic constraint gives \(u(L, y) = u(0, y)\), and this function, with the right edge marked, coefficient 1 and point \(B\), adds \(u^B\).
- Parameters:
V – The space of this constraint, or an uncollapsed subspace of it
slave_marker – Marks the coordinates of the slaves, (3, n) to (n,). Each marked dof must already be a slave, and the dofs at point must not be marked.
coefficient – The coefficient \(k\) of each slave, from its coordinates, (3, n) to (n,), or one value for all.
point – The point of the master, of gdim or 3 coordinates. Exactly one block of dofs of V must be there (see
dofs_at_point()).distance_tol – The largest distance between point and its dofs. Defaults to 500 machine epsilon of the coordinate type of the mesh.
Note
Collective. Must be called by every process, before the constraint is finalized.
- add_rbe2_geometrical(locators: Callable[[ndarray], ndarray] | Sequence[Callable[[ndarray], ndarray] | None], W: FunctionSpace)[source]#
Tie the dofs located geometrically rigidly to a point, as the RBE2 element of other codes (a rigid “spider”). See
add_rbe2_topological()for the relation.- Parameters:
locators – Marks the dofs tied to spider 0, given their coordinates, shape (3, num_points), or a sequence whose entry k marks the dofs tied to the spider with input index k. An entry may be None.
W – Space on the spider mesh, see
add_rbe2_topological()
Note
Collective. Must be called by every process, with the same number of locators.
- add_rbe2_topological(dim: int, entities: ndarray[tuple[Any, ...], dtype[int32]] | Sequence[ndarray[tuple[Any, ...], dtype[int32]] | None], W: FunctionSpace)[source]#
Tie the dofs on mesh entities rigidly to a point, as the RBE2 element of other codes (a rigid “spider”).
Each dof of this constraint’s space on the entities is a “foot” of a spider whose “body” is a point of the point mesh of W. Every component of a foot follows the motion of its body,
\[u(x) = t + \theta \times (x - x_c),\]where \(x_c\) is the coordinate of the dofs of W at the point, \(t\) its translation and \(\theta\) its rotation, the dofs of W at the point. Without rotations, \(u(x) = t\). All rotation terms are kept, also where their coefficient is zero, so
update_rbe2()can follow the motion of the meshes.- Parameters:
dim – Topological dimension of the entities
entities – Entities (local to the process) whose dofs are tied to spider 0, or a sequence whose entry k holds the entities tied to the spider with input index k (see
dolfinx_mpc.create_spider_mesh()). An entry may be None.W – Space on the spider mesh (
dolfinx_mpc.create_spider_mesh()). Its value size is the geometric dimension, for translations only, or 6 in 3D and 3 in 2D, for translations and rotations. W must be the space of another constraint finalized together with this one byfinalize_multipointconstraints().
Note
Collective. Must be called by every process, with the same number of entries in entities.
- add_rbe3_geometrical(V: FunctionSpace, locators: Callable[[ndarray], ndarray] | Sequence[Callable[[ndarray], ndarray] | None], weights: None | float | Callable[[ndarray], ndarray] = None)[source]#
Tie the dofs of spiders to the motion of the dofs of V located geometrically, as the RBE3 element of other codes. See
add_rbe3_topological()for the relation.- Parameters:
V – The space of the feet, with one component per dimension
locators – Marks the feet of spider 0, given their coordinates, shape (3, num_points), or a sequence whose entry k marks the feet of the spider with input index k. An entry may be None.
weights – See
add_rbe3_topological()
Note
Collective. Must be called by every process, with the same number of locators.
- add_rbe3_topological(V: FunctionSpace, dim: int, entities: ndarray[tuple[Any, ...], dtype[int32]] | Sequence[ndarray[tuple[Any, ...], dtype[int32]] | None], weights: None | float | Callable[[ndarray], ndarray] = None)[source]#
Tie the dofs of spiders to the motion of the dofs of V on mesh entities, as the RBE3 element of other codes (a flexible “spider”).
This constraint is on the space of the spider mesh (
dolfinx_mpc.create_spider_mesh()). Each spider moves with the rigid motion that best fits its “feet”, in the weighted least-squares sense,\[\min_{t, \theta} \sum_i w_i |u_i - t - \theta \times (x_i - x_c)|^2,\]where \(x_c\) is the coordinate of the spider, \(t\) and \(\theta\) its translation and rotation, and \(u_i\) the displacement of foot \(i\) at \(x_i\). Without rotations, \(t\) is the weighted mean of the feet. Unlike RBE2, the feet keep their stiffness: a load on the spider is spread over them without making them rigid.
The feet may be in several spaces, given by one call each. The constraint is built when it is finalized, by
finalize_multipointconstraints()together with the constraints of the spaces of the feet.- Parameters:
V – The space of the feet, with one component per dimension
dim – Topological dimension of the entities
entities – Entities (local to the process) whose dofs are feet of spider 0, or a sequence whose entry k holds those of the spider with input index k. An entry may be None.
weights – The weight of each foot: None for one, a number, or a function of the coordinates, shape (3, num_points), returning one non-negative weight per foot. Evaluated once, here:
update_rbe3()keeps the weights.
Note
Collective. Must be called by every process, with the same number of entries in entities.
- all_coefficients() Tuple[ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]], ndarray[tuple[Any, ...], dtype[int32]]][source]#
Returns the coefficients of all masters, including those eliminated by a Dirichlet condition, in the order supplied before
finalize(), and the offsets for the ith degree of freedom. This is the layout taken byupdate_coefficients(). The corresponding masters are given byall_masters().Examples
coeffs, offsets = mpc.all_coefficients() coeffs_of_slave_i = coeffs[offsets[i]:offsets[i+1]]
- all_masters() ndarray[tuple[Any, ...], dtype[int32]][source]#
Returns the masters (local index in
function_space) in the layout ofall_coefficients().
- backsubstitution(u: Function | Sequence[Function] | Vec) None[source]#
For a Function, impose the multi-point constraint by backsubstiution. This function is used after solving the reduced problem to obtain the values at the slave degrees of freedom
Note
It is the users responsibility to destroy the PETSc vector
- Parameters:
u – The input function. For a constraint with masters in another block, the function of every block, in the order given to
finalize_multipointconstraints(); only the function of this constraint’s block is changed. The ghosts of the functions holding masters must be up to date.
- property cell_to_slaves#
Returns an dolfinx.cpp.graph.AdjacencyList_int32 whose ith node corresponds to the ith cell (local to process), and links the corresponding slave degrees of freedom in the cell (local to process).
Examples
cell_to_slaves = mpc.cell_to_slaves() slaves_in_cell_i = cell_to_slaves.links(i)
- coefficients() ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]][source]#
Returns a vector containing the coefficients for the constraint, and the corresponding offsets for the ith degree of freedom.
Examples
coeffs, offsets = mpc.coefficients() coeffs_of_slave_i = coeffs[offsets[i]:offsets[i+1]]
- property constants: ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]]#
The constraint offset \(g\) for each degree of freedom local to the process, i.e. the affine term in \(x = K x_{red} + g\).
- create_contact_inelastic_condition(meshtags: MeshTags_int32, slave_marker: int, master_marker: int, eps2: float | None = None, allow_missing_masters: bool = False, num_threads: int | None = 1, *, distance_tol: float | None = None, coefficient_tol: float | None = None)[source]#
Create a contact inelastic condition between two sets of facets marker with individual markers. The interfaces should be within machine precision of eachother, but the vertices does not need to align. The condition created is \(u_s = u_m\) where s is the restriction to the slave facets, m to the master facets.
- Parameters:
meshtags – The meshtags of the set of facets to tie together
slave_marker – The marker of the slave facets
master_marker – The marker of the master facets
eps2 – Deprecated, use distance_tol, which is sqrt(eps2).
allow_missing_masters – If true, the function will not throw an error if a degree of freedom in the closure of the master entities does not have a corresponding set of slave degree of freedom.
num_threads – The number of threads to use for certain operations
distance_tol – The largest distance from a slave point to a master cell for the point to be in the cell, and the padding of the bounding boxes of the cells. Defaults to 500 machine epsilon of the coordinate type of the mesh.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest of its slave is dropped. 0 keeps every master. Defaults to 500 machine epsilon of the real type of the constraint.
- create_contact_slip_condition(meshtags: MeshTags, slave_marker: int, master_marker: int, normal: Function, eps2: float | None = None, num_threads: int | None = 1, *, distance_tol: float | None = None, coefficient_tol: float | None = None)[source]#
Create a slip condition between two sets of facets marker with individual markers. The interfaces should be within machine precision of eachother, but the vertices does not need to align. The condition created is \(u_s \cdot normal_s = u_m \cdot normal_m\) where s is the restriction to the slave facets, m to the master facets.
- Parameters:
meshtags – The meshtags of the set of facets to tie together
slave_marker – The marker of the slave facets
master_marker – The marker of the master facets
normal – The function used in the dot-product of the constraint
eps2 – Deprecated, use distance_tol, which is sqrt(eps2).
num_threads – The number of threads to use for certain operations
distance_tol – The largest distance from a slave point to a master cell for the point to be in the cell, and the padding of the bounding boxes of the cells. Defaults to 500 machine epsilon of the coordinate type of the mesh.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest of its slave is dropped. 0 keeps every master. Defaults to 500 machine epsilon of the real type of the constraint.
- create_general_constraint(slave_master_dict: Dict[bytes, Dict[bytes, float]], subspace_slave: int | None = None, subspace_master: int | None = None, *, distance_tol: float | None = None)[source]#
- Parameters:
V – The function space
slave_master_dict – Nested dictionary, where the first key is the bit representing the slave dof’s coordinate in the mesh. The item of this key is a dictionary, where each key of this dictionary is the bit representation of the master dof’s coordinate, and the item the coefficient for the MPC equation.
subspace_slave – If using mixed or vector space, and only want to use dofs from a sub space as slave add index here
subspace_master – Subspace index for mixed or vector spaces
distance_tol – The largest distance between the coordinate of a key and that of its dof. Defaults to 500 machine epsilon of the coordinate type of the mesh.
Example
If the dof D located at [d0, d1] should be constrained to the dofs E and F at [e0, e1] and [f0, f1] as \(D = \alpha E + \beta F\) the dictionary should be:
{numpy.array([d0, d1], dtype=mesh.geometry.x.dtype).tobytes(): {numpy.array([e0, e1], dtype=mesh.geometry.x.dtype).tobytes(): alpha, numpy.array([f0, f1], dtype=mesh.geometry.x.dtype).tobytes(): beta}}
- create_periodic_constraint_geometrical(V: ~dolfinx.fem.function.FunctionSpace, indicator: ~typing.Callable[[~numpy.ndarray], ~numpy.ndarray], relation: ~typing.Callable[[~numpy.ndarray], ~numpy.ndarray], bcs: ~typing.List[~dolfinx.fem.bcs.DirichletBC], scale: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | complex = 1.0, tol: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | None | ~dolfinx_mpc.container._Unset = <unset>, num_threads: int | None = 1, *, distance_tol: float | None = None, coefficient_tol: float | None = None)[source]#
Create a periodic condition for all degrees of freedom whose physical location satisfies \(indicator(x_i)==True\), i.e. \(u(x_i) = scale * u(relation(x_i))\) for all \(x_i\)
- Parameters:
V – The function space to assign the condition to. Should either be the space of the MPC or an uncollapsed subspace of it.
indicator – Lambda-function to locate degrees of freedom that should be slaves
relation – Lambda-function describing the geometrical relation to master dofs
bcs – Dirichlet boundary conditions for the problem (Periodic constraints will be ignored for these dofs)
scale – Factor of the masters, of the scalar type of the constraint
tol – Deprecated, use distance_tol and coefficient_tol: a value sets both, None sets coefficient_tol=0.
num_threads – The number of threads to use for certain operations.
distance_tol – The largest distance from a mapped slave point to a master cell for the point to be in the cell, and the padding of the bounding boxes of the cells. Defaults to 500 machine epsilon of the coordinate type of the mesh.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest of its slave is dropped. 0 keeps every master, so that the coefficients can later be changed with
scale_coefficients()orupdate_coefficients(). Defaults to 500 machine epsilon of the real type of the constraint.
- create_periodic_constraint_topological(V: ~dolfinx.fem.function.FunctionSpace, meshtag: ~dolfinx.mesh.MeshTags, tag: int, relation: ~typing.Callable[[~numpy.ndarray], ~numpy.ndarray], bcs: ~typing.List[~dolfinx.fem.bcs.DirichletBC], scale: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | complex = 1.0, tol: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | None | ~dolfinx_mpc.container._Unset = <unset>, num_threads: int | None = 1, *, distance_tol: float | None = None, coefficient_tol: float | None = None)[source]#
Create periodic condition for all closure dofs of on all entities in meshtag with value tag. \(u(x_i) = scale * u(relation(x_i))\) for all of \(x_i\) on marked entities.
- Parameters:
V –
- The function space to assign the condition to. Should either be the space of the MPC or an uncollapsed
subspace of it.
meshtag: MeshTag for entity to apply the periodic condition on
tag – Tag indicating which entities should be slaves
relation – Lambda-function describing the geometrical relation
bcs – Dirichlet boundary conditions for the problem (Periodic constraints will be ignored for these dofs)
scale – Factor of the masters, of the scalar type of the constraint
tol – Deprecated, use distance_tol and coefficient_tol: a value sets both, None sets coefficient_tol=0.
num_threads – The number of threads to use for certain operations
distance_tol – The largest distance from a mapped slave point to a master cell for the point to be in the cell, and the padding of the bounding boxes of the cells. Defaults to 500 machine epsilon of the coordinate type of the mesh.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest of its slave is dropped. 0 keeps every master, so that the coefficients can later be changed with
scale_coefficients()orupdate_coefficients(). Defaults to 500 machine epsilon of the real type of the constraint.
- create_slip_constraint(space: FunctionSpace, facet_marker: Tuple[MeshTags, int], v: Function, bcs: List[DirichletBC] = [])[source]#
Create a slip constraint \(u \cdot v=0\) over the entities defined in facet_marker with the given index.
- Parameters:
space – Function space (possibly an uncollapsed subspace) for the current constraint
facet_marker – Tuple containomg the mesh tag and marker used to locate degrees of freedom
v – Function containing the directional vector to dot your slip condition (most commonly a normal vector)
bcs – List of Dirichlet BCs (slip conditions will be ignored on these dofs)
Examples
Create constaint \(u\cdot n=0\) of all indices in mt marked with i
V = dolfinx.fem.functionspace(mesh, ("CG", 1)) mpc = MultiPointConstraint(V) n = dolfinx.fem.Function(V) mpc.create_slip_constaint(V, (mt, i), n)
Create slip constaint for a mixed function space:
cellname = mesh.basix_cell() Ve = basix.ufl.element(basix.ElementFamily.P, cellname , 2, shape=(mesh.geometry.dim,)) Qe = basix.ufl.element(basix.ElementFamily.P, cellname , 1) me = basix.ufl.mixed_element([Ve, Qe]) W = dolfinx.fem.functionspace(mesh, me) mpc = MultiPointConstraint(W) n_space, _ = W.sub(0).collapse() normal = dolfinx.fem.Function(n_space) mpc.create_slip_constraint(W.sub(0), (mt, i), normal, bcs=[])
A slip condition cannot be applied on the same degrees of freedom as a Dirichlet BC, and therefore any Dirichlet bc for the space of the multi point constraint should be supplied.
cellname = mesh.basix_cell() Ve = basix.ufl.element(basix.ElementFamily.P, cellname , 2, shape=(mesh.geometry.dim,)) Qe = basix.ufl.element(basix.ElementFamily.P, cellname , 1) me = basix.ufl.mixed_element([Ve, Qe]) W = dolfinx.fem.functionspace(mesh, me) mpc = MultiPointConstraint(W) n_space, _ = W.sub(0).collapse() normal = Function(n_space) bc = dolfinx.fem.dirichletbc(inlet_velocity, dofs, W.sub(0)) mpc.create_slip_constraint(W.sub(0), (mt, i), normal, bcs=[bc])
- create_submesh_constraint(V: ~dolfinx.fem.function.FunctionSpace, master_space: ~dolfinx.fem.function.FunctionSpace, entity_map: ~dolfinx.mesh.EntityMap, bcs: ~typing.List[~dolfinx.fem.bcs.DirichletBC] | None = None, scale: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | complex = 1.0, tol: ~numpy.float32 | ~numpy.float64 | ~numpy.complex128 | ~numpy.complex64 | float | None | ~dolfinx_mpc.container._Unset = <unset>, num_threads: int = 1, *, coefficient_tol: float | None = None)[source]#
Tie the degrees of freedom of V to master_space on a related mesh: a submesh and its parent, related by entity_map as returned by
dolfinx.mesh.create_submesh().Every degree of freedom of V in the closure of a cell related to a cell of master_space becomes a slave, \(u(x_i) = \mathrm{scale}\, u_m(x_i)\), with \(u_m\) evaluated in the related cell and component b tied to component b. With V on the submesh this is every degree of freedom of V, for instance the trace \(\bar u = u|_\Gamma\) on a submesh of facets; with V on the parent it is the degrees of freedom on the submesh. No search is involved: the related cell is a table lookup. For a submesh of facets the parent cell is one attached to the facet, so for a discontinuous master_space the side is arbitrary.
- Parameters:
V – The space of the constraint, or an uncollapsed subspace of it
master_space – The space of another constraint finalized together with this one by
finalize_multipointconstraints(), or an uncollapsed subspace of it. Its mesh and the mesh of V are the two meshes of entity_map, either way round.entity_map – Relates the cells of the submesh to entities of the parent, of codimension 0 or 1
bcs – Dirichlet conditions on the space of the constraint. Their degrees of freedom are not made slaves.
scale – Factor of the masters, of the scalar type of the constraint
tol – Deprecated, use coefficient_tol: a value sets it, None sets coefficient_tol=0.
num_threads – The number of threads to use
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest of its slave is dropped. 0 keeps every basis function of the related cell, so that the coefficients can later be changed with
scale_coefficients()orupdate_coefficients(). Defaults to 500 machine epsilon of the real type of the constraint. No distance tolerance is needed, as the related cell is not searched for.
- Raises:
ValueError – If entity_map does not relate the two meshes, relates entities other than the cells of the submesh, is of codimension above 1, or the spaces have different numbers of components. Raised on every process.
Note
Collective.
- property dtype: type#
The scalar type of the coefficients, also that of everything built from the constraint.
- extend_masters(slaves: ndarray[tuple[Any, ...], dtype[int32]], masters: ndarray[tuple[Any, ...], dtype[int64]], coeffs: ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]], owners: ndarray[tuple[Any, ...], dtype[int32]], master_space: FunctionSpace | None = None)[source]#
Add a master to the rows of existing slaves.
A row is the equation \(u_s = \sum_j c_j u_{m_j}\) of its slave \(u_s\), whichever constraint made it. Entry i adds a term \(k u_d\) to its right-hand side, giving \(u_s = \sum_j c_j u_{m_j} + k u_d\), with \(s\) = slaves[i], \(u_d\) = masters[i] and \(k\) = coeffs[i]. If \(u_d\) is already a master of the row, in the same space, \(k\) is added to its coefficient. The ghost copies of the rows are extended too.
A call adds one term per slave. Further terms of the same slave are added by further calls, each with its own master_space, so that a row may have masters in several spaces.
For instance, a periodic condition \(u(x) = u(\mathrm{relation}(x))\) extended, by one call per entry \(\bar H_{bk}\) of a macroscopic gradient on a point mesh, with coefficient \(d_k = (x - \mathrm{relation}(x))_k\) for component \(b\), ties u to \(\bar H x\) plus a periodic field.
- Parameters:
slaves – The slave of each entry: owned dofs of the space of the constraint (local, unrolled), each already a slave and each at most once.
masters – The master of each entry, in the global (unrolled) numbering of master_space
coeffs – The coefficient of each entry, of the scalar type of the constraint
owners – The process owning each master
master_space – The space of the masters if not that of the constraint. It must be the space of another constraint finalized together with this one by
finalize_multipointconstraints(), or an uncollapsed subspace of it.
- Raises:
ValueError – On every process, if a slave is not owned, appears twice or has no row yet, or the arrays differ in length.
Note
Collective. Must be called by every process, with the same master_space, before the constraint is finalized.
- finalize(filter: floating | None = None) None[source]#
Finializes the multi point constraint. After this function is called, no new constraints can be added to the constraint. This function creates a map from the cells (local to index) to the slave degrees of freedom and builds a new index map and function space where unghosted master dofs are added as ghosts.
- Parameters:
filter – If given, discard every master whose coefficient satisfies \(|c_{sj}| < \mathrm{filter}\cdot\max_k|c_{sk}|\), the maximum being over the masters of that same slave. A negligible coefficient contributes nothing to the constraint, but still costs a ghost, a row of the sparsity pattern and an entry in every element matrix modification, so removing them can shrink \(K^HAK\) substantially. With None (the default) every master supplied is kept.
Note
Filtering changes the constraint that is enforced, by exactly the terms that are dropped. It is local and adds no communication.
Note
To finalize the constraints of several function spaces, for instance the blocks of a
ufl.MixedFunctionSpace, usefinalize_multipointconstraints().
- property function_space#
Return the function space for the multi-point constraint with the updated index map
- property has_cross_block_masters: bool#
Whether a master on any process is in another block than the slaves.
- property has_inhomogeneity: bool#
Whether any process carries a non-zero constraint offset. The value is globally reduced, so it is identical on every process.
- homogenize(u: Function) None[source]#
For a vector, homogenize (set to zero) the vector components at the multi-point constraint slave DoF indices. This is particularly useful for nonlinear problems.
- Parameters:
u – The input vector
- property input_space: FunctionSpace#
The function space the constraint was created with.
Forms and Dirichlet conditions are stated on this space, while functions holding a solution live in
function_space, its extension by the masters of the constraint. For a system of several blocks,[mpc.input_space for mpc in mpcs]gives the spaces in the order of the blocks, for instance for aufl.MixedFunctionSpace.
- property is_slave: ndarray#
Returns a vector of integers where the ith entry indicates if a degree of freedom (local to process) is a slave.
- property master_blocks: ndarray[tuple[Any, ...], dtype[int32]]#
the position, in the list given to
finalize_multipointconstraints(), of the constraint whose space the master is in. The local index of a master is in the space of its block.- Type:
The block of each master, parallel to
masters.array
- property masters: AdjacencyList_int32#
Returns an adjacency-list whose ith node corresponds to a degree of freedom (local to process), and links the corresponding master dofs (local to process).
Examples
masters = mpc.masters masters_of_dof_i = masters.links(i)
- property num_local_slaves#
Return the number of slaves owned by the current process.
- scale_coefficients(scale: float32 | float64 | complex128 | complex64 | float | complex | Expr | Expression) None[source]#
Multiply the coefficients of all masters of each slave \(s\) by a factor \(f_s\), and recompute the constraint offset \(g\). For a periodic constraint \(u(x_s) = f_s u(relation(x_s))\), which for instance gives a Floquet-Bloch condition with \(f=e^{i k\cdot L}\).
The factors are stored in a function in the space of the constraint, and \(f_s\) is the degree of freedom \(s\) of that function: the value at the slave for a Lagrange space, the corresponding moment for e.g. a Nédélec space.
Repeated calls compound. Masters eliminated by a Dirichlet condition are scaled as well, the user supplied rhs_coeffs are not.
- Parameters:
scale – A scalar, a
dolfinx.fem.Functionin the constraint’s space (copied by interpolation), a UFL expression, compiled into adolfinx.fem.Expressionat the interpolation points of the space, or such a compiled expression. Pass a compiled expression to avoid recompilation when the factor is updated throughdolfinx.fem.Constant’s in it.
Note
Collective. Must be called by every process.
- property slaves#
Returns the degrees of freedom for all slaves local to process
- update_coefficients(coeffs: ndarray[tuple[Any, ...], dtype[float32]] | ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex64]] | ndarray[tuple[Any, ...], dtype[complex128]]) None[source]#
Replace the coefficient of every master, including masters eliminated by a Dirichlet condition, and recompute the constraint offset \(g\).
The masters are fixed at creation. A master dropped by coefficient_tol or by the filter of
finalize()cannot be given a coefficient, so create the constraint with coefficient_tol=0 and no filter if the coefficients are to be changed.- Parameters:
coeffs – The new coefficients, in the layout of
all_coefficients(), for all degrees of freedom local to the process (owned and ghost).
Note
Collective. Must be called by every process.
- update_constants() None[source]#
Recompute the constraint offset \(g\) from the current values of the Dirichlet conditions supplied to the constructor.
Call this whenever the value of one of those conditions changes, for instance between time steps, before re-assembling.
LinearProblemcalls it automatically.Note
Collective. Must be called by every process.
- update_rbe2() None[source]#
Recompute the coefficients of every RBE2 constraint from the current coordinates.
The feet are at the dof coordinates of the constraint’s space, the spiders at those of the space on the spider mesh, both read now. Move the meshes, for instance to the deformed configuration in an updated Lagrangian analysis, then call this to tie the feet to the rigid motion about the new positions. Assemble again afterwards.
The constraint must be finalized without a filter, which could drop a master whose coefficient becomes nonzero.
Note
Collective. Must be called by every process.
- update_rbe3() None[source]#
Recompute the coefficients of the RBE3 constraint from the current coordinates.
The feet are at the dof coordinates of their spaces, the spiders at those of the space of this constraint, both read now. Move the meshes, then call this. Assemble again afterwards.
Note
Collective. Must be called by every process.
- class dolfinx_mpc.NonlinearProblem(F: Form | Sequence[Form], u: Function | Sequence[Function], mpc: MultiPointConstraint | Sequence[MultiPointConstraint], bcs: Sequence[DirichletBC] | None = None, J: Form | Sequence[Sequence[Form]] | None = None, P: Form | Sequence[Sequence[Form]] | None = None, kind: str | Sequence[Sequence[str]] | None = None, form_compiler_options: dict | None = None, jit_options: dict | None = None, petsc_options_prefix: str = 'dolfinx_mpc_nonlinear_problem_', petsc_options: dict | None = None, entity_maps: Sequence[EntityMap] | None = None)[source]#
- dolfinx_mpc.apply_lifting(b: Vec, form: Sequence[Sequence[Form | None]] | Sequence[Form | None], bcs: Sequence[DirichletBC] | Sequence[Sequence[DirichletBC]], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], x0: Sequence[Vec] | None = None, scale: float32 | float64 | complex128 | complex64 = np.float64(1.0), num_threads: int | None = 1, bc_data: BCData | None = None)[source]#
Apply lifting of Dirichlet conditions to the vector b.
For a single vector,
\[b \leftarrow b - \mathrm{scale}\, K^T \sum_j A_j (g_j - x0_j),\]where \(A_j\) is assembled from form[j], \(g_j\) holds the Dirichlet values on its trial space and \(K\) is the reduction matrix of constraint. For a nest vector, block row \(i\) is
\[b_i \leftarrow b_i - \mathrm{scale}\, K_i^T \sum_j A_{ij} (g_j - x0_j),\]where \(A_{ij}\) is assembled from form[i][j] and \(K_i\) is the reduction matrix of constraint[i]. A None form is skipped.
- Parameters:
b – PETSc vector to assemble into
form – The bilinear forms, form[j] (single vector) or form[i][j] (nest vector) as above
bcs – List of Dirichlet boundary conditions. A condition contributes to \(g_j\) if it is defined on the trial space of column j or a subspace of it, so the conditions may be given per block or as one flat list.
constraint – The multi point constraint
x0 – List of vectors
scale – Scaling for lifting
num_threads – The number of threads to use for certain operations
bc_data – A
BCDatacache. Built from bcs when not supplied; pass one to reuse the dof markers across calls.
- dolfinx_mpc.apply_mpc_lifting(b: Vec, form: Sequence[Form], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], constraint1: Sequence[MultiPointConstraint] | None = None, scale: float32 | float64 | complex128 | complex64 = np.float64(1.0), num_threads: int | None = 1)[source]#
Lift the inhomogeneity of a multi point constraint into the vector b, i.e.
\(b = b - scale \cdot K^T (A_j g_j)\)
where \(g\) is the constraint offset of the constraint on the trial space. This is the term arising in \(K^T A K x_{red} = K^T (b - A g)\) for the affine constraint \(x = K x_{red} + g\), and is a no-op for a homogeneous constraint.
Note
Only required when solving directly for \(x_{red}\). A residual assembled at an iterate that already satisfies the constraint contains \(K^T A g\) already, so the Newton/SNES path must not call this.
- Parameters:
b – PETSc vector to assemble into
form – The bilinear forms, one per block column
constraint – The multi point constraint for the rows of b
constraint1 – The multi point constraints for the columns, one per block. Defaults to constraint, which is correct for a square problem.
scale – Scaling for lifting
num_threads – The number of threads to use for certain operations
- dolfinx_mpc.assemble_jacobian_mpc(u: Sequence[Function] | Function, jacobian: Form | Sequence[Sequence[Form | None]], preconditioner: Form | Sequence[Sequence[Form | None]] | None, bcs: Iterable[DirichletBC], mpc: MultiPointConstraint | Sequence[MultiPointConstraint], bc_data: BCData, _snes: SNES, x: Vec, J: Mat, P: Mat, _blocks: tuple[tuple[int, ...], tuple[int, ...]] | None = None)[source]#
Assemble the Jacobian matrix and preconditioner.
A function conforming to the interface expected by SNES.setJacobian can be created by fixing the first four arguments:
- functools.partial(assemble_jacobian, u, jacobian, preconditioner,
bcs)
- Parameters:
u – Function tied to the solution vector within the residual and jacobian
jacobian – Form of the Jacobian
preconditioner – Form of the preconditioner
bcs – List of Dirichlet boundary conditions
mpc – The multi point constraint or a sequence of multi point
bc_data – Dof marker and diagonal row cache, built once by the caller so that every Newton iteration reuses it. The Jacobian and the preconditioner share it: entries are keyed by function space, and the two forms are over the same spaces.
_snes – The solver instance
x – The vector containing the point to evaluate at
J – Matrix to assemble the Jacobian into
P – Matrix to assemble the preconditioner into
_blocks – For a monolithic system of several blocks, the offsets of its blocks, see
dolfinx_mpc.create_vector(). SNES may pass a vector other than the one the problem created, so they are set on x here.
- dolfinx_mpc.assemble_matrix(form: Form | Sequence[Sequence[Form | None]], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], bcs: Sequence[DirichletBC] | None = None, diagval: float64 = 1, A: Mat | None = None, num_threads: int | None = 1, bc_data: BCData | None = None, kind: str | Sequence[Sequence[str | None]] | None = None) Mat[source]#
Assemble a compiled DOLFINx bilinear form, or an array of them, into a PETSc matrix with corresponding multi point constraints and Dirichlet boundary conditions.
As in
dolfinx.fem.petsc.assemble_matrix(), the kind of matrix is selected by kind, or by the type of A if it is supplied.- Parameters:
form – The compiled bilinear variational form, or a rank 2 list of them with None for a block without a form
constraint – For a single form, its multi point constraint, or for a rectangular form a list of 2 constraints on axis 0 & 1. For an array of forms, the constraint of each block, which is used for the rows and the columns.
bcs – Sequence of Dirichlet boundary conditions
diagval – Value to set on the diagonal of the matrix
A – PETSc matrix to assemble into. Assembly is additive, so A is not zeroed; call A.zeroEntries() first to discard its contents. If not supplied a new matrix is created, which is already zeroed.
num_threads – The number of threads to use for certain operations
bc_data – A
BCDatacache. Built from bcs when not supplied; pass one to share it with the other assemblies of the same system.kind – The kind of matrix to create when A is not supplied, see
create_matrix().
- Returns:
The matrix with the assembled bi-linear form #type: ignore
- Return type:
_PETSc.Mat
- dolfinx_mpc.assemble_matrix_nest(A: Mat, a: Sequence[Sequence[Form | None]], constraints: Sequence[MultiPointConstraint], bcs: Sequence[DirichletBC] = [], diagval: float64 = 1, num_threads: int | None = 1, bc_data: BCData | None = None)[source]#
Assemble a compiled DOLFINx bilinear form into a PETSc matrix of type “nest” with corresponding multi point constraints and Dirichlet boundary conditions.
Deprecated since version Use:
assemble_matrix(), which selects the layout from A.- Parameters:
A – PETSc matrix to assemble into. Assembly is additive, so A is not zeroed; call A.zeroEntries() first to discard its contents.
a – The compiled bilinear variational form provided in a rank 2 list
constraints – An ordered list of multi point constraints
bcs – Sequence of Dirichlet boundary conditions
diagval – Value to set on the diagonal of the matrix (Default 1)
num_threads – The number of threads to use for certain operations
bc_data – A
BCDatacache. Built from bcs when not supplied; pass one to share it with the other assemblies of the same system.
- dolfinx_mpc.assemble_residual_mpc(u: Function | Sequence[Function], residual: Form | Sequence[Form], jacobian: Form | Sequence[Sequence[Form]], bcs: Sequence[DirichletBC], mpc: MultiPointConstraint | Sequence[MultiPointConstraint], bc_data: BCData, _snes: SNES, x: Vec, F: Vec, _blocks: tuple[tuple[int, ...], tuple[int, ...]] | None = None)[source]#
Assemble the residual into the vector F.
A function conforming to the interface expected by SNES.setResidual can be created by fixing the first four arguments:
- functools.partial(assemble_residual, u, jacobian, preconditioner,
bcs)
- Parameters:
u – Function(s) tied to the solution vector within the residual and Jacobian.
residual – Form of the residual. It can be a sequence of forms.
jacobian – Form of the Jacobian. It can be a nested sequence of forms.
bcs – List of Dirichlet boundary conditions.
mpc – The multi point constraint or a sequence of multi point constraints.
bc_data – Dof marker cache shared with the Jacobian, built once by the caller so that every Newton iteration reuses it.
_snes – The solver instance.
x – The vector containing the point to evaluate the residual at.
F – Vector to assemble the residual into.
_blocks – For a monolithic system of several blocks, the offsets of its blocks, see
dolfinx_mpc.create_vector(). A line search evaluates the residual in vectors duplicated from the one given to SNES, so they are set on x and F here.
- dolfinx_mpc.assemble_vector(form: Form | Sequence[Form], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], b: Vec | None = None, num_threads: int | None = 1, kind: str | Sequence[Sequence[str | None]] | None = None) Vec[source]#
Assemble a linear form, or a sequence of them, into vector b with the corresponding multi point constraints. The kind of vector is selected by kind, or by the type of b if it is supplied.
- Parameters:
form – The linear form, or a sequence of them, one per block
constraint – The multi point constraint, or one per block
b – PETSc vector to assemble into. Assembly is additive, so b is not zeroed; use dolfinx.la.petsc._zero_vector first to discard its contents. If not supplied a new, zeroed vector is created.
num_threads – The number of threads to use for certain operations
kind – The kind of vector to create when b is not supplied, see
create_vector().
- Returns:
The vector with the assembled linear form (b if supplied)
- dolfinx_mpc.assemble_vector_nest(b: Vec, L: Sequence[Form], constraints: Sequence[MultiPointConstraint], num_threads: int | None = 1)[source]#
Assemble a linear form into a PETSc vector of type “nest”
Deprecated since version Use:
assemble_vector(), which selects the layout from b.- Parameters:
b – A PETSc vector of type “nest” to assemble into. Assembly is additive, so b is not zeroed; use dolfinx.la.petsc._zero_vector first to discard its contents.
L – A sequence of linear forms
constraints – An ordered list of multi point constraints
- dolfinx_mpc.create_integral_constraint(V: FunctionSpace, weight_form: Form, value: floating | complexfloating | float | complex, bcs: Sequence[DirichletBC] | None = None, rtol: floating | float | None = None, *, coefficient_tol: floating | float | None = None) tuple[ndarray[tuple[Any, ...], dtype[int32]], ndarray[tuple[Any, ...], dtype[int64]], ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[int32]], ndarray[tuple[Any, ...], dtype[int32]], Function][source]#
Build the constraint data enforcing a scalar integral condition.
A linear functional \(L\) applied to \(u_h=\sum_i u_i\phi_i\) is a single linear equation between all the coefficients,
\[L(u_h) = \sum_i w_i u_i = \gamma, \qquad w_i = L(\phi_i),\]where \(w\) is the assembled vector of
weight_form. Solving it for one degree of freedom \(s\) gives the affine relation\[u_s = \sum_{i \neq s} \left(-\frac{w_i}{w_s}\right) u_i + \frac{\gamma}{w_s},\]that is a constraint with a single slave, every other degree of freedom in the support of the functional as a master, and the inhomogeneity \(\gamma/w_s\). Typical uses are fixing the mean value of a solution, \(\int_\Omega u~\mathrm{d}x = \gamma\), which makes a pure Neumann problem non-singular, or prescribing a boundary average or a flow rate, \(\int_\Gamma u\cdot n~\mathrm{d}s = \gamma\), without prescribing the profile that carries it.
- Parameters:
V – The function space the constraint acts on.
weight_form – A linear form in
ufl.TestFunction(V)defining the functional, for instancev * ufl.dxorufl.dot(v, n) * ds(tag).value – The prescribed value \(\gamma\) of the functional.
bcs – Dirichlet conditions on
V. A constrained degree of freedom is never chosen as the slave, but may still appear as a master, in which case passing the same conditions toMultiPointConstraintfolds its contribution into the constraint offset.rtol – Deprecated, use coefficient_tol.
coefficient_tol – A master whose coefficient is below coefficient_tol times the largest one is dropped. The weights of degrees of freedom outside the support of the functional are returned by quadrature as roundoff rather than as exact zeros, so the threshold is relative rather than a test against zero. Defaults to 500 machine epsilon of the real type of the scalar type: a threshold tight enough for float64 roundoff is far below float32 roundoff, and would then discard nothing, inflating the master count and the conditioning of the reduced operator.
- Returns:
The
slaves,masters,coeffs,ownersandoffsetsarrays accepted byMultiPointConstraint.add_constraint(), and adolfinx.fem.Functionholding the inhomogeneity, to be passed toMultiPointConstraintasrhs_coeffs.
Note
Collective. Every process contributes its owned weights to the slave’s owner, which is the only one that needs the whole functional; the owner then reduces them to the (generally far smaller) list of significant masters and forwards that, not the raw weights, to any process ghosting the slave. Those are the only processes that declare the constraint.
- dolfinx_mpc.create_matrix(a: Form | Sequence[Sequence[Form | None]], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], kind: str | Sequence[Sequence[str | None]] | None = None) Mat[source]#
Create a PETSc matrix with the sparsity pattern of a bilinear form, or an array of them, under multi point constraints.
As in
dolfinx.fem.petsc.create_matrix(), three cases are supported:A single form gives a matrix of the PETSc type kind, the default if None.
An array of forms with kind
"nest", or a nested sequence of PETSc matrix types of the same shape as the array, gives a matrix of typenestwhose blocks have those types.An array of forms with any other kind gives a single, monolithic matrix of PETSc type kind, the default if None or
"mpi", arranged as \(A = [a_{ij}]\) with the dofs of each block ordered[owned, ghosts]and the blocks one after another. The ghosts include the masters added by the constraint of the block. A diagonal block that has no form still reserves the diagonal entry of each of its slaves.
- Parameters:
a – The compiled bilinear form, or a rank 2 list of them with None for a block without a form
constraint – As in
assemble_matrix()kind – The kind of matrix, as above
- Returns:
The matrix, to assemble into with
assemble_matrix().
- dolfinx_mpc.create_matrix_nest(a: Sequence[Sequence[Form | None]], constraints: Sequence[MultiPointConstraint])[source]#
Create a PETSc matrix of type “nest” with appropriate sparsity pattern given the provided multi points constraints
Deprecated since version Use:
create_matrix()withkind="nest".- Parameters:
a – The compiled bilinear variational form provided in a rank 2 list constraints: An ordered list of multi point constraints
- dolfinx_mpc.create_sparsity_pattern(form: Form, mpc: MultiPointConstraint | Sequence[MultiPointConstraint])[source]#
Create sparsity-pattern for MPC given a compiled DOLFINx form
- Parameters:
form – The form
mpc – For square forms, the MPC. For rectangular forms a list of 2 MPCs on axis 0 & 1, respectively
- dolfinx_mpc.create_spider_mesh(comm: Comm, points: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], dtype: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None = None) Mesh[source]#
Create the point mesh holding the bodies of spiders.
The points are given on the first process. Every other process passes either no points or the same points. Spider k is the point in row k, its input index; coinciding points are distinct spiders, for instance two spiders joined by a spring. The points are spread over the processes as the post office splits an index range: of M points, process r owns those in
dolfinx.common.local_range(r, M, size). Spider k of any two spider meshes of M points is therefore on the same process.- Parameters:
comm – The communicator of the meshes the spiders join
points – The points, shape (num_points, 3), on the first process. On the others, no points or the same points.
dtype – The coordinate type of the mesh. Defaults to the type of the first process’s points, or the default real type if they are not floating point.
- Returns:
A mesh of points, from
dolfinx.mesh.create_point_mesh().- Raises:
ValueError – If a process passes points other than those of the first process. Raised on every process.
Note
Collective.
- dolfinx_mpc.create_spider_pair(spiders_A: Mesh, spiders_B: Mesh) EntityMap[source]#
Relate spider k of one spider mesh to spider k of another, for every k.
The pairs are, for instance, the two ends of springs: order the points of the two meshes so that row k of each holds the two ends of spring k. A form coupling the spaces on the two meshes, such as a spring \(\int K (w_A - w_B) \cdot (v_A - v_B)\), is integrated over spiders_A with the returned map in entity_maps. Each mesh keeps its own geometry, so the two spiders of a pair may start at the same point and move apart.
Both meshes must have the same number of spiders.
create_spider_mesh()then puts spider k of both on the same process.- Parameters:
spiders_A – The spider mesh integrated over
spiders_B – The other spider mesh
- Returns:
The entity map with spiders_A as topology and spiders_B as sub-topology.
- Raises:
ValueError – If the meshes have different numbers of spiders, or spider k of the two is on different processes, as for a point mesh not made by
create_spider_mesh(). Raised on every process.
Note
Collective.
- dolfinx_mpc.create_vector(L: Form | Sequence[Form], constraint: MultiPointConstraint | Sequence[MultiPointConstraint], kind: str | Sequence[Sequence[str | None]] | None = None) Vec[source]#
Create a PETSc vector appropriate for a linear form, or a sequence of them, under multi point constraints.
As in
dolfinx.fem.petsc.create_vector(), a single form gives a ghosted vector, while a sequence of forms with kind"nest", or a nested sequence of matrix types, gives a vector of typenestand any other kind a single, monolithic vector. On each process the monolithic vector is[b_0, b_1, ..., b_n, b_0g, b_1g, ..., b_ng], whereb_iholds the owned entries of blockiandb_igits ghosts, which include the masters added by the constraint. The offsets of the blocks are in the attribute_blocks, seedolfinx.la.petsc.create_vector().- Parameters:
L – A linear form, or a sequence of them, one per block
constraint – The multi point constraint, or one per block
kind – The kind of vector, as above
- Returns:
A PETSc vector, not initialised to zero.
- dolfinx_mpc.create_vector_nest(L: Sequence[Form], constraints: Sequence[MultiPointConstraint]) Vec[source]#
Create a PETSc vector of type “nest” appropriate for the provided multi point constraints
Deprecated since version Use:
create_vector()withkind="nest".- Parameters:
L – A sequence of linear forms
constraints – An ordered list of multi point constraints
- Returns:
A PETSc vector of type “nest” #type: ignore
- Return type:
PETSc.Vec
- dolfinx_mpc.dofs_at_point(V: FunctionSpace, point: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], distance_tol: float | None = None) tuple[ndarray[tuple[Any, ...], dtype[int64]], int][source]#
The global dofs of the block of V at a point, and the process owning them.
The dofs are in the global, unrolled numbering of the space V is an uncollapsed subspace of (or of V), as masters are given to
MultiPointConstraint.add_constraint()andMultiPointConstraint.extend_masters(): one per component of V. Works for a space on a point mesh too.- Parameters:
V – The function space, or an uncollapsed subspace of it
point – The point, of gdim or 3 coordinates
distance_tol – The largest distance from the point to the dof. Defaults to 500 machine epsilon of the coordinate type of the mesh.
- Returns:
The dofs, one per component, and the owning process. The same on every process.
- Raises:
ValueError – On every process, unless exactly one block of dofs of V is at the point: none, or several, as in a discontinuous space or on a point mesh with coinciding points.
Note
Collective.
- dolfinx_mpc.finalize_multipointconstraints(mpcs: Sequence[MultiPointConstraint], filter: floating | None = None) None[source]#
Finalize the multi point constraints of several function spaces together.
Entry
kofmpcsconstrains its own function space, for instance thek-th block of aufl.MixedFunctionSpace. Each is finalized as byMultiPointConstraint.finalize(), but the checks that need communication are reduced once for all of them, and the meshes of the spaces may be distinct, as long as they live on congruent communicators.- Parameters:
mpcs – The constraints to finalize. None may be finalized already, and they must all use the same
dtype.filter – See
MultiPointConstraint.finalize(). Applied to every constraint.
- Raises:
ValueError – If the input is inconsistent, or if a dof is both a slave and constrained by a Dirichlet condition, a master is also a slave, or the meshes are on communicators of different size or rank order. Raised on every process.
Note
Collective. Must be called by every process, with the constraints in the same order.
- dolfinx_mpc.spider_values(u: Function, spider: int) ndarray[source]#
The values of a function on a spider mesh at one spider, on every process.
A process only holds a spider’s values if it owns the spider’s dofs or has feet tied to it, so the owner broadcasts them.
- Parameters:
u – A function on a space of a mesh from
create_spider_mesh()spider – The input index of the spider
- Returns:
The values at the spider, one per component of the space.
Note
Collective.