Chombo + EB + MF  3.2
CubedSphereShellPanelCS.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _CUBEDSPHERESHELLPANELCS_H_
12 #define _CUBEDSPHERESHELLPANELCS_H_
13 
14 #include <utility>
15 using std::pair;
16 
17 #include "REAL.H"
18 #include "DisjointBoxLayout.H"
19 #include "RealVect.H"
20 #include "IntVect.H"
21 #include "LevelData.H"
22 #include "FArrayBox.H"
23 #include "FluxBox.H"
24 #include "Vector.H"
25 #include "NewFourthOrderCoordSys.H"
26 #include "Spline1DMapping.H"
27 
28 #include "NamespaceHeader.H"
29 // #include "UsingNamespace.H"
30 
31 /// Basic single-panel cubed sphere Coordinates
32 /// Multiblock coordinate system for single-panel cubed sphere shell
33 /// with variable-thickness spherical layers
34 /**
35  The CubedSphereShellPanelCS class implements the NewFourthOrderCoordSys class
36  for cubed sphere panels in equiangular coordinates, with variable-thickness
37  layers making up the shell in the r direction, total r thickness "height".
38  NOTE: Assumes a "thin atmosphere" approximation which ignores the
39  r dependencies of the horizontal grid metrics
40  NOTE: For 2D, hdf5 output uses sphere radius = 1, and for 3D r \in [1,2]
41 */
43 {
44 public:
45  /// constructor
46  /**
47  nPanel
48  (0-3 Equatorial, 4 North Pole, 5 South Pole) and defines the
49  panel on the cubed sphere described by this object.
50  dDX
51  The cell spacing on this panel.
52  ix
53  Index of the bottom-left edge of this panel in index space.
54  */
55  CubedSphereShellPanelCS(int nPanel, RealVect& dDX, IntVect& ix);
56 
57  void setFlatMap(bool a_flatMap);
58 
59  // Height of the atmosphere
60  void setHeight(Real a_height)
61  {
62  CH_assert(a_height > 0);
63  m_height = a_height;
64  }
65 
66  // Height of the atmosphere
67  Real getHeight() const
68  {
69  CH_assert(m_height > 0);
70  return m_height;
71  }
72 
73  // Constant radius of the sphere
74  void setRadius(Real a_radius)
75  {
76  CH_assert(a_radius > 0);
77  m_radius = a_radius;
78  }
79 
80  // Radius of the earth
81  Real getRadius() const
82  {
83  CH_assert(m_radius > 0);
84  return m_radius;
85  }
86 
87  // Sets the vertical mapping, if there is one
89  {
90  m_verticalMap = a_map;
91  }
92 
94  {
96  return m_verticalMap;
97  }
98 
99  /**
100  Destructor.
101  */
102  virtual ~CubedSphereShellPanelCS();
103 
104  //void panel(int nPanel) {m_nPanel = nPanel;}
105 
106  /// given coordinate in mapped space, return its location in real space
107  RealVect realCoord(const RealVect& a_Xi) const;
108 
109  void realCoord(FArrayBox& a_x,
110  const FArrayBox& a_Xi,
111  const Box& a_box) const;
112 
113  /// given coordinate in real space, return its location in the mapped space
114  RealVect mappedCoord(const RealVect& a_x) const;
115 
116  /// return Cartesian XYZ locations of cell centers
117  virtual void getNodeRealCoordinates(FArrayBox& a_nodeCoords,
118  const Box& a_box) const;
119 
120  // return cell center positions in mapped coordinates
121  virtual void getCellMappedCoordinates(FArrayBox& a_cellCoords,
122  const Box& a_box) const;
123 
124  // return face center positions in mapped coordinates
125  virtual void getFaceMappedCoordinates(FArrayBox& a_faceCoords,
126  const int a_dir,
127  const Box& a_box) const;
128 
129  // return node positions in mapped coordinates
130  virtual void getNodeMappedCoordinates(FArrayBox& a_nodeCoords,
131  const Box& a_box) const;
132 
133  // return positions in mapped coordinates, depending on centering of a_box
134  virtual void getMappedCoordinates(FArrayBox& a_coords,
135  const Box& a_box) const;
136 
137  // Calculate the derivative of each Cartesian coordinate vector
138  virtual Real dXdXi(const RealVect& a_Xi, int a_dirX, int a_dirXi) const;
139 
140  // Calculate the derivative of each mapped coordinate vector
141  virtual Real dXidX(const RealVect& a_X, int a_dirX, int a_dirXi) const;
142 
143  /// returns dimensionality of the space (3, or 2 if flat)
144  /**
145  */
146  virtual int dimension() const
147  {
148  return m_realDim;
149  }
150 
151  /// computes cell volumes
152  virtual void cellVol(FArrayBox& a_vol,
153  const FluxBox& a_N,
154  const Box& a_box) const;
155 
156  /// computes NT * F.
157  virtual void volFlux(FluxBox& a_volFlux,
158  const FluxBox& a_Nt,
159  const Box& a_box) const;
160 
161  /// computes face-centered N
162  virtual void getN(FluxBox& a_N, const Box& a_box) const;
163 
164  /// computes cell-averaged J
165  virtual void getAvgJ(FArrayBox& a_avgJ, const Box& a_box) const;
166 
167  /// computes line element metrics in each coordinate direction
168  void getLineMetrics(FArrayBox& a_metrics, const Box& a_box) const;
169 
170  /// computes cell-averaged J; ignores a_volFlux
171  virtual void getAvgJ(FArrayBox& a_avgJ,
172  const FluxBox& a_volFlux,
173  const Box& a_box) const;
174 
175  /// computes face-averaged 1/J
176  virtual void getAvgJinverse(FluxBox& a_avgJinverse,
177  const Box& a_box) const;
178 
179  /// Jacobian evaluated at location X in real space
180  virtual Real pointwiseJ(const RealVect& a_X) const;
181 
182  /// Jacobian evaluated at locations Xi in mapped space
183  virtual void pointwiseJ(FArrayBox& a_J,
184  const FArrayBox& a_Xi,
185  const Box& a_box) const;
186 
187  /// returns integral of divergence over mapped-grid cells
188  virtual void computeDivergence(FArrayBox& a_divF,
189  const FluxBox& a_F,
190  const FluxBox& a_N,
191  const Box& a_box,
192  Interval& divInterval) const;
193 
194  /// this evaluates the script N values from equation 12 in Phil's notes
195  /** note that a_Xi is in mapped space.
196  */
197  virtual Real getN(const RealVect& a_Xi, int a_s, int a_d, int a_d1) const;
198 
199  virtual Real getNMatrixEntry(const RealVect& a_Xi,
200  int a_s, int a_d, int a_d1,
201  int a_row, int a_column) const;
202 
203  /// transform a point from mapped-coordinate basis to longitude-latitude
204  /// coordinate basis
206  RealVect & a_rllXi) const;
207 
208  /// transform a point from mapped-coordinate basis to Cartesian
209  /// coordinate basis
211  Real * a_xyz) const;
212 
213  /// transform a FAB of points from mapped-coordinate basis to latitude-longitude
214  /// coordinate basis
216  const FArrayBox& a_xiFab,
217  FArrayBox& a_rllXiFab) const;
218 
219  /// transform a FAB of points from mapped-coordinate basis to Cartesian
220  /// coordinate basis
222  const FArrayBox& a_xiFab,
223  FArrayBox& a_xyzFab) const;
224 
225  /// transform a vector from mapped-coordinate basis to real-coordinate basis,
226  /// given a point a_xi in mapped space
228  const Real * a_vecCS,
229  Real * a_vecXYZ) const;
230 
231  /// transform a vector from real-coordinate basis to mapped-coordinate basis,
232  /// given a point a_xi in mapped space
234  const Real * a_vecXYZ,
235  Real * a_vecCS) const;
236 
237  /// transform a vector from longitude-latitude coordinate basis to
238  /// mapped-coordinate basis
240  const RealVect& a_vecRLL,
241  RealVect& a_vecCS) const;
242 
243  /// transform a FAB of vectors from latitude-longitude coordinate basis to
244  /// mapped-coordinate basis
246  const FArrayBox& a_xiFab,
247  const FArrayBox& a_vecRLLFab,
248  FArrayBox& a_vecCSFab) const;
249 
250  /// transform a FAB of vectors from mapped-coordinate basis to
251  /// latitude-longitude coordinate basis
253  const FArrayBox& a_xiFab,
254  const FArrayBox& a_vecCSFab,
255  FArrayBox& a_vecRLLFab) const;
256 
257  /// transform a FAB of SpaceDim-vectors from mapped-coordinate basis to real-coordinate basis at cell centers
258  virtual void vectorTransformMappedToRealCenterFab(FArrayBox& a_vectorFab) const;
259 
260  /// transform a FAB of SpaceDim-vectors from real-coordinate basis to mapped-coordinate basis at cell centers
261  virtual void vectorTransformRealToMappedCenterFab(FArrayBox& a_vectorFab) const;
262 
263  /// return row a_idir of contravariant metric
264  virtual void contravariantMetric(FArrayBox& a_metric,
265  int a_dir) const;
266 
267  /// convert components in a_csComps of vector a_csFab in coordinate-system basis to components in a_orthoComps of vector a_orthoFab in orthonormal basis, at points with indices in a_box, on lines where direction a_idir is constant
268  virtual void orthonormalize(
269  const FArrayBox& a_csFab,
270  FArrayBox& a_orthoFab,
271  const Box& a_box,
272  int a_idir,
273  const IntVect& a_csComps,
274  const IntVect& a_orthoComps) const;
275 
276  /// convert components in a_orthoComps of vector a_orthoFab in orthonormal basis to components in a_csComps of vector a_csFab in coordinate-system basis, at points with indices in a_box, on lines where direction a_idir is constant
277  virtual void deorthonormalize(
278  const FArrayBox& a_orthoFab,
279  FArrayBox& a_csFab,
280  const Box& a_box,
281  int a_idir,
282  const IntVect& a_orthoComps,
283  const IntVect& a_csComps) const;
284 
285  /// convert from fluxes in block frame in component directions to fluxes in orthonormal frame in normal and tangential directions
286  virtual void orthonormalizeVectorFluxes(
287  FArrayBox& a_fluxFab,
288  const Box& a_box,
289  const Interval& a_vectorIntv) const;
290 
291  /// convert from fluxes in orthonormal frame in normal and tangential directions to fluxes in block frame in component directions
292  virtual void deorthonormalizeVectorFluxes(
293  FArrayBox& a_fluxFab,
294  const Box& a_box,
295  const Interval& a_vectorIntv) const;
296 
297  /// convert from fluxes in block frame in component directions to fluxes in orthonormal frame in normal and tangential directions
298  virtual void orthonormalizeVectorFluxes(
299  FluxBox& a_flux,
300  const Interval& a_vectorIntv) const;
301 
302  /// convert from fluxes in orthonormal frame in normal and tangential directions to fluxes in block frame in component directions
303  virtual void deorthonormalizeVectorFluxes(
304  FluxBox& a_flux,
305  const Interval& a_vectorIntv) const;
306 
307 #if 0
308  /// return coefficients to convert components of a vector from coordinate-system basis to orthonormal basis, at points with indices in a_box, on lines where direction a_idir is constant
309  virtual void getOrthonormalizingMatrix(
310  FArrayBox& a_matrixFab,
311  const Box& a_box,
312  int a_idir) const;
313 
314  /// return coefficients to convert components of a vector from orthonormal basis to coordinate-system basis, at points with indices in a_box, on lines where direction a_idir is constant
315  virtual void getDeorthonormalizingMatrix(
316  FArrayBox& a_matrixFab,
317  const Box& a_box,
318  int a_idir) const;
319 
320 #endif
321 
322  /// return cell-centered radial component of curl of a_vecFab, which has SpaceDim components and is cell-centered.
323  virtual void curlRadial(
324  const FArrayBox& a_vecFab,
325  FArrayBox& a_curlFab,
326  const Box& a_box) const;
327 
328 
329  /// return radial component of curl of a_vecRLLFab, which has SpaceDim components and is cell-centered, by converting to spherical coordinates.
330  virtual void curlSpherical(
331  const FArrayBox& a_vecRLLFab,
332  FArrayBox& a_curlFab,
333  const Box& a_box) const;
334 
335  /// return face-centered divergence of a_vecRLLFab, which has SpaceDim components and is cell-centered, by converting to spherical coordinates.
336  virtual void divSpherical(
337  const FArrayBox& a_vecRLLFab,
338  FluxBox& a_divFlux,
339  const Box& a_box) const;
340 
341  /// return cell-centered gradient of a_fab, with derivatives of all components in the alpha direction, then all in beta direction, then all in r direction.
342  virtual void gradient(
343  const FArrayBox& a_fab,
344  FArrayBox& a_gradFab,
345  const Box& a_box) const;
346 
347  /// return magnitude of SpaceDim-vector with all components (in UNIT basis) in alpha direction, then all in beta direction, then all in r direction.
348  virtual void magnitude(
349  const FArrayBox& a_vecFab,
350  FArrayBox& a_magFab,
351  const Box& a_box) const;
352 
353  /// return magnitude of SpaceDim-vector with components in NATURAL basis.
354  virtual void magnitudeNatural(
355  const FArrayBox& a_vecFab,
356  FArrayBox& a_magFab,
357  const Box& a_box) const;
358 
359  /// access function to panel id
360  int panel() const
361  {
362  return m_nPanel;
363  }
364 
365  /// returns G^{ij}J averaged over faces of direction a_dir
366  void getContravariantMetricJAverage(FArrayBox& a_matrixFab,const int a_dir) const;
367 
368 protected:
369  // Panel id (this object has different behaviour depending on the panel)
370  int m_nPanel;
371 
372  // number of dimensions in real space
374 
375  // Height of the domain in r direction
377 
378  // Radius of the domain in r direction
380 
381  // whether to map to a flat plane; default false
382  bool m_flatMap;
383 
384  // Pointer to a vertical mapping class
386 
387  // Index of the bottom-left edge of this panel in index space
389 };
390 
391 #include "NamespaceFooter.H"
392 
393 #endif
int panel() const
access function to panel id
Definition: CubedSphereShellPanelCS.H:360
virtual void getCellMappedCoordinates(FArrayBox &a_cellCoords, const Box &a_box) const
virtual void getN(FluxBox &a_N, const Box &a_box) const
computes face-centered N
virtual Real getNMatrixEntry(const RealVect &a_Xi, int a_s, int a_d, int a_d1, int a_row, int a_column) const
note that a_Xi is in mapped space.
void fabVectorTransformLatLonToEquiangular(const FArrayBox &a_xiFab, const FArrayBox &a_vecRLLFab, FArrayBox &a_vecCSFab) const
virtual void orthonormalize(const FArrayBox &a_csFab, FArrayBox &a_orthoFab, const Box &a_box, int a_idir, const IntVect &a_csComps, const IntVect &a_orthoComps) const
convert components in a_csComps of vector a_csFab in coordinate-system basis to components in a_ortho...
void getLineMetrics(FArrayBox &a_metrics, const Box &a_box) const
computes line element metrics in each coordinate direction
virtual Real dXidX(const RealVect &a_X, int a_dirX, int a_dirXi) const
RefCountedPtr< Spline1DMapping > getVerticalMap() const
Definition: CubedSphereShellPanelCS.H:93
#define CH_assert(cond)
Definition: CHArray.H:37
void fabTransformEquiangularToLonLat(const FArrayBox &a_xiFab, FArrayBox &a_rllXiFab) const
virtual void getAvgJinverse(FluxBox &a_avgJinverse, const Box &a_box) const
computes face-averaged 1/J
void vectorTransformEquiangularToCartesian(const RealVect &a_xi, const Real *a_vecCS, Real *a_vecXYZ) const
void setFlatMap(bool a_flatMap)
virtual void contravariantMetric(FArrayBox &a_metric, int a_dir) const
return row a_idir of contravariant metric
Virtual base class encapsulating mapped-grid coordinate systems.
Definition: NewFourthOrderCoordSys.H:77
Definition: CubedSphereShellPanelCS.H:42
void setVerticalMap(RefCountedPtr< Spline1DMapping > a_map)
Definition: CubedSphereShellPanelCS.H:88
Real m_radius
Definition: CubedSphereShellPanelCS.H:379
virtual int dimension() const
returns dimensionality of the space (3, or 2 if flat)
Definition: CubedSphereShellPanelCS.H:146
bool m_flatMap
Definition: CubedSphereShellPanelCS.H:382
int m_realDim
Definition: CubedSphereShellPanelCS.H:373
CubedSphereShellPanelCS(int nPanel, RealVect &dDX, IntVect &ix)
constructor
virtual void curlSpherical(const FArrayBox &a_vecRLLFab, FArrayBox &a_curlFab, const Box &a_box) const
return radial component of curl of a_vecRLLFab, which has SpaceDim components and is cell-centered...
bool isNull() const
Definition: RefCountedPtr.H:599
void getContravariantMetricJAverage(FArrayBox &a_matrixFab, const int a_dir) const
returns G^{ij}J averaged over faces of direction a_dir
virtual void getAvgJ(FArrayBox &a_avgJ, const Box &a_box) const
computes cell-averaged J
virtual void getMappedCoordinates(FArrayBox &a_coords, const Box &a_box) const
A FArrayBox-like container for face-centered fluxes.
Definition: FluxBox.H:22
virtual Real dXdXi(const RealVect &a_Xi, int a_dirX, int a_dirXi) const
note that a_Xi is in mapped space.
virtual void deorthonormalize(const FArrayBox &a_orthoFab, FArrayBox &a_csFab, const Box &a_box, int a_idir, const IntVect &a_orthoComps, const IntVect &a_csComps) const
convert components in a_orthoComps of vector a_orthoFab in orthonormal basis to components in a_csCom...
Structure for passing component ranges in code.
Definition: Interval.H:23
virtual void orthonormalizeVectorFluxes(FArrayBox &a_fluxFab, const Box &a_box, const Interval &a_vectorIntv) const
convert from fluxes in block frame in component directions to fluxes in orthonormal frame in normal a...
virtual void magnitude(const FArrayBox &a_vecFab, FArrayBox &a_magFab, const Box &a_box) const
return magnitude of SpaceDim-vector with all components (in UNIT basis) in alpha direction, then all in beta direction, then all in r direction.
IntVect m_ix
Definition: CubedSphereShellPanelCS.H:388
virtual void getNodeMappedCoordinates(FArrayBox &a_nodeCoords, const Box &a_box) const
void vectorTransformLatLonToEquiangular(const RealVect &a_xi, const RealVect &a_vecRLL, RealVect &a_vecCS) const
void fabTransformEquiangularToCartesian(const FArrayBox &a_xiFab, FArrayBox &a_xyzFab) const
double Real
Definition: REAL.H:33
virtual Real pointwiseJ(const RealVect &a_X) const
Jacobian evaluated at location X in real space.
void fabVectorTransformEquiangularToLatLon(const FArrayBox &a_xiFab, const FArrayBox &a_vecCSFab, FArrayBox &a_vecRLLFab) const
RealVect realCoord(const RealVect &a_Xi) const
given coordinate in mapped space, return its location in real space
RefCountedPtr< Spline1DMapping > m_verticalMap
Definition: CubedSphereShellPanelCS.H:385
virtual void vectorTransformRealToMappedCenterFab(FArrayBox &a_vectorFab) const
transform a FAB of SpaceDim-vectors from real-coordinate basis to mapped-coordinate basis at cell cen...
void pointTransformEquiangularToCartesian(const RealVect &a_xi, Real *a_xyz) const
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
virtual void getFaceMappedCoordinates(FArrayBox &a_faceCoords, const int a_dir, const Box &a_box) const
virtual void gradient(const FArrayBox &a_fab, FArrayBox &a_gradFab, const Box &a_box) const
return cell-centered gradient of a_fab, with derivatives of all components in the alpha direction...
virtual void volFlux(FluxBox &a_volFlux, const FluxBox &a_Nt, const Box &a_box) const
computes NT * F.
Real m_height
Definition: CubedSphereShellPanelCS.H:376
virtual void computeDivergence(FArrayBox &a_divF, const FluxBox &a_F, const FluxBox &a_N, const Box &a_box, Interval &divInterval) const
returns integral of divergence over mapped-grid cells
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:45
virtual void vectorTransformMappedToRealCenterFab(FArrayBox &a_vectorFab) const
transform a FAB of SpaceDim-vectors from mapped-coordinate basis to real-coordinate basis at cell cen...
void setHeight(Real a_height)
Definition: CubedSphereShellPanelCS.H:60
virtual void magnitudeNatural(const FArrayBox &a_vecFab, FArrayBox &a_magFab, const Box &a_box) const
return magnitude of SpaceDim-vector with components in NATURAL basis.
int m_nPanel
Definition: CubedSphereShellPanelCS.H:370
virtual void getNodeRealCoordinates(FArrayBox &a_nodeCoords, const Box &a_box) const
return Cartesian XYZ locations of cell centers
Real getHeight() const
Definition: CubedSphereShellPanelCS.H:67
void setRadius(Real a_radius)
Definition: CubedSphereShellPanelCS.H:74
void vectorTransformCartesianToEquiangular(const RealVect &a_xi, const Real *a_vecXYZ, Real *a_vecCS) const
virtual void deorthonormalizeVectorFluxes(FArrayBox &a_fluxFab, const Box &a_box, const Interval &a_vectorIntv) const
convert from fluxes in orthonormal frame in normal and tangential directions to fluxes in block frame...
virtual ~CubedSphereShellPanelCS()
virtual void divSpherical(const FArrayBox &a_vecRLLFab, FluxBox &a_divFlux, const Box &a_box) const
return face-centered divergence of a_vecRLLFab, which has SpaceDim components and is cell-centered...
Real getRadius() const
Definition: CubedSphereShellPanelCS.H:81
void pointTransformEquiangularToLonLat(const RealVect &a_xi, RealVect &a_rllXi) const
virtual void cellVol(FArrayBox &a_vol, const FluxBox &a_N, const Box &a_box) const
computes cell volumes
virtual void curlRadial(const FArrayBox &a_vecFab, FArrayBox &a_curlFab, const Box &a_box) const
return cell-centered radial component of curl of a_vecFab, which has SpaceDim components and is cell-...
RealVect mappedCoord(const RealVect &a_x) const
given coordinate in real space, return its location in the mapped space