Skip to content

Commit 0cacb92

Browse files
committed
Add read capability directly from Xdr, remove old infinite reload try
1 parent b031a0f commit 0cacb92

2 files changed

Lines changed: 35 additions & 92 deletions

File tree

include/systems/equation_systems.h

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -458,28 +458,22 @@ class EquationSystems : public ReferenceCountedObject<EquationSystems>,
458458
* processes. This renumbering is not compatible with meshes
459459
* that have two nodes in exactly the same position!
460460
*/
461-
template <typename InValType>
461+
template <typename InValType = Number>
462462
void read (std::string_view name,
463463
const XdrMODE,
464464
const unsigned int read_flags=(READ_HEADER | READ_DATA),
465465
bool partition_agnostic = true);
466466

467-
void read (std::string_view name,
468-
const XdrMODE mode,
469-
const unsigned int read_flags=(READ_HEADER | READ_DATA),
470-
bool partition_agnostic = true)
471-
{ read<Number>(name, mode, read_flags, partition_agnostic); }
472-
473-
template <typename InValType>
467+
template <typename InValType = Number>
474468
void read (std::string_view name,
475469
const unsigned int read_flags=(READ_HEADER | READ_DATA),
476470
bool partition_agnostic = true);
477471

478-
void read (std::string_view name,
472+
template <typename InValType = Number>
473+
void read (Xdr & io,
474+
std::function<std::unique_ptr<Xdr>()> & local_io_functor,
479475
const unsigned int read_flags=(READ_HEADER | READ_DATA),
480-
bool partition_agnostic = true)
481-
{ read<Number>(name, read_flags, partition_agnostic); }
482-
476+
bool partition_agnostic = true);
483477

