Boundary Conditions

1D Boundary Condiions

class FEMpy.Boundaries.BoundaryConditions(mesh, boundary_types, boundary_coords=None, dirichlet_fun=None, neumann_fun=None, robin_fun_q=None, robin_fun_p=None, coeff_fun=None)[source]

Defines all boundary conditions to be applied to a Poisson equation.

Takes in the coordinates for the boundary nodes and the boundary condition types and provides the treatments for each of the boundry condition types.

Parameters:
  • mesh ({:class: FEMpy.Mesh.Interval1D, :class: FEMpy.Mesh.TriangularMesh2D}) – A Mesh class defining the mesh and associated information matrices.
  • boundary_types (array_like of str {‘dirichlet`, ‘neumann’, ‘robin’}) – Boundary condition type for each coordinate in boundary_coords.
  • boundary_coords (array_like, optional) – List of coordinate values of the boundary nodes. If not specified, will use the boundary node coordinates stored in mesh.
  • dirichlet_fun (function, optional) – The Dirichlet boundary condition function g`(`x). Must be defined at the boundary values specified in boundary_coords.
  • neumann_fun (function, optional) – The Neumann boundary condition function r`(`x). Must be defined at the bounadry values specified in boundary_coords.
  • robin_fun_q (function, optional) – The Robin boundary condition function q`(`x). Must be defined at the boundary values specified in boundary_coords.
  • robin_fun_p (function, optional) – The Robin boundary condition function p`(`x). Must be defined at the boundary values specified in boundary_coords.
  • coeff_fun (function, optional) – Function name of the coefficient function c`(`x) in the Poisson equation. Required if Neumann or Robin boundary conditions are included.

Warning

Both end point boundary conditions cannot be Neumann as this may result in a loss of uniqueness of the solution.

Notes

  • The Dirichlet boundary conditions are be defined as

    \[u(x) = g(x); x = a \text{ or } b.\]
  • The Neumann boundary conditions are defined as

    \[\frac{{\rm d}}{{\rm d} x} u(x) = r(x); x = a \text{ or } b.\]
  • The Robin boundary conditions are defined as

    \[\frac{{\rm d}}{{\rm d}x} u(x) + q(x) u(x) = p(x); x = a \text{ or } b.\]
treat_dirichlet(matrix, vector)[source]

Overwrites the appropriate entries in the stiffness matrix and load vector.

Corrects the stiffness matrix and load vector to properly incorporate the boundary conditions.

Parameters:
  • matrix (ndarray) – Finite element stiffness matrix.
  • vector (ndarray) – Finite element load vector.
Returns:

  • matrix (ndarray) – Corrected finite element stiffness matrix with Dirichlet boundary conditions incorporated.
  • vector (ndarray) – Corrected finite element load vector with Dirichlet boundary conditions incorporated.

treat_neumann(vector)[source]

Overwrites the appropriate entries in the load vector.

Corrects the load vector to properly incorporate the boundary conditions.

Parameters:vector (ndarray) – Finite element load vector.
Returns:vector – Corrected finite element load vector with Neumann boundary conditions incorporated.
Return type:ndarray
treat_robin(matrix, vector)[source]

Overwrites the appropriate entries in the stiffness matrix and load vector.

Corrects the stiffness matrix and load vector to properly incorporate the boundary conditions.

Parameters:
  • matrix (ndarray) – Finite element stiffness matrix.
  • vector (ndarray) – Finite element load vector.
Returns:

  • matrix (ndarray) – Corrected finite element stiffness matrix with Robin boundary conditions incorporated.
  • vector (ndarray) – Corrected finite element load vector with Robin boundary conditions incorporated.

2D Boundary Conditions

class FEMpy.Boundaries.BoundaryConditions2D(mesh, boundary_node_types, boundary_edge_types, boundary_node_coords=None, boundary_edge_coords=None, trial_basis=None, test_basis=None, dirichlet_fun=None, neumann_fun=None, robin_fun_q=None, robin_fun_p=None, coeff_fun=None)[source]

Defines all boundary conditions to be applied to a Poisson equation.

Takes in the coordinates for the boundary nodes and boundary edges and the boundary condition types for each and provides the treatments for each of the boundry condition types.

Parameters:
  • mesh ({:class: FEMpy.Mesh.Interval1D, :class: FEMpy.Mesh.TriangularMesh2D}) – A Mesh class defining the mesh and associated information matrices.
  • boundary_node_types (array_like of str {‘dirichlet`, ‘neumann’, ‘robin’}) – Boundary condition type for each coordinate in boundary_node_coords.
  • boundary_edge_types (array_like of str {‘dirichlet`, ‘neumann’, ‘robin’}) – Boundary condition type for each edge segment in boundary_edge_coords.
  • boundary_node_coords (array_like, optional) – List of coordinate values of the boundary nodes. If not specified, will use the boundary node coordinates stored in mesh.
  • boundary_edge_coords (array_like, optional) – List of grid coordinates for edge nodes. If not specified, will use the boundary edge coordinates stored in mesh.
  • trial_basis, test_basis ({:class: FEMpy.FEBasis.IntervalBasis1D, :class: FEMpy.FEBasis.TriangularBasis2D}, optional) – A :class: FEBasis class defining the finite element basis functions for the trial and test bases. If Neumann boundary conditions included test_basis is required. If Robin boundary conditions included, then both bases are required.
  • dirichlet_fun (function, optional) – The Dirichlet boundary condition function g`(`x, y). Must be defined at the boundary values specified in boundary_coords.
  • neumann_fun (function, optional) – The Neumann boundary condition function r`(`x, y). Must be defined at the bounadry values specified in boundary_coords.
  • robin_fun_q (function, optional) – The Robin boundary condition function q`(`x, y). Must be defined at the boundary values specified in boundary_coords.
  • robin_fun_p (function, optional) – The Robin boundary condition function p`(`x, y). Must be defined at the boundary values specified in boundary_coords.
  • coeff_fun (function, optional) – Function name of the coefficient function c`(`x, y) in the Poisson equation. Required if Neumann or Robin boundary conditions are included.

Warning

All edge boundary conditions cannot be Neumann as this may result in a loss of uniqueness of the solution.

Notes

  • The Dirichlet boundary conditions are be defined as

    \[u(x, y) = g(x, y); (x, y) \in \delta\Omega \setminus (\Gamma_1 \cup \Gamma_2).\]
  • The Neumann boundary conditions are defined as

    \[\nabla u(x, y) \cdot \hat{\mathbf{n}} = r(x, y); (x, y) \in \Gamma_1 \subseteq \delta\Omega,\]
  • The Robin boundary conditions are defined as

    \[\nabla u(x, y) \cdot \hat{\mathbf{n}} + q(x, y) u(x, y) = p(x, y); (x, y) \in \Gamma_2 \subseteq \delta\Omega.\]
treat_neumann(vector)[source]

Overwrites the appropriate entries in the load vector.

Corrects the load vector to properly incorporate the boundary conditions.

Parameters:vector (ndarray) – Finite element load vector.
Returns:vector – Corrected finite element load vector with Neumann boundary conditions incorporated.
Return type:ndarray
treat_robin(matrix, vector)[source]

Overwrites the appropriate entries in the stiffness matrix and load vector.

Corrects the stiffness matrix and load vector to properly incorporate the boundary conditions.

Parameters:
  • matrix (ndarray) – Finite element stiffness matrix.
  • vector (ndarray) – Finite element load vector.
Returns:

  • matrix (ndarray) – Corrected finite element stiffness matrix with Robin boundary conditions incorporated.
  • vector (ndarray) – Corrected finite element load vector with Robin boundary conditions incorporated.