IOSS 2.0
Loading...
Searching...
No Matches
Ioss::Utils Class Reference

#include <Ioss_Utils.h>

Static Public Member Functions

static void set_all_streams (std::ostream &out_stream)
 set the stream for all streams (output, debug, and warning) to the specified out_stream
 
static IOSS_NODISCARD std::ostream & get_debug_stream ()
 get the debug stream.
 
static IOSS_NODISCARD std::ostream & get_warning_stream ()
 get the warning stream.
 
static IOSS_NODISCARD std::ostream & get_output_stream ()
 get the output stream.
 
static void set_output_stream (std::ostream &output_stream)
 set the output stream to the specified output_stream
 
static void set_debug_stream (std::ostream &debug_stream)
 set the debug stream to the specified debug_stream
 
static void set_warning_stream (std::ostream &warning_stream)
 set the warning stream to the specified warning_stream
 
static void set_pre_warning_text (const std::string &text)
 set the pre-warning text Sets the text output prior to a warning to the specified text. Pass an empty string to disable this. Default is "\nIOSS WARNING: "
 
static void copyright (std::ostream &out, const std::string &year_range)
 
static void check_dynamic_cast (const void *ptr)
 
static bool is_path_absolute (const std::string &path)
 
static IOSS_NODISCARD std::string get_type_from_file (const std::string &filename)
 guess file type from extension
 
template<typename T >
static void uniquify (std::vector< T > &vec, bool skip_first=false)
 
template<typename T >
static void generate_index (std::vector< T > &index)
 
template<typename T >
static IOSS_NODISCARDfind_index_location (T node, const std::vector< T > &index)
 
static void copy_string (char *dest, char const *source, size_t elements)
 
static void copy_string (char *dest, const std::string &source, size_t elements)
 
template<size_t size>
static void copy_string (char(&output)[size], const std::string &source)
 
template<size_t size>
static void copy_string (char(&output)[size], const char *source)
 
template<typename T >
static void clear (std::vector< T > &vec)
 
static IOSS_NODISCARD int number_width (const size_t number, bool use_commas=false)
 
static IOSS_NODISCARD int power_2 (int count)
 
template<typename T >
static IOSS_NODISCARD bool check_block_order (IOSS_MAYBE_UNUSED const std::vector< T * > &blocks)
 
static IOSS_NODISCARD int term_width ()
 
static IOSS_NODISCARD int log_power_2 (uint64_t value)
 
static IOSS_NODISCARD char ** get_name_array (size_t count, int size)
 
static void delete_name_array (char **names, int count)
 
static void time_and_date (char *time_string, char *date_string, size_t length)
 Get formatted time and date strings.
 
static IOSS_NODISCARD std::string decode_filename (const std::string &filename, int processor, int num_processors)
 
static IOSS_NODISCARD int get_number (const std::string &suffix)
 
static IOSS_NODISCARD int extract_id (const std::string &name_id)
 
static IOSS_NODISCARD std::string encode_entity_name (const std::string &entity_type, int64_t id)
 
static IOSS_NODISCARD std::string get_trailing_digits (const std::string &name)
 
static IOSS_NODISCARD std::string format_id_list (const std::vector< size_t > &ids, const std::string &rng_sep=" to ", const std::string &seq_sep=", ")
 create a string that describes the list of input ids collapsing ranges if possible.
 
static void fixup_name (char *name)
 Convert a string to lower case, and convert spaces to _.
 
static void fixup_name (std::string &name)
 Convert a string to lower case, and convert spaces to _.
 
static bool check_set_bool_property (const Ioss::PropertyManager &properties, const std::string &prop_name, bool &prop_value)
 Check whether property prop_name exists and if so, set prop_value
 
static IOSS_NODISCARD bool block_is_omitted (Ioss::GroupingEntity *block)
 Determine whether an entity has the property omitted.
 
static IOSS_NODISCARD std::string fixup_type (const std::string &base, int nodes_per_element, int spatial)
 Process the base element type base which has nodes_per_element nodes and a spatial dimension of spatial into a form that the IO system can (hopefully) recognize.
 
static IOSS_NODISCARD std::string capitalize (std::string name)
 Uppercase the first letter of the string.
 
