/home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/levelset/levelset_ops.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/levelset/levelset_ops.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
levelset_ops.H
Go to the documentation of this file.
1#ifndef LEVELSET_OPS_H
2#define LEVELSET_OPS_H
3
6
7namespace amr_wind::pde {
8
12template <typename Scheme>
13struct FieldRegOp<Levelset, Scheme>
14{
15 explicit FieldRegOp(CFDSim& sim_in) : sim(sim_in) {}
16
18 {
19 auto& repo = sim.repo();
20 auto fields = create_fields_instance<Levelset, Scheme>(time, repo);
21
22 auto& normal =
23 repo.declare_cc_field("interface_normal", AMREX_SPACEDIM, 1, 1);
24 auto& curvature = repo.declare_cc_field("interface_curvature", 1, 1, 1);
25
26 normal.template register_fill_patch_op<FieldFillPatchOps<FieldBCNoOp>>(
27 repo.mesh(), time);
28 curvature
29 .template register_fill_patch_op<FieldFillPatchOps<FieldBCNoOp>>(
30 repo.mesh(), time);
31
32 // Register fields for output/restart
33 auto& iomgr = sim.io_manager();
34 iomgr.register_io_var(fields.field.name());
35 iomgr.register_io_var(normal.name());
36 iomgr.register_io_var(curvature.name());
37
38 return fields;
39 }
40
42};
43
47template <typename Scheme>
48struct ComputeRHSOp<Levelset, Scheme>
49{
50 explicit ComputeRHSOp(PDEFields& fields_in) : fields(fields_in) {}
51
53 const DiffusionType /*unused*/,
54 const amrex::Real dt,
55 bool /*mesh_mapping*/)
56 {
57 // Field states for diffusion and advection terms. In Godunov scheme
58 // these terms only have one state.
59 auto fstate = std::is_same<Scheme, fvm::Godunov>::value
62
63 const int nlevels = fields.repo.num_active_levels();
64 auto& field = fields.field;
65 const auto& field_old = field.state(FieldState::Old);
66 const auto& conv_term = fields.conv_term.state(fstate);
67
68 for (int lev = 0; lev < nlevels; ++lev) {
69#ifdef AMREX_USE_OMP
70#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
71#endif
72 for (amrex::MFIter mfi(field(lev)); mfi.isValid(); ++mfi) {
73 const auto& bx = mfi.tilebox();
74 auto phi = field(lev).array(mfi);
75 const auto phi_o = field_old(lev).const_array(mfi);
76 const auto ddt_o = conv_term(lev).const_array(mfi);
77
78 amrex::ParallelFor(
79 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
80 phi(i, j, k) = phi_o(i, j, k) + dt * ddt_o(i, j, k);
81 // Defer n+1/2 update to the time-stepping algorithm
82 // phi_nph(i, j, k) = 0.5 * (phi(i, j, k) + phi_o(i, j,
83 // k));
84 });
85 }
86 }
87 }
88
90 const DiffusionType /*unused*/,
91 const amrex::Real dt,
92 bool /*mesh_mapping*/)
93 {
94 const int nlevels = fields.repo.num_active_levels();
95 auto& field = fields.field;
96 const auto& field_old = field.state(FieldState::Old);
97 const auto& conv_term = fields.conv_term;
98 const auto& conv_term_old = fields.conv_term.state(FieldState::Old);
99
100 for (int lev = 0; lev < nlevels; ++lev) {
101#ifdef AMREX_USE_OMP
102#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
103#endif
104 for (amrex::MFIter mfi(field(lev)); mfi.isValid(); ++mfi) {
105 const auto& bx = mfi.tilebox();
106 auto phi = field(lev).array(mfi);
107 const auto phi_o = field_old(lev).const_array(mfi);
108 const auto ddt = conv_term(lev).const_array(mfi);
109 const auto ddt_o = conv_term_old(lev).const_array(mfi);
110
111 amrex::ParallelFor(
112 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
113 phi(i, j, k) =
114 phi_o(i, j, k) +
115 dt * 0.5 * (ddt_o(i, j, k) + ddt(i, j, k));
116 // Defer n+1/2 update to time-stepping algorithm
117 // phi_nph(i, j, k) =
118 // 0.5 * (phi(i, j, k) + phi_o(i, j, k));
119 });
120 }
121 }
122 }
123
124 // data members
126};
127
131template <>
133{
134 PostSolveOp(CFDSim& sim, PDEFields& fields) : m_sim(sim), m_fields(fields)
135 {}
136
137 void operator()(const amrex::Real /*unused*/)
138 {
140 auto& multiphase = m_sim.physics_manager().get<MultiPhase>();
141 multiphase.set_density_via_levelset();
142 }
143
146};
147
148} // namespace amr_wind::pde
149
150#endif /* LEVELSET_OPS_H */
Definition CFDSim.H:51
FieldRepo & repo()
Return the field repository.
Definition CFDSim.H:66
PhysicsMgr & physics_manager()
Definition CFDSim.H:72
SimTime & time()
Return simulation time control.
Definition CFDSim.H:62
IOManager & io_manager()
Definition CFDSim.H:93
Field & state(const FieldState fstate)
Return field at a different time state.
Definition Field.cpp:114
void fillpatch(const amrex::Real time) noexcept
Definition Field.cpp:206
int num_active_levels() const noexcept
Total number of levels currently active in the AMR mesh.
Definition FieldRepo.H:361
void register_io_var(const std::string &fname)
Convenience function to register a variable for both output and restart.
Definition IOManager.H:76
Definition MultiPhase.H:27
void set_density_via_levelset()
Definition MultiPhase.cpp:298
T & get()
Return a concrete physics instance.
Definition Physics.H:104
Definition SimTime.H:30
AMREX_FORCE_INLINE amrex::Real current_time() const
Definition SimTime.H:102
@ New
Same as FieldState::NP1.
@ Old
Same as FieldState::N.
DiffusionType
Definition incflo_enums.H:4
Definition AdvOp_Godunov.H:16
PDEFields create_fields_instance(const SimTime &time, FieldRepo &repo, const FieldInterpolator itype=FieldInterpolator::CellConsLinear)
Definition PDEHelpers.H:49
void corrector_rhs(const DiffusionType, const amrex::Real dt, bool)
Definition levelset_ops.H:89
ComputeRHSOp(PDEFields &fields_in)
Definition levelset_ops.H:50
PDEFields & fields
Definition levelset_ops.H:125
void predictor_rhs(const DiffusionType, const amrex::Real dt, bool)
Definition levelset_ops.H:52
Definition CompRHSOps.H:18
PDEFields & fields
Definition CompRHSOps.H:270
FieldRegOp(CFDSim &sim_in)
Definition levelset_ops.H:15
CFDSim & sim
Definition levelset_ops.H:41
PDEFields operator()(const SimTime &time)
Definition levelset_ops.H:17
Definition PDEOps.H:35
CFDSim & sim
Definition PDEOps.H:53
Definition levelset.H:28
Definition PDEFields.H:27
Field & conv_term
Convective term for this PDE.
Definition PDEFields.H:43
FieldRepo & repo
Reference to the field repository instance.
Definition PDEFields.H:31
Field & field
Solution variable (e.g., velocity, temperature)
Definition PDEFields.H:34
void operator()(const amrex::Real)
Definition levelset_ops.H:137
PostSolveOp(CFDSim &sim, PDEFields &fields)
Definition levelset_ops.H:134
PDEFields & m_fields
Definition levelset_ops.H:145
CFDSim & m_sim
Definition levelset_ops.H:144
Definition PDEOps.H:205
CFDSim & m_sim
Definition PDEOps.H:212
PDEFields & m_fields
Definition PDEOps.H:213