LBIBCell
 All Classes Functions Variables Friends Pages
PhysicalNode.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/nodes/PhysicalNode.hpp>
23 #include <LbmLib/include/nodes/BoundaryNode.hpp>
24 #include <LbmLib/include/solver/CDESolver/CDEAbstractSolver.hpp>
25 #include <LbmLib/include/solver/CDESolver/CDESolverFactory.hpp>
26 #include <UtilLib/include/Exception.hpp>
27 #include <UtilLib/include/Log.hpp>
28 #include <iomanip>
29 #include <cassert>
30 #include <sstream>
31 #include <string>
32 #include <map>
33 #include <array>
34 #include <vector>
35 #include <algorithm>
36 
37 namespace LbmLib {
38 namespace nodes {
40  int x,
41  int y) : EulerianPoint(x, y),
42  fluidSolver_(solver::FluidSolver(*this)),
43  neighbourNodes_(std::array<PhysicalNode*,
44  9> {{nullptr, nullptr, nullptr, nullptr,
45  nullptr, nullptr, nullptr,
46  nullptr, nullptr}
47  }),
48  boundaryNodes_(std::array<BoundaryNode*,
49  5> {{nullptr, nullptr, nullptr, nullptr,
50  nullptr }
51  }),
52  domainIdentifier_(0),
53  cellType_(0)
54 {}
55 
57  for (const auto& i : cdeSolvers_) {
58  delete i;
59  }
60 }
61 
62 void PhysicalNode::addCDESolver(const std::string& cdeSolverName) {
63  struct Contains {
64  const std::string d;
65  explicit Contains(std::string s) : d(s) {}
66 
67  bool operator()(solver::CDEAbstractSolver* n) const { return n->getName()
68  == d; }
69  };
70 
71 
72  if (std::any_of(this->cdeSolvers_.begin(), this->cdeSolvers_.end(),
73  Contains(cdeSolverName))) {
74  std::stringstream error;
75  error << "The CDE Solver with the name " << cdeSolverName <<
76  " already exists. You cannot add the same twice\n";
77  lbm_fail(error.str());
78  }
79  this->cdeSolvers_.push_back(solver::CDESolverFactory::instance().createObject(
80  cdeSolverName));
81 
82  this->cdeSolvers_.back()->initCDESolver(this, this->cdeSolvers_.size() - 1);
83 }
84 
86  PhysicalNode* const node,
87  const Direction& d) {
88  assert(node != nullptr);
89  neighbourNodes_[d] = node;
90  assert(node == neighbourNodes_[d]);
91 }
92 
94  BoundaryNode* const boundaryNode,
95  const Direction& d) {
96  assert(boundaryNode != nullptr);
97  boundaryNodes_[d] = boundaryNode;
98  assert(boundaryNode == boundaryNodes_[d]);
99 }
100 
102  return boundaryNodes_[d];
103 }
104 
106  return neighbourNodes_[d];
107 }
108 
110  unsigned int domainTemp = this->domainIdentifier_;
111  for (auto bd : this->boundaryNodes_) {
112  if (bd != nullptr) {
113  domainTemp = bd->getDomainIdentifier();
114  }
115  }
116 
117  if (this->domainIdentifier_ != domainTemp) {
118  LOG(UtilLib::logINFO) << "PhysicalNode at (" <<this->getXPos() << ","
119  << this->getYPos() << ") " << "changed domainID from "
120  << this->domainIdentifier_ << " to " << domainTemp;
121  this->domainIdentifier_ = domainTemp;
122  this->reinitialiseCDESolvers();
123  }
124 }
125 
126 unsigned int PhysicalNode::getDomainIdentifier() const {
127  return domainIdentifier_;
128 }
129 
130 void PhysicalNode::setDomainIdentifier(unsigned int domainIdentifier) {
131  domainIdentifier_ = domainIdentifier;
132 }
133 
134 unsigned int PhysicalNode::getCellType () const {
135  return this->cellType_;
136 }
137 
138 void PhysicalNode::setCellType(unsigned int celltype) {
139  this->cellType_ = celltype;
140 }
141 
142 void PhysicalNode::reinitialiseCDESolvers() {
143  for (auto cdeSolver : cdeSolvers_) {
144  cdeSolver->reinitialise();
145  }
146 }
147 
149  boundaryNodes_ =
150  std::array<BoundaryNode*, 5> {{nullptr, nullptr, nullptr, nullptr,
151  nullptr}};
152 }
153 
154 std::string PhysicalNode::getType() const {
155  return std::string("PhysicalNode");
156 }
157 
159  return fluidSolver_;
160 }
161 
163  return fluidSolver_;
164 }
165 
167  return *cdeSolvers_[id];
168 }
169 
171  const std::string& name) const {
172  for (const auto& cdeSolver : cdeSolvers_) {
173  if (cdeSolver->getName() == name) {
174  return *cdeSolver;
175  }
176  }
177  std::stringstream error;
178  error << "The CDE Solver with the name " << name <<
179  " does not exists. You need to add them first\n";
180  throw UtilLib::Exception(error.str());
181 }
182 
183 std::vector<solver::CDEAbstractSolver*>& PhysicalNode::getCDESolvers() {
184  return this->cdeSolvers_;
185 }
186 
187 void PhysicalNode::dumpNode(std::ostream* oStream) const {
188  double localId = 10000000.0 * getXPos() + 10000.0 *
189  static_cast<double>(getYPos());
190  (*oStream) << std::setprecision(12) << localId << "[pos=\"" << getXPos() <<
191  "," << getYPos() << std::setprecision(5) <<
192  "!\",shape=circle, label=\"" << domainIdentifier_ << "\"];" <<
193  std::endl;
194  int i = 0;
195  for (auto bt : boundaryNodes_) {
196  if (bt != nullptr) {
197  double nodeId1 = 10000000.0 * bt->getXPos() + 10000.0 *
198  static_cast<double>(bt->getYPos());
199  (*oStream) << std::setprecision(12) << nodeId1 << std::setprecision(
200  5) << "[pos=\"" << bt->getXPos() << "," << bt->getYPos() <<
201  "!\",shape=triangle, label=\"" << bt->getXPos() << ";" <<
202  bt->getYPos() << "\"];" << std::endl;
203 
204  (*oStream) << std::setprecision(12) << localId << "->" <<
205  nodeId1 << std::setprecision(5) << " [ label=\"" << i <<
206  "\" ];" << std::endl;
207  }
208  i++;
209  }
210 }
211 }
212 } // end namespace
The abstract base class for all CDESolvers.
solver::CDEAbstractSolver & getCDESolverSlow(const std::string &name) const
getCDESolverSlow Getter method for the cde Solver
void dumpNode(std::ostream *oStream) const
dumpNode dumps the node for dot
virtual std::string getName()=0
Get the name of the solver.
void setCellType(unsigned int celltype)
setCellType setter for the celltype
PhysicalNode * getPhysicalNeighbour(const Direction &d) const
getPhysicalNeighbour Getter method to access the Physical Neighbour
static T & instance()
Definition: Singleton.hpp:90
The EulerianPoint class The base class for all points with an integer position and no speed...
class representing a physical node
void setDomainIdentifier(unsigned int domainIdentifier)
setDomainIdentifier setter for the domain identifier
the Fluid Solver which solves the D2Q9 LBGK
Definition: FluidSolver.hpp:41
void setBoundaryNeighbour(BoundaryNode *const boundaryNode, const Direction &d)
setBoundaryNeighbour Setter for the neighbour boundary point
PhysicalNode(int x, int y)
PhysicalNode constructs a physical node.
unsigned int getDomainIdentifier() const
getter for the Domain Identifier of this node
~PhysicalNode()
~PhysicalNode Destructor
unsigned int getCellType() const
getter for the cell type of this node
void updateDomainIdentifier()
updateDomainIdentifier updates the domain Identifier of this node. If the domain changes it returns t...
const solver::FluidSolver & getFluidSolver() const
getFluidSolver Const getter method for the fluid Solver
int getXPos() const
getXPos Getter for the X position
virtual std::string getType() const
getType The type of a node class
BoundaryNode * getBoundaryNeighbour(const Direction &d) const
getBoundaryNeighbour Getter method to access the Boundary Neighbour
int getYPos() const
getYPos Getter for the Y position
void addCDESolver(const std::string &cdeSolverName)
addCDESolver Adds a CDESolver to this node
class representing a boundary node
solver::CDEAbstractSolver & getCDESolver(size_t id) const
getCDESolver Getter method for the cde Solver
std::vector< solver::CDEAbstractSolver * > & getCDESolvers()
getCDESolvers Getter method for all CDE Solvers
void resetBoundaryNodes()
resetBoundaryNodes Resets the boundary nodes to nullptr
void setPhysicalNeighbour(PhysicalNode *const node, const Direction &d)
setPhysicalNeighbour Setter for the neighbour fluid point