• No results found

Object-oriented scientific computing

N/A
N/A
Protected

Academic year: 2021

Share "Object-oriented scientific computing"

Copied!
65
0
0

Loading.... (view fulltext now)

Full text

(1)

Object-oriented scientific computing

Pras Pathmanathan

(2)
(3)

Main advantages of FE over FD

1 Deal with Neumann boundary conditions in a natural (systematic) way

(4)

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

(5)

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

(6)

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

(7)

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

(8)

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

(9)

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

(10)
(11)

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     

(12)

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     

(13)

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     

(14)

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

(15)

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

(16)

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

(17)

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

(18)

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

(19)

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

(20)

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

(21)

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

(22)

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

(23)

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

(24)

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

(25)
(26)

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)

(27)

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)

(28)

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.

(29)

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.

(30)

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.

(31)

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.

(32)

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.

(33)
(34)

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).

(35)

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),

(36)

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(ξ, η) = ξ

(37)

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

(38)

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

(39)

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

(40)

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

(41)

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

(42)

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

(43)

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

(44)

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

(45)

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

(46)

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

(47)

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

(48)

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

(49)

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

(50)

What are the self-contained ‘concepts’ (objects) that form the overall simulation code, and what functionality should each of these objects have?

(51)

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

(52)

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.

(53)

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)

(54)

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:

(55)

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).

(56)

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).

(57)

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).

(58)

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).

(59)

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).

(60)

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).

(61)

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

(62)

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).

(63)

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).

(64)

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).

(65)

A (possible) more complete interface PoissonEquationSolver: PoissonEquationSolver(mesh,abstractForce,boundaryConditions) Solve() PlotSolution() PlotForce() ComputeQOI() WriteSolutionToFile(filename)

References

Related documents

Based on the idea, we have put forward novel routing strategies for Barrat- Barthelemy- Vespignani (BBV) weighted network. By defining the weight of edges as

A model based on texture metrics, gradient information, Hessian matrix eigenvalues, and local statistics showed good results with accuracies up to 88.2%, an area under the ROC

(i) The maximum monthly amount that the loan holder may require the borrower to repay is the amount the borrower would have paid under the FFEL standard repayment plan based on

Self-transcendence Physical self Extrinsic Intrinsic Spirituality Community Affiliation Self-acceptance Physical health Safety Hedonism Financial success Image Popularity

The figure revealed higher rate of evolution of hydrogen gas by the blank solutions as compared to the evolution by solutions containing different concentrations of OC

Frederick Banting and Charles Best extracted insulin from bovine pancreas in 1922, who received the Nobel Prize for their contribution in Medical field with John

The feasibility of intermittent subcutaneous administration of a sulfadiazine-sulfa- merazine combination (2.5% aqueous solutions of the sodium salts in equal amounts) in. infants