SpatialOps
FieldHelper.h File Reference
#include <spatialops/structured/MemoryWindow.h>
#include <ostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
Include dependency graph for FieldHelper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename Field >
void SpatialOps::internal_initialize_field (typename Field::iterator fi, const MemoryWindow &mw, const double start, const bool print, const double range)
 INTERNAL initialize a field with pseudorandom numbers. More...
 
template<typename Field >
void SpatialOps::initialize_field (Field &f, const double start=0.0, const bool print=false, const double range=1.0)
 initialize a field (and ghost cells) with pseudorandom numbers More...
 
template<typename Field >
void SpatialOps::interior_initialize_field (Field &f, const double start=0.0, const bool print=false, const double range=1.0)
 initialize a field (without ghost cells) with pseudorandom numbers More...
 
template<typename Field >
void SpatialOps::internal_print_field (typename Field::const_iterator fi, const MemoryWindow &mw, std::ostream &os, bool addFormat)
 INTERNAL print the values of a field to standard output. More...
 
template<typename Field >
void SpatialOps::print_field (const Field &f, std::ostream &os, const bool addFormat=false)
 print the values of a field (and ghost cells) to standard output More...
 
template<typename Field >
void SpatialOps::interior_print_field (const Field &f, std::ostream &os, const bool addFormat=false)
 print the values of a field (without ghost cells) to standard output More...
 
template<typename Field >
bool SpatialOps::internal_display_fields_compare (typename Field::const_iterator fi1, typename Field::const_iterator fi2, const MemoryWindow &mw, const bool display, const bool print)
 INTERNAL compare two fields and possibly print values. More...
 
template<typename Field >
bool SpatialOps::display_fields_compare (const Field &field1, const Field &field2, const bool display=false, const bool print=false)
 compare two fields and possibly print values (with ghost cells) More...
 
template<typename Field >
bool SpatialOps::interior_display_fields_compare (const Field &field1, const Field &field2, const bool display=false, const bool print=false)
 compare two fields and possibly print values (without ghost cells) More...
 

Function Documentation

◆ internal_display_fields_compare()

template<typename Field >
bool SpatialOps::internal_display_fields_compare ( typename Field::const_iterator  fi1,
typename Field::const_iterator  fi2,
const MemoryWindow mw,
const bool  display,
const bool  print 
)
inline

INTERNAL compare two fields and possibly print values.

NOTE: As this function is internally used by other functions, it generally should not be called in user code.

Parameters
fi1first field iterator to use to read values
fi2second field iterator to use to read values
mwmemory window of fi1 and fi2 (field iterator)
displayboolean value, if true prints comparison of each index
printboolean value, if true prints values of each index of each iterator
Returns
boolean value, if true fields are equal within given window

This function prints values starting with the lowest index first (0,0,0). The first line contains the X-axis row of values (with Y and Z indicies fixed at 0). The second line contains the X-axis row of values (with Y index of 1, and Z index of 0). A blank line represents the end of one XY plane and the start of the next.

Graphically, with X-axis extent of I, Y-axis extent of J, and Z-axis extent of K:

 (0,0,0) (1,0,0) ... (I,0,0)
 (0,1,0) (1,1,0) ... (I,1,0)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,0) (1,J,0) ... (I,J,0)

 (0,0,1) (1,0,1) ... (I,0,1)
 (0,1,1) (1,1,1) ... (I,1,1)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,1) (1,J,1) ... (I,J,1)

 (0,0,K) (1,0,K) ... (I,0,K)
 (0,1,K) (1,1,K) ... (I,1,K)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,K) (1,J,K) ... (I,J,K)

If display is true, prints 0 or 1 for each index. 0 is printed if values in fields are different at that index. 1 is printed if values in fields are the same.

If print is true, prints two tabs, then values for the first field in one X-axis row, two more tabs, and then values for the second field in one X-axis row. Thus, the values of the two fields can be compared visually side-by-side. Note that the values printed with the print flag are rounded and do NOT show machine-precision values.

If both display and print are true, the output of both appear, side-by-side, per X-axis row.

If both display and print are false, nothing is printed to standard output.

Printing values may be difficult to read if the fields' extents are too large, or the screen used to view them is too small.

Currently this function only works on CPU-allocated memory and fields. (CPU is at least valid, if not active.)

Definition at line 403 of file FieldHelper.h.

References SpatialOps::internal_display_fields_compare().

Referenced by SpatialOps::internal_display_fields_compare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_initialize_field()

template<typename Field >
void SpatialOps::internal_initialize_field ( typename Field::iterator  fi,
const MemoryWindow mw,
const double  start,
const bool  print,
const double  range 
)
inline

INTERNAL initialize a field with pseudorandom numbers.

NOTE: As this function is internally used by other functions, it generally should not be called in user code.

Parameters
fifield iterator to use to assign values
mwmemory window of fi (field iterator)
startdouble that represents minimum value to assign
printboolean value, if true prints the values it assigns to standard output
rangemaximum value to assign (negation will be minimum value)

This function assigns non-integer values to the field described by iterator fi and memory window mw. The value assigned to a cell with index (x,y,z) is given by:

range * sin(start + x + y * xExtent + z * xExtent * yExtent)

Since sine of anything returns values between [-1, 1], the range of values assigned by this function are [-range, range].

This function can be used to initialize multiple fields with different pseudorandom numbers by setting start to different values. This function turns each index triplet into a flat index. For new values, set start to be past the last used flat index. So in general, for the first field, set start to 0. Assuming all fields are the same size, set start to xExtent * yExtent * zExtent for the second field. For the third field, set start to be twice that value, and so on.

Currently this function only works on CPU-allocated memory and fields. (CPU set to active.)

Definition at line 72 of file FieldHelper.h.

References SpatialOps::internal_initialize_field().

Referenced by SpatialOps::internal_initialize_field().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_print_field()

template<typename Field >
void SpatialOps::internal_print_field ( typename Field::const_iterator  fi,
const MemoryWindow mw,
std::ostream &  os,
bool  addFormat 
)
inline

INTERNAL print the values of a field to standard output.

NOTE: As this function is internally used by other functions, it generally should not be called in user code.

Parameters
fifield iterator to use to read values to print
mwmemory window of fi (field iterator)
osoutput stream to write to
addFormatboolean flag to either print with tight format or standard precision

This function prints values starting with the lowest index first (0,0,0). The first line contains the X-axis row of values (with Y and Z indicies fixed at 0). The second line contains the X-axis row of values (with Y index of 1, and Z index of 0). A blank line represents the end of one XY plane and the start of the next.

Graphically, with X-axis extent of I, Y-axis extent of J, and Z-axis extent of K:

 (0,0,0) (1,0,0) ... (I,0,0)
 (0,1,0) (1,1,0) ... (I,1,0)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,0) (1,J,0) ... (I,J,0)

 (0,0,1) (1,0,1) ... (I,0,1)
 (0,1,1) (1,1,1) ... (I,1,1)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,1) (1,J,1) ... (I,J,1)

 (0,0,K) (1,0,K) ... (I,0,K)
 (0,1,K) (1,1,K) ... (I,1,K)
    .       .    .      .
    .       .     .     .
    .       .      .    .
 (0,J,K) (1,J,K) ... (I,J,K)

Currently this function only works on CPU-allocated memory and fields. (CPU is at least valid, if not active.)

Definition at line 215 of file FieldHelper.h.

References SpatialOps::internal_print_field().

Referenced by SpatialOps::internal_print_field().

Here is the call graph for this function:
Here is the caller graph for this function: