76 LOGERR <<
"The line " << obj->
number <<
" was already registered"
78 throw moordyn::invalid_value_error(
"Repeated object");
91 auto it = std::find(
lines.begin(),
lines.end(), obj);
92 if (it ==
lines.end()) {
93 LOGERR <<
"The line " << obj->
number <<
" was not registered"
95 throw moordyn::invalid_value_error(
"Missing object");
97 const unsigned int i = std::distance(
lines.begin(), it);
109 LOGERR <<
"The point " << obj->
number <<
" was already registered"
111 throw moordyn::invalid_value_error(
"Repeated object");
126 LOGERR <<
"The point " << obj->
number <<
" was not registered"
128 throw moordyn::invalid_value_error(
"Missing object");
130 const unsigned int i = std::distance(
points.begin(), it);
141 if (std::find(
rods.begin(),
rods.end(), obj) !=
rods.end()) {
142 LOGERR <<
"The rod " << obj->
number <<
" was already registered"
144 throw moordyn::invalid_value_error(
"Repeated object");
157 auto it = std::find(
rods.begin(),
rods.end(), obj);
158 if (it ==
rods.end()) {
159 LOGERR <<
"The rod " << obj->
number <<
" was not registered"
161 throw moordyn::invalid_value_error(
"Missing object");
163 const unsigned int i = std::distance(
rods.begin(), it);
175 LOGERR <<
"The body " << obj->
number <<
" was already registered"
177 throw moordyn::invalid_value_error(
"Repeated object");
192 LOGERR <<
"The body " << obj->
number <<
" was not registered"
194 throw moordyn::invalid_value_error(
"Missing object");
196 const unsigned int i = std::distance(
bodies.begin(), it);
238 for (
unsigned int i = 0; i <
lines.size(); i++) {
239 lines[i]->updateUnstretchedLength();
270 unsigned int i = 0) {};
277 inline virtual void SaveState(
const std::string filepath,
286 inline virtual void LoadState(
const std::string filepath,
334 #define AS_STATE(R) ((moordyn::state::State*)R)
341 template<
unsigned int NSTATE,
unsigned int NDERIV>
348 for (
unsigned int substep = 0; substep < NSTATE; substep++) {
351 for (
unsigned int substep = 0; substep < NDERIV; substep++) {
367 for (
unsigned int i = 0; i < NSTATE; i++)
369 for (
unsigned int i = 0; i < NDERIV; i++)
422 for (
unsigned int i = 0; i < NSTATE; i++)
424 for (
unsigned int i = 0; i < NDERIV; i++)
461 for (
unsigned int i = 0; i < NSTATE; i++)
463 for (
unsigned int i = 0; i < NDERIV; i++)
483 for (
unsigned int i = 0; i < NSTATE; i++)
485 for (
unsigned int i = 0; i < NDERIV; i++)
502 for (
unsigned int i = 0; i < NSTATE; i++)
504 for (
unsigned int i = 0; i < NDERIV; i++)
524 for (
unsigned int i = 0; i < NSTATE; i++)
526 for (
unsigned int i = 0; i < NDERIV; i++)
543 for (
unsigned int i = 0; i < NSTATE; i++)
545 for (
unsigned int i = 0; i < NDERIV; i++)
565 for (
unsigned int i = 0; i < NSTATE; i++)
567 for (
unsigned int i = 0; i < NDERIV; i++)
584 for (
unsigned int i = 0; i <
bodies.size(); i++) {
590 for (
unsigned int j = 0; j < NDERIV; j++)
594 for (
unsigned int i = 0; i <
rods.size(); i++) {
598 for (
unsigned int j = 0; j < NDERIV; j++)
602 for (
unsigned int i = 0; i <
points.size(); i++) {
606 for (
unsigned int j = 0; j < NDERIV; j++)
610 for (
unsigned int i = 0; i <
lines.size(); i++) {
612 for (
unsigned int j = 0; j < NDERIV; j++)
636 LOGERR <<
"State " << i <<
" cannot be got on a '" <<
name
637 <<
"' scheme that has " << NSTATE <<
"states" << endl;
638 throw moordyn::invalid_value_error(
"Invalid state");
657 LOGERR <<
"State " << i <<
" cannot be setted on a '" <<
name
658 <<
"' scheme that has " << NSTATE <<
" states" << endl;
659 throw moordyn::invalid_value_error(
"Invalid state");
670 inline virtual void SaveState(
const std::string filepath,
675 LOGERR <<
"State " << i <<
" cannot be saved on a '" <<
name
676 <<
"' scheme that has " << NSTATE <<
"states" << endl;
677 throw moordyn::invalid_value_error(
"Invalid state");
679 std::vector<uint64_t> data =
AS_STATE(
_r[i])->Serialize();
680 const uint64_t size = data.size();
681 f.write((
char*)&size,
sizeof(uint64_t));
682 for (
auto v : data) {
683 f.write((
char*)&v,
sizeof(uint64_t));
696 inline virtual void LoadState(
const std::string filepath,
699 auto [length, data] =
LoadFile(filepath);
701 LOGERR <<
"State " << i <<
" cannot be loaded on a '" <<
name
702 <<
"' scheme that has " << NSTATE <<
"states" << endl;
703 throw moordyn::invalid_value_error(
"Invalid state");
705 const uint64_t* end =
AS_STATE(
_r[i])->Deserialize(data);
706 if (data + length != end) {
707 const uint64_t l = end - data;
708 LOGERR << l *
sizeof(uint64_t) <<
" bytes (vs. "
709 << length *
sizeof(uint64_t)
710 <<
" bytes expected) unpacked from '" << filepath <<
"'"
712 throw moordyn::mem_error(
"Mismatching data size");
727 LOGERR <<
"State derivative " << i <<
" cannot be got on a '"
728 <<
name <<
"' scheme that has " << NDERIV
729 <<
"state derivatives" << endl;
730 throw moordyn::invalid_value_error(
"Invalid state derivative");
743 std::vector<uint64_t> data, subdata;
752 for (
unsigned int substep = 0; substep < NSTATE; substep++) {
753 subdata =
_r[substep]->Serialize();
754 data.insert(data.end(), subdata.begin(), subdata.end());
756 for (
unsigned int substep = 0; substep < NDERIV; substep++) {
757 subdata =
_rd[substep]->Serialize();
758 data.insert(data.end(), subdata.begin(), subdata.end());
773 uint64_t* ptr = (uint64_t*)data;
780 for (
unsigned int substep = 0; substep < NSTATE; substep++) {
781 ptr =
_r[substep]->Deserialize(ptr);
783 for (
unsigned int substep = 0; substep < NDERIV; substep++) {
784 ptr =
_rd[substep]->Deserialize(ptr);
805 for (
unsigned int substep = 0; substep < NSTATE; substep++) {
808 for (
unsigned int substep = 0; substep < NDERIV; substep++) {
830 std::array<moordyn::state::State*, NSTATE>
_r;
833 std::array<moordyn::state::State*, NDERIV>
_rd;
904 for (
size_t i = 0; i <
lines.size(); i++)
905 n +=
lines[i]->stateN();
918 void MakeStationary(
real& dt,
unsigned int i = 0,
unsigned int id = 0);
961 template<
unsigned int NSTATE,
unsigned int NDERIV>
1015 typedef struct _sdeltat
1018 std::vector<real>
lines;
1020 std::vector<real>
points;
1022 std::vector<real>
rods;
1024 std::vector<real>
bodies;
1153 template<
unsigned int order,
bool local>
1207 unsigned int n_steps;
1212 inline void shift(
unsigned int org)
1214 const unsigned int dst = org + 1;
1215 for (
unsigned int i = 0; i <
lines.size(); i++) {
1221 for (
unsigned int i = 0; i <
points.size(); i++) {
1228 for (
unsigned int i = 0; i <
rods.size(); i++) {
1235 for (
unsigned int i = 0; i <
bodies.size(); i++) {
1247 for (
unsigned int i = 0; i <
_rd.size() - 1; i++)
1257 template<
unsigned int NSTATE,
unsigned int NDERIV>
1268 unsigned int iters = 10);
1277 inline unsigned int iters()
const {
return _iters; }
1309 unsigned int _iters;
1337 unsigned int iters = 10,
1338 real dt_factor = 0.5);
1375 unsigned int iters = 10,
1407 void MakeNewmark(
const real& dt);
1440 unsigned int iters = 10,
1473 void MakeWilson(
const real& tau,
const real& dt);
#define LOGERR
Log an error.
Definition: Log.hpp:69
#define AS_STATE(R)
Definition: Time.hpp:334
A rigid body.
Definition: Body.hpp:72
@ FREE
Is free to move, controlled by MoorDyn.
Definition: Body.hpp:157
@ CPLDPIN
Is coupled pinned, i.e. translational dof are controlled by the user.
Definition: Body.hpp:161
int number
Body number.
Definition: Body.hpp:189
A mooring line.
Definition: Line.hpp:71
int number
Line ID.
Definition: Line.hpp:424
A Logging utility.
Definition: Log.hpp:149
A point for a line endpoint.
Definition: Point.hpp:69
int number
Point number.
Definition: Point.hpp:190
@ FREE
Is free to move, controlled by MoorDyn.
Definition: Point.hpp:159
A cylindrical rod.
Definition: Rod.hpp:65
int number
Rod number.
Definition: Rod.hpp:277
@ PINNED
Definition: Rod.hpp:242
@ FREE
Is free to move, controlled by MoorDyn.
Definition: Rod.hpp:239
A base class for all the entities that must save/load data to/from disk.
Definition: IO.hpp:60
IO(moordyn::Log *log)
Costructor.
Definition: IO.cpp:195
ofstream MakeFile(const std::string filepath) const
Create an output file and write the MoorDyn magic header.
Definition: IO.cpp:236
std::tuple< uint64_t, uint64_t * > LoadFile(const std::string filepath) const
Open an input file and load the data.
Definition: IO.cpp:253
virtual std::vector< uint64_t > Serialize(void)=0
Produce the packed data to be saved.
virtual uint64_t * Deserialize(const uint64_t *data)=0
Unpack the data to restore the Serialized information.
The collection of state variables of the whole system.
Definition: State.hpp:54
Adam-Bashforth time schemes collection.
Definition: Time.hpp:1155
~ABScheme()
Destructor.
Definition: Time.hpp:1164
virtual uint64_t * Deserialize(const uint64_t *data)
Unpack the data to restore the Serialized information.
Definition: Time.hpp:1195
ABScheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:511
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:530
virtual std::vector< uint64_t > Serialize(void)
Produce the packed data to be saved.
Definition: Time.hpp:1179
The simplest 1st order Euler's time scheme.
Definition: Time.hpp:937
EulerScheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:284
virtual ~EulerScheme()
Destructor.
Definition: Time.hpp:946
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:291
Quasi 2nd order Heun's time scheme.
Definition: Time.hpp:1071
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:414
~HeunScheme()
Destructor.
Definition: Time.hpp:1080
HeunScheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:407
Implicit 1st order Euler time scheme.
Definition: Time.hpp:1326
ImplicitEulerScheme(moordyn::Log *log, WavesRef waves, unsigned int iters=10, real dt_factor=0.5)
Constructor.
Definition: Time.cpp:596
virtual ~ImplicitEulerScheme()
Destructor.
Definition: Time.hpp:1341
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:609
Implicit Newmark Scheme.
Definition: Time.hpp:1364
~ImplicitNewmarkScheme()
Destructor.
Definition: Time.hpp:1380
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:656
ImplicitNewmarkScheme(moordyn::Log *log, WavesRef waves, unsigned int iters=10, real gamma=0.5, real beta=0.25)
Constructor.
Definition: Time.cpp:638
A generic abstract implicit scheme.
Definition: Time.hpp:1259
virtual ~ImplicitSchemeBase()
Destructor.
Definition: Time.hpp:1271
void c1(const real c)
Set the tanh relaxation part coefficient.
Definition: Time.hpp:1297
real c1() const
Get the tanh relaxation part coefficient.
Definition: Time.hpp:1292
real c0() const
Get the constant relaxation part coefficient.
Definition: Time.hpp:1282
real Relax(const unsigned int &iter)
Compute the relaxation factor.
Definition: Time.cpp:588
void c0(const real c)
Set the constant relaxation part coefficient.
Definition: Time.hpp:1287
ImplicitSchemeBase(moordyn::Log *log, WavesRef waves, unsigned int iters=10)
Constructor.
Definition: Time.cpp:576
unsigned int iters() const
Get the number of subiterations.
Definition: Time.hpp:1277
Definition: Time.hpp:1429
~ImplicitWilsonScheme()
Destructor.
Definition: Time.hpp:1444
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:761
ImplicitWilsonScheme(moordyn::Log *log, WavesRef waves, unsigned int iters=10, real theta=1.37)
Constructor.
Definition: Time.cpp:746
A modification of the 1st order Euler's time scheme, which is considering different time steps for ea...
Definition: Time.hpp:1046
void Step(real &dt)
Run a time step.
Definition: Time.cpp:396
~LocalEulerScheme()
Destructor.
Definition: Time.hpp:1055
LocalEulerScheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:389
A generic abstract integration scheme.
Definition: Time.hpp:963
virtual ~LocalSchemeBase()
Destructor.
Definition: Time.hpp:966
LocalSchemeBase(moordyn::Log *log, moordyn::WavesRef waves)
Costructor.
Definition: Time.hpp:995
void SetCalcMask(real &dt)
Set the calculation mask.
Definition: Time.cpp:303
void Init()
Create an initial state for all the entities.
Definition: Time.hpp:973
virtual void SetState(const state::State &state, unsigned int i=0)
Resume the simulation from the stationary solution.
Definition: Time.hpp:983
2nd order Runge-Kutta time scheme
Definition: Time.hpp:1096
RK2Scheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:434
~RK2Scheme()
Destructor.
Definition: Time.hpp:1105
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:441
4th order Runge-Kutta time scheme
Definition: Time.hpp:1124
virtual void Step(real &dt)
Run a time step.
Definition: Time.cpp:469
RK4Scheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:462
~RK4Scheme()
Destructor.
Definition: Time.hpp:1133
A generic abstract integration scheme.
Definition: Time.hpp:343
mask _calc_mask
The SchemeBase::CalcStateDeriv() mask.
Definition: Time.hpp:855
virtual void AddPoint(Point *obj)
Add a point.
Definition: Time.hpp:454
state::State * rd(unsigned int i=0)
Get the state derivative.
Definition: Time.hpp:724
void Update(real t_local, unsigned int substep=0)
Update all the entities to set the state.
Definition: Time.cpp:42
virtual void AddRod(Rod *obj)
Add a rod.
Definition: Time.hpp:495
virtual uint64_t * Deserialize(const uint64_t *data)
Unpack the data to restore the Serialized information.
Definition: Time.hpp:771
virtual void AddBody(Body *obj)
Add a body.
Definition: Time.hpp:536
virtual unsigned int RemoveBody(Body *obj)
Remove a body.
Definition: Time.hpp:557
SchemeBase(moordyn::Log *log, moordyn::WavesRef waves)
Constructor.
Definition: Time.hpp:796
virtual void Step(real &dt)
Run a time step.
Definition: Time.hpp:624
void CalcStateDeriv(unsigned int substep=0)
Compute the time derivatives and store them.
Definition: Time.cpp:95
virtual unsigned int RemoveLine(Line *obj)
Remove a line.
Definition: Time.hpp:414
virtual unsigned int RemoveRod(Rod *obj)
Remove a rod.
Definition: Time.hpp:516
virtual std::vector< uint64_t > Serialize(void)
Produce the packed data to be saved.
Definition: Time.hpp:741
virtual unsigned int RemovePoint(Point *obj)
Remove a point.
Definition: Time.hpp:475
virtual void Init()
Create an initial state for all the entities.
Definition: Time.hpp:578
std::array< moordyn::state::State *, NDERIV > _rd
The list of state derivatives.
Definition: Time.hpp:833
state::State GetState(unsigned int i=0)
Get the state variable.
Definition: Time.hpp:643
std::shared_ptr< Waves > waves
The waves instance.
Definition: Time.hpp:836
virtual void LoadState(const std::string filepath, unsigned int i=0)
Load the system state from a file.
Definition: Time.hpp:696
std::array< moordyn::state::State *, NSTATE > _r
The list of states.
Definition: Time.hpp:830
virtual void SaveState(const std::string filepath, unsigned int i=0)
Save the system state on a file.
Definition: Time.hpp:670
struct moordyn::time::SchemeBase::_mask mask
A mask to determine which entities shall be computed.
virtual void AddLine(Line *obj)
Add a line.
Definition: Time.hpp:360
virtual void SetState(const state::State &state, unsigned int i=0)
Resume the simulation from the stationary solution.
Definition: Time.hpp:654
state::State * r(unsigned int i=0)
Get the state.
Definition: Time.hpp:633
virtual ~SchemeBase()
Destructor.
Definition: Time.hpp:346
Time scheme abstraction.
Definition: Time.hpp:59
real cfl
Maximum CFL factor.
Definition: Time.hpp:326
virtual void AddPoint(Point *obj)
Add a point.
Definition: Time.hpp:106
virtual void AddLine(Line *obj)
Add a line.
Definition: Time.hpp:73
std::vector< Rod * > rods
The rods.
Definition: Time.hpp:312
virtual unsigned int RemoveLine(Line *obj)
Remove a line.
Definition: Time.hpp:89
virtual void SetState(const moordyn::state::State &state, unsigned int i=0)
Resume the simulation from the stationary solution.
Definition: Time.hpp:269
void Next()
Prepare everything for the next outer time step.
Definition: Time.hpp:235
void SetTime(const real &time)
Set the simulation time.
Definition: Time.hpp:215
std::string name
The scheme name.
Definition: Time.hpp:318
virtual void SaveState(const std::string filepath, unsigned int i=0)
Save the system state on a file.
Definition: Time.hpp:277
real t_local
The local time, within the outer time step.
Definition: Time.hpp:323
Scheme(moordyn::Log *log)
Constructor.
Definition: Time.hpp:295
std::vector< Line * > lines
The lines.
Definition: Time.hpp:306
std::vector< Point * > points
The points.
Definition: Time.hpp:309
virtual void Step(real &dt)
Run a time step.
Definition: Time.hpp:257
real t
The simulation time.
Definition: Time.hpp:321
real GetTime() const
Get the simulation time.
Definition: Time.hpp:209
virtual void AddBody(Body *obj)
Add a body.
Definition: Time.hpp:172
std::vector< Body * > bodies
The bodies.
Definition: Time.hpp:315
virtual unsigned int RemoveBody(Body *obj)
Remove a body.
Definition: Time.hpp:188
virtual moordyn::state::State GetState(unsigned int i=0)=0
Get the state variable.
virtual void AddRod(Rod *obj)
Add a rod.
Definition: Time.hpp:139
virtual ~Scheme()
Destructor.
Definition: Time.hpp:62
void SetGround(Body *obj)
Set the ground body.
Definition: Time.hpp:67
std::string GetName() const
Get the name of the scheme.
Definition: Time.hpp:204
void SetCFL(const real &cfl)
Set the CFL factor.
Definition: Time.hpp:229
virtual void Init()=0
Create an initial state for all the entities.
virtual unsigned int RemoveRod(Rod *obj)
Remove a rod.
Definition: Time.hpp:155
virtual unsigned int RemovePoint(Point *obj)
Remove a point.
Definition: Time.hpp:122
virtual void LoadState(const std::string filepath, unsigned int i=0)
Load the system state from a file.
Definition: Time.hpp:286
real GetCFL() const
Get the CFL factor.
Definition: Time.hpp:224
Body * ground
The ground body.
Definition: Time.hpp:303
A stationary solution.
Definition: Time.hpp:865
~StationaryScheme()
Destructor.
Definition: Time.hpp:874
StationaryScheme(moordyn::Log *log, WavesRef waves)
Constructor.
Definition: Time.cpp:151
real Error() const
Get the error computed at the last time step.
Definition: Time.hpp:886
void Step(real &dt)
Run a time step.
Definition: Time.cpp:176
size_t NStates() const
Compute the number of state variables.
Definition: Time.hpp:897
MoorDyn2 C++ API namespace.
Definition: Body.cpp:27
std::shared_ptr< Waves > WavesRef
Definition: Body.hpp:53
double real
Real numbers wrapper. It is either double or float.
Definition: Misc.hpp:118
A mask to determine which entities shall be computed.
Definition: Time.hpp:843
std::vector< bool > lines
The lines mask.
Definition: Time.hpp:845
std::vector< bool > rods
The rods mask.
Definition: Time.hpp:849
std::vector< bool > bodies
The bodies mask.
Definition: Time.hpp:851
std::vector< bool > points
The points mask.
Definition: Time.hpp:847