www.mooseframework.org
MeshOnlyAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MeshOnlyAction.h"
11 
12 #include "MooseApp.h"
13 #include "MooseMesh.h"
14 #include "Exodus.h"
15 #include "libmesh/exodusII_io.h"
16 
17 registerMooseAction("MooseApp", MeshOnlyAction, "mesh_only");
18 
19 template <>
22 {
23  return validParams<Action>();
24 }
25 
27 
28 void
30 {
31  auto mesh_file = _app.parameters().get<std::string>("mesh_only");
32  auto & mesh_ptr = _app.actionWarehouse().mesh();
33 
34  // Print information about the mesh
35  mesh_ptr->getMesh().print_info();
36 
37  bool should_generate = false;
38  // If no argument specified or if the argument following --mesh-only starts
39  // with a dash, try to build an output filename based on the input mesh filename.
40  if (mesh_file.empty() || (mesh_file[0] == '-'))
41  should_generate = true;
42  // There's something following the --mesh-only flag, let's make an attempt to validate it.
43  // If we don't find a '.' or we DO find an equals sign, chances are this is not a file!
44  else if ((mesh_file.find('.') == std::string::npos || mesh_file.find('=') != std::string::npos))
45  {
46  mooseWarning("The --mesh-only option should be followed by a file name. Move it to the end of "
47  "your CLI args or follow it by another \"-\" argument.");
48  should_generate = true;
49  }
50 
51  if (should_generate)
52  {
53  mesh_file = _app.parser().getFileName();
54  size_t pos = mesh_file.find_last_of('.');
55 
56  // Default to writing out an ExodusII mesh base on the input filename.
57  mesh_file = mesh_file.substr(0, pos) + "_in.e";
58  }
59 
65  if (mesh_file.find(".e") + 2 == mesh_file.size())
66  {
67  ExodusII_IO exio(mesh_ptr->getMesh());
68 
70 
71  exio.write(mesh_file);
72  }
73  else
74  {
75  // Just write the file using the name requested by the user.
76  mesh_ptr->getMesh().write(mesh_file);
77  }
78 }
InputParameters & parameters()
Get the parameters of the object.
Definition: MooseApp.h:86
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:219
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for actions.
Definition: Action.h:35
std::shared_ptr< MooseMesh > & mesh()
ActionWarehouse & actionWarehouse()
Definition: MooseApp.h:146
Parser & parser()
Definition: MooseApp.h:148
static void setOutputDimensionInExodusWriter(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...
Definition: Exodus.C:206
InputParameters validParams< MeshOnlyAction >()
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:290
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
MeshOnlyAction(InputParameters params)
registerMooseAction("MooseApp", MeshOnlyAction, "mesh_only")
InputParameters validParams< Action >()
Definition: Action.C:22