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
24
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.addDeprecatedParam<bool>("nemesis",
45 false,
46 "If nemesis=true and file=foo.n, actually reads "
47 "foo.n.N.0, foo.n.N.1, ... foo.n.N.N-1, "
48 "where N = # CPUs, with NemesisIO.",
49 "This parameter should no longer be necessary if you use the "
50 "'.n' or '.nem' file extension for Nemesis files");
51 params.addClassDescription("Read a mesh from a file.");
52 return params;
53}
54
56 : MooseMesh(parameters), _file_name(getParam<MeshFileName>("file"))
57{
58 // Detect nemesis files from the extension or the parameter (deprecated)
59 if (isParamSetByUser("nemesis"))
60 _is_nemesis = getParam<bool>("nemesis");
61 else
62 _is_nemesis = (MooseUtils::hasExtension(_file_name, "n", /*strip_exodus_ext =*/true) ||
64
65 // We may have determined this is a nemesis file from the extension, which MooseMesh cannot do
67}
68
69FileMesh::FileMesh(const FileMesh & other_mesh)
70 : MooseMesh(other_mesh), _file_name(other_mesh._file_name)
71{
72}
73
75
76std::unique_ptr<MooseMesh>
78{
79 return _app.getFactory().copyConstruct(*this);
80}
81
82void
84{
85 TIME_SECTION("buildMesh", 2, "Reading Mesh");
86
87 // This dimension should get overridden if the mesh reader can determine the dimension
88 getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));
89
90 if (_is_nemesis)
91 {
92 // Nemesis_IO only takes a reference to DistributedMesh, so we can't be quite so short here.
93 DistributedMesh & pmesh = cast_ref<DistributedMesh &>(getMesh());
95
96 getMesh().allow_renumbering(false);
97
98 // Even if we want repartitioning when load balancing later, we'll
99 // begin with the default partitioning defined by the Nemesis
100 // file.
101 bool skip_partitioning_later = getMesh().skip_partitioning();
102 getMesh().skip_partitioning(true);
103 getMesh().prepare_for_use();
104 getMesh().skip_partitioning(skip_partitioning_later);
105 }
106 else // not reading Nemesis files
107 {
108 // See if the user has requested reading a solution from the file. If so, we'll need to read
109 // the mesh with the exodus reader instead of using mesh.read(). This will read the mesh on
110 // every processor
111
112 if (_app.getExodusFileRestart() && (_file_name.rfind(".exo") < _file_name.size() ||
113 _file_name.rfind(".e") < _file_name.size()))
114 {
116
117 auto exreader = std::make_shared<ExodusII_IO>(getMesh());
118 _app.setExReaderForRestart(std::move(exreader));
119 exreader->read(_file_name);
120
121 getMesh().allow_renumbering(false);
122 getMesh().prepare_for_use();
123 }
124 else
125 {
127
128 // If we are reading a mesh while restarting, then we might have
129 // a solution file that relies on that mesh partitioning and/or
130 // numbering. In that case, we need to turn off repartitioning
131 // and renumbering, at least at first.
132 bool restarting = _file_name.rfind(".cpa.gz") < _file_name.size();
133
134 const bool skip_partitioning_later = restarting && getMesh().skip_partitioning();
135 const bool allow_renumbering_later = restarting && getMesh().allow_renumbering();
136
137 if (restarting)
138 {
139 getMesh().skip_partitioning(true);
140 getMesh().allow_renumbering(false);
141 }
142
144 getMesh().read(_file_name);
145
146 if (getParam<bool>("clear_spline_nodes"))
148
150
151 if (restarting)
152 {
153 getMesh().allow_renumbering(allow_renumbering_later);
154 getMesh().skip_partitioning(skip_partitioning_later);
155 }
156 }
157 }
158}
159
160void
161FileMesh::read(const std::string & file_name)
162{
163 if (dynamic_cast<DistributedMesh *>(&getMesh()) && !_is_nemesis)
164 getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/false);
165 else
166 getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/true);
167}
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:161
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:77
virtual ~FileMesh()
Definition FileMesh.C:74
virtual void buildMesh() override
Must be overridden by child classes.
Definition FileMesh.C:83
std::string _file_name
the file_name from whence this mesh came
Definition FileMesh.h:35
FileMesh(const InputParameters &parameters)
Definition FileMesh.C:55
static InputParameters validParams()
Definition FileMesh.C:28
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:2530
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:3549
void determineUseDistributedMesh()
Determine whether to use a distributed mesh.
Definition MooseMesh.C:2882
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition MooseMesh.C:83
bool _is_nemesis
True if a Nemesis Mesh was read in.
Definition MooseMesh.h:1639
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 &)