Skip to content

Commit

Permalink
Actuator source passive scalar and tagging (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf authored Jul 30, 2024
1 parent e8a1709 commit c53a9e8
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 62 deletions.
46 changes: 46 additions & 0 deletions amr-wind/physics/ActuatorSourceTagging.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef ACTUATORSOURCETAGGING_H
#define ACTUATORSOURCETAGGING_H

#include "amr-wind/core/Physics.H"
#include "amr-wind/core/Field.H"
#include "amr-wind/core/IntField.H"

namespace amr_wind {

/** Tracer Tagging physics
* \ingroup physics
*/
class ActuatorSourceTagging : public Physics::Register<ActuatorSourceTagging>
{
public:
static std::string identifier() { return "ActuatorSourceTagging"; }

explicit ActuatorSourceTagging(CFDSim& sim);

~ActuatorSourceTagging() override = default;

void initialize_fields(int level, const amrex::Geometry& geom) override;

void post_init_actions() override;

void post_regrid_actions() override {}

void pre_advance_work() override {}

void post_advance_work() override;

private:
const FieldRepo& m_repo;
Field* m_act_src{nullptr};
IntField* m_iblank{nullptr};
Field* m_tracer{nullptr};
amrex::Real m_src_threshold{0.1};
bool m_tag_hole{false};
bool m_tag_fringe{true};
bool m_has_act_src{false};
bool m_has_iblank{false};
};

} // namespace amr_wind

#endif /* ACTUATORSOURCETAGGING_H */
84 changes: 84 additions & 0 deletions amr-wind/physics/ActuatorSourceTagging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "amr-wind/CFDSim.H"
#include "amr-wind/physics/ActuatorSourceTagging.H"
#include "AMReX_ParmParse.H"

namespace amr_wind {

ActuatorSourceTagging::ActuatorSourceTagging(CFDSim& sim) : m_repo(sim.repo())
{
auto& pseqn = sim.pde_manager().register_transport_pde("PassiveScalar");
m_tracer = &(pseqn.fields().field);

amrex::ParmParse pp("ActuatorSourceTagging");
pp.query("actuator_source_threshold", m_src_threshold);
}

void ActuatorSourceTagging::initialize_fields(
int level, const amrex::Geometry& /*geom*/)
{
(*m_tracer)(level).setVal(0.0);
}

void ActuatorSourceTagging::post_init_actions()
{
m_has_act_src = m_repo.field_exists("actuator_src_term");
m_has_iblank = m_repo.field_exists("iblank_cell");

if (m_has_act_src) {
m_act_src = &(m_repo.get_field("actuator_src_term"));
}

if (m_has_iblank) {
m_iblank = &(m_repo.get_int_field("iblank_cell"));
}
}

void ActuatorSourceTagging::post_advance_work()
{
if (!m_has_act_src && !m_has_iblank) {
amrex::Print()
<< "Warning ActuatorSourceTagging activated but neither actuators "
"or overset are being used"
<< std::endl;
return;
}

const amrex::Real src_threshold = m_src_threshold;
for (int lev = 0; lev <= m_repo.mesh().finestLevel(); ++lev) {

const auto& tracer_arrs = (*m_tracer)(lev).arrays();
if (m_has_act_src) {
const auto& src_arrs = (*m_act_src)(lev).const_arrays();
amrex::ParallelFor(
(*m_tracer)(lev), m_tracer->num_grow(),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
const auto src = src_arrs[nbx];
const amrex::Real srcmag = std::sqrt(
src(i, j, k, 0) * src(i, j, k, 0) +
src(i, j, k, 1) * src(i, j, k, 1) +
src(i, j, k, 2) * src(i, j, k, 2));

if (srcmag > src_threshold) {
tracer_arrs[nbx](i, j, k) = 1.0;
}
});
}

if (m_has_iblank) {
const auto& iblank_arrs = (*m_iblank)(lev).const_arrays();
const bool tag_fringe = m_tag_fringe;
const bool tag_hole = m_tag_hole;
amrex::ParallelFor(
(*m_tracer)(lev), m_tracer->num_grow(),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
const auto ib = iblank_arrs[nbx](i, j, k);
if ((tag_fringe && (ib == -1)) || (tag_hole && (ib == 0))) {
tracer_arrs[nbx](i, j, k) = 1.0;
}
});
}
}
amrex::Gpu::synchronize();
}

} // namespace amr_wind
1 change: 1 addition & 0 deletions amr-wind/physics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target_sources(${amr_wind_lib_name}
ScalarAdvection.cpp
VortexDipole.cpp
BurggrafFlow.cpp
ActuatorSourceTagging.cpp
)

add_subdirectory(multiphase)
Expand Down
Loading

0 comments on commit c53a9e8

Please sign in to comment.