https://mooseframework.inl.gov
FileMesh.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "FileMesh.h"
11 #include "Parser.h"
12 #include "MooseUtils.h"
13 #include "Moose.h"
14 #include "MooseApp.h"
15 #include "FileMeshGenerator.h"
16 
17 #include "libmesh/exodusII_io.h"
18 #include "libmesh/mesh_tools.h"
19 #include "libmesh/nemesis_io.h"
20 #include "libmesh/parallel_mesh.h"
21 
24 
25 registerMooseObject("MooseApp", FileMesh);
26 
29 {
31  params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
32  MooseEnum dims("1=1 2 3", "1");
33  params.addParam<MooseEnum>("dim",
34  dims,
35  "This is only required for certain mesh formats where "
36  "the dimension of the mesh cannot be autodetected. "
37  "In particular you must supply this for GMSH meshes. "
38  "Note: This is completely ignored for ExodusII meshes!");
39  params.addParam<bool>("clear_spline_nodes",
40  false,
41  "If clear_spline_nodes=true, IsoGeometric Analyis spline nodes "
42  "and constraints are removed from an IGA mesh, after which only "
43  "C^0 Rational-Bernstein-Bezier elements will remain.");
44  params.addClassDescription("Read a mesh from a file.");
45  return params;
46 }
47 
49  : MooseMesh(parameters), _file_name(getParam<MeshFileName>("file"))
50 {
51 }
52 
53 FileMesh::FileMesh(const FileMesh & other_mesh)
54  : MooseMesh(other_mesh), _file_name(other_mesh._file_name)
55 {
56 }
57 
59 
60 std::unique_ptr<MooseMesh>
62 {
63  return _app.getFactory().copyConstruct(*this);
64 }
65 
66 void
68 {
69  TIME_SECTION("buildMesh", 2, "Reading Mesh");
70 
71  // This dimension should get overridden if the mesh reader can determine the dimension
72  getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));
73 
74  if (_is_nemesis)
75  {
76  // Nemesis_IO only takes a reference to DistributedMesh, so we can't be quite so short here.
77  DistributedMesh & pmesh = cast_ref<DistributedMesh &>(getMesh());
78  Nemesis_IO(pmesh).read(_file_name);
79 
80  getMesh().allow_renumbering(false);
81 
82  // Even if we want repartitioning when load balancing later, we'll
83  // begin with the default partitioning defined by the Nemesis
84  // file.
85  bool skip_partitioning_later = getMesh().skip_partitioning();
86  getMesh().skip_partitioning(true);
87  getMesh().prepare_for_use();
88  getMesh().skip_partitioning(skip_partitioning_later);
89  }
90  else // not reading Nemesis files
91  {
92  // See if the user has requested reading a solution from the file. If so, we'll need to read
93  // the mesh with the exodus reader instead of using mesh.read(). This will read the mesh on
94  // every processor
95 
96  if (_app.getExodusFileRestart() && (_file_name.rfind(".exd") < _file_name.size() ||
97  _file_name.rfind(".e") < _file_name.size()))
98  {
100 
101  auto exreader = std::make_shared<ExodusII_IO>(getMesh());
102  _app.setExReaderForRestart(std::move(exreader));
103  exreader->read(_file_name);
104 
105  getMesh().allow_renumbering(false);
106  getMesh().prepare_for_use();
107  }
108  else
109  {
111 
112  // If we are reading a mesh while restarting, then we might have
113  // a solution file that relies on that mesh partitioning and/or
114  // numbering. In that case, we need to turn off repartitioning
115  // and renumbering, at least at first.
116  bool restarting = _file_name.rfind(".cpa.gz") < _file_name.size();
117 
118  const bool skip_partitioning_later = restarting && getMesh().skip_partitioning();
119  const bool allow_renumbering_later = restarting && getMesh().allow_renumbering();
120 
121  if (restarting)
122  {
123  getMesh().skip_partitioning(true);
124  getMesh().allow_renumbering(false);
125  }
126 
128  getMesh().read(_file_name);
129 
130  if (getParam<bool>("clear_spline_nodes"))
131  MeshTools::clear_spline_nodes(getMesh());
132 
134 
135  if (restarting)
136  {
137  getMesh().allow_renumbering(allow_renumbering_later);
138  getMesh().skip_partitioning(skip_partitioning_later);
139  }
140  }
141  }
142 }
143 
144 void
145 FileMesh::read(const std::string & file_name)
146 {
147  if (dynamic_cast<DistributedMesh *>(&getMesh()) && !_is_nemesis)
148  getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/false);
149  else
150  getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/true);
151 }
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:83
virtual std::unique_ptr< MooseMesh > safeClone() const override
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer...
Definition: FileMesh.C:61
bool _is_nemesis
True if a Nemesis Mesh was read in.
Definition: MooseMesh.h:1469
virtual void read(const std::string &base_filename) override
virtual void buildMesh() override
Must be overridden by child classes.
Definition: FileMesh.C:67
static const RestartableDataMapName MESH_META_DATA
Definition: MooseApp.h:123
std::string _file_name
the file_name from whence this mesh came
Definition: FileMesh.h:35
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual ~FileMesh()
Definition: FileMesh.C:58
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition: Factory.h:310
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:424
bool getExodusFileRestart() const
Whether or not we need to use a separate Exodus reader to read the mesh BEFORE we create the mesh...
Definition: MooseApp.h:453
void possiblyLoadRestartableMetaData(const RestartableDataMapName &name, const std::filesystem::path &folder_base)
Loads the restartable meta data for name if it is available with the folder base folder_base.
Definition: MooseApp.C:2528
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3443
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:250
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
static std::string deduceCheckpointPath(const MooseObject &object, const std::string &file_name)
Helper for deducing a checkpoint file given the path.
FileMesh(const InputParameters &parameters)
Definition: FileMesh.C:48
void read(const std::string &file_name)
Definition: FileMesh.C:145
static InputParameters validParams()
Definition: FileMesh.C:28
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
registerMooseObject("MooseApp", FileMesh)
void setExReaderForRestart(std::shared_ptr< libMesh::ExodusII_IO > &&exreader)
Set the Exodus reader to restart variables from an Exodus mesh file.
Definition: MooseApp.h:458