Different modes allow to solved the ecoupled heat or stress system.
Different meshes can be used to perform a convergence study with given
exact solution.
# General# =======# - output_folder: Used as output folderoutput_folder:r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_stab# Meshes# ======# - meshes: List of input meshes in h5 format to run simulations onmeshes:-../mesh/ring0.h5-../mesh/ring1.h5-../mesh/ring2.h5-../mesh/ring3.h5-../mesh/ring4.h5# - ../mesh/ring5.h5# - ../mesh/ring6.h5# - ../mesh/ring7.h5# - ../mesh/ring8.h5# Numerical Parameters# ====================# - elements: Must contain the fields: theta, s, p, u, sigma# - fields: List of FEM parameters (shape, degree)# - shape: Element shape, e.g. Lagrange# - degree: Element degree, e.g. 2# - stabilization: Must contain cip and gls# - cip: Collection of Continous Interior Penalty (CIP) parameters# - enable: Enable CIP stabilization# - delta_theta: Stabilization of grad(T)*grad(T_test) over edge# - delta_u: Stabilization of grad(u)*grad(u_test) over edge# - delta_p: Stabilization of grad(p)*grad(p_test) over edge# - gls: Collection of Garlerkin Least Squares (GLS) parameters# - enable: Enable GLS stabilization# - tau_energy: Stabilization with energy eq. residual# - tau_heatflux: Stabilization with heatflux eq. residual# - tau_mass: Stabilization with mass eq. residual# - tau_momentum: Stabilization with momentum eq. residual# - tau_stress: Stabilization with stress eq. residualelements:theta:shape:Lagrangedegree:2s:shape:Lagrangedegree:2p:shape:Lagrangedegree:2u:shape:Lagrangedegree:2sigma:shape:Lagrangedegree:2stabilization:cip:enable:Truedelta_theta:1.0delta_u:1.0delta_p:0.01gls:enable:Falsetau_energy:0.001tau_heatflux:0.001tau_mass:0.01tau_momentum:0.01tau_stress:0.01# Formulation Parameters# ======================# - nsd: Number of spatial dimensions == 2# - mode: Formulation mode, one of heat, stress, r13# - kn: Knudsen numberkn# - heat_source: Heat source function for mode==heat||r13# - mass_source: Mass source function for mode==stress||r13# - body_force: Body force for mode==stress||r13nsd:2mode:r13heat_source:0mass_source:1.0 * (1.0 - (5.0*pow(R,2))/(18.0*pow(0.1,2))) * cos(phi)body_force:[0,0]# Region Parameters# =================# - regs: Dictionary of all mesh regions# - reg_id: Must contain the following parameters:# - kn: Knudsen number# Boundary Conditions# ===================# - bcs: Dictionary of all boundary IDs from mesh# - bc_id: must contain the following parameters# - chi_tilde: Refaction coefficient in Maxwell accomodation model# - theta_w: Value for temperature at wall# - u_t_w: Value for tangential velocity at wall# - u_n_w: Value for normal velocity at wall# - p_w: Value for pressure at wall# - epsilon_w: Inflow-model parameter <=> Weight of pressurebcs:3000:chi_tilde:1.0theta_w:1.0u_t_w:-10u_n_w:0p_w:0epsilon_w:03100:chi_tilde:1.0theta_w:0.5u_t_w:0u_n_w:0p_w:0epsilon_w:0# Convergence Study# =================# - enable: Enable convergence study on given meshes# - exact_solution: Path to exact solution in cpp-format to compare# - plot: Show errors in matplotlib window. PDF output is default# - write_systemmatrix: Writes out systemmatrix (LHS)# - rescale_pressure: Rescale numerical pressure result for zero mean# - relative_errors: Use relative errors. If esol=0, use absolute.convergence_study:enable:Trueexact_solution:esols/1_coeffs_sources_rot_noinflow.cppplot:Falsewrite_systemmatrix:Falserescale_pressure:Truerelative_error:True# Postprocessing# ==============# - write_pdfs: Write all solution fields as PDF plot# - write_vecs: Write all solution fields as vectors# - flows: List of BC IDs for <mass|heat> flow J=int_bc dot(<u|s>,n)dl# - line_integrals: List of line integral dicts:# - name: Name for output# - expr: Expression to evaluate# - start: Start point# - end: End point# - res: Sampling resolution of linepostprocessing:write_pdfs:Truewrite_vecs:Trueflows:[]line_integrals:-name:"avg(abs(uy(x,y=0.5)))"expr:abs(uy)/8start:[0,0.5]end:[8,0.5]res:10000-name:"avg(abs(uy(x,y=4.5)))"expr:abs(uy)/8start:[0,4.5]end:[8,4.5]res:10000# Parameter Study# ==============# - enable: Repeat simulation with different p. values (study)# - parameter_key: Key as list, e.g. ["elemenets", "p", "degree"]# - parameter_values: List of value for parameter, e.g. [0.01,0.1,1,10]parameter_study:enable:Trueparameter_key:["kn"]parameter_values:[1,2,3]
Further input examples can be found in the tests or examples
folders.
Possible order of methods in context of convergence study
(see main program):
“mesh=meshes[i=0]”,
“__init__”, “assemble()”,
“solve()”,
“write()”,
“…”,
“mesh=meshes[i+1]”,
“__init__”,
“…”
Return a DOLFIN scalar expression with predefined macros.
These macros include:
Name
Macro
CPP Replacement
Radius wrt. to \((0,0)\)
R
sqrt(pow(x[0],2)+pow(x[1],2))
Angle wrt. \((0,0)\)
phi
atan2(x[1],x[0])
The following expressions are therefore equal:
# expr1 is equal to expr2expr1=self.__createMacroScaExpr("R*cos(phi)")expr2=dolfin.Expression("R*cos(phi)",degree=2,R=dolfin.Expression("sqrt(pow(x[0],2)+pow(x[1],2))",degree=2),phi=dolfin.Expression("atan2(x[1],x[0])",degree=2),)
Assemble the weak form of the system, depending on the mode. This
routine contains the main implementation of a stable variational
formulation of the R13 system which allows equal order ansatz
spaces for all variables and correctly incorporates the R13
boundary conditions.
The system of partial differential equations results from the two
dimensional, linearized R13 equations of [1], that have been
derived from Boltzmann’s equation as a continuum model for
rarefied gas flows. The boundary conditions have been presented
in [2], while the variational formulation and its stabilization was
introduced in [3]. See also [4] for a general review and [5] for
the modified stable boundary conditions.
# Some solver paramssolver_parameters={"linear_solver":"gmres","preconditioner":"ilu"# or"linear_solver":"petsc","preconditioner":"ilu"# or"linear_solver":"direct"# or"linear_solver":"mumps"# or"linear_solver":"mumps"}# List all available solvers and preconditioners:list_linear_solver_methods()bicgstab|Biconjugategradientstabilizedmethodcg|Conjugategradientmethoddefault|defaultlinearsolvergmres|Generalizedminimalresidualmethodminres|Minimalresidualmethodmumps|MUMPS(MUltifrontalMassivelyParallelSparseDirect)petsc|PETScbuiltinLUsolverrichardson|Richardsonmethodsuperlu|SuperLUtfqmr|Transpose-freequasi-minimalresidualmethodumfpack|UMFPACK(UnsymmetricMultiFrontalsparseLUfactoriz.)# "direct" means "default" means "lu" of default backendprint(parameters["linear_algebra_backend"])# usually PETSclist_krylov_solver_preconditioners()amg|Algebraicmultigriddefault|defaultpreconditionerhypre_amg|Hyprealgebraicmultigrid(BoomerAMG)hypre_euclid|HypreparallelincompleteLUfactorizationhypre_parasails|Hypreparallelsparseapproximateinverseicc|IncompleteCholeskyfactorizationilu|IncompleteLUfactorizationjacobi|Jacobiiterationnone|Nopreconditionerpetsc_amg|PETScalgebraicmultigridsor|Successiveover-relaxation
Load exact solution from the location given in input.yml.
The exact solution must be C++ format with a specific syntax.
The esol.cpp must contain the classes:
Class
mode
Temperature
heat or r13
Heatflux
heat or r13
Pressure
stress or r13
Velocity
stress or r13
Stress
stress or r13
The file has to follow a specific syntax for DOLFIN.
An example file could look like:
#include<pybind11/pybind11.h>#include<pybind11/eigen.h>#include<cmath>// additional includes#include<boost/math/special_functions/bessel.hpp>usingnamespacestd;namespacepy=pybind11;#include<dolfin/function/Expression.h>doublelambda_3=sqrt(3.0/2.0);// some own constantsclassTemperature:publicdolfin::Expression{public:Temperature():dolfin::Expression(){}voideval(Eigen::Ref<Eigen::VectorXd>values,Eigen::Ref<constEigen::VectorXd>x)constoverride{values[0]=1;// value}};classHeatflux:publicdolfin::Expression{public:Heatflux():dolfin::Expression(2){}// note components=2!voideval(Eigen::Ref<Eigen::VectorXd>values,Eigen::Ref<constEigen::VectorXd>x)constoverride{values[0]=42;values[1]=3.14;}};classPressure:publicdolfin::Expression{public:Pressure():dolfin::Expression(){}voideval(Eigen::Ref<Eigen::VectorXd>values,Eigen::Ref<constEigen::VectorXd>x)constoverride{values[0]=boost::math::cyl_bessel_i(1,2.71);// external}};classVelocity:publicdolfin::Expression{public:Velocity():dolfin::Expression(2){}voideval(Eigen::Ref<Eigen::VectorXd>values,Eigen::Ref<constEigen::VectorXd>x)constoverride{values[0]=lambda_3;values[1]=2;}};classStress:publicdolfin::Expression{public:Stress():dolfin::Expression(2,2){}// note dim=2, shape=(2,2)voideval(Eigen::Ref<Eigen::VectorXd>values,Eigen::Ref<constEigen::VectorXd>x)constoverride{doublexx_val=1.23;doublexy_val=1.23;doubleyy_val=1.23;values[0]=xx_val;values[1]=xy_val;values[2]=yy_val;// values[3] = xy_val // not used due to symmetry, skip}};PYBIND11_MODULE(SIGNATURE,m){// needed for DOLFINpy::class_<Temperature,std::shared_ptr<Temperature>,dolfin::Expression>(m,"Temperature").def(py::init<>());py::class_<Heatflux,std::shared_ptr<Heatflux>,dolfin::Expression>(m,"Heatflux").def(py::init<>());py::class_<Pressure,std::shared_ptr<Pressure>,dolfin::Expression>(m,"Pressure").def(py::init<>());py::class_<Velocity,std::shared_ptr<Velocity>,dolfin::Expression>(m,"Velocity").def(py::init<>());py::class_<Stress,std::shared_ptr<Stress>,dolfin::Expression>(m,"Stress").def(py::init<>());}
np.set_printoptions(precision=16)# Precision is not soo nice, only 9 digits:print(mean)# In solve() has m. prec. hmmm:print(self.__calc_sf_mean(self.sol["p"]))
Works for scalars, vectors and tensors.
The difference is written to a file.
The exact solution is written to a file.
Relative errors are based per field component and the maximum value of
the analytical solution. If the analytical solution is uniformly zero,
then the absolute erorrs is used.
(equivalent to setting the maximum to 1)
Parameters:
field (DOLFIN function) – calculated field
field_e (DOLFIN function) – exact solution of field
v_field (DOLFIN fspace) – function space for error calculation
name (string) – name of the field, used to write difference
Returns:
Dict with an error list for “L_2” and a list for “l_inf”
Calculate and return the errors of numerical to exact solution.
This includes all calculated fields.
Note
Usage of np.max() does not work in parallel.
So convergence studies have to be performed in serial for now.
Final fields should be right, so MPI can be used for production
simulations.
Write a given field to a XDMF file in the output folder.
Arguments
name
The name to be given to the field. Will be used as filename
and is the name of the field in e.g. Paraview.
field
The field to write.
write_pdf
If true, write a simple PDF plot for all solution fields
Problems
For MPi execution, XDMFFile.write function fails if the mesh
is too small. I wasn’t able to fix this in 2 days.
Possible reasons:
- Too much overlap in Schwarz-like decomposition
Struchtrup, H. (2005). Macroscopic transport equations for
rarefied gas flows. In Macroscopic Transport Equations for Rarefied Gas
Flows. Springer, Berlin, Heidelberg.
Torrilhon, M. et al. (2018). “Kinetic Theory of Non-Equilibrium
Gas Flows:
Theory and Computations”. Lecture Notes. Indian Institute of Technology
Madras.
Return the 3D symmetric and trace-free part of a 2D 2-tensor.
Warning
Return a 2-tensor with the same dimensions as the input tensor.
For the \(2 \times 2\) case, return the 3D symmetric and
trace-free (dev(sym(.)))
\(B \in \mathbb{R}^{2 \times 2}\)
of the 2D 2-tensor
\(A \in \mathbb{R}^{2 \times 2}\).
Return the symmetric and trace-free part of a 3D 3-tensor.
Return the symmetric and trace-free part of a 3D 3-tensor. (dev(sym(.)))
Returns the STF part \(A_{\langle i j k\rangle}\) of a rank-3 tensor
\(A \in \mathbb{R}^{3 \times 3 \times 3}\)[TOR2018].
\[A_{\langle i j k\rangle}=A_{(i j k)}-\frac{1}{5}\left[A_{(i l l)}
\delta_{j k}+A_{(l j l)} \delta_{i k}+A_{(l l k)} \delta_{i j}\right]\]
A gradient \(\frac{\partial S_{\langle i j}}{\partial x_{k \rangle}}\)
of a symmetric 2-tensor \(S \in \mathbb{R}^{3 \times 3}\) has the
deviator [STR2005]:
Generate a 3D 2-tensor from a 2D 2-tensor (add zeros to last dimensions).
Returns the synthetic 3D version
\(A \in \mathbb{R}^{3 \times 3}\)
of a 2D rank-2 tensor
\(B \in \mathbb{R}^{2 \times 2}\).
The 3D-components are set to zero.
Returns the 3D gradient (w.r.t. \(x,y,z\))
\(\frac{\partial A_{ij}}{\partial x_{k}}\)
of a 3D \(z\)-independent rank-2 tensor
\(A(x,y) \in \mathbb{R}^{3 \times 3}\)
where