KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
Variables
generate_weakly_compressible_navier_stokes_element Namespace Reference

Variables

string mode = "c"
 Settings explanation DIMENSION TO COMPUTE: This symbolic generator is valid for both 2D and 3D cases. More...
 
bool do_simplifications = False
 
string dim_to_compute = "Both"
 
bool divide_by_rho = True
 
bool ASGS_stabilization = True
 
string formulation = "WeaklyCompressibleNavierStokes"
 
bool darcy_term = True
 
bool convective_term = True
 
bool artificial_compressibility = True
 
string linearisation = "Picard"
 
string output_filename = "weakly_compressible_navier_stokes.cpp"
 
string template_filename = "weakly_compressible_navier_stokes_cpp_template.cpp"
 
string err_msg = "Wrong formulation. Given \'" + formulation + "\'. Available options are \'WeaklyCompressibleNavierStokes\' and \'Stokes\'."
 
string info_msg = "\n"
 
list dim_vector = [2]
 
list nnodes_vector = [3]
 
 templatefile = open(template_filename)
 Initialize the outstring to be filled with the template .cpp file. More...
 
 outstring = templatefile.read()
 Replace the computed RHS and LHS in the template outstring. More...
 
int strain_size = 3
 
bool impose_partion_of_unity = False
 
 N
 
 DN
 
 v = DefineMatrix('v',nnodes,dim)
 Unknown fields definition. More...
 
 vn = DefineMatrix('vn',nnodes,dim)
 
 vnn = DefineMatrix('vnn',nnodes,dim)
 
 p = DefineVector('p',nnodes)
 
 pn = DefineVector('pn',nnodes)
 
 pnn = DefineVector('pnn',nnodes)
 
 rho_nodes = DefineVector('rho',nnodes)
 Fluid properties. More...
 
 c_nodes = DefineVector('c',nnodes)
 
 rho = rho_nodes.transpose()*N
 
 c = c_nodes.transpose()*N
 
 w = DefineMatrix('w',nnodes,dim)
 Test functions definition. More...
 
 q = DefineVector('q',nnodes)
 
 f = DefineMatrix('f',nnodes,dim)
 Other data definitions. More...
 
 C = DefineSymmetricMatrix('C',strain_size,strain_size)
 Constitutive matrix definition. More...
 
 stress = DefineVector('stress',strain_size)
 Stress vector definition. More...
 
 dt = sympy.Symbol('dt', positive = True)
 Other simbols definition. More...
 
 mu = sympy.Symbol('mu', positive = True)
 
 h = sympy.Symbol('h', positive = True)
 
 dyn_tau = sympy.Symbol('dyn_tau', positive = True)
 
 stab_c1 = sympy.Symbol('stab_c1', positive = True)
 
 stab_c2 = sympy.Symbol('stab_c2', positive = True)
 
 gauss_weight = sympy.Symbol('gauss_weight', positive = True)
 
bool sigma = sympy.Symbol('sigma', positive = True) if darcy_term else 0.0
 Symbols for Darcy term. More...
 
bool stab_c3 = sympy.Symbol('stab_c3', positive = True) if darcy_term else 0.0
 
 bdf0 = sympy.Symbol('bdf0')
 Backward differences coefficients. More...
 
 bdf1 = sympy.Symbol('bdf1')
 
 bdf2 = sympy.Symbol('bdf2')
 
 f_gauss = f.transpose()*N
 Data interpolation to the Gauss points. More...
 
 v_gauss = v.transpose()*N
 
 vconv = DefineMatrix('vconv',nnodes,dim)
 Convective velocity definition. More...
 
 vmesh = DefineMatrix('vmesh',nnodes,dim)
 
 vconv_gauss = vconv.transpose()*N
 
float stab_norm_a = 0.0
 Compute the stabilization parameters. More...
 
float tau1 = 1.0/(rho*dyn_tau/dt + stab_c2*rho*stab_norm_a/h + stab_c1*mu/h**2 + stab_c3*sigma/h**2)
 
 tau2 = mu + (stab_c2*rho*stab_norm_a*h + stab_c3*sigma)/stab_c1
 
