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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/DiffusionOps.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
DiffusionOps.H
Go to the documentation of this file.
1#ifndef DIFFUSIONOPS_H
2#define DIFFUSIONOPS_H
3
10
11#include "AMReX_MLABecLaplacian.H"
12#include "AMReX_MLTensorOp.H"
13#include "AMReX_MLMG.H"
14#include "AMReX_AmrCore.H"
15#include "AMReX_MultiFabUtil.H"
16
17namespace amr_wind::pde {
18
28template <typename LinOp>
30{
31public:
33 PDEFields& fields,
34 const bool has_overset,
35 const bool mesh_mapping,
36 const std::string& prefix = "diffusion");
37
38 virtual ~DiffSolverIface() = default;
39
44 virtual void linsys_solve(const amrex::Real dt);
45
46 virtual void linsys_solve_impl();
47
48 virtual void set_acoeffs(LinOp& linop, const FieldState fstate);
49
50 template <typename L>
52 L& linop,
53 std::enable_if_t<std::is_same_v<L, amrex::MLTensorOp>>* /*unused*/
54 = nullptr)
55 {
56 const int nlevels = m_pdefields.repo.num_active_levels();
57 const auto& viscosity = m_pdefields.mueff;
58 const auto& geom = m_pdefields.repo.mesh().Geom();
59
60 for (int lev = 0; lev < nlevels; ++lev) {
62 geom[lev], viscosity(lev));
63 if (m_mesh_mapping) {
65 }
66 linop.setShearViscosity(lev, amrex::GetArrOfConstPtrs(b));
67 }
68 }
69
70 template <typename L>
72 L& linop,
73 std::enable_if_t<std::is_same_v<L, amrex::MLABecLaplacian>>* /*unused*/
74 = nullptr)
75 {
76 const int nlevels = m_pdefields.repo.num_active_levels();
77 const auto& viscosity = m_pdefields.mueff;
78 const auto& geom = m_pdefields.repo.mesh().Geom();
79
80 for (int lev = 0; lev < nlevels; ++lev) {
82 geom[lev], viscosity(lev));
83 if (m_mesh_mapping) {
85 }
86 linop.setBCoeffs(lev, amrex::GetArrOfConstPtrs(b));
87 }
88 }
89
90protected:
92 virtual void setup_operator(
93 LinOp& linop,
94 const amrex::Real alpha,
95 const amrex::Real beta,
96 const FieldState fstate);
97
98 virtual void setup_solver(amrex::MLMG& mlmg);
99
102
104
105 bool m_mesh_mapping{false};
106
107 std::unique_ptr<LinOp> m_solver;
108 std::unique_ptr<LinOp> m_applier;
109};
110
114template <typename PDE, typename Scheme>
116 PDE,
117 Scheme,
118 std::enable_if_t<std::is_base_of_v<ScalarTransport, PDE>>>
119 : public DiffSolverIface<typename PDE::MLDiffOp>
120{
121 static_assert(
122 PDE::ndim == 1, "DiffusionOp invoked for non-scalar PDE type");
123 static_assert(
124 std::is_same_v<typename PDE::MLDiffOp, amrex::MLABecLaplacian>,
125 "Invalid linear operator for scalar diffusion operator");
126
128 PDEFields& fields, const bool has_overset, const bool mesh_mapping)
129 : DiffSolverIface<typename PDE::MLDiffOp>(
130 fields, has_overset, mesh_mapping)
131 {
132 this->m_solver->setDomainBC(
134 this->m_pdefields.field, amrex::Orientation::low),
136 this->m_pdefields.field, amrex::Orientation::high));
137 this->m_applier->setDomainBC(
139 this->m_pdefields.field, amrex::Orientation::low),
141 this->m_pdefields.field, amrex::Orientation::high));
142 }
143
145 void compute_diff_term(const FieldState fstate)
146 {
147 this->setup_operator(*this->m_applier, 0.0, -1.0, fstate);
148
149 auto tau_state = std::is_same<Scheme, fvm::Godunov>::value
151 : fstate;
152 amrex::MLMG mlmg(*this->m_applier);
153 mlmg.apply(
154 this->m_pdefields.diff_term.state(tau_state).vec_ptrs(),
155 this->m_pdefields.field.vec_ptrs());
156 }
157};
158
159} // namespace amr_wind::pde
160
161#endif /* DIFFUSIONOPS_H */
Definition Field.H:116
int num_active_levels() const noexcept
Total number of levels currently active in the AMR mesh.
Definition FieldRepo.H:361
const amrex::AmrCore & mesh() const
Return a reference to the underlying AMR mesh instance.
Definition FieldRepo.H:358
Definition DiffusionOps.H:30
virtual void setup_solver(amrex::MLMG &mlmg)
Definition DiffusionOps.cpp:101
PDEFields & m_pdefields
Definition DiffusionOps.H:100
Field & m_density
Definition DiffusionOps.H:101
std::unique_ptr< LinOp > m_applier
Definition DiffusionOps.H:108
virtual void setup_operator(LinOp &linop, const amrex::Real alpha, const amrex::Real beta, const FieldState fstate)
Sets up the linear operator (e.g., setup BCs, etc.)
Definition DiffusionOps.cpp:54
void set_bcoeffs(L &linop, std::enable_if_t< std::is_same_v< L, amrex::MLABecLaplacian > > *=nullptr)
Definition DiffusionOps.H:71
MLMGOptions m_options
Definition DiffusionOps.H:103
virtual void linsys_solve_impl()
Definition DiffusionOps.cpp:109
bool m_mesh_mapping
Definition DiffusionOps.H:105
virtual void linsys_solve(const amrex::Real dt)
Definition DiffusionOps.cpp:157
std::unique_ptr< LinOp > m_solver
Definition DiffusionOps.H:107
void set_bcoeffs(L &linop, std::enable_if_t< std::is_same_v< L, amrex::MLTensorOp > > *=nullptr)
Definition DiffusionOps.H:51
virtual void set_acoeffs(LinOp &linop, const FieldState fstate)
Definition DiffusionOps.cpp:73
DiffSolverIface(PDEFields &fields, const bool has_overset, const bool mesh_mapping, const std::string &prefix="diffusion")
Definition DiffusionOps.cpp:9
virtual ~DiffSolverIface()=default
FieldState
Definition FieldDescTypes.H:14
@ New
Same as FieldState::NP1.
Definition AdvOp_Godunov.H:16
void viscosity_to_uniform_space(amrex::Array< amrex::MultiFab, AMREX_SPACEDIM > &b, const amr_wind::FieldRepo &repo, int lev)
Definition incflo_diffusion.cpp:205
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > get_diffuse_scalar_bc(amr_wind::Field &scalar, amrex::Orientation::Side side) noexcept
amrex::Array< amrex::MultiFab, AMREX_SPACEDIM > average_velocity_eta_to_faces(const amrex::Geometry &geom, amrex::MultiFab const &cc_eta)
Definition MLMGOptions.H:25
DiffusionOp(PDEFields &fields, const bool has_overset, const bool mesh_mapping)
Definition DiffusionOps.H:127
void compute_diff_term(const FieldState fstate)
Computes the diffusion term that goes in the RHS.
Definition DiffusionOps.H:145
Definition PDEOps.H:172
Definition PDEFields.H:27
Field & mueff
Effective visocity field (e.g., velocity_mueff)
Definition PDEFields.H:36
FieldRepo & repo
Reference to the field repository instance.
Definition PDEFields.H:31