Verified Commit 5de4e3d5 authored by Lars Bilke's avatar Lars Bilke

Addressed MR comments.

Apply 17 suggestion(s) to 6 file(s)
parent 14aaa12e
......@@ -27,6 +27,7 @@
#include "XdmfData.h"
#include "writeHDF5.h"
using namespace MeshLib::IO;
using namespace std::string_literals;
static std::string getTimeSection(int const step, std::string const& name)
......@@ -34,8 +35,6 @@ static std::string getTimeSection(int const step, std::string const& name)
return "t_"s + std::to_string(step) + "/"s + name;
}
using namespace MeshLib::IO;
static boost::shared_ptr<XdmfGeometry> getLightGeometry(
std::string const& hdf5filename, int const step, Geometry const& geometry)
{
......@@ -96,19 +95,20 @@ namespace MeshLib::IO
Xdmf3Writer::Xdmf3Writer(std::filesystem::path const& filepath,
Geometry const& geometry,
Topology const& topology,
std::vector<AttributeMeta> const& attributes,
std::vector<AttributeMeta>
attributes,
int const timestep)
: _attributes(std::move(attributes)),
_hdf5filepath(filepath.parent_path() /
(std::string(filepath.stem()) + ".h5"))
{
std::filesystem::path xdmf_filepath =
std::filesystem::path const xdmf_filepath =
filepath.parent_path() / (std::string(filepath.stem()) + ".xdmf");
auto ret_hdf5 = writeHDF5Initial(geometry.flattend_values,
geometry.vldims,
topology.flattend_values,
timestep,
_hdf5filepath);
auto const ret_hdf5 = writeHDF5Initial(geometry.flattend_values,
geometry.vldims,
topology.flattend_values,
timestep,
_hdf5filepath);
// If we find a library for compression we use it
_use_compression = ret_hdf5.second;
......@@ -132,28 +132,28 @@ Xdmf3Writer::Xdmf3Writer(std::filesystem::path const& filepath,
_root->insert(grid_collection);
}
void Xdmf3Writer::WriteStep(int const time_step, double const time)
void Xdmf3Writer::writeStep(int const time_step, double const time)
{
auto grid = XdmfUnstructuredGrid::New();
grid->setGeometry(_initial_geometry);
grid->setTopology(_initial_topology);
grid->setTime(XdmfTime::New(time));
for (auto const& attribute_data : _attributes)
for (auto const& attribute : _attributes)
{
writeHDF5Step(_hdf5filepath,
time_step,
attribute_data.name,
attribute_data.data_start,
attribute_data.vldims,
attribute_data.data_type,
attribute.name,
attribute.data_start,
attribute.vldims,
attribute.data_type,
_use_compression);
grid->insert(getLightAttribute(
_hdf5filepath.filename(), time_step, attribute_data));
grid->insert(
getLightAttribute(_hdf5filepath.filename(), time_step, attribute));
}
auto gridcollection = _root->getGridCollection(0);
gridcollection->insert(grid);
_root->accept(_writer);
}
} // namespace MeshLib::IO
\ No newline at end of file
} // namespace MeshLib::IO
......@@ -47,7 +47,7 @@ public:
Xdmf3Writer(std::filesystem::path const& filepath,
Geometry const& geometry,
Topology const& topology,
std::vector<AttributeMeta> const& attributes,
std::vector<AttributeMeta> attributes,
int time_step);
/**
* \brief Write attribute data that has modified to previous time step or
......@@ -56,8 +56,7 @@ public:
* @param time_step number of the step (temporal collection)
* @param time time value of the current time_step
*/
void WriteStep(int time_step, double time);
void writeStep(int time_step, double time);
private:
boost::shared_ptr<XdmfGridCollection> _gridCollection;
......
......@@ -82,7 +82,7 @@ std::optional<AttributeMeta> transformAttribute(
std::pair<std::string, PropertyVectorBase*> const& property)
{
// lambda f : Transforms property to AttributeMeta, first parameter is
// semantic output because the boolean return type is used to allow kind of
// output parameter because the boolean return type is used to allow kind of
// pipe using || operator
auto f = [&](std::optional<AttributeMeta>& attribute_meta,
auto basic_type,
......@@ -191,7 +191,6 @@ std::optional<AttributeMeta> transformAttribute(
}
else
{
// attribute_meta = std:
return false;
}
......@@ -289,7 +288,7 @@ Topology transformTopology(MeshLib::Mesh const& mesh)
values.push_back(celltype->getNodesPerElement());
}
for (size_t i = 0; i < cell->getNumberOfNodes(); ++i)
for (std::size_t i = 0; i < cell->getNumberOfNodes(); ++i)
{
MeshLib::Node const* node = cell->getNode(i);
values.push_back(node->getID());
......
......@@ -17,7 +17,7 @@
#include "XdmfArrayType.hpp"
#include "hdf5.h"
unsigned short int const compression_factor = 9;
static unsigned short int const compression_factor = 9;
hid_t XdmfType2Hdf5Type(boost::shared_ptr<XdmfArrayType const> xdmf)
{
......@@ -58,7 +58,7 @@ int writeHDF5Step(std::filesystem::path const& filepath, int const step,
// C++API negative value is failure
hid_t file = H5Fopen(filepath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
std::string time_section = getTimeSection(step);
std::string const time_section = getTimeSection(step);
// Open or create Group
hid_t group_id = [](auto file, auto time_section) {
......@@ -110,9 +110,8 @@ std::pair<int, bool> writeHDF5Initial(
{
// Check if gzip compression is available and can be used for both
// compression and decompression.
htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
bool has_compression_lib = true;
if (!avail)
if (htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE); !avail)
{
WARN("gzip filter not available.\n");
has_compression_lib = false;
......@@ -148,7 +147,7 @@ std::pair<int, bool> writeHDF5Initial(
{
hid_t file = H5Fcreate(filepath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT);
std::string time_section = getTimeSection(step);
std::string const time_section = getTimeSection(step);
hid_t group_id = H5Gcreate2(file, time_section.c_str(), H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
......
......@@ -52,7 +52,7 @@ int writeMeshToFile(const MeshLib::Mesh& mesh,
// \TODO Errorhandling, Change data model into static and time depended,
// then is is not neccessary to give time step 0 a special treatment
// here
writer->WriteStep(0, 0);
writer->writeStep(0, 0);
return 0;
}
......
......@@ -229,10 +229,10 @@ struct Output::OutputFile
void Output::outputMeshXdmf(OutputFile const& output_file,
MeshLib::Mesh const& mesh,
const int timestep,
int const timestep,
double const t)
{
// ToDo Refactor to a dedicated VTKOutput and XdmfOutput
// \TODO (tm) Refactor to a dedicated VTKOutput and XdmfOutput
// The XdmfOutput will create on contruction the Xdmf3Writer
if (!_mesh_xdmf_writer)
{
......@@ -243,13 +243,13 @@ void Output::outputMeshXdmf(OutputFile const& output_file,
MeshLib::IO::transformTopology(mesh),
MeshLib::IO::transformAttributes(mesh), timestep));
}
_mesh_xdmf_writer->WriteStep(timestep, t);
_mesh_xdmf_writer->writeStep(timestep, t);
}
void Output::outputMesh(OutputFile const& output_file,
MeshLib::IO::PVDFile* const pvd_file,
MeshLib::Mesh const& mesh,
const int timestep,
int const timestep,
double const t) const
{
DBUG("output to {:s}", output_file.path);
......@@ -265,7 +265,7 @@ void Output::outputMesh(OutputFile const& output_file,
void Output::doOutputAlways(Process const& process,
const int process_id,
const int timestep,
int const timestep,
const double t,
std::vector<GlobalVector*> const& x)
{
......@@ -313,13 +313,12 @@ void Output::doOutputAlways(Process const& process,
}
else if (_output_file_type == ProcessLib::OutputType::xdmf)
{
OutputFile const file(
_output_directory, _output_file_type, _output_file_prefix, "",
mesh.getName(), timestep, t, _output_file_data_mode,
_output_file_compression);
OutputFile const file(_output_directory, _output_file_type,
_output_file_prefix, "", mesh.getName(),
timestep, t, _output_file_data_mode,
_output_file_compression);
outputMeshXdmf(file, mesh, timestep, t);
// this->XdmfOutputHandler = outputChangedMeshPartsToXdmf(mesh, t);
}
};
......@@ -382,7 +381,7 @@ void Output::doOutputAlways(Process const& process,
void Output::doOutput(Process const& process,
const int process_id,
const int timestep,
int const timestep,
const double t,
std::vector<GlobalVector*> const& x)
{
......@@ -393,13 +392,14 @@ void Output::doOutput(Process const& process,
#ifdef USE_INSITU
// Note: last time step may be output twice: here and in
// doOutputLastTimestep() which throws a warning.
InSituLib::CoProcess(process.getMesh(), t, timestep, false, _output_directory);
InSituLib::CoProcess(process.getMesh(), t, timestep, false,
_output_directory);
#endif
}
void Output::doOutputLastTimestep(Process const& process,
const int process_id,
const int timestep,
int const timestep,
const double t,
std::vector<GlobalVector*> const& x)
{
......@@ -408,13 +408,14 @@ void Output::doOutputLastTimestep(Process const& process,
doOutputAlways(process, process_id, timestep, t, x);
}
#ifdef USE_INSITU
InSituLib::CoProcess(process.getMesh(), t, timestep, true, _output_directory);
InSituLib::CoProcess(process.getMesh(), t, timestep, true,
_output_directory);
#endif
}
void Output::doOutputNonlinearIteration(Process const& process,
const int process_id,
const int timestep, const double t,
int const timestep, const double t,
std::vector<GlobalVector*> const& x,
const int iteration)
{
......@@ -454,8 +455,8 @@ void Output::doOutputNonlinearIteration(Process const& process,
std::string const output_file_name = OutputFile::constructFilename(
_output_file_type, _output_file_prefix,
"_ts_{:timestep}_nliter_{:time}", process.getMesh().getName(),
timestep, iteration);
"_ts_{:timestep}_nliter_{:time}", process.getMesh().getName(), timestep,
iteration);
std::string const output_file_path =
BaseLib::joinPaths(_output_directory, output_file_name);
......
......@@ -39,8 +39,8 @@ public:
public:
Output(std::string output_directory, OutputType const type,
std::string prefix, std::string suffix,
bool const compress_output, std::string const& data_mode,
std::string prefix, std::string suffix, bool const compress_output,
std::string const& data_mode,
bool const output_nonlinear_iteration_results,
std::vector<PairRepeatEachSteps> repeats_each_steps,
std::vector<double>&& fixed_output_times,
......@@ -54,47 +54,48 @@ public:
//! Writes output for the given \c process if it should be written in the
//! given \c timestep.
void doOutput(Process const& process, const int process_id,
const int timestep, const double t,
int const timestep, const double t,
std::vector<GlobalVector*> const& x);
//! Writes output for the given \c process if it has not been written yet.
//! This method is intended for doing output after the last timestep in
//! order to make sure that its results are written.
void doOutputLastTimestep(Process const& process, const int process_id,
const int timestep, const double t,
int const timestep, const double t,
std::vector<GlobalVector*> const& x);
//! Writes output for the given \c process.
//! This method will always write.
//! It is intended to write output in error handling routines.
void doOutputAlways(Process const& process, const int process_id,
const int timestep, const double t,
int const timestep, const double t,
std::vector<GlobalVector*> const& x);
//! Writes output for the given \c process.
//! To be used for debug output after an iteration of the nonlinear solver.
void doOutputNonlinearIteration(Process const& process,
const int process_id, const int timestep,
const int process_id, int const timestep,
const double t,
std::vector<GlobalVector*> const& x,
const int iteration);
std::vector<double> getFixedOutputTimes() {return _fixed_output_times;}
std::vector<double> getFixedOutputTimes() { return _fixed_output_times; }
private:
struct OutputFile;
void outputMesh(OutputFile const& output_file,
MeshLib::IO::PVDFile* const pvd_file,
MeshLib::Mesh const& mesh,
const int timestep,
double const t) const;
MeshLib::IO::PVDFile* const pvd_file,
MeshLib::Mesh const& mesh,
int const timestep,
double const t) const;
void outputMeshXdmf(OutputFile const& output_file,
MeshLib::Mesh const& mesh,
const int timestep,
int const timestep,
double const t);
private:
std::unique_ptr<MeshLib::IO::Xdmf3Writer>_mesh_xdmf_writer;
std::unique_ptr<MeshLib::IO::Xdmf3Writer> _mesh_xdmf_writer;
std::string const _output_directory;
OutputType const _output_file_type;
std::string const _output_file_prefix;
......
......@@ -270,8 +270,8 @@ void makeOutput(std::string const& file_name, MeshLib::Mesh const& mesh,
fegetenv(&fe_env);
fesetenv(FE_DFL_ENV); // Set default environment effectively disabling
// exceptions.
#endif //_WIN32
#endif //__APPLE__
#endif //_WIN32
#endif //__APPLE__
switch (file_type)
{
......@@ -289,7 +289,7 @@ void makeOutput(std::string const& file_name, MeshLib::Mesh const& mesh,
file_name, MeshLib::IO::transformGeometry(mesh),
MeshLib::IO::transformTopology(mesh),
MeshLib::IO::transformAttributes(mesh), time_step);
writer.WriteStep(time_step, time);
writer.writeStep(time_step, time);
}
}
......
Markdown is supported
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