Equation-Based Modeling
© Copyright 2013 COMSOL. COMSOL, COMSOL Multiphysics, Capture the Concept, COMSOL Desktop, and LiveLink are either registered trademarks or trademarks of COMSOL AB. All other trademarks are the property of their respective owners, and COMSOL AB and its subsidiaries and products are not affiliated with, endorsed by, sponsored by, or supported by those trademark owners. For a list of such trademark owners, see http://www.comsol.com/tm
fauuuuctud
tue aa
)(2
2
Multiphysics and Single-Physics Simulation Platform
• Mechanical, Fluid, Electrical, and Chemical Simulations
• Multiphysics - Coupled Phenomena– Two or more physics phenomena that affect each other with no
limitation on• which combinations• how many combinations
• Single Physics– One integrated environment – different physics and applications– One day you work on Heat Transfer, next day Structural
Analysis, then Fluid Flow, and so on– Same workflow for any type of modeling
• Enables cross-disciplinary product development and a unified simulation platform
Highly Customizable and Adaptable
• Create your own multiphysics couplings• Customize material properties and boundary
conditions– Type in mathematical expressions, combine with look-up
tables and function calls• User-interfaces for differential and algebraic equations• Parameterize on material properties, boundary
conditions, geometric dimensions, and more• High-Performance Computing (HPC)
– Multicore & Multiprocessor: Included with any license type
– Clusters & Cloud: With floating network licenses
The COMSOL Multiphysics® 4.3b Product Suite
Equation-Based Modeling
• Partial Differential Equations (PDEs)– PDE Interfaces– Boundary Conditions
• Ordinary Differential Equations (ODEs)– Global ODEs– Distributed ODEs
• Algebraic Equations– Global algebraic equations– Distributed algebraic equations
When is Equation-Based Modeling Needed?
• Try to avoid equation-based modeling if possible!– Using built-in physics interfaces enables ready-made postprocessing variables
and other tools for faster model setup with much lower risk of human error
• Applications that previously required equation-based modeling but now has a dedicated physics interface:– Fluid-Structure Interaction (Structural Mechanics Module, MEMS Module)– Surface adsorption and reactions (Chemical Reaction Engineering Module,
Plasma Module)– Shell-Acoustics and Piezo-Acoustics (Acoustics Module)– Thermoacoustics (Acoustics Module)– and many more…
When is Equation-Based Modeling Needed?
• Try to avoid equation-based modeling if possible!• But: we don’t have every imaginable physics equation built-
into COMSOL (yet!). So there is sometimes a need for custom modeling.
Custom-Modeling in COMSOL
• COMSOL Multiphysics allows you to model with PDEs or ODEs directly:– Use one of the equation-template user interfaces
• You do *not* need to write “user-subroutines” in COMSOL to implement your own equation!– Benefit: COMSOL’s nonlinear solver gets all the nonlinear info with
gradients and all. Faster and more robust convergence.
Customization Approaches
• Four modeling approaches:1. Ready-made physics interfaces2. First principles with the equation templates3. Start with ready-made physics interface and add additional terms.4. Start with a ready-made physics interface and add your own
separate equation (PDE,ODE) to represent physics that is not already available as a ready-made application mode
• Also: – The Physics Builder lets you create your own user interfaces that hides the
mathematics for your colleagues and customers
PDEs
Linear Model Problems: Fundamental Phenomena
• Laplace’s equation
• Heat equation
• Wave equation
• Helmholtz equation
• Convective Transport equation
0 u
0)( ukut
0)( uutt
uu )(
0 xt buu
COMSOL PDE Modes: Graphical User Interfaces
• Coefficient form• General form• Weak form
• All these can be used for scalar equations or systems• Which to use?
– Whichever is more convenient for you and your simulation needs
Coefficient Form
• Coefficient Matching Example: Poisson’s equation
rhuhgquuuc T )(n
inside domain
on boundary
1 u0u
inside subdomain
on subdomain boundary
Implies c=f=h=1 and all other coefficients are 0.
fauuuuctud
tue aa
)(2
2
Demo:Block: 10x1x1
PDE: default Poisson’s equation with unknown u.
Dirichlet boundary condition everywhere: u=0
d(u,x) with no Recover smoothing
d(u,x) with Recover smoothing
The Recover feature applies “polynomial-preserving recovery” on the partial derivatives (gradients).
Higher-order approximation of the solution on a patch of mesh elements around each mesh vertex.
Also available as ppr operator.
Coefficient Form, Interpretations
mass damping/mass
diffusion
convection
source
convection
absorption
source
fauuuuctud
tue aa
)(2
2
mass damped mass
elastic stress initial/thermal stress
body force (gravitation)
a
aed
cc
u
2
2 ( )a ae d c a ft t
u u u u u u
Coefficient Form, Structural Analysis Wave Equation
density
damping coefficient
stress, u= displacement vectorstiffness, “spring constant”
accumulation/storage
diffusion
convection
source
convection
absorption
source
Coefficient Form, Transport Diffusion Equation
fauuuuctud
tue aa
)(2
2
fauuuuctud
tue aa
)(2
2
0
0
2
2
tutu
Coefficient Form, Steady-State Equation
diffusion Helmholtz term
source2
2
( )
2
c u k u f
a k
k
Helmholtz equation:
Coefficient Form, Frequency-Response Wave Equation
Wave number
Wave length
fauuuuctud
tue aa
)(2
2
Demo:lambda=2.5
k=2*pi/lambda
a= - k^2
f=0
u=1 one end
u=0 other end
Complex Arithmetics
• Can compute:real(w)imag(w)abs(w)arg(w)conj(w)
General Form – A more compact formulation
• inside domain
• on domain boundary
• For Poisson’s equation, the corresponding general form implies
• All other coefficients are 0
RuRG
T
0
n
uyux .uR
1F
Ftud
tue aa
2
2
Weak Form• Think of the weak form as a generalization of the principal of virtual
work (for those familiar with that) with virtual displacement du– The test function n ~ du
• Convection-diffusion equation:
• Multiply by test function n and integrate:
• Integrate by parts and use boundary conditions:
• In COMSOL you can type the integrands of this integral expression: Weak Form PDE
Typing the Weak Form
c*grad(u) ·grad(test(u))=c*grad(u) ·test(grad(u))=
c*(ux*test(ux)+uy*test(uy)+uz*test(uz))
Note: COMSOL convention has the integral in the right-hand side so additional negative
sign needed in the GUI
2
2 ( )a au ue d c u u u au fu t
accumulation/storage
diffusion
source
Transient Diffusion Equation ~ Heat Equation
sourceheat volume
fkcCda
“Heat Source” f=1
“Cooling” u=0 at ends
Demo:c=1
da=1
f=0
Transient 0->100 s
PDEs+ODEs
2
2 ( )a au ue d c u u u au fu t
Transient Diffusion Equation + ODE
integral volumeof integral e tim
solution of integral volume
dtUw
dVuU
t
V
What if we wish to measure the global accumulation of “heat” over time?
2
2 ( )a au ue d c u u u au fu t
Transient Diffusion Equation + ODE
0],[ 10
Uwt
Udtdw
dtUw
dVuU
ttt
V
=> This is a Global ODE in the global state variable w
What if we wish to measure the global accumulation of “heat” over time?
Demo:Global Equation ODE
Same time-dependent problem as earlier
Time-dependent 0-100
Volume integration of u
ODE: wt-U
PDEs + Distributed ODEs
2
2 ( )a au ue d c u u u au fu t
Transient Diffusion Equation + Distributed ODE
solution of integral timelocal ),,( ),,( dtzyxuzyxPt
What if we get “damage” from local accumulation of “heat”.
Example of real application: bioheating
We want to visualize the P-field to assess local damage.
Let’s assume damage happens where P>20.
Disclaimer: There is no need to use equation-based modeling for bioheating in COMSOL. You are better off using the preset user interface options of the Heat Transfer Module.
Transient Diffusion Equation + Distributed ODE
solution of integral timelocal ),,( ),,( dtzyxuzyxPt
What if we get “damage” from local accumulation of “heat”.
Example of real application: bioheating
spacein point each at udtdP
2
2 ( )a au ue d c u u u au fu t
Transient Diffusion Equation + Distributed ODE
solution of integral timelocal udtdP
But this can be seen as a PDE with no spatial derivatives =
= Distributed ODE
Use coefficient form with unknown field P, c = 0, f = u, da=1
Let all other coefficients be zero
Or use Domain ODEs and DAEs interface
2
2 ( )a au ue d c u u u au fu t
Volume where P>20 and we get damage
Demo:Distributed ODE
Same time-dependent problem as earlier
Time-dependent 0-100
Volume integration of u
ODE: wt-U
Distributed Algebraic Equations
Example: Ideal gas law
• Assume u=(u,v,w) and p given by Navier-Stokes• Want to solve Convection-Conduction in gas:
• given by ideal gas law:
• Easy - analytical
0u)( TCTk
RTpM
Example: Non-ideal gas law
• Assume u=(u,v,w) and p given by Navier-Stokes• Want to solve Convection-Conduction in gas:
• given by non-ideal gas law: • Needed for high molecular weight at very high pressures• Difficult – implicit equation• How to proceed?
0)1)((* 2 DCBpA
0u)( TCTk
Example: Non-ideal gas law
• How to solve:• Third order equation in • Pressure p is function of space• So: this is an algebraic equation at each point in space!
0)1)((* 2 DCBpA
Distributed Algebraic Equation
• So: this is an algebraic equation at each point in space• See as PDE with no space or time derivatives!
– A*(p+B*u^2)*(1-C*u)-D*u– Here we let: A=1,B=2,C=3, D=4, p=x*y
• How: Put the entire equation in the source (f) term and zero out the rest
• Or, use user interface for Domain ODEs and DAEs
The solution u corresponding to the equation A*(p+B*u^2)*(1-C*u)-D*u, where p=x*y is spatially varying.Here the equation is solved for each point within the unit square.
Distributed Algebraic Equation
• What about nonlinear equations with multiple solutions?• Which solution do you get?• For simplicity, consider the equation (u-2)^2-p=0, where p is a constant• This can be entered as earlier with an f=(u-2)^2-p• The solution is easy to get analytically: u=2±sqrt(p)• The solution you get will depend on the Initial Guess given by the PDE Physics
Interface
• If we let p=x*y and let our modeling region be the unit square, then at (x,y)=(0,0) we should get the unique solution u=2 but at (x,y)=(1,1) we get 1 or 3 depending on our starting guess (and also the convergence region of the solver). See next slide.
Distributed Algebraic Equation
u=3
u=2
u=1u=2
End of Presentation