Skip to content

Commit

Permalink
Add IDDES unit test (#1181)
Browse files Browse the repository at this point in the history
* Use the paper's form for limiting production

* Commit unit test

* format

* Missed a field

* go back to original iddes

* Remove spurious addition

---------

Co-authored-by: psakievich <[email protected]>
  • Loading branch information
marchdf and psakievich committed May 4, 2023
1 parent 472317f commit b5a0342
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
26 changes: 26 additions & 0 deletions unit_tests/kernels/UnitTestKernelUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ struct TrigFieldFunction
(std::sin(a * pi * x) * std::cos(a * pi * y) * std::sin(a * pi * z));
}

void iddes_rans_indicator(const double* coords, double* qField) const
{
double x = coords[0];
double y = coords[1];
double z = coords[2];

qField[0] =
iddes_rans_indicatornot *
(std::sin(a * pi * x) * std::cos(a * pi * y) * std::sin(a * pi * z));
}

void minimum_distance_to_wall(const double* coords, double* qField) const
{
double x = coords[0];
Expand Down Expand Up @@ -288,6 +299,9 @@ private:
/// Factor for fOneBlend field
static constexpr double sst_f_one_blendingnot{1.0};

/// Factor for rans_indicator field
static constexpr double iddes_rans_indicatornot{1.0};

const double pi;
};

