From e2bf74e798aaed348603c60a7ef810686b6c550f Mon Sep 17 00:00:00 2001 From: Bumseok Lee Date: Tue, 17 Sep 2024 14:53:44 -0600 Subject: [PATCH] create unit tests for tke & sdr of the sst-gamma --- unit_tests/kernels/UnitTestKernelUtils.C | 26 ++ unit_tests/kernels/UnitTestKernelUtils.h | 10 + .../node_kernels/UnitTestSSTNodeKernel.C | 266 ++++++++++++++++++ 3 files changed, 302 insertions(+) diff --git a/unit_tests/kernels/UnitTestKernelUtils.C b/unit_tests/kernels/UnitTestKernelUtils.C index 1dbc8c54a..74eba0b04 100644 --- a/unit_tests/kernels/UnitTestKernelUtils.C +++ b/unit_tests/kernels/UnitTestKernelUtils.C @@ -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]; @@ -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}; @@ -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") @@ -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, diff --git a/unit_tests/kernels/UnitTestKernelUtils.h b/unit_tests/kernels/UnitTestKernelUtils.h index 1919ea237..350f9445b 100644 --- a/unit_tests/kernels/UnitTestKernelUtils.h +++ b/unit_tests/kernels/UnitTestKernelUtils.h @@ -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, @@ -731,6 +736,8 @@ class SSTKernelHex8Mesh : public LowMachKernelHex8Mesh &meta_->declare_field(stk::topology::NODE_RANK, "viscosity")), tvisc_(&meta_->declare_field( stk::topology::NODE_RANK, "turbulent_viscosity")), + gamint_(&meta_->declare_field( + stk::topology::NODE_RANK, "gamma_transition")), //added maxLengthScale_(&meta_->declare_field( stk::topology::NODE_RANK, "sst_max_length_scale")), minDistance_(&meta_->declare_field( @@ -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( @@ -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( @@ -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}; diff --git a/unit_tests/node_kernels/UnitTestSSTNodeKernel.C b/unit_tests/node_kernels/UnitTestSSTNodeKernel.C index 823f5272a..1ed348f7a 100644 --- a/unit_tests/node_kernels/UnitTestSSTNodeKernel.C +++ b/unit_tests/node_kernels/UnitTestSSTNodeKernel.C @@ -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 { @@ -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, @@ -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 @@ -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(*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 @@ -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(*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); +}