https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FileMeshGenerator.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 "FileMeshGenerator.h"
11#include "CastUniquePointer.h"
12
13#include "libmesh/replicated_mesh.h"
14#include "libmesh/face_quad4.h"
15#include "libmesh/exodusII_io.h"
16#include "libmesh/mesh_communication.h"
17#include "libmesh/mesh_tools.h"
18#include "libmesh/sparse_matrix.h"
19
21
24{
26
27 params.addRequiredParam<MeshFileName>("file", "The filename to read.");
28 params.addParam<std::vector<std::string>>(
29 "exodus_extra_element_integers",
30 "The variable names in the mesh file for loading extra element integers");
31 params.addParam<bool>("use_for_exodus_restart",
32 false,
33 "True to indicate that the mesh file this generator is reading can be used "
34 "for restarting variables");
35 params.addParam<bool>("skip_partitioning",
36 false,
37 "True to skip partitioning, only after this mesh generator, "
38 "because the mesh was pre-split for example.");
39 params.addParam<bool>("allow_renumbering",
40 true,
41 "Whether to allow the mesh to renumber nodes and elements, if not "
42 "overridden by a global parameter or by a requirement (e.g. an exodus "
43 "restart or a constraint matrix) that disables renumbering.");
44 params.addParam<bool>("clear_spline_nodes",
45 false,
46 "If clear_spline_nodes=true, IsoGeometric Analyis spline nodes "
47 "and constraints are removed from an IGA mesh, after which only "
48 "C^0 Rational-Bernstein-Bezier elements will remain.");
49 params.addParam<bool>("discontinuous_spline_extraction",
50 false,
51 "If discontinuous_spline_extraction=true, "
52 "Rational-Bernstein-Bezier elements extracted from a spline mesh "
53 "will be disconnected from neighboring elements, coupled only via "
54 "their extraction operators. This may be less efficient than the "
55 "default C^0 extracted mesh, but may be necessary if the extracted "
56 "mesh is non-conforming.");
57 params.addParam<MatrixFileName>(
58 "constraint_matrix", "", "The name of a constraint matrix file to apply to the mesh");
59 params.addParam<Real>("constraint_preconditioning",
60 0.0,
61 "Whether to attempt preconditioning with constraint matrix application");
62 params.addClassDescription("Read a mesh from a file.");
64 "clear_spline_nodes discontinuous_spline_extraction constraint_matrix",
65 "IsoGeometric Analysis (IGA) and other mesh constraint options");
66 return params;
67}
68
70 : MeshGenerator(parameters),
71 _file_name(getParam<MeshFileName>("file")),
72 _matrix_file_name(getParam<MatrixFileName>("constraint_matrix")),
73 _matrix_preconditioning(getParam<Real>("constraint_preconditioning")),
74 _skip_partitioning(getParam<bool>("skip_partitioning")),
75 _allow_renumbering(getParam<bool>("allow_renumbering"))
76{
78 paramError("constraint_preconditioning",
79 "The 'constraint_preconditioning' parameter is only applicable to "
80 "meshes loaded with a corresponding 'constraint_matrix'.");
82 paramError("constraint_preconditioning",
83 "This version of MOOSE only supports a 'constraint_preconditioning' "
84 "value of 1.0 if it is enabled. Non-binary preconditioning values "
85 "are reserved for future use.");
86}
87
88std::unique_ptr<MeshBase>
90{
92
93 // Maybe we'll reallow renumbering after constraints are applied?
94 bool eventually_allow_renumbering = _allow_renumbering && mesh->allow_renumbering();
95
96 // If we have a constraint matrix, we need its numbering to match
97 // the numbering in the mesh file
98 if (!_matrix_file_name.empty())
99 mesh->allow_renumbering(false);
100
101 // Figure out if we are reading an Exodus file, but not Tetgen (*.ele)
102 bool exodus = (_file_name.rfind(".exo") < _file_name.size() ||
103 _file_name.rfind(".e") < _file_name.size()) &&
104 _file_name.rfind(".ele") == std::string::npos;
105 bool has_exodus_integers = isParamValid("exodus_extra_element_integers");
106 bool restart_exodus = (getParam<bool>("use_for_exodus_restart") && _app.getExodusFileRestart());
107 if (exodus)
108 {
109 auto exreader = std::make_shared<libMesh::ExodusII_IO>(*mesh);
111
112 if (has_exodus_integers)
113 exreader->set_extra_integer_vars(
114 getParam<std::vector<std::string>>("exodus_extra_element_integers"));
115
116 if (restart_exodus)
117 {
118 _app.setExReaderForRestart(std::move(exreader));
119 exreader->read(_file_name);
120 eventually_allow_renumbering = false;
121 mesh->allow_renumbering(false);
122 }
123 else
124 {
125 if (mesh->processor_id() == 0)
126 {
127 if (getParam<bool>("discontinuous_spline_extraction"))
128 exreader->set_discontinuous_bex(true);
129
130 exreader->read(_file_name);
131
132 if (getParam<bool>("clear_spline_nodes"))
134 }
136 }
137 // Skip partitioning if the user requested it
139 mesh->skip_partitioning(true);
140 mesh->prepare_for_use();
141 mesh->skip_partitioning(false);
142 }
143 else
144 {
145 if (_pars.isParamSetByUser("exodus_extra_element_integers"))
146 mooseError("\"exodus_extra_element_integers\" should be given only for Exodus mesh files");
147 if (_pars.isParamSetByUser("use_for_exodus_restart"))
148 mooseError("\"use_for_exodus_restart\" should be given only for Exodus mesh files");
149
150 const auto file_name = deduceCheckpointPath(*this, _file_name);
152
153 mesh->skip_partitioning(_skip_partitioning);
154 mesh->allow_renumbering(_allow_renumbering);
155 mesh->read(file_name);
156
157 // Load the meta data if it is available
159 }
160
161 if (!_matrix_file_name.empty())
162 {
163 auto matrix = SparseMatrix<Number>::build(mesh->comm());
164 matrix->read(_matrix_file_name);
165
166 // In the future we might deduce matrix orientation via matrix
167 // size; for now we simply hardcode that the Flex IGA standard for
168 // projection operator matrices is the transpose of our standard
169 // for constraint equations.
170 matrix->get_transpose(*matrix);
171 mesh->copy_constraint_rows(*matrix, _matrix_preconditioning);
172
173 // libMesh should probably update this in copy_constraint_rows();
174 // once it does this will be a redundant sweep we can remove.
175 mesh->cache_elem_data();
176 }
177
178 mesh->allow_renumbering(eventually_allow_renumbering);
179
180 return dynamic_pointer_cast<MeshBase>(mesh);
181}
182
183std::string
184FileMeshGenerator::deduceCheckpointPath(const MooseObject & object, const std::string & file_name)
185{
186 // Just exists, use it
187 if (MooseUtils::pathExists(file_name))
188 return file_name;
189
190 // LATEST
191 return MooseUtils::convertLatestCheckpoint(file_name) + object.getMooseApp().checkpointSuffix();
192}
registerMooseObject("MooseApp", FileMeshGenerator)
Generates a mesh by reading it from an file.
const MeshFileName & _file_name
the path/name of the file containing the mesh
static std::string deduceCheckpointPath(const MooseObject &object, const std::string &file_name)
Helper for deducing a checkpoint file given the path.
FileMeshGenerator(const InputParameters &parameters)
static InputParameters validParams()
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const bool _skip_partitioning
whether to skip partitioning after loading the mesh
const MatrixFileName & _matrix_file_name
the path/name of any file containing a matrix of mesh constraints
const bool _allow_renumbering
Whether to allow renumbering (for non-exodus files) when the mesh is read and prepared for use.
const Real _matrix_preconditioning
Whether (and later, how much) libMesh should try constraint matrix preconditioning.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block.
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
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
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
const InputParameters & _pars
The object's parameters.
Definition MooseBase.h:384
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
void broadcast(MeshBase &) const
MeshBase & mesh
bool pathExists(const std::string &path)
Definition MooseUtils.C:258
std::string convertLatestCheckpoint(std::string orig)
Definition MooseUtils.C:168
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 &)