VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
DragLift.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34
35#include "DragLift.h"
36
37#include <cuda_runtime.h>
38#include <helper_cuda.h>
39
40#include <cstdio>
41#include <fstream>
42#include <sstream>
43
45#include "Parameter/Parameter.h"
47
48using namespace std;
49
50namespace vf::gpu {
51
54void calcDragLift(Parameter* para, CudaMemoryManager* cudaMemoryManager, int lev)
55{
57 //copy to host
58 //finest Grid ... with the geometry nodes
59 cudaMemoryManager->cudaCopyDragLift(lev, para->getParH(lev)->geometryBC.numberOfBCnodes);
61 double dragX = 0., dragY = 0., dragZ = 0.;
62 double CDX = 0., CDY = 0., CDZ = 0.;
64 // the calculation of the related area (A) will change, please take care
65 double delta_x_F = 0.00625; //[m]
66 double A = 2.19/(delta_x_F*delta_x_F);
68
69 for (unsigned int it = 0; it < para->getParH(lev)->geometryBC.numberOfBCnodes; it++)
70 {
71 dragX += (double) (para->getParH(lev)->DragLiftPreProcessingInXdirection[it] - para->getParH(lev)->DragLiftPostProcessingInXdirection[it]); //Kraft da Impuls pro Zeitschritt merke: andere nennen es FD
72 dragY += (double) (para->getParH(lev)->DragLiftPreProcessingInYdirection[it] - para->getParH(lev)->DragLiftPostProcessingInYdirection[it]); //Kraft da Impuls pro Zeitschritt merke: andere nennen es FD
73 dragZ += (double) (para->getParH(lev)->DragLiftPreProcessingInZdirection[it] - para->getParH(lev)->DragLiftPostProcessingInZdirection[it]); //Kraft da Impuls pro Zeitschritt merke: andere nennen es FD
74 }
76 //calc CD
77 CDX = 2.0 * dragX / (1.0 /*rho_0*/ * para->getVelocity() * para->getVelocity() * A);
78 CDY = 2.0 * dragY / (1.0 /*rho_0*/ * para->getVelocity() * para->getVelocity() * A);
79 CDZ = 2.0 * dragZ / (1.0 /*rho_0*/ * para->getVelocity() * para->getVelocity() * A);
81 //Copy to vector x,y,z
82 para->getParH(lev)->DragLiftVectorInXdirection.push_back(CDX);
83 para->getParH(lev)->DragLiftVectorInYdirection.push_back(CDY);
84 para->getParH(lev)->DragLiftVectorInZdirection.push_back(CDZ);
86}
87
88
89
90void allocDragLift(Parameter* para, CudaMemoryManager* cudaMemoryManager)
91{
93 //set level
94 int lev = para->getMaxLevel();
96 //allocation
97 //finest Grid ... with the geometry nodes
98 cudaMemoryManager->cudaAllocDragLift(lev, para->getParH(lev)->geometryBC.numberOfBCnodes);
100 printf("\n number of elements for drag and lift = %d \n", para->getParH(lev)->geometryBC.numberOfBCnodes);
101}
102
103
104
105void printDragLift(Parameter* para, CudaMemoryManager* cudaMemoryManager, int timestep)
106{
108 //set level
109 int lev = para->getMaxLevel();
111 //set filename
112 std::string ffname = para->getFName()+StringUtil::toString<int>(para->getMyProcessID())+"_"+StringUtil::toString<int>(timestep)+"_DragLift.txt";
113 const char* fname = ffname.c_str();
115 //set ofstream
118 //open file
119 ostr.open(fname);
121 //fill file with data
122 for (size_t i = 0; i < para->getParH(lev)->DragLiftVectorInXdirection.size(); i++)
123 {
124 ostr << para->getParH(lev)->DragLiftVectorInXdirection[i] << "\t" << para->getParH(lev)->DragLiftVectorInYdirection[i] << "\t" << para->getParH(lev)->DragLiftVectorInZdirection[i] << endl ;
125 }
127 //close file
128 ostr.close();
130 if (timestep == (int)para->getTimestepEnd())
131 {
132 cudaMemoryManager->cudaFreeDragLift(lev);
133 }
135}
136
137}
138
void cudaAllocDragLift(int lev, int numofelem)
void cudaCopyDragLift(int lev, int numofelem)
Class for LBM-parameter management.
Definition Parameter.h:359
int getMyProcessID() const
std::shared_ptr< LBMSimulationParameter > getParH(int level) const
Pointer to instance of LBMSimulationParameter - stored on Host System.
int getMaxLevel() const
std::string getFName() const
unsigned int getTimestepEnd() const
real getVelocity() const
std::shared_ptr< T > SPtr
void calcDragLift(Parameter *para, CudaMemoryManager *cudaMemoryManager, int lev)
Calculate drag and lift for a geometry.
Definition DragLift.cpp:54
void printDragLift(Parameter *para, CudaMemoryManager *cudaMemoryManager, int timestep)
Definition DragLift.cpp:105
void allocDragLift(Parameter *para, CudaMemoryManager *cudaMemoryManager)
Definition DragLift.cpp:90