13#include "libmesh/dof_map.h"
14#include "libmesh/explicit_system.h"
15#include "libmesh/fe_compute_data.h"
16#include "libmesh/libmesh_common.h"
17#include "libmesh/numeric_vector.h"
21 const std::string & exodus_mesh,
22 const std::string var_name)
23 : _communicator(MPI_COMM_SELF), _mesh(_communicator), _var_name(var_name)
31 _eq = std::make_unique<libMesh::EquationSystems>(
_mesh);
32 _sys = &
_eq->add_system<ExplicitSystem>(
"_reading_exodus_mesh_var");
35 const std::vector<std::string> & all_nodal(
_exodusII_io->get_nodal_var_names());
36 const std::vector<std::string> & all_elemental(
_exodusII_io->get_elem_var_names());
38 std::string nodal_variable;
39 std::string elemental_variable;
41 if (std::find(all_nodal.begin(), all_nodal.end(),
_var_name) != all_nodal.end())
43 if (std::find(all_elemental.begin(), all_elemental.end(),
_var_name) != all_elemental.end())
49 if (!nodal_variable.empty())
51 if (!elemental_variable.empty())
56 if (nodal_variable.empty() && elemental_variable.empty())
58 std::string out(
"\n Parameter Requested: " + var_name);
59 out +=
"\n Exodus Nodal Variables: ";
60 for (
const auto & var : all_nodal)
62 out +=
"\n Exodus Elemental Variables: ";
63 for (
const auto & var : all_elemental)
65 mooseError(
"Exodus file did not contain the parameter name being intitialized.", out);
73 unsigned int step_to_read =
_exodusII_io->get_num_time_steps();
74 if (time_step <= step_to_read)
75 step_to_read = time_step;
76 else if (time_step != std::numeric_limits<unsigned int>::max())
77 mooseError(
"Invalid value passed as \"time_step\". Expected a valid integer "
85 const std::vector<std::string> & all_nodal(
_exodusII_io->get_nodal_var_names());
86 const std::vector<std::string> & all_elemental(
_exodusII_io->get_elem_var_names());
88 if (std::find(all_nodal.begin(), all_nodal.end(),
_var_name) != all_nodal.end())
90 else if (std::find(all_elemental.begin(), all_elemental.end(),
_var_name) != all_elemental.end())
98 std::set<dof_id_type> var_indices;
100 std::vector<dof_id_type> var_indices_vector(var_indices.begin(), var_indices.end());
102 std::vector<Real> parameter_values;
103 _sys->
solution->localize(parameter_values, var_indices_vector);
104 return parameter_values;
void mooseError(Args &&... args)
std::unique_ptr< libMesh::EquationSystems > _eq
ReadExodusMeshVars(const libMesh::FEType ¶m_type, const std::string &exodus_mesh, const std::string var_name)
libMesh::ReplicatedMesh _mesh
std::unique_ptr< libMesh::ExodusII_IO > _exodusII_io
std::vector< Real > getParameterValues(const unsigned int timestep) const
Initializes parameter data and sets bounds in the main optmiization application getParameterValues is...
const std::string _var_name
variable name read from Exodus mesh
void allow_renumbering(bool allow)
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
std::unique_ptr< NumericVector< Number > > solution
unsigned int variable_number(std::string_view var) const
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false) override