enrichedfem.solver_fem package

Submodules

enrichedfem.solver_fem.EllipticDirFEMSolver module

class enrichedfem.solver_fem.EllipticDirFEMSolver.Elliptic1DDirFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

FEM solver for general elliptic system and convection-dominated regime with Dirichlet boundary conditions.

This class defines the variational formulation and assembles the system for this 1D Elliptic problem with Dirichlet boundary conditions, including standard FEM and correction methods (additive and multiplicative).

_define_corr_add_system(params, u, v, u_PINNs, V_solve)[source]

Define the additive correction system.

This method defines the additive correction system for the given parameters, trial function, test function, PINNs solution, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_corr_mult_system(params, u, v, u_PINNs, V_solve, M, impose_bc)[source]

Define the multiplicative correction system.

This method defines the multiplicative correction system for the given parameters, trial function, test function, PINNs solution, function space, lifting constant, and boundary condition flag (weak or strong).

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

  • M (float) – Lifting constant.

  • impose_bc (bool) – Boundary condition flag. If True, strong BC. If False, weak BC.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_fem_system(params, u, v, V_solve)[source]

Define the FEM system.

This method defines the FEM system for the given parameters, trial function, test function, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

class enrichedfem.solver_fem.EllipticDirFEMSolver.Elliptic1DDirLineFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: Elliptic1DDirFEMSolver, LineFEMSolver

FEM solver for the general elliptic system and convection-dominated regime with Dirichlet boundary conditions on a line.

This class combines the Elliptic1DDirFEMSolver and LineFEMSolver to solve the general elliptic system and convection-dominated regime with Dirichlet boundary conditions on a line.

class enrichedfem.solver_fem.EllipticDirFEMSolver.EllipticDirFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

FEM solver for an anisotropic elliptic problem with Dirichlet boundary conditions.

This class defines the variational formulation and assembles the system for this Elliptic problem with Dirichlet boundary conditions, including standard FEM and additive correction.

_define_corr_add_system(params, u, v, u_PINNs, V_solve)[source]

Define the additive correction system.

This method defines the additive correction system for the given parameters, trial function, test function, PINNs solution, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_corr_mult_system(params, u, v, u_PINNs, V_solve, M, impose_bc)[source]

Define the multiplicative correction system.

This method defines the multiplicative correction system for the given parameters, trial function, test function, PINNs solution, function space, lifting constant, and boundary condition flag (weak or strong).

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

  • M (float) – Lifting constant.

  • impose_bc (bool) – Boundary condition flag. If True, strong BC. If False, weak BC.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_fem_system(params, u, v, V_solve)[source]

Define the FEM system.

This method defines the FEM system for the given parameters, trial function, test function, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

class enrichedfem.solver_fem.EllipticDirFEMSolver.EllipticDirSquareFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: EllipticDirFEMSolver, SquareFEMSolver

FEM solver for the anisotropic elliptic problem with Dirichlet boundary conditions on a square.

This class combines the EllipticDirFEMSolver and SquareFEMSolver to solve the anisotropic elliptic problem with Dirichlet boundary conditions on a square.

enrichedfem.solver_fem.FEMSolver module

class enrichedfem.solver_fem.FEMSolver.FEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: ABC

FEM solver.

This class sets up the FEM domain, solves the FEM system, and computes the error between the FEM solution and the analytical or reference solution. It also includes the enriched FEM methods (correction with addition and multiplication). If needed, it can compute the reference solution and save it.

Parameters:
  • params (list) – Sample of sets of parameters.

  • problem (Problem) – Problem considered.

  • degree (int, optional) – Degree of the finite element space. Defaults to 1.

  • error_degree (int, optional) – Degree of the error space. Defaults to 4.

  • high_degree (int, optional) – Degree of the expression space for f. Defaults to 9.

  • save_uref (str, optional) – Directory to save reference solution. Defaults to None.

  • load_uref (bool, optional) – Load flag for reference solution. Defaults to True.

__plot_mesh(plot_mesh=False, filename=None)

Plot the mesh.

This method plots the mesh and saves it to a file if a filename is provided.

Parameters:
  • plot_mesh (bool, optional) – Plot the mesh. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

_create_FEM_domain(nb_vert, degree, save_times=False)[source]

