SpatialOps
field_creation.cpp
Go to the documentation of this file.
1 
86 #include <spatialops/structured/FVStaggered.h> // everything required to build fields on structured meshes
87 
88 using namespace SpatialOps;
89 
90 // If we are compiling with GPU CUDA support, create fields on the device.
91 // Otherwise, create them on the host.
92 #ifdef ENABLE_CUDA
93 # define LOCATION GPU_INDEX
94 #else
95 # define LOCATION CPU_INDEX
96 #endif
97 
98 int main()
99 {
100  // SVolField = Scalar Volume Field (non-staggered, cell-centered field)
101  typedef SVolField FieldT;
102 
103  //----------------------------------------------------------------------------
104  // Use default values to create objects required to build a field:
105 
106  // Ghost cells are needed by some applications and operations
107  // In general, set ghost cells to zero, unless they are needed:
108  const GhostData nghost(0);
109 
110  // Determine if we have physical boundaries present on each right/positive (+) face.
111  const bool bcx=true, bcy=true, bcz=true;
112  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bcx, bcy, bcz );
113 
114  // Define the size of the field (nx,ny,nz)
115  const IntVec fieldDim( 10, 9, 8 );
116 
117  // Construct a memory window (logical extents of a field) from dimensions,
118  // ghost cell data, and boundary cell information
119  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
120 
121  //----------------------------------------------------------------------------
122  // Create a field from scratch
123  // parameters:
124  // window : logical extents for the field
125  // bcInfo : boundary cell information for the field
126  // nghost : ghost cell data for the field
127  // NULL : externally allocated memory (not needed here; hence, NULL)
128  // InternalStorage : internally manage memory (could also be ExternalStorage)
129  // LOCATION : CPU or GPU memory
130  FieldT f( window, bcInfo, nghost, NULL, InternalStorage, LOCATION );
131 
132  //----------------------------------------------------------------------------
133  // Create a field from a prototype using the "SpatialFieldStore." SpatFldPtr has
134  // regular pointer semantics but is a reference-counted pointer.
135  SpatFldPtr<FieldT> f2 = SpatialFieldStore::get<FieldT>(f); // field with same layout as "f"
136 
137  return 0;
138 }
139 
140 
Provides tools to index into a sub-block of memory.
Definition: MemoryWindow.h:63
MemoryWindow get_window_with_ghost(const IntVec &localDim, const GhostData &ghost, const BoundaryCellInfo &bc)
Obtain the memory window for a field on a patch that is a single, contiguous memory block...
Definition: MemoryWindow.h:314
Holds information about the number of ghost cells on each side of the domain.
Definition: GhostData.h:54
Abstracts a field.
Definition: SpatialField.h:132
Provides information about boundary cells for various fields.
Wrapper for pointers to SpatialField objects. Provides reference counting.