Block Solver
This function builds a block preconditioner P for ksp solve of matrix A:
Let ksp(A, P) means a Krylov solve of matrix A with preconditioner P
Define a block matrix system A as
A = [ A00, A01
A10, A11 ]
Composite type options are:
additive: P = [ksp(A00,Ap00), 0
0 , ksp(A11,Ap11)]
multiplicative: P = J.K.L
where J = [I, 0
0, ksp(A11,Ap11)]
K = [0, 0 + [ I , 0 *[I, 0 (see PETSc's doc page for details here)
0, I] -A10, -A11] 0, 0]
L = [ksp(A00,Ap00), 0
0 , I]
symmetric_multiplicative: (see PETSc's doc page. This is too big)
schur: (schur complement decomposition, see doc page)
- class flatiron_tk.solver.block_solver.BlockNonLinearSolver(*args: Any, **kwargs: Any)[source]
Bases:
NonLinearSolver- default_set_ksp0(ksp)[source]
Default KSP setup function for the root block in the block split tree. This is a placeholder and can be customized as needed.
- class flatiron_tk.solver.block_solver.BlockSplitNode[source]
Bases:
objectA node in the block split tree for managing block preconditioners.
- get_field_tags()[source]
Get the field tags associated with this node.
Returns:
tuple: A tuple of field tags.
- get_ksp()[source]
Get the KSP (Krylov Subspace Solver) associated with this node.
Returns:
PETSc.KSP: The KSP object for this node.
- get_node_tag()[source]
Get the tag of this node, which is a string concatenation of field tags.
Returns:
str: The node tag.
- insert_node(child_node, position)[source]
Insert a child node at the specified position (‘left’ or ‘right’).
Parameters:
node (BlockSplitNode): The node to insert. position (str): The position to insert the node (‘left’ or ‘right’).
- is_root()[source]
Check if this node is the root node.
Returns:
bool: True if this node is the root, False otherwise.
- set_IS(IS)[source]
Set the PETSc Index Set for this node.
Parameters:
IS (PETSc.IS): The Index Set to set.
- set_field_tags(fields)[source]
Set the field names for this node. Each field name is equivalent to the tag of a PhysicsProblem in the flatiron_tk framework
Parameters:
fields (Iterable[str]): An iterable of field tags (physics tags) to set.
Sets:
_field_tags (tuple): A tuple of field names. _node_tag (str): A string that concatenates the field names with an underscore.
- class flatiron_tk.solver.block_solver.BlockSplitTree(physics, splits)[source]
Bases:
objectA class to manage a block split tree for building block preconditioners.
- Parameters:
(PhysicsProblem) (physics)
Iterable[dict]) (splits (dict or) –
splits. Each dictionary should have the following keys:
’fields’: A list of two lists, each containing field tags to be grouped together.
- ’composite_type’: The type of composite preconditioner to use (‘additive’, ‘multiplicative’,
’symmetric_multiplicative’, ‘schur’, ‘special’).
- ’schur_fact_type’ (optional): The Schur factorization type if ‘composite_type’ is ‘schur’
(‘diag’, ‘full’, ‘lower’, ‘upper’).
- ’schur_pre_type’ (optional): The Schur preconditioner type if ‘composite_type’ is ‘schur’
(‘a11’, ‘full’, ‘self’, ‘selfp’, ‘user’).
’ksp0_set_function’ (optional): A function to set up the KSP for the first block.
’ksp1_set_function’ (optional): A function to set up the KSP for the second block.
- build_block_split_pc(blocks_0, blocks_1, is0_data, is1_data, composite_type='additive', schur_fact_type='full', schur_pre_type='a11')[source]
Build the block split preconditioner for the given blocks.
- Parameters:
(Iterable[str]) (blocks_1)
(Iterable[str])
(tuple) (is1_data)
(tuple)
(str) (schur_pre_type) – Options: ‘additive’, ‘multiplicative’, ‘symmetric_multiplicative’, ‘schur’, ‘special’. Default is ‘additive’.
(str) – is ‘schur’. Options: ‘diag’, ‘full’, ‘lower’, ‘upper’. Default is ‘full’.
(str) – is ‘schur’. Options: ‘a11’, ‘full’, ‘self’, ‘selfp’, ‘user’. Default is ‘a11’.
- Returns:
PETSc.KSP
- Return type:
The KSP object for the block split preconditioner.
- get_block_split_index_set(node, dofs0, dofs1)[source]
Get the PETSc Index Set (IS) for the block split.
Parameters:
node (BlockSplitNode): The node for which to get the IS. dofs0 (np.ndarray): DOFs for the first block. dofs1 (np.ndarray): DOFs for the second block.
Returns:
PETSc.IS: The Index Set for the block split.
- set_child_node_ksps(blocks_0, blocks_1, is0_data, is1_data, ksp0, ksp1)[source]
Set the KSPs for the child nodes of the block split. :param blocks_0 (Iterable[str]): :type blocks_0 (Iterable[str]): The first set of blocks (field tags). :param blocks_1 (Iterable[str]): :type blocks_1 (Iterable[str]): The second set of blocks (field tags). :param is0_data (tuple): :type is0_data (tuple): A tuple containing the name and PETSc Index Set for the first block. :param is1_data (tuple): :type is1_data (tuple): A tuple containing the name and PETSc Index Set for the second block. :param ksp0 (PETSc.KSP): :type ksp0 (PETSc.KSP): The KSP for the first block. :param ksp1 (PETSc.KSP): :type ksp1 (PETSc.KSP): The KSP for the second block.
- Return type:
None
- split_IS(blocks_0, blocks_1)[source]
Split the blocks into two sets and create a PETSc Index Set (IS) for each.
Parameters:
blocks_0 (Iterable[str]): The first set of blocks (field tags). blocks_1 (Iterable[str]): The second set of blocks (field tags).
Returns:
tuple: A tuple containing two PETSc Index Sets (IS) for the blocks.