20 #include "libmesh/exodusII_io.h" 21 #include "libmesh/exodusII_io_helper.h" 22 #include "libmesh/checkpoint_io.h" 48 _console << mesh_ptr->getMesh().get_info( 2) << std::endl;
50 if (mesh_file.empty())
53 size_t pos = mesh_file.find_last_of(
'.');
56 mesh_file = mesh_file.substr(0, pos) +
"_in.e";
64 if (mesh_file.find(
".e") + 2 == mesh_file.size())
66 TIME_SECTION(
"act", 1,
"Writing Exodus");
68 auto & output_mesh = mesh_ptr->getMesh();
76 exio.
write(mesh_file);
79 unsigned int n_eeid = output_mesh.n_elem_integers();
86 bool output_extra_ids = (n_eeid > 0);
87 bool restrict_element_id_names =
false;
88 std::vector<std::string> element_id_names;
89 for (
const auto &
act : output_actions)
101 output_extra_ids = params.
get<
bool>(
"output_extra_element_ids");
102 if (output_extra_ids)
106 restrict_element_id_names = params.
isParamValid(
"extra_element_ids_to_output");
107 if (restrict_element_id_names)
109 element_id_names = params.
get<std::vector<std::string>>(
"extra_element_ids_to_output");
112 for (
auto it = element_id_names.begin(); it != element_id_names.end();)
115 if (!output_mesh.has_elem_integer(*it))
117 it = element_id_names.erase(it);
120 " defined in Outputs/extra_element_ids_to_output " 121 "is not defined on the mesh and will be ignored.");
133 if (output_extra_ids)
136 const auto n_elem = output_mesh.n_elem();
137 std::vector<std::string> eeid_vars;
138 const auto n_eeid_to_output = restrict_element_id_names ? element_id_names.size() : n_eeid;
139 std::vector<Number> eeid_soln(
n_elem * n_eeid_to_output);
140 unsigned int soln_index = 0;
141 for (
unsigned int i = 0; i < n_eeid; i++)
143 const auto eeid_name = output_mesh.get_elem_integer_name(i);
147 if (!restrict_element_id_names ||
148 (std::find(element_id_names.begin(), element_id_names.end(), eeid_name) !=
149 element_id_names.end()))
151 eeid_vars.push_back(output_mesh.get_elem_integer_name(i));
152 for (
const auto & elem : output_mesh.element_ptr_range())
154 eeid_soln[soln_index] = (
int)elem->get_extra_integer(i);
162 if (eeid_vars.size() > 0)
168 int empty_timestep = 1;
169 Real default_time = 1.0;
170 exio_helper.write_timestep(empty_timestep, default_time);
173 std::vector<std::set<subdomain_id_type>> vars_active_subdomains;
174 vars_active_subdomains.resize(n_eeid_to_output);
175 exio_helper.initialize_element_variables(eeid_vars, vars_active_subdomains);
176 exio_helper.write_element_values(
177 output_mesh, eeid_soln, empty_timestep, vars_active_subdomains);
181 "Outputs/output_extra_element_ids is set to true but no extra element ids are being " 182 "outputted. Please check extra element ids are properly defined on the mesh and any " 183 "variables specified in Outputs/extra_element_ids_to_output are spelled correctly.");
187 else if (mesh_file.find(
".cpa.gz") + 7 == mesh_file.size())
189 TIME_SECTION(
"act", 1,
"Writing Checkpoint");
198 Moose::out <<
"Mesh meta data written into " 199 << std::filesystem::absolute(filenames[0].parent_path()) <<
"." << std::endl;
205 mesh_ptr->getMesh().write(mesh_file);
virtual void write(const std::string &name) override
static InputParameters validParams()
ExodusII_IO_Helper & get_exio_helper()
static const RestartableDataMapName MESH_META_DATA
const Parallel::Communicator & comm() const
std::vector< std::filesystem::path > writeRestartableMetaData(const RestartableDataMapName &name, const std::filesystem::path &folder_base)
Writes the restartable meta data for name with a folder base of folder_base.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
const InputParameters & parameters()
Get the parameters of the object.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::shared_ptr< MooseMesh > & mesh()
Action for creating output objects.
static InputParameters validParams()
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
Moose::Builder & builder()
Returns a writable reference to the builder.
bool unusedFlagIsError() const
Returns whether the flag for unused parameters is set to throw an error.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
void errorCheck(const libMesh::Parallel::Communicator &comm, bool warn_unused, bool err_unused)
MooseApp & _app
The MOOSE application this is associated with.
std::string getPrimaryFileName(bool stripLeadingPath=true) const
Return the primary (first) filename that was parsed.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
virtual void write(const std::string &fname) override
static void setOutputDimensionInExodusWriter(libMesh::ExodusII_IO &exodus_io, const MooseMesh &mesh, OutputDimension output_dim=OutputDimension::DEFAULT)
Helper method to change the output dimension in the passed in Exodus writer depending on the dimensio...
bool unusedFlagIsWarning() const
Returns whether the flag for unused parameters is set to throw a warning only.
MeshOnlyAction(const InputParameters ¶ms)
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
processor_id_type processor_id() const
void set_hdf5_writing(bool write_hdf5)
void ErrorVector unsigned int
registerMooseAction("MooseApp", MeshOnlyAction, "mesh_only")