92 bool skip_ic =
false);
106 Step(
const double* x,
const double* xd,
double* f,
double& t,
double& dt);
110 inline vector<Body*>
GetBodies()
const {
return BodyList; }
114 inline vector<Rod*>
GetRods()
const {
return RodList; }
118 inline vector<Point*>
GetPoints()
const {
return PointList; }
122 inline vector<Line*>
GetLines()
const {
return LineList; }
148 std::size_t n = 6 * CpldBodyIs.size() + 3 * CpldPointIs.size();
149 for (
auto rodi : CpldRodIs) {
155 return static_cast<unsigned int>(n);
182 const auto& points = waves->getWaveKinematicsPoints();
183 npW =
static_cast<unsigned int>(points.size());
213 for (
const auto&
vec : points) {
231 return waves->getWaveKinematicsPoints();
246 std::vector<vec>
const& Ud,
264 std::vector<vec>
const& Ud,
268 waves->setWaveKinematics(U, Ud);
305 void saveVTK(
const char* filename)
const;
320 for (
auto obj : LineList)
321 cfl = (std::max)(cfl, obj->dt2cfl(dtM0));
322 for (
auto obj : PointList)
323 cfl = (std::max)(cfl, obj->dt2cfl(dtM0));
324 for (
auto obj : RodList)
325 cfl = (std::max)(cfl, obj->dt2cfl(dtM0));
326 for (
auto obj : BodyList)
327 cfl = (std::max)(cfl, obj->dt2cfl(dtM0));
342 this->dtM0 = (std::numeric_limits<real>::max)();
343 for (
auto obj : LineList)
344 dtM0 = (std::min)(dtM0, obj->cfl2dt(cfl));
345 for (
auto obj : PointList)
346 dtM0 = (std::min)(dtM0, obj->cfl2dt(cfl));
347 for (
auto obj : RodList)
348 dtM0 = (std::min)(dtM0, obj->cfl2dt(cfl));
349 for (
auto obj : BodyList)
350 dtM0 = (std::min)(dtM0, obj->cfl2dt(cfl));
364 delete _t_integrator;
365 _t_integrator = tscheme;
367 for (
auto obj : BodyList)
369 for (
auto obj : RodList)
370 _t_integrator->
AddRod(obj);
371 for (
auto obj : PointList)
373 for (
auto obj : LineList)
375 _t_integrator->
SetCFL(cfl);
376 _t_integrator->
Init();
463 int supposedNumberOfEntries,
489 <<
"Warning: Forces have been asked on "
490 <<
"the coupled entities, but there are no such entities"
497 <<
" called with a NULL forces pointer, but there are "
498 <<
NCoupledDOF() <<
" coupled Degrees Of Freedom" << std::endl;
502 for (
auto l : CpldBodyIs) {
504 const vec6 f_i = BodyList[l]->getFnet();
513 for (
auto l : CpldRodIs) {
514 const vec6 f_i = RodList[l]->getFnet();
523 for (
auto l : CpldPointIs) {
525 PointList[l]->getFnet(fnet);
556 moordyn::waves::waves_settings WaveKinTemp;
579 vector<LineProps*> LinePropList;
581 vector<RodProps*> RodPropList;
583 vector<FailProps*> FailList;
585 vector<Body*> BodyList;
587 vector<Rod*> RodList;
589 vector<moordyn::Point*> PointList;
591 vector<moordyn::Line*> LineList;
594 vector<unsigned int> FreeBodyIs;
596 vector<unsigned int> FixedBodyIs;
598 vector<unsigned int> CpldBodyIs;
602 vector<unsigned int> FreeRodIs;
604 vector<unsigned int> CpldRodIs;
607 vector<unsigned int> FreePointIs;
609 vector<unsigned int> CpldPointIs;
616 bool disableOutput =
false;
619 bool disableOutTime =
false;
622 ofstream outfileMain;
625 vector<shared_ptr<ofstream>> outfiles;
628 vector<OutChanProps> outChans;
648 if (env->writeLog > 0) {
651 stringstream filepath;
652 filepath << _basepath << _basename <<
".log";
658 LOGERR <<
"Unable to create the log at '" << filepath.str()
659 <<
"': " << std::endl
660 << err_msg << std::endl;
662 LOGMSG <<
"MoorDyn v2 log file with output level "
664 << filepath.str() <<
"'" << std::endl;
687 y.push_back((
real)std::stold(entry));
691 }
catch (std::out_of_range) {
692 LOGERR <<
"" << std::endl;
694 }
catch (std::invalid_argument) {
698 string fpath = _basepath + entry;
699 LOGMSG <<
"Loading a curve from '" << fpath <<
"'..." << std::endl;
702 LOGERR <<
"Cannot read the file '" << fpath <<
"'" << std::endl;
706 vector<string> flines;
712 moordyn::str::rtrim(fline);
713 flines.push_back(fline);
720 LOGERR <<
"Error: Not enough curve data in curve file" << endl;
724 for (
auto fline : flines) {
725 vector<string> entries = moordyn::str::split(fline,
' ');
726 if (entries.size() < 2) {
727 LOGERR <<
"Error: Bad curve point" << std::endl
728 <<
"\t'" << fline <<
"'" << std::endl
729 <<
"\t2 fields required, but just " << entries.size()
730 <<
" are provided" << std::endl;
733 x.push_back(atof(entries[0].c_str()));
734 y.push_back(atof(entries[1].c_str()));
735 LOGDBG <<
"(" << x.back() <<
", " << y.back() <<
")" << std::endl;
738 LOGMSG << (i - 3) <<
" lines of curve successfully loaded" << std::endl;
762 vector<double> xv, yv;
767 if (xv.size() == 1) {
773 if (xv.size() > nCoef) {
775 <<
"Error: Too much points in the curve" << std::endl
776 <<
"\t" << xv.size() <<
" points given, but just " << nCoef
777 <<
" are accepted" << std::endl;
782 *n =
static_cast<unsigned int>(xv.size());
783 memcpy(x, xv.data(), xv.size() *
sizeof(
double));
784 memcpy(y, yv.data(), yv.size() *
sizeof(
double));
839 inline double GetOutput(
const OutChanProps channel)
const
841 if (channel.OType == 1)
842 return LineList[channel.ObjID - 1]->GetLineOutput(channel);
843 else if (channel.OType == 2)
844 return PointList[channel.ObjID - 1]->GetPointOutput(channel);
845 else if (channel.OType == 3)
846 return RodList[channel.ObjID - 1]->GetRodOutput(channel);
847 else if (channel.OType == 4)
848 return BodyList[channel.ObjID - 1]->GetBodyOutput(channel);
850 s <<
"Error: output type of " << channel.Name
851 <<
" does not match a supported object type";
#define LOGDBG
Log a debug message, without extra info about the source code.
Definition: Log.hpp:63
#define LOGMSG
Log an info message, without extra info about the source code.
Definition: Log.hpp:65
#define LOGERR
Log an error.
Definition: Log.hpp:69
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition: MoorDynAPI.h:68
#define __PRETTY_FUNC_NAME__
Macro that is substituted by the beautified function name.
Definition: MoorDynAPI.h:102
#define DEPRECATED
Prefix for deprecated functions that will be removed on a future version.
Definition: MoorDynAPI.h:85
A rigid body.
Definition: Body.hpp:72
@ COUPLED
Is coupled, i.e. is controlled by the user.
Definition: Body.hpp:155
void SetFile(const char *file_path)
Set the log file path.
Definition: Log.cpp:142
void SetLogLevel(const int level)
Set the log file printing level.
Definition: Log.hpp:190
MultiStream & Cout(const int level=MOORDYN_MSG_LEVEL) const
Get a stream to log data.
Definition: Log.cpp:118
Log * GetLogger() const
Get the log handler.
Definition: Log.hpp:248
Log * _log
The log handler.
Definition: Log.hpp:252
A Mooring system.
Definition: MoorDyn2.hpp:60
void SetDisableOutput(bool disable)
Set whether console and file output is disabled.
Definition: MoorDyn2.hpp:129
void DEPRECATED SetWaveKin(std::vector< vec > const &U, std::vector< vec > const &Ud, double t)
Set the kinematics of the waves.
Definition: MoorDyn2.hpp:245
moordyn::error_id ReadInFile()
Read the input file, setting up all the required objects and their relationships.
Definition: MoorDyn2.cpp:907
bool checkNumberOfEntriesInLine(vector< string > entries, int supposedNumberOfEntries, int lineNum)
Check that the provided entries match the expected ones.
Definition: MoorDyn2.cpp:2570
Body * readBody(string inputText, int lineNum)
Helper function to read a new body given a line from the input file.
Definition: MoorDyn2.cpp:2144
void SetTimeScheme(time::Scheme *tscheme)
Set the current time integrator.
Definition: MoorDyn2.hpp:361
moordyn::error_id icLegacy()
Compute an initial condition using the legacy upscaled drag dynamic solver.
Definition: MoorDyn2.cpp:197
moordyn::error_id readFileIntoBuffers(vector< string > &in_txt)
Read the input file and store it as a set of strings, one per line.
Definition: MoorDyn2.cpp:1910
real GetDt() const
Get the model time step.
Definition: MoorDyn2.hpp:310
DECLDIR ~MoorDyn()
Destructor.
Definition: MoorDyn2.cpp:163
std::vector< vec > ExternalWaveKinGetPoints() const
Get the points where the waves kinematics shall be provided.
Definition: MoorDyn2.hpp:229
void readOptionsLine(vector< string > &in_txt, int index)
Helper function to read an option given a line from the input file.
Definition: MoorDyn2.cpp:2453
unsigned int NCoupledDOF() const
Return the number of coupled Degrees Of Freedom (DOF)
Definition: MoorDyn2.hpp:146
real GetCFL() const
Get the model Courant–Friedrichs–Lewy factor.
Definition: MoorDyn2.hpp:333
unsigned int ExternalWaveKinInit()
Initializes the external Wave kinetics.
Definition: MoorDyn2.hpp:180
int findStartOfSection(vector< string > &in_txt, vector< string > sectionName)
Get the file line index where a section starts.
Definition: MoorDyn2.cpp:1929
moordyn::error_id DECLDIR Init(const double *x, const double *xd, bool skip_ic=false)
Initializes Moordyn, reading the input file and setting up the mooring lines.
Definition: MoorDyn2.cpp:433
moordyn::error_id DECLDIR Step(const double *x, const double *xd, double *f, double &t, double &dt)
Runs a time step of the MoorDyn system.
Definition: MoorDyn2.cpp:653
vector< Body * > GetBodies() const
Get the points.
Definition: MoorDyn2.hpp:110
moordyn::error_id icStationary()
Compute an initial condition using the stationary solver.
Definition: MoorDyn2.cpp:348
unsigned int ExternalWaveKinGetN() const
Get the number of points where the waves kinematics shall be provided.
Definition: MoorDyn2.hpp:196
DECLDIR MoorDyn(const char *infilename=NULL, int log_level=MOORDYN_MSG_LEVEL)
Constructor.
Definition: MoorDyn2.cpp:90
Rod * readRod(string inputText, int lineNum)
Helper function to read a new rod given a line from the input file.
Definition: MoorDyn2.cpp:2303
vector< Rod * > GetRods() const
Get the points.
Definition: MoorDyn2.hpp:114
std::vector< uint64_t > Serialize(void)
Produce the packed data to be saved.
Definition: MoorDyn2.cpp:799
void SetDt(real dt)
Set the model time step.
Definition: MoorDyn2.hpp:316
time::Scheme * GetTimeScheme() const
Get the current time integrator.
Definition: MoorDyn2.hpp:356
LineProps * readLineProps(string inputText, int lineNum)
Helper function to read a new line property given a line from the input file.
Definition: MoorDyn2.cpp:1949
RodProps * readRodProps(string inputText, int lineNum)
Helper function to read a new rod property given a line from the input file.
Definition: MoorDyn2.cpp:2112
moordyn::SeafloorRef GetSeafloor() const
Get the 3D seafloor instance.
Definition: MoorDyn2.hpp:173
vector< Line * > GetLines() const
Get the lines.
Definition: MoorDyn2.hpp:122
void SetCFL(real cfl)
Set the model Courant–Friedrichs–Lewy factor.
Definition: MoorDyn2.hpp:339
void ExternalWaveKinSet(std::vector< vec > const &U, std::vector< vec > const &Ud, double t)
Set the kinematics of the waves.
Definition: MoorDyn2.hpp:263
moordyn::error_id DEPRECATED GetWaveKinCoordinates(double *r) const
Get the points where the waves kinematics shall be provided.
Definition: MoorDyn2.hpp:209
uint64_t * Deserialize(const uint64_t *data)
Unpack the data to restore the Serialized information.
Definition: MoorDyn2.cpp:830
moordyn::WavesRef DECLDIR GetWaves() const
Get the wave kinematics instance.
Definition: MoorDyn2.hpp:165
moordyn::error_id GetForces(double *f) const
Get the forces.
Definition: MoorDyn2.hpp:484
void saveVTK(const char *filename) const
Save the whole system on a VTK (.vtm) file.
Definition: MoorDyn2.cpp:856
vector< Point * > GetPoints() const
Get the points.
Definition: MoorDyn2.hpp:118
A cylindrical rod.
Definition: Rod.hpp:65
@ COUPLED
Is attached rigidly to a coupling point (6dof)
Definition: Rod.hpp:235
A base class for all the entities that must save/load data to/from disk.
Definition: IO.hpp:60
Time scheme abstraction.
Definition: Time.hpp:59
virtual void AddPoint(Point *obj)
Add a point.
Definition: Time.hpp:106
virtual void AddLine(Line *obj)
Add a line.
Definition: Time.hpp:73
virtual void AddBody(Body *obj)
Add a body.
Definition: Time.hpp:172
virtual void AddRod(Rod *obj)
Add a rod.
Definition: Time.hpp:139
void SetGround(Body *obj)
Set the ground body.
Definition: Time.hpp:67
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.
struct moordyn::_FailProps FailProps
Failure conditions.
#define MOORDYN_INVALID_INPUT_FILE
Invalid input file path.
Definition: MoorDynAPI.h:145
#define MOORDYN_INVALID_VALUE
Invalid values.
Definition: MoorDynAPI.h:155
#define MOORDYN_INVALID_INPUT
Invalid input in the input file.
Definition: MoorDynAPI.h:149
#define MOORDYN_SUCCESS
Successfully dispatched task.
Definition: MoorDynAPI.h:143
#define MOORDYN_CATCHER(err, msg)
Definition: Misc.hpp:662
int error_id
Error identifier.
Definition: Misc.hpp:594
#define MOORDYN_THROW(err, msg)
Exception thrown for invalid input files.
Definition: Misc.hpp:628
#define MOORDYN_DBG_LEVEL
Debug message.
Definition: MoorDynAPI.h:126
#define MOORDYN_WRN_LEVEL
Warning message.
Definition: MoorDynAPI.h:122
#define MOORDYN_MSG_LEVEL
Info message.
Definition: MoorDynAPI.h:124
#define MOORDYN_ERR_LEVEL
Error message.
Definition: MoorDynAPI.h:120
#define MOORDYN_NO_OUTPUT
Disable the output since no output will never reach this level.
Definition: MoorDynAPI.h:128
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
std::string log_level_name(int level)
Name the log level.
Definition: Log.cpp:39
Eigen::Vector6d vec6
6-D vector of real numbers
Definition: Misc.hpp:126
double real
Real numbers wrapper. It is either double or float.
Definition: Misc.hpp:118
void vec62array(const vec6 &v, T *a)
Convert a vector to a C-ish array.
Definition: Misc.hpp:384
std::shared_ptr< Seafloor > SeafloorRef
Shared pointer.
Definition: Seafloor.hpp:109
void vec2array(const vec &v, T *a)
Convert a vector to a C-ish array.
Definition: Misc.hpp:358
Definition: Misc.hpp:1146
Definition: Misc.hpp:1292
Definition: Misc.hpp:1188