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 GhostData nghost(0);
72  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bcx, bcy, bcz );
73  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
74 
75  FieldT x( window, bcInfo, nghost, NULL, InternalStorage );
76  FieldT y( window, bcInfo, nghost, NULL, InternalStorage );
77  FieldT z( window, bcInfo, nghost, NULL, InternalStorage );
78 
79  FieldT f( window, bcInfo, nghost, NULL, InternalStorage );
80 
81  //----------------------------------------------------------------------------
82  // Build coordinates.
83  const Grid grid( fieldDim, length );
84  grid.set_coord<XDIR>(x);
85  grid.set_coord<YDIR>(y);
86  grid.set_coord<ZDIR>(z);
87 
88  //----------------------------------------------------------------------------
89  // Perform operations on fields.
90 
91  f <<= x + y + z; // set values in a field
92 
93  const double fnorm = nebo_norm( f ); // L-2 norm of f
94  const double fmax = nebo_max ( f ); // maximum value in f
95  const double fmin = nebo_min ( f ); // minimum value in f
96 
97  //----------------------------------------------------------------------------
98  // Print out the domain extents for this field type as well as the max and min
99  // of the "f" field that we created above.
100  cout << setprecision(4) << left
101  << " X-min: " << setprecision(4) << left << setw(10) << nebo_min(x)
102  << " X-max: " << setprecision(4) << left << setw(10) << nebo_max(x) << endl
103  << " Y-min: " << setprecision(4) << left << setw(10) << nebo_min(y)
104  << " Y-max: " << setprecision(4) << left << setw(10) << nebo_max(y) << endl
105  << " Z-min: " << setprecision(4) << left << setw(10) << nebo_min(z)
106  << " Z-max: " << setprecision(4) << left << setw(10) << nebo_max(z) << endl
107  << " f-Min: " << setprecision(4) << left << setw(10) << fmin
108  << " f-Max: " << setprecision(4) << left << setw(10) << fmax << endl
109  << " f-Norm: " << setprecision(4) << left << setw(10) << fnorm
110  << endl << endl;
111 
112  return 0;
113 }
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.