MoorDyn
Point.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022, Matt Hall
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
35 #pragma once
36 
37 #include "Misc.hpp"
38 #include "Instance.hpp"
39 #include "Seafloor.hpp"
40 #include "Util/CFL.hpp"
41 #include "leanvtk/leanvtk.hpp"
42 #include <utility>
43 
44 using namespace std;
45 
46 namespace moordyn {
47 
48 class Line;
49 class Waves;
50 typedef std::shared_ptr<Waves> WavesRef;
51 
66 class DECLDIR Point final
67  : public Instance
68  , public SuperCFL
69 {
70  public:
75  Point(moordyn::Log* log, size_t id);
76 
79  ~Point();
80 
82  typedef struct _attachment
83  {
88  } attachment;
89 
90  private:
91  // ENVIRONMENTAL STUFF
93  EnvCondRef env;
95  moordyn::WavesRef waves;
96  moordyn::SeafloorRef seafloor;
97 
99  std::vector<attachment> attached;
100 
106  real pointM;
108  real pointV;
110  vec pointF;
112  real pointCdA;
114  real pointCa;
115 
125  vec r;
127  vec rd;
128 
134  vec r_ves;
136  vec rd_ves;
137 
139  vec Fnet;
140 
141  // time
143  moordyn::real t;
144 
146  mat M;
147 
149  vec acc;
150 
151  public:
154  typedef enum
155  {
157  COUPLED = -1,
159  FREE = 0,
161  FIXED = 1,
162  // Some aliases
163  VESSEL = COUPLED,
164  FAIRLEAD = COUPLED,
165  POINT = FREE,
166  ANCHOR = FIXED,
167  } types;
168 
173  static string TypeName(types t)
174  {
175  switch (t) {
176  case COUPLED:
177  return "COUPLED";
178  case FREE:
179  return "FREE";
180  case FIXED:
181  return "FIXED";
182  }
183  return "UNKNOWN";
184  }
185 
187  size_t pointId;
188 
190  int number;
193 
197  inline void setTime(real time) { t = time; }
198 
214  void setup(int number_in,
215  types type_in,
216  vec r0_in,
217  double M_in,
218  double V_in,
219  vec F_in,
220  double CdA_in,
221  double Ca_in,
222  EnvCondRef env_in);
223 
228  void addLine(moordyn::Line* theLine, EndPoints end_point);
229 
236  EndPoints removeLine(Line* line);
237 
241  inline std::vector<attachment> getLines() const { return attached; }
242 
248  std::pair<vec, vec> initialize();
249 
251  {
252  const auto [pos, vel] = initialize();
253  r.row(0).head<3>() = pos;
254  r.row(0).tail<3>() = vel;
255  }
263  inline const vec& getPosition() const { return r; }
264 
268  inline const vec& getVelocity() const { return rd; }
269 
274  inline void getState(vec& r_out, vec& rd_out)
275  {
276  r_out = r;
277  rd_out = rd;
278  };
279 
283  inline std::pair<vec, vec> getState() { return std::make_pair(r, rd); }
284 
288  inline void getFnet(vec& Fnet_out) const { Fnet_out = Fnet; }
289 
293  inline const vec& getFnet() const { return Fnet; }
294 
298  inline void getM(mat& M_out) const { M_out = M; }
299 
303  inline const mat& getM() const { return M; };
304 
309  real GetPointOutput(OutChanProps outChan);
310 
315  inline void setWaves(moordyn::WavesRef waves_in,
316  moordyn::SeafloorRef seafloor_in)
317  {
318  waves = waves_in; // set pointer to Waves object
319  seafloor = seafloor_in;
320  }
321 
327  inline void scaleDrag(real scaler) { pointCdA *= scaler; }
328 
337  void initiateStep(vec rFairIn, vec rdFairIn);
338 
346  void updateFairlead(real time);
347 
356  void setKinematics(vec r_in, vec rd_in);
357 
367  void setState(vec pos, vec vel);
368 
377  inline void setState(const InstanceStateVarView r)
378  {
379  setState(r.row(0).head<3>(),
380  r.row(0).tail<3>()); // TODO: when working on line failures,
381  // make this setState call match rods,
382  // bodies, and lines structure
383  }
384 
390  void getStateDeriv(InstanceStateVarView drdt);
391 
399  void getNetForceAndMass(vec6& Fnet_out,
400  mat6& M_out,
401  vec rBody = vec::Zero(),
402  vec6 vBody = vec6::Zero());
403 
409  moordyn::error_id doRHS();
410 
414  inline const size_t stateN() const { return 1; }
415 
421  inline const size_t stateDims() const { return 6; }
422 
432  std::vector<uint64_t> Serialize(void);
433 
440  uint64_t* Deserialize(const uint64_t* data);
441 
446  void saveVTK(const char* filename);
447 
453  const leanvtk::VTPWriter* getVTK() const { return &vtk; }
454 
455  private:
457  leanvtk::VTPWriter vtk;
458 
464  inline vec getCentripetalForce(vec r, vec w) const
465  {
466  return -M * (w.cross(w.cross(this->r - r)));
467  }
468 };
469 
470 } // ::moordyn
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition: MoorDynAPI.h:68
A generic instance.
Definition: Instance.hpp:55
A mooring line.
Definition: Line.hpp:71
A Logging utility.
Definition: Log.hpp:149
A point for a line endpoint.
Definition: Point.hpp:69
void initialize(InstanceStateVarView r)
Initialize a free instance.
Definition: Point.hpp:250
static string TypeName(types t)
Return a string with the name of a type.
Definition: Point.hpp:173
void setTime(real time)
Set the line simulation time.
Definition: Point.hpp:197
size_t pointId
Point ID.
Definition: Point.hpp:187
const size_t stateDims() const
Get the dimension of the state variable.
Definition: Point.hpp:421
const vec & getVelocity() const
Get the point velocity.
Definition: Point.hpp:268
const mat & getM() const
Get the mass matrix.
Definition: Point.hpp:303
void getFnet(vec &Fnet_out) const
Get the force on the point.
Definition: Point.hpp:288
const vec & getPosition() const
Get the point position.
Definition: Point.hpp:263
std::vector< attachment > getLines() const
Get the list of attachments.
Definition: Point.hpp:241
const vec & getFnet() const
Get the force on the point.
Definition: Point.hpp:293
void setWaves(moordyn::WavesRef waves_in, moordyn::SeafloorRef seafloor_in)
Set the environmental data.
Definition: Point.hpp:315
void getState(vec &r_out, vec &rd_out)
Get the point state.
Definition: Point.hpp:274
int number
Point number.
Definition: Point.hpp:190
std::pair< vec, vec > getState()
Get the point state.
Definition: Point.hpp:283
void setState(const InstanceStateVarView r)
Set the point state.
Definition: Point.hpp:377
void scaleDrag(real scaler)
Multiply the drag by a factor.
Definition: Point.hpp:327
types
Types of points.
Definition: Point.hpp:155
const leanvtk::VTPWriter * getVTK() const
Get the VTK writer.
Definition: Point.hpp:453
const size_t stateN() const
Get the number of state variables required by this instance.
Definition: Point.hpp:414
void getM(mat &M_out) const
Get the mass matrix.
Definition: Point.hpp:298
types type
Point type.
Definition: Point.hpp:192
int error_id
Error identifier.
Definition: Misc.hpp:594
MoorDyn2 C++ API namespace.
Definition: Body.cpp:27
vec3 vec
vec3 renaming
Definition: Misc.hpp:130
std::shared_ptr< Waves > WavesRef
Definition: Body.hpp:53
Eigen::Block< InstanceStateVar, Eigen::Dynamic > InstanceStateVarView
View of the State variables for a particular instance.
Definition: Misc.hpp:167
Eigen::Vector6d vec6
6-D vector of real numbers
Definition: Misc.hpp:126
Eigen::Matrix6d mat6
6x6 matrix of real numbers
Definition: Misc.hpp:138
EndPoints
End point qualifiers.
Definition: Misc.hpp:570
double real
Real numbers wrapper. It is either double or float.
Definition: Misc.hpp:118
std::shared_ptr< Seafloor > SeafloorRef
Shared pointer.
Definition: Seafloor.hpp:109
mat3 mat
mat3 renaming
Definition: Misc.hpp:142
Definition: Misc.hpp:1292
Attached lines to the point.
Definition: Point.hpp:83
EndPoints end_point
The attachment end point.
Definition: Point.hpp:87
Line * line
The attached line.
Definition: Point.hpp:85