finite elements libmesh

121
Introduction Object Models System Assembly Examples Summary libMesh Finite Element Library Roy Stogner [email protected] Derek Gaston [email protected] 1 Univ. of Texas at Austin 2 Sandia National Laboratories Albuquerque,NM August 22, 2007

Upload: m-reza-rahmati

Post on 05-Jun-2015

336 views

Category:

Technology


10 download

TRANSCRIPT

Page 1: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

libMesh Finite Element Library

Roy [email protected]

Derek [email protected]

1Univ. of Texas at Austin

2Sandia National LaboratoriesAlbuquerque,NM

August 22, 2007

Page 2: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Outline1 Introduction2 Object Models

Core ClassesBVP Framework

3 System AssemblyBasic ExampleCoupled VariablesEssential Boundary Conditions

4 ExamplesFluid DynamicsBiologyMaterial Science

5 Summary

Page 3: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is not

A physics implementation.

A stand-alone application.

libMesh is

A software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 4: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh is

A software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 5: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh is

A software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 6: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh is

A software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 7: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh isA software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 8: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh isA software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 9: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Goals

libMesh is notA physics implementation.

A stand-alone application.

libMesh isA software library and toolkit.

Classes and functions for writing parallel adaptivefinite element applications.

An interface to linear algebra, meshing, partitioning,etc. libraries.

Page 10: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

For most applications weassume there is a BoundaryValue Problem to beapproximated in a FiniteElement function space

M∂u∂t

= F(u) ∈ Ω

G(u) = 0 ∈ Ω

u = uD ∈ ∂ΩD

N(u) = 0 ∈ ∂ΩN

u(x, 0) = u0(x)

δΩD

δΩN

Ω

Page 11: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Associated to Ω is theMesh data structure

A Mesh is basically acollection of geometricelements and nodes

Ωh :=⋃

e

Ωe

Ωh

Page 12: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Object Oriented Programming

Abstract Base Classes define user interfaces.

Concrete Subclasses implement functionality.

One physics code can work with manydiscretizations.

Page 13: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Object Oriented Programming

Abstract Base Classes define user interfaces.

Concrete Subclasses implement functionality.

One physics code can work with manydiscretizations.

Page 14: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Object Oriented Programming

Abstract Base Classes define user interfaces.

Concrete Subclasses implement functionality.

One physics code can work with manydiscretizations.

Page 15: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Object Oriented Programming

Abstract Base Classes define user interfaces.

Concrete Subclasses implement functionality.

One physics code can work with manydiscretizations.

Page 16: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Geometric Element Classes

Elem#_nodes: Node **#_neighbors: Elem **#_parent: Elem *#_children: Elem **#_*flag: RefinementState#_p_level: unsigned char#_subdomain_id: unsigned char

+n_faces,sides,vertices,edges,children(): unsigned int+centroid(): Point+hmin,hmax(): Real

NodeElem FaceEdge Cell InfQuad InfCell

Prism Hex Pyramid Tet

Hex8 Hex20 Hex27

DofObject-_n_systems: unsigned char-_n_vars: unsigned char *-_n_comp: unsigned char **-_dof_ids: unsigned int **-_id: unsigned int-_processor_id: unsigned short int

NodeAbstract interfacegives mesh topology

Concreteinstantiations ofmesh geometry

Hides element typefrom mostapplications

Page 17: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Finite Element Classes

FEBase

+phi, dphi, d2phi

+quadrature_rule, JxW

+reinit(Elem)

+reinit(Elem,side)

Lagrange

Hermi te

Hierarchic

Monomial

Finite Element objectbuilds data for eachGeometric object

User only deals withshape function,quadrature data

Page 18: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Core Features

Mixed element geometries in unstructured grids

Adaptive mesh h refinement with hanging nodes, prefinement

Integration w/ PETSc, LASPack, METIS, ParMETIS,Triangle, TetGen

Support for UNV, ExodusII, Tecplot, GMV, UCD files

Mesh creation, modification utilities

Page 19: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 20: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 21: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 22: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 23: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 24: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Degree of Freedom Handling

