20#include "libmesh/exodusII_io.h"
21#include "libmesh/exodusII_io_helper.h"
22#include "libmesh/checkpoint_io.h"
46 _console << mesh_ptr->getMesh().get_info( 2) << std::endl;
48 if (mesh_file.empty())
51 size_t pos = mesh_file.find_last_of(
'.');
54 mesh_file = mesh_file.substr(0, pos) +
"_in.e";
62 if (mesh_file.find(
".e") + 2 == mesh_file.size())
64 TIME_SECTION(
"act", 1,
"Writing Exodus");
66 auto & output_mesh = mesh_ptr->getMesh();
67 ExodusII_IO exio(output_mesh);
70 exio.set_max_name_length(80);
75 for (
const auto &
act : output_actions)
84 const int max_output_name_length =
87 exio.set_max_name_length(max_output_name_length);
96 exio.set_hdf5_writing(
false);
98 exio.write(mesh_file);
101 unsigned int n_eeid = output_mesh.n_elem_integers();
108 bool output_extra_ids = (n_eeid > 0);
109 bool restrict_element_id_names =
false;
110 std::vector<std::string> element_id_names;
111 for (
const auto &
act : output_actions)
123 output_extra_ids = params.
get<
bool>(
"output_extra_element_ids");
124 if (output_extra_ids)
128 restrict_element_id_names = params.
isParamValid(
"extra_element_ids_to_output");
129 if (restrict_element_id_names)
131 element_id_names = params.
get<std::vector<std::string>>(
"extra_element_ids_to_output");
134 for (
auto it = element_id_names.begin(); it != element_id_names.end();)
137 if (!output_mesh.has_elem_integer(*it))
139 it = element_id_names.erase(it);
142 " defined in Outputs/extra_element_ids_to_output "
143 "is not defined on the mesh and will be ignored.");
155 if (output_extra_ids)
158 const auto n_elem = output_mesh.n_elem();
159 std::vector<std::string> eeid_vars;
160 const auto n_eeid_to_output = restrict_element_id_names ? element_id_names.size() : n_eeid;
161 std::vector<Number> eeid_soln(n_elem * n_eeid_to_output);
162 unsigned int soln_index = 0;
163 for (
unsigned int i = 0; i < n_eeid; i++)
165 const auto eeid_name = output_mesh.get_elem_integer_name(i);
169 if (!restrict_element_id_names ||
170 (std::find(element_id_names.begin(), element_id_names.end(), eeid_name) !=
171 element_id_names.end()))
173 eeid_vars.push_back(output_mesh.get_elem_integer_name(i));
174 for (
const auto & elem : output_mesh.element_ptr_range())
176 eeid_soln[soln_index] = (
int)elem->get_extra_integer(i);
184 if (eeid_vars.size() > 0)
187 auto & exio_helper = exio.get_exio_helper();
190 int empty_timestep = 1;
191 Real default_time = 1.0;
192 exio_helper.write_timestep(empty_timestep, default_time);
195 std::vector<std::set<subdomain_id_type>> vars_active_subdomains;
196 vars_active_subdomains.resize(n_eeid_to_output);
197 exio_helper.initialize_element_variables(eeid_vars, vars_active_subdomains);
198 exio_helper.write_element_values(
199 output_mesh, eeid_soln, empty_timestep, vars_active_subdomains);
203 "Outputs/output_extra_element_ids is set to true but no extra element ids are being "
204 "outputted. Please check extra element ids are properly defined on the mesh and any "
205 "variables specified in Outputs/extra_element_ids_to_output are spelled correctly.");
209 else if (mesh_file.find(
".cpa.gz") + 7 == mesh_file.size())
211 TIME_SECTION(
"act", 1,
"Writing Checkpoint");
220 Moose::out <<
"Mesh meta data written into "
221 << std::filesystem::absolute(filenames[0].parent_path()) <<
"." << std::endl;
227 mesh_ptr->getMesh().write(mesh_file);
registerMooseAction("MooseApp", MeshOnlyAction, "mesh_only")
void ErrorVector unsigned int
std::shared_ptr< MooseMesh > & mesh()
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
static InputParameters validParams()
MooseApp & _app
The MOOSE application this is associated with.
Action for creating output objects.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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...
static InputParameters validParams()
MeshOnlyAction(const InputParameters ¶ms)
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
bool unusedFlagIsError() const
Returns whether the flag for unused parameters is set to throw an error.
Moose::Builder & builder()
Returns a writable reference to the builder.
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.
bool unusedFlagIsWarning() const
Returns whether the flag for unused parameters is set to throw a warning only.
static const RestartableDataMapName MESH_META_DATA
const InputParameters & parameters() const
Get the parameters of the object.
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
std::string getPrimaryFileName(bool stripLeadingPath=true) const
Return the primary (first) filename that was parsed.
void errorCheck(const libMesh::Parallel::Communicator &comm, bool warn_unused, bool err_unused)
void mooseWarning(Args &&... args) const
virtual void write(const std::string &name) override
processor_id_type processor_id() const
const Parallel::Communicator & comm() const