AMR-Solver  1.0
Block-based Octree AMR grid flow solver
input.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <stdlib.h>
4 #include <string>
5 #include "boundary.h"
6 #include "octreegrid.h"
7 #include "adapt.h"
8 #include "direction.h"
9 
11 
12 namespace std {
13 
16 
17  myOctree::NodeBc bcc;
18 
19  if(bc=="N")
20  bcc = myOctree::NONE;
21 
22  if(bc=="B")
23  bcc = myOctree::BOUNDARY;
24 
25  if(bc=="MPI_BOUNDARY")
27 
28  return bcc;
29 }
30 
33 
35 
36  if(bc=="N")
37  bcc = myOctree::none;
38 
39  if(bc=="D")
40  bcc = myOctree::dirichlet;
41 
42  if(bc=="NE")
43  bcc = myOctree::neumann;
44 
45  if(bc=="MB")
47 
48  return bcc;
49 }
50 
52 void read_scalar_fields(ifstream& file) {
53 
54  string line, str;
55 
56  //Skips if a line is empty
57  getline(file, line);
58  while(line.empty()) {
59  getline(file, line);
60  }
61 
62  if(line=="scalar_fields") {
63 
64  file >> str;
65  if(str != "{") {
66  cerr << "Expected an opening bracket" <<endl;
67  exit(1);
68  }
69 
70  cerr << "\nUser defined scalar fields" << endl;
71 
72  while(file) {
73 
74 
75  if(file >> str && str == "}") break;
76  else myOctree::scalar_fields.push_back(str);
77  cerr << str << endl;
78 
79  }
80  }
81 }
82 
84 void read_vector_fields(ifstream& file) {
85 
86  string line, str;
87 
88  //Skips if a line is empty
89  getline(file, line);
90  while(line.empty()) {
91  getline(file, line);
92  }
93 
94  if(line=="vector_fields") {
95 
96  file >> str;
97  if(str != "{") {
98  cerr << "Expected an opening bracket" <<endl;
99  exit(1);
100  }
101 
102  cerr << "\nUser defined vector Fields" << endl;
103 
104  while(file) {
105 
106 
107  if(file >> str && str == "}") break;
108  else myOctree::vector_fields.push_back(str);
109  cerr << str << endl;
110  }
111  }
112 
113 }
114 
116 int read_blocks(ifstream& file) {
117 
118  string line, str;
119 
120  int blocknumber, level;
121  double xmin, xmax, ymin, ymax, zmin, zmax;
122  string eastbc, westbc, northbc, southbc, topbc, bottombc;
123  myOctree::NodeBc east_bc, west_bc, north_bc, south_bc, top_bc, bottom_bc;
124 
125  myOctree::NodeBc **bc;
126  bc = new myOctree::NodeBc* [3];
127  for(int i = 0; i < 3; i++)
128  bc[i] = new myOctree::NodeBc [2];
129 
130  //skips line if line is empty
131  getline(file,line);
132  while(line.empty()) {
133  getline(file, line);
134  }
135 
136 
137  if(line=="blocks") {
138 
139 
140  file >> str;
141  if(str != "{") {
142  cerr << "Expected an opening bracket" <<endl;
143  exit(1);
144  }
145 
146  while(file) {
147  if(file >> str && str == "}") break;
148  else blocknumber = atoi(str.c_str());
149 
150  //file >> blocknumber;
151  file >> xmin >> xmax >> ymin >> ymax >> zmin >> zmax;
152  file >> level;
153  file >> eastbc >> westbc >> northbc >> southbc >> topbc >> bottombc;
154 
161 
162  //cerr << blocknumber << xmin << xmax << ymin << ymax << zmin << zmax << endl;
163 
164  myOctree::create_node(blocknumber, xmin, xmax, ymin, ymax, zmin, zmax, level, bc);
165 
166  }
167 
168  }
169 
170  delete [] bc;
171 
172  return blocknumber;
173 }
174 
176 void read_scalar_field_Bc(ifstream& file, int number) {
177 
178 
179  int blocknumber;
180  string line, str;
181  string eastbc, westbc, northbc, southbc, topbc, bottombc;
182 
183 
184  myOctree::FieldBc **bc;
185  double **bcval;
186  bc = new myOctree::FieldBc* [3];
187  bcval = new double* [3];
188  for(int i = 0; i < 3; i++) {
189  bc[i] = new myOctree::FieldBc [2];
190  bcval[i] = new double [2];
191  }
192 
193  myOctree::FieldBc east_bc, west_bc, north_bc, south_bc, top_bc, bottom_bc;
194  double eastbcval, westbcval, northbcval, southbcval, topbcval, bottombcval;
195 
196  //Skips if a line is empty
197  getline(file, line);
198  while(line.empty()) {
199  getline(file, line);
200  }
201 
202  if(line=="scalar_field_boundary_conditions") {
203 
204  file >> str;
205  if(str != "{") {
206  cerr << "Expected an opening bracket" <<endl;
207  exit(1);
208  }
209 
210  cerr << "\nSetting scalar field boundary conditions" << endl;
211 
212  while(file) {
213 
214 
215  if(file >> str && str == "}") break;
216  //else myOctree::scalar_fields.push_back(str);
217  cerr << str << endl;
218 
219  for(int i = 0; i < number ; ++i) {
220 
221  file >> blocknumber;
222  file >> eastbc >> westbc >> northbc >> southbc >> topbc >> bottombc;
223  file >> bcval[0][0] >> bcval[0][1] >> bcval[1][0] >> bcval[1][1] >> bcval[2][0] >> bcval[2][1];
224 
231 
232  //cerr << blocknumber << eastbc << westbc << northbc << southbc << topbc << bottombc << endl;
233 
234  /*add a function here which sets boundary condition and boundary values*/
235  myOctree::set_FieldBc_FieldBcVal(blocknumber, str, bc, bcval);
236  }
237  }
238  }
239 
240  delete [] bc;
241  delete [] bcval;
242 }
243 
245 void read_vector_field_Bc(ifstream& file, int number) {
246 
247  int blocknumber;
248  string line, str;
249  string eastbc, westbc, northbc, southbc, topbc, bottombc;
250 
251  myOctree::FieldBc **xbc;
252  myOctree::FieldBc **ybc;
253  myOctree::FieldBc **zbc;
254  double **xbcval;
255  double **ybcval;
256  double **zbcval;
257  xbc = new myOctree::FieldBc* [3];
258  ybc = new myOctree::FieldBc* [3];
259  zbc = new myOctree::FieldBc* [3];
260  xbcval = new double* [3];
261  ybcval = new double* [3];
262  zbcval = new double* [3];
263  for(int i = 0; i < 3; i++) {
264  xbc[i] = new myOctree::FieldBc [2];
265  ybc[i] = new myOctree::FieldBc [2];
266  zbc[i] = new myOctree::FieldBc [2];
267  xbcval[i] = new double [2];
268  ybcval[i] = new double [2];
269  zbcval[i] = new double [2];
270  }
271 
272  myOctree::FieldBc east_bc, west_bc, north_bc, south_bc, top_bc, bottom_bc;
273  double eastbcval, westbcval, northbcval, southbcval, topbcval, bottombcval;
274 
275  //Skips if a line is empty
276  getline(file, line);
277  while(line.empty()) {
278  getline(file, line);
279  }
280 
281  if(line=="vector_field_boundary_conditions") {
282 
283  file >> str;
284  if(str != "{") {
285  cerr << "Expected an opening bracket" <<endl;
286  exit(1);
287  }
288 
289  cerr << "\nSetting vector field boundary conditions " << endl;
290 
291  while(file) {
292 
293 
294  if(file >> str && str == "}") break;
295  //else myOctree::vector_fields.push_back(str);
296  cerr << str << endl;
297 
298  for(int i = 0; i < number ; ++i) {
299 
300  file >> blocknumber;
301 
302 
303  file >> eastbc >> westbc >> northbc >> southbc >> topbc >> bottombc;
304  file >> xbcval[0][0] >> xbcval[0][1] >> xbcval[1][0] >> xbcval[1][1] >> xbcval[2][0] >> xbcval[2][1];
305 
312 
313  //cerr << blocknumber << eastbc << westbc << northbc << southbc << topbc << bottombc << endl;
314 
315  file >> eastbc >> westbc >> northbc >> southbc >> topbc >> bottombc;
316  file >> ybcval[0][0] >> ybcval[0][1] >> ybcval[1][0] >> ybcval[1][1] >> ybcval[2][0] >> ybcval[2][1];
317 
324 
325  //cerr << blocknumber << eastbc << westbc << northbc << southbc << topbc << bottombc << endl;
326 
327  file >> eastbc >> westbc >> northbc >> southbc >> topbc >> bottombc;
328  file >> zbcval[0][0] >> zbcval[0][1] >> zbcval[1][0] >> zbcval[1][1] >> zbcval[2][0] >> zbcval[2][1];
329 
336 
337  //cerr << blocknumber << eastbc << westbc << northbc << southbc << topbc << bottombc << endl;
338 
339 
340  /*add a function here which sets boundary condition and boundary values*/
341  myOctree::set_VecFieldBc_VecFieldBcVal(blocknumber, str, xbc, ybc, zbc, xbcval, ybcval, zbcval);
342  }
343  }
344  }
345 
346  delete [] xbc;
347  delete [] ybc;
348  delete [] zbc;
349  delete [] xbcval;
350  delete [] ybcval;
351  delete [] zbcval;
352 }
353 
355 void read_max_level(ifstream& file) {
356 
357  string line, str;
358 
359  //Skips if a line is empty
360  getline(file, line);
361  while(line.empty()) {
362  getline(file, line);
363  }
364 
365  if(line=="max_level") {
366 
367  file >> myOctree::max_level;
368 
369  }
370 
371 }
372 
375 
376  int blocknumber;
377  string line, str;
378 
379  ifstream file ("../input/input.pfs");
380  if(file.fail()) {
381  cerr << "Error opening input file\n";
382  exit(1);
383  }
384 
385  if(file.peek() == ifstream::traits_type::eof()) {
386  cerr << "Nothing in the input file\n";
387  exit(1);
388  }
389 
390  else {
391 
392  cerr << "\nReading input files" << endl;
393 
394  read_scalar_fields(file);
395 
396  read_vector_fields(file);
397 
398  blocknumber = read_blocks(file);
399 
400  read_scalar_field_Bc(file, blocknumber);
401 
402  read_vector_field_Bc(file, blocknumber);
403 
404  read_max_level(file);
405 
406  }
407 
408  file.close();
409 }
410 
411 }
std::vector< std::string > scalar_fields
Definition: block.cpp:8
void read_vector_field_Bc(ifstream &file, int number)
Definition: input.cpp:245
void read_scalar_fields(ifstream &file)
Definition: input.cpp:52
int max_level
Definition: adapt.cpp:8
Standard input output stuff.
Definition: input.cpp:12
void read_vector_fields(ifstream &file)
Definition: input.cpp:84
void set_FieldBc_FieldBcVal(int number, std::string name, FieldBc **bc, double **bcval)
Definition: boundary.cpp:9
void read_max_level(ifstream &file)
Definition: input.cpp:355
myOctree::FieldBc string_to_FieldBc(string bc)
Definition: input.cpp:32
std::vector< std::string > vector_fields
Definition: block.cpp:9
void set_VecFieldBc_VecFieldBcVal(int number, std::string name, FieldBc **xbc, FieldBc **ybc, FieldBc **zbc, double **xbcval, double **ybcval, double **zbcval)
Definition: boundary.cpp:57
myOctree::NodeBc string_to_NodeBc(string bc)
Definition: input.cpp:15
void read_scalar_field_Bc(ifstream &file, int number)
Definition: input.cpp:176
void read_input_file()
Definition: input.cpp:374
node_boundary_flags
Definition: boundary.h:7
void create_node(int blocknumber, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, int level, NodeBc **bc)
Definition: octreegrid.cpp:60
int read_blocks(ifstream &file)
Definition: input.cpp:116
field_boundary_flags
Definition: boundary.h:16