SpatialOps
field_reductions.cpp
Go to the documentation of this file.
1 
51 #include <spatialops/structured/Grid.h>
52 
53 #include <iostream>
54 #include <iomanip>
55 
56 using namespace SpatialOps;
57 using namespace std;
58 
59 int main()
60 {
61  typedef SVolField FieldT;
62 
63  // Define the size and number of points in the domain.
64  const IntVec fieldDim( 10, 10, 10 ); // 10 x 10 x 10 points
65  const DoubleVec length( 1.0, 1.0, 1.0 ); // a cube of unit length
66 
67  //----------------------------------------------------------------------------
68  // Create fields of type FieldT.
69 
70  const bool bcx=true, bcy=true, bcz=true;
71  const IntVec bc(bcx,bcy,bcz);
72  const GhostData nghost(0);
73  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bc, bc );
74  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
75 
76  FieldT x( window, bcInfo, nghost, NULL, InternalStorage );
77  FieldT y( window, bcInfo, nghost, NULL, InternalStorage );
78  FieldT z( window, bcInfo, nghost, NULL, InternalStorage );
79 
80  FieldT f( window, bcInfo, nghost, NULL, InternalStorage );
81 
82  //----------------------------------------------------------------------------
83  // Build coordinates.
84  const Grid grid( fieldDim, length );
85  grid.set_coord<XDIR>(x);
86  grid.set_coord<YDIR>(y);
87  grid.set_coord<ZDIR>(z);
88 
89  //----------------------------------------------------------------------------
90  // Perform operations on fields.
91 
92  f <<= x + y + z; // set values in a field
93 
94  const double fnorm = nebo_norm( f ); // L-2 norm of f
95  const double fmax = nebo_max ( f ); // maximum value in f
96  const double fmin = nebo_min ( f ); // minimum value in f
97 
98  //----------------------------------------------------------------------------
99  // Print out the domain extents for this field type as well as the max and min
100  // of the "f" field that we created above.
101  cout << setprecision(4) << left
102  << " X-min: " << setprecision(4) << left << setw(10) << nebo_min(x)
103  << " X-max: " << setprecision(4) << left << setw(10) << nebo_max(x) << endl
104  << " Y-min: " << setprecision(4) << left << setw(10) << nebo_min(y)
105  << " Y-max: " << setprecision(4) << left << setw(10) << nebo_max(y) << endl
106  << " Z-min: " << setprecision(4) << left << setw(10) << nebo_min(z)
107  << " Z-max: " << setprecision(4) << left << setw(10) << nebo_max(z) << endl
108  << " f-Min: " << setprecision(4) << left << setw(10) << fmin
109  << " f-Max: " << setprecision(4) << left << setw(10) << fmax << endl
110  << " f-Norm: " << setprecision(4) << left << setw(10) << fnorm
111  << endl << endl;
112 
113  return 0;
114 }
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
STL namespace.
Provides a simple interface to set coordinate fields.
Definition: Grid.h:36
Holds information about the number of ghost cells on each side of the domain.
Definition: GhostData.h:54
Defines a type for the x-direction.
Defines a type for the y-direction.
Defines a type for the z-direction.
Abstracts a field.
Definition: SpatialField.h:132
Provides information about boundary cells for various fields.