Skip to content
Snippets Groups Projects
Commit 09982954 authored by Anna Wellmann's avatar Anna Wellmann
Browse files

Add Parameters for rotating grid and function for coordinate transformation

parent c8ae3832
No related branches found
No related tags found
1 merge request!307[GPU] Add a cylinder geometry
......@@ -66,6 +66,7 @@
#include "VirtualFluids_GPU/Output/FileWriter.h"
#include "VirtualFluids_GPU/Output/NeighborDebugWriter.h"
#include "VirtualFluids_GPU/Parameter/Parameter.h"
#include "VirtualFluids_GPU/Parameter/ParameterRotatingGrid.h"
//////////////////////////////////////////////////////////////////////////
......@@ -90,8 +91,8 @@ int main()
const real velocityLB = 0.05; // LB units
const uint nx = 64;
const uint timeStepOut = 10000;
const uint timeStepEnd = 10000;
const uint timeStepOut = 1;
const uint timeStepEnd = 1;
//////////////////////////////////////////////////////////////////////////
// compute parameters in lattice units
......@@ -109,8 +110,8 @@ int main()
gridBuilder->addCoarseGrid(-1.5 * L, -0.5 * L, -0.5 * L, 1.5 * L, 0.5 * L, 0.5 * L, dx);
if (rotOrInt == Rot) gridBuilder->addGridRotatingGrid(std::make_shared<Cylinder>(0.0, 0.0, 0.0, 0.3 * L, 1. * L, Cylinder::RotationalAxis::x));
if (rotOrInt == Int) gridBuilder->addGrid(std::make_shared<Cylinder>(0.0, 0.0, 0.0, 0.3 * L, 1. * L, Cylinder::RotationalAxis::x), 1);
if (rotOrInt == Rot) gridBuilder->addGridRotatingGrid(std::make_shared<Cylinder>(0.0, 0.0, 0.0, 0.3 * L, 1. * L, Axis::x));
if (rotOrInt == Int) gridBuilder->addGrid(std::make_shared<Cylinder>(0.0, 0.0, 0.0, 0.3 * L, 1. * L, Axis::x), 1);
GridScalingFactory scalingFactory = GridScalingFactory();
scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleCompressible);
......@@ -200,9 +201,11 @@ int main()
Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, &scalingFactory);
const std::string gridName = rotOrInt == Rot ? "rot_grid" : "grid";
gridBuilder->writeGridsToVtk(para->getOutputPath() + gridName);
// gridBuilder->writeGridsToVtk(para->getOutputPath() + gridName);
// NeighborDebugWriter::writeNeighborLinkLinesDebug(para.get());
SPtr<ParameterRotatingGrid> paraRot = para->getRotatingGridParameter();
paraRot->transformNestedToBase({para->getParH(1)->coordinateX, para->getParH(1)->coordinateY, para->getParH(1)->coordinateZ});
sim.run();
} catch (const spdlog::spdlog_ex &ex) {
......
#include "GridGenerator.h"
#include <basics/geometry3d/Axis.h>
#include "LBM/LB.h"
#include "Parameter/Parameter.h"
#include "GridGenerator/grid/GridBuilder/GridBuilder.h"
#include "GridGenerator/grid/Grid.h"
#include "GridGenerator/geometries/Object.h"
#include "GPU/CudaMemoryManager.h"
#include "Parameter/CudaStreamManager.h"
#include "IndexRearrangementForStreams.h"
......@@ -10,6 +13,7 @@
#include <iostream>
#include <algorithm>
#include "Parameter/ParameterRotatingGrid.h"
#include "utilities/math/Math.h"
#include "Output/QDebugWriter.hpp"
#include "GridGenerator/TransientBCSetter/TransientBCSetter.h"
......@@ -94,6 +98,7 @@ void GridGenerator::allocArrays_CoordNeighborGeo()
para->getParH(level)->typeOfGridNode,
level);
setInitialNodeValues(numberOfNodesPerLevel, level);
cudaMemoryManager->cudaCopyNeighborWSB(level);
......@@ -102,6 +107,15 @@ void GridGenerator::allocArrays_CoordNeighborGeo()
if(para->getIsBodyForce())
cudaMemoryManager->cudaCopyBodyForce(level);
}
if (builder->getUseRotatingGrid()) {
SPtr<const Object> cylinder = builder->getGrid(1)->getObject();
const std::array<real, 3> centerPointOfCylinder = { (real)cylinder->getX1Centroid(), (real)cylinder->getX2Centroid(),
(real)cylinder->getX3Centroid() };
auto parameterRotatingGrid = std::make_shared<ParameterRotatingGrid>(centerPointOfCylinder, Axis::x);
para->setRotatingGridParameter(std::move(parameterRotatingGrid));
}
VF_LOG_INFO("Number of Nodes: {}", numberOfNodesGlobal);
VF_LOG_TRACE("-----finish Coord, Neighbor, Geo------");
}
......
#ifndef COORDINATE_TRANSFORMATION
#define COORDINATE_TRANSFORMATION
#include <basics/DataTypes.h>
#include <math.h>
__inline__ void transformRotatingToGlobal(real &globalX, real &globalY, real &globalZ, real localX,
real localY, real localZ, real centerCoordX, real centerCoordY,
real centerCoordZ, real angleX, real angleY, real angleZ)
{
globalX = localX;
globalY = localY;
globalZ = localZ;
// rotate
if (angleX != 0) {
// rotate in x
globalY = localY * cos(angleX) - localZ * sin(angleX);
globalZ = localY * sin(angleX) + localZ * cos(angleX);
} else if (angleY != 0) {
// rotate in y
globalX = localX * cos(angleY) + localZ * sin(angleY);
globalZ = -localX * sin(angleY) + localZ * cos(angleY);
} else if (angleZ != 0) {
// rotate in z
globalX = localX * cos(angleZ) - localY * sin(angleZ);
globalY = localX * sin(angleZ) + localY * cos(angleZ);
}
// translate
globalX += centerCoordX;
globalY += centerCoordY;
globalZ += centerCoordZ;
}
#endif
\ No newline at end of file
......@@ -53,6 +53,7 @@
#include "Logger.h"
#include "Parameter/CudaStreamManager.h"
#include "Parameter/ParameterRotatingGrid.h"
Parameter::Parameter() : Parameter(1, 0, {}) {}
......@@ -1657,6 +1658,13 @@ void Parameter::setADKernel(std::string adKernel)
{
this->adKernel = adKernel;
}
void Parameter::setRotatingGridParameter(std::shared_ptr<ParameterRotatingGrid> parameterRotatingGrid)
{
this->parameterRotatingGrid = std::move(parameterRotatingGrid);
this->parameterRotatingGrid->initializeNestedCoordinates(
{ this->parH[1]->coordinateX, this->parH[1]->coordinateY, this->parH[1]->coordinateZ },
this->parH[1]->numberOfNodes);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// add-methods
......@@ -2614,6 +2622,12 @@ std::string Parameter::getADKernel()
{
return adKernel;
}
SPtr<ParameterRotatingGrid> Parameter::getRotatingGridParameter()
{
return parameterRotatingGrid;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// initial condition fluid
void Parameter::setInitialCondition(
......
......@@ -57,6 +57,8 @@ class CudaStreamManager;
class TransientBCInputFileReader;
struct ParameterRotatingGrid;
//! \struct LBMSimulationParameter
//! \brief struct holds and manages the LB-parameter of the simulation
//! \brief For this purpose it holds structures and pointer for host and device data, respectively.
......@@ -681,8 +683,9 @@ public:
void setMultiKernelOn(bool isOn);
void setMultiKernelLevel(std::vector<int> kernelLevel);
void setMultiKernel(std::vector<std::string> kernel);
void setADKernel(std::string adKernel);
// rotating grid
void setRotatingGridParameter(std::shared_ptr<ParameterRotatingGrid> parameterRotatingGrid);
// adder
void addActuator(SPtr<PreCollisionInteractor> actuator);
......@@ -937,8 +940,9 @@ public:
bool getMultiKernelOn();
std::vector<int> getMultiKernelLevel();
std::vector<std::string> getMultiKernel();
std::string getADKernel();
// rotating grid
SPtr<ParameterRotatingGrid> getRotatingGridParameter();
// Forcing///////////////
real *forcingH, *forcingD;
......@@ -1122,6 +1126,8 @@ private:
std::vector<SPtr<PreCollisionInteractor>> actuators;
std::vector<SPtr<PreCollisionInteractor>> probes;
SPtr<ParameterRotatingGrid> parameterRotatingGrid = nullptr;
// Step of Ensight writing//
unsigned int stepEnsight;
......
#include "ParameterRotatingGrid.h"
#include "LBM/GPUHelperFunctions/CoordinateTransformation.h"
ParameterRotatingGrid::ParameterRotatingGrid(const std::array<real, 3> &centerPoint, const Axis &rotationalAxis)
: centerPoint(centerPoint), rotationalAxis(rotationalAxis)
{
}
void ParameterRotatingGrid::initializeNestedCoordinates(const std::array<real *, 3> &globalCoordinates, uint numberOfNodes)
{
this->nestedCoordinatesX.resize(numberOfNodes);
this->nestedCoordinatesY.resize(numberOfNodes);
this->nestedCoordinatesZ.resize(numberOfNodes);
// #pragma omp parallel for
for (uint index = 0; index < numberOfNodes; index++) {
this->nestedCoordinatesX[index] = globalCoordinates[0][index] - centerPoint[0];
this->nestedCoordinatesY[index] = globalCoordinates[1][index] - centerPoint[1];
this->nestedCoordinatesZ[index] = globalCoordinates[2][index] - centerPoint[2];
}
}
void ParameterRotatingGrid::transformNestedToBase(const std::array<real *, 3> &globalCoordinates)
{
// #pragma omp parallel for
for (uint index = 0; index < nestedCoordinatesX.size(); index++) {
transformRotatingToGlobal(
globalCoordinates[0][index], globalCoordinates[1][index], globalCoordinates[2][index], nestedCoordinatesX[index],
nestedCoordinatesY[index], nestedCoordinatesZ[index], centerPoint[0], centerPoint[1], centerPoint[2],
gridAngle * unitVectors.at(this->rotationalAxis)[0], gridAngle * unitVectors.at(this->rotationalAxis)[1],
gridAngle * unitVectors.at(this->rotationalAxis)[2]);
}
}
#ifndef PARAMETER_ROTATING_GRID
#define PARAMETER_ROTATING_GRID
#include <array>
#include <vector>
#include <basics/DataTypes.h>
#include <basics/geometry3d/Axis.h>
struct ParameterRotatingGrid {
public:
ParameterRotatingGrid(const std::array<real, 3> &centerPoint, const Axis &rotationalAxis);
void initializeNestedCoordinates(const std::array<real *, 3> &globalCoordinates, uint numberOfNodes);
void transformNestedToBase(const std::array<real *, 3> &globalCoordinates);
public:
const std::array<real, 3> centerPoint;
const Axis rotationalAxis;
std::vector<real> nestedCoordinatesX;
std::vector<real> nestedCoordinatesY;
std::vector<real> nestedCoordinatesZ;
real gridAngle = 1.0;
std::array<real, 3> angularVelocity;
};
#endif
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