/var/opm/opm-verteq/opm/verteq/SimulatorOutput.hpp

Create an output writer that is coupled to a simulator capable of reading Eclipse deck files. Output will be written only when specified in the deck file.

Note
This class is a template since there is no fixed interface for simulators, only an implied type class of common method signatures.
// configuration
ParameterGroup params (argc, argv, false);
// input file
auto deck = make_shared <const Deck> ( ... );
const GridManager manager (*parser);
auto grid = share_obj (*manager.c_grid ());
// timestep ends up here
auto timer = make_shared <SimulatorTimer> ();
// state ends up here
auto state = make_shared <TwophaseState> ();
auto wellState = make_shared <WellState> ();
// set up simulation
auto timeMap = make_shared <const TimeMap> (deck);
auto sim = make_shared <SimulatorIncompTwophase> (params, *grid, ... );
// use this to dump state to disk
auto output = make_shared <SimulatorOutput> (
params, deck, timeMap, grid, timer, state, wellState, sim);
// start simulation
sim.run (timer, state, ... )
/*
Copyright (c) 2013 Uni Research AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_SIMULATOR_OUTPUT_HPP
#define OPM_SIMULATOR_OUTPUT_HPP
// need complete def. of this since we use it in template
#include <opm/core/utility/Event.hpp>
#include <opm/core/utility/share_obj.hpp>
#include <memory> // unique_ptr, shared_ptr
#include <vector>
struct UnstructuredGrid;
namespace Opm {
// forward definitions
class Deck;
class EclipseState;
class OutputWriter;
namespace parameter { class ParameterGroup; }
class SimulationDataContainer;
class SimulatorTimer;
class TimeMap;
class WellState;
struct PhaseUsage;
class SimulatorOutputBase {
protected:
SimulatorOutputBase (const parameter::ParameterGroup& p,
std::shared_ptr <const EclipseState> eclipseState,
const Opm::PhaseUsage &phaseUsage,
std::shared_ptr <const UnstructuredGrid> grid,
std::shared_ptr <const SimulatorTimer> timer,
std::shared_ptr <const SimulationDataContainer> state,
std::shared_ptr <const WellState> wellState);
operator std::function <void ()> ();
std::shared_ptr <const SimulatorTimer> timer_;
std::shared_ptr <const TimeMap> timeMap_;
std::shared_ptr <const SimulationDataContainer> reservoirState_;
std::shared_ptr <const WellState> wellState_;
std::unique_ptr <OutputWriter> writer_;
virtual void writeOutput ();
virtual void sync ();
private:
std::vector <double>::size_type next_;
std::vector <double> times_;
};
template <typename Simulator>
struct SimulatorOutput : public SimulatorOutputBase {
SimulatorOutput (const parameter::ParameterGroup& params,
std::shared_ptr <const EclipseState> eclipseState,
const Opm::PhaseUsage &phaseUsage,
std::shared_ptr <const UnstructuredGrid> grid,
std::shared_ptr <const SimulatorTimer> timer,
std::shared_ptr <const SimulationDataContainer> state,
std::shared_ptr <const WellState> wellState,
std::shared_ptr <Simulator> sim)
// send all other parameters to base class
: SimulatorOutputBase (params, eclipseState, phaseUsage,
grid, timer, state, wellState)
// store reference to simulator in derived class
, sim_ (sim) {
// connect simulation with output writer
sim->timestep_completed ().add (*this);
}
SimulatorOutput (const parameter::ParameterGroup& params,
const EclipseState& eclipseState,
const Opm::PhaseUsage &phaseUsage,
const UnstructuredGrid& grid,
const SimulatorTimer& timer,
const SimulationDataContainer& state,
const WellState& wellState,
Simulator& sim)
// send all other parameters to base class
share_obj (eclipseState),
phaseUsage,
share_obj (grid),
share_obj (timer),
share_obj (state),
share_obj (wellState))
// store reference to simulator in derived class
, sim_ (share_obj (sim)) {
// connect simulation with output writer
sim_->timestep_completed ().add (*this);
}
protected:
// forward this request to the simulator
virtual void sync () { sim_->sync (); }
private:
std::shared_ptr <Simulator> sim_;
};
}
#endif /* OPM_SIMULATOR_OUTPUT_HPP */
std::unique_ptr< OutputWriter > writer_
Created locally and destructed together with us.
Definition: SimulatorOutput.hpp:88
SimulatorOutputBase(const parameter::ParameterGroup &p, std::shared_ptr< const EclipseState > eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr< const UnstructuredGrid > grid, std::shared_ptr< const SimulatorTimer > timer, std::shared_ptr< const SimulationDataContainer > state, std::shared_ptr< const WellState > wellState)
std::shared_ptr< const SimulationDataContainer > reservoirState_
Definition: SimulatorOutput.hpp:84
std::shared_ptr< const SimulatorTimer > timer_
Just hold a reference to these objects that are owned elsewhere.
Definition: SimulatorOutput.hpp:82
std::shared_ptr< const WellState > wellState_
Definition: SimulatorOutput.hpp:85
virtual void sync()
Make sure that the simulator state is up to date before writing.
std::shared_ptr< const TimeMap > timeMap_
Definition: SimulatorOutput.hpp:83
virtual void writeOutput()
Call the writers that were created based on the parameters.
Definition: opmfwd.hpp:15
SimulatorOutput(const parameter::ParameterGroup &params, std::shared_ptr< const EclipseState > eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr< const UnstructuredGrid > grid, std::shared_ptr< const SimulatorTimer > timer, std::shared_ptr< const SimulationDataContainer > state, std::shared_ptr< const WellState > wellState, std::shared_ptr< Simulator > sim)
Definition: SimulatorOutput.hpp:148
virtual void sync()
Make sure that the simulator state is up to date before writing.
Definition: SimulatorOutput.hpp:197