Skip to content
Snippets Groups Projects
Commit fdeb9778 authored by Soeren Peters's avatar Soeren Peters
Browse files

- refactoring

parent 848dd535
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
template<typename Grid>
MultipleGridBuilder<Grid>::MultipleGridBuilder()
{
}
template<typename Grid>
......@@ -17,20 +18,16 @@ template <typename Grid>
void MultipleGridBuilder<Grid>::addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta)
{
auto grid = Grid::makeShared(startX, startY, startZ, endX, endY, endZ, delta);
grids.push_back(grid);
addGridToList(grid);
}
template <typename Grid>
void MultipleGridBuilder<Grid>::addGrid(real startX, real startY, real startZ, real endX, real endY, real endZ)
{
checkIfCoarseGridIsMissing();
auto grid = makeGrid(startX, startY, startZ, endX, endY, endZ);
checkIfGridIsInCoarseGrid(grid);
grids.push_back(grid);
addGridToList(grid);
}
template <typename Grid>
......@@ -58,28 +55,27 @@ real MultipleGridBuilder<Grid>::calculateDelta() const
}
template <typename Grid>
std::array<real, 6> MultipleGridBuilder<Grid>::getStaggeredCoordinates(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta) const
std::array<real, 6> MultipleGridBuilder<Grid>::getStaggeredCoordinates(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta)
{
const real offset = delta * 0.5;
const real startXStaggered = getStaggered(startX, offset);
const real startYStaggered = getStaggered(startY, offset);
const real startZStaggered = getStaggered(startZ, offset);
const real startXStaggered = getStaggeredCoordinate(startX, offset);
const real startYStaggered = getStaggeredCoordinate(startY, offset);
const real startZStaggered = getStaggeredCoordinate(startZ, offset);
const real endXStaggered = getStaggered(endX, -offset);
const real endYStaggered = getStaggered(endY, -offset);
const real endZStaggered = getStaggered(endZ, -offset);
const real endXStaggered = getStaggeredCoordinate(endX, -offset);
const real endYStaggered = getStaggeredCoordinate(endY, -offset);
const real endZStaggered = getStaggeredCoordinate(endZ, -offset);
return std::array<real, 6>{startXStaggered, startYStaggered, startZStaggered, endXStaggered, endYStaggered, endZStaggered};
}
template <typename Grid>
real MultipleGridBuilder<Grid>::getStaggered(real value, real offset) const
real MultipleGridBuilder<Grid>::getStaggeredCoordinate(real value, real offset)
{
return value + offset;
}
template <typename Grid>
void MultipleGridBuilder<Grid>::checkIfGridIsInCoarseGrid(SPtr<Grid> grid) const
{
......@@ -149,5 +145,10 @@ real MultipleGridBuilder<Grid>::getEndZ(uint level) const
return grids[level]->endZ;
}
template <typename Grid>
void MultipleGridBuilder<Grid>::addGridToList(SPtr<Grid> grid)
{
grids.push_back(grid);
}
template class MultipleGridBuilder<GridDummy>;
......@@ -4,11 +4,9 @@
#include "GridGenerator/global.h"
#include <vector>
#include <string>
#include <memory>
#include <array>
#include <exception>
#include "grid/GridMocks.h"
class MultipleGridBuilderException : public std::exception
{
......@@ -60,6 +58,7 @@ public:
VF_PUBLIC void addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta);
VF_PUBLIC void addGrid(real startX, real startY, real startZ, real endX, real endY, real endZ);
VF_PUBLIC uint getNumberOfLevels() const;
VF_PUBLIC real getDelta(int level) const;
......@@ -72,19 +71,17 @@ public:
VF_PUBLIC real getEndZ(uint level) const;
private:
void addGridToList(SPtr<Grid> grid);
bool isInsideOfGrids(SPtr<Grid> grid) const;
real calculateDelta() const;
void checkIfCoarseGridIsMissing() const;
void checkIfGridIsInCoarseGrid(SPtr<Grid> grid) const;
SPtr<Grid> makeGrid(real startX, real startY, real startZ, real endX, real endY, real endZ) const;
real getStaggered(real value, real offset) const;
std::array<real, 6> getStaggeredCoordinates(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta) const;
static std::array<real, 6> getStaggeredCoordinates(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta);
static real getStaggeredCoordinate(real value, real offset);
std::vector<SPtr<Grid> > grids;
};
#endif
......@@ -64,8 +64,6 @@ TEST(MultipleGridBuilderTest, getInvalidLevel_shouldThrowException)
}
void expectStartCoordinatesAreStaggered(const real givenStartX, const real givenStartY, const real givenStartZ, const real staggeredOffset, SPtr<MultipleGridBuilder<GridDummy> > gridBuilder, const uint level)
{
const real expectedStartX = givenStartX + staggeredOffset;
......@@ -105,7 +103,6 @@ TEST(MultipleGridBuilderTest, addedsecondGrid_shouldBeStaggered)
const real givenStartX = 0.0;
const real givenStartY = 1.0;
const real givenStartZ = 2.0;
const real givenEndX = 10.0;
const real givenEndY = 11.0;
const real givenEndZ = 12.0;
......
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