Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)
set(MOORDYN_MAJOR_VERSION 2)
set(MOORDYN_MINOR_VERSION 6)
set(MOORDYN_PATCH_VERSION 2)
set(MOORDYN_MINOR_VERSION 7)
set(MOORDYN_PATCH_VERSION 0)
set(MOORDYN_VERSION ${MOORDYN_MAJOR_VERSION}.${MOORDYN_MINOR_VERSION})
project(Moordyn VERSION ${MOORDYN_VERSION})

Expand Down
5 changes: 0 additions & 5 deletions source/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,6 @@ IO::LoadFile(const std::string filepath) const
uint8_t major, minor;
f.read((char*)&major, sizeof(uint8_t));
f.read((char*)&minor, sizeof(uint8_t));
std::cout << major << std::endl;
std::cout << minor << std::endl;
std::cout << _min_major_version << std::endl;
std::cout << _min_minor_version << std::endl;
std::cout << "number=" << 7 << std::endl;
if ((major < _min_major_version) ||
((major == _min_major_version) && (minor < _min_minor_version))) {
LOGERR << "The file '" << filepath << "' was written by MoorDyn "
Expand Down
60 changes: 58 additions & 2 deletions source/MoorDyn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,41 @@ moordyn::MoorDyn::Step(const double* x,
return MOORDYN_SUCCESS;
}

void
MoorDyn::BreakLine(moordyn::Point* point, moordyn::Line* line)
{
// Detach the line from the point
moordyn::EndPoints end_point;
auto pt_attachments = point->getLines();
for (auto attachment : pt_attachments) {
if (attachment.line == line) {
end_point = attachment.end_point;
}
}
point->removeLine(line);
// Create the new point
moordyn::Point *pt = new Point(point, PointList.size());
PointList.push_back(pt);
waves->addPoint(pt);
_t_integrator->AddPoint(pt);
// Set the state of the point
auto state = _t_integrator->r(0);
pt->initialize(state->get(pt));
for (unsigned int i = 1; i < _t_integrator->GetNState(); i++) {
_t_integrator->r(i)->get(pt) = state->get(pt);
}
for (unsigned int i = 0; i < _t_integrator->GetNDeriv(); i++) {
_t_integrator->rd(i)->get(pt).row(0)(Eigen::seqN(0, 3)) =
state->get(pt).row(0)(Eigen::seqN(3, 3));
// NOTE: Although when cloning free points we can actually get the
// acceleration, I (Jose Luis Cercos-Pita) do not think is worthy, so
// I am simply setting no acceleration
_t_integrator->rd(i)->get(pt).row(0)(Eigen::seqN(3, 3)) = vec::Zero();
}
// Attach the line to the point
pt->addLine(line, end_point);
}

std::vector<uint64_t>
MoorDyn::Serialize(void)
{
Expand Down Expand Up @@ -1155,8 +1190,7 @@ moordyn::MoorDyn::ReadInFile()
env->WtrDpth = -r0[2];
LOGWRN << "\t Water depth set to point " << PointList.size() + 1
<< " z position because point was specified below the "
"seabed"
<< endl;
"seabed" << endl;
}

// Check point ID is sequential starting from 1
Expand Down Expand Up @@ -2896,6 +2930,28 @@ MoorDyn_GetFASTtens(MoorDyn system,
return MOORDYN_SUCCESS;
}

int DECLDIR
MoorDyn_BreakLine(MoorDyn system,
MoorDynPoint point,
MoorDynLine line)
{
CHECK_SYSTEM(system);

moordyn::error_id err = MOORDYN_SUCCESS;
string err_msg;
try {
((moordyn::MoorDyn*)system)->BreakLine((moordyn::Point*)point,
(moordyn::Line*)line);
}
MOORDYN_CATCHER(err, err_msg);
if (err != MOORDYN_SUCCESS) {
cerr << "Error (" << err << ") at " << __FUNC_NAME__ << "():" << endl
<< err_msg << endl;
return err;
}
return MOORDYN_SUCCESS;
}

int DECLDIR
MoorDyn_GetDt(MoorDyn system, double* dt)
{
Expand Down
15 changes: 15 additions & 0 deletions source/MoorDyn2.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,21 @@ MoorDyn_GetFASTtens(MoorDyn system,
float AnchHTen[],
float AnchVTen[]);

/** @brief Break a line on a specific point
*
* This method is dettaching a line from the point, and in exchange is
* creating a point duplicate of type moordyn::Point::types::FREE
* @param system The Moordyn system
* @param point The discconection point
* @param line The line that is dettaching from the point
* @throw MOORDYN_SUCESS If the line is correctly dettached, an error code
* otherwise (see @ref moordyn_errors)
*/
int DECLDIR
MoorDyn_BreakLine(MoorDyn system,
MoorDynPoint point,
MoorDynLine line);

/** @brief Get the current model time step
* @param system The Moordyn system
* @param dt The output time step
Expand Down
11 changes: 11 additions & 0 deletions source/MoorDyn2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ class MoorDyn final : public io::IO
waves->setWaveKinematics(U, Ud);
}

/** @brief Break a line on a specific point
*
* This method is dettaching a line from the point, and in exchange is
* creating a point duplicate of type moordyn::Point::types::FREE
* @param point The discconection point
* @param line The line that is dettaching from the point
* @throw moordyn::invalid_value_error If the line is not attached to the
* point.
*/
void BreakLine(moordyn::Point* point, moordyn::Line* line);

/** @brief Produce the packed data to be saved
*
* The produced data can be used afterwards to restore the saved information
Expand Down
28 changes: 27 additions & 1 deletion source/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,36 @@ namespace moordyn {

Point::Point(moordyn::Log* log, size_t id)
: Instance(log)
, waves(nullptr)
, seafloor(nullptr)
, pointId(id)
{
vtk.set_binary();
}

Point::Point(Point* visitor, size_t id)
: Instance(visitor->GetLogger())
, env(visitor->env)
, waves(visitor->waves)
, seafloor(visitor->seafloor)
, pointM(visitor->pointM)
, pointV(visitor->pointV)
, pointF(visitor->pointF)
, pointCdA(visitor->pointCdA)
, pointCa(visitor->pointCa)
, r(visitor->r)
, rd(visitor->rd)
, Fnet(visitor->Fnet)
, t(visitor->t)
, M(visitor->M)
, acc(visitor->acc)
, pointId(id)
, number(id + 1)
, type(types::FREE)
{
vtk.set_binary();
}

Point::~Point() {}

void
Expand Down Expand Up @@ -150,7 +174,9 @@ Point::initialize()
seafloor ? seafloor->getDepthAt(r[0], r[1]) : -env->WtrDpth;
if (waterDepth > r[2]) {
LOGERR << "Error: water depth is shallower than Point " << number
<< "." << endl;
<< "." << endl
<< "\tseabed z = " << waterDepth << endl
<< "\tpoint = " << r << endl;
throw moordyn::invalid_value_error("Invalid water depth");
}
}
Expand Down
9 changes: 9 additions & 0 deletions source/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ class DECLDIR Point final
*/
Point(moordyn::Log* log, size_t id);

/** @brief Point duplicator
*
* The duplicated point will have the same dynamics of the original point.
* It will be a ::types::FREE kind of point though
* @param visitor Point to duplicate
* @param id Unique identifier of this instance
*/
Point(Point* visitor, size_t id);

/** @brief Destructor
*/
~Point();
Expand Down
42 changes: 42 additions & 0 deletions source/Time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,26 @@ class Scheme : public io::IO
*/
virtual void Step(real& dt) { t_local += dt; };

/** @brief Get the number of state variables
* @return The number of state variables
*/
virtual const unsigned int GetNState() const = 0;

/** @brief Get the number of state derivative variables
* @return The number of state derivative variables
*/
virtual const unsigned int GetNDeriv() const = 0;

/** @brief Get the state variable
* @param i The index of the state variable to take
* @return The state variable
* @{
*/
virtual moordyn::state::State GetState(unsigned int i = 0) = 0;
virtual moordyn::state::State* r(unsigned int i = 0) = 0;
/**
* @}
*/

/** @brief Resume the simulation from the stationary solution
* @param state The stationary solution
Expand Down Expand Up @@ -288,6 +303,17 @@ class Scheme : public io::IO
{
}

/** @brief Get the state derivative variable
* @param i The index of the state derivative variable to take
* @return The state derivative variable
* @{
*/
virtual moordyn::state::State GetDeriv(unsigned int i = 0) = 0;
virtual moordyn::state::State* rd(unsigned int i = 0) = 0;
/**
* @}
*/

protected:
/** @brief Constructor
* @param log Logging handler
Expand Down Expand Up @@ -623,6 +649,16 @@ class SchemeBase : public Scheme
*/
virtual void Step(real& dt) { Scheme::Step(dt); };

/** @brief Get the number of state variables
* @return The number of state variables
*/
inline const unsigned int GetNState() const { return NSTATE; }

/** @brief Get the number of state derivative variables
* @return The number of state derivative variables
*/
inline const unsigned int GetNDeriv() const { return NDERIV; }

/** @brief Get the state
* @param i The index of the state variable to take
* @return The state variable
Expand Down Expand Up @@ -720,6 +756,7 @@ class SchemeBase : public Scheme
* @return The state derivative
* @throws moordyn::invalid_value_error if the @p i index is greater or
* equal than the number of state derivatives
* @{
*/
inline state::State* rd(unsigned int i = 0)
{
Expand All @@ -732,6 +769,11 @@ class SchemeBase : public Scheme
return _rd[i];
}

inline state::State GetDeriv(unsigned int i = 0) { return *rd(i); }
/**
* @}
*/

/** @brief Produce the packed data to be saved
*
* The produced data can be used afterwards to restore the saved information
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(CATCH2_TESTS
midpoint
aca
wilson
line_break
)

function(make_executable test_name, extension)
Expand Down
Loading
Loading