Skip to content

Commit

Permalink
create unit tests for tke & sdr of the sst-gamma
Browse files Browse the repository at this point in the history
  • Loading branch information
Bumseok Lee committed Sep 17, 2024
1 parent 213b6cc commit e2bf74e
Show file tree
Hide file tree
Showing 3 changed files with 302 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 @@ -158,6 +158,18 @@ struct TrigFieldFunction
std::sin(a * pi * z));
}

void gamint(const double* coords, double* qField) const //added: transition
{
double x = coords[0];
double y = coords[1];
double z = coords[2];

// Range should be from 0.02 to 1.0
qField[0] =
gamintnot + abs(std::cos(a * pi * x) * std::sin(a * pi * y) *
std::sin(a * pi * z))/(1.0 - gamintnot);
}

void tdr(const double* coords, double* qField) const
{
double x = coords[0];
Expand Down Expand Up @@ -290,6 +302,9 @@ private:
/// Factor for sdr field
static constexpr double sdrnot{1.0};

/// Factor for gamint field
static constexpr double gamintnot{0.02};

/// Factor for tdr field
static constexpr double tdrnot{1.0};

Expand Down Expand Up @@ -343,6 +358,8 @@ init_trigonometric_field(
funcPtr = &TrigFieldFunction::dkdx;
else if (fieldName == "specific_dissipation_rate")
funcPtr = &TrigFieldFunction::sdr;
else if (fieldName == "gamma_transition") // added: transition
funcPtr = &TrigFieldFunction::gamint;
else if (fieldName == "total_dissipation_rate")
funcPtr = &TrigFieldFunction::tdr;
else if (fieldName == "dwdx")
Expand Down Expand Up @@ -498,6 +515,15 @@ sdr_test_function(
init_trigonometric_field(bulk, coordinates, sdr);
}

void
gamint_test_function( // added: transition
const stk::mesh::BulkData& bulk,
const sierra::nalu::VectorFieldType& coordinates,
sierra::nalu::ScalarFieldType& gamint)
{
init_trigonometric_field(bulk, coordinates, gamint);
}

void
tdr_test_function(
const stk::mesh::BulkData& bulk,
Expand Down
10 changes: 10 additions & 0 deletions unit_tests/kernels/UnitTestKernelUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void sdr_test_function(
const sierra::nalu::VectorFieldType& coordinates,
sierra::nalu::ScalarFieldType& sdr);

void gamint_test_function( //added
const stk::mesh::BulkData& bulk,
const sierra::nalu::VectorFieldType& coordinates,
sierra::nalu::ScalarFieldType& gamint);

void tdr_test_function(
const stk::mesh::BulkData& bulk,
const sierra::nalu::VectorFieldType& coordinates,
Expand Down Expand Up @@ -731,6 +736,8 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
&meta_->declare_field<double>(stk::topology::NODE_RANK, "viscosity")),
tvisc_(&meta_->declare_field<double>(
stk::topology::NODE_RANK, "turbulent_viscosity")),
gamint_(&meta_->declare_field<double>(
stk::topology::NODE_RANK, "gamma_transition")), //added
maxLengthScale_(&meta_->declare_field<double>(
stk::topology::NODE_RANK, "sst_max_length_scale")),
minDistance_(&meta_->declare_field<double>(
Expand Down Expand Up @@ -759,6 +766,7 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
stk::mesh::put_field_on_mesh(*sdrbc_, meta_->universal_part(), nullptr);
stk::mesh::put_field_on_mesh(*visc_, meta_->universal_part(), nullptr);
stk::mesh::put_field_on_mesh(*tvisc_, meta_->universal_part(), nullptr);
stk::mesh::put_field_on_mesh(*gamint_, meta_->universal_part(), nullptr); //added
stk::mesh::put_field_on_mesh(
*maxLengthScale_, meta_->universal_part(), nullptr);
stk::mesh::put_field_on_mesh(
Expand Down Expand Up @@ -807,6 +815,7 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
*bulk_, *coordinates_, *density_);
unit_test_kernel_utils::tke_test_function(*bulk_, *coordinates_, *tke_);
unit_test_kernel_utils::sdr_test_function(*bulk_, *coordinates_, *sdr_);
unit_test_kernel_utils::gamint_test_function(*bulk_, *coordinates_, *gamint_); // added
unit_test_kernel_utils::minimum_distance_to_wall_test_function(
*bulk_, *coordinates_, *minDistance_);
unit_test_kernel_utils::sst_f_one_blending_test_function(
Expand All @@ -825,6 +834,7 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh
sierra::nalu::ScalarFieldType* sdrbc_{nullptr};
sierra::nalu::ScalarFieldType* visc_{nullptr};
sierra::nalu::ScalarFieldType* tvisc_{nullptr};
sierra::nalu::ScalarFieldType* gamint_{nullptr}; // added
sierra::nalu::ScalarFieldType* maxLengthScale_{nullptr};
sierra::nalu::ScalarFieldType* minDistance_{nullptr};
sierra::nalu::ScalarFieldType* fOneBlend_{nullptr};
Expand Down
266 changes: 266 additions & 0 deletions unit_tests/node_kernels/UnitTestSSTNodeKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include "node_kernels/TKESSTLRNodeKernel.h"
#include "node_kernels/TKESSTDESNodeKernel.h"
#include "node_kernels/TKESSTIDDESNodeKernel.h"
#include "node_kernels/TKESSTBLTM2015NodeKernel.h"
#include "node_kernels/SDRSSTNodeKernel.h"
#include "node_kernels/SDRSSTLRNodeKernel.h"
#include "node_kernels/SDRSSTDESNodeKernel.h"
#include "node_kernels/SDRSSTBLTM2015NodeKernel.h"

namespace {
namespace hex8_golds {
Expand Down Expand Up @@ -408,6 +410,103 @@ static constexpr double rhs[8] = {
};
} // namespace tke_sst_des_sust


namespace tke_sst_trans {
static constexpr double rhs[8] = {
-0.004499999980007,
-0.0026450336235646,
-0.0037149722043966,
-0.0013217844303503,
-0.0026450336153232,
-0.0015547117509048,
-0.017568942314324,
0.0073065228754648,
};

static constexpr double lhs[8][8] = {
{
0.00225,
0,
0,
0,
0,
0,
0,
0,
},
{
0,
0.0013225168176581,
0,
0,
0,
0,
0,
0,
},
{
0,
0,
0.0013225168176581,
0,
0,
0,
0,
0,
},
{
0,
0,
0,
0.00077735588132818,
0,
0,
0,
0,
},
{
0,
0,
0,
0,
0.0013225168176581,
0,
0,
0,
},
{
0,
0,
0,
0,
0,
0.00077735588132818,
0,
0,
},
{
0,
0,
0,
0,
0,
0,
0.0070970479374154,
0,
},
{
0,
0,
0,
0,
0,
0,
0,
0.0022476729243034,
},
};
} // // namespace tke_sst_trans

namespace sdr_sst {
static constexpr double rhs[8] = {
-0.0414,
Expand Down Expand Up @@ -717,6 +816,102 @@ static constexpr double rhs[8] = {
};
} // namespace sdr_sst_des_sust

namespace sdr_sst_trans {
static constexpr double rhs[8] = {
-0.0414,
-0.024334309444908,
-0.024334309444908,
0.00096369609149651,
-0.024334309444908,
-0.013421452431681,
-0.025196833148802,
-0.0016391627843042,
};

static constexpr double lhs[8][8] = {
{
0.0414,
0,
0,
0,
0,
0,
0,
0,
},
{
0,
0.024334309444908,
0,
0,
0,
0,
0,
0,
},
{
0,
0,
0.024334309444908,
0,
0,
0,
0,
0,
},
{
0,
0,
0,
0.014303348216439,
0,
0,
0,
0,
},
{
0,
0,
0,
0,
0.024334309444908,
0,
0,
0,
},
{
0,
0,
0,
0,
0,
0.013421452431681,
0,
0,
},
{
0,
0,
0,
0,
0,
0,
0.018984179689384,
0,
},
{
0,
0,
0,
0,
0,
0,
0,
0.0096611889086056,
},
};
} // namespace sdr_sst_trans

} // namespace hex8_golds
} // namespace

Expand Down Expand Up @@ -936,6 +1131,41 @@ TEST_F(SSTKernelHex8Mesh, NGP_tke_sst_des_sust_node)
helperObjs.linsys->lhs_, hex8_golds::tke_sst_des::lhs, 1.0e-12);
}

TEST_F(SSTKernelHex8Mesh, NGP_tke_sst_trans_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::TKESSTBLTM2015NodeKernel>(*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_trans;
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_sdr_sst_node)
{
// Only execute for 1 processor runs
Expand Down Expand Up @@ -1118,3 +1348,39 @@ TEST_F(SSTKernelHex8Mesh, NGP_sdr_sst_des_sust_node)
unit_test_kernel_utils::expect_all_near<8>(
helperObjs.linsys->lhs_, hex8_golds::sdr_sst_des::lhs, 1.0e-12);
}

TEST_F(SSTKernelHex8Mesh, NGP_sdr_sst_trans_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::SDRSSTBLTM2015NodeKernel>(*meta_);

helperObjs.execute();
//helperObjs.print_lhs_and_rhs();

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::sdr_sst_trans;
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);
}

0 comments on commit e2bf74e

Please sign in to comment.