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();
77 for (
const auto &
act : output_actions)
86 const int max_output_name_length =
100 exio.
write(mesh_file);
103 unsigned int n_eeid = output_mesh.n_elem_integers();
110 bool output_extra_ids = (n_eeid > 0);
111 bool restrict_element_id_names =
false;
112 std::vector<std::string> element_id_names;
113 for (
const auto &
act : output_actions)
125 output_extra_ids = params.
get<
bool>(
"output_extra_element_ids");
126 if (output_extra_ids)
130 restrict_element_id_names = params.
isParamValid(
"extra_element_ids_to_output");
131 if (restrict_element_id_names)
133 element_id_names = params.
get<std::vector<std::string>>(
"extra_element_ids_to_output");
136 for (
auto it = element_id_names.begin(); it != element_id_names.end();)
139 if (!output_mesh.has_elem_integer(*it))
141 it = element_id_names.erase(it);
144 " defined in Outputs/extra_element_ids_to_output "
145 "is not defined on the mesh and will be ignored.");
157 if (output_extra_ids)
160 const auto n_elem = output_mesh.n_elem();
161 std::vector<std::string> eeid_vars;
162 const auto n_eeid_to_output = restrict_element_id_names ? element_id_names.size() : n_eeid;
163 std::vector<Number> eeid_soln(n_elem * n_eeid_to_output);
164 unsigned int soln_index = 0;
165 for (
unsigned int i = 0; i < n_eeid; i++)
167 const auto eeid_name = output_mesh.get_elem_integer_name(i);
171 if (!restrict_element_id_names ||
172 (std::find(element_id_names.begin(), element_id_names.end(), eeid_name) !=
173 element_id_names.end()))
175 eeid_vars.push_back(output_mesh.get_elem_integer_name(i));
176 for (
const auto & elem : output_mesh.element_ptr_range())
178 eeid_soln[soln_index] = (
int)elem->get_extra_integer(i);
186 if (eeid_vars.size() > 0)
192 int empty_timestep = 1;
193 Real default_time = 1.0;
197 std::vector<std::set<subdomain_id_type>> vars_active_subdomains;
198 vars_active_subdomains.resize(n_eeid_to_output);
199 exio_helper.initialize_element_variables(eeid_vars, vars_active_subdomains);
200 exio_helper.write_element_values(
201 output_mesh, eeid_soln, empty_timestep, vars_active_subdomains);
205 "Outputs/output_extra_element_ids is set to true but no extra element ids are being "
206 "outputted. Please check extra element ids are properly defined on the mesh and any "
207 "variables specified in Outputs/extra_element_ids_to_output are spelled correctly.");
211 else if (mesh_file.find(
".cpa.gz") + 7 == mesh_file.size())
213 TIME_SECTION(
"act", 1,
"Writing Checkpoint");
222 Moose::out <<
"Mesh meta data written into "
223 << std::filesystem::absolute(filenames[0].parent_path()) <<
"." << std::endl;
229 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
void write_timestep(int timestep, Real time)
void set_max_name_length(unsigned int max_length)
virtual void write(const std::string &fname) override
void set_hdf5_writing(bool write_hdf5)
ExodusII_IO_Helper & get_exio_helper()
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
OStreamProxy err(std::cerr)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real