Create the FEM domain.

This method creates the FEM domain with the given number of vertices and degree.

Parameters:
  • nb_vert (int) – Number of vertices.

  • degree (int) – Degree of the finite element space.

  • save_times (bool, optional) – Save computational times. Defaults to False.

Returns:

Mesh, function space, and integration measure.

Return type:

tuple

abstract _create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

abstract _define_corr_add_system(params, u, v, u_PINNs, V_solve)[source]

Define the additive correction system.

This method defines the additive correction system for the given parameters, trial function, test function, PINNs solution, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

abstract _define_corr_mult_system(params, u, v, u_PINNs, V_solve, M, impose_bc)[source]

Define the multiplicative correction system.

This method defines the multiplicative correction system for the given parameters, trial function, test function, PINNs solution, function space, lifting constant, and boundary condition flag (weak or strong).

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

  • M (float) – Lifting constant.

  • impose_bc (bool) – Boundary condition flag. If True, strong BC. If False, weak BC.

Returns:

Bilinear and linear forms.

Return type:

tuple

abstract _define_fem_system(params, u, v, V_solve)[source]

Define the FEM system.

This method defines the FEM system for the given parameters, trial function, test function, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

_plot_results_corr(u_ex_V, C_ex_V, C_tild_V, sol_V, V_solve, type, plot_result=False, filename=None, impose_bc=None)[source]

Plot the correction results.

This method plots the corrected solution, the analytical solution, the correction, and the errors. It also saves the plots to a file if a filename is provided.

Parameters:
  • u_ex_V (Function) – Analytical solution.

  • C_ex_V (Function) – Analytical correction.

  • C_tild_V (Function) – Computed correction.

  • sol_V (Function) – Corrected solution.

  • V_solve (FunctionSpace) – Function space.

  • type (str) – Type of correction (“Add” or “Mult”).

  • plot_result (bool, optional) – Plot the results. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

  • impose_bc (bool, optional) – Whether boundary conditions are imposed strongly or weakly (for multiplicative correction). Defaults to None.

_plot_results_fem(u_ex_V, sol_V, V_solve, plot_result=False, filename=None)[source]

Plot the FEM results.

This method plots the FEM solution, the analytical solution, and the error. It also saves the plots to a file if a filename is provided.

Parameters:
  • u_ex_V (Function) – Analytical solution.

  • sol_V (Function) – FEM solution.

  • V_solve (FunctionSpace) – Function space.

  • plot_result (bool, optional) – Plot the results. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

corr_add(i, u_PINNs, plot_result=False, filename=None)[source]

Solve the problem using the additive correction method.

This method solves the problem for the given parameter index using the additive correction method. It computes the solution, the correction, the error, and optionally plots the results.

Parameters:
  • i (int) – Parameter index.

  • u_PINNs (Function) – PINNs solution.

  • plot_result (bool, optional) – Plot the results. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

Returns:

Corrected solution, correction, and L2 norm of the error.

Return type:

tuple

corr_mult(i, u_PINNs, M=0.0, impose_bc=True, plot_result=False, filename=None)[source]

Solve the problem using the multiplicative correction method.

This method solves the problem for the given parameter index using the multiplicative correction method. It computes the solution, the correction, the error, and optionally plots the results.

Parameters:
  • i (int) – Parameter index.

  • u_PINNs (Function) – PINNs solution.

  • M (float, optional) – Lifting constant. Defaults to 0.0.

  • impose_bc (bool, optional) – Whether boundary conditions are imposed strongly or weakly. Defaults to True.

  • plot_result (bool, optional) – Plot the results. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

Returns:

Corrected solution, correction, and L2 norm of the error.

Return type:

tuple

fem(i, plot_result=False, filename=None)[source]

Solve the problem using the finite element method.

This method solves the problem for the given parameter index using the finite element method. It computes the solution, the error, and optionally plots the results.

Parameters:
  • i (int) – Parameter index.

  • plot_result (bool, optional) – Plot the results. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

Returns:

FEM solution and L2 norm of the error.

Return type:

tuple

get_uref(i)[source]

Get the reference solution.

This method gets the reference solution for the given parameter index. It loads the solution from a file if it exists and load_uref is True, otherwise it computes the solution and saves it to a file.

