LBIBCell
 All Classes Functions Variables Friends Pages
BoundaryNode.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/BoundaryNode.hpp>
23 #include <LbmLib/include/nodes/PhysicalNode.hpp>
24 #include <LbmLib/include/solver/BoundarySolverFactory.hpp>
25 #include <LbmLib/include/solver/BoundaryAbstractSolver.hpp>
26 #include <iomanip>
27 #include <map>
28 #include <string>
29 #include <vector>
30 #include <cassert>
31 #include <sstream>
32 
33 namespace LbmLib {
34 namespace nodes {
36  double x,
37  double y,
38  const std::map<std::string, std::vector<std::string> >& connectionType,
39  unsigned int domainId) : LagrangianPoint(x, y),
40  domainId_(domainId),
41  physicalNeighbour_(nullptr) {
42  // make the connection between the boundary solvers and the cde solvers
43  for (auto solver : connectionType) {
44  this->addBoundarySolver(solver.first);
45  this->getBoundarySolver(solver.first).connectToCDESolvers(solver.second);
46  }
47 }
48 
49 unsigned int BoundaryNode::getDomainIdentifier() const {
50  return this->domainId_;
51 }
52 
54  for (const auto& i : boundarySolvers_) {
55  delete i.second;
56  }
57 }
58 
60  PhysicalNode* const physicalNode,
61  const Direction& dir) {
62  assert(physicalNode != nullptr);
63  physicalNeighbour_ = physicalNode;
64  directionToPhysicalNeighbour_ = dir;
65  physicalNode->setBoundaryNeighbour(this, getInverseDirection(dir));
66  assert(physicalNeighbour_->getBoundaryNeighbour(getInverseDirection(
67  dir)) == this);
68  assert(physicalNeighbour_ == physicalNode);
69 }
70 
72  return directionToPhysicalNeighbour_;
73 }
74 
76  return physicalNeighbour_;
77 }
78 
79 std::string BoundaryNode::getType() const {
80  return std::string("BoundaryNode");
81 }
82 
84  const std::string& name) {
85  auto retVal = boundarySolvers_.find(name);
86  if (retVal == boundarySolvers_.end()) {
87  std::stringstream error;
88  error << "The CDE Solver with the name " << name <<
89  " does not exists. You need to add them first\n";
90  throw UtilLib::Exception(error.str());
91  }
92  return *retVal->second;
93 }
94 
95 std::map<std::string,
97  return boundarySolvers_;
98 }
99 
100 void BoundaryNode::addBoundarySolver(const std::string& name) {
101  if (boundarySolvers_.find(name) != boundarySolvers_.end()) {
102  std::stringstream error;
103  error << "The Boundary Solver with the name " << name <<
104  " already exists. You cannot add the same twice\n";
105  throw UtilLib::Exception(error.str());
106  }
107  boundarySolvers_[name] =
108  solver::BoundarySolverFactory::instance().createObject(name);
109  boundarySolvers_[name]->connectBoundaryNode(this);
110 }
111 
112 void BoundaryNode::dumpNode(std::ostream* oStream) const {
113  double localId = 10000000.0 * getXPos() + 10000.0 * static_cast<double>(getYPos());
114  (*oStream) << std::setprecision(12) << localId << "[pos=\"" << getXPos() <<
115  "," << getYPos() << std::setprecision(5) <<
116  "!\",shape=triangle, label=\"" << getXPos() << ";" << getYPos() <<
117  "\"];" << std::endl;
118 
119  double nodeId1 = 10000000.0 * physicalNeighbour_->getXPos() + 10000.0 *
120  static_cast<double>(physicalNeighbour_->getYPos());
121  (*oStream) << std::setprecision(12) << nodeId1 << std::setprecision(5) <<
122  "[pos=\"" << physicalNeighbour_->getXPos() << "," <<
123  physicalNeighbour_->getYPos() << "!\",shape=circle, label=\"" <<
124  physicalNeighbour_->getXPos() << ";" <<
125  physicalNeighbour_->getYPos() << "\"];" << std::endl;
126 
127  (*oStream) << std::setprecision(12) << localId << "->" << nodeId1 <<
128  std::endl;
129 }
130 } // end namespace
131 } // end namespace
BoundaryNode(double x, double y, const std::map< std::string, std::vector< std::string > > &connectionType, unsigned int domainId)
BoundaryNode Constructor for a boundary node.
The BoundaryAbstractSolver class The abstract base class for all Boundary Solvers.
double getYPos() const
getYPos Getter for the Y position
std::map< std::string, solver::BoundaryAbstractSolver * > & getBoundarySolvers()
getBoundarySolvers Getter method for all Boundary Solvers
static T & instance()
Definition: Singleton.hpp:90
class representing a physical node
void setBoundaryNeighbour(BoundaryNode *const boundaryNode, const Direction &d)
setBoundaryNeighbour Setter for the neighbour boundary point
PhysicalNode * getPhysicalNeighbour() const
getFluidNeighbour Getter for the Physical neighbour
unsigned int getDomainIdentifier() const
getDomainIdentifier Getter for the domain Identifier
void connectToCDESolvers(const std::vector< std::string > &cdeSolvers)
connectToCDESolvers makes sure that this boundary Solver is executed on all connected CDE Solvers ...
~BoundaryNode()
~BoundaryNode Destructor
int getXPos() const
getXPos Getter for the X position
Direction getDirectionToNeighbour() const
getDirectionToNeighbour returns the direction to the next neighbour
BoundaryNode * getBoundaryNeighbour(const Direction &d) const
getBoundaryNeighbour Getter method to access the Boundary Neighbour
virtual std::string getType() const
getType The type of a node class
int getYPos() const
getYPos Getter for the Y position
double getXPos() const
getXPos Getter for the X position
void dumpNode(std::ostream *oStream) const
dumpNode dumps the node for dot
solver::BoundaryAbstractSolver & getBoundarySolver(const std::string &name)
getBoundarySolver Getter method for the boundary Solver
The LagrangianPoint class A class for storing a point's coordinates and its velocity This class is th...
void setPhysicalNeighbours(PhysicalNode *const physicalNode, const Direction &dir)
setPhysicalNeighbours Sets the corresponding Physical neighbours of this node