forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileMeshGenerator.C
121 lines (106 loc) · 4.36 KB
/
FileMeshGenerator.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "FileMeshGenerator.h"
#include "CastUniquePointer.h"
#include "RestartableDataIO.h"
#include "libmesh/replicated_mesh.h"
#include "libmesh/face_quad4.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/mesh_communication.h"
#include "libmesh/mesh_tools.h"
registerMooseObject("MooseApp", FileMeshGenerator);
InputParameters
FileMeshGenerator::validParams()
{
InputParameters params = MeshGenerator::validParams();
params.addRequiredParam<MeshFileName>("file", "The filename to read.");
params.addParam<std::vector<std::string>>(
"exodus_extra_element_integers",
"The variable names in the mesh file for loading extra element integers");
params.addParam<bool>("use_for_exodus_restart",
false,
"True to indicate that the mesh file this generator is reading can be used "
"for restarting variables");
params.addParam<bool>("skip_partitioning",
false,
"True to skip partitioning, only after this mesh generator, "
"because the mesh was pre-split for example.");
params.addParam<bool>("clear_spline_nodes",
false,
"If clear_spline_nodes=true, IsoGeometric Analyis spline nodes "
"and constraints are removed from an IGA mesh, after which only "
"C^0 Rational-Bernstein-Bezier elements will remain.");
params.addClassDescription("Read a mesh from a file.");
return params;
}
FileMeshGenerator::FileMeshGenerator(const InputParameters & parameters)
: MeshGenerator(parameters),
_file_name(getParam<MeshFileName>("file")),
_skip_partitioning(getParam<bool>("skip_partitioning"))
{
}
std::unique_ptr<MeshBase>
FileMeshGenerator::generate()
{
auto mesh = buildMeshBaseObject();
bool exodus =
_file_name.rfind(".exd") < _file_name.size() || _file_name.rfind(".e") < _file_name.size();
bool has_exodus_integers = isParamValid("exodus_extra_element_integers");
bool restart_exodus = (getParam<bool>("use_for_exodus_restart") && _app.getExodusFileRestart());
if (exodus)
{
auto exreader = std::make_shared<ExodusII_IO>(*mesh);
if (has_exodus_integers)
exreader->set_extra_integer_vars(
getParam<std::vector<std::string>>("exodus_extra_element_integers"));
if (restart_exodus)
{
_app.setExReaderForRestart(std::move(exreader));
exreader->read(_file_name);
mesh->allow_renumbering(false);
}
else
{
if (mesh->processor_id() == 0)
{
exreader->read(_file_name);
if (getParam<bool>("clear_spline_nodes"))
MeshTools::clear_spline_nodes(*mesh);
}
MeshCommunication().broadcast(*mesh);
}
// Skip partitioning if the user requested it
if (_skip_partitioning)
mesh->skip_partitioning(true);
mesh->prepare_for_use();
mesh->skip_partitioning(false);
}
else
{
if (_pars.isParamSetByUser("exodus_extra_element_integers"))
mooseError("\"exodus_extra_element_integers\" should be given only for Exodus mesh files");
if (_pars.isParamSetByUser("use_for_exodus_restart"))
mooseError("\"use_for_exodus_restart\" should be given only for Exodus mesh files");
// to support LATEST word for loading checkpoint files
std::string file_name = MooseUtils::convertLatestCheckpoint(_file_name, false);
mesh->read(file_name);
// we also read declared mesh meta data here if there is meta data file
RestartableDataIO restartable(_app);
std::string fname = file_name + "/meta_data_mesh" + restartable.getRestartableDataExt();
if (MooseUtils::pathExists(fname))
{
restartable.setErrorOnLoadWithDifferentNumberOfProcessors(false);
// get reference to mesh meta data (created by MooseApp)
auto & meta_data = _app.getRestartableDataMap(MooseApp::MESH_META_DATA);
if (restartable.readRestartableDataHeaderFromFile(fname, false))
restartable.readRestartableData(meta_data, DataNames());
}
}
return dynamic_pointer_cast<MeshBase>(mesh);
}