Skip to content

Commit f7c7dfb

Browse files
feat(core)!: Line breaking utilities (#379)
1 parent 094ecff commit f7c7dfb

14 files changed

Lines changed: 379 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22
set(MOORDYN_MAJOR_VERSION 2)
3-
set(MOORDYN_MINOR_VERSION 6)
4-
set(MOORDYN_PATCH_VERSION 2)
3+
set(MOORDYN_MINOR_VERSION 7)
4+
set(MOORDYN_PATCH_VERSION 0)
55
set(MOORDYN_VERSION ${MOORDYN_MAJOR_VERSION}.${MOORDYN_MINOR_VERSION})
66
project(Moordyn VERSION ${MOORDYN_VERSION})
77

source/IO.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,6 @@ IO::LoadFile(const std::string filepath) const
278278
uint8_t major, minor;
279279
f.read((char*)&major, sizeof(uint8_t));
280280
f.read((char*)&minor, sizeof(uint8_t));
281-
std::cout << major << std::endl;
282-
std::cout << minor << std::endl;
283-
std::cout << _min_major_version << std::endl;
284-
std::cout << _min_minor_version << std::endl;
285-
std::cout << "number=" << 7 << std::endl;
286281
if ((major < _min_major_version) ||
287282
((major == _min_major_version) && (minor < _min_minor_version))) {
288283
LOGERR << "The file '" << filepath << "' was written by MoorDyn "

source/MoorDyn2.cpp

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,41 @@ moordyn::MoorDyn::Step(const double* x,
795795
return MOORDYN_SUCCESS;
796796
}
797797

798+
void
799+
MoorDyn::BreakLine(moordyn::Point* point, moordyn::Line* line)
800+
{
801+
// Detach the line from the point
802+
moordyn::EndPoints end_point;
803+
auto pt_attachments = point->getLines();
804+
for (auto attachment : pt_attachments) {
805+
if (attachment.line == line) {
806+
end_point = attachment.end_point;
807+
}
808+
}
809+
point->removeLine(line);
810+
// Create the new point
811+
moordyn::Point *pt = new Point(point, PointList.size());
812+
PointList.push_back(pt);
813+
waves->addPoint(pt);
814+
_t_integrator->AddPoint(pt);
815+
// Set the state of the point
816+
auto state = _t_integrator->r(0);
817+
pt->initialize(state->get(pt));
818+
for (unsigned int i = 1; i < _t_integrator->GetNState(); i++) {
819+
_t_integrator->r(i)->get(pt) = state->get(pt);
820+
}
821+
for (unsigned int i = 0; i < _t_integrator->GetNDeriv(); i++) {
822+
_t_integrator->rd(i)->get(pt).row(0)(Eigen::seqN(0, 3)) =
823+
state->get(pt).row(0)(Eigen::seqN(3, 3));
824+
// NOTE: Although when cloning free points we can actually get the
825+
// acceleration, I (Jose Luis Cercos-Pita) do not think is worthy, so
826+
// I am simply setting no acceleration
827+
_t_integrator->rd(i)->get(pt).row(0)(Eigen::seqN(3, 3)) = vec::Zero();
828+
}
829+
// Attach the line to the point
830+
pt->addLine(line, end_point);
831+
}
832+
798833
std::vector<uint64_t>
799834
MoorDyn::Serialize(void)
800835
{
@@ -1155,8 +1190,7 @@ moordyn::MoorDyn::ReadInFile()
11551190
env->WtrDpth = -r0[2];
11561191
LOGWRN << "\t Water depth set to point " << PointList.size() + 1
11571192
<< " z position because point was specified below the "
1158-
"seabed"
1159-
<< endl;
1193+
"seabed" << endl;
11601194
}
11611195

11621196
// Check point ID is sequential starting from 1
@@ -3137,6 +3171,28 @@ MoorDyn_GetFASTtens(MoorDyn system,
31373171
return MOORDYN_SUCCESS;
31383172
}
31393173

3174+
int DECLDIR
3175+
MoorDyn_BreakLine(MoorDyn system,
3176+
MoorDynPoint point,
3177+
MoorDynLine line)
3178+
{
3179+
CHECK_SYSTEM(system);
3180+
3181+
moordyn::error_id err = MOORDYN_SUCCESS;
3182+
string err_msg;
3183+
try {
3184+
((moordyn::MoorDyn*)system)->BreakLine((moordyn::Point*)point,
3185+
(moordyn::Line*)line);
3186+
}
3187+
MOORDYN_CATCHER(err, err_msg);
3188+
if (err != MOORDYN_SUCCESS) {
3189+
cerr << "Error (" << err << ") at " << __FUNC_NAME__ << "():" << endl
3190+
<< err_msg << endl;
3191+
return err;
3192+
}
3193+
return MOORDYN_SUCCESS;
3194+
}
3195+
31403196
int DECLDIR
31413197
MoorDyn_GetDt(MoorDyn system, double* dt)
31423198
{

source/MoorDyn2.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,21 @@ MoorDyn_GetFASTtens(MoorDyn system,
435435
float AnchHTen[],
436436
float AnchVTen[]);
437437

438+
/** @brief Break a line on a specific point
439+
*
440+
* This method is dettaching a line from the point, and in exchange is
441+
* creating a point duplicate of type moordyn::Point::types::FREE
442+
* @param system The Moordyn system
443+
* @param point The discconection point
444+
* @param line The line that is dettaching from the point
445+
* @throw MOORDYN_SUCESS If the line is correctly dettached, an error code
446+
* otherwise (see @ref moordyn_errors)
447+
*/
448+
int DECLDIR
449+
MoorDyn_BreakLine(MoorDyn system,
450+
MoorDynPoint point,
451+
MoorDynLine line);
452+
438453
/** @brief Get the current model time step
439454
* @param system The Moordyn system
440455
* @param dt The output time step

source/MoorDyn2.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ class MoorDyn final : public io::IO
268268
waves->setWaveKinematics(U, Ud);
269269
}
270270

271+
/** @brief Break a line on a specific point
272+
*
273+
* This method is dettaching a line from the point, and in exchange is
274+
* creating a point duplicate of type moordyn::Point::types::FREE
275+
* @param point The discconection point
276+
* @param line The line that is dettaching from the point
277+
* @throw moordyn::invalid_value_error If the line is not attached to the
278+
* point.
279+
*/
280+
void BreakLine(moordyn::Point* point, moordyn::Line* line);
281+
271282
/** @brief Produce the packed data to be saved
272283
*
273284
* The produced data can be used afterwards to restore the saved information

source/Point.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,36 @@ namespace moordyn {
3838

3939
Point::Point(moordyn::Log* log, size_t id)
4040
: Instance(log)
41+
, waves(nullptr)
4142
, seafloor(nullptr)
4243
, pointId(id)
4344
{
4445
vtk.set_binary();
4546
}
4647

48+
Point::Point(Point* visitor, size_t id)
49+
: Instance(visitor->GetLogger())
50+
, env(visitor->env)
51+
, waves(visitor->waves)
52+
, seafloor(visitor->seafloor)
53+
, pointM(visitor->pointM)
54+
, pointV(visitor->pointV)
55+
, pointF(visitor->pointF)
56+
, pointCdA(visitor->pointCdA)
57+
, pointCa(visitor->pointCa)
58+
, r(visitor->r)
59+
, rd(visitor->rd)
60+
, Fnet(visitor->Fnet)
61+
, t(visitor->t)
62+
, M(visitor->M)
63+
, acc(visitor->acc)
64+
, pointId(id)
65+
, number(id + 1)
66+
, type(types::FREE)
67+
{
68+
vtk.set_binary();
69+
}
70+
4771
Point::~Point() {}
4872

4973
void
@@ -150,7 +174,9 @@ Point::initialize()
150174
seafloor ? seafloor->getDepthAt(r[0], r[1]) : -env->WtrDpth;
151175
if (waterDepth > r[2]) {
152176
LOGERR << "Error: water depth is shallower than Point " << number
153-
<< "." << endl;
177+
<< "." << endl
178+
<< "\tseabed z = " << waterDepth << endl
179+
<< "\tpoint = " << r << endl;
154180
throw moordyn::invalid_value_error("Invalid water depth");
155181
}
156182
}

source/Point.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ class DECLDIR Point final
7474
*/
7575
Point(moordyn::Log* log, size_t id);
7676

77+
/** @brief Point duplicator
78+
*
79+
* The duplicated point will have the same dynamics of the original point.
80+
* It will be a ::types::FREE kind of point though
81+
* @param visitor Point to duplicate
82+
* @param id Unique identifier of this instance
83+
*/
84+
Point(Point* visitor, size_t id);
85+
7786
/** @brief Destructor
7887
*/
7988
~Point();

source/Time.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,26 @@ class Scheme : public io::IO
256256
*/
257257
virtual void Step(real& dt) { t_local += dt; };
258258

259+
/** @brief Get the number of state variables
260+
* @return The number of state variables
261+
*/
262+
virtual const unsigned int GetNState() const = 0;
263+
264+
/** @brief Get the number of state derivative variables
265+
* @return The number of state derivative variables
266+
*/
267+
virtual const unsigned int GetNDeriv() const = 0;
268+
259269
/** @brief Get the state variable
260270
* @param i The index of the state variable to take
261271
* @return The state variable
272+
* @{
262273
*/
263274
virtual moordyn::state::State GetState(unsigned int i = 0) = 0;
275+
virtual moordyn::state::State* r(unsigned int i = 0) = 0;
276+
/**
277+
* @}
278+
*/
264279

265280
/** @brief Resume the simulation from the stationary solution
266281
* @param state The stationary solution
@@ -288,6 +303,17 @@ class Scheme : public io::IO
288303
{
289304
}
290305

306+
/** @brief Get the state derivative variable
307+
* @param i The index of the state derivative variable to take
308+
* @return The state derivative variable
309+
* @{
310+
*/
311+
virtual moordyn::state::State GetDeriv(unsigned int i = 0) = 0;
312+
virtual moordyn::state::State* rd(unsigned int i = 0) = 0;
313+
/**
314+
* @}
315+
*/
316+
291317
protected:
292318
/** @brief Constructor
293319
* @param log Logging handler
@@ -623,6 +649,16 @@ class SchemeBase : public Scheme
623649
*/
624650
virtual void Step(real& dt) { Scheme::Step(dt); };
625651

652+
/** @brief Get the number of state variables
653+
* @return The number of state variables
654+
*/
655+
inline const unsigned int GetNState() const { return NSTATE; }
656+
657+
/** @brief Get the number of state derivative variables
658+
* @return The number of state derivative variables
659+
*/
660+
inline const unsigned int GetNDeriv() const { return NDERIV; }
661+
626662
/** @brief Get the state
627663
* @param i The index of the state variable to take
628664
* @return The state variable
@@ -720,6 +756,7 @@ class SchemeBase : public Scheme
720756
* @return The state derivative
721757
* @throws moordyn::invalid_value_error if the @p i index is greater or
722758
* equal than the number of state derivatives
759+
* @{
723760
*/
724761
inline state::State* rd(unsigned int i = 0)
725762
{
@@ -732,6 +769,11 @@ class SchemeBase : public Scheme
732769
return _rd[i];
733770
}
734771

772+
inline state::State GetDeriv(unsigned int i = 0) { return *rd(i); }
773+
/**
774+
* @}
775+
*/
776+
735777
/** @brief Produce the packed data to be saved
736778
*
737779
* The produced data can be used afterwards to restore the saved information

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(CATCH2_TESTS
5656
midpoint
5757
aca
5858
wilson
59+
line_break
5960
)
6061

6162
function(make_executable test_name, extension)

0 commit comments

Comments
 (0)