VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
BoundaryQs.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//
32//=======================================================================================
33#include "BoundaryQs.h"
34
35#include "Parameter/Parameter.h"
36
37#include <iostream>
38#include <stdio.h>
39#include <stdlib.h>
40
41#define QCOLUMNS 27
42
43namespace vf::gpu {
44
45BoundaryQs::BoundaryQs(std::string path, bool isBinary)
46{
47 if (isBinary)
48 {
49 file.open(path.c_str(), std::ios::in | std::ios::binary);
50 checkFileStatus(path);
51 init_Binary();
52 }
53 else
54 {
55 file.open(path.c_str(), std::ios::in );
56 checkFileStatus(path);
57 init();
58 }
59}
60
61BoundaryQs::BoundaryQs(std::string path, std::shared_ptr<Parameter> para, std::string str, bool isBinary)
62{
63 if (isBinary) file.open(path.c_str(), std::ios::in | std::ios::binary);
64 else file.open(path.c_str(), std::ios::in);
65
66 if (!file)
67 para->setObj(str, false);
68 else
69 {
70 para->setObj(str, true);
71 if(isBinary)
72 init_Binary();
73 else
74 init();
75 }
76
77}
78
83
84
85void BoundaryQs::checkFileStatus(std::string path)
86{
87 if (!file)
88 {
89 std::cerr << "can not open q-file: " << path << std::endl;
90 exit(1);
91 }
92}
93
95{
96 file.close();
97}
98
99void BoundaryQs::init()
100{
101 std::vector<uint32_t> vec1D_code;
102 std::string bufferString;
103
104 file >> maxLevel;
105 resizeVectors();
106
107 for (unsigned int level = 0; level <= maxLevel; level++)
108 {
109 file >> levelSizes[level];
110 resizeVectorsPerLevel(level, vec1D_code);
111 if (levelSizes[level] == 0)
112 continue;
113
114 for (unsigned int elem = 0; elem < levelSizes[level]; elem++)
115 {
116 int columnCounter = 26;
117 file >> indices[level][elem];
118 file >> vec1D_code[elem];
119
120 while (vec1D_code[elem] != 0)
121 {
122 if (vec1D_code[elem] % 2 == 1)
123 file >> values[level][columnCounter][elem];
124 vec1D_code[elem] /= 2;
126 }
127 getline(file, bufferString);
128 }
129 vec1D_code.clear();
130 }
131}
132
133void BoundaryQs::init_Binary()
134{
135 std::vector<uint32_t> vec1D_code;
136
137 std::string bufferString;
138 unsigned int bufferInt;
141
142 file >> maxLevel;
143 resizeVectors();
144
145 for (unsigned int level = 0; level <= maxLevel; level++)
146 {
147 file >> levelSizes[level];
148 resizeVectorsPerLevel(level, vec1D_code);
149 if (levelSizes[level] == 0)
150 continue;
151
152 for (unsigned int elem = 0; elem < levelSizes[level]; elem++)
153 {
154 int zaehler = 26;
155 file.read((char*)&bufferInt, sizeof(int));
156 indices[level][elem] = bufferInt;
157
158 file.read((char*)&bufferUint32_t, sizeof(uint32_t));
160 while (vec1D_code[elem] != 0)
161 {
162 if (vec1D_code[elem] % 2 == 1)
163 {
164 file.read((char*)&bufferDouble, sizeof(double));
165 values[level][zaehler][elem] = bufferDouble;
166 }
167 vec1D_code[elem] /= 2;
168 zaehler--;
169 }
170 getline(file, bufferString);
171 }
172 vec1D_code.clear();
173 }
174}
175
176void BoundaryQs::resizeVectors()
177{
178 levelSizes.resize(maxLevel + 1);
179 values.resize(maxLevel + 1);
180 indices.resize(maxLevel + 1);
181}
182
183void BoundaryQs::resizeVectorsPerLevel(unsigned int level, std::vector<uint32_t> &vec1D_code)
184{
185 values[level].resize(QCOLUMNS);
186 for (int i = 0; i < QCOLUMNS; i++)
187 values[level][i].resize(levelSizes[level], -1);
188 indices[level].resize(levelSizes[level]);
189 vec1D_code.resize(levelSizes[level]);
190}
191
192unsigned int BoundaryQs::getSize(unsigned int level)
193{
194 return this->levelSizes[level];
195}
196
198{
199 return maxLevel;
200}
201
202
203void BoundaryQs::setValuesInVector(std::vector<std::vector<std::vector<real>>> &q27, unsigned int level) const
204{
205 for (std::size_t column = 0; column < values[level].size(); column++)
206 for (std::size_t index = 0; index < values[level][column].size(); index++)
207 q27[level][column].push_back(values[level][column][index]);
208}
209
210void BoundaryQs::setValues(real **q27, unsigned int level) const
211{
212 for (std::size_t column = 0; column < values[level].size(); column++)
213 for (std::size_t index = 0; index < values[level][column].size(); index++)
214 q27[column][index] = values[level][column][index];
215}
216
217void BoundaryQs::setIndexInVector(std::vector<std::vector<int>> &data, unsigned int level) const
218{
219 for (std::size_t index = 0; index < indices[level].size(); index++)
220 data[level].push_back(indices[level][index]);
221}
222
223void BoundaryQs::setIndex(int *data, unsigned int level) const
224{
225 for (std::size_t index = 0; index < indices[level].size(); index++)
226 data[index] = indices[level][index];
227}
228
229
230void BoundaryQs::getQs(std::vector<std::vector<std::vector<real> > > &qs) {
231 int j = 0;
232 int i = 0;
233 for (std::vector<std::vector<std::vector<real> > >::iterator it = values.begin(); it != values.end(); it++) {
234 i = 0;
235 for (std::vector<std::vector<real> >::iterator it2 = it->begin(); it2 != it->end(); it2++) {
236
237 for (std::vector<real>::iterator it3 = it2->begin(); it3 != it2->end(); it3++) {
238 qs[j][i].push_back(*it3);
239 }
240 i++;
241 }
242 j++;
243 }
244}
245
246void BoundaryQs::getIndices(std::vector<std::vector<uint> > &indices) {
247 for (std::size_t level = 0; level < this->indices.size(); level++)
248 for (std::size_t index = 0; index < this->indices[level].size(); index++)
249 indices[level].push_back(this->indices[level][index]);
250}
251
252}
253
void setValuesInVector(std::vector< std::vector< std::vector< real > > > &q27, unsigned int level) const
unsigned int getSize(unsigned int level)
void getQs(std::vector< std::vector< std::vector< real > > > &qs)
void getIndices(std::vector< std::vector< uint > > &indices)
void setValues(real **q27, unsigned int level) const
unsigned int getLevel()
void setIndex(int *indices, unsigned int level) const
void setIndexInVector(std::vector< std::vector< int > > &data, unsigned int level) const
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
#define QCOLUMNS