DofObject subclasses store global Degree ofFreedom indices

DofMap class assigns indices to a partitioned mesh

FE classes calculate hanging node, periodicconstraints

DofMap class applies constraints

System class handles AMR/C projections

Page 25: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Generic Constraint Calculations

To maintain function space continuity, constrain “hangingnode” Degrees of Freedom coefficients on fine elementsin terms of DoFs on coarse neighbors.

uF = uC∑i

uFi φF

i =∑

j

uCj φC

j

Akiui = Bkjuj

ui = A−1ki Bkjuj

Integrated values (and fluxes, for C1 continuity) giveelement-independent matrices:

Aki ≡ (φFi , φF

k )

Bkj ≡ (φCj , φC

k )

Page 26: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

Generic Projection Calculations

Upon element coarsening (or refinement in non-nestedspaces):

Copy nodal Degree of Freedom coefficients

Project edge DoFs, holding nodal DoFs constant

Project face DoFs, holding nodes/edges constant

Project interior DoFs, holding boundaries constant

Advantages / Disadvantages

Requires only local solves

Consistent in parallel

May violate physical conservation laws

Page 27: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel code

PetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial code

Mesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 28: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial code

Mesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 29: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial code

Mesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 30: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial code

Mesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 31: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial code

Mesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 32: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial codeMesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 33: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial codeMesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 34: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial codeMesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 35: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

libMesh Parallelization

Parallel codePetscVector, DistributedVector classes for LinearAlgebra

Parallel assembly, error indicators, etc.

Mesh partitioning with ParMETIS, etc.

Serial codeMesh storage on every node

DoF renumbering, constraint calculations

Refinement/Coarsening flagging

Mesh, solution I/O

Page 36: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Core Classes

ParallelMesh

Parallel subclassing of MeshBase

Start from unstructured Mesh class

Add methods to delete, reconstruct non-semilocalElem and Node objects

Parallelize DofMap methods

Parallelize MeshRefinement methods

Add parallel or chunked I/O support

Add load balancing support

Also want parallel BoundaryInfo, BoundaryMesh, Data,Function, Generation, Modification, Smoother, and Toolsclasses

Page 37: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

BVP Framework

Boundary Value Problem Framework Goals

GoalsImproved test coverage and reliability

Hiding implementation details from user code

Rapid prototyping of new formulations

Physics-dependent error estimators

MethodsObject-oriented System and Solver subclasses

Factoring common patterns into library code

Per-element Numerical Jacobian verification

Page 38: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

BVP Framework

FEM System Classes

FEMSystem+elem_solution: DenseVector<Number>+elem_residual: DenseVector<Number>+elem_jacobian: DenseMatrix<Number>#elem_fixed_solution: DenseVector<Number>#*_fe_var: std::vector<FEBase *>#elem: Elem *

+*_time_derivative(request_jacobian)+*_constraint(request_jacobian)+*_postprocess()

NavierStokesSystem

LaplaceYoungSystem

CahnHilliardSystem

SurfactantSystem

Generalized IBVPrepresentation

FEMSystem does allinitialization, globalassembly

User code onlyneeds weighted timederivative residuals(∂u

∂t , vi) = Fi(u) and/orconstraintsGi(u, vi) = 0

Page 39: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

BVP Framework

ODE Solver Classes

TimeSolver

+*_residual(request_jacobian)+solve()+advance_timestep()

SteadySolver EulerSolver

AdamsMoultonSolver EigenSolver

Calls user code oneach element

Assembleselement-by-elementtime derivatives,constraints, andweighted oldsolutions

Page 40: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

BVP Framework

Nonlinear Solver Classes

NonlinearSolver+*_tolerance+*_max_iterations

+solve()

QuasiNewtonSolverLinearSolver

ContinuationSolver

Acquires residuals,jacobians fromFEMSystemassembly

Handles inner loops,inner solvers andtolerances,convergence tests,etc

Page 41: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

System Assembly

For simplicity we will focus on the weighted residualstatement arising from the Poisson equation, with∂ΩN = ∅,

(R(uh), vh) :=∫Ωh

[∇uh · ∇vh − fvh

]dx = 0 ∀vh ∈ Vh

Page 42: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The element integrals . . .∫Ωe

[∇uh · ∇vh − fvh

]dx

are written in terms of the local “φi” basis functions

Ns∑j=1

uj

∫Ωe

∇φj · ∇φi dx−∫

Ωe

fφi dx , i = 1, . . . , Ns

This can be expressed naturally in matrix notation as

KeUe− Fe

Page 43: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The element integrals . . .∫Ωe

[∇uh · ∇vh − fvh

]dx

are written in terms of the local “φi” basis functions

Ns∑j=1

uj

∫Ωe

∇φj · ∇φi dx−∫

Ωe

fφi dx , i = 1, . . . , Ns

This can be expressed naturally in matrix notation as

KeUe− Fe

Page 44: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The element integrals . . .∫Ωe

[∇uh · ∇vh − fvh

]dx

are written in terms of the local “φi” basis functions

Ns∑j=1

uj

∫Ωe

∇φj · ∇φi dx−∫

Ωe

fφi dx , i = 1, . . . , Ns

This can be expressed naturally in matrix notation as

KeUe− Fe

Page 45: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals are performed on a “reference” elementΩe, transformed via Lagrange basis to the geometricelement.

eΩx ξ)x(

ξ

Page 46: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals are performed on a “reference” elementΩe, transformed via Lagrange basis to the geometricelement.

eΩx x(ξ)

ξ

Ωe

The Jacobian of the map x(ξ) is J.

Fei =

∫Ωe

fφidx =

∫Ωe

f (x(ξ))φi|J|dξ

Page 47: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals are performed on a “reference” elementΩe, transformed via Lagrange basis to the geometricelement.

eΩx ξ)x(

ξ

Ωe

Page 48: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals on the “reference” element areapproximated via numerical quadrature.

The quadrature rule has Nq points “ξq” and weights“wq”.

Page 49: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals on the “reference” element areapproximated via numerical quadrature.

The quadrature rule has Nq points “ξq” and weights“wq”.

Page 50: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals on the “reference” element areapproximated via numerical quadrature.

The quadrature rule has Nq points “ξq” and weights“wq”.

Fei =

∫Ωe

fφi|J|dξ

≈Nq∑

q=1

f (x(ξq))φi(ξq)|J(ξq)|wq

Page 51: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The integrals on the “reference” element areapproximated via numerical quadrature.

The quadrature rule has Nq points “ξq” and weights“wq”.

Keij =

∫Ωe

∇φj · ∇φi |J|dξ

≈Nq∑

q=1

∇φj(ξq) · ∇φi(ξq)|J(ξq)|wq

Page 52: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

At the qth quadrature point, LibMesh can providevariables including:

Code Math Description

JxW[q] |J(ξq)|wq Jacobian times weight

phi[i][q] φi(ξq) value of i th shape fn.

dphi[i][q] ∇φi(ξq) value of i th shape fn. gradient

d2phi[i][q] ∇∇φi(ξq) value of i th shape fn. Hessian

xyz[q] x(ξq) location of ξq in physical space

normals[q] ~n(x(ξq)) normal vector at x on a side

Page 53: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Page 54: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Fei =

Nq∑q=1

f (x(ξq))φi(ξq)|J(ξq)|wq

Page 55: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Fei =

Nq∑q=1

f (x(ξq))φi(ξq)|J(ξq)|wq

Page 56: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Fei =

Nq∑q=1

f (x(ξq))φi(ξq)|J(ξq)|wq

Page 57: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Fei =

Nq∑q=1

f (x(ξq))φi(ξq)|J(ξq)|wq

Page 58: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Keij =

Nq∑q=1

∇ξφj(ξq) · ∇ξφi(ξq)|J(ξq)|wq

Page 59: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Keij =

Nq∑q=1

∇ξφj(ξq) · ∇ξφi(ξq)|J(ξq)|wq

Page 60: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

The LibMesh representation of the matrix and rhsassembly is similar to the mathematical statements.

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q] * f(xyz[q]) * phi[i][q] ;

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q] *( dphi[j][q]*dphi[i][q] );

Keij =

Nq∑q=1

∇ξφj(ξq) · ∇ξφi(ξq)|J(ξq)|wq

Page 61: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

Convection-Diffusion Equation

The matrix assembly routine for the linearconvection-diffusion equation,

−k∆u + b · ∇u = f

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q]*f(xyz[q])*phi[i][q];

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q]*( k*(dphi[j][q]*dphi[i][q])

+ ( b*dphi[j][q] )*phi[i][q]);

Page 62: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

Convection-Diffusion Equation

The matrix assembly routine for the linearconvection-diffusion equation,

−k∆u + b · ∇u = f

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q]*f(xyz[q])*phi[i][q];

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q]*( k*(dphi[j][q]*dphi[i][q])

+ ( b*dphi[j][q] )*phi[i][q]);

Page 63: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Basic Example

Convection-Diffusion Equation

The matrix assembly routine for the linearconvection-diffusion equation,

−k∆u + b · ∇u = f

for (q=0; q<Nq; ++q)for (i=0; i<Ns; ++i)

Fe(i) += JxW[q]*f(xyz[q])*phi[i][q];

for (j=0; j<Ns; ++j)Ke(i,j) += JxW[q]*( k*(dphi[j][q]*dphi[i][q])

+ ( b*dphi[j][q] )*phi[i][q]);

Page 64: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

We have an array of submatrices: Ke[ ][ ]

Page 65: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

We have an array of submatrices: Ke[ 1][ 1]

Page 66: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

We have an array of submatrices: Ke[ 2][ 2]

Page 67: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

We have an array of submatrices: Ke[ 3][ 2]

Page 68: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

And an array of right-hand sides: Fe[] .

Page 69: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

And an array of right-hand sides: Fe[ 1] .

Page 70: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

For multi-variable systems like Stokes flow,

∇p− ν∆u = f∇ · u = 0

∈ Ω ⊂ R2

The element stiffness matrix concept can extended toinclude sub-matrices Ke

u1u1Ke

u1u2Ke

u1p

Keu2u1

Keu2u2

Keu2p

Kepu1

Kepu2

Kepp

Ueu1

Ueu2

Uep

− Fe

u1

Feu2

Fep

And an array of right-hand sides: Fe[ 2] .

Page 71: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Coupled Variables

Stokes Flow

The matrix assembly can proceed in essentially thesame way.

For the momentum equations:

for (q=0; q<Nq; ++q)for (d=0; d<2; ++d)

for (i=0; i<Ns; ++i) Fe[d] (i) += JxW[q]*f(xyz[q], d)*phi[i][q];

for (j=0; j<Ns; ++j)Ke[d][d] (i,j) +=

JxW[q]* nu*(dphi[j][q]*dphi[i][q]);

Page 72: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Essential Boundary Data

Dirichlet boundary conditions can be enforced afterthe global stiffness matrix K has been assembledThis usually involves

1 placing a “1” on the main diagonal of the globalstiffness matrix

2 zeroing out the row entries3 placing the Dirichlet value in the rhs vector4 subtracting off the column entries from the rhs

k11 k12 k13 .k21 k22 k23 .k31 k32 k33 .. . . .

,

f1f2f3.

1 0 0 00 k22 k23 .0 k32 k33 .0 . . .

,

g1

f2 − k21g1

f3 − k31g1

.

Page 73: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Essential Boundary Data

Dirichlet boundary conditions can be enforced afterthe global stiffness matrix K has been assembledThis usually involves

1 placing a “1” on the main diagonal of the globalstiffness matrix

2 zeroing out the row entries

3 placing the Dirichlet value in the rhs vector4 subtracting off the column entries from the rhs

k11 k12 k13 .k21 k22 k23 .k31 k32 k33 .. . . .

,

f1f2f3.

1 0 0 00 k22 k23 .0 k32 k33 .0 . . .

,

g1

f2 − k21g1

