Alsvinn  0.5.3
The fast FVM simulator with UQ support
Volume.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
17 #include "alsfvm/types.hpp"
19 #include "alsfvm/memory/Memory.hpp"
20 #include <string>
21 #include <vector>
22 
23 namespace alsfvm {
24 namespace volume {
30 class Volume : public std::enable_shared_from_this<Volume> {
31 public:
49  Volume(const std::vector<std::string>& variableNames,
50  alsfvm::shared_ptr<memory::MemoryFactory> memoryFactory,
51  size_t nx, size_t ny, size_t nz,
52  size_t numberOfGhostCells = 0);
53 
58  Volume(Volume& volume, const std::vector<size_t>& components,
59  const std::vector<std::string>& variableNames);
60 
61  // We need a virtual destructor in case we want to inherit from this
62  virtual ~Volume();
63 
68  virtual size_t getNumberOfVariables() const;
69 
71  virtual ivec3 getSize() const;
72 
74  virtual ivec3 getInnerSize() const;
75 
77  virtual ivec3 getNumberOfGhostCells() const;
85  virtual alsfvm::shared_ptr<memory::Memory<real> >&
86  getScalarMemoryArea(size_t index);
87 
95  virtual alsfvm::shared_ptr<const memory::Memory<real> >
96  getScalarMemoryArea(size_t index) const;
97 
105  virtual alsfvm::shared_ptr<memory::Memory<real> >&
106  getScalarMemoryArea(const std::string& name);
107 
115  virtual alsfvm::shared_ptr<const memory::Memory<real> >
116  getScalarMemoryArea(const std::string& name) const;
117 
125  virtual alsfvm::shared_ptr<const memory::Memory<real> >
126  operator[](size_t index) const;
127 
128 
129 
130 
138  virtual alsfvm::shared_ptr<memory::Memory<real> >
139  operator[](size_t index);
140 
141 
149  virtual const memory::Memory<real>&
150  operator[](const std::string& name) const;
151 
152 
153 
154 
162  virtual memory::Memory<real>&
163  operator[](const std::string& name);
164 
165 
166 
172  virtual size_t getIndexFromName(const std::string& name) const ;
173 
180  virtual std::string getName(size_t index) const;
181 
185  virtual Volume& operator+=(const Volume& other);
186 
187 
191  virtual Volume& operator*=(real scalar);
192 
196  virtual size_t getNumberOfXCells() const;
197 
201  virtual size_t getNumberOfYCells() const;
202 
206  virtual size_t getNumberOfZCells() const;
207 
211  virtual void makeZero();
212 
217  virtual size_t getNumberOfXGhostCells() const;
218 
223  virtual size_t getNumberOfYGhostCells() const;
224 
229  virtual size_t getNumberOfZGhostCells() const;
230 
234  virtual size_t getTotalNumberOfXCells() const;
235 
239  virtual size_t getTotalNumberOfYCells() const;
240 
244  virtual size_t getTotalNumberOfZCells() const;
245 
253  virtual void copyInternalCells(size_t memoryAreaIndex, real* output,
254  size_t outputSize) const;
255 
259  virtual void copyTo(volume::Volume& other) const;
260 
266  virtual void setVolume(const volume::Volume& other);
267 
269  virtual size_t getDimensions() const;
270 
271 
276  void addLinearCombination(real a1, real a2, const Volume& v2, real a3,
277  const Volume& v3, real a4, const Volume& v4, real a5, const Volume& v5);
278 
279 
287  virtual ivec3 getTotalDimensions() const;
288 
289 
296  virtual void addPower(const Volume& other, real power);
297 
304  virtual void addPower(const Volume& other, real power, real factor);
305 
312  virtual void subtractPower(const Volume& other, real power);
313 
314 
316  std::shared_ptr<volume::Volume> makeInstance() const;
317 
320  std::shared_ptr<volume::Volume> makeInstance(size_t nx, size_t ny, size_t nz,
321  const std::string& platform = "default") const;
322 
325  std::shared_ptr<volume::Volume> getCopyOnCPU();
326 
328  bool hasVariable(const std::string& variableName) const;
329 
330 private:
331  const std::vector<std::string> variableNames;
332  alsfvm::shared_ptr<memory::MemoryFactory> memoryFactory;
333  std::vector<alsfvm::shared_ptr<memory::Memory<real> > >
334  memoryAreas;
335  size_t nx;
336  size_t ny;
337  size_t nz;
338 
339 
340  size_t numberOfXGhostCells;
341  size_t numberOfYGhostCells;
342  size_t numberOfZGhostCells;
343 };
344 
345 typedef alsfvm::shared_ptr<Volume> VolumePointer;
346 }
347 }
virtual void setVolume(const volume::Volume &other)
setVolume sets the contents of this volume to the contenst of the other volume
Definition: Volume.cpp:307
virtual size_t getIndexFromName(const std::string &name) const
getIndexFromName returns the given index from the name
Definition: Volume.cpp:151
Volume(const std::vector< std::string > &variableNames, alsfvm::shared_ptr< memory::MemoryFactory > memoryFactory, size_t nx, size_t ny, size_t nz, size_t numberOfGhostCells=0)
Volume creates a new volume object.
Definition: Volume.cpp:44
virtual void addPower(const Volume &other, real power)
Definition: Volume.cpp:378
std::shared_ptr< volume::Volume > getCopyOnCPU()
Definition: Volume.cpp:424
virtual void copyInternalCells(size_t memoryAreaIndex, real *output, size_t outputSize) const
Definition: Volume.cpp:219
virtual size_t getNumberOfYCells() const
Definition: Volume.cpp:208
virtual alsfvm::shared_ptr< memory::Memory< real > > & getScalarMemoryArea(size_t index)
getScalarMemoryArea gets the scalar memory area (real)
Definition: Volume.cpp:107
The Volume class represents a volume (a collection of cells with values for each cell (eg...
Definition: Volume.hpp:30
virtual size_t getNumberOfVariables() const
getNumberOfVariables gets the number of variables used
Definition: Volume.cpp:83
virtual ivec3 getSize() const
Returns the size in each dimension.
Definition: Volume.cpp:87
virtual size_t getTotalNumberOfYCells() const
Definition: Volume.cpp:268
virtual void copyTo(volume::Volume &other) const
Definition: Volume.cpp:292
double real
Definition: types.hpp:65
virtual ~Volume()
Definition: Volume.cpp:79
virtual size_t getTotalNumberOfZCells() const
Definition: Volume.cpp:275
virtual size_t getNumberOfZCells() const
Definition: Volume.cpp:215
Definition: Memory.hpp:28
std::shared_ptr< volume::Volume > makeInstance() const
Makes a volume with the same memory areas and the same sizes.
Definition: Volume.cpp:402
virtual size_t getNumberOfXGhostCells() const
Definition: Volume.cpp:238
alsfvm::shared_ptr< Volume > VolumePointer
Definition: Volume.hpp:345
std::string name
Definition: EquationParameterFactory.cpp:39
virtual size_t getNumberOfZGhostCells() const
Definition: Volume.cpp:254
virtual ivec3 getTotalDimensions() const
Definition: Volume.cpp:372
virtual Volume & operator*=(real scalar)
Definition: Volume.cpp:190
virtual size_t getNumberOfYGhostCells() const
Definition: Volume.cpp:246
virtual size_t getNumberOfXCells() const
Definition: Volume.cpp:201
size_t numberOfGhostCells
Definition: VolumeFactory.cpp:90
virtual size_t getDimensions() const
Gets the number of space dimensions.
Definition: Volume.cpp:279
virtual std::string getName(size_t index) const
Definition: Volume.cpp:170
virtual ivec3 getNumberOfGhostCells() const
Returns the number of ghostcells in each dimension.
Definition: Volume.cpp:96
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
virtual Volume & operator+=(const Volume &other)
Definition: Volume.cpp:178
virtual ivec3 getInnerSize() const
Gets the size without ghost cells in each dimension.
Definition: Volume.cpp:92
virtual size_t getTotalNumberOfXCells() const
Definition: Volume.cpp:261
void addLinearCombination(real a1, real a2, const Volume &v2, real a3, const Volume &v3, real a4, const Volume &v4, real a5, const Volume &v5)
Definition: Volume.cpp:359
virtual alsfvm::shared_ptr< const memory::Memory< real > > operator[](size_t index) const
gets the scalar memory area (real)
Definition: Volume.cpp:335
bool hasVariable(const std::string &variableName) const
Returns true if the volume has the given variable, false otherwise.
Definition: Volume.cpp:443
virtual void makeZero()
makeZero sets every element of the volume to zero (0).
Definition: Volume.cpp:228
virtual void subtractPower(const Volume &other, real power)
Definition: Volume.cpp:394