Parameters:

i (int) – Parameter index.

Returns:

Reference solution interpolated on V_ex.

Return type:

Function

pinns(i, u_PINNs)[source]

Compute the L2 norm of the error between the PINNs solution and the analytical solution.

This method computes the L2 norm of the error between the PINNs solution and the analytical solution for the given parameter index.

Parameters:
  • i (int) – Parameter index.

  • u_PINNs (Function) – PINNs solution.

Returns:

L2 norm of the error.

Return type:

float

run_uref(i)[source]

Compute the reference solution.

This method computes the reference solution for the given parameter index.

Parameters:

i (int) – Parameter index.

Returns:

Reference solution.

Return type:

Function

set_meshsize(nb_cell, plot_mesh=False, filename=None)[source]

Set the mesh size.

This method sets the mesh size with the given number of cells and creates the associated finite element space. It also plots the mesh if plot_mesh is True or saves the plot if filename is not None.

Parameters:
  • nb_cell (int) – Number of cells.

  • plot_mesh (bool, optional) – Plot the mesh. Defaults to False.

  • filename (str, optional) – Filename to save the plot. Defaults to None.

enrichedfem.solver_fem.GeometryFEMSolver module

class enrichedfem.solver_fem.GeometryFEMSolver.CircleFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: ComplexFEMSolver

Create a 2D mesh for a circle domain.

This subclass of the ComplexFEMSolver creates a circluar mesh for the circle domain defined by the problem’s geometry.

_create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

class enrichedfem.solver_fem.GeometryFEMSolver.ComplexFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

Generate mesh for complex 2D geometries.

This subclass of the FEMSolver provides a method to generate meshes for complex 2D geometries using mshr, ensuring the mesh resolution is appropriate.

_generate_mesh_given_size(domain, nb_vert)[source]

Generate a mesh with a given characteristic size.

This method generates a mesh for the given domain and number of vertices, iteratively refining until the mesh size is appropriate.

Parameters:
  • domain (mshr.Domain) – The domain to mesh.

  • nb_vert (int) – Number of vertices for the rectangular mesh.

Returns:

Mesh and computational time.

Return type:

tuple

class enrichedfem.solver_fem.GeometryFEMSolver.CubeFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

Create a 3D mesh for a cube domain.

This subclass of the ComplexFEMSolver creates a mesh for the cube domain defined by the problem’s geometry.

_create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

class enrichedfem.solver_fem.GeometryFEMSolver.DonutFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: ComplexFEMSolver

Create a 2D mesh for a annulus domain.

This subclass of the ComplexFEMSolver creates a mesh for the donut defined by the problem’s geometry.

_create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

class enrichedfem.solver_fem.GeometryFEMSolver.LineFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

Create a 1D mesh for a line segment.

This subclass of the FEMSolver creates a 1D mesh of the line segment defined by the problem’s geometry.

_create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

class enrichedfem.solver_fem.GeometryFEMSolver.SquareFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

Create a 2D mesh for a square domain.

This subclass of the FEMSolver creates a rectangular mesh for the square domain defined by the problem’s geometry.

_create_mesh(nb_vert)[source]

Create the mesh.

This method creates the mesh with the given number of vertices. For non-rectangular domains, we consider a box containing the domain.

Parameters:

nb_vert (int) – Number of vertices.

Returns:

Mesh and computational time.

Return type:

tuple

enrichedfem.solver_fem.PoissonDirFEMSolver module

class enrichedfem.solver_fem.PoissonDirFEMSolver.PoissonDirDonutFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: PoissonDirFEMSolver, DonutFEMSolver

FEM solver for the Poisson equation with Dirichlet boundary conditions on a donut.

This class combines the PoissonDirFEMSolver and DonutFEMSolver to solve the Poisson equation with Dirichlet boundary conditions on a 2D donut-shaped domain.

class enrichedfem.solver_fem.PoissonDirFEMSolver.PoissonDirFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

FEM solver for the Poisson problem with Dirichlet boundary conditions.

This class defines the variational formulation and assembles the system for the Poisson equation with Dirichlet boundary conditions, including standard FEM and correction methods (additive and multiplicative).

