Skip to content

Commit 85a3479

Browse files
fix(core): Explicit names for the elastic models
1 parent 34fa76d commit 85a3479

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

source/Line.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Line::setup(int number_in,
152152
d = props->d;
153153
A = pi / 4. * d * d;
154154
rho = props->w / A;
155-
ElasticMod = props->ElasticMod;
155+
ElasticMod = (elastic_model)props->ElasticMod;
156156
EA = props->EA;
157157
EA_D = props->EA_D;
158158
alphaMBL = props->alphaMBL;
@@ -242,7 +242,7 @@ Line::setup(int number_in,
242242
// segments) (1 = fully submerged, 0 = out of water)
243243

244244
// viscoelastic things
245-
if (ElasticMod > 1) {
245+
if (ElasticMod != ELASTIC_CONSTANT) {
246246
dl_1.assign(
247247
N,
248248
0.0); // segment stretch attributed to static stiffness portion [m]
@@ -615,7 +615,7 @@ Line::initialize()
615615
// the segment. This is required here to initalize the state as non-zero,
616616
// which avoids an initial transient where the segment goes from unstretched
617617
// to stretched in one time step.
618-
if (ElasticMod > 1) {
618+
if (ElasticMod != ELASTIC_CONSTANT) {
619619
for (unsigned int i = 0; i < N; i++) {
620620
lstr[i] = unitvector(qs[i], r[i], r[i + 1]);
621621
dl_1[i] = lstr[i] - l[i]; // delta l of the segment
@@ -790,32 +790,32 @@ Line::setState(const InstanceStateVarView state)
790790

791791
// Error check for number of columns (if VIV and Visco need row.size() = 8,
792792
// if VIV xor Visco need row.size() = 7, if not VIV need row.size() = 6)
793-
if ((state.row(0).size() != 8 && Cl > 0 && ElasticMod > 1) ||
794-
(state.row(0).size() != 7 && ((Cl > 0) ^ (ElasticMod > 1))) ||
795-
(state.row(0).size() != 6 && Cl == 0 && ElasticMod == 1)) {
793+
if ((state.row(0).size() != 8 && Cl > 0 && ElasticMod != ELASTIC_CONSTANT) ||
794+
(state.row(0).size() != 7 && ((Cl > 0) ^ (ElasticMod != ELASTIC_CONSTANT))) ||
795+
(state.row(0).size() != 6 && Cl == 0 && ElasticMod == ELASTIC_CONSTANT)) {
796796
LOGERR << "Invalid state.row size for Line " << number << endl;
797797
throw moordyn::mem_error("Invalid state.row size");
798798
}
799799

800800
// Error check for number of rows (if visco need N rows, if normal need N-1
801801
// rows)
802-
if ((state.rows() != N && ElasticMod > 1) ||
803-
(state.rows() != N - 1 && ElasticMod == 1)) {
802+
if ((state.rows() != N && ElasticMod != ELASTIC_CONSTANT) ||
803+
(state.rows() != N - 1 && ElasticMod == ELASTIC_CONSTANT)) {
804804
LOGERR << "Invalid number of rows in state matrix for Line " << number
805805
<< endl;
806806
throw moordyn::mem_error("Invalid number of rows in state matrix");
807807
}
808808

809809
// If using the viscoelastic model, interate N rows, else iterate N-1 rows.
810-
for (unsigned int i = 0; i < (ElasticMod > 1 ? N : N - 1); i++) {
810+
for (unsigned int i = 0; i < (ElasticMod != ELASTIC_CONSTANT ? N : N - 1); i++) {
811811
// node number is i+1
812812
// segment number is i
813813
if (i < N - 1) { // only assign the internal nodes
814814
r[i + 1] = state.row(i).head<3>();
815815
rd[i + 1] = state.row(i).segment<3>(3);
816816
}
817817

818-
if (ElasticMod > 1)
818+
if (ElasticMod != ELASTIC_CONSTANT)
819819
dl_1[i] =
820820
state.row(i)
821821
.tail<1>()[0]; // [0] needed becasue tail<1> returns a one
@@ -826,7 +826,7 @@ Line::setState(const InstanceStateVarView state)
826826
!(IC_gen)) { // not needed in IC_gen. Initializes as distribution on
827827
// 0-2pi. State is initialized by init function in this
828828
// code, which sets phi to range 0-2pi
829-
if (ElasticMod > 1)
829+
if (ElasticMod != ELASTIC_CONSTANT)
830830
phi[i + 1] =
831831
state.row(i)
832832
.tail<2>()[0]; // if both VIV and viscoelastic second to
@@ -1010,7 +1010,7 @@ Line::getStateDeriv(InstanceStateVarView drdt)
10101010
// V[i] = A * l[i]; // volume attributed to segment
10111011

10121012
// Calculate segment stiffness
1013-
if (ElasticMod == 1) {
1013+
if (ElasticMod == ELASTIC_CONSTANT) {
10141014
// line tension
10151015
if (nEApoints > 0)
10161016
EA = getNonlinearEA(lstr[i], l[i]);
@@ -1028,18 +1028,17 @@ Line::getStateDeriv(InstanceStateVarView drdt)
10281028
BA = getNonlinearBA(ldstr[i], l[i]);
10291029
Td[i] = BA * ldstr[i] / l[i] * qs[i];
10301030

1031-
} else if (
1032-
ElasticMod >
1033-
1) { // viscoelastic model from
1034-
// https://asmedigitalcollection.asme.org/OMAE/proceedings/IOWTC2023/87578/V001T01A029/1195018
1031+
} else {
1032+
// viscoelastic model from
1033+
// https://asmedigitalcollection.asme.org/OMAE/proceedings/IOWTC2023/87578/V001T01A029/1195018
10351034
// note that dl_1[i] is the same as Line%dl_1 in MD-F. This is the
10361035
// deltaL of the first static spring k1.
10371036

1038-
if (ElasticMod == 2) {
1037+
if (ElasticMod == ELASTIC_VISCO_CTE) {
10391038
// constant dynamic stiffness
10401039
EA_2 = EA_D;
10411040

1042-
} else if (ElasticMod == 3) {
1041+
} else if (ElasticMod == ELASTIC_VISCO_MEAN) {
10431042
if (dl_1[i] >= 0.0) // spring k1 is in tension
10441043
// Mean load dependent dynamic stiffness: from combining
10451044
// eqn. 2 and eqn. 10 from original MD viscoelastic paper,
@@ -1468,7 +1467,7 @@ Line::getStateDeriv(InstanceStateVarView drdt)
14681467
// Update state derivative for VIV. i-1 indexing because this is
14691468
// only called for internal nodes (i.e. node 1 maps to row 0 in the
14701469
// state deriv matrix).
1471-
if (ElasticMod > 1)
1470+
if (ElasticMod != ELASTIC_CONSTANT)
14721471
drdt.row(i - 1).tail<2>()[0] =
14731472
phi_dot[i]; // second to last element if visco model
14741473
else

source/Line.hpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ class DECLDIR Line final
8585
~Line();
8686

8787
private:
88+
/// @brief Elasticity models
89+
typedef enum
90+
{
91+
/// Constant EA
92+
ELASTIC_CONSTANT = 1,
93+
/// viscoelastic model with constant dynamic stiffness
94+
ELASTIC_VISCO_CTE = 2,
95+
/// mean load dependent dynamic stiffness
96+
ELASTIC_VISCO_MEAN = 3,
97+
} elastic_model;
98+
99+
88100
/** @brief Get the non-linear stiffness. This is interpolated from a
89101
* curve provided in the input file.
90102
* @param l_stretched The actual length of the segment
@@ -142,9 +154,8 @@ class DECLDIR Line final
142154
moordyn::real d;
143155
/// line density (kg/m^3)
144156
moordyn::real rho;
145-
/// Elasticity model flag (1: constant EA, 2: viscoelastic model with
146-
/// constant dynamic stiffness, 3: mean load depenedent dynamic stiffness)
147-
unsigned int ElasticMod;
157+
/// Elasticity model flag. See ::elastic_model
158+
elastic_model ElasticMod;
148159
/// line normal/static elasticity modulus * crosssectional area [N]
149160
moordyn::real EA;
150161
/// constant line dynamic stiffness modulus * area for viscoelastic stuff
@@ -158,8 +169,8 @@ class DECLDIR Line final
158169
moordyn::real vbeta;
159170
/// stiffness of spring 2 in viscoelastic model (dynamic stiffness). This is
160171
/// the spring in series with the parallel spring-dashpot. if ElasticMod =
161-
/// 2, EA_2 = EA_D. If ElasticMod = 3, EA_2 is load dependent dynamic
162-
/// stiffness.
172+
/// ELASTIC_VISCO_CTE, EA_2 = EA_D. If ElasticMod = ELASTIC_VISCO_MEAN, EA_2
173+
/// is load dependent dynamic stiffness.
163174
moordyn::real EA_2;
164175
/// segment stretch attributed to static stiffness portion [m] (deltaL_1)
165176
std::vector<moordyn::real> dl_1;
@@ -435,38 +446,38 @@ class DECLDIR Line final
435446
// Line::setState but flipped) ------ Error check for number of columns
436447
// (if VIV and Visco need row.size() = 8, if VIV xor Visco need
437448
// row.size() = 7, if not VIV need row.size() = 6)
438-
if ((state.row(0).size() != 8 && Cl > 0 && ElasticMod > 1) ||
439-
(state.row(0).size() != 7 && ((Cl > 0) ^ (ElasticMod > 1))) ||
440-
(state.row(0).size() != 6 && Cl == 0 && ElasticMod == 1)) {
449+
if ((state.row(0).size() != 8 && Cl > 0 && ElasticMod != ELASTIC_CONSTANT) ||
450+
(state.row(0).size() != 7 && ((Cl > 0) ^ (ElasticMod != ELASTIC_CONSTANT))) ||
451+
(state.row(0).size() != 6 && Cl == 0 && ElasticMod == ELASTIC_CONSTANT)) {
441452
LOGERR << "Invalid state.row size for Line " << number << endl;
442453
throw moordyn::mem_error("Invalid state.row size");
443454
}
444455

445456
// Error check for number of rows (if visco need N rows, if normal need
446457
// N-1 rows)
447-
if ((state.rows() != N && ElasticMod > 1) ||
448-
(state.rows() != N - 1 && ElasticMod == 1)) {
458+
if ((state.rows() != N && ElasticMod != ELASTIC_CONSTANT) ||
459+
(state.rows() != N - 1 && ElasticMod == ELASTIC_CONSTANT)) {
449460
LOGERR << "Invalid number of rows in state matrix for Line "
450461
<< number << endl;
451462
throw moordyn::mem_error("Invalid number of rows in state matrix");
452463
}
453464

454465
// If using the viscoelastic model, iterate N rows, else iterate N-1
455466
// rows.
456-
for (unsigned int i = 0; i < (ElasticMod > 1 ? N : N - 1); i++) {
467+
for (unsigned int i = 0; i < (ElasticMod != ELASTIC_CONSTANT ? N : N - 1); i++) {
457468
// node number is i+1
458469
// segment number is i
459470
state.row(i).head<3>() = r[i + 1];
460471
state.row(i).segment<3>(3) = rd[i + 1];
461472

462-
if (ElasticMod > 1)
473+
if (ElasticMod != ELASTIC_CONSTANT)
463474
state.row(i).tail<1>()[0] =
464475
dl_1[i]; // [0] needed becasue tail<1> returns a one element
465476
// vector. Viscoelastic state is always the last
466477
// element in the row
467478

468479
if (Cl > 0) {
469-
if (ElasticMod > 1)
480+
if (ElasticMod != ELASTIC_CONSTANT)
470481
state.row(i).tail<2>()[0] =
471482
phi[i + 1]; // if both VIV and viscoelastic second to
472483
// last element in the row
@@ -561,7 +572,7 @@ class DECLDIR Line final
561572
*/
562573
inline void setConstantEA(moordyn::real EA_in)
563574
{
564-
if (ElasticMod > 1) {
575+
if (ElasticMod != ELASTIC_CONSTANT) {
565576
LOGERR << "Cannot set constant EA for viscoelastic model" << endl;
566577
throw moordyn::invalid_value_error(
567578
"Cannot set constant EA for viscoelastic model");
@@ -1014,7 +1025,7 @@ class DECLDIR Line final
10141025
*/
10151026
inline const size_t stateN() const
10161027
{
1017-
if (ElasticMod > 1)
1028+
if (ElasticMod != ELASTIC_CONSTANT)
10181029
return getN(); // N rows for viscoelastic case
10191030
else
10201031
return getN() - 1; // N-1 rows for other cases
@@ -1032,10 +1043,10 @@ class DECLDIR Line final
10321043
*/
10331044
inline const size_t stateDims() const
10341045
{
1035-
if (Cl > 0 && ElasticMod > 1)
1046+
if (Cl > 0 && ElasticMod != ELASTIC_CONSTANT)
10361047
return 8; // 3 for position, 3 for velocity, 1 for VIV phase, 1 for
10371048
// viscoelasticity
1038-
else if ((Cl > 0) ^ (ElasticMod > 1))
1049+
else if ((Cl > 0) ^ (ElasticMod != ELASTIC_CONSTANT))
10391050
return 7; // 3 for position, 3 for velocity, 1 for VIV phase or
10401051
// viscoelasticity
10411052
else

0 commit comments

Comments
 (0)