Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions include/mesh/exodusII_io_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ class ExodusII_IO_Helper : public ParallelObject
int time_step,
std::map<dof_id_type, Real> & elem_var_value_map);

/**
* Reads element "extra integer" values, using the variable names
* specified in \p extra_integer_var_names, and converting the
* stored values to integer format. The returned value is a vector
* (indexed in the same way as extra_integer_vars) of maps from
* element id to extra integer value.
*
* Currently values from the last time step are used.
*/
std::vector<std::map<dof_id_type, dof_id_type>> read_extra_integers(
const std::vector<std::string> & extra_integer_var_names);

/**
* Helper function that takes a (1-based) Exodus node/elem id and
* determines the corresponding libMesh Node/Elem id. Takes into account
Expand Down Expand Up @@ -942,36 +954,22 @@ class ExodusII_IO_Helper : public ParallelObject
* each processor. This plus a node id gives a valid nodal solution
* vector index.
*/
dof_id_type node_id_to_vec_id(dof_id_type n) const
{
if (_added_side_node_offsets.empty())
return n;

// Find the processor id that has node_id in the parallel vec
const auto lb = std::upper_bound(_true_node_offsets.begin(),
_true_node_offsets.end(), n);
libmesh_assert(lb != _true_node_offsets.end());
const processor_id_type p = lb - _true_node_offsets.begin();

return n + (p ? _added_side_node_offsets[p-1] : 0);
}
dof_id_type node_id_to_vec_id(dof_id_type n) const;

/*
* Returns the sum of both added node "offsets" on processors 0
* through p-1 and real nodes added on processors 0 to p.
* This is the starting index for added nodes' data.
*/
dof_id_type added_node_offset_on(processor_id_type p) const
{
libmesh_assert (p < _true_node_offsets.size());
const dof_id_type added_node_offsets =
(_added_side_node_offsets.empty() || !p) ? 0 :
_added_side_node_offsets[p-1];
return _true_node_offsets[p] + added_node_offsets;
}

dof_id_type added_node_offset_on(processor_id_type p) const;

protected:
/**
* Calculate _added_side_node_offsets needed to add "fake" side
* elements to the given mesh
*/
void calculate_added_side_node_offsets(const MeshBase & mesh);

/**
* When appending: during initialization, check that variable names
* in the file match those you attempt to initialize with.
Expand Down Expand Up @@ -1104,13 +1102,28 @@ class ExodusII_IO_Helper : public ParallelObject
int & count,
std::vector<std::string> & result);

private:

/**
* Set to true iff we want to write separate "side" elements too.
*/
bool _add_sides = false;

/**
* Map of subdomains to element numbers.
*/
std::map<subdomain_id_type, std::vector<dof_id_type>> _subdomain_map;

/**
* One beyond the last "real" subdomain id, in cases where we have
* "fake" subdomain ids for added sides
*/
subdomain_id_type _subdomain_id_end;

/**
* Method for constructing _subdomain_map
*/
void build_subdomain_map(const MeshBase & mesh, bool local);

private:
/**
* write_var_names() dispatches to this function.
*/
Expand Down
5 changes: 0 additions & 5 deletions include/mesh/nemesis_io_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ class Nemesis_IO_Helper : public ExodusII_IO_Helper
*/
std::set<int> nodes_attached_to_local_elems;

/**
* Map of subdomains to element numbers.
*/
std::map<subdomain_id_type, std::vector<dof_id_type>> subdomain_map;

/**
* This is the block connectivity, i.e. for each subdomain (block) there
* is an element connectivity list. This map associates the block ID to that vector.
Expand Down
49 changes: 5 additions & 44 deletions src/mesh/exodusII_io.C
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,11 @@ void ExodusII_IO::read (const std::string & fname)
// have already been attached to spline control nodes.
mesh.reserve_elem(exio_helper->w.size() + exio_helper->num_elem);

// Read variables for extra integer IDs
std::vector<std::map<dof_id_type, Real>> elem_ids(extra_ids.size());
// We use the last time step to load the IDs
exio_helper->read_num_time_steps();
unsigned int last_step = exio_helper->num_time_steps;
for (auto i : index_range(extra_ids))
exio_helper->read_elemental_var_values(_extra_integer_vars[i], last_step, elem_ids[i]);

// Read variables for extra integer IDs
auto extra_integer_values =
exio_helper->read_extra_integers(_extra_integer_vars);

// Read in the element connectivity for each block.
int nelem_last_block = 0;
Expand Down Expand Up @@ -504,44 +502,7 @@ void ExodusII_IO::read (const std::string & fname)

// Assign extra integer IDs
for (auto & id : extra_ids)
{
const Real v = elem_ids[id][elem->id()];

if (v == Real(-1))
{
elem->set_extra_integer(id, DofObject::invalid_id);
continue;
}

// Ignore FE_INVALID here even if we've enabled FPEs; a
// thrown exception is preferred over an FPE signal.
FPEDisabler disable_fpes;
const long long iv = std::llround(v);

// Check if the real number is outside of the range we can
// convert exactly

long long max_representation = 1;
max_representation = (max_representation << std::min(std::numeric_limits<Real>::digits,
std::numeric_limits<double>::digits));
libmesh_error_msg_if(iv > max_representation,
"Error! An element integer value higher than "
<< max_representation
<< " was found! Exodus uses real numbers for storing element "
" integers, which can only represent integers from 0 to "
<< max_representation
<< ".");

libmesh_error_msg_if(iv < 0,
"Error! An element integer value less than -1"
<< " was found! Exodus uses real numbers for storing element "
" integers, which can only represent integers from 0 to "
<< max_representation
<< ".");


elem->set_extra_integer(id, cast_int<dof_id_type>(iv));
}
elem->set_extra_integer(id, extra_integer_values[id][elem->id()]);

// Set all the nodes for this element
//
Expand Down
Loading