Analytical Solution#

If the problem being simulated has a known analytical solution, or an exact solution is imposed (manufactured solutions) it can be added in this section. The default parameters are:

subsection analytical solution
 set enable                = false
 set verbosity             = quiet
 set filename              = L2Error
 subsection uvwp
   set Function expression = 0; 0; 0  # In 2D : u;v;p
     or
   set Function expression = 0; 0; 0; 0  #In 3D u;v;w;p
 end
 subsection temperature
   set Function expression = 0
 end
 subsection tracer
   set Function expression = 0
 end
 subsection VOF
   set Function expression = 0
 end
 subsection cahn hilliard
   set Function expression = 0; 0 # phase order parameter; chemical potential
 end
end
  • The enable parameter is set to true if the problem has an analytical solution. This enables the calculation of the analytical solution and the \(L^2\) norm of the error.

    The \(L^2\) norm of the error is calculated as

    \[L^2 = \int_\Omega (u-u_a)^2 \mathrm{d} \Omega\]

    where \(u\) is the numerical solution and \(u_a\) is the analytical solution.

  • The verbosity parameter enables printing the L2 error after each mesh refinement if it is set to verbose and if enable is true.

  • The filename parameter sets the file name to output the L2 error norm if enable is true.

Analytical solutions for all physics are supported. They are all declared in their own subsection:

  • uvwp: Analytical solution for the velocity and pressure fields obtained from fluid dynamics. The expression must provide \(u\), \(v\) and \(p\) for a 2D simulation and \(u\), \(v\), \(w\) and \(p\) for a 3D simulation.

  • temperature: Analytical solution for temperature obtained with the heat transfer physics.

  • tracer: Analytical solution for the tracer physics.

  • VOF: Analytical solution for the VOF field.

  • cahn hilliard: Analytical solution for the phase order and the chemical potential of the Cahn-Hilliard physics.

Note

The variables x, y, z (3D) and t (time-dependent) can be used in the function expressions.

In all subsections, you can add a Function constants parameter that will act as a constant in the Function expression.

Ex:

subsection analytical solution
 set enable                = true
 set verbosity             = true
 set filename              = L2Error
 subsection uvwp
   set Function constants = A=2.0
   set Function expression = A*y; -A*x; 0
 end
end

Note

A \(\pi\) variable is already defined as both pi and Pi

Your function expression can also contain common functions such as \(\sin\), \(\cos\) as well as if statements.

Ex.

subsection analytical solution
 set enable                = true
 set verbosity             = true
 set filename              = L2Error
 subsection phase
   set Function expression = if(sin(x) > pi, 1, 0)
 end
end

Note

The first parameter in the if() function is the statement. If this statement is true, then the function expression takes the second parameter as value. If this statement is false, the function expression takes the third parameter as value. In this example, the analytical phase will vary within the calculation domain.