f3 − k31g1

.

Page 74: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Essential Boundary Data

Dirichlet boundary conditions can be enforced afterthe global stiffness matrix K has been assembledThis usually involves

1 placing a “1” on the main diagonal of the globalstiffness matrix

2 zeroing out the row entries3 placing the Dirichlet value in the rhs vector

4 subtracting off the column entries from the rhs

k11 k12 k13 .k21 k22 k23 .k31 k32 k33 .. . . .

,

f1f2f3.

1 0 0 00 k22 k23 .0 k32 k33 .0 . . .

,

g1

f2 − k21g1

f3 − k31g1

.

Page 75: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Essential Boundary Data

Dirichlet boundary conditions can be enforced afterthe global stiffness matrix K has been assembledThis usually involves

1 placing a “1” on the main diagonal of the globalstiffness matrix

2 zeroing out the row entries3 placing the Dirichlet value in the rhs vector4 subtracting off the column entries from the rhs

k11 k12 k13 .k21 k22 k23 .k31 k32 k33 .. . . .

,

f1f2f3.

1 0 0 00 k22 k23 .0 k32 k33 .0 . . .

,

g1

f2 − k21g1

f3 − k31g1

.

Page 76: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Essential Boundary Data

Dirichlet boundary conditions can be enforced afterthe global stiffness matrix K has been assembledThis usually involves

1 placing a “1” on the main diagonal of the globalstiffness matrix

2 zeroing out the row entries3 placing the Dirichlet value in the rhs vector4 subtracting off the column entries from the rhs

k11 k12 k13 .k21 k22 k23 .k31 k32 k33 .. . . .

,

f1f2f3.

1 0 0 00 k22 k23 .0 k32 k33 .0 . . .

,

g1

f2 − k21g1

f3 − k31g1

.

Page 77: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Cons of this approach :

Works for an interpolary finite element basis but not ingeneral.May be inefficient to change individual entries oncethe global matrix is assembled.

Need to enforce boundary conditions for a genericfinite element basis at the element stiffness matrixlevel.

Page 78: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Cons of this approach :Works for an interpolary finite element basis but not ingeneral.

May be inefficient to change individual entries oncethe global matrix is assembled.

Need to enforce boundary conditions for a genericfinite element basis at the element stiffness matrixlevel.

Page 79: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Cons of this approach :Works for an interpolary finite element basis but not ingeneral.May be inefficient to change individual entries oncethe global matrix is assembled.

Need to enforce boundary conditions for a genericfinite element basis at the element stiffness matrixlevel.

Page 80: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

Cons of this approach :Works for an interpolary finite element basis but not ingeneral.May be inefficient to change individual entries oncethe global matrix is assembled.

Need to enforce boundary conditions for a genericfinite element basis at the element stiffness matrixlevel.

Page 81: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

A “penalty” term is added to the standard weightedresidual statement

(R(u), v) +1ε

∫∂ΩD

(u− uD)v dx︸ ︷︷ ︸penalty term

= 0 ∀v ∈ V

Here ε 1 is chosen so that, in floating pointarithmetic, 1

ε+ 1 = 1

ε.

This weakly enforces u = uD on the Dirichletboundary, and works for general finite element bases.

Page 82: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

A “penalty” term is added to the standard weightedresidual statement

(R(u), v) +1ε

∫∂ΩD

(u− uD)v dx︸ ︷︷ ︸penalty term

= 0 ∀v ∈ V

Here ε 1 is chosen so that, in floating pointarithmetic, 1

ε+ 1 = 1

ε.

This weakly enforces u = uD on the Dirichletboundary, and works for general finite element bases.

Page 83: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

A “penalty” term is added to the standard weightedresidual statement

(R(u), v) +1ε

∫∂ΩD

(u− uD)v dx︸ ︷︷ ︸penalty term

= 0 ∀v ∈ V

Here ε 1 is chosen so that, in floating pointarithmetic, 1

ε+ 1 = 1

ε.

This weakly enforces u = uD on the Dirichletboundary, and works for general finite element bases.

Page 84: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

LibMesh provides:

