libMesh
Loading...
Searching...
No Matches
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 1073 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 606 of file exodusII_io_helper.C.

609 : our_data(our_data_in),
610 single_precision(single_precision_in)
611{
613 {
614 if (sizeof(Real) != sizeof(float))
615 {
616 float_vec.resize(our_data.size());
617 // boost float128 demands explicit downconversions
618 for (std::size_t i : index_range(our_data))
619 float_vec[i] = float(our_data[i]);
620 }
621 }
622
623 else if (sizeof(Real) != sizeof(double))
624 {
625 double_vec.resize(our_data.size());
626 // boost float128 demands explicit downconversions
627 for (std::size_t i : index_range(our_data))
628 double_vec[i] = double(our_data[i]);
629 }
630}
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:153
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

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

◆ ~MappedOutputVector()

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

Member Function Documentation

◆ data()

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

Definition at line 633 of file exodusII_io_helper.C.

634{
636 {
637 if (sizeof(Real) != sizeof(float))
638 return static_cast<void*>(float_vec.data());
639 }
640
641 else if (sizeof(Real) != sizeof(double))
642 return static_cast<void*>(double_vec.data());
643
644 // Otherwise return a (suitably casted) pointer to the original underlying data.
645 return const_cast<void *>(static_cast<const void *>(our_data.data()));
646}

References libMesh::Real.

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

Member Data Documentation

◆ double_vec

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

Definition at line 1089 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 1090 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 1087 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().

◆ single_precision

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

Definition at line 1088 of file exodusII_io_helper.h.

Referenced by MappedOutputVector().


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