Multiphysics Problem

class flatiron_tk.physics.multiphysics_problem.MultiphysicsProblem(*physics_problems)[source]

Bases: PhysicsProblem

A class to represent a multiphysics problem by combining multiple physics problems.

Initialize a multiphysics problem by combining multiple physics problems. :param *physics_problems: A variable number of physics problem instances to be combined into a multiphysics problem. :type *physics_problems: PhysicsProblem

Raises:

ValueError – If the provided physics problems do not share the same mesh or if there are tag conflicts.

flux(h, physics_tag)[source]

Get the flux for a given physics tag.

Parameters:
  • h (ufl.core.expr.Expr) – The test function for the flux calculation.

  • physics_tag (str) – The tag of the physics problem for which to calculate the flux.

Returns:

The flux expression for the specified physics problem.

Return type:

ufl.core.expr.Expr

get_function_space(physics_tag=None)[source]

Get the function space for a given physics tag. :param physics_tag: The tag of the physics problem. If None, returns the function space for the multiphysics problem. :type physics_tag: str, optional

Returns:

The function space associated with the given physics tag, or the multiphysics function space if no tag is provided.

Return type:

dolfinx.fem.FunctionSpace

get_global_dofs(global_function_space, physics_tag=None, sort=True)[source]

Get the global degrees of freedom (DOFs) indices on the local process for a given physics tag or for all physics problems.

Parameters:
  • global_function_space (dolfinx.fem.FunctionSpace) – The global function space from which to extract the DOFs.

  • physics_tag (str or list of str, optional) – The tag(s) of the physics problem(s). If None, returns the DOFs for all physics problems.

  • sort (bool, optional) – Whether to sort the DOFs before returning. Default is True.

Returns:

An array of global DOFs indices on local process associated with the given physics tag(s), or all DOFs

Return type:

np.ndarray

get_physics(physics_tag)[source]

Get the physics problem for a given physics tag.

Parameters:

physics_tag (str) – The tag of the physics problem.

Returns:

The physics problem associated with the given tag.

Return type:

PhysicsProblem

get_physics_id(physics_tag)[source]

Get the physics ID for a given physics tag.

Parameters:

physics_tag (str) – The tag of the physics problem.

Returns:

The ID of the physics problem.

Return type:

int

get_residual()[source]

Get the residual of the multiphysics problem by summing the residuals of each subphysics problem.

Returns:

The residual expression for the multiphysics problem.

Return type:

ufl.core.expr.Expr

get_solution_function(physics_tag=None)[source]

Get the solution function for a given physics tag.

Parameters:

physics_tag (str, optional) – The tag of the physics problem. If None, returns the solution function for the multiphysics problem.

Returns:

The solution function associated with the given physics tag, or the multiphysics solution function if no tag is provided.

Return type:

ufl.core.expr.Expr

get_test_function(physics_tag=None)[source]

Get the test function for a given physics tag. :param physics_tag: The tag of the physics problem. If None, returns the test function for the multiphysics problem. :type physics_tag: str, optional

Returns:

The test function associated with the given physics tag, or the multiphysics test function if no tag is provided.

Return type:

ufl.core.expr.Expr

get_trial_function(physics_tag=None)[source]

Get the trial function for a given physics tag.

Parameters:

physics_tag (str, optional) – The tag of the physics problem. If None, returns the trial function for the multiphysics problem.

Returns:

The trial function associated with the given physics tag, or the multiphysics trial function if no tag is provided.

Return type:

ufl.core.expr.Expr

set_bcs(multiphysics_bc_dict)[source]

Set the boundary conditions for the multiphysics problem by iterating over the boundary conditions of each subphysics problem.

Parameters:

multiphysics_bc_dict (dict) – A dictionary containing the boundary conditions for each subphysics problem. The keys are the boundary IDs and the values are dictionaries with the boundary condition type and value.

Raises:

ValueError – If a boundary condition type is not recognized or if the physics ID is not found in the multiphysics problem.

set_element()[source]

Set the finite element for the multiphysics problem by creating a mixed element from the elements of the subphysics problems.

set_function_space(V)[source]

Set the function space for the multiphysics problem and for each subphysics problem. :param V: The function space for the multiphysics problem. :type V: dolfinx.fem.FunctionSpace

set_solution_function(multiphysics_solution_function)[source]

Set the solution function for the multiphysics problem and for each subphysics problem. :param multiphysics_solution_function: The solution function for the multiphysics problem. :type multiphysics_solution_function: dolfinx.fem.Function

set_test_function(multiphysics_test_function)[source]

Set the test function for the multiphysics problem and for each subphysics problem. :param multiphysics_test_function: The test function for the multiphysics problem. :type multiphysics_test_function: ufl.TestFunction

set_trial_function(multiphysics_trial_function)[source]

Set the trial function for the multiphysics problem and for each subphysics problem. :param multiphysics_trial_function: The trial function for the multiphysics problem. :type multiphysics_trial_function: ufl.TrialFunction

set_weak_form(*options)[source]

Set the weak form for the multiphysics problem by summing the weak forms of each subphysics problem.

Parameters:

options (dict, optional) – Options for each subphysics problem’s weak form. If not provided, an empty dictionary is used for each subphysics problem.

Raises:

ValueError – If a subphysics problem does not have the attribute weak_form defined.

set_writer(output_dir, file_format)[source]

Set the writer for each subphysics problem to write output to the specified directory.

Parameters:
  • output_dir (str) – The directory where the output files will be written.

  • file_format (str, optional) – The file format for the output files.

write(function_to_save=None, *args, **kwargs)[source]

Write the solution of the multiphysics problem to files. :param function_to_save: The function to save. If None, the solution function of the multiphysics problem is used. :type function_to_save: ufl.core.expr.Expr, optional :param *args: Additional positional arguments to pass to the write method of each subphysics problem. :type *args: tuple :param **kwargs: Additional keyword arguments to pass to the write method of each subphysics problem. :type **kwargs: dict

write_subphysics(physics, solution, *args, **kwargs)[source]

Recursive function that splits (monolithic) multiphysics problems and solutions until each sub solution can be written.

Example

Coupled-Flow-Transport[Navier-Stokes[momentum, continuity], Transport]
    |
Split 1
    |----Navier-Stokes[momentum, continuity] (call function)
    |       |
    |    Split 2
    |       |----Momentum -> write to file
    |       |
    |       |----Continuity -> write to file
    |
    |----Transport -> write to file
Parameters:
  • physics (PhysicsProblem) – The physics problem to write the solution for.

  • solution (dolfinx.fem.Function) – The solution function to write.

class flatiron_tk.physics.multiphysics_problem.TransientMultiPhysicsProblem(*physics_problems)[source]

Bases: MultiphysicsProblem

Extension of MultiphysicsProblem to support transient simulations.

This class manages the storage and update of the previous time step’s solution, which is essential for time-stepping schemes in transient simulations involving multiple coupled physics components.

build_function_space()[source]

Build the function space for the multiphysics problem and initialize the previous solution function. This method extends the build_function_space method of the MultiphysicsProblem class by also creating a function to store the solution from the previous time step.

update_previous_solution()[source]

Update the previous solution function with the current solution. This method copies the values from the current solution function to the previous solution function, preparing it for the next time step in a transient simulation.

This is a class that provide an interface for a coupled multi-physics problem. This class provides an interface for physics problem with multiple variables and multiple equation problems.

Designing multiphysics

MultiPhysics take in the different PhysicsProblem classes in the constructor, and build a monolithic problem based on all of the Physics. The weak formulation that we solve is the sum of all of the weak formulations from the base physics. Here, functions such as the trial, test, and solution functions requires a tag input indicating which variable you are pulling from. These functions will return the reference to the specific variable in the monolothic function object.