static IOSS_NODISCARD std::string uppercase (std::string name)
 Convert a string to upper case.
 
static IOSS_NODISCARD std::string lowercase (std::string name)
 Convert a string to lower case.
 
static void check_non_null (void *ptr, const char *type, const std::string &name, const std::string &func)
 
static IOSS_NODISCARD bool str_equal (const std::string &s1, const std::string &s2)
 Case-insensitive string comparison.
 
static IOSS_NODISCARD bool substr_equal (const std::string &prefix, const std::string &str)
 Case-insensitive substring comparison.
 
static bool check_int_to_real_overflow (const Ioss::Field &field, int64_t *data, size_t num_entity)
 
static IOSS_NODISCARD std::string platform_information ()
 Get a string containing uname output.
 
static IOSS_NODISCARD std::string local_filename (const std::string &relative_filename, const std::string &type, const std::string &working_directory)
 Get a filename relative to the specified working directory (if any) of the current execution.
 
static void get_fields (int64_t entity_count, char **names, int num_names, Ioss::Field::RoleType fld_role, const DatabaseIO *db, int *local_truth, std::vector< Ioss::Field > &fields)
 
static int field_warning (const Ioss::GroupingEntity *ge, const Ioss::Field &field, const std::string &inout)
 
static void calculate_sideblock_membership (IntVector &face_is_member, const SideBlock *sb, size_t int_byte_size, const void *element, const void *sides, int64_t number_sides, const Region *region)
 
static IOSS_NODISCARD int64_t get_side_offset (const Ioss::SideBlock *sb)
 Get the appropriate index offset for the sides of elements in a SideBlock.
 
static IOSS_NODISCARD unsigned int hash (const std::string &name)
 
static IOSS_NODISCARD double timer ()
 
static void input_file (const std::string &file_name, std::vector< std::string > *lines, size_t max_line_length=0)
 Convert an input file to a vector of strings containing one string for each line of the file.
 
template<class T >
static IOSS_NODISCARD std::string to_string (const T &t)
 
static IOSS_NODISCARD std::string variable_name_kluge (const std::string &name, size_t component_count, size_t copies, size_t max_var_len)
 Tries to shorten long variable names to an acceptable length, and converts to lowercase and spaces to _
 
static IOSS_NODISCARD std::string shape_to_string (const Ioss::ElementShape &shape)
 
static IOSS_NODISCARD std::string entity_type_to_string (const Ioss::EntityType &type)
 
static void generate_history_mesh (Ioss::Region *region)
 Create a nominal mesh for use in history databases.
 
static void info_fields (const Ioss::GroupingEntity *ige, Ioss::Field::RoleType role, const std::string &header, const std::string &suffix="\n\t")
 
static void info_property (const Ioss::GroupingEntity *ige, Ioss::Property::Origin origin, const std::string &header, const std::string &suffix="\n\t", bool print_empty=false)
 
static void insert_sort_and_unique (const std::vector< std::string > &src, std::vector< std::string > &dest)
 

Static Public Attributes

static std::ostream * m_outputStream = &std::cerr
 general informational output (very rare). Default std::cerr
 
static std::ostream * m_debugStream = &std::cerr
 debug output when requested. Default std::cerr
 
static std::ostream * m_warningStream = &std::cerr
 IOSS warning output. Default std::cerr.
 
static std::string m_preWarningText = "\nIOSS WARNING: "
 

Static Private Member Functions

template<typename T >
static size_t unique (std::vector< T > &out, bool skip_first)
 

Member Function Documentation

◆ block_is_omitted()

bool Ioss::Utils::block_is_omitted ( Ioss::GroupingEntity * block)
static

Determine whether an entity has the property omitted.

Parameters
[in]blockThe entity.
Returns
True if the entity has the property omitted.

◆ calculate_sideblock_membership()

void Ioss::Utils::calculate_sideblock_membership ( IntVector & face_is_member,
const SideBlock * sb,
size_t int_byte_size,
const void * element,
const void * sides,
int64_t number_sides,
const Region * region )
static

◆ capitalize()

std::string Ioss::Utils::capitalize ( std::string name)
static

Uppercase the first letter of the string.

Parameters
[in]nameThe string to convert.
Returns
The converted string.