484478
/**
485479
* Write the systems to disk using the XDR data format.
@@ -627,27 +621,6 @@ class EquationSystems : public ReferenceCountedObject<EquationSystems>,
627621
bool _enable_default_ghosting;
628622

629623
private:
630-
631-
/**
632-
* Actual read implementation. This can be called repeatedly
633-
* inside a try-catch block in an attempt to read broken files.
634-
*
635-
* \param name Name of the file to be read.
636-
* \param read_flags Single flag created by bitwise-OR'ing several flags together.
637-
* \param partition_agnostic If true then the mesh and degrees of freedom
638-
* will be temporarily renumbered in a partition agnostic way so that
639-
* files written using "n" mpi processes can be re-read on "m" mpi
640-
* processes.
641-
*
642-
* \note This renumbering is not compatible with meshes that have
643-
* two nodes in exactly the same position!
644-
*/
645-
template <typename InValType>
646-
void _read_impl (std::string_view name,
647-
const XdrMODE,
648-
const unsigned int read_flags,
649-
bool partition_agnostic = true);
650-
651624
/**
652625
* This function is used in the implementation of add_system,
653626
* it loops over the nodes and elements of the Mesh, adding the

src/systems/equation_systems_io.C

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ void EquationSystems::read (std::string_view name,
8181
if (name.find(".xdr") != std::string::npos)
8282
mode = DECODE;
8383
this->read(name, mode, read_flags, partition_agnostic);
84-
85-
#ifdef LIBMESH_ENABLE_AMR
86-
MeshRefinement mesh_refine(_mesh);
87-
mesh_refine.clean_refinement_flags();
88-
#endif
8984
}
9085

9186

@@ -96,58 +91,24 @@ void EquationSystems::read (std::string_view name,
9691
const unsigned int read_flags,
9792
bool partition_agnostic)
9893
{
99-
// If we have exceptions enabled we can be considerate and try
100-
// to read old restart files which contain infinite element
101-
// information but do not have the " with infinite elements"
102-
// string in the version information.
103-
104-
// First try the read the user requested
105-
libmesh_try
106-
{
107-
this->_read_impl<InValType> (name, mode, read_flags, partition_agnostic);
108-
}
109-
110-
// If that fails, try it again but explicitly request we look for infinite element info
111-
libmesh_catch (...)
112-
{
113-
libMesh::out << "\n*********************************************************************\n"
114-
<< "READING THE FILE \"" << name << "\" FAILED.\n"
115-
<< "It is possible this file contains infinite element information,\n"
116-
<< "but the version string does not contain \" with infinite elements\"\n"
117-
<< "Let's try this again, but looking for infinite element information...\n"
118-
<< "*********************************************************************\n"
119-
<< std::endl;
120-
121-
libmesh_try
122-
{
123-
this->_read_impl<InValType> (name, mode, read_flags | EquationSystems::TRY_READ_IFEMS, partition_agnostic);
124-
}
94+
// This will unzip a file with .bz2 as the extension, otherwise it
95+
// simply returns the name if the file need not be unzipped.
96+
Xdr io ((this->processor_id() == 0) ? std::string(name) : "", mode);
12597

126-
// If all that failed, we are out of ideas here...
127-
libmesh_catch (...)
128-
{
129-
libMesh::out << "\n*********************************************************************\n"
130-
<< "Well, at least we tried!\n"
131-
<< "Good Luck!!\n"
132-
<< "*********************************************************************\n"
133-
<< std::endl;
134-
libmesh_error();
135-
}
136-
}
98+
std::function<std::unique_ptr<Xdr>()> local_io_functor;
99+
local_io_functor = [this,&name,&mode]() {
100+
return std::make_unique<Xdr>(local_file_name(this->processor_id(), name), mode); };
137101

138-
#ifdef LIBMESH_ENABLE_AMR
139-
MeshRefinement mesh_refine(_mesh);
140-
mesh_refine.clean_refinement_flags();
141-
#endif
102+
this->read(io, local_io_functor, read_flags, partition_agnostic);
142103
}
143104

144105

145106

146107
template <typename InValType>
147-
void EquationSystems::_read_impl (std::string_view name,
148-
const XdrMODE mode,
149-
const unsigned int read_flags,
150-
bool partition_agnostic)
108+
void EquationSystems::read (Xdr & io,
109+
std::function<std::unique_ptr<Xdr>()> & local_io_functor,
110+
const unsigned int read_flags,
111+
bool partition_agnostic)
151112
{
152113
/**
153114
* This program implements the output of an
@@ -223,9 +184,6 @@ void EquationSystems::_read_impl (std::string_view name,
223184

224185
std::vector<std::pair<std::string, System *>> xda_systems;
225186

226-
// This will unzip a file with .bz2 as the extension, otherwise it
227-
// simply returns the name if the file need not be unzipped.
228-
Xdr io ((this->processor_id() == 0) ? std::string(name) : "", mode);
229187
libmesh_assert (io.reading());
230188

231189
{
@@ -247,7 +205,7 @@ void EquationSystems::_read_impl (std::string_view name,
247205

248206
// Recursively call this read() function but with the
249207
// EquationSystems::READ_LEGACY_FORMAT bit set.
250-
this->read (name, mode, (read_flags | EquationSystems::READ_LEGACY_FORMAT), partition_agnostic);
208+
this->read (io, local_io_functor, (read_flags | EquationSystems::READ_LEGACY_FORMAT), partition_agnostic);
251209
return;
252210
}
253211

@@ -328,6 +286,8 @@ void EquationSystems::_read_impl (std::string_view name,
328286
// Read and set the numeric vector values
329287
if (read_data)
330288
{
289+
std::unique_ptr<Xdr> local_io;
290+
331291
// the EquationSystems::read() method should look constant from the mesh
332292
// perspective, but we need to assign a temporary numbering to the nodes
333293
// and elements in the mesh, which requires that we abuse const_cast
@@ -337,8 +297,6 @@ void EquationSystems::_read_impl (std::string_view name,
337297
MeshTools::Private::globally_renumber_nodes_and_elements(mesh);
338298
}
339299

340-
Xdr local_io (read_parallel_files ? local_file_name(this->processor_id(),name) : "", mode);
341-
342300
for (auto & pr : xda_systems)
343301
if (read_legacy_format)
344302
{
@@ -349,7 +307,14 @@ void EquationSystems::_read_impl (std::string_view name,
349307
}
350308
else
351309
if (read_parallel_files)
352-
pr.second->read_parallel_data<InValType> (local_io, read_additional_data);
310+
{
311+
if (!local_io)
312+
{
313+
local_io = local_io_functor();
314+
libmesh_assert(local_io->reading());
315+
}
316+
pr.second->read_parallel_data<InValType> (*local_io, read_additional_data);
317+
}
353318
else
354319
pr.second->read_serialized_data<InValType> (io, read_additional_data);
355320

@@ -361,6 +326,11 @@ void EquationSystems::_read_impl (std::string_view name,
361326

362327
// Localize each system's data
363328
this->update();
329+
330+
#ifdef LIBMESH_ENABLE_AMR
331+
MeshRefinement mesh_refine(_mesh);
332+
mesh_refine.clean_refinement_flags();
333+
#endif
364334
}
365335

366336

@@ -602,13 +572,13 @@ void EquationSystems::write(Xdr & io,
602572

603573
// template specialization
604574

575+
template LIBMESH_EXPORT void EquationSystems::read<Number> (Xdr & io, std::function<std::unique_ptr<Xdr>()> & local_io_functor, const unsigned int read_flags, bool partition_agnostic);
605576
template LIBMESH_EXPORT void EquationSystems::read<Number> (std::string_view name, const unsigned int read_flags, bool partition_agnostic);
606577
template LIBMESH_EXPORT void EquationSystems::read<Number> (std::string_view name, const XdrMODE mode, const unsigned int read_flags, bool partition_agnostic);
607-
template LIBMESH_EXPORT void EquationSystems::_read_impl<Number> (std::string_view name, const XdrMODE mode, const unsigned int read_flags, bool partition_agnostic);
608578
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
579+
template LIBMESH_EXPORT void EquationSystems::read<Real> (Xdr & io, std::function<std::unique_ptr<Xdr>()> & local_io_functor, const unsigned int read_flags, bool partition_agnostic);
609580
template LIBMESH_EXPORT void EquationSystems::read<Real> (std::string_view name, const unsigned int read_flags, bool partition_agnostic);
610581
template LIBMESH_EXPORT void EquationSystems::read<Real> (std::string_view name, const XdrMODE mode, const unsigned int read_flags, bool partition_agnostic);
611-
template LIBMESH_EXPORT void EquationSystems::_read_impl<Real> (std::string_view name, const XdrMODE mode, const unsigned int read_flags, bool partition_agnostic);
612582
#endif
613583

614584
} // namespace libMesh

0 commit comments

Comments
 (0)