diff --git a/include/user_functions/SloshingTankVOFAuxFunction.h b/include/user_functions/SloshingTankVOFAuxFunction.h new file mode 100644 index 0000000000..f71501de28 --- /dev/null +++ b/include/user_functions/SloshingTankVOFAuxFunction.h @@ -0,0 +1,47 @@ +// 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 SloshingTankVOFAuxFunction_h +#define SloshingTankVOFAuxFunction_h + +#include + +#include + +namespace sierra { +namespace nalu { + +class SloshingTankVOFAuxFunction : public AuxFunction +{ +public: + SloshingTankVOFAuxFunction(const std::vector& params); + + virtual ~SloshingTankVOFAuxFunction() {} + + using AuxFunction::do_evaluate; + virtual void do_evaluate( + const double* coords, + const double time, + const unsigned spatialDimension, + const unsigned numPoints, + double* fieldPtr, + const unsigned fieldSize, + const unsigned beginPos, + const unsigned endPos) const; + + double water_level_; + double amplitude_; + double kappa_; + double interface_thickness_; +}; + +} // namespace nalu +} // namespace sierra + +#endif diff --git a/src/LowMachEquationSystem.C b/src/LowMachEquationSystem.C index cf362d0c46..425d1dbc1f 100644 --- a/src/LowMachEquationSystem.C +++ b/src/LowMachEquationSystem.C @@ -175,6 +175,8 @@ #include #include +#include + // deprecated // stk_util diff --git a/src/VolumeOfFluidEquationSystem.C b/src/VolumeOfFluidEquationSystem.C index 7e5723e818..de312a543e 100644 --- a/src/VolumeOfFluidEquationSystem.C +++ b/src/VolumeOfFluidEquationSystem.C @@ -43,6 +43,7 @@ #include "user_functions/ZalesakDiskVOFAuxFunction.h" #include "user_functions/ZalesakSphereVOFAuxFunction.h" #include "user_functions/DropletVOFAuxFunction.h" +#include "user_functions/SloshingTankVOFAuxFunction.h" #include "ngp_utils/NgpFieldBLAS.h" #include "ngp_utils/NgpLoopUtils.h" #include "ngp_utils/NgpFieldUtils.h" @@ -466,7 +467,7 @@ void VolumeOfFluidEquationSystem::register_initial_condition_fcn( stk::mesh::Part* part, const std::map& theNames, - const std::map>& /* theParams */) + const std::map>& theParams) { // iterate map and check for name const std::string dofName = "volume_of_fluid"; @@ -520,6 +521,13 @@ VolumeOfFluidEquationSystem::register_initial_condition_fcn( } } else if (fcnName == "droplet") { theAuxFunc = new DropletVOFAuxFunction(); + } else if (fcnName == "sloshing_tank") { + std::map>::const_iterator iterParams = + theParams.find(dofName); + std::vector fcnParams = (iterParams != theParams.end()) + ? (*iterParams).second + : std::vector(); + theAuxFunc = new SloshingTankVOFAuxFunction(fcnParams); } else { throw std::runtime_error("VolumeOfFluidEquationSystem::register_initial_" "condition_fcn: limited functions supported"); diff --git a/src/user_functions/CMakeLists.txt b/src/user_functions/CMakeLists.txt index 9c2e3dba7c..1d13dd8590 100644 --- a/src/user_functions/CMakeLists.txt +++ b/src/user_functions/CMakeLists.txt @@ -41,4 +41,5 @@ target_sources(nalu PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ZalesakSphereMassFlowRateKernel.C ${CMAKE_CURRENT_SOURCE_DIR}/DropletVOFAuxFunction.C ${CMAKE_CURRENT_SOURCE_DIR}/DropletVelocityAuxFunction.C + ${CMAKE_CURRENT_SOURCE_DIR}/SloshingTankVOFAuxFunction.C ) diff --git a/src/user_functions/DropletVOFAuxFunction.C b/src/user_functions/DropletVOFAuxFunction.C index b377ed0460..ae8fa2f9d1 100644 --- a/src/user_functions/DropletVOFAuxFunction.C +++ b/src/user_functions/DropletVOFAuxFunction.C @@ -44,7 +44,7 @@ DropletVOFAuxFunction::do_evaluate( fieldPtr[0] = 0.0; //fieldPtr[0] += -0.5 * (std::erf(y / interface_thickness) + 1.0) + 1.0; - auto radius = std::sqrt(x * x + (y) * (y) + z * z) - 0.075; + auto radius = std::sqrt(x * x + y * y + z * z) - 0.075; fieldPtr[0] += -0.5 * (std::erf(radius / interface_thickness) + 1.0) + 1.0; fieldPtr += fieldSize; diff --git a/src/user_functions/SloshingTankVOFAuxFunction.C b/src/user_functions/SloshingTankVOFAuxFunction.C new file mode 100644 index 0000000000..58ecea7fc9 --- /dev/null +++ b/src/user_functions/SloshingTankVOFAuxFunction.C @@ -0,0 +1,71 @@ +// 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 +#include + +// basic c++ +#include +#include +#include +#include + +namespace sierra { +namespace nalu { + +SloshingTankVOFAuxFunction::SloshingTankVOFAuxFunction( + const std::vector& params) + : AuxFunction(0, 1), + water_level_(0.), + amplitude_(0.1), + kappa_(0.25), + interface_thickness_(0.1) +{ + // check size and populate + if (params.size() != 4 && !params.empty()) + throw std::runtime_error("Realm::setup_initial_conditions: " + "sloshing_tank requires 4 params: water level, " + "amplitude, kappa, and interface thickness"); + if (!params.empty()) { + water_level_ = params[0]; + amplitude_ = params[1]; + kappa_ = params[2]; + interface_thickness_ = params[3]; + } +} + +void +SloshingTankVOFAuxFunction::do_evaluate( + const double* coords, + const double /*time*/, + const unsigned spatialDimension, + const unsigned numPoints, + double* fieldPtr, + const unsigned fieldSize, + const unsigned /*beginPos*/, + const unsigned /*endPos*/) const +{ + for (unsigned p = 0; p < numPoints; ++p) { + + const double x = coords[0]; + const double y = coords[1]; + const double z = coords[2]; + + const double z0 = + water_level_ + amplitude_ * std::exp(-kappa_ * (x * x + y * y)); + fieldPtr[0] = + -0.5 * (std::erf((z - z0) / interface_thickness_) + 1.0) + 1.0; + + fieldPtr += fieldSize; + coords += spatialDimension; + } +} + +} // namespace nalu +} // namespace sierra