Expand Down Expand Up @@ -341,6 +355,8 @@ init_trigonometric_field(
funcPtr = &TrigFieldFunction::tensor_turbulent_viscosity;
else if (fieldName == "sst_f_one_blending")
funcPtr = &TrigFieldFunction::sst_f_one_blending;
else if (fieldName == "iddes_rans_indicator")
funcPtr = &TrigFieldFunction::iddes_rans_indicator;
else if (fieldName == "minimum_distance_to_wall")
funcPtr = &TrigFieldFunction::minimum_distance_to_wall;
else if (fieldName == "dplus_wall_function")
Expand Down Expand Up @@ -517,6 +533,7 @@ tensor_turbulent_viscosity_test_function(
{
init_trigonometric_field(bulk, coordinates, mutij);
}

void
sst_f_one_blending_test_function(
const stk::mesh::BulkData& bulk,
Expand All @@ -526,6 +543,15 @@ sst_f_one_blending_test_function(
init_trigonometric_field(bulk, coordinates, sst_f_one_blending);
}

void
iddes_rans_indicator_test_function(
const stk::mesh::BulkData& bulk,
const VectorFieldType& coordinates,
ScalarFieldType& iddes_rans_indicator)
{
init_trigonometric_field(bulk, coordinates, iddes_rans_indicator);
}

void
minimum_distance_to_wall_test_function(
const stk::mesh::BulkData& bulk,
Expand Down
12 changes: 12 additions & 0 deletions unit_tests/kernels/UnitTestKernelUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void sst_f_one_blending_test_function(
const VectorFieldType& coordinates,
ScalarFieldType& sst_f_one_blending);

void iddes_rans_indicator_test_function(
const stk::mesh::BulkData& bulk,
const VectorFieldType& coordinates,
ScalarFieldType& iddes_rans_indicator);

void minimum_distance_to_wall_test_function(
const stk::mesh::BulkData& bulk,
const VectorFieldType& coordinates,
Expand Down Expand Up @@ -726,6 +731,8 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
stk::topology::NODE_RANK, "minimum_distance_to_wall")),
fOneBlend_(&meta_->declare_field<ScalarFieldType>(
stk::topology::NODE_RANK, "sst_f_one_blending")),
iddes_rans_indicator_(&meta_->declare_field<ScalarFieldType>(
stk::topology::NODE_RANK, "iddes_rans_indicator")),
dudx_(&meta_->declare_field<TensorFieldType>(
stk::topology::NODE_RANK, "dudx")),
dkdx_(&meta_->declare_field<VectorFieldType>(
Expand Down Expand Up @@ -755,6 +762,8 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
*minDistance_, meta_->universal_part(), 1, nullptr);
stk::mesh::put_field_on_mesh(
*fOneBlend_, meta_->universal_part(), 1, nullptr);
stk::mesh::put_field_on_mesh(
*iddes_rans_indicator_, meta_->universal_part(), 1, nullptr);
stk::mesh::put_field_on_mesh(
*dudx_, meta_->universal_part(), spatialDim_ * spatialDim_, nullptr);
stk::mesh::put_field_on_mesh(
Expand Down Expand Up @@ -797,6 +806,8 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
*bulk_, *coordinates_, *minDistance_);
unit_test_kernel_utils::sst_f_one_blending_test_function(
*bulk_, *coordinates_, *fOneBlend_);
unit_test_kernel_utils::iddes_rans_indicator_test_function(
*bulk_, *coordinates_, *iddes_rans_indicator_);
unit_test_kernel_utils::dudx_test_function(*bulk_, *coordinates_, *dudx_);
stk::mesh::field_fill(0.0, *dkdx_);
stk::mesh::field_fill(0.0, *dwdx_);
Expand All @@ -812,6 +823,7 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
ScalarFieldType* maxLengthScale_{nullptr};
ScalarFieldType* minDistance_{nullptr};
ScalarFieldType* fOneBlend_{nullptr};
ScalarFieldType* iddes_rans_indicator_{nullptr};
TensorFieldType* dudx_{nullptr};
VectorFieldType* dkdx_{nullptr};
VectorFieldType* dwdx_{nullptr};
Expand Down
125 changes: 125 additions & 0 deletions unit_tests/node_kernels/UnitTestSSTNodeKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "node_kernels/TKESSTNodeKernel.h"
#include "node_kernels/TKESSTLRNodeKernel.h"
#include "node_kernels/TKESSTDESNodeKernel.h"
#include "node_kernels/TKESSTIDDESNodeKernel.h"
#include "node_kernels/SDRSSTNodeKernel.h"
#include "node_kernels/SDRSSTLRNodeKernel.h"
#include "node_kernels/SDRSSTDESNodeKernel.h"
Expand Down Expand Up @@ -310,6 +311,95 @@ static constexpr double lhs[8][8] = {
};
} // namespace tke_sst_des

namespace tke_sst_iddes {
static constexpr double rhs[8] = {
-0.78566371211666, -0.57734551764836, -0.081969668080736, -0.31147981334595,
-0.20433593046136, -0.19416508662489, -0.026042361300698, -0.037056788165969};

static constexpr double lhs[8][8] = {
{
0.5892477840875,
0,
0,
0,
0,
0,
0,
0,
},
{
0,
0.43300913823627,
0,
0,
0,
0,
0,
0,
},
{
0,
0,
0.043771362853026,
0,
0,
0,
0,
0,
},
{
0,
0,
0,
0.22332033598677,
0,
0,
0,
0,
},
{
0,
0,
0,
0,
0.15325194784602,
0,
0,
0,
},
{
0,
0,
0,
0,
0,
0.14562381496867,
0,
0,
},
{
0,
0,
0,
0,
0,
0,
0.015779881252609,
0,
},
{
0,
0,
0,
0,
0,
0,
0,
0.061943732501324,
},
};
} // namespace tke_sst_iddes

namespace tke_sst_des_sust {
static constexpr double rhs[8] = {
3.4229150667019503, 2.0119389960571135, 1.5591709764645274,
Expand Down Expand Up @@ -773,6 +863,41 @@ TEST_F(SSTKernelHex8Mesh, NGP_tke_sst_des_node)
helperObjs.linsys->lhs_, hex8_golds::lhs, 1.0e-12);
}

TEST_F(SSTKernelHex8Mesh, NGP_tke_sst_iddes_node)
{
// Only execute for 1 processor runs
if (bulk_->parallel_size() > 1)
return;

fill_mesh_and_init_fields();

// Setup solution options
solnOpts_.meshMotion_ = false;
solnOpts_.externalMeshDeformation_ = false;
solnOpts_.initialize_turbulence_constants();

unit_test_utils::NodeHelperObjects helperObjs(
bulk_, stk::topology::HEX_8, 1, partVec_[0]);

helperObjs.nodeAlg->add_kernel<sierra::nalu::TKESSTIDDESNodeKernel>(*meta_);

helperObjs.execute();

Kokkos::deep_copy(
helperObjs.linsys->hostNumSumIntoCalls_,
helperObjs.linsys->numSumIntoCalls_);
EXPECT_EQ(helperObjs.linsys->lhs_.extent(0), 8u);
EXPECT_EQ(helperObjs.linsys->lhs_.extent(1), 8u);
EXPECT_EQ(helperObjs.linsys->rhs_.extent(0), 8u);
EXPECT_EQ(helperObjs.linsys->hostNumSumIntoCalls_(0), 8u);

namespace hex8_golds = hex8_golds::tke_sst_iddes;
unit_test_kernel_utils::expect_all_near(
helperObjs.linsys->rhs_, hex8_golds::rhs, 1.0e-12);
unit_test_kernel_utils::expect_all_near<8>(
helperObjs.linsys->lhs_, hex8_golds::lhs, 1.0e-12);
}

TEST_F(SSTKernelHex8Mesh, NGP_tke_sst_des_sust_node)
{
// Only execute for 1 processor runs
Expand Down

0 comments on commit b5a0342

Please sign in to comment.