_define_corr_add_system(params, u, v, u_PINNs, V_solve)[source]

Define the additive correction system.

This method defines the additive correction system for the given parameters, trial function, test function, PINNs solution, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_corr_mult_system(params, u, v, u_PINNs, V_solve, M, impose_bc)[source]

Define the multiplicative correction system.

This method defines the multiplicative correction system for the given parameters, trial function, test function, PINNs solution, function space, lifting constant, and boundary condition flag (weak or strong).

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

  • M (float) – Lifting constant.

  • impose_bc (bool) – Boundary condition flag. If True, strong BC. If False, weak BC.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_fem_system(params, u, v, V_solve)[source]

Define the FEM system.

This method defines the FEM system for the given parameters, trial function, test function, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

class enrichedfem.solver_fem.PoissonDirFEMSolver.PoissonDirLineFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: PoissonDirFEMSolver, LineFEMSolver

FEM solver for the Poisson equation with Dirichlet boundary conditions on a line segment.

This class combines the PoissonDirFEMSolver and LineFEMSolver to solve the Poisson equation with Dirichlet boundary conditions on a 1D line segment.

class enrichedfem.solver_fem.PoissonDirFEMSolver.PoissonDirSquareFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: PoissonDirFEMSolver, SquareFEMSolver

FEM solver for the Poisson equation with Dirichlet boundary conditions on a square.

This class combines the PoissonDirFEMSolver and SquareFEMSolver to solve the Poisson equation with Dirichlet boundary conditions on a 2D square domain.

enrichedfem.solver_fem.PoissonMixedFEMSolver module

class enrichedfem.solver_fem.PoissonMixedFEMSolver.PoissonMixedDonutFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: DonutFEMSolver, PoissonMixedFEMSolver

FEM solver for the Poisson equation with Mixed boundary conditions on a donut.

This class combines the PoissonMixedFEMSolver and DonutFEMSolver to solve the Poisson equation with Mixed boundary conditions on a donut.

class enrichedfem.solver_fem.PoissonMixedFEMSolver.PoissonMixedFEMSolver(params, problem, degree=1, error_degree=4, high_degree=9, save_uref=None, load_uref=True)[source]

Bases: FEMSolver

FEM solver for the Poisson problem with Mixed boundary conditions.

This class defines the variational formulation and assembles the system for the Poisson equation with Mixed boundary conditions, including standard FEM and additive correction.

_define_corr_add_system(params, u, v, u_PINNs, V_solve)[source]

Define the additive correction system.

This method defines the additive correction system for the given parameters, trial function, test function, PINNs solution, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_corr_mult_system(params, u, v, u_PINNs, V_solve, M)[source]

Define the multiplicative correction system.

This method defines the multiplicative correction system for the given parameters, trial function, test function, PINNs solution, function space, lifting constant, and boundary condition flag (weak or strong).

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • u_PINNs (Function) – PINNs solution.

  • V_solve (FunctionSpace) – Function space.

  • M (float) – Lifting constant.

  • impose_bc (bool) – Boundary condition flag. If True, strong BC. If False, weak BC.

Returns:

Bilinear and linear forms.

Return type:

tuple

_define_fem_system(params, u, v, V_solve)[source]

Define the FEM system.

This method defines the FEM system for the given parameters, trial function, test function, and function space.

Parameters:
  • params (list) – List of parameters.

  • u (TrialFunction) – Trial function.

  • v (TestFunction) – Test function.

  • V_solve (FunctionSpace) – Function space.

Returns:

Bilinear and linear forms.

Return type:

tuple

enrichedfem.solver_fem.utils module

enrichedfem.solver_fem.utils.get_divmatgradutheta_fenics_fromV(V_test, params, u_PINNs, anisotropy_matrix)[source]
enrichedfem.solver_fem.utils.get_gradutheta_fenics_fromV(V_test, params, u_PINNs)[source]
enrichedfem.solver_fem.utils.get_laputheta_fenics_fromV(V_test, params, u_PINNs)[source]
enrichedfem.solver_fem.utils.get_test_sample_fromV(V_test, params)[source]
enrichedfem.solver_fem.utils.get_utheta_fenics_onV(V_test, params, u_PINNs)[source]

Module contents