Alsvinn  0.5.3
The fast FVM simulator with UQ support
Simulator.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
18 #include "alsfvm/io/Writer.hpp"
24 #include "alsfvm/grid/Grid.hpp"
30 #include <vector>
31 #include <memory>
32 
33 #ifdef ALSVINN_USE_MPI
35 #endif
36 
37 namespace alsfvm {
38 namespace simulator {
39 
52 
54 class Simulator : public AbstractSimulator {
55 public:
72  Simulator(const SimulatorParameters& simulatorParameters,
73  alsfvm::shared_ptr<grid::Grid>& grid,
74  volume::VolumeFactory& volumeFactory,
75  integrator::IntegratorFactory& integratorFactory,
76  boundary::BoundaryFactory& boundaryFactory,
77  numflux::NumericalFluxFactory& numericalFluxFactory,
78  equation::CellComputerFactory& cellComputerFactory,
79  alsfvm::shared_ptr<memory::MemoryFactory>& memoryFactory,
80  real endTime,
81  alsfvm::shared_ptr<DeviceConfiguration>& deviceConfiguration,
82  std::string& equationName,
83  alsfvm::shared_ptr<alsfvm::diffusion::DiffusionOperator> diffusionOperator,
84  const std::string& name
85  );
86 
87  ~Simulator();
88 
89 
90 
94  bool atEnd() override;
95 
99  void performStep() override;
100 
104  void callWriters() override;
105 
110  void addWriter(alsfvm::shared_ptr<io::Writer> writer) override;
111 
123  void addTimestepAdjuster(alsfvm::shared_ptr<integrator::TimestepAdjuster>&
124  adjuster) override;
125 
129  real getCurrentTime() const override;
130 
134  real getEndTime() const override;
135 
144  void setSimulationState(const volume::Volume& conservedVolume);
145 
146  std::string getPlatformName() const;
147 
148  std::string getEquationName() const;
149 
150  void setInitialValue(alsfvm::shared_ptr<init::InitialData>& initialData);
151 
152  const std::shared_ptr<grid::Grid>& getGrid() const override;
153  std::shared_ptr<grid::Grid>& getGrid() override;
154 
155  void finalize() override;
156 
157 #ifdef ALSVINN_USE_MPI
158  void setCellExchanger(mpi::CellExchangerPtr value);
159 #endif
160 
161  std::string getName() const;
162 
163 private:
164 
165 
166  void checkConstraints();
167  void incrementSolution();
168  void doCellExchange(volume::Volume& volume);
169 
170  SimulatorParameters simulatorParameters;
171  volume::VolumeFactory volumeFactory;
172  TimestepInformation timestepInformation;
173  alsfvm::shared_ptr<grid::Grid> grid;
174  alsfvm::shared_ptr<numflux::NumericalFlux> numericalFlux;
175  alsfvm::shared_ptr<integrator::System> system;
176  alsfvm::shared_ptr<integrator::Integrator> integrator;
177  alsfvm::shared_ptr<boundary::Boundary> boundary;
178  std::vector<alsfvm::shared_ptr<volume::Volume> > conservedVolumes;
179  alsfvm::shared_ptr<equation::CellComputer> cellComputer;
180 
181  alsfvm::shared_ptr<alsfvm::diffusion::DiffusionOperator> diffusionOperator;
182  std::vector<alsfvm::shared_ptr<io::Writer> > writers;
183  alsfvm::shared_ptr<init::InitialData> initialData;
184 
185  const real cflNumber;
186  const real endTime;
187  const std::string equationName;
188  const std::string platformName;
189  alsfvm::shared_ptr<DeviceConfiguration> deviceConfiguration;
190 
191 #ifdef ALSVINN_USE_MPI
192  mpi::CellExchangerPtr cellExchanger;
193 #endif
194 
195  const std::string name;
196 };
197 } // namespace alsfvm
198 } // namespace simulator
std::string getName() const
Definition: Simulator.cpp:219
void callWriters() override
Definition: Simulator.cpp:172
alsfvm::shared_ptr< memory::MemoryFactory > memoryFactory
Definition: VolumeFactory.cpp:86
void addTimestepAdjuster(alsfvm::shared_ptr< integrator::TimestepAdjuster > &adjuster) override
Definition: Simulator.cpp:91
const std::shared_ptr< grid::Grid > & getGrid() const override
Gets the current grid that is being used.
Definition: Simulator.cpp:164
alsfvm::shared_ptr< CellExchanger > CellExchangerPtr
Definition: CellExchanger.hpp:43
bool atEnd() override
Definition: Simulator.cpp:77
Definition: VolumeFactory.hpp:29
The Volume class represents a volume (a collection of cells with values for each cell (eg...
Definition: Volume.hpp:30
Definition: NumericalFluxFactory.hpp:27
void finalize() override
Finalizes the computation, should be called at the end.
Definition: Simulator.cpp:70
void setSimulationState(const volume::Volume &conservedVolume)
Definition: Simulator.cpp:104
double real
Definition: types.hpp:65
real getEndTime() const override
Definition: Simulator.cpp:100
The Simulator class contains all the neccesary tools for running the whole simulation.
Definition: Simulator.hpp:54
~Simulator()
Definition: Simulator.cpp:66
Simulator(const SimulatorParameters &simulatorParameters, alsfvm::shared_ptr< grid::Grid > &grid, volume::VolumeFactory &volumeFactory, integrator::IntegratorFactory &integratorFactory, boundary::BoundaryFactory &boundaryFactory, numflux::NumericalFluxFactory &numericalFluxFactory, equation::CellComputerFactory &cellComputerFactory, alsfvm::shared_ptr< memory::MemoryFactory > &memoryFactory, real endTime, alsfvm::shared_ptr< DeviceConfiguration > &deviceConfiguration, std::string &equationName, alsfvm::shared_ptr< alsfvm::diffusion::DiffusionOperator > diffusionOperator, const std::string &name)
Simulator.
Definition: Simulator.cpp:26
real getCurrentTime() const override
Definition: Simulator.cpp:96
void performStep() override
Definition: Simulator.cpp:81
Definition: IntegratorFactory.hpp:24
void setInitialValue(alsfvm::shared_ptr< init::InitialData > &initialData)
Definition: Simulator.cpp:117
std::string getEquationName() const
Definition: Simulator.cpp:113
The CellComputerFactory class is used to create new cell computers.
Definition: CellComputerFactory.hpp:28
Definition: AbstractSimulator.hpp:36
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
std::string getPlatformName() const
Definition: Simulator.cpp:109
Definition: BoundaryFactory.hpp:23
Definition: SimulatorParameters.hpp:22
void addWriter(alsfvm::shared_ptr< io::Writer > writer) override
addWriter adds a writer, this will be called every time callWriter is called
Definition: Simulator.cpp:87
Definition: TimestepInformation.hpp:22