ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImplicitDiff_S.cpp File Reference
#include "ERF_Diffusion.H"
#include "ERF_EddyViscosity.H"
#include "ERF_PBLModels.H"
#include "ERF_SetupVertDiff.H"
Include dependency graph for ERF_ImplicitDiff_S.cpp:

Functions

void ImplicitDiffForState_S (const Box &bx, const Box &domain, const int level, const Real dt, const GpuArray< Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const Array4< Real > &cell_data, const Gpu::DeviceVector< Real > &stretched_dz_d, const Array4< Real > &hfx_z, const Array4< const Real > &mu_turb, const SolverChoice &solverChoice, const BCRec *bc_ptr, const bool use_SurfLayer, const Real implicit_fac)
 

Function Documentation

◆ ImplicitDiffForState_S()

void ImplicitDiffForState_S ( const Box &  bx,
const Box &  domain,
const int  level,
const Real  dt,
const GpuArray< Real, AMREX_SPACEDIM *2 > &  bc_neumann_vals,
const Array4< Real > &  cell_data,
const Gpu::DeviceVector< Real > &  stretched_dz_d,
const Array4< Real > &  hfx_z,
const Array4< const Real > &  mu_turb,
const SolverChoice solverChoice,
const BCRec *  bc_ptr,
const bool  use_SurfLayer,
const Real  implicit_fac 
)

Function for computing the scalar RHS for diffusion operator without terrain.

Parameters
[in]bxcell-centered box to loop over
[in]domainbox of the whole domain
[in]dttime step
[in]bc_neumann_valsvalues of derivatives if bc_type == Neumann
[in,out]cell_dataconserved cell center vars
[in]stretched_dz_darray over z of dz[k]
[in,out]hfx_zheat flux in z-dir
[in]mu_turbturbulent viscosity
[in]solverChoicecontainer of parameters
[in]bc_ptrcontainer with boundary conditions
[in]use_SurfLayerwhether we have turned on subgrid diffusion
[in]implicit_facif 1 then fully implicit; if 0 then fully explicit
36 {
37  BL_PROFILE_VAR("ImplicitDiffForState_S()",ImplicitDiffForState_S);
38 
39  // this uses domain, level, start_comp, num_comp
40 #include "ERF_SetupVertDiff.H"
41 
42  const int n = RhoTheta_comp;
43  const int qty_index = RhoTheta_comp;
44  const int prim_index = qty_index - 1;
45  const int prim_scal_index = (qty_index >= RhoScalar_comp && qty_index < RhoScalar_comp+NSCALARS) ? PrimScalar_comp : prim_index;
46 
47  // Box bounds
48  int ilo = bx.smallEnd(0);
49  int ihi = bx.bigEnd(0);
50  int jlo = bx.smallEnd(1);
51  int jhi = bx.bigEnd(1);
52  int klo = bx.smallEnd(2);
53  int khi = bx.bigEnd(2);
54 
55  // Temporary FABs for tridiagonal solve (allocated on column)
56  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
57  amrex::FArrayBox RHS_fab, soln_fab, coeffA_fab, coeffB_fab, inv_coeffB_fab, coeffC_fab;
58  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
59  soln_fab.resize(bx,1, amrex::The_Async_Arena());
60  coeffA_fab.resize(bx,1, amrex::The_Async_Arena());
61  coeffB_fab.resize(bx,1, amrex::The_Async_Arena());
62  inv_coeffB_fab.resize(bx,1, amrex::The_Async_Arena());
63  coeffC_fab.resize(bx,1, amrex::The_Async_Arena());
64  auto const& RHS_a = RHS_fab.array();
65  auto const& soln_a = soln_fab.array();
66  auto const& coeffA_a = coeffA_fab.array(); // lower diagonal
67  auto const& coeffB_a = coeffB_fab.array(); // diagonal
68  auto const& inv_coeffB_a = inv_coeffB_fab.array();
69  auto const& coeffC_a = coeffC_fab.array(); // upper diagonal
70 
71  int bc_comp = qty_index;
72 
73  Real rhoAlpha_lo;
74  Real rhoAlpha_hi;
75 
76  auto dz_ptr = stretched_dz_d.data();
77 
78 // bool ext_dir_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir ||
79 // bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)
80 // bool ext_dir_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir ||
81 // bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)
82  bool neumann_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::neumann);
83  bool neumann_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::neumann);
84 
85  for (int j(jlo); j<=jhi; ++j) {
86  for (int i(ilo); i<=ihi; ++i) {
87 
88  // Build the coefficients and RHS
89  for (int k(klo); k <= khi; k++)
90  {
91  if (l_consA && l_turb) {
92  rhoAlpha_lo = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp) ) * d_alpha_eff[prim_scal_index]
93  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_scal_index])
94  + mu_turb(i,j,k-1, d_eddy_diff_idz[prim_scal_index]) );
95  rhoAlpha_hi = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k+1,Rho_comp) ) * d_alpha_eff[prim_scal_index]
96  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_scal_index])
97  + mu_turb(i,j,k+1, d_eddy_diff_idz[prim_scal_index]) );
98  }
99  else if (l_turb) // with MolecDiffType::Constant or None
100  {
101  rhoAlpha_lo = d_alpha_eff[prim_index]
102  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_index])
103  + mu_turb(i,j,k-1, d_eddy_diff_idz[prim_index]) );
104  rhoAlpha_hi = d_alpha_eff[prim_index]
105  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_index])
106  + mu_turb(i,j,k+1, d_eddy_diff_idz[prim_index]) );
107  }
108  else if (l_consA) // without an LES/PBL model
109  {
110  rhoAlpha_lo = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp) ) * d_alpha_eff[prim_index];
111  rhoAlpha_hi = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k+1,Rho_comp) ) * d_alpha_eff[prim_index];
112  }
113  else // with MolecDiffType::Constant or None - without an LES/PBL model
114  {
115  rhoAlpha_lo = d_alpha_eff[prim_index];
116  rhoAlpha_hi = d_alpha_eff[prim_index];
117  }
118 
119  Real dz_inv = 1.0 / dz_ptr[k];
120  Real dz_inv_lo = (k == dom_lo.z) ? dz_inv
121  : 2.0 / (dz_ptr[k] + dz_ptr[k-1]);
122  Real dz_inv_hi = (k == dom_hi.z) ? dz_inv
123  : 2.0 / (dz_ptr[k] + dz_ptr[k+1]);
124 
125  RHS_a(i,j,k) = cell_data(i,j,k,n); // Note this is rho*theta, whereas solution will be theta
126 
127  coeffA_a(i,j,k) = -implicit_fac * rhoAlpha_lo * dt * dz_inv * dz_inv_lo;
128  coeffC_a(i,j,k) = -implicit_fac * rhoAlpha_hi * dt * dz_inv * dz_inv_hi;
129 
130  if (k == dom_lo.z) {
131  if (use_SurfLayer) {
132  RHS_a(i,j,klo) += implicit_fac * dt * dz_inv * hfx_z(i,j,0);
133  } else if (neumann_on_zlo) {
134  RHS_a(i,j,klo) += coeffA_a(i,j,klo) * bc_neumann_vals[2] / dz_inv_lo;
135  }
136 
137  coeffA_a(i,j,klo) = 0.;
138  }
139  if (k == dom_hi.z) {
140  if (neumann_on_zhi) {
141  RHS_a(i,j,khi) -= coeffC_a(i,j,khi) * bc_neumann_vals[5] / dz_inv_hi;
142  }
143 
144  coeffC_a(i,j,khi) = 0.;
145  }
146 
147  coeffB_a(i,j,k) = cell_data(i,j,k,Rho_comp) - coeffA_a(i,j,k) - coeffC_a(i,j,k);
148  } // k
149 
150  // Forward sweep
151 
152  Real bet = coeffB_a(i,j,klo);
153 
154  for (int k(klo+1); k<=khi; ++k) {
155  Real gam = coeffC_a(i,j,k-1) / bet;
156  bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam;
157  AMREX_ASSERT(bet != 0.0);
158  coeffB_a(i,j,k) = bet;
159  }
160 
161  for (int k(klo); k<=khi; ++k) {
162  inv_coeffB_a(i,j,k) = 1.0 / coeffB_a(i,j,k);
163  }
164 
165  //
166  // Tridiagonal solve
167  //
168  soln_a(i,j,klo) = RHS_a(i,j,klo) * inv_coeffB_a(i,j,klo);
169 
170  for (int k(klo+1); k<=khi; ++k) {
171  soln_a(i,j,k) = (RHS_a(i,j,k)-coeffA_a(i,j,k)*soln_a(i,j,k-1)) * inv_coeffB_a(i,j,k);
172  }
173 
174  for (int k(khi-1); k>=klo; --k) {
175  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) * soln_a(i,j,k+1);
176  }
177 
178  //
179  // Transfer back to original array
180  //
181  for (int k(klo); k<=khi; ++k) {
182  cell_data(i,j,k,n) = soln_a(i,j,k) * cell_data(i,j,k,Rho_comp);
183  }
184 
185  } // i
186  } // j
187 }
void ImplicitDiffForState_S(const Box &bx, const Box &domain, const int level, const Real dt, const GpuArray< Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const Array4< Real > &cell_data, const Gpu::DeviceVector< Real > &stretched_dz_d, const Array4< Real > &hfx_z, const Array4< const Real > &mu_turb, const SolverChoice &solverChoice, const BCRec *bc_ptr, const bool use_SurfLayer, const Real implicit_fac)
Definition: ERF_ImplicitDiff_S.cpp:24
const int bc_comp
Definition: ERF_Implicit.H:8
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define PrimScalar_comp
Definition: ERF_IndexDefines.H:52
const auto & dom_hi
Definition: ERF_SetupVertDiff.H:2
bool l_turb
Definition: ERF_SetupVertDiff.H:8
const auto & dom_lo
Definition: ERF_SetupVertDiff.H:1
bool l_consA
Definition: ERF_SetupVertDiff.H:7
int * d_eddy_diff_idz
Definition: ERF_SetupVertDiff.H:107
Real * d_alpha_eff
Definition: ERF_SetupVertDiff.H:104
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ neumann
Definition: ERF_IndexDefines.H:213