13 #if !defined(KRATOS_CONVECTION_DIFFUSION_REACTION_STABILIZATION_UTILITIES_H_INCLUDED)
14 #define KRATOS_CONVECTION_DIFFUSION_REACTION_STABILIZATION_UTILITIES_H_INCLUDED
32 namespace ConvectionDiffusionReactionStabilizationUtilities
35 const double VelocityNorm,
37 const double DynamicReaction)
39 return VelocityNorm + Tau * VelocityNorm * DynamicReaction;
43 const double DynamicReaction,
45 const double ElementLength)
47 return (DynamicReaction + Tau * DynamicReaction * std::abs(DynamicReaction)) *
48 std::pow(ElementLength, 2) * (1.0 / 6.0);
51 template<
unsigned int TDim>
54 double& rElementLength,
56 const Matrix& rContravariantMetricTensor,
57 const double Reaction,
58 const double EffectiveKinematicViscosity,
61 const double DeltaTime,
62 const double DynamicTau)
65 const double velocity_norm =
norm_2(rVelocity);
67 if (velocity_norm > 0.0) {
69 rElementLength = 2.0 * velocity_norm / std::sqrt(
inner_prod(rVelocity,
temp));
72 for (
unsigned int i = 0;
i < TDim; ++
i)
73 for (
unsigned int j = 0;
j < TDim; ++
j)
74 rElementLength += rContravariantMetricTensor(
i,
j);
75 rElementLength = std::sqrt(1.0 / rElementLength) * 2.0;
78 const double stab_convection = std::pow(2.0 *
norm_2(rVelocity) / rElementLength, 2);
79 const double stab_diffusion = std::pow(
80 12.0 * EffectiveKinematicViscosity / (rElementLength * rElementLength), 2);
81 const double stab_dynamics =
82 std::pow(DynamicTau * (1 -
Alpha) / (
Gamma * DeltaTime), 2);
83 const double stab_reaction = std::pow(Reaction, 2);
85 rTau = 1.0 / std::sqrt(stab_dynamics + stab_convection + stab_diffusion + stab_reaction);
89 const double ElementLength,
90 const double Velocity,
91 const double Reaction,
92 const double EffectiveKinematicViscosity,
95 const double DeltaTime,
96 const double DynamicTau)
98 const double stab_convection = std::pow(2.0 * Velocity / ElementLength, 2);
99 const double stab_diffusion = std::pow(
100 12.0 * EffectiveKinematicViscosity / (ElementLength * ElementLength), 2);
101 const double stab_dynamics =
102 std::pow(DynamicTau * (1 -
Alpha) / (
Gamma * DeltaTime), 2);
103 const double stab_reaction = std::pow(Reaction, 2);
105 return 1.0 / std::sqrt(stab_dynamics + stab_convection + stab_diffusion + stab_reaction);
110 double& rStreamLineDiffusionCoeff,
111 double& rCrossWindDiffusionCoeff,
112 const double VelocityMagnitude,
114 const double EffectiveKinematicViscosity,
115 const double Reaction,
118 const double DeltaTime,
119 const double ElementLength,
120 const double DynamicTau)
122 const double reaction_dynamics =
123 Reaction + DynamicTau * (1 -
Alpha) / (
Gamma * DeltaTime);
125 rChi = 2.0 / (std::abs(reaction_dynamics) * ElementLength + 2.0 * VelocityMagnitude);
127 const double psi_one =
CalculatePsiOne(VelocityMagnitude, Tau, reaction_dynamics);
128 const double psi_two =
CalculatePsiTwo(reaction_dynamics, Tau, ElementLength);
131 0.5 * std::abs(psi_one - Tau * VelocityMagnitude * reaction_dynamics) * ElementLength;
132 value -= (EffectiveKinematicViscosity + Tau * std::pow(VelocityMagnitude, 2));
137 value = 0.5 * std::abs(psi_one) * ElementLength;
138 value -= EffectiveKinematicViscosity;
144 template <
unsigned int TSize>
146 double& rScalarCoeff,
150 rDiffusionMatrix.
clear();
152 for (
unsigned int a = 0;
a < TSize; ++
a) {
153 for (
unsigned int b =
a + 1;
b < TSize; ++
b) {
154 rDiffusionMatrix(
a,
b) =
156 rDiffusionMatrix(
b,
a) = rDiffusionMatrix(
a,
b);
160 for (
unsigned int a = 0;
a < TSize; ++
a) {
161 double row_sum = 0.0;
162 for (
unsigned int b = 0;
b < TSize; ++
b) {
164 row_sum += rDiffusionMatrix(
a,
b);
166 rDiffusionMatrix(
a,
a) = -row_sum;
173 const Matrix& rInputMatrix)
175 double coefficient = 0.0;
176 for (
unsigned int a = 0;
a < rInputMatrix.size1(); ++
a) {
177 double row_sum = 0.0;
178 for (
unsigned int b = 0;
b < rInputMatrix.size2(); ++
b) {
179 row_sum += rInputMatrix(
a,
b);
181 coefficient =
std::max(coefficient, -row_sum);
188 const double AbsoluteReactionTerm,
190 const Vector& rVelocityConvectiveTerms,
191 const double GaussWeight,
192 const Vector& rGaussShapeFunctions)
198 rMassMatrix(
i,
j) += GaussWeight * Tau *
199 (rVelocityConvectiveTerms[
i] +
200 AbsoluteReactionTerm * rGaussShapeFunctions[
i]) *
201 rGaussShapeFunctions[
j];
208 const double ReactionTerm,
210 const Vector& rVelocityConvectiveTerms,
211 const double GaussWeight,
212 const Vector& rGaussShapeFunctions)
215 const double s = std::abs(ReactionTerm);
222 value += Tau * (rVelocityConvectiveTerms[
a] + s * rGaussShapeFunctions[
a]) *
223 rVelocityConvectiveTerms[
b];
224 value += Tau * (rVelocityConvectiveTerms[
a] + s * rGaussShapeFunctions[
a]) *
225 ReactionTerm * rGaussShapeFunctions[
b];
227 rDampingMatrix(
a,
b) += value * GaussWeight;
233 Vector& rRightHandSideVector,
234 const double SourceTerm,
235 const double AbsoluteReactionTerm,
237 const Vector& rVelocityConvectiveTerms,
238 const double GaussWeight,
239 const Vector& rGaussShapeFunctions)
241 for (
IndexType a = 0;
a < rRightHandSideVector.size(); ++
a) {
244 value += rGaussShapeFunctions[
a] * SourceTerm;
247 value += (rVelocityConvectiveTerms[
a] +
248 AbsoluteReactionTerm * rGaussShapeFunctions[
a]) *
251 rRightHandSideVector[
a] += GaussWeight * value;
void clear()
Definition: amatrix_interface.h:284
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
void CalculateCrossWindDiffusionParameters(double &rChi, double &rStreamLineDiffusionCoeff, double &rCrossWindDiffusionCoeff, const double VelocityMagnitude, const double Tau, const double EffectiveKinematicViscosity, const double Reaction, const double Alpha, const double Gamma, const double DeltaTime, const double ElementLength, const double DynamicTau)
Definition: convection_diffusion_reaction_stabilization_utilities.h:108
void AddMassMatrixSUPGStabilizationGaussPointContributions(Matrix &rMassMatrix, const double AbsoluteReactionTerm, const double Tau, const Vector &rVelocityConvectiveTerms, const double GaussWeight, const Vector &rGaussShapeFunctions)
Definition: convection_diffusion_reaction_stabilization_utilities.h:186
void AddSourceTermWithSUPGStabilizationGaussPointContributions(Vector &rRightHandSideVector, const double SourceTerm, const double AbsoluteReactionTerm, const double Tau, const Vector &rVelocityConvectiveTerms, const double GaussWeight, const Vector &rGaussShapeFunctions)
Definition: convection_diffusion_reaction_stabilization_utilities.h:232
void AddDampingMatrixSUPGStabilizationGaussPointContributions(Matrix &rDampingMatrix, const double ReactionTerm, const double Tau, const Vector &rVelocityConvectiveTerms, const double GaussWeight, const Vector &rGaussShapeFunctions)
Definition: convection_diffusion_reaction_stabilization_utilities.h:206
void CalculateDiscreteUpwindOperator(double &rScalarCoeff, BoundedMatrix< double, TSize, TSize > &rDiffusionMatrix, const BoundedMatrix< double, TSize, TSize > &rInputMatrix)
Definition: convection_diffusion_reaction_stabilization_utilities.h:145
void CalculateStabilizationTau(double &rTau, double &rElementLength, const array_1d< double, TDim > &rVelocity, const Matrix &rContravariantMetricTensor, const double Reaction, const double EffectiveKinematicViscosity, const double Alpha, const double Gamma, const double DeltaTime, const double DynamicTau)
Definition: convection_diffusion_reaction_stabilization_utilities.h:52
double CalculatePsiOne(const double VelocityNorm, const double Tau, const double DynamicReaction)
Definition: convection_diffusion_reaction_stabilization_utilities.h:34
double CalculatePositivityPreservingMatrix(const Matrix &rInputMatrix)
Definition: convection_diffusion_reaction_stabilization_utilities.h:172
double CalculatePsiTwo(const double DynamicReaction, const double Tau, const double ElementLength)
Definition: convection_diffusion_reaction_stabilization_utilities.h:42
static double max(double a, double b)
Definition: GeometryFunctions.h:79
long double SoftPositive(const long double value)
Definition: rans_calculation_utilities.h:50
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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
TExpressionType::data_type norm_frobenius(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:687
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
def Gamma(n, j)
Definition: quadrature.py:146
def Alpha(n, j)
Definition: quadrature.py:93
int j
Definition: quadrature.py:648
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17