Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create basic buoyancy term as node kernel, named buoyancy_density #1274

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions include/node_kernels/MomentumBuoyancyNodeKernel.h
Original file line number Diff line number Diff line change
@@ -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<MomentumBuoyancyNodeKernel>
{
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<double> dualNodalVolume_;
stk::mesh::NgpField<double> 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
6 changes: 3 additions & 3 deletions reg_tests/test_files/VOFDroplet/VOFDroplet.norm.gold
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion reg_tests/test_files/VOFDroplet/VOFDroplet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ realms:

- source_terms:
momentum:
- buoyancy
- buoyancy_density

- user_constants:
reference_density: 0.00
Expand Down
4 changes: 4 additions & 0 deletions src/LowMachEquationSystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1390,6 +1391,9 @@ MomentumEquationSystem::register_interior_algorithm(stk::mesh::Part* part)
if (srcName == "buoyancy_boussinesq") {
nodeAlg.add_kernel<MomentumBoussinesqNodeKernel>(
realm_.bulk_data(), *realm_.solutionOptions_);
} else if (srcName == "buoyancy_density") {
nodeAlg.add_kernel<MomentumBuoyancyNodeKernel>(
realm_.bulk_data(), *realm_.solutionOptions_);
} else if (srcName == "body_force") {
const auto it =
realm_.solutionOptions_->srcTermParamMap_.find("momentum");
Expand Down
1 change: 1 addition & 0 deletions src/node_kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions src/node_kernels/MomentumBuoyancyNodeKernel.C
Original file line number Diff line number Diff line change
@@ -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<MomentumBuoyancyNodeKernel>(),
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<double>& 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<double>(dualNodalVolumeID_);
densityNp1_ = fieldMgr.get_field<double>(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
Loading