LBIBCell
 All Classes Functions Variables Friends Pages
ForceStructs.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 FORCESTRUCTS_HPP
23 #define FORCESTRUCTS_HPP
24 
25 #include <LbmLib/include/Field.hpp>
26 #include <LbmLib/include/nodes/EulerianPoint.hpp>
27 #include <LbmLib/include/nodes/GeometryNode.hpp>
28 #include <LbmLib/include/solver/ForceSolver.hpp>
29 #include <UtilLib/include/Exception.hpp>
30 #include <omp.h>
31 #include <fstream>
32 #include <iostream>
33 #include <map>
34 #include <memory>
35 #include <sstream>
36 #include <string>
37 namespace LbmLib {
38 namespace solver {
39 
40 
41 
42 namespace ForceStructs{
43 
44 //=================================================================================================================
58  unsigned int id1,
59  unsigned int id2,
60  double k,
61  double l0) : AbstractForceStruct(),
62  id1_(id1),
63  id2_(id2),
64  k_(k),
65  l0_(l0) {}
66 
67  void calculateForce(const std::map<unsigned int,
68  std::shared_ptr<nodes::GeometryNode> >& nodes)
69  {
70  try {
71  const double f = k_ *
72  (nodes::getDistance(*(nodes.at(this->id2_)),
73  *(nodes.at(this->id1_))) - this->l0_);
74 
75  nodes.at(this->id1_)->addForce(f *
76  (nodes.at(this->id2_)->getPos() - nodes.at(this->id1_)->getPos()) /
77  nodes::getDistance(*(nodes.at(this->id2_)), *(nodes.at(this->id1_))));
78  }
79  catch (...){
80  lbm_fail("Could not compute and set the forces.");
81  }
82  }
83 
84  void writeForceStruct(std::ofstream* const stream) const {
85  (*stream) << this->type << "\t" << this->id1_ << "\t" << this->id2_ << "\t" << this->k_ <<
86  "\t" << this->l0_ << "\n";
87  }
88 
89  unsigned int getType() const {
90  return 0;
91  }
92 
93  unsigned int getPartnerGeometryNode(void) const {
94  return this->id2_;
95  }
96 
97  private:
98  const unsigned int type = 0;
99  const unsigned int id1_;
100  const unsigned int id2_;
101  const double k_;
102  const double l0_;
103 };
104 
110 std::shared_ptr<ForceType0> loadForceType0(std::stringstream* const stream) {
111  unsigned int type, id1, id2;
112  double k, l0;
113  (*stream) >> type >> id1 >> id2 >> k >> l0;
114  return std::make_shared<ForceType0>(ForceType0(id1, id2, k, l0));
115 }
116 
117 //=================================================================================================================
131  unsigned int id1,
132  double x,
133  double y,
134  double k,
135  double l0) : AbstractForceStruct(),
136  id1_(id1),
137  x_(x),
138  y_(y),
139  k_(k),
140  l0_(l0) {}
141 
142  void calculateForce(const std::map<unsigned int,
143  std::shared_ptr<nodes::GeometryNode> >& nodes) {
144  nodes::LagrangianPoint tempNode(x_, y_);
145  const double f = k_ * (nodes::getDistance(tempNode, *(nodes.at(id1_))) - l0_);
146  double distance = nodes::getDistance(tempNode, *(nodes.at(id1_)));
147  if (distance != 0.0) {
148  nodes.at(id1_)->addForce(f * (tempNode.getPos() - nodes.at(
149  id1_)->getPos()) / distance);
150  }
151  }
152 
153  void writeForceStruct(std::ofstream* const stream) const {
154  (*stream) << type << "\t" << id1_ << "\t" << x_ << '\t' <<
155  y_ << "\t" << k_ << "\t" << l0_ << "\n";
156  }
157 
158  unsigned int getType() const {
159  return 1;
160  }
161 
162  unsigned int getPartnerGeometryNode(void) const {
163  return 0;
164  }
165 
166  private:
167  const unsigned int type = 1;
168  const unsigned int id1_;
169  const double x_;
170  const double y_;
171  const double k_;
172  const double l0_;
173 };
174 
180 std::shared_ptr<ForceType1> loadForceType1(std::stringstream* const stream) {
181  unsigned int type, id1;
182  double x, y, k, l0;
183  (*stream) >> type >> id1 >> x >> y >> k >> l0;
184 // return new ForceType1(id1, x, y, k, l0);
185  return std::make_shared<ForceType1>(ForceType1(id1, x, y, k, l0));
186 }
187 
188 //=================================================================================================================
200  unsigned int id1,
201  double fx,
202  double fy) : AbstractForceStruct(),
203  id1_(id1),
204  fx_(fx),
205  fy_(fy) {}
206 
207  void calculateForce(const std::map<unsigned int,
208  std::shared_ptr<nodes::GeometryNode> >& nodes) {
209  nodes.at(id1_)->addForce(Field<double>(fx_, fy_));
210  }
211 
212  void writeForceStruct(std::ofstream* const stream) const {
213  (*stream) << type << "\t" << id1_ << "\t" << fx_ << "\t" << fy_ << "\n";
214  }
215 
216  unsigned int getType() const {
217  return 2;
218  }
219 
220  unsigned int getPartnerGeometryNode(void) const {
221  return 0;
222  }
223 
224  private:
225  const unsigned int type = 2;
226  const unsigned int id1_;
227  const double fx_;
228  const double fy_;
229 };
230 
236 std::shared_ptr<ForceType2> loadForceType2(std::stringstream* const stream) {
237  unsigned int type, id1;
238  double fx, fy;
239  (*stream) >> type >> id1 >> fx >> fy;
240 // return new ForceType2(id1, fx, fy);
241  return std::make_shared<ForceType2>(ForceType2(id1, fx, fy));
242 }
243 
244 //=================================================================================================================
257  unsigned int id1,
258  double y,
259  double k,
260  double l0) : AbstractForceStruct(),
261  id1_(id1),
262  y_(y),
263  k_(k),
264  l0_(l0) {}
265 
266  void calculateForce(const std::map<unsigned int,
267  std::shared_ptr<nodes::GeometryNode> >& nodes) {
268  nodes::LagrangianPoint tempNode(nodes.at(this->id1_)->getXPos(), y_);
269  const double f = this->k_ * (nodes::getDistance(tempNode, *(nodes.at(this->id1_))) - this->l0_);
270  Field<double> force;
271  force.x = 0;
272  if (nodes.at(this->id1_)->getYPos() < this->y_) { // get the sign right
273  force.y = f;
274  }
275  else {
276  force.y = -f;
277  }
278  nodes.at(this->id1_)->addForce(force);
279  }
280 
281  void writeForceStruct(std::ofstream* const stream) const {
282  (*stream) << type << "\t" << id1_ << "\t" <<
283  y_ << "\t" << k_ << "\t" << l0_ << "\n";
284  }
285 
286  unsigned int getType() const {
287  return 3;
288  }
289 
290  unsigned int getPartnerGeometryNode(void) const {
291  return 0;
292  }
293 
294  private:
295  const unsigned int type = 3;
296  const unsigned int id1_;
297  const double y_;
298  const double k_;
299  const double l0_;
300 };
301 
307 std::shared_ptr<ForceType3> loadForceType3(std::stringstream* const stream) {
308  unsigned int type, id1;
309  double y, k, l0;
310  (*stream) >> type >> id1 >> y >> k >> l0;
311  return std::make_shared<ForceType3>(ForceType3(id1, y, k, l0));
312 }
313 
314 //=================================================================================================================
327  unsigned int id1,
328  double x,
329  double k,
330  double l0) : AbstractForceStruct(),
331  id1_(id1),
332  x_(x),
333  k_(k),
334  l0_(l0) {}
335 
336  void calculateForce(const std::map<unsigned int,
337  std::shared_ptr<nodes::GeometryNode> >& nodes) {
338  nodes::LagrangianPoint tempNode(x_, nodes.at(this->id1_)->getYPos());
339  const double f = this->k_ * (nodes::getDistance(tempNode, *(nodes.at(this->id1_))) - this->l0_);
340  Field<double> force;
341  if (nodes.at(this->id1_)->getXPos() < this->x_) {
342  force.x = f;
343  }
344  else {
345  force.x = -f;
346  }
347  force.y = 0;
348  nodes.at(this->id1_)->addForce(force);
349  }
350 
351  void writeForceStruct(std::ofstream* const stream) const {
352  (*stream) << type << "\t" << id1_ << "\t" <<
353  x_ << "\t" << k_ << "\t" << l0_ << "\n";
354  }
355 
356  unsigned int getType() const {
357  return 4;
358  }
359 
360  unsigned int getPartnerGeometryNode(void) const {
361  return 0;
362  }
363 
364  private:
365  const unsigned int type = 4;
366  const unsigned int id1_;
367  const double x_;
368  const double k_;
369  const double l0_;
370 };
371 
377 std::shared_ptr<ForceType4> loadForceType4(std::stringstream* const stream) {
378  unsigned int type, id1;
379  double x, k, l0;
380  (*stream) >> type >> id1 >> x >> k >> l0;
381 // return new ForceType4(id1, x, k, l0);
382  return std::make_shared<ForceType4>(ForceType4(id1, x, k, l0));
383 }
384 
385 //=================================================================================================================
398  unsigned int id1,
399  unsigned int id2,
400  double f) : AbstractForceStruct(),
401  id1_(id1),
402  id2_(id2),
403  f_(f) {}
404 
405  void calculateForce(const std::map<unsigned int,
406  std::shared_ptr<nodes::GeometryNode> >& nodes)
407  {
408  try {
409  nodes.at(this->id1_)->addForce(this->f_ *
410  (nodes.at(this->id2_)->getPos() - nodes.at(this->id1_)->getPos()) /
411  nodes::getDistance(*(nodes.at(this->id2_)), *(nodes.at(this->id1_))));
412  }
413  catch (...){
414  lbm_fail("Could not compute and set the forces.");
415  }
416  }
417 
418  void writeForceStruct(std::ofstream* const stream) const {
419  (*stream) << this->type << "\t" << this->id1_ << "\t" << this->id2_ << "\t" << this->f_ << "\n";
420  }
421 
422  unsigned int getType() const {
423  return 5;
424  }
425 
426  unsigned int getPartnerGeometryNode(void) const {
427  return this->id2_;
428  }
429 
430  private:
431  const unsigned int type = 5;
432  const unsigned int id1_;
433  const unsigned int id2_;
434  const double f_;
435 };
436 
442 std::shared_ptr<ForceType5> loadForceType5(std::stringstream* const stream) {
443  unsigned int type, id1, id2;
444  double f;
445  (*stream) >> type >> id1 >> id2 >> f;
446 // return new ForceType5(id1, id2, f);
447  return std::make_shared<ForceType5>(ForceType5(id1, id2, f));
448 }
449 
450 //=================================================================================================================
463  unsigned int id1,
464  unsigned int id2,
465  double f) : AbstractForceStruct(),
466  id1_(id1),
467  id2_(id2),
468  f_(f) {}
469 
470  void calculateForce(const std::map<unsigned int,
471  std::shared_ptr<nodes::GeometryNode> >& nodes)
472  {
473  assert(nodes.find(this->id1_) != nodes.end());
474  assert(nodes.find(this->id2_) != nodes.end());
475  try {
476  nodes.at(this->id1_)->addForce(this->f_ *
477  (nodes.at(this->id2_)->getPos() - nodes.at(this->id1_)->getPos()) /
478  nodes::getDistance(*(nodes.at(this->id2_)), *(nodes.at(this->id1_))));
479  }
480  catch (...){
481  lbm_fail("Could not compute and set the forces.");
482  }
483  }
484 
485  void writeForceStruct(std::ofstream* const stream) const {
486  (*stream) << this->type << "\t" << this->id1_ << "\t" << this->id2_ << "\t" << this->f_ << "\n";
487  }
488 
489  unsigned int getType() const {
490  return 6;
491  }
492 
493  unsigned int getPartnerGeometryNode(void) const {
494  return this->id2_;
495  }
496 
497  private:
498  const unsigned int type = 6;
499  const unsigned int id1_;
500  const unsigned int id2_;
501  const double f_;
502 };
503 
509 std::shared_ptr<ForceType6> loadForceType6(std::stringstream* const stream) {
510  unsigned int type, id1, id2;
511  double f;
512  (*stream) >> type >> id1 >> id2 >> f;
513  return std::make_shared<ForceType6>(ForceType6(id1, id2, f));
514 }
515 
516 //=================================================================================================================
530  unsigned int id1,
531  unsigned int id2,
532  double k,
533  double l0) : AbstractForceStruct(),
534  id1_(id1),
535  id2_(id2),
536  k_(k),
537  l0_(l0) {}
538 
539  void calculateForce(const std::map<unsigned int,
540  std::shared_ptr<nodes::GeometryNode> >& nodes)
541  {
542  try {
543  const double f = k_ *
544  (nodes::getDistance(*(nodes.at(this->id2_)),
545  *(nodes.at(this->id1_))) - this->l0_);
546 
547  nodes.at(this->id1_)->addForce(f *
548  (nodes.at(this->id2_)->getPos() - nodes.at(this->id1_)->getPos()) /
549  nodes::getDistance(*(nodes.at(this->id2_)), *(nodes.at(this->id1_))));
550  }
551  catch (...){
552  lbm_fail("Could not compute and set the forces.");
553  }
554  }
555 
556  void writeForceStruct(std::ofstream* const stream) const {
557  (*stream) << this->type << "\t" << this->id1_ << "\t" << this->id2_ << "\t" << this->k_ <<
558  "\t" << this->l0_ << "\n";
559  }
560 
561  unsigned int getType() const {
562  return 7;
563  }
564 
565  unsigned int getPartnerGeometryNode(void) const {
566  return this->id2_;
567  }
568 
569  private:
570  const unsigned int type = 7;
571  const unsigned int id1_;
572  const unsigned int id2_;
573  const double k_;
574  const double l0_;
575 };
576 
582 std::shared_ptr<ForceType7> loadForceType7(std::stringstream* const stream) {
583  unsigned int type, id1, id2;
584  double k, l0;
585  (*stream) >> type >> id1 >> id2 >> k >> l0;
586 // return new ForceType7(id1, id2, k, l0);
587  return std::make_shared<ForceType7>(ForceType7(id1, id2, k, l0));
588 }
589 
590 
591 
592 
593 } // end anonymous namespace
594 
595 }
596 }
597 
598 #endif // FORCESTRUCTS_HPP
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
a spring force between a node and a horzontal slider (sliding at hight y)
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
a spring force between a node and a certain point
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
ForceType0(unsigned int id1, unsigned int id2, double k, double l0)
the constructor of this force
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
unsigned int getType() const
Returns the force type.
ForceType3(unsigned int id1, double y, double k, double l0)
the constructor of this force
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
ForceType4(unsigned int id1, double x, double k, double l0)
the constructor of this force
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
a constant force between 2 nodes
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
T x
x the value in x direction
Definition: Field.hpp:50
unsigned int getType() const
Returns the force type.
unsigned int getType() const
Returns the force type.
a spring froce between 2 nodes
unsigned int getType() const
Returns the force type.
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
a constant force between 2 nodes
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
unsigned int getType() const
Returns the force type.
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
unsigned int getType() const
Returns the force type.
unsigned int getType() const
Returns the force type.
ForceType7(unsigned int id1, unsigned int id2, double k, double l0)
the constructor of this force
ForceType5(unsigned int id1, unsigned int id2, double f)
the constructor of this force
ForceType1(unsigned int id1, double x, double y, double k, double l0)
the constructor of this force
unsigned int getType() const
Returns the force type.
the base class for all forces
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
a spring force between a node and a vertical slider (sliding at width x)
Field< double > getPos() const
getPos Getter for the pos
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
a spring froce between 2 nodes
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
ForceType6(unsigned int id1, unsigned int id2, double f)
the constructor of this force
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the force on the geometry nodes
The LagrangianPoint class A class for storing a point's coordinates and its velocity This class is th...
unsigned int getPartnerGeometryNode(void) const
getPartnerGeometryNode
void writeForceStruct(std::ofstream *const stream) const
writes the force struct to the ostream
ForceType2(unsigned int id1, double fx, double fy)
the constructor of this force