Commit adbc5f31 authored by Tom Fischer's avatar Tom Fischer Committed by Dmitry Yu. Naumov
Browse files

[PL/Output] Mv file format specific fcts to OutputVtkFormat or OutputXDMFHDF5Format

parent 5c85f5bc
......@@ -65,43 +65,6 @@ void addBulkMeshNodePropertyToSubMesh(MeshLib::Mesh const& bulk_mesh,
{ return bulk_mesh_property[id]; });
}
/**
* Get the address of a PVDFile corresponding to the given process.
* @param process Process.
* @param process_id Process ID.
* @param mesh_name_for_output mesh name for the output.
* @param process_to_pvd_file a multimap that holds the PVD files associated
* with each process.
* @return Address of a PVDFile.
*/
MeshLib::IO::PVDFile& findPVDFile(
Process const& process, const int process_id, std::string const& filename,
std::multimap<Process const*, MeshLib::IO::PVDFile>& process_to_pvd_file)
{
auto range = process_to_pvd_file.equal_range(&process);
int counter = 0;
MeshLib::IO::PVDFile* pvd_file = nullptr;
for (auto spd_it = range.first; spd_it != range.second; ++spd_it)
{
if (spd_it->second.pvd_filename == filename)
{
if (counter == process_id)
{
pvd_file = &spd_it->second;
break;
}
counter++;
}
}
if (pvd_file == nullptr)
{
OGS_FATAL(
"The given process is not contained in the output configuration. "
"Aborting.");
}
return *pvd_file;
}
bool Output::isOutputStep(int timestep, double const t) const
{
......@@ -137,15 +100,23 @@ bool Output::isOutputStep(int timestep, double const t) const
bool Output::isOutputProcess(const int process_id, const Process& process) const
{
auto const n_processes = static_cast<int>(_process_to_pvd_file.size() /
_mesh_names_for_output.size());
if (!dynamic_cast<OutputVtkFormat*>(output_file.get()))
{
return process.isMonolithicSchemeUsed();
}
auto const number_of_pvd_files =
dynamic_cast<OutputVtkFormat*>(output_file.get())
->process_to_pvd_file.size();
auto const n_processes =
static_cast<int>(number_of_pvd_files / _mesh_names_for_output.size());
auto const is_last_process = process_id == n_processes - 1;
return process.isMonolithicSchemeUsed()
// For the staggered scheme for the coupling, only the last process,
// which gives the latest solution within a coupling loop, is allowed
// to make output.
// For the staggered scheme for the coupling, only the last
// process, which gives the latest solution within a coupling
// loop, is allowed to make output.
|| is_last_process;
}
......@@ -168,14 +139,7 @@ void Output::addProcess(ProcessLib::Process const& process)
{
_mesh_names_for_output.push_back(process.getMesh().getName());
}
for (auto const& mesh_output_name : _mesh_names_for_output)
{
auto const filename = output_file->constructPVDName(mesh_output_name);
_process_to_pvd_file.emplace(std::piecewise_construct,
std::forward_as_tuple(&process),
std::forward_as_tuple(filename));
}
output_file->addProcess(process, _mesh_names_for_output);
}
void Output::outputMeshes(
......@@ -183,23 +147,9 @@ void Output::outputMeshes(
const double t, const int iteration,
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes)
{
if (output_file->type == ProcessLib::OutputType::vtk)
{
for (auto const& mesh : meshes)
{
auto const filename =
output_file->constructPVDName(mesh.get().getName());
auto& pvd_file = findPVDFile(process, process_id, filename,
_process_to_pvd_file);
outputMeshVtk(*output_file.get(), pvd_file, mesh, t, timestep,
iteration);
}
}
else if (output_file->type == ProcessLib::OutputType::xdmf)
{
output_file->outputMeshXdmf(_output_data_specification.output_variables,
std::move(meshes), timestep, t, iteration);
}
output_file->outputMeshes(process, process_id, timestep, t, iteration,
meshes,
_output_data_specification.output_variables);
}
MeshLib::Mesh const& Output::prepareSubmesh(
......
......@@ -97,14 +97,6 @@ private:
bool const _output_nonlinear_iteration_results;
//! Holds the PVD files associated with each process.
//!
//! Each \c process_id of each Process (in the current simulation) has a PVD
//! file in this map for each element of #_mesh_names_for_output. I.e., the
//! number of elements in this map is (roughly):
//! <no. of processes> x <no. of process IDs per process> x <no. of meshes>.
std::multimap<Process const*, MeshLib::IO::PVDFile> _process_to_pvd_file;
OutputDataSpecification const _output_data_specification;
std::vector<std::string> _mesh_names_for_output;
std::vector<std::unique_ptr<MeshLib::Mesh>> const& _meshes;
......
......@@ -17,6 +17,44 @@
namespace ProcessLib
{
/**
* Get the address of a PVDFile corresponding to the given process.
* @param process Process.
* @param process_id Process ID.
* @param mesh_name_for_output mesh name for the output.
* @param process_to_pvd_file a multimap that holds the PVD files associated
* with each process.
* @return Address of a PVDFile.
*/
MeshLib::IO::PVDFile& findPVDFile(
Process const& process, const int process_id, std::string const& filename,
std::multimap<Process const*, MeshLib::IO::PVDFile>& process_to_pvd_file)
{
auto range = process_to_pvd_file.equal_range(&process);
int counter = 0;
MeshLib::IO::PVDFile* pvd_file = nullptr;
for (auto spd_it = range.first; spd_it != range.second; ++spd_it)
{
if (spd_it->second.pvd_filename == filename)
{
if (counter == process_id)
{
pvd_file = &spd_it->second;
break;
}
counter++;
}
}
if (pvd_file == nullptr)
{
OGS_FATAL(
"The given process is not contained in the output configuration. "
"Aborting.");
}
return *pvd_file;
}
void outputMeshVtk(std::string const& file_name, MeshLib::Mesh const& mesh,
bool const compress_output, int const data_mode)
{
......@@ -61,7 +99,8 @@ void outputMeshVtk(ProcessLib::OutputFile const& output_file,
outputMeshVtk(path, mesh, output_file.compression, output_file.data_mode);
}
std::string OutputFile::constructPVDName(std::string const& mesh_name) const
std::string OutputVtkFormat::constructPVDName(
std::string const& mesh_name) const
{
return BaseLib::joinPaths(
directory,
......@@ -127,4 +166,31 @@ void OutputFile::outputMeshXdmf(
};
}
void OutputVtkFormat::outputMeshes(
const Process& process, const int process_id, const int timestep,
const double t, const int iteration,
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes,
[[maybe_unused]] std::set<std::string> const& output_variables)
{
for (auto const& mesh : meshes)
{
auto const filename = constructPVDName(mesh.get().getName());
auto& pvd_file =
findPVDFile(process, process_id, filename, process_to_pvd_file);
outputMeshVtk(*this, pvd_file, mesh, t, timestep, iteration);
}
}
void OutputVtkFormat::addProcess(
ProcessLib::Process const& process,
std::vector<std::string> const& mesh_names_for_output)
{
for (auto const& mesh_output_name : mesh_names_for_output)
{
auto const filename = constructPVDName(mesh_output_name);
process_to_pvd_file.emplace(std::piecewise_construct,
std::forward_as_tuple(&process),
std::forward_as_tuple(filename));
}
}
} // namespace ProcessLib
......@@ -36,6 +36,18 @@ struct OutputFile
std::string suffix;
OutputType const type;
virtual void outputMeshes(
const Process& process, const int process_id, const int timestep,
const double t, const int iteration,
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes,
std::set<std::string> const& output_variables) = 0;
virtual void addProcess(
[[maybe_unused]] ProcessLib::Process const& process,
[[maybe_unused]] std::vector<std::string> const& mesh_names_for_output)
{
}
//! Chooses vtk's data mode for output following the enumeration given
/// in the vtkXMLWriter: {Ascii, Binary, Appended}. See vtkXMLWriter
/// documentation
......@@ -58,7 +70,7 @@ struct OutputFile
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes,
int const timestep, double const t, int const iteration);
std::string constructPVDName(std::string const& mesh_name) const;
// std::string constructPVDName(std::string const& mesh_name) const;
};
struct OutputVtkFormat final : public OutputFile
......@@ -71,6 +83,16 @@ struct OutputVtkFormat final : public OutputFile
{
}
void outputMeshes(
const Process& process, const int process_id, const int timestep,
const double t, const int iteration,
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes,
std::set<std::string> const& output_variables) override;
void addProcess(
ProcessLib::Process const& process,
std::vector<std::string> const& mesh_names_for_output) override;
//! Chooses vtk's data mode for output following the enumeration given
/// in the vtkXMLWriter: {Ascii, Binary, Appended}. See vtkXMLWriter
/// documentation
......@@ -80,11 +102,19 @@ struct OutputVtkFormat final : public OutputFile
//! Enables or disables zlib-compression of the output files.
// bool const compression;
//! Holds the PVD files associated with each process.
//!
//! Each \c process_id of each Process (in the current simulation) has a PVD
//! file in this map for each element of #_mesh_names_for_output. I.e., the
//! number of elements in this map is (roughly):
//! <no. of processes> x <no. of process IDs per process> x <no. of meshes>.
std::multimap<Process const*, MeshLib::IO::PVDFile> process_to_pvd_file;
std::string constructFilename(std::string mesh_name, int const timestep,
double const t,
int const iteration) const override;
// std::string constructPVDName(std::string const& mesh_name) const;
std::string constructPVDName(std::string const& mesh_name) const;
};
struct OutputXDMFHDF5Format final : public OutputFile
......@@ -98,6 +128,17 @@ struct OutputXDMFHDF5Format final : public OutputFile
{
}
void outputMeshes(
[[maybe_unused]] const Process& process,
[[maybe_unused]] const int process_id, const int timestep,
const double t, const int iteration,
std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes,
std::set<std::string> const& output_variables) override
{
outputMeshXdmf(output_variables, std::move(meshes), timestep, t,
iteration);
}
std::string constructFilename(std::string mesh_name, int const timestep,
double const t,
int const iteration) const override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment