enrichedfem.problem package
Submodules
enrichedfem.problem.problem_1D module
- class enrichedfem.problem.problem_1D.TestCase1(version=1)[source]
Bases:
TestCase1DTest case 1 for 1D problems.
This test case defines the 1D Poisson problem with Dirichlet BC with three parameters (alpha, beta, gamma) and provides an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- d2u_ex_dx2(pre, xy, mu)[source]
Second derivative of the exact solution d^2u/dx^2.
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s).
mu – The parameter vector (alpha, beta, gamma).
- Returns:
The value of the second derivative of the exact solution.
- du_ex_dx(pre, xy, mu)[source]
First derivative of the exact solution du/dx.
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s).
mu – The parameter vector (alpha, beta, gamma).
- Returns:
The value of the first derivative of the exact solution.
- f(pre, xy, mu)[source]
Source term f(x).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s).
mu – The parameter vector (alpha, beta, gamma).
- Returns:
The value of the source term at the given point.
- class enrichedfem.problem.problem_1D.TestCase1D(testcase, version)[source]
Bases:
ABCAbstract base class for 1D test cases.
This class defines the common interface for all 1D test cases, including properties for geometry, number of parameters, parameter domain, and availability of an analytical solution.
- Parameters:
testcase (int) – The test case number.
version (int) – The version number of the test case.
- class enrichedfem.problem.problem_1D.TestCase2(version=1)[source]
Bases:
TestCase1DTest case 2 for 1D problems.
This test case defines a 1D general elliptic system and convection-dominated regime with Dirichlet BC with two parameters (r, Pe) and provides an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- d2u_ex_dx2(pre, xy, mu)[source]
Second derivative of the exact solution d^2u/dx^2.
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s).
mu – The parameter vector (r, Pe).
- Returns:
The value of the second derivative of the exact solution.
- du_ex_dx(pre, xy, mu)[source]
First derivative of the exact solution du/dx.
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s).
mu – The parameter vector (r, Pe).
- Returns:
The value of the first derivative of the exact solution.
enrichedfem.problem.problem_2D module
- class enrichedfem.problem.problem_2D.TestCase1(version=1)[source]
Bases:
TestCase2DTest case 1 for 2D problems.
This test case defines a 2D Poisson problem with low frequency in a square domain with Dirichlet BC, two parameters (mu1, mu2), and provides an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- f(pre, xy, mu)[source]
Source term f(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu1, mu2).
- Returns:
The value of the source term at the given point.
- g(pre, xy, mu)[source]
Dirichlet boundary condition g(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu1, mu2).
- Returns:
The value of the Dirichlet boundary condition.
- grad2u_ex(pre, xy, mu)[source]
Hessian of the exact solution grad^2(u)(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu1, mu2).
- Returns:
The Hessian of the exact solution at the given point.
- gradf(pre, xy, mu)[source]
Gradient of the source term grad(f)(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu1, mu2).
- Returns:
The gradient of the source term at the given point.
- class enrichedfem.problem.problem_2D.TestCase2(version=1)[source]
Bases:
TestCase2DTest case 2 for 2D problems.
This test case defines a 2D Poisson problem with high frequency in a square domain with Dirichlet BC, two parameters (mu1, mu2), and provides an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- f(pre, xy, mu)[source]
Source term f(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu1, mu2).
- Returns:
The value of the source term at the given point.
- class enrichedfem.problem.problem_2D.TestCase2D(testcase, version)[source]
Bases:
ABCAbstract base class for 2D test cases.
This class defines the common interface for all 2D test cases, including properties for geometry, number of parameters, parameter domain, and availability of an analytical solution.
- Parameters:
testcase (int) – The test case number.
version (int) – The version number of the test case.
- class enrichedfem.problem.problem_2D.TestCase3(version=1)[source]
Bases:
TestCase2DTest case 3 for 2D problems.
This test case defines a 2D anisotropic elliptic problem on a square domain with Dirichlet BC, four parameters (c1, c2, sigma, eps), and does not provide an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- anisotropy_matrix(pre, xy, mu)[source]
Anisotropy matrix A(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (c1, c2, sigma, eps).
- Returns:
The components of the anisotropy matrix (a11, a12, a21, a22).
- f(pre, xy, mu)[source]
Source term f(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (c1, c2, sigma, eps).
- Returns:
The value of the source term at the given point.
- class enrichedfem.problem.problem_2D.TestCase4(version=1)[source]
Bases:
TestCase2DTest case 4 for 2D problems.
This test case defines a 2D Poisson problem on an annulus with mixed boundary conditions (Robin on the inner boundary, Dirichlet on the outer boundary), one parameter (mu), and provides an analytical solution.
- Parameters:
version (int) – The version number of the test case. Defaults to 1.
- f(pre, xy, mu)[source]
Source term f(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The value of the source term at the given point.
- g(pre, xy, mu)[source]
Dirichlet boundary condition g(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The value of the Dirichlet boundary condition.
- gr(pre, xy, mu)[source]
Robin boundary condition gr(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The value of the Robin boundary condition.
- grad2u_ex(pre, xy, mu)[source]
Hessian of the exact solution grad^2(u)(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The Hessian of the exact solution at the given point.
- gradf(pre, xy, mu)[source]
Gradient of the source term grad(f)(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The gradient of the source term at the given point.
- gradu_ex(pre, xy, mu)[source]
Gradient of the exact solution grad(u)(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The gradient of the exact solution at the given point.
- h_ext(pre, xy, mu)[source]
Dirichlet boundary condition on the outer boundary h_ext(x,y).
- Parameters:
pre – The precision module (e.g., dolfin, numpy).
xy – The spatial coordinate(s) (x,y).
mu – The parameter vector (mu).
- Returns:
The value of the Dirichlet boundary condition on the outer boundary.
enrichedfem.problem.utils module
- enrichedfem.problem.utils.compute_slope(i, tab_nb_vert, tab_err)[source]
Computes the slope between two points on a log-log plot.
This function calculates the slope of the line segment connecting two points on a log-log plot, given by the i-th and (i-1)-th elements of ‘tab_nb_vert’ and ‘tab_err’. It also plots this segment and returns the midpoint of the segment.
- Parameters:
i (int) – The index of the point in ‘tab_nb_vert’ and ‘tab_err’.
tab_nb_vert (list or numpy.ndarray) – A list or array of x-coordinates.
tab_err (list or numpy.ndarray) – A list or array of y-coordinates.
- Returns:
- A tuple containing the computed slope and the midpoint of the
segment on the log-log plot.
- Return type:
tuple
- enrichedfem.problem.utils.create_tree(path)[source]
Creates a directory tree from a given path.
This function takes a path string and creates all necessary directories in the tree. It handles both absolute and relative paths.
- Parameters:
path (str) – The path string representing the directory tree to create.
- enrichedfem.problem.utils.get_random_param(i, parameter_domain)[source]
Generates a random parameter set within a specified domain.
This function generates a random parameter set based on the provided parameter domain and an index ‘i’, which is used to seed the random number generator. The generated parameters are rounded to two decimal places.
- Parameters:
i (int) – An index used to seed the random number generator.
parameter_domain (list) – A list of tuples, where each tuple defines the lower and upper bounds for a parameter.
- Returns:
A list or array of random parameters.
- Return type:
list or numpy.ndarray
- enrichedfem.problem.utils.get_random_params(n_params, parameter_domain)[source]
Generates multiple random parameter sets within a specified domain.
This function generates ‘n_params’ random parameter sets, where each set is drawn from a uniform distribution within the provided parameter domain. The random number generator is seeded for reproducibility.
- Parameters:
n_params (int) – The number of parameter sets to generate.
parameter_domain (list) – A list of tuples, where each tuple defines the lower and upper bounds for a parameter.
- Returns:
- A 2D array of random parameters, where each row
represents a parameter set.
- Return type:
numpy.ndarray
- enrichedfem.problem.utils.select_param(problem, param_num)[source]
Selects a parameter set for a given problem.
This function selects a parameter set based on the provided problem and parameter number (param_num). It prioritizes using predefined parameter sets from problem.set_params if available. Otherwise, it generates a random parameter set within the problem’s parameter domain. A specific parameter set is hardcoded for problem.testcase == 3 and param_num == 3.
- Parameters:
problem – The problem object, which should have either a set_params attribute or a parameter_domain attribute.
param_num (int) – The index of the parameter set to select (1-based).
- Returns:
The selected parameter set.
- Return type:
list or numpy.ndarray