◆ check_block_order()

template<typename T >
static IOSS_NODISCARD bool Ioss::Utils::check_block_order ( IOSS_MAYBE_UNUSED const std::vector< T * > & blocks)
inlinestatic

◆ check_dynamic_cast()

static void Ioss::Utils::check_dynamic_cast ( const void * ptr)
inlinestatic

◆ check_int_to_real_overflow()

bool Ioss::Utils::check_int_to_real_overflow ( const Ioss::Field & field,
int64_t * data,
size_t num_entity )
static

Check all values in data to make sure that if they are converted to a double and back again, there will be no data loss. This requires that the value be less than 2^53. This is done in the exodus database since it stores all transient data as doubles...

◆ check_non_null()

void Ioss::Utils::check_non_null ( void * ptr,
const char * type,
const std::string & name,
const std::string & func )
static

◆ check_set_bool_property()

bool Ioss::Utils::check_set_bool_property ( const Ioss::PropertyManager & properties,
const std::string & prop_name,
bool & prop_value )
static

Check whether property prop_name exists and if so, set prop_value

based on the property value. Either "TRUE", "YES", "ON", or nonzero for true; or "FALSE", "NO", "OFF", or 0 for false.

Parameters
[in]propertiesthe Ioss::PropertyManager containing the properties to be checked.
[in]prop_namethe name of the property to check whether it exists and if so, set its value.
[out]prop_valueif prop_name exists and has a valid value, set prop_value accordingly. Does not modify if prop_name does not exist.
Returns
true/false depending on whether property found and value set.

◆ clear()

template<typename T >
static void Ioss::Utils::clear ( std::vector< T > & vec)
inlinestatic

◆ copy_string() [1/4]

void Ioss::Utils::copy_string ( char * dest,
char const * source,
size_t elements )
static

◆ copy_string() [2/4]

static void Ioss::Utils::copy_string ( char * dest,
const std::string & source,
size_t elements )
inlinestatic

◆ copy_string() [3/4]

template<size_t size>
static void Ioss::Utils::copy_string ( char(&) output[size],
const char * source )
inlinestatic

◆ copy_string() [4/4]

template<size_t size>
static void Ioss::Utils::copy_string ( char(&) output[size],
const std::string & source )
inlinestatic

◆ copyright()

void Ioss::Utils::copyright ( std::ostream & out,
const std::string & year_range )
static

◆ decode_filename()

std::string Ioss::Utils::decode_filename ( const std::string & filename,
int processor,
int num_processors )
static

◆ delete_name_array()

void Ioss::Utils::delete_name_array ( char ** names,
int count )
static

◆ encode_entity_name()

std::string Ioss::Utils::encode_entity_name ( const std::string & entity_type,
int64_t id )
static

◆ entity_type_to_string()

std::string Ioss::Utils::entity_type_to_string ( const Ioss::EntityType & type)
static

◆ extract_id()

int Ioss::Utils::extract_id ( const std::string & name_id)
static

◆ field_warning()

int Ioss::Utils::field_warning ( const Ioss::GroupingEntity * ge,
const Ioss::Field & field,
const std::string & inout )
static

◆ find_index_location()

template<typename T >
static IOSS_NODISCARD T Ioss::Utils::find_index_location ( T node,
const std::vector< T > & index )
inlinestatic

◆ fixup_name() [1/2]

void Ioss::Utils::fixup_name ( char * name)
static

Convert a string to lower case, and convert spaces to _.

The conversion is performed in place.

Parameters
[in,out]nameOn input, the string to convert. On output, the converted string.

◆ fixup_name() [2/2]

void Ioss::Utils::fixup_name ( std::string & name)
static

Convert a string to lower case, and convert spaces to _.

The conversion is performed in place.

Parameters
[in,out]nameOn input, the string to convert. On output, the converted string.

◆ fixup_type()

std::string Ioss::Utils::fixup_type ( const std::string & base,
int nodes_per_element,
int spatial )
static

Process the base element type base which has nodes_per_element nodes and a spatial dimension of spatial into a form that the IO system can (hopefully) recognize.

Lowercases the name; converts spaces to _, adds nodes_per_element at end of name (if not already there), and does some other transformations to remove some exodusII ambiguity.

