Object-oriented scientific computing
Pras Pathmanathan
Main advantages of FE over FD
1 Deal with Neumann boundary conditions in a natural (systematic) way
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions 2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs 4 Solve linear system
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs 4 Solve linear system
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
In practice, rather using the basis functions in V0h(i.e. bases satisfying φi = 0
on Γ1), we use Vh, i.e. all the basis functions corresponding to all nodes in the
mesh.
We then impose (any) Dirichlet boundary conditions by altering the appropriate rows of the linear system, for example, for K U = b, if we want to impose U1= c K11 K12 . . . K1N K21 K22 . . . K2N . . . ... . .. ... KN1 KN2 . . . KNN U1 U2 . . . UN = b1 b2 . . . bN
In practice, rather using the basis functions in V0h(i.e. bases satisfying φi = 0
on Γ1), we use Vh, i.e. all the basis functions corresponding to all nodes in the
mesh.
We then impose (any) Dirichlet boundary conditions by altering the appropriate rows of the linear system, for example, for K U = b, if we want to impose
U1= c K11 K12 . . . K1N K21 K22 . . . K2N . . . ... . .. ... KN1 KN2 . . . KNN U1 U2 . . . UN = b1 b2 . . . bN
In practice, rather using the basis functions in V0h(i.e. bases satisfying φi = 0
on Γ1), we use Vh, i.e. all the basis functions corresponding to all nodes in the
mesh.
We then impose (any) Dirichlet boundary conditions by altering the appropriate rows of the linear system, for example, for K U = b, if we want to impose
U1= c 1 0 . . . 0 K21 K22 . . . K2N . . . ... . .. ... KN1 KN2 . . . KNN U1 U2 . . . UN = c b2 . . . bN
Consider the general problem of solving the linear system
Ax= b
where A is an n × n matrix and b an n-vector.
Direct solvers
One approach is to compute A−1 and calculatex= A−1b
Gaussian elimination is an algorithm that is often used and is essentially equivalent to computing A−1
These approaches get too costly (in time and memory) for large n
Consider the general problem of solving the linear system
Ax= b
where A is an n × n matrix and b an n-vector.
Direct solvers
One approach is to compute A−1 and calculatex= A−1b
Gaussian elimination is an algorithm that is often used and is essentially
equivalent to computing A−1
These approaches get too costly (in time and memory) for large n For n ≤ 10000 (maybe even 50000) this may be the best approach
Consider the general problem of solving the linear system
Ax= b
where A is an n × n matrix and b an n-vector.
Direct solvers
One approach is to compute A−1 and calculatex= A−1b
Gaussian elimination is an algorithm that is often used and is essentially
equivalent to computing A−1
These approaches get too costly (in time and memory) for large n
Consider the general problem of solving the linear system
Ax= b
where A is an n × n matrix and b an n-vector.
Direct solvers
One approach is to compute A−1 and calculatex= A−1b
Gaussian elimination is an algorithm that is often used and is essentially
equivalent to computing A−1
These approaches get too costly (in time and memory) for large n For n ≤ 10000 (maybe even 50000) this may be the best approach
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x? For any non-singular matrix P, the system
PAx= Pb
is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved
solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x?
For any non-singular matrix P, the system PAx= Pb is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved
solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x? For any non-singular matrix P, the system
PAx= Pb
is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved
solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x?
For any non-singular matrix P, the system PAx= Pb is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved
solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x?
For any non-singular matrix P, the system
PAx= Pb
is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Iterative solvers
Often A is sparse
This means that computing Ay for given y is cheap.
Choose initial guess x0
An iterative solver takes in a current guess xnand provides an improved
solution xn+1, just using matrix-vector products
Common iterative solvers are conjugate gradients (for when A is symmetric and positive-definite) and GMRES.
Preconditioning
Question is then: (i) does xn→ x and (ii) how fast does xn→ x?
For any non-singular matrix P, the system
PAx= Pb
is equivalent to the original system Ax= b.
By choosing P appropriately, can obtain (massively) improved convergence—preconditioning
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
Suppose we want to compute Z
unit square
F (x , y ) dx dy
We can use the approximation Z
unit square
F (x , y ) dx dy ≈X
i
wiF (xi, yi)
Suppose we want to compute Z
unit square
F (x , y ) dx dy We can use the approximation
Z
unit square
F (x , y ) dx dy ≈X
i
wiF (xi, yi)
Consider computing the mass matrix Mjk =
R
ΩφjφkdV , an N by N matrix say,
and let’s suppose (for clarity only) that we are in 2D.
We do not write out the full basis functions explicitly in computing this integral. Instead: firstly, we break the integral down into an integral over elements: Mjk= X K Z K φjφkdV ConsiderR
KφjφkdV . Key point: The only basis functions with are non-zero in the triangle are the 3 basis functions corresponding to the 3 nodes of the element.
Therefore: compute the elemental contribution to the mass matrix, a3 by 3 matrix of the formR
KφjφkdV for 3 choices of j and k only.
Consider computing the mass matrix Mjk =
R
ΩφjφkdV , an N by N matrix say,
and let’s suppose (for clarity only) that we are in 2D.
We do not write out the full basis functions explicitly in computing this integral. Instead: firstly, we break the integral down into an integral over elements: Mjk= X K Z K φjφkdV ConsiderR
KφjφkdV . Key point: The only basis functions with are non-zero in the triangle are the 3 basis functions corresponding to the 3 nodes of the element.
Therefore: compute the elemental contribution to the mass matrix, a3 by 3
matrix of the formR
KφjφkdV for 3 choices of j and k only.
Consider computing the mass matrix Mjk =
R
ΩφjφkdV , an N by N matrix say,
and let’s suppose (for clarity only) that we are in 2D.
We do not write out the full basis functions explicitly in computing this integral. Instead: firstly, we break the integral down into an integral over elements: Mjk= X K Z K φjφkdV ConsiderR
KφjφkdV . Key point: The only basis functions with are non-zero in
the triangle are the 3 basis functions corresponding to the 3 nodes of the element.
Therefore: compute the elemental contribution to the mass matrix, a3 by 3
matrix of the formR
KφjφkdV for 3 choices of j and k only.
Consider computing the mass matrix Mjk =
R
ΩφjφkdV , an N by N matrix say,
and let’s suppose (for clarity only) that we are in 2D.
We do not write out the full basis functions explicitly in computing this integral. Instead: firstly, we break the integral down into an integral over elements: Mjk= X K Z K φjφkdV ConsiderR
KφjφkdV . Key point: The only basis functions with are non-zero in
the triangle are the 3 basis functions corresponding to the 3 nodes of the element.
Therefore: compute the elemental contribution to the mass matrix, a3 by 3
matrix of the formR
KφjφkdV for 3 choices of j and k only.
Consider computing the mass matrix Mjk =
R
ΩφjφkdV , an N by N matrix say,
and let’s suppose (for clarity only) that we are in 2D.
We do not write out the full basis functions explicitly in computing this integral. Instead: firstly, we break the integral down into an integral over elements: Mjk= X K Z K φjφkdV ConsiderR
KφjφkdV . Key point: The only basis functions with are non-zero in
the triangle are the 3 basis functions corresponding to the 3 nodes of the element.
Therefore: compute the elemental contribution to the mass matrix, a3 by 3
matrix of the formR
KφjφkdV for 3 choices of j and k only.
We have reduced the problem to computing small matrices/vectors, for example the 3 by 3 matrix
Z
K
φjφkdV
where φj, φkare the 3 basis functions corresponding to the 3 nodes of the
mesh.
Next, map to the reference triangle (also known as the canonical triangle), Kref, the triangle with nodes (0, 0), (0, 1), (1, 0).
We have reduced the problem to computing small matrices/vectors, for example the 3 by 3 matrix
Z
K
φjφkdV
where φj, φkare the 3 basis functions corresponding to the 3 nodes of the
mesh.
Next, map to the reference triangle (also known as the canonical triangle),
We now need to be able to compute Z K φjφkdx dy = Z Kref φjφkdet J dξdη
where J is the Jacobian of the mapping from the true element to the canonical element.
The basis functions on the reference triangle are easy to write down
φ1(ξ, η) = 1 − ξ − η
φ2(ξ, η) = ξ
J is also required if ∇φi is needed (for example, in computing the stiffness
matrix), since ∇φi = J∇ξNi.
Consider the mapping from an element with nodes x1, x2, x3, to the canonical
element. The inverse mapping can in fact be easily written down using the basis functions. x(ξ, η) = 3 X j =1 xjNj(ξ, η)
from which it is easy to show that J is the following function of nodal positions J = inv
x2− x1 x3− x1
y2− y1 y3− y1
J is also required if ∇φi is needed (for example, in computing the stiffness
matrix), since ∇φi = J∇ξNi.
Consider the mapping from an element with nodes x1, x2, x3, to the canonical
element. The inverse mapping can in fact be easily written down using the basis functions. x(ξ, η) = 3 X j =1 xjNj(ξ, η)
from which it is easy to show that J is the following function of nodal positions J = inv
x2− x1 x3− x1
y2− y1 y3− y1
Solve:
∇2
u+ f = 0
subject to boundary conditions
u = u∗ on Γ1
(∇u) · n = g on Γ2
1 Set up the mesh and choose basis functions
2 Compute the matrix K and vector b:
Kjk = Z Ω ∇φj· ∇φkdV bj = Z Ω f φjdV + Z Γ2 g φjdS
3 Alter linear system KU= b to impose Dirichlet BCs
4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature 4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs 4 Solve linear system
Write bj= Z Ω f φjdV + Z Γ2 g φjdS as b = bvol+ bsurf
1 Set up the computational mesh and choose basis functions
2 Compute the matrix K and vector b:
1 Loop over elements, for each compute the elemental contributions Kelem and bvol
elem(3 by 3 matrix and 3-vector)
For this, need to compute Jacobian J for this element, and loop over quadrature points
2 Add Kelemand bvolelemto K and bvol appropriately
3 Loop over surface-elements on Γ2, for each compute the elemental
contribution bsurf
elem(a 2-vector).
Similar to integrals over elements, again use quadrature
4 Add bsurfelemto bsurfappropriately
3 Alter linear system K U = b to impose Dirichlet BCs
FEM for simple PDEs: Object-oriented implementation (general ideas)
Note that in the following:
We consider one possible approach - the appropriate design will depend fundamentally on the precise nature of the solver required (eg, a solver for a particular equation versus a general solver of several)
Purplerepresents an abstract class/method,redrepresents a concrete class or implemented method,bluerepresents a self-contained class (no inheritance).
Important members or methods of the classes will be given, but obvious extra methods will be omitted, such as Get/Set methods
FEM for simple PDEs: Object-oriented implementation (general ideas)
Note that in the following:
We consider one possible approach - the appropriate design will depend fundamentally on the precise nature of the solver required (eg, a solver for a particular equation versus a general solver of several)
Purplerepresents an abstract class/method,redrepresents a concrete
class or implemented method,bluerepresents a self-contained class (no
inheritance).
Important members or methods of the classes will be given, but obvious extra methods will be omitted, such as Get/Set methods
FEM for simple PDEs: Object-oriented implementation (general ideas)
Note that in the following:
We consider one possible approach - the appropriate design will depend fundamentally on the precise nature of the solver required (eg, a solver for a particular equation versus a general solver of several)
Purplerepresents an abstract class/method,redrepresents a concrete
class or implemented method,bluerepresents a self-contained class (no
inheritance).
Important members or methods of the classes will be given, but obvious extra methods will be omitted, such as Get/Set methods
What are the self-contained ‘concepts’ (objects) that form the overall simulation code, and what functionality should each of these objects have?
Node
Member var: mLocation B a vector
Member var: mIsBoundaryNode B a boolean (true/false) Element
Member var: mNodes
B (Pointers to) the 3 nodes (assuming a 2d simulation) of this element
Method: ComputeJacobian()
Method: ComputeJacobianDeterminant()
SurfaceElement
Member var: mNodes
B (Pointers to) the 2 nodes of this element
Mesh mNodes
B a list of Node objects mElements
B a list of Element objects mBoundaryElements
B a list of surface elements (SurfaceElement) on the boundary
Method: ReadFromFile(filename)
Method: GenerateRegularMesh(width,height,stepsize)
Method: Refine()
Note
Here, boundary nodes/elements represent the entire boundary—‘mesh’ concept is self-contained and not dependent on PDE problem being solved.
There are various ways this could be implemented Key point: the implementation requires that
Dirichlet BCs be defined at boundary nodes
Neumann BCs be defined on boundary elements (ie element interiors)
BoundaryConditions<DIM> mDirichletBoundaryNodes mDirichletValues mNeumannBoundaryElements mNeumannValues AddDirichletBoundaryCondition(node,dirichletBcValue) AddNeumannBoundaryCondition(boundaryElement,neumannBcValue)
Suppose we want to write a solver for Poisson’s equation ∇2u = f for general forcing terms f (x) and general boundary conditions. The solver class could be self-contained, and look like:
PoissonEquationSolver:
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b 2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”,
“mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over
quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and assemble bsurfi =
R Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over
quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and assemble bsurfi =
R Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and assemble bsurfi =
R Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and assemble bsurfi =
R Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and assemble bsurfi =
R Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and
assemble bsurfi = R
Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R
Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and
assemble bsurfi = R
Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into
account (using boundaryConditions again). 6 Solve the linear system
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R
Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and
assemble bsurfi =
R
Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into
account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R
Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and
assemble bsurfi =
R
Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into
account (using boundaryConditions again).
PoissonEquationSolver:
Solve(mesh,abstractForce,boundaryConditions)
The Solve method needs to:
1 Initialise a matrix K and vector b
2 Set up stiffness matrix Kij=R
ΩφiφjdV
1 Loop over elements of mesh (“mesh.GetNumElements()”, “mesh.GetElement(i)”)
2 For each element set-up the elemental stiffness matrix – loop over quadrature points, call element.GetJacobian() etc
3 Add elemental contribution to K
3 Similarly, loop over elements and assemble bvol
i =
R
Ωf φidV
4 Loop over Neumann boundary elements (using boundaryConditions) and
assemble bsurfi =
R
Γ2g φidS
5 Alter the linear system K U = bvol+ bsurf to take the Dirichlet BCs into
account (using boundaryConditions again).
A (possible) more complete interface PoissonEquationSolver: PoissonEquationSolver(mesh,abstractForce,boundaryConditions) Solve() PlotSolution() PlotForce() ComputeQOI() WriteSolutionToFile(filename)