libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::ExodusII_IO_Helper::MappedOutputVector Struct Reference

This class facilitates inline conversion of an input data vector to a different precision level, depending on the underlying type of Real and whether or not the single_precision flag is set. More...

#include <exodusII_io_helper.h>

Public Member Functions

 MappedOutputVector (const std::vector< Real > &vec_in, bool single_precision_in)
 
 ~MappedOutputVector ()=default
 
void * data ()
 

Private Attributes

const std::vector< Real > & our_data
 
bool single_precision
 
std::vector< double > double_vec
 
std::vector< float > float_vec
 

Detailed Description

This class facilitates inline conversion of an input data vector to a different precision level, depending on the underlying type of Real and whether or not the single_precision flag is set.

This should be used whenever floating point data is being written to the Exodus file. Note that if no precision conversion has to take place, there should be very little overhead involved in using this object.

Definition at line 1000 of file exodusII_io_helper.h.

Constructor & Destructor Documentation

◆ MappedOutputVector()

libMesh::ExodusII_IO_Helper::MappedOutputVector::MappedOutputVector ( const std::vector< Real > &  vec_in,
bool  single_precision_in 
)

Definition at line 577 of file exodusII_io_helper.C.

References double_vec, float_vec, libMesh::index_range(), our_data, libMesh::Real, and single_precision.

579  : our_data(our_data_in),
580  single_precision(single_precision_in)
581 {
582  if (single_precision)
583  {
584  if (sizeof(Real) != sizeof(float))
585  {
586  float_vec.resize(our_data.size());
587  // boost float128 demands explicit downconversions
588  for (std::size_t i : index_range(our_data))
589  float_vec[i] = float(our_data[i]);
590  }
591  }
592 
593  else if (sizeof(Real) != sizeof(double))
594  {
595  double_vec.resize(our_data.size());
596  // boost float128 demands explicit downconversions
597  for (std::size_t i : index_range(our_data))
598  double_vec[i] = double(our_data[i]);
599  }
600 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117

◆ ~MappedOutputVector()

libMesh::ExodusII_IO_Helper::MappedOutputVector::~MappedOutputVector ( )
default

Member Function Documentation

◆ data()

void * libMesh::ExodusII_IO_Helper::MappedOutputVector::data ( )

Definition at line 603 of file exodusII_io_helper.C.

References libMesh::Real.

Referenced by libMesh::Nemesis_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_element_values_element_major(), libMesh::Nemesis_IO_Helper::write_nodal_coordinates(), and libMesh::ExodusII_IO_Helper::write_nodal_coordinates().

604 {
605  if (single_precision)
606  {
607  if (sizeof(Real) != sizeof(float))
608  return static_cast<void*>(float_vec.data());
609  }
610 
611  else if (sizeof(Real) != sizeof(double))
612  return static_cast<void*>(double_vec.data());
613 
614  // Otherwise return a (suitably casted) pointer to the original underlying data.
615  return const_cast<void *>(static_cast<const void *>(our_data.data()));
616 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Member Data Documentation

◆ double_vec

std::vector<double> libMesh::ExodusII_IO_Helper::MappedOutputVector::double_vec
private

Definition at line 1016 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().

◆ float_vec

std::vector<float> libMesh::ExodusII_IO_Helper::MappedOutputVector::float_vec
private

Definition at line 1017 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().

◆ our_data

const std::vector<Real>& libMesh::ExodusII_IO_Helper::MappedOutputVector::our_data
private

Definition at line 1014 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().

◆ single_precision

bool libMesh::ExodusII_IO_Helper::MappedOutputVector::single_precision
private

Definition at line 1015 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().


The documentation for this struct was generated from the following files: