From 4a527811b72a56f9be02f01035026a04f3a0149f Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Thu, 25 Jul 2024 16:38:05 -0600 Subject: [PATCH 1/2] create basic buoyancy term as node kernel, named buoyancy_density --- .../node_kernels/MomentumBuoyancyNodeKernel.h | 60 +++++++++++++++++ src/LowMachEquationSystem.C | 4 ++ src/node_kernels/CMakeLists.txt | 1 + src/node_kernels/MomentumBuoyancyNodeKernel.C | 64 +++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 include/node_kernels/MomentumBuoyancyNodeKernel.h create mode 100644 src/node_kernels/MomentumBuoyancyNodeKernel.C diff --git a/include/node_kernels/MomentumBuoyancyNodeKernel.h b/include/node_kernels/MomentumBuoyancyNodeKernel.h new file mode 100644 index 000000000..f938db064 --- /dev/null +++ b/include/node_kernels/MomentumBuoyancyNodeKernel.h @@ -0,0 +1,60 @@ +// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS), National Renewable Energy Laboratory, University of Texas Austin, +// Northwest Research Associates. Under the terms of Contract DE-NA0003525 +// with NTESS, the U.S. Government retains certain rights in this software. +// +// This software is released under the BSD 3-clause license. See LICENSE file +// for more details. +// + +#ifndef MOMENTUMBUOYANCYNODEKERNEL_h +#define MOMENTUMBUOYANCYNODEKERNEL_h + +#include "node_kernels/NodeKernel.h" + +#include "stk_mesh/base/BulkData.hpp" +#include "stk_mesh/base/Ngp.hpp" +#include "stk_mesh/base/NgpField.hpp" +#include "stk_mesh/base/Types.hpp" + +namespace sierra { +namespace nalu { + +class SolutionOptions; + +class MomentumBuoyancyNodeKernel + : public NGPNodeKernel +{ +public: + MomentumBuoyancyNodeKernel( + const stk::mesh::BulkData&, const SolutionOptions&); + + MomentumBuoyancyNodeKernel() = delete; + + KOKKOS_DEFAULTED_FUNCTION + virtual ~MomentumBuoyancyNodeKernel() = default; + + virtual void setup(Realm&) override; + + KOKKOS_FUNCTION + virtual void execute( + NodeKernelTraits::LhsType&, + NodeKernelTraits::RhsType&, + const stk::mesh::FastMeshIndex&) override; + +private: + stk::mesh::NgpField dualNodalVolume_; + stk::mesh::NgpField densityNp1_; + const int nDim_; + NodeKernelTraits::DblType rhoRef_; + + unsigned dualNodalVolumeID_{stk::mesh::InvalidOrdinal}; + unsigned densityNp1ID_{stk::mesh::InvalidOrdinal}; + + NALU_ALIGNED NodeKernelTraits::DblType gravity_[NodeKernelTraits::NDimMax]; +}; + +} // namespace nalu +} // namespace sierra + +#endif diff --git a/src/LowMachEquationSystem.C b/src/LowMachEquationSystem.C index 6711d3824..28604eb4b 100644 --- a/src/LowMachEquationSystem.C +++ b/src/LowMachEquationSystem.C @@ -91,6 +91,7 @@ #include "node_kernels/MomentumBodyForceNodeKernel.h" #include "node_kernels/MomentumBodyForceBoxNodeKernel.h" #include "node_kernels/MomentumBoussinesqNodeKernel.h" +#include "node_kernels/MomentumBuoyancyNodeKernel.h" #include "node_kernels/MomentumCoriolisNodeKernel.h" #include "node_kernels/MomentumMassBDFNodeKernel.h" #include "node_kernels/MomentumGclSrcNodeKernel.h" @@ -1390,6 +1391,9 @@ MomentumEquationSystem::register_interior_algorithm(stk::mesh::Part* part) if (srcName == "buoyancy_boussinesq") { nodeAlg.add_kernel( realm_.bulk_data(), *realm_.solutionOptions_); + } else if (srcName == "buoyancy_density") { + nodeAlg.add_kernel( + realm_.bulk_data(), *realm_.solutionOptions_); } else if (srcName == "body_force") { const auto it = realm_.solutionOptions_->srcTermParamMap_.find("momentum"); diff --git a/src/node_kernels/CMakeLists.txt b/src/node_kernels/CMakeLists.txt index 2d8d0e3cf..822a003df 100644 --- a/src/node_kernels/CMakeLists.txt +++ b/src/node_kernels/CMakeLists.txt @@ -6,6 +6,7 @@ target_sources(nalu PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/MomentumBodyForceNodeKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/MomentumBodyForceBoxNodeKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/MomentumBoussinesqNodeKernel.C + ${CMAKE_CURRENT_SOURCE_DIR}/MomentumBuoyancyNodeKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/MomentumGclNodeKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/MomentumMassBDFNodeKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/MomentumActuatorNodeKernel.C diff --git a/src/node_kernels/MomentumBuoyancyNodeKernel.C b/src/node_kernels/MomentumBuoyancyNodeKernel.C new file mode 100644 index 000000000..a45d7591d --- /dev/null +++ b/src/node_kernels/MomentumBuoyancyNodeKernel.C @@ -0,0 +1,64 @@ +// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS), National Renewable Energy Laboratory, University of Texas Austin, +// Northwest Research Associates. Under the terms of Contract DE-NA0003525 +// with NTESS, the U.S. Government retains certain rights in this software. +// +// This software is released under the BSD 3-clause license. See LICENSE file +// for more details. +// + +#include "node_kernels/MomentumBuoyancyNodeKernel.h" +#include "Realm.h" + +#include "stk_mesh/base/MetaData.hpp" +#include "stk_mesh/base/Types.hpp" +#include "utils/StkHelpers.h" + +#include "SolutionOptions.h" + +namespace sierra { +namespace nalu { + +MomentumBuoyancyNodeKernel::MomentumBuoyancyNodeKernel( + const stk::mesh::BulkData& bulk, const SolutionOptions& solnOpts) + : NGPNodeKernel(), + nDim_(bulk.mesh_meta_data().spatial_dimension()), + rhoRef_(solnOpts.referenceDensity_) +{ + const auto& meta = bulk.mesh_meta_data(); + + dualNodalVolumeID_ = get_field_ordinal(meta, "dual_nodal_volume"); + densityNp1ID_ = get_field_ordinal(meta, "density"); + + const std::vector& solnOptsGravity = + solnOpts.get_gravity_vector(nDim_); + for (int i = 0; i < nDim_; i++) + gravity_[i] = solnOptsGravity[i]; +} + +void +MomentumBuoyancyNodeKernel::setup(Realm& realm) +{ + const auto& fieldMgr = realm.ngp_field_manager(); + dualNodalVolume_ = fieldMgr.get_field(dualNodalVolumeID_); + densityNp1_ = fieldMgr.get_field(densityNp1ID_); +} + +KOKKOS_FUNCTION +void +MomentumBuoyancyNodeKernel::execute( + NodeKernelTraits::LhsType&, + NodeKernelTraits::RhsType& rhs, + const stk::mesh::FastMeshIndex& node) +{ + const NodeKernelTraits::DblType rhoNp1 = densityNp1_.get(node, 0); + const NodeKernelTraits::DblType dualVolume = dualNodalVolume_.get(node, 0); + const double fac = (rhoNp1 - rhoRef_) * dualVolume; + + for (int i = 0; i < nDim_; ++i) { + rhs(i) += fac * gravity_[i]; + } +} + +} // namespace nalu +} // namespace sierra From f650ffebe111d4e1f5e4b2602287005777e1f335 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Mon, 29 Jul 2024 09:00:44 -0600 Subject: [PATCH 2/2] changes to reg test --- reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold | 6 +++--- reg_tests/test_files/VOFDroplet/VOFDroplet.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold b/reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold index c69bff960..4f2573b88 100644 --- a/reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold +++ b/reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold @@ -1,3 +1,3 @@ -2.67343413675555e-05 11 0.0001 -6.859619665424383e-06 12 0.0002 -3.313464463487743e-06 13 0.0003 +2.673434136755543e-05 11 0.0001 +6.859619665424398e-06 12 0.0002 +3.313464463487801e-06 13 0.0003 diff --git a/reg_tests/test_files/VOFDroplet/VOFDroplet.yaml b/reg_tests/test_files/VOFDroplet/VOFDroplet.yaml index b3e88225c..6bb2c5226 100755 --- a/reg_tests/test_files/VOFDroplet/VOFDroplet.yaml +++ b/reg_tests/test_files/VOFDroplet/VOFDroplet.yaml @@ -120,7 +120,7 @@ realms: - source_terms: momentum: - - buoyancy + - buoyancy_density - user_constants: reference_density: 0.00