A quadrature rule with Nqf points and JxW f[]

A finite element coincident with the boundary facethat has shape function values phi f[][]

for (qf=0; qf<Nqf; ++qf) for (i=0; i<Nf; ++i)

Fe(i) += JxW_f[qf]*penalty * uD(xyz[q]) *phi_f[i][qf];

for (j=0; j<Nf; ++j)Ke(i,j) += JxW_f[qf]*

penalty *phi_f[j][qf]*phi_f[i][qf];

Page 85: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

LibMesh provides:

A quadrature rule with Nqf points and JxW f[]

A finite element coincident with the boundary facethat has shape function values phi f[][]

for (qf=0; qf<Nqf; ++qf) for (i=0; i<Nf; ++i)

Fe(i) += JxW_f[qf]*penalty * uD(xyz[q]) *phi_f[i][qf];

for (j=0; j<Nf; ++j)Ke(i,j) += JxW_f[qf]*

penalty *phi_f[j][qf]*phi_f[i][qf];

Page 86: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Essential Boundary Conditions

LibMesh provides:

A quadrature rule with Nqf points and JxW f[]

A finite element coincident with the boundary facethat has shape function values phi f[][]

for (qf=0; qf<Nqf; ++qf) for (i=0; i<Nf; ++i)

Fe(i) += JxW_f[qf]*penalty * uD(xyz[q]) *phi_f[i][qf];

for (j=0; j<Nf; ++j)Ke(i,j) += JxW_f[qf]*

penalty *phi_f[j][qf]*phi_f[i][qf];

Page 87: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Introduction

Laplace-Young equation model surface tension effects forenclosed liquids.

Combining surface tension, gravity and contact the energyfunctional for Laplace-Young is:∫

Ω

√1 + |∇u|2 dΩ +

∫Ω

12κu2 dΩ−

∫∂Ω

σu ds

Where κ is the ratio of surface energy to gravitationalenergy and u is the height of the liquid.

