Skip to content
Snippets Groups Projects
Commit 2d42f28e authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] Move output creation in own file.

Also move a single piece checking the output type being
VTK.
parent f86aadfb
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "CreateOutput.h"
#include <logog/include/logog.hpp>
#include <memory>
#include <tuple>
#include "BaseLib/ConfigTree.h"
#include "BaseLib/FileTools.h"
#include "Output.h"
namespace ProcessLib
{
std::unique_ptr<Output> createOutput(const BaseLib::ConfigTree& config,
std::string const& output_directory)
{
DBUG("Parse output configuration:");
//! \ogs_file_param{prj__time_loop__output__type}
config.checkConfigParameter("type", "VTK");
auto const prefix =
//! \ogs_file_param{prj__time_loop__output__prefix}
config.getConfigParameter<std::string>("prefix");
auto const compress_output =
//! \ogs_file_param{prj__time_loop__output__compress_output}
config.getConfigParameter("compress_output", true);
auto const data_mode =
//! \ogs_file_param{prj__time_loop__output__data_mode}
config.getConfigParameter<std::string>("data_mode", "Binary");
// Construction of output times
std::vector<Output::PairRepeatEachSteps> repeats_each_steps;
//! \ogs_file_param{prj__time_loop__output__timesteps}
if (auto const timesteps = config.getConfigSubtreeOptional("timesteps"))
{
//! \ogs_file_param{prj__time_loop__output__timesteps__pair}
for (auto pair : timesteps->getConfigSubtreeList("pair"))
{
//! \ogs_file_param{prj__time_loop__output__timesteps__pair__repeat}
auto repeat = pair.getConfigParameter<unsigned>("repeat");
//! \ogs_file_param{prj__time_loop__output__timesteps__pair__each_steps}
auto each_steps = pair.getConfigParameter<unsigned>("each_steps");
assert(repeat != 0 && each_steps != 0);
repeats_each_steps.emplace_back(repeat, each_steps);
}
if (repeats_each_steps.empty())
{
OGS_FATAL(
"You have not given any pair (<repeat/>, <each_steps/>) that "
"defines"
" at which timesteps output shall be written. Aborting.");
}
}
else
{
repeats_each_steps.emplace_back(1, 1);
}
bool const output_iteration_results =
//! \ogs_file_param{prj__time_loop__output__output_iteration_results}
config.getConfigParameter<bool>("output_iteration_results", false);
return std::make_unique<Output>(output_directory, prefix, compress_output,
data_mode, output_iteration_results,
std::move(repeats_each_steps));
}
} // namespace ProcessLib
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <memory>
#include <string>
namespace BaseLib
{
class ConfigTree;
}
namespace ProcessLib
{
class Process;
class Output;
} // namespace ProcessLib
namespace ProcessLib
{
std::unique_ptr<Output> createOutput(const BaseLib::ConfigTree& config,
const std::string& output_directory);
} // namespace ProcessLib
......@@ -72,63 +72,17 @@ namespace ProcessLib
{
Output::Output(std::string output_directory, std::string prefix,
bool const compress_output, std::string const& data_mode,
bool const output_nonlinear_iteration_results)
bool const output_nonlinear_iteration_results,
std::vector<PairRepeatEachSteps> repeats_each_steps)
: _output_directory(std::move(output_directory)),
_output_file_prefix(std::move(prefix)),
_output_file_compression(compress_output),
_output_file_data_mode(convertVtkDataMode(data_mode)),
_output_nonlinear_iteration_results(output_nonlinear_iteration_results)
_output_nonlinear_iteration_results(output_nonlinear_iteration_results),
_repeats_each_steps(std::move(repeats_each_steps))
{
}
std::unique_ptr<Output> Output::newInstance(const BaseLib::ConfigTree& config,
std::string const& output_directory)
{
auto const output_iteration_results =
//! \ogs_file_param{prj__time_loop__output__output_iteration_results}
config.getConfigParameterOptional<bool>("output_iteration_results");
std::unique_ptr<Output> out{new Output{
output_directory,
//! \ogs_file_param{prj__time_loop__output__prefix}
config.getConfigParameter<std::string>("prefix"),
//! \ogs_file_param{prj__time_loop__output__compress_output}
config.getConfigParameter("compress_output", true),
//! \ogs_file_param{prj__time_loop__output__data_mode}
config.getConfigParameter<std::string>("data_mode", "Binary"),
output_iteration_results ? *output_iteration_results : false}};
//! \ogs_file_param{prj__time_loop__output__timesteps}
if (auto const timesteps = config.getConfigSubtreeOptional("timesteps"))
{
//! \ogs_file_param{prj__time_loop__output__timesteps__pair}
for (auto pair : timesteps->getConfigSubtreeList("pair"))
{
//! \ogs_file_param{prj__time_loop__output__timesteps__pair__repeat}
auto repeat = pair.getConfigParameter<unsigned>("repeat");
//! \ogs_file_param{prj__time_loop__output__timesteps__pair__each_steps}
auto each_steps = pair.getConfigParameter<unsigned>("each_steps");
assert(repeat != 0 && each_steps != 0);
out->_repeats_each_steps.emplace_back(repeat, each_steps);
}
if (out->_repeats_each_steps.empty())
{
OGS_FATAL(
"You have not given any pair (<repeat/>, <each_steps/>) that "
"defines"
" at which timesteps output shall be written. Aborting.");
}
}
else
{
out->_repeats_each_steps.emplace_back(1, 1);
}
return out;
}
void Output::addProcess(ProcessLib::Process const& process,
const int process_id)
{
......
......@@ -12,7 +12,6 @@
#include <map>
#include <utility>
#include "BaseLib/ConfigTree.h"
#include "MeshLib/IO/VtkIO/PVDFile.h"
#include "ProcessOutput.h"
......@@ -28,8 +27,22 @@ class Process;
class Output
{
public:
static std::unique_ptr<Output> newInstance(
const BaseLib::ConfigTree& config, const std::string& output_directory);
struct PairRepeatEachSteps
{
explicit PairRepeatEachSteps(unsigned c, unsigned e)
: repeat(c), each_steps(e)
{
}
const unsigned repeat; //!< Apply \c each_steps \c repeat times.
const unsigned each_steps; //!< Do output every \c each_steps timestep.
};
public:
Output(std::string output_directory, std::string prefix,
bool const compress_output, std::string const& data_mode,
bool const output_nonlinear_iteration_results,
std::vector<PairRepeatEachSteps> repeats_each_steps);
//! TODO doc. Opens a PVD file for each process.
void addProcess(ProcessLib::Process const& process, const int process_id);
......@@ -64,17 +77,6 @@ public:
GlobalVector const& x,
const unsigned iteration);
struct PairRepeatEachSteps
{
explicit PairRepeatEachSteps(unsigned c, unsigned e)
: repeat(c), each_steps(e)
{
}
const unsigned repeat; //!< Apply \c each_steps \c repeat times.
const unsigned each_steps; //!< Do output every \c each_steps timestep.
};
private:
struct SingleProcessData
{
......@@ -83,10 +85,6 @@ private:
MeshLib::IO::PVDFile pvd_file;
};
Output(std::string output_directory, std::string prefix,
bool const compress_output, std::string const& data_mode,
bool const output_nonlinear_iteration_results);
std::string const _output_directory;
std::string const _output_file_prefix;
......
......@@ -17,20 +17,11 @@
#include "NumLib/ODESolver/TimeDiscretizationBuilder.h"
#include "NumLib/ODESolver/TimeDiscretizedODESystem.h"
#include "NumLib/TimeStepping/CreateTimeStepper.h"
#include "ProcessLib/Output/CreateOutput.h"
#include "ProcessLib/Output/CreateProcessOutput.h"
#include "CoupledSolutionsForStaggeredScheme.h"
std::unique_ptr<ProcessLib::Output> createOutput(
BaseLib::ConfigTree const& config, std::string const& output_directory)
{
//! \ogs_file_param{prj__time_loop__output__type}
config.checkConfigParameter("type", "VTK");
DBUG("Parse output configuration:");
return ProcessLib::Output::newInstance(config, output_directory);
}
//! Sets the EquationSystem for the given nonlinear solver,
//! which is Picard or Newton depending on the NLTag.
template <NumLib::NonlinearSolverTag NLTag>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment