diff --git a/ProcessLib/Output/CreateOutput.cpp b/ProcessLib/Output/CreateOutput.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88ee97252592e5941e50cb6e53a75f39e80093bd --- /dev/null +++ b/ProcessLib/Output/CreateOutput.cpp @@ -0,0 +1,83 @@ +/** + * \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 diff --git a/ProcessLib/Output/CreateOutput.h b/ProcessLib/Output/CreateOutput.h new file mode 100644 index 0000000000000000000000000000000000000000..34847b5e4ed9420531657a295d66d1348793487e --- /dev/null +++ b/ProcessLib/Output/CreateOutput.h @@ -0,0 +1,31 @@ +/** + * \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 diff --git a/ProcessLib/Output/Output.cpp b/ProcessLib/Output/Output.cpp index 8f0822dc22e5c34401a0657e8a61f47d0e740777..f572d0d635e66235ff7acc5b1fbb75912932fb6c 100644 --- a/ProcessLib/Output/Output.cpp +++ b/ProcessLib/Output/Output.cpp @@ -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) { diff --git a/ProcessLib/Output/Output.h b/ProcessLib/Output/Output.h index fafab45047df766c4cc72f67443bdfc77c4e0c2d..ff015a13c5bfe6c97409aec3c24b5dbf177e1ff4 100644 --- a/ProcessLib/Output/Output.h +++ b/ProcessLib/Output/Output.h @@ -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; diff --git a/ProcessLib/UncoupledProcessesTimeLoop.cpp b/ProcessLib/UncoupledProcessesTimeLoop.cpp index 741fcf27262eaa519d375f533e6717c464a09c8b..6532c3d748082ebff941dae336faceee7b111e30 100644 --- a/ProcessLib/UncoupledProcessesTimeLoop.cpp +++ b/ProcessLib/UncoupledProcessesTimeLoop.cpp @@ -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>