SpatialOps
StencilBuilder.cpp
1 /*
2  * Copyright (c) 2014-2017 The University of Utah
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 
23 #include "StencilBuilder.h"
24 #include "FVStaggeredOperatorTypes.h"
26 #include <spatialops/structured/Grid.h>
28 
29 namespace SpatialOps{
30 
31 #define REG_BASIC_OP_TYPES( VOL ) \
32  { \
33  typedef BasicOpTypes<VOL> OpTypes; \
34  opdb.register_new_operator( new OpTypes::InterpC2FX( coefHalf ) ); \
35  opdb.register_new_operator( new OpTypes::InterpC2FY( coefHalf ) ); \
36  opdb.register_new_operator( new OpTypes::InterpC2FZ( coefHalf ) ); \
37  opdb.register_new_operator( new OpTypes::InterpF2CX( coefHalf ) ); \
38  opdb.register_new_operator( new OpTypes::InterpF2CY( coefHalf ) ); \
39  opdb.register_new_operator( new OpTypes::InterpF2CZ( coefHalf ) ); \
40  opdb.register_new_operator( new OpTypes::GradX( coefDx ) ); \
41  opdb.register_new_operator( new OpTypes::GradY( coefDy ) ); \
42  opdb.register_new_operator( new OpTypes::GradZ( coefDz ) ); \
43  opdb.register_new_operator( new OpTypes::DivX ( coefDx ) ); \
44  opdb.register_new_operator( new OpTypes::DivY ( coefDy ) ); \
45  opdb.register_new_operator( new OpTypes::DivZ ( coefDz ) ); \
46  }
47 
48  //------------------------------------------------------------------
49 
50  // defined in StencilBuilderCustom.cpp
51  void build_custom_stencils( const unsigned int nx,
52  const unsigned int ny,
53  const unsigned int nz,
54  const double Lx,
55  const double Ly,
56  const double Lz,
57  OperatorDatabase& opdb );
58 
59  //------------------------------------------------------------------
60 
61  void build_stencils( const unsigned int nx,
62  const unsigned int ny,
63  const unsigned int nz,
64  const double Lx,
65  const double Ly,
66  const double Lz,
67  OperatorDatabase& opdb )
68  {
69  const double dx = Lx/nx;
70  const double dy = Ly/ny;
71  const double dz = Lz/nz;
72 
73  //Coefficients:
74  NeboStencilCoefCollection<2> coefHalf = build_two_point_coef_collection( 0.5, 0.5 );
75  NeboStencilCoefCollection<2> coefDx = build_two_point_coef_collection( -1.0/dx, 1.0/dx );
76  NeboStencilCoefCollection<2> coefDy = build_two_point_coef_collection( -1.0/dy, 1.0/dy );
77  NeboStencilCoefCollection<2> coefDz = build_two_point_coef_collection( -1.0/dz, 1.0/dz );
78  NeboStencilCoefCollection<4> coefQuarter = build_four_point_coef_collection( 0.25, 0.25, 0.25, 0.25 );
79  NeboStencilCoefCollection<2> coefHalfDx = build_two_point_coef_collection( -0.5/dx, 0.5/dx );
80  NeboStencilCoefCollection<2> coefHalfDy = build_two_point_coef_collection( -0.5/dy, 0.5/dy );
81  NeboStencilCoefCollection<2> coefHalfDz = build_two_point_coef_collection( -0.5/dz, 0.5/dz );
82 
83  //___________________________________________________________________
84  // stencil2:
85  //
86  REG_BASIC_OP_TYPES( SVolField ) // basic operator types on a scalar volume
87  REG_BASIC_OP_TYPES( XVolField ) // basic operator types on a x volume
88  REG_BASIC_OP_TYPES( YVolField ) // basic operator types on a y volume
89  REG_BASIC_OP_TYPES( ZVolField ) // basic operator types on a z volume
90 
95 
100 
105 
108 
111 
114 
117 
120 
123 
124  // the following six operators are needed for calculating the strain tensor on a collocated grid
127 
130 
133 
134  //___________________________________________________________________
135  // NullStencil:
136  //
141 
145 
149 
153 
157 
158  //___________________________________________________________________
159  // stencil4:
160  //
163 
166 
169 
176 
183 
184  //___________________________________________________________________
185  // Box filter:
186  //
191 
195 
199 
203 
204  // note that this splits out some of the stencil building to allow parallel
205  // compilation since this leans pretty heavily on the compiler
206  build_custom_stencils( nx, ny, nz, Lx, Ly, Lz, opdb );
207  }
208 
209  //------------------------------------------------------------------
210 
211  void build_stencils( const Grid& grid, OperatorDatabase& opDB )
212  {
213  build_stencils( grid.extent(0), grid.extent(1), grid.extent(2),
214  grid.length(0), grid.length(1), grid.length(2),
215  opDB );
216  }
217 
218 } // namespace SpatialOps
Provides a simple interface to set coordinate fields.
Definition: Grid.h:36
void build_stencils(const Grid &grid, OperatorDatabase &opDB)
builds commonly used stencil operators
int register_new_operator(OpT *const op)
Register a new operator of the given type.
Builds operator types from field types and operator type descriptors.
Provides a database to hold operators of any type.
Abstracts a field.
Definition: SpatialField.h:132