13 #if !defined(KRATOS_SHOCK_CAPTURING_UTILITIES_H_INCLUDED)
14 #define KRATOS_SHOCK_CAPTURING_UTILITIES_H_INCLUDED
121 , mrModelPart(rModelPart)
123 ValidateAndAssignParameters(rParameters);
138 void Execute()
override;
142 void ExecuteInitializeSolutionStep()
override;
144 int Check()
override;
146 const Parameters GetDefaultParameters()
const override;
163 std::string
Info()
const override
165 std::stringstream buffer;
166 buffer <<
"ShockCapturingPhysicsBasedProcess";
171 void PrintInfo(std::ostream &rOStream)
const override { rOStream <<
"ShockCapturingPhysicsBasedProcess"; }
174 void PrintData(std::ostream &rOStream)
const override {}
193 bool mUpdateNodalArea;
197 bool mThermallyCoupledFormulation;
198 double mArtBulkViscosityConstant = 0.0;
199 double mFarFieldPrandtlNumber = 0.0;
200 double mArtConductivityConstant = 0.0;
201 double mArtDynViscosityConstant = 0.0;
212 void ValidateAndAssignParameters(
Parameters &rParameters);
219 void CalculatePhysicsBasedShockCapturing();
231 template<std::
size_t TDim, std::
size_t TNumNodes,
class TTLSContainerType>
232 void CalculatePhysicsBasedShockCapturingElementContribution(
234 TTLSContainerType &rShockCapturingTLS)
237 const unsigned int n_nodes = r_geom.PointsNumber();
240 if (mShockSensor) {rElement.
GetValue(ARTIFICIAL_BULK_VISCOSITY) = 0.0;}
241 if (mShearSensor) {rElement.
GetValue(ARTIFICIAL_DYNAMIC_VISCOSITY) = 0.0;}
242 if (mThermalSensor || mShockSensor) {rElement.
GetValue(ARTIFICIAL_CONDUCTIVITY) = 0.0;}
245 double& r_vol = rShockCapturingTLS.Vol;
246 auto& r_DN_DX = rShockCapturingTLS.DN_DX;
247 auto& r_N = rShockCapturingTLS.N;
248 auto& r_metric_tensor = rShockCapturingTLS.MetricTensor;
249 auto& r_inv_metric_tensor = rShockCapturingTLS.InverseMetricTensor;
255 double h_ref, metric_tensor_inf, metric_tensor_sup;
269 const double c_v = r_prop.
GetValue(SPECIFIC_HEAT);
270 const double gamma = r_prop.GetValue(HEAT_CAPACITY_RATIO);
273 const double k = 1.0;
274 const double eps = std::numeric_limits<double>::epsilon();
277 double midpoint_rho, formulation_midpoint_temp;
278 auto& r_midpoint_v = rShockCapturingTLS.MidpointVelocity;
279 if (mThermallyCoupledFormulation) {
281 double midpoint_temp;
284 formulation_midpoint_temp = midpoint_temp;
290 formulation_midpoint_temp = midpoint_p / (midpoint_rho * (
gamma - 1.0) * c_v);
294 const double v_norm_pow = SquaredArrayNorm(r_midpoint_v);
295 const double stagnation_temp = formulation_midpoint_temp + 0.5 *
inner_prod(r_midpoint_v,r_midpoint_v)/(
gamma * c_v);
296 const double critical_temp = stagnation_temp * (2.0 / (
gamma + 1.0));
297 const double c_star = std::sqrt(
gamma * (
gamma - 1.0) * c_v * critical_temp);
298 const double ref_mom_norm = midpoint_rho * std::sqrt(v_norm_pow + std::pow(c_star, 2));
304 auto& r_grad_rho = rShockCapturingTLS.DensityGradient;
305 auto& r_rot_v = rShockCapturingTLS.VelocityRotational;
306 CalculateShockSensorValues<TDim,TNumNodes>(r_geom, r_N, r_DN_DX, mach,
div_v, r_grad_rho, r_rot_v);
309 const double h_beta = h_ref *
norm_2(r_grad_rho) / std::sqrt(CalculateProjectedInverseMetricElementSize(r_inv_metric_tensor, r_grad_rho) + eps);
313 const double s_omega = c_star > 0.0 ? -h_beta *
div_v / (
k * c_star) : 0.0;
316 const double div_v_pow = std::pow(
div_v, 2);
317 const double rot_v_norm_pow = SquaredArrayNorm(r_rot_v);
318 const double s_w = div_v_pow / (div_v_pow + rot_v_norm_pow + eps);
321 const double s_beta_0 = 0.01;
322 const double s_beta_max = 2.0 / std::sqrt(std::pow(
gamma, 2) - 1.0);
323 const double s_beta = s_omega * s_w;
324 const double s_beta_hat = SmoothedLimitingFunction(s_beta, s_beta_0, s_beta_max);
325 rElement.
GetValue(SHOCK_SENSOR) = s_beta_hat;
328 const double elem_b_star = (mArtBulkViscosityConstant * h_beta /
k) * ref_mom_norm * s_beta_hat;
329 rElement.
GetValue(ARTIFICIAL_BULK_VISCOSITY) = elem_b_star;
333 if (mThermallyCoupledFormulation) {
334 const double Pr_beta_min = 0.9;
335 const double alpha_pr_beta = 2.0;
336 const double mach_threshold = 3.0;
337 double ArtPrandtlNumber_beta;
338 if (mFarFieldPrandtlNumber < std::numeric_limits<double>::epsilon()) {
339 ArtPrandtlNumber_beta = Pr_beta_min * (1.0 + std::exp(-2.0 * alpha_pr_beta * (mach - mach_threshold)));
341 ArtPrandtlNumber_beta = mFarFieldPrandtlNumber;
343 const double elem_k1_star = (
gamma * c_v / ArtPrandtlNumber_beta) * elem_b_star;
344 rElement.
GetValue(ARTIFICIAL_CONDUCTIVITY) += elem_k1_star;
348 if (mThermalSensor || mShearSensor) {
354 if (mThermalSensor) {
356 auto& r_grad_temp = rShockCapturingTLS.TemperatureGradient;
357 auto& r_grad_temp_local = rShockCapturingTLS.TemperatureLocalGradient;
358 CalculateTemperatureGradients(r_geom, r_DN_DX, mid_pt_jacobian, r_grad_temp, r_grad_temp_local);
361 const double h_kappa = h_ref *
norm_2(r_grad_temp) / std::sqrt(CalculateProjectedInverseMetricElementSize(r_inv_metric_tensor, r_grad_temp) + eps);
364 const double s_kappa_0 = 1.0;
365 const double s_kappa_max = 2.0;
366 const double s_kappa = h_ref *
norm_2(r_grad_temp_local) /
k / stagnation_temp;
367 const double s_kappa_hat = SmoothedLimitingFunction(s_kappa, s_kappa_0, s_kappa_max);
368 rElement.
GetValue(THERMAL_SENSOR) = s_kappa_hat;
371 const double elem_k2_star = (
gamma * c_v) * (mArtConductivityConstant * h_kappa /
k) * ref_mom_norm * s_kappa_hat;
372 rElement.
GetValue(ARTIFICIAL_CONDUCTIVITY) += elem_k2_star;
379 auto& r_local_shear_grad_v = rShockCapturingTLS.VelocityShearLocalGradient;
380 CalculateShearSensorValues(r_geom, r_N, r_DN_DX, mid_pt_jacobian, r_local_shear_grad_v, r_c);
381 BoundedMatrix<double,TDim,TDim> eigen_vect_mat, eigen_val_mat;
383 double shear_spect_norm = 0.0;
384 for (
unsigned int d = 0;
d < eigen_val_mat.size1(); ++
d) {
385 if (eigen_val_mat(
d,
d) > shear_spect_norm) {
386 shear_spect_norm = eigen_val_mat(
d,
d);
389 shear_spect_norm = std::sqrt(shear_spect_norm);
392 const double h_mu = h_ref * metric_tensor_inf;
395 const double isentropic_max_vel = std::sqrt(v_norm_pow + (2.0 / (
gamma - 1.0)) * std::pow(r_c, 2));
396 const double s_mu_0 = 1.0;
397 const double s_mu_max = 2.0;
398 const double s_mu = h_ref * shear_spect_norm / isentropic_max_vel /
k;
399 const double s_mu_hat = SmoothedLimitingFunction(s_mu, s_mu_0, s_mu_max);
400 rElement.
GetValue(SHEAR_SENSOR) = s_mu_hat;
403 const double elem_mu_star = (mArtDynViscosityConstant * h_mu /
k) * ref_mom_norm * s_mu_hat;
404 rElement.
GetValue(ARTIFICIAL_DYNAMIC_VISCOSITY) = elem_mu_star;
409 const double aux_weight = r_vol /
static_cast<double>(
n_nodes);
410 for (
unsigned int i_node = 0; i_node <
n_nodes; ++i_node) {
411 auto &r_node = r_geom[i_node];
412 if (mShockSensor) {
AtomicAdd(r_node.GetValue(ARTIFICIAL_BULK_VISCOSITY), aux_weight * rElement.
GetValue(ARTIFICIAL_BULK_VISCOSITY));}
413 if (mShearSensor) {
AtomicAdd(r_node.GetValue(ARTIFICIAL_DYNAMIC_VISCOSITY), aux_weight * rElement.
GetValue(ARTIFICIAL_DYNAMIC_VISCOSITY));}
414 if (mShockSensor || mThermalSensor) {
AtomicAdd(r_node.GetValue(ARTIFICIAL_CONDUCTIVITY), aux_weight * rElement.
GetValue(ARTIFICIAL_CONDUCTIVITY));}
424 inline double SquaredArrayNorm(
const array_1d<double,3>& rArray)
426 return rArray[0]*rArray[0] + rArray[1]*rArray[1] + rArray[2]*rArray[2];
438 double LimitingFunction(
442 const double s_min = 0.0);
452 double SmoothedLimitingFunction(
463 double SmoothedMaxFunction(
const double s);
471 double SmoothedMinFunction(
const double s);
481 double CalculateProjectedInverseMetricElementSize(
482 const Matrix& rInverseMetricTensor,
483 const array_1d<double,3>& rScalarGradient);
498 template<std::
size_t TDim, std::
size_t TNumNodes>
499 void KRATOS_API(FLUID_DYNAMICS_APPLICATION) CalculateShockSensorValues(
500 const Geometry<Node>& rGeometry,
501 const array_1d<double,TNumNodes>& rN,
502 const BoundedMatrix<double,TNumNodes,TDim>& rDN_DX,
504 double& rVelocityDivergence,
505 array_1d<double,3>& rDensityGradient,
506 array_1d<double,3>& rVelocityRotational);
519 template<std::
size_t TDim, std::
size_t TNumNodes>
520 void KRATOS_API(FLUID_DYNAMICS_APPLICATION) CalculateTemperatureGradients(
521 const Geometry<Node>& rGeometry,
522 const BoundedMatrix<double,TNumNodes,TDim>& rDN_DX,
523 const Matrix& rJacobianMatrix,
524 array_1d<double,3>& rTemperatureGradient,
525 array_1d<double,3>& rTemperatureLocalGradient);
539 template<std::
size_t TDim, std::
size_t TNumNodes>
540 void KRATOS_API(FLUID_DYNAMICS_APPLICATION) CalculateShearSensorValues(
541 const Geometry<Node>& rGeometry,
542 const array_1d<double,TNumNodes>& rN,
543 const BoundedMatrix<double,TNumNodes,TDim>& rDN_DX,
544 const Matrix& rJacobianMatrix,
545 BoundedMatrix<double,TDim,TDim>& rLocalVelocityShearGradient,
546 double& rSoundVelocity);
563 ShockCapturingPhysicsBasedProcess&
operator=(ShockCapturingPhysicsBasedProcess
const& rOther);
566 ShockCapturingPhysicsBasedProcess(ShockCapturingPhysicsBasedProcess
const& rOther);
583 std::ostream& rOStream,
584 const ShockCapturingPhysicsBasedProcess& rThis);
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
void ExecuteInitialize() override
Definition: periodic_interface_process.hpp:37
Base class for all Elements.
Definition: element.h:60
PropertiesType & GetProperties()
Definition: element.h:1024
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometrical_object.h:248
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
static void CalculateMetricTensorDimensionless(const GeometryType &rGeometry, BoundedMatrix< double, TDim, TDim > &rMetricTensorDimensionless, double &rReferenceElementSize, double &rMetricInfimum, double &rMetricSupremum)
Calculate the metric tensor of a given geometry This function calculates the metric tensor and its da...
Definition: geometry_metric_calculator.cpp:117
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
Definition: amatrix_interface.h:41
static BoundedMatrix< double, TDim, TDim > InvertMatrix(const BoundedMatrix< double, TDim, TDim > &rInputMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
Calculates the inverse of a 2x2, 3x3 and 4x4 matrices (using bounded matrix for performance)
Definition: math_utils.h:197
static bool GaussSeidelEigenSystem(const TMatrixType1 &rA, TMatrixType2 &rEigenVectorsMatrix, TMatrixType2 &rEigenValuesMatrix, const double Tolerance=1.0e-18, const SizeType MaxIterations=20)
Calculates the eigenvectors and eigenvalues of given symmetric matrix.
Definition: math_utils.h:1587
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
The base class for all processes in Kratos.
Definition: process.h:49
TVariableType::Type & GetValue(const TVariableType &rVariable)
Definition: properties.h:228
Definition: shock_capturing_physics_based_process.h:59
std::function< std::tuple< double, double, Matrix >Geometry< Node > &rGeometry)> ElementMetricFunctionType
Type for the metric calculation function.
Definition: shock_capturing_physics_based_process.h:69
~ShockCapturingPhysicsBasedProcess()
Destructor.
Definition: shock_capturing_physics_based_process.h:127
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: shock_capturing_physics_based_process.h:171
Process BaseType
The base process type.
Definition: shock_capturing_physics_based_process.h:66
ShockCapturingPhysicsBasedProcess(Model &rModel, Parameters rParameters)
Constructor with model.
Definition: shock_capturing_physics_based_process.h:111
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: shock_capturing_physics_based_process.h:174
ShockCapturingPhysicsBasedProcess(ModelPart &rModelPart, Parameters rParameters)
Constructor with model part.
Definition: shock_capturing_physics_based_process.h:117
std::string Info() const override
Turn back information as a string.
Definition: shock_capturing_physics_based_process.h:163
KRATOS_CLASS_POINTER_DEFINITION(ShockCapturingPhysicsBasedProcess)
Pointer definition of ShockCapturingPhysicsBasedProcess.
static void EvaluateInPoint(const GeometryType &rGeometry, const Vector &rShapeFunction, const int Step, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates given list of variable pairs at gauss point locations at step.
Definition: fluid_calculation_utilities.h:75
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
void AtomicAdd(TDataType &target, const TDataType &value)
Definition: atomic_utilities.h:55
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
div_v
Definition: generate_convection_diffusion_explicit_element.py:150
int n_nodes
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:15
float gamma
Definition: generate_two_fluid_navier_stokes.py:131
int d
Definition: ode_solve.py:397
int k
Definition: quadrature.py:595
Type for the 2D (linear triangle) TLS geometry data.
Definition: shock_capturing_physics_based_process.h:73
array_1d< double, 3 > VelocityRotational
Definition: shock_capturing_physics_based_process.h:81
BoundedMatrix< double, 2, 2 > InverseMetricTensor
Definition: shock_capturing_physics_based_process.h:78
BoundedMatrix< double, 3, 2 > DN_DX
Definition: shock_capturing_physics_based_process.h:76
array_1d< double, 3 > DensityGradient
Definition: shock_capturing_physics_based_process.h:80
BoundedMatrix< double, 2, 2 > MetricTensor
Definition: shock_capturing_physics_based_process.h:77
array_1d< double, 3 > TemperatureGradient
Definition: shock_capturing_physics_based_process.h:82
array_1d< double, 3 > N
Definition: shock_capturing_physics_based_process.h:75
double Vol
Definition: shock_capturing_physics_based_process.h:74
array_1d< double, 3 > TemperatureLocalGradient
Definition: shock_capturing_physics_based_process.h:83
array_1d< double, 3 > MidpointVelocity
Definition: shock_capturing_physics_based_process.h:79
BoundedMatrix< double, 2, 2 > VelocityShearLocalGradient
Definition: shock_capturing_physics_based_process.h:84
Type for the 3D (linear tetrahedra) TLS geometry data.
Definition: shock_capturing_physics_based_process.h:89
BoundedMatrix< double, 3, 3 > MetricTensor
Definition: shock_capturing_physics_based_process.h:93
array_1d< double, 3 > TemperatureLocalGradient
Definition: shock_capturing_physics_based_process.h:99
array_1d< double, 3 > MidpointVelocity
Definition: shock_capturing_physics_based_process.h:95
BoundedMatrix< double, 4, 3 > DN_DX
Definition: shock_capturing_physics_based_process.h:92
BoundedMatrix< double, 3, 3 > VelocityShearLocalGradient
Definition: shock_capturing_physics_based_process.h:100
array_1d< double, 3 > DensityGradient
Definition: shock_capturing_physics_based_process.h:96
array_1d< double, 3 > VelocityRotational
Definition: shock_capturing_physics_based_process.h:97
double Vol
Definition: shock_capturing_physics_based_process.h:90
array_1d< double, 3 > TemperatureGradient
Definition: shock_capturing_physics_based_process.h:98
BoundedMatrix< double, 3, 3 > InverseMetricTensor
Definition: shock_capturing_physics_based_process.h:94
array_1d< double, 4 > N
Definition: shock_capturing_physics_based_process.h:91