LBIBCell
 All Classes Functions Variables Friends Pages
GeometryNode.hpp
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 #ifndef POLYGONPOINT_HPP
23 #define POLYGONPOINT_HPP
24 
25 #include <LbmLib/include/nodes/LagrangianPoint.hpp>
26 #include <LbmLib/include/geometry/Connection.hpp>
27 #include <LbmLib/include/GlobalSimulationParameters.hpp>
28 #include <UtilLib/include/Log.hpp>
29 #include <boost/geometry/geometries/point.hpp>
30 #include <array>
31 #include <iostream>
32 #include <ostream>
33 #include <string>
34 
35 namespace LbmLib {
36 namespace geometry {
37 class Connection;
38 }
39 }
40 
41 namespace LbmLib {
42 namespace nodes {
43 class PhysicalNode;
44 
48 class GeometryNode : public LagrangianPoint {
49  public:
57  double x,
58  double y,
59  unsigned int id);
63  ~GeometryNode();
64 
65 
70  void writeNode(std::ostream* stream);
71 
75  void move();
76 
82  void addPhysicalNode(
83  PhysicalNode* const physicalNode,
84  unsigned int pos);
85 
90  virtual std::string getType() const;
91 
98  virtual void setPos(
99  double x,
100  double y);
101 
105  void collectVelocity();
106 
110  void distributeForce();
111 
116  bool isUpdateNeeded() const;
117 
123  void setForce(Field<double> f);
124 
130  void addForce(Field<double> f);
131 
137  unsigned int getId() const;
138 
143  template<std::size_t K>
144  void setConnection(const std::shared_ptr<LbmLib::geometry::Connection> newconnection)
145  {
146  assert(K==0 || K==1);
147  if (this->connections_[K] != nullptr) {
148  if (newconnection != nullptr) {
149  std::stringstream message;
150  message << std::setprecision(12) <<
151  "GeometryNode::setConnection<" << K << ">() on point ID= "<< this->getId() <<
152  " (" << this->getXPos() << "," << this->getYPos() << "): overwrite non-nullptr entry (this should not happen)";
153  lbm_fail(message.str().c_str());
154  }
155  }
156  this->connections_[K] = newconnection;
157  }
158 
163  template<std::size_t K>
164  const std::shared_ptr<LbmLib::geometry::Connection> getConnection() const
165  {
166  if (this->connections_[K] == nullptr) {
167  std::stringstream message;
168  message << std::setprecision(12) <<
169  "GeometryNode::getConnection<" << K << ">() on point ID= "<< this->getId() <<
170  " (" << this->getXPos() << "," << this->getYPos() << ")" <<
171  " at time " << Parameters.getCurrentIteration() <<
172  ": nullptr found (this should not happen)";
173  LOG(UtilLib::logINFO) << message.str().c_str();
174  }
175  assert(K==0 || K==1);
176  assert(this->connections_[K] != nullptr);
177  return this->connections_[K];
178  }
179 
184  unsigned int getDomainIdOfAdjacentConnections(void) const;
185 
186 
187 
188  private:
192  Field<double> oldPosition_;
196  Field<double> force_;
200  void perturbatePosition();
201 
205  const unsigned int id_;
206 
210  std::array<PhysicalNode*,
211  16> neighbourPhysicalNodes_;
212 
217  std::array<std::shared_ptr<LbmLib::geometry::Connection>,
218  2> connections_;
219 
220 
221 };
222 } // end namespace
223 } // end namespace
224 
225 #endif // POLYGONPOINT_HPP
void setConnection(const std::shared_ptr< LbmLib::geometry::Connection > newconnection)
setter for the Kth Connection
void addPhysicalNode(PhysicalNode *const physicalNode, unsigned int pos)
addPhysicalNode Adds a physical node at a certain position
virtual std::string getType() const
getType The type of a node class
void setForce(Field< double > f)
set the force of this node
unsigned int getDomainIdOfAdjacentConnections(void) const
get the domainID of the (max two) adjacent *Connection*s
class representing a geometry node
double getYPos() const
getYPos Getter for the Y position
class representing a physical node
void collectVelocity()
collectVelocity collects the velocities from the fluid nodes to the geometry Nodes ...
void distributeForce()
distributes the Force to the fluid nodes
bool isUpdateNeeded() const
isUpdateNeeded Calculates if the connections of this points need to be updates
void move()
movePoint Moves the geomety node exactly one timestep
double getXPos() const
getXPos Getter for the X position
const std::shared_ptr< LbmLib::geometry::Connection > getConnection() const
getter for the Kth Connection
unsigned int getId() const
getter for the node id
virtual void setPos(double x, double y)
setPos Set the position new override to make sure that perturbation occures
~GeometryNode()
~GeometryNode Destructor
void writeNode(std::ostream *stream)
writes the node to the stream
GeometryNode(double x, double y, unsigned int id)
GeometryNode constructs a Geometry node.
void addForce(Field< double > f)
adds the force to the force of this node
The LagrangianPoint class A class for storing a point's coordinates and its velocity This class is th...