ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImplicitDiff_N.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_N.cpp:

Functions

void ImplicitDiffForState_N (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 GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, 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_N()

void ImplicitDiffForState_N ( 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 GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
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]levelAMR level
[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]cellSizeInvinverse cell size array
[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
37 {
38  BL_PROFILE_VAR("ImplicitDiffForState_N()",ImplicitDiffForState_N);
39 
40  // this uses domain, level, start_comp, num_comp
41 #include "ERF_SetupVertDiff.H"
42 
43  const int n = RhoTheta_comp;
44  const int qty_index = RhoTheta_comp;
45  const int prim_index = qty_index - 1;
46  const int prim_scal_index = (qty_index >= RhoScalar_comp && qty_index < RhoScalar_comp+NSCALARS) ? PrimScalar_comp : prim_index;
47 
48  // Box bounds
49  int ilo = bx.smallEnd(0);
50  int ihi = bx.bigEnd(0);
51  int jlo = bx.smallEnd(1);
52  int jhi = bx.bigEnd(1);
53  int klo = bx.smallEnd(2);
54  int khi = bx.bigEnd(2);
55 
56  // Temporary FABs for tridiagonal solve (allocated on column)
57  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
58  amrex::FArrayBox RHS_fab, soln_fab, coeffA_fab, coeffB_fab, inv_coeffB_fab, coeffC_fab;
59  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
60  soln_fab.resize(bx,1, amrex::The_Async_Arena());
61  coeffA_fab.resize(bx,1, amrex::The_Async_Arena());
62  coeffB_fab.resize(bx,1, amrex::The_Async_Arena());
63  inv_coeffB_fab.resize(bx,1, amrex::The_Async_Arena());
64  coeffC_fab.resize(bx,1, amrex::The_Async_Arena());
65  auto const& RHS_a = RHS_fab.array();
66  auto const& soln_a = soln_fab.array();
67  auto const& coeffA_a = coeffA_fab.array(); // lower diagonal
68  auto const& coeffB_a = coeffB_fab.array(); // diagonal
69  auto const& inv_coeffB_a = inv_coeffB_fab.array();
70  auto const& coeffC_a = coeffC_fab.array(); // upper diagonal
71 
72  int bc_comp = qty_index;
73 
74  Real rhoAlpha_lo;
75  Real rhoAlpha_hi;
76 
77  Real dz_inv = cellSizeInv[2];
78 
79 // bool ext_dir_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir ||
80 // bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)
81 // bool ext_dir_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir ||
82 // bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)
83  bool neumann_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::neumann);
84  bool neumann_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::neumann);
85 
86  for (int j(jlo); j<=jhi; ++j) {
87  for (int i(ilo); i<=ihi; ++i) {
88 
89  // Build the coefficients and RHS
90  for (int k(klo); k <= khi; k++)
91  {
92  if (l_consA && l_turb) {
93  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]
94  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_scal_index])
95  + mu_turb(i,j,k-1, d_eddy_diff_idz[prim_scal_index]) );
96  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]
97  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_scal_index])
98  + mu_turb(i,j,k+1, d_eddy_diff_idz[prim_scal_index]) );
99  }
100  else if (l_turb) // with MolecDiffType::Constant or None
101  {
102  rhoAlpha_lo = d_alpha_eff[prim_index]
103  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_index])
104  + mu_turb(i,j,k-1, d_eddy_diff_idz[prim_index]) );
105  rhoAlpha_hi = d_alpha_eff[prim_index]
106  + 0.5 * ( mu_turb(i,j,k , d_eddy_diff_idz[prim_index])
107  + mu_turb(i,j,k+1, d_eddy_diff_idz[prim_index]) );
108  }
109  else if (l_consA) // without an LES/PBL model
110  {
111  rhoAlpha_lo = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp) ) * d_alpha_eff[prim_index];
112  rhoAlpha_hi = 0.5 * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k+1,Rho_comp) ) * d_alpha_eff[prim_index];
113  }
114  else // with MolecDiffType::Constant or None - without an LES/PBL model
115  {
116  rhoAlpha_lo = d_alpha_eff[prim_index];
117  rhoAlpha_hi = d_alpha_eff[prim_index];
118  }
119 
120  RHS_a(i,j,k) = cell_data(i,j,k,n); // Note this is rho*theta, whereas solution will be theta
121 
122  coeffA_a(i,j,k) = -implicit_fac * rhoAlpha_lo * dt * dz_inv * dz_inv;
123  coeffC_a(i,j,k) = -implicit_fac * rhoAlpha_hi * dt * dz_inv * dz_inv;
124 
125  if (k == dom_lo.z) {
126  if (use_SurfLayer) {
127  RHS_a(i,j,klo) += implicit_fac * dt * dz_inv * hfx_z(i,j,0);
128  } else if (neumann_on_zlo) {
129  RHS_a(i,j,klo) += coeffA_a(i,j,klo) * bc_neumann_vals[2] / dz_inv;
130  }
131 
132  coeffA_a(i,j,klo) = 0.;
133  }
134  if (k == dom_hi.z) {
135  if (neumann_on_zhi) {
136  RHS_a(i,j,khi) -= coeffC_a(i,j,khi) * bc_neumann_vals[5] / dz_inv;
137  }
138 
139  coeffC_a(i,j,khi) = 0.;
140  }
141 
142  coeffB_a(i,j,k) = cell_data(i,j,k,Rho_comp) - coeffA_a(i,j,k) - coeffC_a(i,j,k);
143  } // k
144 
145  // Forward sweep
146 
147  Real bet = coeffB_a(i,j,klo);
148 
149  for (int k(klo+1); k<=khi; ++k) {
150  Real gam = coeffC_a(i,j,k-1) / bet;
151  bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam;
152  AMREX_ASSERT(bet != 0.0);
153  coeffB_a(i,j,k) = bet;
154  }
155 
156  for (int k(klo); k<=khi; ++k) {
157  inv_coeffB_a(i,j,k) = 1.0 / coeffB_a(i,j,k);
158  }
159 
160  //
161  // Tridiagonal solve
162  //
163  soln_a(i,j,klo) = RHS_a(i,j,klo) * inv_coeffB_a(i,j,klo);
164 
165  for (int k(klo+1); k<=khi; ++k) {
166  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);
167  }
168 
169  for (int k(khi-1); k>=klo; --k) {
170  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) * soln_a(i,j,k+1);
171  }
172 
173  //
174  // Transfer back to original array
175  //
176  for (int k(klo); k<=khi; ++k) {
177  cell_data(i,j,k,n) = soln_a(i,j,k) * cell_data(i,j,k,Rho_comp);
178  }
179 
180  } // i
181  } // j
182 }
void ImplicitDiffForState_N(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 GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, 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_N.cpp:25
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