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 IntVec bc(bcx,bcy,bcz);
113  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bc, bc );
114 
115  // Define the size of the field (nx,ny,nz)
116  const IntVec fieldDim( 10, 9, 8 );
117 
118  // Construct a memory window (logical extents of a field) from dimensions,
119  // ghost cell data, and boundary cell information
120  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
121 
122  //----------------------------------------------------------------------------
123  // Create a field from scratch
124  // parameters:
125  // window : logical extents for the field
126  // bcInfo : boundary cell information for the field
127  // nghost : ghost cell data for the field
128  // NULL : externally allocated memory (not needed here; hence, NULL)
129  // InternalStorage : internally manage memory (could also be ExternalStorage)
130  // LOCATION : CPU or GPU memory
131  FieldT f( window, bcInfo, nghost, NULL, InternalStorage, LOCATION );
132 
133  //----------------------------------------------------------------------------
134  // Create a field from a prototype using the "SpatialFieldStore." SpatFldPtr has
135  // regular pointer semantics but is a reference-counted pointer.
136  SpatFldPtr<FieldT> f2 = SpatialFieldStore::get<FieldT>(f); // field with same layout as "f"
137 
138  return 0;
139 }
140 
141 
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.