Parameters
[in]baseThe element base name.
[in]nodes_per_elementThe number of nodes per element.
[in]spatialThe spatial dimension of the element.
Returns
The Ioss-formatted element name.

◆ format_id_list()

std::string Ioss::Utils::format_id_list ( const std::vector< size_t > & ids,
const std::string & rng_sep = " to ",
const std::string & seq_sep = ", " )
static

create a string that describes the list of input ids collapsing ranges if possible.

Traverse the sorted input vector ids and return a string that has all sequential ranges collapsed and separated by rng_sep and all individual ids or ranges separated by seq_sep. Will throw an exception if ids is not sorted. An empty list returns an empty string. The sequence of ids 1, 2, 3, 5, 6, 7 with rng_sep=".." will return the default string 1..3, 5..8

◆ generate_history_mesh()

void Ioss::Utils::generate_history_mesh ( Ioss::Region * region)
static

Create a nominal mesh for use in history databases.

The model for a history file is a single sphere element (1 node, 1 element). This is needed for some applications that read this file that require a "mesh" even though a history file is just a collection of global variables with no real mesh. This routine will add the mesh portion to a history file.

Parameters
[in,out]regionThe region on which the nominal mesh is to be defined.

◆ generate_index()

template<typename T >
static void Ioss::Utils::generate_index ( std::vector< T > & index)
inlinestatic

◆ get_fields()

void Ioss::Utils::get_fields ( int64_t entity_count,
char ** names,
int num_names,
Ioss::Field::RoleType fld_role,
const DatabaseIO * db,
int * local_truth,
std::vector< Ioss::Field > & fields )
static

◆ get_name_array()

char ** Ioss::Utils::get_name_array ( size_t count,
int size )
static

◆ get_number()

int Ioss::Utils::get_number ( const std::string & suffix)
static

◆ get_side_offset()

int64_t Ioss::Utils::get_side_offset ( const Ioss::SideBlock * sb)
static

Get the appropriate index offset for the sides of elements in a SideBlock.

And yet another idiosyncrasy of sidesets... The side of an element (especially shells) can be either a face or an edge in the same sideset. The ordinal of an edge is (local_edge_number+numfaces) on the database, but needs to be (local_edge_number) for Sierra...

If the sideblock has a "parent_element_topology" and a "topology", then we can determine whether to offset the side ordinals...

Parameters
[in]sbCompute the offset for element sides in this SideBlock
Returns
The offset.

◆ get_trailing_digits()

std::string Ioss::Utils::get_trailing_digits ( const std::string & name)
static

Return the trailing digits (if any) from name hex20 would return the string 20 tetra would return an empty string.

◆ get_type_from_file()

std::string Ioss::Utils::get_type_from_file ( const std::string & filename)
static

guess file type from extension

◆ hash()

unsigned int Ioss::Utils::hash ( const std::string & name)
static

◆ info_fields()

void Ioss::Utils::info_fields ( const Ioss::GroupingEntity * ige,
Ioss::Field::RoleType role,
const std::string & header,
const std::string & suffix = "\n\t" )
static

◆ info_property()

void Ioss::Utils::info_property ( const Ioss::GroupingEntity * ige,
Ioss::Property::Origin origin,
const std::string & header,
const std::string & suffix = "\n\t",
bool print_empty = false )
static

◆ input_file()

void Ioss::Utils::input_file ( const std::string & file_name,
std::vector< std::string > * lines,
size_t max_line_length = 0 )
static

Convert an input file to a vector of strings containing one string for each line of the file.

Should only be called by a single processor or each processor will be accessing the file at the same time...

Parameters
[in]file_nameThe name of the file.
[out]linesThe vector of strings containing the lines of the file
[in]max_line_lengthThe maximum number of characters in any line of the file.

◆ insert_sort_and_unique()

static void Ioss::Utils::insert_sort_and_unique ( const std::vector< std::string > & src,
std::vector< std::string > & dest )
inlinestatic

◆ is_path_absolute()

static bool Ioss::Utils::is_path_absolute ( const std::string & path)
inlinestatic

◆ local_filename()

std::string Ioss::Utils::local_filename ( const std::string & relative_filename,
const std::string & type,
const std::string & working_directory )
static