tuple accel_gauss = (bdf0*v + bdf1*vn + bdf2*vnn).transpose()*N
 Compute the rest of magnitudes at the Gauss points. More...
 
 p_gauss = p.transpose()*N
 
tuple pder_gauss = (bdf0*p + bdf1*pn + bdf2*pnn).transpose()*N
 
 w_gauss = w.transpose()*N
 
 q_gauss = q.transpose()*N
 
 grad_w = DfjDxi(DN,w)
 Gradients computation (fluid dynamics gradient) More...
 
 grad_q = DfjDxi(DN,q)
 
 grad_p = DfjDxi(DN,p)
 
 grad_v = DfjDxi(DN,v)
 
 grad_rho = DfjDxi(DN,rho_nodes)
 
 div_w = div(DN,w)
 
 div_v = div(DN,v)
 
 div_vconv = div(DN,vconv)
 
 grad_sym_v = grad_sym_voigtform(DN,v)
 
 grad_w_voigt = grad_sym_voigtform(DN,w)
 
tuple convective_term_gauss = (vconv_gauss.transpose()*grad_v)
 
 rho_convective_term_gauss = vconv_gauss.transpose()*grad_rho
 
tuple rv_galerkin = rho*w_gauss.transpose()*f_gauss - rho*w_gauss.transpose()*accel_gauss - grad_w_voigt.transpose()*stress + div_w*p_gauss - sigma*w_gauss.transpose()*v_gauss - q_gauss*div_v
 Compute galerkin functional Navier-Stokes functional. More...
 
tuple vel_residual = rho*f_gauss - rho*accel_gauss - grad_p - sigma*v_gauss
 Stabilization functional terms Momentum conservation residual Note that the viscous stress term is dropped since linear elements are used. More...
 
 mas_residual = -div_v
 
float vel_subscale = tau1*vel_residual
 
 mas_subscale = tau2*mas_residual
 
float rv_stab = grad_q.transpose()*vel_subscale
 
tuple rv = rv_galerkin + rv_stab
 Add the stabilization terms to the original residual terms. More...
 
 dofs = sympy.zeros(nnodes*(dim+1), 1)
 Define DOFs and test function vectors. More...
 
 testfunc = sympy.zeros(nnodes*(dim+1), 1)
 
 rhs = Compute_RHS(rv.copy(), testfunc, do_simplifications)
 Compute LHS and RHS For the RHS computation one wants the residual of the previous iteration (residual based formulation). More...
 
 rhs_out = OutputVector_CollectingFactors(gauss_weight*rhs, "rRHS", mode, assignment_op='+=')
 
 lhs = Compute_LHS(rhs, testfunc, dofs, do_simplifications)
 
 lhs_out = OutputMatrix_CollectingFactors(gauss_weight*lhs, "rLHS", mode, assignment_op='+=')
 
 out = open(output_filename,'w')
 Write the modified template. More...
 

Variable Documentation

◆ accel_gauss

tuple generate_weakly_compressible_navier_stokes_element.accel_gauss = (bdf0*v + bdf1*vn + bdf2*vnn).transpose()*N

Compute the rest of magnitudes at the Gauss points.

◆ artificial_compressibility

bool generate_weakly_compressible_navier_stokes_element.artificial_compressibility = True

◆ ASGS_stabilization

bool generate_weakly_compressible_navier_stokes_element.ASGS_stabilization = True

◆ bdf0

generate_weakly_compressible_navier_stokes_element.bdf0 = sympy.Symbol('bdf0')

Backward differences coefficients.

◆ bdf1

generate_weakly_compressible_navier_stokes_element.bdf1 = sympy.Symbol('bdf1')

◆ bdf2

generate_weakly_compressible_navier_stokes_element.bdf2 = sympy.Symbol('bdf2')

◆ c

generate_weakly_compressible_navier_stokes_element.c = c_nodes.transpose()*N

◆ C

generate_weakly_compressible_navier_stokes_element.C = DefineSymmetricMatrix('C',strain_size,strain_size)

Constitutive matrix definition.

◆ c_nodes

generate_weakly_compressible_navier_stokes_element.c_nodes = DefineVector('c',nnodes)

◆ convective_term

bool generate_weakly_compressible_navier_stokes_element.convective_term = True

◆ convective_term_gauss

tuple generate_weakly_compressible_navier_stokes_element.convective_term_gauss = (vconv_gauss.transpose()*grad_v)

◆ darcy_term

bool generate_weakly_compressible_navier_stokes_element.darcy_term = True

◆ dim_to_compute

string generate_weakly_compressible_navier_stokes_element.dim_to_compute = "Both"

◆ dim_vector

list generate_weakly_compressible_navier_stokes_element.dim_vector = [2]

◆ div_v

generate_weakly_compressible_navier_stokes_element.div_v = div(DN,v)

◆ div_vconv

generate_weakly_compressible_navier_stokes_element.div_vconv = div(DN,vconv)

◆ div_w

generate_weakly_compressible_navier_stokes_element.div_w = div(DN,w)

◆ divide_by_rho

bool generate_weakly_compressible_navier_stokes_element.divide_by_rho = True

◆ DN

generate_weakly_compressible_navier_stokes_element.DN

◆ do_simplifications

bool generate_weakly_compressible_navier_stokes_element.do_simplifications = False

◆ dofs

generate_weakly_compressible_navier_stokes_element.dofs = sympy.zeros(nnodes*(dim+1), 1)

Define DOFs and test function vectors.

◆ dt

generate_weakly_compressible_navier_stokes_element.dt = sympy.Symbol('dt', positive = True)

Other simbols definition.

◆ dyn_tau

generate_weakly_compressible_navier_stokes_element.dyn_tau = sympy.Symbol('dyn_tau', positive = True)

◆ err_msg

string generate_weakly_compressible_navier_stokes_element.err_msg = "Wrong formulation. Given \'" + formulation + "\'. Available options are \'WeaklyCompressibleNavierStokes\' and \'Stokes\'."

◆ f

generate_weakly_compressible_navier_stokes_element.f = DefineMatrix('f',nnodes,dim)

Other data definitions.

◆ f_gauss

generate_weakly_compressible_navier_stokes_element.f_gauss = f.transpose()*N

Data interpolation to the Gauss points.

◆ formulation

string generate_weakly_compressible_navier_stokes_element.formulation = "WeaklyCompressibleNavierStokes"

◆ gauss_weight

generate_weakly_compressible_navier_stokes_element.gauss_weight = sympy.Symbol('gauss_weight', positive = True)

◆ grad_p

generate_weakly_compressible_navier_stokes_element.grad_p = DfjDxi(DN,p)

◆ grad_q

generate_weakly_compressible_navier_stokes_element.grad_q = DfjDxi(DN,q)

◆ grad_rho

generate_weakly_compressible_navier_stokes_element.grad_rho = DfjDxi(DN,rho_nodes)

◆ grad_sym_v

generate_weakly_compressible_navier_stokes_element.grad_sym_v = grad_sym_voigtform(DN,v)

◆ grad_v

generate_weakly_compressible_navier_stokes_element.grad_v = DfjDxi(DN,v)

◆ grad_w

generate_weakly_compressible_navier_stokes_element.grad_w = DfjDxi(DN,w)

Gradients computation (fluid dynamics gradient)

◆ grad_w_voigt

generate_weakly_compressible_navier_stokes_element.grad_w_voigt = grad_sym_voigtform(DN,w)

◆ h

generate_weakly_compressible_navier_stokes_element.h = sympy.Symbol('h', positive = True)

◆ impose_partion_of_unity

bool generate_weakly_compressible_navier_stokes_element.impose_partion_of_unity = False

◆ info_msg

string generate_weakly_compressible_navier_stokes_element.info_msg = "\n"

◆ lhs

generate_weakly_compressible_navier_stokes_element.lhs = Compute_LHS(rhs, testfunc, dofs, do_simplifications)

◆ lhs_out

generate_weakly_compressible_navier_stokes_element.lhs_out = OutputMatrix_CollectingFactors(gauss_weight*lhs, "rLHS", mode, assignment_op='+=')

◆ linearisation

string generate_weakly_compressible_navier_stokes_element.linearisation = "Picard"

◆ mas_residual

generate_weakly_compressible_navier_stokes_element.mas_residual = -div_v

◆ mas_subscale

generate_weakly_compressible_navier_stokes_element.mas_subscale = tau2*mas_residual

◆ mode

string generate_weakly_compressible_navier_stokes_element.mode = "c"

Settings explanation DIMENSION TO COMPUTE: This symbolic generator is valid for both 2D and 3D cases.

Since the element has been programed with a dimension template in Kratos, it is advised to set the dim_to_compute flag as "Both". In this case the generated .cpp file will contain both 2D and 3D implementations. LINEARISATION SETTINGS: FullNR considers the convective velocity as "v-vmesh", hence v is taken into account in the derivation of the LHS and RHS. Picard (a.k.a. QuasiNR) considers the convective velocity as "a", thus it is considered as a constant in the derivation of the LHS and RHS. DIVIDE BY RHO: If set to true, divides the mass conservation equation by rho in order to have a better conditioned matrix. Otherwise the original form is kept. ARTIFICIAL COMPRESSIBILITY: If set to true, the time derivative of the density is introduced in the mass conservation equation together with the state equation dp/drho=c^2 (being c the sound velocity). Besides, the velocity divergence is not considered to be 0. These assumptions add some extra terms to the usual Navier-Stokes equations that act as a weak compressibility controlled by the value of "c". CONVECTIVE TERM: If set to true, the convective term is taken into account in the calculation of the variational form. This allows generating both Navier-Stokes and Stokes elements.

Symbolic generation settings

◆ mu

generate_weakly_compressible_navier_stokes_element.mu = sympy.Symbol('mu', positive = True)

◆ N

generate_weakly_compressible_navier_stokes_element.N

◆ nnodes_vector

list generate_weakly_compressible_navier_stokes_element.nnodes_vector = [3]

◆ out

generate_weakly_compressible_navier_stokes_element.out = open(output_filename,'w')

Write the modified template.

◆ output_filename

string generate_weakly_compressible_navier_stokes_element.output_filename = "weakly_compressible_navier_stokes.cpp"

◆ outstring

generate_weakly_compressible_navier_stokes_element.outstring = templatefile.read()

Replace the computed RHS and LHS in the template outstring.

◆ p

generate_weakly_compressible_navier_stokes_element.p = DefineVector('p',nnodes)

◆ p_gauss

generate_weakly_compressible_navier_stokes_element.p_gauss = p.transpose()*N

◆ pder_gauss

tuple generate_weakly_compressible_navier_stokes_element.pder_gauss = (bdf0*p + bdf1*pn + bdf2*pnn).transpose()*N

◆ pn

generate_weakly_compressible_navier_stokes_element.pn = DefineVector('pn',nnodes)

◆ pnn

generate_weakly_compressible_navier_stokes_element.pnn = DefineVector('pnn',nnodes)

◆ q

generate_weakly_compressible_navier_stokes_element.q = DefineVector('q',nnodes)

◆ q_gauss

generate_weakly_compressible_navier_stokes_element.q_gauss = q.transpose()*N

◆ rho

generate_weakly_compressible_navier_stokes_element.rho = rho_nodes.transpose()*N

◆ rho_convective_term_gauss

generate_weakly_compressible_navier_stokes_element.rho_convective_term_gauss = vconv_gauss.transpose()*grad_rho

◆ rho_nodes

generate_weakly_compressible_navier_stokes_element.rho_nodes = DefineVector('rho',nnodes)

Fluid properties.

◆ rhs

generate_weakly_compressible_navier_stokes_element.rhs = Compute_RHS(rv.copy(), testfunc, do_simplifications)

Compute LHS and RHS For the RHS computation one wants the residual of the previous iteration (residual based formulation).

By this reason the stress is included as a symbolic variable, which is assumed to be passed as an argument from the previous iteration database.

◆ rhs_out

generate_weakly_compressible_navier_stokes_element.rhs_out = OutputVector_CollectingFactors(gauss_weight*rhs, "rRHS", mode, assignment_op='+=')

◆ rv

tuple generate_weakly_compressible_navier_stokes_element.rv = rv_galerkin + rv_stab

Add the stabilization terms to the original residual terms.

◆ rv_galerkin

tuple generate_weakly_compressible_navier_stokes_element.rv_galerkin = rho*w_gauss.transpose()*f_gauss - rho*w_gauss.transpose()*accel_gauss - grad_w_voigt.transpose()*stress + div_w*p_gauss - sigma*w_gauss.transpose()*v_gauss - q_gauss*div_v

Compute galerkin functional Navier-Stokes functional.

◆ rv_stab

float generate_weakly_compressible_navier_stokes_element.rv_stab = grad_q.transpose()*vel_subscale

◆ sigma

bool generate_weakly_compressible_navier_stokes_element.sigma = sympy.Symbol('sigma', positive = True) if darcy_term else 0.0

Symbols for Darcy term.

◆ stab_c1

generate_weakly_compressible_navier_stokes_element.stab_c1 = sympy.Symbol('stab_c1', positive = True)

◆ stab_c2

generate_weakly_compressible_navier_stokes_element.stab_c2 = sympy.Symbol('stab_c2', positive = True)

◆ stab_c3

bool generate_weakly_compressible_navier_stokes_element.stab_c3 = sympy.Symbol('stab_c3', positive = True) if darcy_term else 0.0

◆ stab_norm_a

generate_weakly_compressible_navier_stokes_element.stab_norm_a = 0.0

Compute the stabilization parameters.

◆ strain_size

int generate_weakly_compressible_navier_stokes_element.strain_size = 3

◆ stress

generate_weakly_compressible_navier_stokes_element.stress = DefineVector('stress',strain_size)

Stress vector definition.

◆ tau1

float generate_weakly_compressible_navier_stokes_element.tau1 = 1.0/(rho*dyn_tau/dt + stab_c2*rho*stab_norm_a/h + stab_c1*mu/h**2 + stab_c3*sigma/h**2)

◆ tau2

bool generate_weakly_compressible_navier_stokes_element.tau2 = mu + (stab_c2*rho*stab_norm_a*h + stab_c3*sigma)/stab_c1

◆ template_filename

string generate_weakly_compressible_navier_stokes_element.template_filename = "weakly_compressible_navier_stokes_cpp_template.cpp"

◆ templatefile

generate_weakly_compressible_navier_stokes_element.templatefile = open(template_filename)

Initialize the outstring to be filled with the template .cpp file.

◆ testfunc

generate_weakly_compressible_navier_stokes_element.testfunc = sympy.zeros(nnodes*(dim+1), 1)

◆ v

generate_weakly_compressible_navier_stokes_element.v = DefineMatrix('v',nnodes,dim)

Unknown fields definition.

◆ v_gauss

generate_weakly_compressible_navier_stokes_element.v_gauss = v.transpose()*N

◆ vconv

generate_weakly_compressible_navier_stokes_element.vconv = DefineMatrix('vconv',nnodes,dim)

Convective velocity definition.

◆ vconv_gauss

generate_weakly_compressible_navier_stokes_element.vconv_gauss = vconv.transpose()*N

◆ vel_residual

tuple generate_weakly_compressible_navier_stokes_element.vel_residual = rho*f_gauss - rho*accel_gauss - grad_p - sigma*v_gauss

Stabilization functional terms Momentum conservation residual Note that the viscous stress term is dropped since linear elements are used.

◆ vel_subscale

float generate_weakly_compressible_navier_stokes_element.vel_subscale = tau1*vel_residual

◆ vmesh

generate_weakly_compressible_navier_stokes_element.vmesh = DefineMatrix('vmesh',nnodes,dim)

◆ vn

generate_weakly_compressible_navier_stokes_element.vn = DefineMatrix('vn',nnodes,dim)

◆ vnn

generate_weakly_compressible_navier_stokes_element.vnn = DefineMatrix('vnn',nnodes,dim)

◆ w

generate_weakly_compressible_navier_stokes_element.w = DefineMatrix('w',nnodes,dim)

Test functions definition.

◆ w_gauss

generate_weakly_compressible_navier_stokes_element.w_gauss = w.transpose()*N