LBIBCell
 All Classes Functions Variables Friends Pages
GlobalSimulationParameters.cpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  * 2013-2015 Simon Tanaka <tanakas"at"gmx"dot"ch>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 #include <LbmLib/include/GlobalSimulationParameters.hpp>
23 #include <UtilLib/include/Exception.hpp>
24 #include <omp.h>
25 #include <fstream>
26 #include <iomanip>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 
31 namespace LbmLib {
33 
35  const std::string& fileName) {
36  std::ifstream fileStream;
37  fileStream.open(fileName);
38  if (fileStream.is_open()) {
39  std::string line;
40  while (std::getline(fileStream, line)) {
41  std::stringstream lineStream(line);
42  if (line.at(0) != '#') {
43  std::string identifier;
44  lineStream >> identifier;
45  if (identifier == "CurrentIterations:") {
46  lineStream >> currentIteration_;
47  } else if (identifier == "Iterations:") {
48  lineStream >> iterations_;
49  } else if (identifier == "ReportStep:") {
50  lineStream >> reportSteps_;
51  } else if (identifier == "SizeX:") {
52  lineStream >> sizeX_;
53  } else if (identifier == "SizeY:") {
54  lineStream >> sizeY_;
55  } else if (identifier == "tauFluid:") {
56  lineStream >> tauFluid_;
57  } else if (identifier == "CDESolvers:") {
58  std::string tempName;
59  double tempTau;
60  while (lineStream >> tempName >> tempTau) {
61  cdeSolvers_[tempName] = tempTau;
62  }
63  } else { throw UtilLib::Exception(
64  "An unknown parameter was passed in the global Parameter file");
65  }
66  }
67  }
68  } else {
69  lbm_fail("Cannot find the parameter file.");
70  }
71  fileStream.close();
72 }
73 
75  const std::string& fileName) const {
76  std::ofstream fileStream;
77  fileStream.open(fileName);
78  if (fileStream.is_open()) {
79  fileStream << "#Global Parameter file\n";
80  fileStream << "CurrentIterations:" << '\t' << currentIteration_ << "\n";
81  fileStream << "Iterations:" << '\t' << iterations_ << "\n";
82  fileStream << "ReportStep:" << '\t' << reportSteps_ << "\n";
83  fileStream << "SizeX:" << '\t' << sizeX_ << "\n";
84  fileStream << "SizeY:" << '\t' << sizeY_ << "\n";
85  fileStream << "tauFluid:" << '\t' << tauFluid_ << "\n";
86  fileStream << "CDESolvers:";
87  for (const auto& solver : cdeSolvers_) {
88  fileStream << '\t' << solver.first << '\t' << solver.second;
89  }
90  fileStream << "\n";
91  } else {
92  throw UtilLib::Exception(
93  "Problem to open the output file for the force solver");
94  }
95 
96  fileStream.close();
97 }
98 
100  const int num_threads(omp_get_max_threads());
101  omp_set_num_threads(num_threads);
102  std::cout << std::endl;
103  std::cout << std::left << std::setfill('*') << std::setw(51) << "*" <<
104  std::endl << std::setfill(' ');
105  std::cout << std::setw(25) << "| PARAMETERS:" << std::setw(25) <<
106  " " << "|\n";
107  std::cout << std::setw(25) << "| Threads:" << std::setw(25) <<
108  num_threads << "|\n";
109  std::cout << std::setw(25) << "| Size X:" << std::setw(25) <<
110  sizeX_ << "|\n";
111  std::cout << std::setw(25) << "| Size Y:" << std::setw(25) <<
112  sizeY_ << "|\n";
113  std::cout << std::setw(25) << "| Fluid Tau:" << std::setw(25) <<
114  tauFluid_ << "|\n";
115  std::cout << std::setw(25) << "| Iterations:" << std::setw(25) <<
116  iterations_ << "|\n";
117  std::cout << std::setw(25) << "| Current iterations:" << std::setw(25) <<
118  currentIteration_ << "|\n";
119  std::cout << std::setw(25) << "| Report Steps:" << std::setw(25) <<
120  reportSteps_ << "|\n";
121  for (const auto& solver : cdeSolvers_) {
122  std::cout << std::setw(15) << "| CDESolver:" << std::setw(10) <<
123  "name:" << std::setw(25) << solver.first << "|\n";
124  std::cout << std::setw(15) << "| " << std::setw(10) << "tau: " <<
125  std::setw(25) << solver.second << "|\n";
126  }
127  std::cout << std::setfill('*') << std::setw(51) << "*" << std::endl;
128  std::cout << std::setfill(' ');
129 }
130 } // end namespace
void loadGlobalSimulationParameters(const std::string &fileName)
loads the parameters from the file
GlobalSimulationParameters_()
the class that stores all parameters related to the simulation
void printParameters() const
prints the parameters to the standard output
void writeGlobalSimulationParameters(const std::string &fileName) const
writes all parameters to the file