Get a filename relative to the specified working directory (if any) of the current execution.

Working_directory must end with / or be empty.

Parameters
[in]relative_filenameThe file path to be appended to the working directory path.
[in]typeThe file type. "generated" file types are treated differently.
[in]working_directorythe path to which the relative_filename path is appended.
Returns
The full path (working_directory + relative_filename)

◆ log_power_2()

int Ioss::Utils::log_power_2 ( uint64_t value)
static

◆ lowercase()

std::string Ioss::Utils::lowercase ( std::string name)
static

Convert a string to lower case.

Parameters
[in]nameThe string to convert.
Returns
The converted string.

◆ number_width()

static IOSS_NODISCARD int Ioss::Utils::number_width ( const size_t number,
bool use_commas = false )
inlinestatic

Returns the number of digits required to print the number. If use_commas is specified, then the width will be adjusted to account for the comma used every 3 digits. (1,234,567,890 would return 13) Typically used with the fmt::print() functions as:

fmt::print("{:{}}", number, number_width(number,true))
fmt::print("{:{}d}", number, number_width(number,false))
static IOSS_NODISCARD int number_width(const size_t number, bool use_commas=false)
Definition Ioss_Utils.h:261

◆ platform_information()

std::string Ioss::Utils::platform_information ( )
static

Get a string containing uname output.

This output contains information about the current computing platform. This is used as information data in the created results file to help in tracking when/where/... the file was created.

Returns
The platform information string.

◆ power_2()

static IOSS_NODISCARD int Ioss::Utils::power_2 ( int count)
inlinestatic

◆ shape_to_string()

std::string Ioss::Utils::shape_to_string ( const Ioss::ElementShape & shape)
static

◆ str_equal()

bool Ioss::Utils::str_equal ( const std::string & s1,
const std::string & s2 )
static

Case-insensitive string comparison.

Parameters
[in]s1First string
[in]s2Second string
Returns
true if strings are equal

◆ substr_equal()

bool Ioss::Utils::substr_equal ( const std::string & prefix,
const std::string & str )
static

Case-insensitive substring comparison.

Parameters
[in]prefixThe prefix that should start the string
[in]strThe string which should begin with prefix
Returns
true if str begins with prefix or prefix is empty

◆ term_width()

int Ioss::Utils::term_width ( )
static

◆ time_and_date()

void Ioss::Utils::time_and_date ( char * time_string,
char * date_string,
size_t length )
static

Get formatted time and date strings.

Fill time_string and date_string with current time and date formatted as "HH:MM:SS" for time and "yy/mm/dd" or "yyyy/mm/dd" for date.

Parameters
[out]time_stringThe formatted time string.
[out]date_stringThe formatted date string.
[in]lengthUse 8 for short-year date format, or 10 for long-year date format.

◆ timer()

double Ioss::Utils::timer ( )
static

◆ to_string()

template<class T >
static IOSS_NODISCARD std::string Ioss::Utils::to_string ( const T & t)
inlinestatic

◆ unique()

template<typename T >
static size_t Ioss::Utils::unique ( std::vector< T > & out,
bool skip_first )
inlinestaticprivate

◆ uniquify()

template<typename T >
static void Ioss::Utils::uniquify ( std::vector< T > & vec,
bool skip_first = false )
inlinestatic

◆ uppercase()

std::string Ioss::Utils::uppercase ( std::string name)
static

Convert a string to upper case.

Parameters
[in]nameThe string to convert.
Returns
The converted string.

◆ variable_name_kluge()

std::string Ioss::Utils::variable_name_kluge ( const std::string & name,
size_t component_count,
size_t copies,
size_t max_var_len )
static

Tries to shorten long variable names to an acceptable length, and converts to lowercase and spaces to _

Many databases have a maximum length for variable names which can cause a problem with variable name length. This routine tries to shorten long variable names to an acceptable length (max_var_len characters max). If the name is already less than this length, it is returned unchanged...

Since there is a (good) chance that two shortened names will match, a 2-letter hash code is appended to the end of the variable name.

So, we shorten the name to a maximum of max_var_len-3 characters and append a 2 character hash+separator.

It also converts name to lowercase and converts spaces to _


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