forked from idaholab/moose
/
FileMesh.C
132 lines (110 loc) · 4.04 KB
/
FileMesh.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
122
123
124
125
126
127
128
129
130
131
132
//* 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 "FileMesh.h"
#include "Parser.h"
#include "MooseUtils.h"
#include "Moose.h"
#include "MooseApp.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/nemesis_io.h"
#include "libmesh/parallel_mesh.h"
registerMooseObject("MooseApp", FileMesh);
defineLegacyParams(FileMesh);
InputParameters
FileMesh::validParams()
{
InputParameters params = MooseMesh::validParams();
params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
params.addClassDescription("Read a mesh from a file.");
return params;
}
FileMesh::FileMesh(const InputParameters & parameters)
: MooseMesh(parameters),
_file_name(getParam<MeshFileName>("file")),
_dim(getParam<MooseEnum>("dim"))
{
}
FileMesh::FileMesh(const FileMesh & other_mesh)
: MooseMesh(other_mesh), _file_name(other_mesh._file_name), _dim(other_mesh._dim)
{
}
FileMesh::~FileMesh() {}
std::unique_ptr<MooseMesh>
FileMesh::safeClone() const
{
return libmesh_make_unique<FileMesh>(*this);
}
void
FileMesh::buildMesh()
{
TIME_SECTION("buildMesh", 2, "Reading Mesh");
getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));
if (_is_nemesis)
{
// Nemesis_IO only takes a reference to DistributedMesh, so we can't be quite so short here.
DistributedMesh & pmesh = cast_ref<DistributedMesh &>(getMesh());
Nemesis_IO(pmesh).read(_file_name);
getMesh().allow_renumbering(false);
// Even if we want repartitioning when load balancing later, we'll
// begin with the default partitioning defined by the Nemesis
// file.
bool skip_partitioning_later = getMesh().skip_partitioning();
getMesh().skip_partitioning(true);
getMesh().prepare_for_use(false, false);
getMesh().skip_partitioning(skip_partitioning_later);
}
else // not reading Nemesis files
{
// See if the user has requested reading a solution from the file. If so, we'll need to read
// the mesh with the exodus reader instead of using mesh.read(). This will read the mesh on
// every processor
if (_app.setFileRestart() && (_file_name.rfind(".exd") < _file_name.size() ||
_file_name.rfind(".e") < _file_name.size()))
{
MooseUtils::checkFileReadable(_file_name);
_exreader = libmesh_make_unique<ExodusII_IO>(getMesh());
_exreader->read(_file_name);
getMesh().allow_renumbering(false);
getMesh().prepare_for_use(false, false);
}
else
{
// If we are reading a mesh while restarting, then we might have
// a solution file that relies on that mesh partitioning and/or
// numbering. In that case, we need to turn off repartitioning
// and renumbering, at least at first.
_file_name = MooseUtils::convertLatestCheckpoint(_file_name, false);
bool restarting = _file_name.rfind(".cpa") < _file_name.size() ||
_file_name.rfind(".cpr") < _file_name.size();
const bool skip_partitioning_later = restarting && getMesh().skip_partitioning();
const bool allow_renumbering_later = restarting && getMesh().allow_renumbering();
if (restarting)
{
getMesh().skip_partitioning(true);
getMesh().allow_renumbering(false);
}
if (!MooseUtils::pathExists(_file_name))
mooseError("cannot locate mesh file '", _file_name, "'");
getMesh().read(_file_name);
if (restarting)
{
getMesh().allow_renumbering(allow_renumbering_later);
getMesh().skip_partitioning(skip_partitioning_later);
}
}
}
}
void
FileMesh::read(const std::string & file_name)
{
if (dynamic_cast<DistributedMesh *>(&getMesh()) && !_is_nemesis)
getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/false);
else
getMesh().read(file_name, /*mesh_data=*/NULL, /*skip_renumber=*/true);
}