https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
23
25
28{
30 params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
31 MooseEnum dims("1=1 2 3", "1");
32 params.addParam<MooseEnum>("dim",
33 dims,
34 "This is only required for certain mesh formats where "
35 "the dimension of the mesh cannot be autodetected. "
36 "In particular you must supply this for GMSH meshes. "
37 "Note: This is completely ignored for ExodusII meshes!");
38 params.addParam<bool>("clear_spline_nodes",
39 false,
40 "If clear_spline_nodes=true, IsoGeometric Analyis spline nodes "
41 "and constraints are removed from an IGA mesh, after which only "
42 "C^0 Rational-Bernstein-Bezier elements will remain.");
43 params.addDeprecatedParam<bool>("nemesis",
44 false,
45 "If nemesis=true and file=foo.n, actually reads "
46 "foo.n.N.0, foo.n.N.1, ... foo.n.N.N-1, "
47 "where N = # CPUs, with NemesisIO.",
48 "This parameter should no longer be necessary if you use the "
49 "'.n' or '.nem' file extension for Nemesis files");
50 params.addClassDescription("Read a mesh from a file.");
51 return params;
52}
53
55 : MooseMesh(parameters), _file_name(getParam<MeshFileName>("file"))
56{
57 // Detect nemesis files from the extension or the parameter (deprecated)
58 if (isParamSetByUser("nemesis"))
59 _is_nemesis = getParam<bool>("nemesis");
60 else
61 _is_nemesis = (MooseUtils::hasExtension(_file_name, "n", /*strip_exodus_ext =*/true) ||
63
64 // We may have determined this is a nemesis file from the extension, which MooseMesh cannot do
66}
67
68FileMesh::FileMesh(const FileMesh & other_mesh)
69 : MooseMesh(other_mesh), _file_name(other_mesh._file_name)
70{
71}
72
74
75std::unique_ptr<MooseMesh>
77{
78 return _app.getFactory().copyConstruct(*this);
79}
80
81void
83{
84 TIME_SECTION("buildMesh", 2, "Reading Mesh");
85
86 // This dimension should get overridden if the mesh reader can determine the dimension
87 getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));
88
89 if (_is_nemesis)
90 {
91 // Nemesis_IO only takes a reference to DistributedMesh, so we can't be quite so short here.
92 DistributedMesh & pmesh = cast_ref<DistributedMesh &>(getMesh());
94
95 getMesh().allow_renumbering(false);
96
97 // Even if we want repartitioning when load balancing later, we'll
98 // begin with the default partitioning defined by the Nemesis
99 // file.
100 bool skip_partitioning_later = getMesh().skip_partitioning();
101 getMesh().skip_partitioning(true);
102 getMesh().prepare_for_use();
103 getMesh().skip_partitioning(skip_partitioning_later);
104 }
105 else // not reading Nemesis files
106 {
107 // See if the user has requested reading a solution from the file. If so, we'll need to read
108 // the mesh with the exodus reader instead of using mesh.read(). This will read the mesh on
109 // every processor
110
111 if (_app.getExodusFileRestart() && (_file_name.rfind(".exo") < _file_name.size() ||
112 _file_name.rfind(".e") < _file_name.size()))
113 {
115
116 auto exreader = std::make_shared<ExodusII_IO>(getMesh());
117 _app.setExReaderForRestart(std::move(exreader));
118 exreader->read(_file_name);
119
120 getMesh().allow_renumbering(false);
121 getMesh().prepare_for_use();
122 }
123 else
124 {
126
127 // If we are reading a mesh while restarting, then we might have
128 // a solution file that relies on that mesh partitioning and/or
129 // numbering. In that case, we need to turn off repartitioning
130 // and renumbering, at least at first.
131 bool restarting = _file_name.rfind(".cpa.gz") < _file_name.size();
132
133 const bool skip_partitioning_later = restarting && getMesh().skip_partitioning();
134 const bool allow_renumbering_later = restarting && getMesh().allow_renumbering();
135
136 if (restarting)
137 {
138 getMesh().skip_partitioning(true);
139 getMesh().allow_renumbering(false);
140 }
141
143 getMesh().read(_file_name);
144
145 if (getParam<bool>("clear_spline_nodes"))
147
149
150 if (restarting)
151 {
152 getMesh().allow_renumbering(allow_renumbering_later);
153 getMesh().skip_partitioning(skip_partitioning_later);
154 }
155 }
156 }
157}
158
159void
160FileMesh::read(const std::string & file_name)
161{
162 if (dynamic_cast<DistributedMesh *>(&getMesh()) && !_is_nemesis)
163 getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/false);
164 else
165 getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/true);
166}
registerMooseObject("MooseApp", FileMesh)
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition Factory.h:358
static std::string deduceCheckpointPath(const MooseObject &object, const std::string &file_name)
Helper for deducing a checkpoint file given the path.
void read(const std::string &file_name)
Definition FileMesh.C:160
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:76
virtual ~FileMesh()
Definition FileMesh.C:73
virtual void buildMesh() override
Must be overridden by child classes.
Definition FileMesh.C:82
std::string _file_name
the file_name from whence this mesh came
Definition FileMesh.h:35
FileMesh(const InputParameters &parameters)
Definition FileMesh.C:54
static InputParameters validParams()
Definition FileMesh.C:27
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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 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:2536
void setExReaderForRestart(std::shared_ptr< libMesh::ExodusII_IO > &&exreader)
Set the Exodus reader to restart variables from an Exodus mesh file.
Definition MooseApp.h:441
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
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:436
static const RestartableDataMapName MESH_META_DATA
Definition MooseApp.h:136
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition MooseBase.h:205
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3557
void determineUseDistributedMesh()
Determine whether to use a distributed mesh.
Definition MooseMesh.C:2890
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition MooseMesh.C:81
bool _is_nemesis
True if a Nemesis Mesh was read in.
Definition MooseMesh.h:1637
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
virtual void read(const std::string &base_filename) override
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext)
Definition MooseUtils.C:398
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
Definition MooseUtils.C:265
void clear_spline_nodes(MeshBase &)