22 #include <LbmLib/include/nodes/GeometryNode.hpp>
23 #include <LbmLib/include/nodes/PhysicalNode.hpp>
24 #include <UtilLib/include/geometry/Rectangle.hpp>
25 #include <LbmLib/include/Constants.hpp>
26 #include <UtilLib/include/Log.hpp>
27 #include <LbmLib/include/Field.hpp>
47 constexpr
double halfPi = M_PI / 2.0;
48 constexpr
double doublePi = 2.0 * M_PI;
55 inline double fastCos(
const double x) {
58 double tempx = x + halfPi;
63 cos = 1.27323954 * tempx + 0.405284735 * tempx * tempx;
65 cos = 0.225 * (cos *-cos - cos) + cos;
68 cos = 0.225 * (cos * cos - cos) + cos;
72 cos = 1.27323954 * tempx - 0.405284735 * tempx * tempx;
74 cos = 0.225 * (cos *-cos - cos) + cos;
77 cos = 0.225 * (cos * cos - cos) + cos;
89 inline double calculateDiscreteDeltaDirac(
const double xpos,
const double ypos) {
91 (1.0 + fastCos(halfPi * xpos)) *
92 (1.0 + fastCos(halfPi * ypos))
102 oldPosition_(x - 5.0, y - 5.0),
105 16> {{
nullptr,
nullptr,
nullptr,
106 nullptr,
nullptr,
nullptr,
107 nullptr,
nullptr,
nullptr,
108 nullptr,
nullptr,
nullptr,
109 nullptr,
nullptr,
nullptr,
111 connections_(std::array<std::shared_ptr<LbmLib::geometry::Connection>,
116 perturbatePosition();
121 std::stringstream message;
122 message <<
"GeometryNode with nodeid=" << this->
getId() <<
" finally destroyed.";
123 LOG(UtilLib::logDEBUG1) << message.str().c_str();
127 (*stream) << id_ <<
'\t' <<
getXPos() <<
'\t' <<
getYPos() <<
'\n';
138 assert(physicalNode !=
nullptr);
139 neighbourPhysicalNodes_[pos] = physicalNode;
140 assert(physicalNode == neighbourPhysicalNodes_[pos]);
149 perturbatePosition();
153 void GeometryNode::perturbatePosition() {
155 static std::random_device rd;
157 static std::mt19937 gen(seed);
158 static std::uniform_real_distribution<> dis(-PERTURBATION, PERTURBATION);
160 if (std::abs(static_cast<int>(
getXPos()) -
getXPos()) <= EPSILON) {
161 std::stringstream message;
162 message << std::setprecision(12)
163 <<
"Perturbation of GeometryNode (ID="<<this->
getId()<<
") "
167 while(std::abs(temprand) < 5.0*EPSILON) {
171 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
172 LOG(UtilLib::logINFO) << message.str().c_str();
174 if (std::abs(static_cast<int>(
getYPos()) -
getYPos()) <= EPSILON) {
175 std::stringstream message;
176 message << std::setprecision(12)
177 <<
"Perturbation of GeometryNode (ID="<<this->
getId()<<
") "
181 while(std::abs(temprand) < 5.0*EPSILON) {
185 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
186 LOG(UtilLib::logINFO) << message.str().c_str();
191 std::stringstream message;
192 message << std::setprecision(12);
193 message <<
"Perturbation of GeometryNode (ID="<<this->
getId()<<
") ";
194 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
198 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
199 LOG(UtilLib::logINFO) << message.str().c_str();
204 std::stringstream message;
205 message << std::setprecision(12);
206 message <<
"Perturbation of GeometryNode (ID="<<this->
getId()<<
") ";
207 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
211 message <<
"(" << this->
getXPos() <<
"," << this->
getYPos() <<
")";
212 LOG(UtilLib::logINFO) << message.str().c_str();
218 for (
const auto& node : neighbourPhysicalNodes_) {
220 velocity += calculateDiscreteDeltaDirac(dist.
x,dist.
y) *
221 node->getFluidSolver().getVelocity();
223 assert(std::isfinite(velocity.
x));
224 assert(std::isfinite(velocity.
y));
230 #pragma omp parallel for schedule(dynamic) private(dist)
231 for (
size_t it=0;it<this->neighbourPhysicalNodes_.size();++it) {
232 dist = nodes::getDistanceField(*
this, *this->neighbourPhysicalNodes_[it]);
233 this->neighbourPhysicalNodes_[it]->getFluidSolver().addForce(calculateDiscreteDeltaDirac(dist.
x,dist.
y) * force_);
242 return std::string(
"GeometryNode");
246 this->oldPosition_.
x = this->
getXPos();
247 this->oldPosition_.
y = this->
getYPos();
249 assert(std::isfinite(this->
getXPos()));
250 assert(std::isfinite(this->
getYPos()));
258 this->oldPosition_.
y), std::floor(this->oldPosition_.y),
259 std::floor(this->oldPosition_.x), std::ceil(this->oldPosition_.x));
270 assert(this->getConnection<0>() !=
nullptr);
271 assert(this->getConnection<1>() !=
nullptr);
273 temp = this->getConnection<0>()->getDomainIdentifier();
274 if (this->getConnection<1>()->getDomainIdentifier() != temp) {
275 std::stringstream message;
276 message << std::setprecision(12) <<
277 "GeometryNode ID="<<this->
getId()<<
") " <<
279 " has adjacent connections with non-identical domainIdentifiers";
280 LOG(UtilLib::logINFO) << message.str().c_str();
virtual void setVelocity(Field< double > velocity)
setVelocity Set the velocity
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
double getYPos() const
getYPos Getter for the Y position
class representing a physical node
T x
x the value in x direction
void collectVelocity()
collectVelocity collects the velocities from the fluid nodes to the geometry Nodes ...
bool pointWithinBounds(double x, double y) const
pointWithinBounds Checks if point is contained inside this rectangle
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
double getXVelocity() const
getXVelocity Getter for x-velocity component
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.
double getYVelocity() const
getYVelocity Getter for the y-velocity component
T y
y the value in y direction
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...
a class representing a rectangle
virtual void setPos(double x, double y)
setPos Set the position new override this method to change default behaviour