While the weak formulation of the stationary condition isgiven by:(

∇u√1 + |∇u|2

,∇ϕ

+ κ (u, ϕ)Ω = σ (1, ϕ)∂Ω (1)

By specifying the parameter σ = cos(γ) (where γ is thecontact angle) along the boundary, the liquid height u canbe solved for.

Page 88: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Introduction

Laplace-Young equation model surface tension effects forenclosed liquids.

Combining surface tension, gravity and contact the energyfunctional for Laplace-Young is:∫

Ω

√1 + |∇u|2 dΩ +

∫Ω

12κu2 dΩ−

∫∂Ω

σu ds

Where κ is the ratio of surface energy to gravitationalenergy and u is the height of the liquid.

While the weak formulation of the stationary condition isgiven by:(

∇u√1 + |∇u|2

,∇ϕ

+ κ (u, ϕ)Ω = σ (1, ϕ)∂Ω (1)

By specifying the parameter σ = cos(γ) (where γ is thecontact angle) along the boundary, the liquid height u canbe solved for.

Page 89: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Introduction

Laplace-Young equation model surface tension effects forenclosed liquids.

Combining surface tension, gravity and contact the energyfunctional for Laplace-Young is:∫

Ω

√1 + |∇u|2 dΩ +

∫Ω

12κu2 dΩ−

∫∂Ω

σu ds

Where κ is the ratio of surface energy to gravitationalenergy and u is the height of the liquid.

While the weak formulation of the stationary condition isgiven by:(

∇u√1 + |∇u|2

,∇ϕ

+ κ (u, ϕ)Ω = σ (1, ϕ)∂Ω (1)

By specifying the parameter σ = cos(γ) (where γ is thecontact angle) along the boundary, the liquid height u canbe solved for.

Page 90: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Introduction

Laplace-Young equation model surface tension effects forenclosed liquids.

Combining surface tension, gravity and contact the energyfunctional for Laplace-Young is:∫

Ω

√1 + |∇u|2 dΩ +

∫Ω

12κu2 dΩ−

∫∂Ω

σu ds

Where κ is the ratio of surface energy to gravitationalenergy and u is the height of the liquid.

While the weak formulation of the stationary condition isgiven by:(

∇u√1 + |∇u|2

,∇ϕ

+ κ (u, ϕ)Ω = σ (1, ϕ)∂Ω (1)

By specifying the parameter σ = cos(γ) (where γ is thecontact angle) along the boundary, the liquid height u canbe solved for.

Page 91: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Introduction

Laplace-Young equation model surface tension effects forenclosed liquids.

Combining surface tension, gravity and contact the energyfunctional for Laplace-Young is:∫

Ω

√1 + |∇u|2 dΩ +

∫Ω

12κu2 dΩ−

∫∂Ω

σu ds

Where κ is the ratio of surface energy to gravitationalenergy and u is the height of the liquid.

While the weak formulation of the stationary condition isgiven by:(

∇u√1 + |∇u|2

,∇ϕ

+ κ (u, ϕ)Ω = σ (1, ϕ)∂Ω (1)

By specifying the parameter σ = cos(γ) (where γ is thecontact angle) along the boundary, the liquid height u canbe solved for.

Page 92: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 93: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 94: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 95: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 96: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 97: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Instead of explicitly finding the Jacobian, we’ll use FEMSystem to finite difference the weak form.

element constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) Number u = interior_value(0, qp);Gradient grad_u = interior_gradient(0, qp);Number K = 1. / sqrt(1. + (grad_u * grad_u));

for (unsigned int i=0; i != n_u_dofs; i++) Fu(i) += JxW[qp] * (( _kappa * u * phi[i][qp] ) +

( K * grad_u * dphi[i][qp] ));

side constraint()

for (unsigned int qp=0; qp != n_qpoints; qp++) for (unsigned int i=0; i != n_u_dofs; i++)

Fu(i) -= JxW[qp] * _gamma * phi[i][qp] ;

0B@ ∇uq1 + |∇u|2

,∇ϕ

1CAΩ

+ κ (u, ϕ)Ω − σ (1, ϕ)∂Ω = 0 ∀ϕ ∈ V

Page 98: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Solution

An overkill solution containing 200,000 DOFs.

(a) 2D. (b) Contour Elevation.

Page 99: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Compressible Shocked Flow

Original compressible flow code written by Ben Kirkutilizing libMesh.

Solves both Compressible Navier Stokes and InviscidEuler.Includes both SUPG and a shock capturing scheme.

Page 100: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Compressible Shocked Flow

Original compressible flow code written by Ben Kirkutilizing libMesh.

Solves both Compressible Navier Stokes and InviscidEuler.

Includes both SUPG and a shock capturing scheme.

Page 101: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Compressible Shocked Flow

Original compressible flow code written by Ben Kirkutilizing libMesh.

Solves both Compressible Navier Stokes and InviscidEuler.Includes both SUPG and a shock capturing scheme.

Page 102: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Problem Specification

The problem studied is that of an oblique shockgenerated by a 10o wedge angle.

This problem has an exact solution for density whichis a step function.Utilizing libmesh’s exact solution capability the exactL2 error can be solved for.The exact solution is shown below:

Page 103: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Problem Specification

The problem studied is that of an oblique shockgenerated by a 10o wedge angle.

This problem has an exact solution for density whichis a step function.

Utilizing libmesh’s exact solution capability the exactL2 error can be solved for.The exact solution is shown below:

Page 104: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Problem Specification

The problem studied is that of an oblique shockgenerated by a 10o wedge angle.

This problem has an exact solution for density whichis a step function.Utilizing libmesh’s exact solution capability the exactL2 error can be solved for.

The exact solution is shown below:

Page 105: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Problem Specification

The problem studied is that of an oblique shockgenerated by a 10o wedge angle.

This problem has an exact solution for density whichis a step function.Utilizing libmesh’s exact solution capability the exactL2 error can be solved for.The exact solution is shown below:

Page 106: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Uniformly Refined Solutions

For comparison purposes, here is a mesh and asolution after 1 uniform refinement with 10890 DOFs.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

(c) Mesh after 1 uniformrefinement.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(d) Solution after 1 uni-form refinement.

Page 107: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

H-Adapted Solutions

A flux jump indicator was employed as the errorindcator along with a statistical flagging scheme.

Here is a mesh and solution after 2 adaptiverefinements containing 10800 DOFs:

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

(e) Mesh after 2 adapta-tions.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(f) Solution after 2 adap-tations.

Page 108: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

H-Adapted Solutions

A flux jump indicator was employed as the errorindcator along with a statistical flagging scheme.Here is a mesh and solution after 2 adaptiverefinements containing 10800 DOFs:

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

(g) Mesh after 2 adapta-tions.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(h) Solution after 2 adap-tations.

Page 109: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Redistributed Solutions

Redistribution utilizing the same flux jump indicator.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

(i) Mesh after 8 redistri-butions.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(j) Solution after 8 redis-tributions.

Page 110: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Redistributed and Adapted

Now combining the two, here are the mesh andsolution after 2 adaptations beyond the previousredistribution containing 10190 DOFs.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

(k) Mesh after 2 adap-tions.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(l) Solution after 2 adap-tations.

Page 111: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Solution Comparison

For a better comparison here are 3 of the solutions,each with around 11000 DOFs:

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(m) Uniform.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(n) Adaptive.

x

y

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

r

1.451.41.351.31.251.21.151.11.051

(o) R + H.

Page 112: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Error Plot

libmesh provides capability for computing error normsagainst an exact solution.

The exact solution is not in H1 therefore we onlyobtain the L2 convergence plot:

3.5 4.0 4.5 5.001 sfoD )N(gol

-2.2

-2.0

-1.8

-1.6

-1.4

-1.2

01)r

orrE2

L(gol

UniformAdaptivityRedist + Adapt

(p) LogLog plot of L2 vs DOFs.

Page 113: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Error Plot

libmesh provides capability for computing error normsagainst an exact solution.The exact solution is not in H1 therefore we onlyobtain the L2 convergence plot:

3.5 4.0 4.5 5.001 sfoD )N(gol

-2.2

-2.0

-1.8

-1.6

-1.4

-1.2

01)rorr

E2L(

gol

UniformAdaptivityRedist + Adapt

(q) LogLog plot of L2 vs DOFs.

Page 114: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Page 115: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Natural Convection

Tetrahedral mesh of “pipe” geometry. Stream ribbonscolored by temperature.

Page 116: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Surface-Tension-Driven Flow

Adaptive grid solution shown with temperaturecontours and velocity vectors.

Page 117: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Fluid Dynamics

Double-Diffusive Convection

Solute contours: a plume of warm, low-salinity fluid isconvected upward through a porous medium.

Page 118: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Biology

Tumor Angiogenesis

The tumor secretes a chemical which stimulatesblood vessel formation.

Page 119: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Material Science

Free Energy Formulation

Cahn-Hilliard systems model phase separation andinterface evolution

f (c,∇c) ≡ f0(c) + fγ(∇c)

fγ(∇c) ≡ ε2c

2∇c · ∇c

f0(c) ≡ NkT(c ln (c) + (1− c) ln (1− c)) + Nωc(1− c)

∂c∂t

= ∇ ·Mc∇(f ′0(c)− ε2

c∆c)

Page 120: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Material Science

Phase Separation - Spinodal Decomposition

Initial EvolutionInitial homogeneous blend quenched below critical T

Random perturbations anti-diffuse into two phasesdivided by narrow interfaces

Gradual coalescence of single-phase regions

Additional physics leads to pattern self-assembly

Page 121: Finite Elements libmesh

Introduction Object Models System Assembly Examples Summary

Summary

libMesh Development

Open Source (LGPL)

Leveraging existing libraries

Public site, mailing lists, CVS tree, examples, etc. athttp://libmesh.sf.net/

18 examples including:Infinite Elements for the wave equation.Helmholtz with complex numbers.Laplace in L-Shaped Domain.Biharmonic Equation.Using SLEPc for an Eigen Problem.Unsteady Navier Stokes.And More!