diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index e7e2c77a..082923e3 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -193,7 +193,16 @@ The effective tangent is `(1 − α_m)/(β Δt²) M + (1 − α_f) K_q + 1e-14, 30 iterations, 12 backtracks. A non-converged step, or on the Hermite path an under-resolved one, is repeated by internal subdivision (4, 16, … up to `recovery_max_substeps`) along a C² quintic boundary trajectory that ends on the -host time. +host time. On `EI = 0` lines `CD_Step_Model` also re-solves a converged step in +`max(4, ceil(turn/ei0_substep_angle))` sub-steps on the same trajectory when a +taut segment turned by more than `ei0_substep_angle` or a slack segment snapped +taut while the step does not resolve its axial wave (`ei0_substeps auto`, the +default; at most `ei0_substep_max`). It restores the committed kinematics and +constitutive and friction states first (`commit_state_copy`, the one list of +that state in `CableDyn_Model`) and keeps the plain step when a sub-step fails. +The sub-steps of a recovered step, the halves of a line-system step halved by +`CD_Step_System`, and the lines attached to the objects of the monolithic +body/point step are taken as given. ### Bodies, rods, and points diff --git a/CHANGELOG.md b/CHANGELOG.md index ba564c6f..4cd9946e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,10 +100,13 @@ All notable changes to CableDyn are recorded in this file. The format follows step before and after, ten times the largest tension anywhere on the line one step before and after, and the largest tension of the initial state. The first spike of a line is reported as a warning, once per line, and the run summary counts them. The run ends with a note when a - taut segment turned by more than 1° in one step (the mean and standard deviation of the - tension err by about 1 % and more above it; 1.3 % at 2.9° on a heaving chain), and when - segments snapped taut while the axial wave crosses a segment more than once per step, so the - snap peaks are not resolved in time. The standalone driver also prints a note for a dynamic + taut segment turned by more than 1° in one solver step (with `ei0_substeps auto`, see Changed, + 1.1 times the larger of 1° and `ei0_substep_angle`; the sub-steps of a sub-stepped or + recovered step count as steps; the mean and standard deviation of the tension err by about + 1 % and more above it, 1.3 % at 2.9° on a heaving chain, and near 6° per step snap-load peaks + come out 10 to 20 % low with either generalised-α blend), and when segments snapped taut + while the axial wave crosses a segment more than once per solver step, so the snap peaks are + not resolved in time. The standalone driver also prints a note for a dynamic deck with `rhoInf` above 0.95, on the missing numerical dissipation. See the manual's troubleshooting page. - Anchor uplift channels for the drag-anchor check of a catenary mooring (no vertical load at @@ -168,6 +171,92 @@ All notable changes to CableDyn are recorded in this file. The format follows ### Changed +- Tension-only (`EI = 0`) lines resolve fast segment rotation and slack-to-taut snaps by + sub-stepping, on by default (new OPTIONS `ei0_substeps auto|off`, `ei0_substep_angle` + (default 1°) and `ei0_substep_max` (default 16), checked when the line is initialised; the + Python deck reader applies the same rules). A converged step in which a segment that ends it + taut (above 0.1 % of the largest step-start tension) turned by more than + `ei0_substep_angle`, or a segment slack at its start ends it above a quarter of that tension + while the step does not resolve the axial wave over it (the wave crosses the segment more + than once per step), is solved again from the same committed state in + `max(4, ceil(turn/angle))` equal sub-steps, at most `ei0_substep_max`, with the end motion on + the quintic of the recovering step and the last sub-step on the given end state; output and + coupling times are unchanged. The tensions are those of the run audit (the elastic tension, + or that of the viscoelastic or Syrope law), and the step-start tension is taken as at least + 0.1 % of the line's initial tension, so a line slack all over does not count barely taut + segments. At `dtM` 0.1 s a taut segment of the Lozon 80 m + all-chain mooring turns by up to 6° per step in 5 m / 7 s heave, and the snap-load peaks of + both generalised-α blends came out 10 to 20 % low. The release cap was not the cause: it acts + in 0.3 % of the element steps, never within 0.5 s of a peak, and the cycle maxima with and + without it agree to within 1 %; the peaks followed the algorithmic damping (28 and 31 % low at + `rhoInf` 0, 10 and 40 % high at 0.6). Over seven runs whose amplitude differs by up to 3e-4, + against 0.5 and 0.25 ms runs, the fairlead and anchor maxima move from 15 and 17 % low to 4 and + 8 % low (the configuration blend of 0.1.1 gave 10 and 18 % low), and the anchor maxima of + the 200 m semitaut mooring in 10 m / 14 s and 5 m / 7 s surge from 16 and 26 % high to 4 % + high and 2 % low (over thirteen runs 5 % high and 0.3 % low, single runs from 4 % low to + 21 % high). A single run at that step varies by 15 to 20 points, so a single comparison + can make either blend look accurate. The decision depends only on the committed state, the + step inputs and the line's initial tension, so restarts repeat it; when a sub-step does not + converge the plain step's own result is kept, and a step recovered after a stall or a half + of a line-system step halved after a failure takes its sub-steps as given (when the halves + fail too, the full step is re-run as the nominal step, sub-steps included). It applies on + every route that steps `EI = 0` lines (standalone lines and line systems, OpenFAST, + FAST.Farm and the C API, whose raw lines always take it) except the lines attached to the + bodies, rods and points of the monolithic body and point coupling, which needs the end + reaction and tangent of the nominal step. `monolithic bodyScheme` is the default of every + standalone deck with `Rigid6` bodies, `Point3` buoys, rods or `Free`/`Connect` points on + `EI = 0` lines, so those lines are not sub-stepped there: 7 of the 21 shipped `EI = 0` + dynamic example decks run this way, and none of them notes an unresolved segment turn. A + line of such a deck whose ends are all fixed or anchored is sub-stepped, `staggered + bodyScheme` sub-steps them all, and the standalone driver notes the exclusion once per run. + `False alpha_force_blend` (paper mode) turns it off unless the deck sets it, so the paper + reproduction is unchanged. A step that triggers costs its plain step and usually four + sub-steps, at most the plain step and three passes of `ei0_substep_max` sub-steps (49 line + solves at the default), and that once for every sub-step where bodies or rods sub-cycle the + lines (`staggered bodyScheme`, coupled runs); the OpenMP loop over the lines of a system + hands them out dynamically, which leaves every line's result unchanged. The standalone + driver reports the sub-stepped steps per line ("solved N of the M line step(s) it + examined"), OpenFAST and FAST.Farm print the counts (steps sub-stepped, largest count, steps + that needed more than `ei0_substep_max`, steps that kept the plain step) at the end of the + run, and `CD_AGG_Get_Substep_Counts` returns them to an aggregate host as 64-bit integers. + Only committed steps count: a step rolled back and taken again (a line-system halving, a + stall recovery, a corrector or a junction iteration) counts once. Over the shipped examples + 19 of the 21 `EI = 0` dynamic decks are unchanged bit for bit; in the two `als_volturnus` + line-break decks the pre-failure anchor snap at 250 s, a single-step peak at `dtM` 0.05 s, + moves from 2.145 to 1.918 MN (1.963 MN converged) and from 2.262 to 2.158 MN (2.334 MN + converged), with the other tension statistics within 0.02 %. The 20-run Lozon mooring + envelope at `dtM` 0.1 s takes 1.67 times as long (1.6 to 2.5 times on the 5 m / 7 s and + 10 m / 14 s motions; the steps that do not trigger cost only the measurement), and the + examples whose steps never trigger run as before. Of the reproducers of the force-blend + entry below, the semi-taut chain–polyester leg in 15 m surge now peaks at 4.65 MN at the + anchor at `dtM` 0.05 s (5.74 MN before, 4.6 MN at 0.0025 s), the Syrope line at 1.81 MN + (1.64 MN before, 1.78 MN at 1 and 2.5 ms), the lightly damped viscoelastic light cable at + 0.062 MN at the anchor (0.085 MN before, 0.082 to 0.095 MN at 0.5 to 2.5 ms; its snap is not + resolved at 0.1 s, and over seven runs whose amplitude differs by up to 3e-4 it peaks at + 0.056 to 0.079 MN with the sub-steps and 0.056 to 0.085 MN without) and the shipped + viscoelastic polyester at 1.80 MN as before (in its steps recovered after a stall, taken as + given, a segment now turns by up to 2.0° per solver step, which the run notes); the light + cable stays at 0.092 / 0.106 MN at `dtM` 0.1 s and its largest segment tension at `dtM` + 0.01 s moves from 0.107 to 0.095 MN. Its fairlead and anchor peaks at `dtM` 2.5 ms move from + 0.099 / 0.091 to 0.102 / 0.119 MN, and on the stiff seabed at `dtM` 0.05 s from 0.52 / 0.67 + to 0.62 / 0.86 MN. None of these is a converged peak: the undamped `EI = 0` cable has no + converged snap peak (see the force-blend entry below; converged finite-EI runs give 0.093 / + 0.057 MN). At a step that does not resolve the axial wave the sub-steps resolve more of the + segment rattle of this undamped cable and can raise isolated spikes, as its anchor peak at + 2.5 ms shows. At `dtM` 0.5 ms, where the step resolves the wave, the cable takes no sub-step, + with or without physical axial damping (`BA` 5.06e5 N·s), and its results equal those taken + as given bit for bit; without the axial-wave condition on the snap trigger `auto` sub-stepped + 8081 of the 60000 steps of that run and raised its anchor peak from 0.116 to 0.52 MN. `ei0_substep_max` and `ei0_substep_angle` do not change these runs. Validation: + the Bergdahl matrix at its 0.3125 ms step resolves the axial wave over a segment and takes no + sub-step, so its maxima are unchanged bit for bit (RMSE 1.58 N, MAPE 3.13 %, Pearson 0.993, + Lin concordance 0.989); of its refinement runs the 0.1 m mesh moves the T = 1.25 s mean + cycle maximum from 68.33 to 68.35 N (largest mesh-halving change 0.52 % to 0.56 %) and the + 0.625 ms step from 72.2 to 69.5 N. The WD0050/A2 cell of the L2-2 parity moves within its + recorded range (largest OrcaFlex summary difference 0.091 to 0.093, MoorDyn-C metric 0.078 + to 0.076); the other L2-2 cells, the one-hour VolturnUS-S record, the L3-2 regular-wave + comparison and the snap-load verification are unchanged bit for bit (the latter two step + the generalised-α kernel directly). `off ei0_substeps` gives the previous results bit for + bit. - Finite-EI node tension, curvature and bend moment are recovered from nodal equilibrium. The `TenN`, `CurvN` and `BendMomN` channels, the `Tension`, `Curvature` and `BendMoment` columns of the static profile and the range graph, and the `.t.out` segment @@ -368,8 +457,9 @@ All notable changes to CableDyn are recorded in this file. The format follows work to the motion than its strain energy. Both happened silently at the default `rhoInf = 0.4`, at every `dtM` from 0.002 to 0.2 s, on realistic input: a light, axially stiff cable (80 kg/m, EA 8e8 N) under 3 m heave reported 4.2 MN at the fairlead and 3.4 MN at the - anchor (`dtM` 0.0025 s) and 20 MN at the anchor (`dtM` 0.1 s), against 0.1 to 0.18 MN at - `rhoInf = 0`, at `dtM` down to 0.25 ms and with a finite-EI model; the same cable in an `Hs` + anchor (`dtM` 0.0025 s) and 20 MN at the anchor (`dtM` 0.1 s), where converged finite-EI + runs of the same cable give 0.093 MN at the fairlead and 0.057 MN at the anchor; the same + cable in an `Hs` 8 m JONSWAP sea 0.41 MN at the anchor against 0.043 MN; the shipped viscoelastic polyester in 15 m surge 2.69 MN against 1.80 MN; a semi-taut chain–polyester leg 9.5 MN at the anchor against 4.6 MN; and a line on a stiff seabed failed the plausibility guard. The step now blends @@ -393,10 +483,21 @@ All notable changes to CableDyn are recorded in this file. The format follows the dashpot's end share, so that the whole blend of a segment ending slack returns at most its strain energy unless that end share alone returns more (in the test chain it returned up to 2750 times that with only the elastic share capped); a damped segment that ends taut beyond - that band keeps the plain force blend. The seabed contact of + that band keeps the plain force blend. A damped segment slack at the step start keeps its + step-start dashpot force under a cap too, so that this kept share returns at most the + dashpot's own one-step dissipation `T_d,n |l̇_n| Δt` plus the end share's credit (up to 46 + times that in the test chain before). The seabed contact of a node that lifts off within a step is not capped (see the manual's theory page). At the - default `rhoInf` the reproducers now give 0.10 / 0.09 MN, 0.092 / 0.106 MN, 0.075 / 0.043 MN - and 1.80 MN, as their references, and the stiff-seabed line runs to completion; the + default `rhoInf` the light cable now peaks at 0.10 / 0.09 MN at `dtM` 0.0025 s and at 0.092 / + 0.106 MN at 0.1 s, the same cable in the JONSWAP sea at 0.075 / 0.043 MN and the + viscoelastic polyester at 1.80 MN, as at 0.0025 s; the stiff-seabed line runs to completion. + The light-cable figures are not converged peaks. The undamped `EI = 0` deck has no converged + snap peak: the peak rises as `dtM` falls (0.32 to 0.46 MN at microsecond steps, also with an + explicit lumped-mass solver), as single segments rattle, and falls with mesh refinement at a + fixed `dtM`; its 20 ms averages converge to 0.083 / 0.047 MN, the slack-to-taut event, and + converged finite-EI runs give 0.093 MN at the fairlead and 0.057 MN at the anchor. On the + stiff seabed the `EI = 0` peak does not converge either (0.74 to 0.95 MN at coarse steps, + 1.2 to 1.4 MN at 0.025 to 0.05 ms). The chain–polyester anchor snap peaks at 5.7 MN at `dtM` 0.05 s, a single-step peak (4.6 MN at 0.0025 s) that the new snap note reports. On a linear element the scheme is unchanged, so taut lines keep their accuracy: every MoorDyn-C, OrcaFlex, analytic and experimental comparison that @@ -410,7 +511,10 @@ All notable changes to CableDyn are recorded in this file. The format follows `EI = 0` dynamic decks (one more force evaluation per step and about 4 % more Newton iterations). `False alpha_force_blend`, which until now applied to finite-EI lines only, selects the former scheme for `EI = 0` lines as well. Lines that the C API builds without a - deck (`CableDyn_InitLine`, `CableDyn_InitLines`) always take the force blend. + deck (`CableDyn_InitLine`, `CableDyn_InitLines`) always take the force blend. The figures + of this entry take every step as given, as `off ei0_substeps` now does; the rotation- and + snap-resolved sub-steps of the default (under Changed) move the snap peaks among them, for + example the chain–polyester anchor to 4.65 MN and the viscoelastic light cable to 0.062 MN. - `modified_newton` on `EI = 0` lines (with or without the force blend, so also under `False alpha_force_blend`) rebuilds the tangent when an iterate reduces the residual by less than a factor four, as the manual states; it had kept the first tangent for the whole step, diff --git a/VALIDATION.md b/VALIDATION.md index 7d7ce2b9..3626f377 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -259,7 +259,8 @@ initialisation. mean, 0.26% in std, 0.50 / 0.43% in minimum / maximum, and 0.27% (90 s) / 1.14% (12 s) in Fourier amplitude**. The end-element tension carries the 1.28% static offset of L2-V in its mean and extremes. The force-blended `EI = 0` step moved the - minimum by +7 kN (0.15% before) and the other statistics by at most 0.01%. + minimum by +7 kN (0.15% before) and the other statistics by at most 0.01%; no step of this + drive needs the rotation- and snap-resolved sub-steps, so they leave it unchanged bit for bit. - **L-fig curvature overlay**: `l3_lazywave_dynamic` writes each site's along-arc curvature profile. [`validation/scripts/curvature_profile_overlay.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/curvature_profile_overlay.py) @@ -291,12 +292,16 @@ scripts, results, and source provenance are in has RMSE 1.58 N, mean absolute percentage error 3.13%, Pearson correlation 0.993, and Lin concordance 0.989. Two phase-averaged measured histories have waveform RMSEs of 5.95% and 2.54% of their force ranges; these two were computed with the - executable of the 2026-10-09 record (the configuration-blended `EI = 0` step), because the + executable of the 2026-10-09 record (the configuration-blended `EI = 0` step, without + sub-steps), because the article supplement's `expData.dat` they need was not available for the rerun (see the experiment's README and `provenance.json`). Halving the mesh length - and the time step changes the mean cycle maximum by at most 0.52% and 0.19%. The - 0.3125 ms step resolves the segment axial modes that the snap loads excite; at - 1.25 ms the maxima are 2–15% higher and vary from cycle to cycle. + and the time step changes the mean cycle maximum by at most 0.56% and 0.19%. The + 0.3125 ms step resolves the segment axial modes that the snap loads excite (and the axial + wave over a segment, so the matrix takes no rotation- and snap-resolved sub-step and equals + the run taken as given bit for bit); at + 0.625 ms the T = 1.25 s maxima are 2.4% higher (6.5% with every step taken as given), and + at 1.25 ms they are 2–15% higher and vary from cycle to cycle. ## L4 coupled OpenFAST @@ -380,6 +385,17 @@ scripts, results, and source provenance are in 30 ms in a sweep); the peak is within **1.5%** of the 0.5 ms sub-CFL reference (1.1% at 10 ms, 0.05% at 5 ms). Before the force-blended `EI = 0` step these were 2.76 / 0.62 / 0.16%; the 2.76% at 20 ms is the value published as 2.7% (truncated). + The test steps the generalised-α kernel itself, without the rotation- and snap-resolved + sub-steps of the line models (next item). +- **Snap-load peaks at a coarse step** (Lozon moorings, `dtM = 0.1 s`): over seven runs whose + motion amplitude differs by up to 3e-4 (the snap peaks of a single run vary by 15–20 + points at this step), against 0.5 and 0.25 ms runs, the fairlead and anchor maxima of the + 80 m all-chain mooring in 5 m / 7 s heave are 15% and 17% low when every step is taken as + given (`off ei0_substeps`) and 4% and 8% low with the default `auto`; the anchor maxima of + the 200 m semitaut mooring in 10 m / 14 s and 5 m / 7 s surge are 16% and 26% high and + 4% high and 2% low (over thirteen runs 5% high and 0.3% low; single runs from 4% low to 21% + high). In 5 m / 7 s surge the 80 m maxima are within 2.5% either way. On the + 0.1 s output grid the converged run itself reads the 80 m heave maxima 5% low. - **Implicit and explicit steps**: on the matched near-taut snap, MoorDyn-C's explicit RK2 needs `dtM ≲ 1 ms`, as expected of an explicit scheme at this line stiffness; CableDyn's implicit step remains stable at **20 ms**. @@ -673,10 +689,14 @@ feedback re-converge each step (three-seed DLC-1.1, L4-1b, <0.6%). **Prescribed-motion moorings.** The Lozon all-chain catenary and semitaut chain–polyester moorings are driven through the same surge-and-heave envelope at -`dtM = 0.1 s`. The all-chain mooring needs no step subdivision and takes 0.7–1.1 ms -of wall time per 0.1 s step with at most 16 Newton iterations; the stiffer composite -subdivides about 1.4% of steps at the severe and extreme excursions and takes less -than 3.3 ms per step. +`dtM = 0.1 s` (72 s each). All 20 runs complete. With the default `ei0_substeps auto`, +the steps in which a taut segment turns by more than 1° or a segment snaps taut are +solved in 4 to 7 sub-steps: none to 3% of the steps in the 3 m / 10 s and 8 m / 20 s +motions, 31–75% in the 5 m / 7 s and 10 m / 14 s ones. The march takes 0.24–0.94 ms of +wall time per 0.1 s step for the all-chain mooring and 0.32–1.2 ms for the composite, +1.67 times the plain steps over the 20 runs (1.6 to 2.5 times on the 5 m / 7 s and +10 m / 14 s motions), and the recovering step +subdivides at most 12 of the 720 intervals of a run. **Coupled OpenFAST sea states.** In the full IEA-15 MW VolturnUS-S model with SeaState JONSWAP waves, the all-chain mooring completes `Hs = 10 m`, `Tp = 14 s` diff --git a/doc/capi.rst b/doc/capi.rst index 19c90a50..c0cafceb 100644 --- a/doc/capi.rst +++ b/doc/capi.rst @@ -1048,8 +1048,10 @@ The Newton settings are fixed at their defaults: relative residual tolerance :math:`10^{-8}`, at most 30 iterations per step, and at most 12 line-search backtracks. So is the generalised-α scheme: these lines always take the force-blended step (``alpha_force_blend`` ``True``, with the release cap on a tension-only line, -:doc:`theory`). They cannot select the configuration blend of 0.1.1 and earlier -(``False alpha_force_blend``), which only a deck sets, through ``CableDyn_InitDeck``. +:doc:`theory`), with the rotation- and snap-resolved sub-steps of ``ei0_substeps auto`` at +their default settings (:doc:`options`). They cannot select the configuration blend of 0.1.1 +and earlier (``False alpha_force_blend``) or ``off ei0_substeps``, which only a deck sets, +through ``CableDyn_InitDeck``. ``CableDyn_InitLines`` ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/driver_format.md b/doc/driver_format.md index e934d6cb..83c23521 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -1026,6 +1026,9 @@ syntax form. The most frequently edited keywords are: | `tensile_safety` | `False`, `warn`, or `True`; audits the element-mean axial force (three-point Gauss mean of the signed axial resultant, averaged over an element and its two neighbours). `True` rejects. `warn` commits the state, counts accepted-step events, and reports the worst force, threshold, element and time (the printed `xi` is always 0.5, the element centre) | `False` | | `tensile_strain_tolerance` | non-negative strain band for the dynamic tensile audit | `2e-6` | | `recovery_max_substeps` | integer from 4 to 65536; maximum step subdivision for dynamic-step recovery on tension-only and bending lines. Internal prescribed states lie on one C2 quintic trajectory and land on the nominal coupling endpoint. The standalone summary reports recovered intervals and the largest subdivision used | `1024` | +| `ei0_substeps` | `auto` or `off`. `auto` solves a converged `EI = 0` step again in `max(4, ceil(turn/ei0_substep_angle))` equal sub-steps (at most `ei0_substep_max`) when a segment that ends it taut turned by more than `ei0_substep_angle`, or a segment slack at its start ends it above a quarter of the largest step-start tension while the step does not resolve the axial wave over it; the end motion follows the C2 quintic of the recovering step, and output and coupling times are unchanged. `off` takes every step as given. The lines attached to the bodies, rods and points of the monolithic body and point coupling (the default `bodyScheme` of decks with them) are not sub-stepped | `auto` (`off` with `False alpha_force_blend`) | +| `ei0_substep_angle` | real in (0, 90], deg; largest taut-segment turn per step before `auto` sub-steps it | `1.0` | +| `ei0_substep_max` | integer from 2 to 1024; most sub-steps `auto` takes for one step | `16` | | `axial_quadrature_order` | Gauss order 1–6 for the finite-EI axial energy; a value different from the bending order gives selective integration | `4` | | `bending_quadrature_order` | Gauss order 1–6 for the finite-EI curvature energy | `4` | | `dynamic_solver rel abs max_iter backtracks [rhoInf]` | dynamic Newton controls; keyword-first syntax, unlike scalar rows. `EI = 0` solves use all four; standalone finite-EI decks use `rel` and `max_iter` (coupled cables: see the OPTIONS reference). Choose them for the mesh and load case; the 952-element Gulf of Maine example uses `1e-4 1e-14 100 12` | `1e-8 1e-14 30 12` | diff --git a/doc/modeling.rst b/doc/modeling.rst index 2ce56278..45bc5616 100644 --- a/doc/modeling.rst +++ b/doc/modeling.rst @@ -140,6 +140,27 @@ only because its stability limit forces a step of that size; the implicit solver (Orcina) shows a similar plateau (about 0.5 %). When snap-tension histories matter, use the coarsest mesh that resolves the line shape and refine ``dtM`` toward :math:`l/(2c)`, rather than refining both. +At a much coarser ``dtM`` the step no longer resolves the rotation of the line during a snap, +and the peaks follow the algorithmic damping (10 to 20 % low at 6° of segment turn per step). +By default (``ei0_substeps auto``) such steps of an ``EI = 0`` line are solved in sub-steps, +which brings the Lozon mooring snap peaks at ``dtM = 0.1 s`` within 8 % on average; single +peaks at that step still vary by 15 to 20 points with tiny changes of the motion, so compare +ensembles or refine ``dtM`` before drawing conclusions from one peak. The driver reports the +sub-stepped steps per line and notes a turn per step it did not resolve (see +:doc:`options`, ``ei0_substeps``). + +The snap peaks of an undamped tension-only line do not converge in time or mesh: its single +segments rattle against the stiff axial spring, and the peak rises as ``dtM`` falls. On a light, +axially stiff cable (80 kg/m, EA 8e8 N, 2 m segments) in 3 m heave it rises from about 0.1 MN at +``dtM = 2.5 ms`` to 0.32 to 0.46 MN at microsecond steps, also with an explicit lumped-mass +solver, while converged finite-EI runs give 0.093 MN at the fairlead and 0.057 MN at the anchor. +To obtain converged peaks, give such lines physical axial damping, ``BA`` as a material +property in N·s (the negative, per-segment damping-ratio form changes with the mesh: it halves +with each halving of the segment length), or model them with finite ``EI``. With ``BA = 0`` and +a ``dtM`` that does not resolve the axial wave over a segment, the sub-steps of +``ei0_substeps auto`` resolve more of the segment rattle and can raise isolated spikes (at +``dtM = 2.5 ms`` the anchor peak of that cable rises from 0.091 to 0.119 MN); at a ``dtM`` that +resolves the wave a snap does not trigger them, and at 0.5 ms the cable takes no sub-step. 6. Establish the static initial condition ----------------------------------------- diff --git a/doc/options.rst b/doc/options.rst index d573b6e4..f01f4ee6 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -353,6 +353,57 @@ rejected as unknown. The dynamic Newton controls are set with ``dynamic_solver`` recovered intervals and the largest subdivision count used - both - ``1024 recovery_max_substeps`` + * - ``ei0_substeps`` / ``ei0substeps`` + - word + - ``auto``; ``off`` with ``False alpha_force_blend`` + - ``auto`` or ``off``. ``auto``: a converged step of an ``EI = 0`` line in which a segment + that ends the step taut (above 0.1 % of the largest step-start tension) turned by more + than ``ei0_substep_angle``, or a segment slack at the start of the step ended it above a + quarter of the largest step-start tension while the step does not resolve the axial wave + over the segment (the wave crosses it more than once per step), is solved again from the + same committed state in ``max(4, ceil(turn/ei0_substep_angle))`` equal sub-steps (at most + ``ei0_substep_max``). The tensions are those of the run audit (the elastic tension, or that + of the viscoelastic or Syrope law), and the step-start tension is taken as at least 0.1 % + of the line's initial tension, so a line slack all over at the step start does not count + barely taut segments. The end motion inside the step follows + the C2 quintic of the recovering step and the last sub-step lands on the given end state; + the output and coupling times are unchanged. At ``dtM = 0.1`` s a taut segment of the + Lozon 80 m all-chain mooring turns by up to 6 deg per step in 5 m / 7 s heave, and both + generalised-α blends then give snap-load peaks 10 to 20 % low; with ``auto`` they are 4 % + and 8 % low on average, within 4 % of the converged run sampled at the same 0.1 s output + times, at 1.6 to 2.5 times the wall time of the plain steps on the 5 m / 7 s and + 10 m / 14 s motions (1.67 times over the 20-case Lozon mooring envelope). A step that + triggers costs its plain step and usually four sub-steps, at most the plain step and + three passes of ``ei0_substep_max`` sub-steps (49 line solves at the default) when the + sub-stepped interval is measured again and that pass fails; where bodies or rods + sub-cycle the lines ``n`` times per ``dtM`` (``staggered bodyScheme``, coupled runs), + each sub-cycle is such a step, so the worst case is ``n (1 + 3 ei0_substep_max)`` line + solves per ``dtM``. If a sub-step does not converge, the plain step's own result is + kept. ``off`` takes every step as given, as before this option. ``monolithic + bodyScheme`` is the default of every standalone deck with ``Rigid6`` bodies, ``Point3`` + buoys, rods or ``Free``/``Connect`` points on ``EI = 0`` lines (7 of the shipped example + decks): its junction Newton needs the end reaction and tangent of the whole step, so the + lines attached to those objects and points are not sub-stepped (a line whose ends are all + fixed or anchored is), and the driver notes it once per run; ``staggered bodyScheme`` + sub-steps them. The standalone driver reports the sub-stepped steps per line, and + OpenFAST and FAST.Farm runs report them at the end of the run. The settings are checked + when the line is initialised. See :doc:`theory` + - both (``EI = 0`` lines) + - ``off ei0_substeps`` + * - ``ei0_substep_angle`` / ``ei0substepangle`` + - real, deg + - ``1.0`` + - finite, in ``(0, 90]``. Largest chord turn of a taut segment in one step before + ``ei0_substeps auto`` sub-steps it + - both (``EI = 0`` lines) + - ``1.0 ei0_substep_angle`` + * - ``ei0_substep_max`` / ``ei0substepmax`` + - integer, – + - ``16`` + - integer from 2 to 1024. Most sub-steps ``ei0_substeps auto`` takes for one step; a step + whose turn needs more is solved in this many, and the run notes it + - both (``EI = 0`` lines) + - ``16 ei0_substep_max`` Finite-EI cable controls ------------------------ @@ -389,7 +440,8 @@ Finite-EI cable controls earlier. On ``EI = 0`` lines ``False`` lets a segment that turns taut within a step carry the stretch extrapolated past the blended state, and lets a release create energy: on a light, axially stiff cable (80 kg/m, EA 8e8 N) under 3 m heave the fairlead peaks at - 4.2 MN against 0.10 MN with ``True`` (see :doc:`theory`). On finite-EI lines the blended + 4.2 MN against 0.10 MN with ``True`` at ``dtM = 2.5`` ms (converged finite-EI runs give + 0.093 MN; see :doc:`theory`). On finite-EI lines the blended tangent vectors are shortened while the line rotates and raise the mean tension at large ``dtM``: on the Lozon Gulf of Mexico 80 m cable in 3 m surge the mean hang-off tension is 12511 / 10097 / 9507 / 9360 N at @@ -398,7 +450,8 @@ Finite-EI cable controls (``True``) or 0.1 deg (``False``) in one step. A dynamic run with a torsional line (``END CONNECTIONS`` ``TorsStiffness`` at both ends) needs ``True``. The lines the raw C API builds without a deck (``CableDyn_InitLine``, ``CableDyn_InitLines``) always use - ``True``: their only integrator setting is ``rho_inf`` (:doc:`capi`) + ``True``: their only integrator setting is ``rho_inf`` (:doc:`capi`). ``False`` also + turns ``ei0_substeps`` off unless the deck sets it - standalone and coupled (finite-EI and ``EI = 0`` lines) - ``False alpha_force_blend`` * - ``cable_statics`` / ``cablestatics`` diff --git a/doc/theory.rst b/doc/theory.rst index 2a61acce..eb199e87 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1487,14 +1487,19 @@ difference (:math:`\partial p/\partial \mathbf{d}_{n+1} = -\mathbf{t}_n`). With state crosses the rest length, so the residual stays continuous in :math:`\mathbf{q}_{n+1}`. A cap on the slack end states alone would jump there, by up to :math:`\alpha_f T_n` for a turned element. The cap does not act on an element that ends above :math:`\alpha_f/(1 - \alpha_f)\,T_n` -(0.4 :math:`T_n`), nor on one that keeps its direction and ends taut, nor on one slack at -:math:`t_n`: those elements, every element going taut (where the force blend dissipates), and +(0.4 :math:`T_n`), nor on one that keeps its direction and ends taut, nor (but for the share of +its dashpot, below) on one slack at :math:`t_n`: those elements, every element going taut (where the force blend dissipates), and every line that allows compression keep the force blend. In the slack-cable case above the internal forces created 2.7e8 J over 20 s with the configuration blend, 6.7e7 J with the force blend alone, 0.19 J with a cap on :math:`e_n - e_{n+1}` (the turn of the releasing segments) and -4e-4 J (round-off) with the projected cap. The fairlead peak is 0.10 MN. The snap is not -resolved in time: with the cap the peak ranges from 0.10 to 0.18 MN over :math:`\Delta t` from -2.5 to 0.25 ms, against 0.13 to 0.19 MN at :math:`\rho_\infty = 0`. For a linear element the +4e-4 J (round-off) with the projected cap. The fairlead peak is 0.10 MN at +:math:`\Delta t` = 2.5 ms, which is not a converged peak. The undamped ``EI = 0`` deck has no +converged snap peak: the peak rises as :math:`\Delta t` falls (0.32 to 0.46 MN at microsecond +steps, also with an explicit lumped-mass solver), as single segments rattle, and falls with +mesh refinement at a fixed step; its 20 ms averages converge to 0.083 MN at the fairlead and +0.047 MN at the anchor, the slack-to-taut event, and converged finite-EI runs give 0.093 MN at +the fairlead and 0.057 MN at the anchor (see :doc:`modeling`, snap loads on slack lines). For +a linear element the force blend and the cap reduce to the configuration blend, so the linear spectral properties and the second-order accuracy are unchanged. @@ -1524,7 +1529,11 @@ segments (the snap is not resolved at that step, so the peak depends on round-of compilers and platforms give other values) and at 0.145 MN without it, against 0.082 to 0.095 MN at :math:`\Delta t` from 0.5 to 2.5 ms. A taut Syrope line in 4 m surge that goes slack peaks at 1.64 MN at 0.1 s, against 1.78 MN at 1 and 2.5 ms, with or -without the cap. +without the cap. These figures take every step as given (``off ei0_substeps``); with the +rotation- and snap-resolved sub-steps of the default (below) the two lines peak at 0.062 MN and +1.81 MN. A single peak of an unresolved snap says little: over seven runs whose heave amplitude +differs by up to :math:`3\times10^{-4}` the viscoelastic anchor peaks at 0.056 to 0.079 MN +(mean 0.063 MN) with the sub-steps and at 0.056 to 0.085 MN (mean 0.065 MN) without them. An elastic segment with axial damping (``BA``) also keeps :math:`\alpha_f T_{d,n}` along :math:`\mathbf{t}_n`, :math:`T_{d,n}` the tension of its dashpot at :math:`t_n`. A segment that @@ -1554,6 +1563,26 @@ so the force-blended dashpot of a taut segment keeps the standard generalised-α which a linear dashpot is dissipative; :math:`\phi` is continuous, and so is the capped force. The viscoelastic law keeps its total tension, dashpots included, as :math:`T_n` (above). +A damped segment slack at :math:`t_n` (:math:`T_n = 0`, :math:`e_n \le 0`) whose ends separate +there keeps :math:`\alpha_f T_{d,n}` along :math:`\mathbf{t}_n` with no strain energy behind it, +and returns :math:`\alpha_f T_{d,n} p` when the step turns or reverses its ends. It has no +:math:`W_n` (and an empty band, :math:`\phi = 1`); its budget is the dashpot's own one-step +dissipation :math:`W_d = T_{d,n}\,|\dot l_n|\,\Delta t`, :math:`\dot l_n` the dashpot's +elongation rate at :math:`t_n` (the axial rate, less :math:`l_n \dot l_0/l_0` while the line +pays out), so that :math:`T_{d,n} = (BA/l_0)\,\dot l_n` and :math:`W_d > 0` whenever +:math:`T_{d,n} \ne 0`. When :math:`p > 0` the kept force :math:`\alpha_f T_{d,n}` is replaced by +:math:`(W_d + N_d)/p` when that is smaller, with the end share's credit +:math:`N_d = \max((1 - \alpha_f) T_{d,n+1} p_{n+1}, 0)`, and the tangent takes the difference as +above (a compressive :math:`T_{d,n}` is capped alike when :math:`p < 0`). The kept dashpot share +of an element slack at the step start returns at most its own one-step dissipation +:math:`T_{d,n} |\dot l_n| \Delta t` plus the end share's credit. The capped force grows without +bound as :math:`p \to 0^+`, so it is continuous there; it acts only where +:math:`\alpha_f |p| > |\dot l_n| \Delta t`, a turn or reversal well beyond the step-start motion +whose end share does little work (a reversal along the chord feeds the end share's dashpot, +whose credit covers it). In the test chain the kept share returned up to 46 times +:math:`W_d + N_d` before the cap covered slack starts. Taut-start and undamped segments are +unchanged. + The one-sided seabed contact is not capped. A node that leaves the floor within a step keeps :math:`\alpha_f` of its step-start contact force :math:`N_n` for the whole step: over a lift-off distance :math:`d` it returns at most :math:`\alpha_f N_n d` to the motion, against the energy @@ -1654,6 +1683,62 @@ the interval-start and target position, velocity, and acceleration. If the halve complete the interval, the interval-start state is restored and the full step is re-run, so no partly subdivided state is ever committed. +**Rotation- and snap-resolved sub-steps** (``ei0_substeps auto``, the default). A converged +``EI = 0`` step is measured against its committed start: the largest chord turn +:math:`\theta` of a segment that ends the step above :math:`10^{-3}\,T_\text{max}`, the +largest step-start tension, and whether a segment slack at the start ends above +:math:`T_\text{max}/4` while the axial wave crosses it more than once in the step +(:math:`\Delta t\,c/l_0 > 1`, :math:`c` from the dynamic axial stiffness as in the run audit +below); a step that resolves the axial wave resolves the snap as given. The tensions are those +the run audit takes, the elastic tension of a plain segment and the law's tension of a +viscoelastic or Syrope one, with the step's unstretched lengths, and :math:`T_\text{max}` is at +least :math:`10^{-3}` of the line's initial tension, so a line slack all over at the step start +does not count barely taut segments. (A floor at the initial tension itself raised the snap +threshold in the slack phases of the Lozon semitaut line below, whose anchor peaks then came +out up to 29 % high.) A +segment slack at the step start counts for the turn: counting only segments taut at both ends +of the step left the Lozon semitaut anchor peaks (below) up to 5 % high on average and up to +25 % high in single runs. When :math:`\theta` exceeds ``ei0_substep_angle`` +:math:`\theta_s` (default 1°), or such a snap occurred, the interval is solved again from the +same committed state, constitutive and friction states included, in +:math:`n = \max(4, \lceil\theta/\theta_s\rceil)` equal sub-steps, at most ``ei0_substep_max`` +(default 16), with the prescribed motion on the quintic trajectory of the recovery above and +the last sub-step on the target state. The trial step under-turns a line whose rotation it does +not resolve, so the sub-stepped interval is measured again; when its turn needs more sub-steps +it is solved once more with them. If a sub-step does not converge, the plain step's own +result is kept. A step recovered after a stall (above) and the halves of a line-system step +halved after a failure take their sub-steps as given; when the halves fail too, the full step +is re-run as the nominal step, sub-steps included. The decision uses only the committed state, +the step inputs and the line's initial tension, so a restart repeats it, and the host time +grid, output and coupling times are unchanged. Every route that steps ``EI = 0`` lines uses it +(standalone lines and line systems, OpenFAST, FAST.Farm and the C API), except the lines +attached to the bodies, rods and points of the monolithic body and point coupling, whose +junction Newton needs the end reaction and condensed end tangent of the nominal step (a line of +such a deck whose ends are all fixed or anchored is sub-stepped); ``off`` takes every step as +given, and ``False alpha_force_blend`` turns it off unless the deck sets it. A step that +triggers costs the plain step and usually four sub-steps; at most it costs the plain step and +three passes of ``ei0_substep_max`` sub-steps, once for each object sub-step where bodies or +rods sub-cycle the lines. + +At ``dtM`` 0.1 s a taut segment of the Lozon 80 m all-chain mooring turns by up to 6° per step +under 5 m / 7 s heave. Over seven runs whose heave amplitude differs by up to +:math:`3\times10^{-4}` (the snap peaks at that step vary by 15 to 20 points from one run to the +next), the fairlead and anchor maxima are then 15 % and 17 % below a 0.25 ms run with the force +blend and 10 % and 18 % below it with the configuration blend; the release cap acts in 0.3 % of +the element steps, never within 0.5 s of a peak, and removing it changes the cycle maxima by less +than 1 %. The peaks follow the algorithmic damping instead: 28 % and 31 % low at +:math:`\rho_\infty = 0`, 10 % and 40 % high at 0.6. With ``auto`` they are 4 % and 8 % low +(1 % high and 4 % low against the reference sampled on the same 0.1 s output grid), and the +anchor maxima of the 200 m semitaut mooring in 10 m / 14 s and 5 m / 7 s surge, 16 % and 26 % +high taken as given, are 4 % high and 2 % low (over thirteen runs 5 % high and 0.3 % low, single +runs from 4 % low to 21 % high). +Two or three sub-steps of a step that turned by 1 to 3° left those anchor peaks 8 % high on +average (up to 22 %); four bring them within 3 %, hence the minimum. Resolving the sub-steps +of a step recovered after a stall as well left them 9 % high, so the recovery takes its sub-steps +as given. Over the 20 motions of the Lozon mooring envelope at ``dtM`` 0.1 s the march takes +1.67 times as long as with plain steps, 1.6 to 2.5 times on the 5 m / 7 s and 10 m / 14 s +motions. + **Step size.** Being implicit, the scheme is not bound by the explicit axial-wave limit. In the snap-load verification a slack line snapping to about 10 MN integrates stably at :math:`\Delta t = 20\,\mathrm{ms}`, well above the explicit limit of 3.2 ms, with the peak @@ -1662,13 +1747,18 @@ response of interest and, for explicitly integrated points and bodies (below), t stability limit. The standalone driver audits every ``EI = 0`` line on the initial state and at each output step, and reports at the end of the run: -- the largest turn of the chord of a taut segment in one step. Above 1 deg it prints a note: - against a 3.125 ms reference on chain catenaries under 5 m heave, 10 m surge and 15 m sway - and on a light laid cable under 10 m sway, the mean and standard deviation of the fairlead - tension err by 0.9 % at 1.2 deg per step (sway, standard deviation), and by 0.6 % at - 1.4 deg and 1.3 % at 2.9 deg (heave, mean), in proportion with the turn; +- the steps ``ei0_substeps auto`` solved in sub-steps, with the largest count, those that needed + more than ``ei0_substep_max``, and those that kept the plain step; +- the largest turn of the chord of a taut segment in one solver step (the sub-steps of a + sub-stepped or recovered step count as steps). Above 1 deg it prints a note (with ``auto`` + above 1.1 times the larger of 1 deg and ``ei0_substep_angle``): against a 3.125 ms reference + on chain catenaries under 5 m heave, 10 m surge and 15 m sway and on a light laid cable under + 10 m sway, the mean and standard deviation of the fairlead tension err by 0.9 % at 1.2 deg per + step (sway, standard deviation), and by 0.6 % at 1.4 deg and 1.3 % at 2.9 deg (heave, mean), + in proportion with the turn, and at about 6 deg per step snap-load peaks come out 10 to 20 % + low (above); - segments that go from slack to taut above the initial tension in one step while the axial - wave crosses a segment more than once per step (:math:`\Delta t\,c/l_0 > 1`, + wave crosses a segment more than once per solver step (:math:`\Delta t\,c/l_0 > 1`, :math:`c = \sqrt{EA/m}` with the dynamic stiffness of the segment, :math:`EA_D` of a viscoelastic segment and :math:`\alpha + \beta T` of a Syrope one): the snap peaks are then not resolved in time, and the note asks for a confirmation at a smaller ``dtM``; diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 30b6a095..bbe679ab 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -571,15 +571,50 @@ Warnings and notes that do not stop a run * - ``Note: line ...: a nodal tangent turned up to ... deg in one step`` - the time-step audit of a finite-EI line: above 0.25° per step (0.1° with ``False alpha_force_blend``) the mean tension can err by about 1 %. Reduce ``dtM``. - * - ``Note: line ...: a taut segment turned up to ... deg in one step`` - - the time-step audit of an ``EI = 0`` line: above 1° per step the mean and standard - deviation of the tension can err by about 1 % (1.3 % at 2.9° on a heaving chain). Reduce - ``dtM`` if that matters for the result. + * - ``Note: line ...: a taut segment turned up to ... deg in one solver step`` + - the time-step audit of an ``EI = 0`` line, per solver step (the sub-steps of a + sub-stepped step count as steps): above 1° per step the mean and standard deviation of + the tension can err by about 1 % (1.3 % at 2.9° on a heaving chain), and near 6° per step + snap-load peaks come out 10 to 20 % low with either generalised-α blend. With + ``off ei0_substeps`` set ``auto`` (the default) or reduce ``dtM``; with ``auto`` the note + means steps it did not resolve (more than ``ei0_substep_max`` needed, a step recovered + after a stall or a half of a line-system step halved after a failure, whose sub-steps + are taken as given, a step that kept its plain result because a sub-step failed, or a + line attached to a body, rod or point of the monolithic body and point coupling, which + is not sub-stepped): reduce ``dtM``. + * - ``Note: line ...: ei0_substeps auto solved ... of the ... line step(s) it examined in sub-steps`` + - information: the steps in which a taut segment turned by more than ``ei0_substep_angle`` + or a segment snapped from slack to taut were solved in sub-steps (see + ``ei0_substeps``). Only committed steps count: a step that is rolled back and taken + again (a line-system step halved after a stall, a step recovered after a stall, a + corrector or a re-solved coupling step) counts once, as it is finally taken, so the + steps examined can be fewer than the line's steps. A companion note counts the steps + that needed more than ``ei0_substep_max`` sub-steps, and another the steps that kept the + plain step's result because a sub-step did not converge. OpenFAST and FAST.Farm print the + same counts, summed over the lines, as ``CableDyn: ei0_substeps auto solved ...`` at the + end of the run. + * - ``Note: ei0_substeps auto does not sub-step the EI = 0 lines attached to the bodies, rods and points of the monolithic body/point step`` + - information, once per run of a deck with ``monolithic bodyScheme`` coupling, the default + of every standalone deck with ``Rigid6`` bodies, ``Point3`` buoys, rods or + ``Free``/``Connect`` points on ``EI = 0`` lines (7 of the shipped example decks): the + lines attached to those objects and points are stepped inside the junction Newton and + taken whole at each monolithic step (``dtM``, divided by ``accuracy bodySubstep``, the + default, to resolve the body-mooring modes), so their rotation and snaps are resolved + only as far as that step resolves them; a line whose ends are all fixed or anchored is + sub-stepped as usual. Reduce ``dtM`` when the segment-turn note above appears for them, + or select ``staggered bodyScheme``, which sub-steps them. * - ``Note: line ...: ... segment step(s) went from slack to taut above the initial tension`` - - snap loads on an ``EI = 0`` line at a ``dtM`` that does not resolve the axial wave over a - segment: the peak is set by a single step (a 15 m surge of a semi-taut chain–polyester - line peaks at 5.7 MN at ``dtM`` 0.05 s against 4.6 MN at 0.0025 s). The run is valid; - confirm design peaks with a smaller ``dtM``. + - snap loads on an ``EI = 0`` line at a solver step that does not resolve the axial wave + over a segment: the peak is set by a single step. A 15 m surge of a semi-taut + chain–polyester line peaks at 4.65 MN at ``dtM`` 0.05 s with the default sub-steps + (5.7 MN with ``off ei0_substeps``) against 4.6 MN at 0.0025 s. The run is valid; confirm + design peaks with a smaller ``dtM``. On a line without axial damping (``BA = 0``) the + snap peaks do not converge in time or mesh, as single segments rattle; a smaller ``dtM`` + raises them, and at a ``dtM`` that does not resolve the axial wave the sub-steps of + ``ei0_substeps auto`` can raise isolated spikes. Give + the line physical axial damping (``BA`` in N·s, not the per-segment damping-ratio form, + which changes with the mesh) or finite ``EI`` to obtain converged peaks (see + :doc:`modeling`). * - ``Warning: line ...: segment ... carried ... N at t = ... s for a single step, ... times the largest tension on the line one step before and after`` - a non-physical tension spike: the tension of one segment (elastic, viscoelastic or diff --git a/examples/cabledyn_options_reference.dat b/examples/cabledyn_options_reference.dat index 2d264baf..dabeaebe 100644 --- a/examples/cabledyn_options_reference.dat +++ b/examples/cabledyn_options_reference.dat @@ -45,6 +45,9 @@ True alpha_force_blend - Generalised-alpha force blend, finite-EI and EI=0 False tensile_safety - Element-mean axial-force audit {False; warn; True=reject} [default: False] 2.0e-6 tensile_strain_tolerance - Dynamic audit strain band [default: 2.0e-6] 1024 recovery_max_substeps - Internal dynamic-step recovery ceiling {4..65536} [default: 1024] +auto ei0_substeps - EI=0 sub-steps for segment rotation and slack-taut snaps {auto; off} [default: auto; off with False alpha_force_blend] +1.0 ei0_substep_angle - Largest taut-segment turn per EI=0 step before sub-stepping (deg) {0 str | None: if value.lower() in {"equilibrium", "element"} else "must be equilibrium or element" ) + if key == "ei0_substeps": + return None if value.lower() in {"auto", "off"} else "must be auto or off" + if key == "ei0_substep_angle": + try: + numeric = _native_float(value) + except ValueError: + return "must lie in (0, 90] deg" + return ( + None if math.isfinite(numeric) and 0.0 < numeric <= 90.0 else "must lie in (0, 90] deg" + ) + if key == "ei0_substep_max": + try: + numeric = _native_float(value) + except ValueError: + return "must be an integer in [2, 1024]" + if not math.isfinite(numeric): + return "must be an integer in [2, 1024]" + nearest = round(numeric) + integer_tolerance = 16.0 * math.ulp(1.0) * max(1.0, abs(numeric)) + if abs(numeric - nearest) > integer_tolerance or not 2 <= nearest <= 1024: + return "must be an integer in [2, 1024]" + return None if key in {"axial_quadrature_order", "bending_quadrature_order"}: try: numeric = _native_float(value) diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index 2760d72a..c8c783b6 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -666,6 +666,14 @@ def test_unknown_scalar_option_keyword_fails_closed(tmp_path): ("maybe", "alpha_force_blend", "native boolean"), ("relaxed", "cable_statics", "continuation or sequenced"), ("nodal", "OutputRecovery", "equilibrium or element"), + ("on", "ei0_substeps", "auto or off"), + ("0", "ei0_substep_angle", r"\(0, 90\] deg"), + ("91", "ei0SubstepAngle", r"\(0, 90\] deg"), + ("NaN", "ei0_substep_angle", r"\(0, 90\] deg"), + ("1", "ei0_substep_max", r"integer in \[2, 1024\]"), + ("2.5", "ei0_substep_max", r"integer in \[2, 1024\]"), + ("1025", "ei0SubstepMax", r"integer in \[2, 1024\]"), + ("2048.5", "ei0_substep_max", r"integer in \[2, 1024\]"), ], ) def test_invalid_scalar_option_values_fail_closed(tmp_path, value, keyword, message): @@ -741,6 +749,13 @@ def test_zero_e_exponent_waterkin_mode_is_accepted(tmp_path): "sequenced cableStatics", "equilibrium OutputRecovery", "element output_recovery", + "auto ei0_substeps", + "off ei0Substeps", + "0.5 ei0_substep_angle", + "90 ei0SubstepAngle", + "2 ei0_substep_max", + "1024 ei0SubstepMax", + "1.9999999999999998 ei0_substep_max", ], ) def test_native_scalar_option_vocabulary_is_accepted(tmp_path, row): diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 8596e50f..497f5ffd 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -51,7 +51,7 @@ MODULE CableDyn_DeckDriver USE CableDyn_Syrope, ONLY: CD_SYROPE_WC_LINEAR, CD_SYROPE_WC_QUADRATIC, CD_SYROPE_WC_EXP, & CD_SyropeType, CD_Syrope_Init, CD_Syrope_End, & CD_Syrope_Static_Tension, CD_Syrope_Slow_For_Tension, CD_SYROPE_OK - USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_DYN_OK + USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_DYN_OK, CD_EI0_SUBSTEPS_OFF, CD_EI0_SUBSTEPS_AUTO USE CableDyn_Model, ONLY: CD_ModelType, CD_Init_Line_Model, CD_End_Model, CD_Model_NCoupledDOF, CD_Model_NDOF, & CD_Get_Model_CoupledDofs, CD_Get_Model_State, CD_Get_Model_Tension, & CD_Get_Model_EndForces, & @@ -606,6 +606,12 @@ MODULE CableDyn_DeckDriver ! Generalised-alpha blend of the finite-EI dynamics (alpha_force_blend): force blend ! (default) or the configuration blend f_int(q_alpha_f). LOGICAL :: alpha_force_blend = CD_HC_FORCE_BLEND_DEFAULT + ! Rotation- and snap-resolved sub-stepping of the EI=0 lines (ei0_substeps): -1 not set + ! (auto with the force blend, off with False alpha_force_blend), else CD_EI0_SUBSTEPS_OFF + ! or CD_EI0_SUBSTEPS_AUTO; the turn per step it allows (deg) and its sub-step cap. + INTEGER :: ei0_substeps = -1 + REAL(wp) :: ei0_substep_angle = 1.0_wp + INTEGER :: ei0_substep_max = 16 ! Finite-EI static route order (cable_statics): 'continuation' (default) solves the ! catenary-seeded EI continuation first and the mesh-sequenced route as its fallback; ! 'sequenced' runs the mesh-sequenced route first. @@ -7632,6 +7638,13 @@ SUBROUTINE init_one_model(ln, sections, types, points, opts, model, ErrStat, Err dynamic_cfg%armijo_max_backtracks = opts%dynamic_backtracks dynamic_cfg%modified_newton = opts%dynamic_modified_newton dynamic_cfg%force_blend = opts%alpha_force_blend + ! ei0_substeps not set: auto with the force blend; the configuration blend (paper mode) + ! takes every step as given, as the article did + dynamic_cfg%ei0_substeps = opts%ei0_substeps + IF (opts%ei0_substeps < 0) dynamic_cfg%ei0_substeps = MERGE(CD_EI0_SUBSTEPS_AUTO, CD_EI0_SUBSTEPS_OFF, & + opts%alpha_force_blend) + dynamic_cfg%ei0_substep_angle = opts%ei0_substep_angle + dynamic_cfg%ei0_substep_max = opts%ei0_substep_max CALL CD_Build_Line_Mesh(secs, lts, .TRUE., conn, l0, ea, mpl, diam, es, em) IF (es /= CD_LINE_OK) THEN CALL fail(ErrStat, ErrMsg, 'line mesh for model init: '//TRIM(em)); RETURN @@ -13041,6 +13054,37 @@ SUBROUTINE apply_option(line, opts, ErrStat, ErrMsg) CALL rd_bool(val, opts%adaptive_mesh, ErrStat, ErrMsg) CASE ('alpha_force_blend', 'alphaforceblend') CALL rd_bool(val, opts%alpha_force_blend, ErrStat, ErrMsg) + CASE ('ei0_substeps', 'ei0substeps') + SELECT CASE (TRIM(to_lower(val))) + CASE ('auto') + opts%ei0_substeps = CD_EI0_SUBSTEPS_AUTO + CASE ('off') + opts%ei0_substeps = CD_EI0_SUBSTEPS_OFF + CASE DEFAULT + CALL fail(ErrStat, ErrMsg, 'OPTION ei0_substeps "'//TRIM(val)//'" must be auto or off') + END SELECT + CASE ('ei0_substep_angle', 'ei0substepangle') + CALL rd(val, x1, ErrStat, ErrMsg) + IF (ErrStat == 0) THEN + IF (.NOT. (IEEE_IS_FINITE(x1) .AND. x1 > CD_ZERO .AND. x1 <= 90.0_wp)) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION ei0_substep_angle must lie in (0, 90] deg'); RETURN + END IF + opts%ei0_substep_angle = x1 + END IF + CASE ('ei0_substep_max', 'ei0substepmax') + CALL rd(val, x1, ErrStat, ErrMsg) + IF (ErrStat == 0) THEN + ! the rule of the Python deck reader: an integer to within 16 ulp, whose nearest integer + ! lies in [2, 1024] (a value beyond 2048 in magnitude fails either test there) + IF (.NOT. IEEE_IS_FINITE(x1) .OR. ABS(x1) > 2048.0_wp) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION ei0_substep_max must be an integer in [2, 1024]'); RETURN + END IF + IF (ABS(x1 - REAL(NINT(x1), wp)) > 16.0_wp*EPSILON(CD_ONE)*MAX(CD_ONE, ABS(x1)) .OR. & + NINT(x1) < 2 .OR. NINT(x1) > 1024) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION ei0_substep_max must be an integer in [2, 1024]'); RETURN + END IF + opts%ei0_substep_max = NINT(x1) + END IF CASE ('cable_statics', 'cablestatics') SELECT CASE (TRIM(to_lower(val))) CASE ('continuation') @@ -18004,6 +18048,15 @@ SUBROUTINE write_multibody_dynamic_out(deck_path, out_root, channels, types, bod IF (mb%implicit .AND. mb%n_steps_imp > 0) THEN WRITE (*, '(A,F6.2,A,I0,A,I0)') ' Monolithic body/point step: mean outer iterations ', & REAL(mb%n_outer, wp)/REAL(mb%n_steps_imp, wp), ', max ', mb%max_outer, ', step halvings ', mb%n_subdiv + ! the junction Newton needs the nominal step's end reaction and tangent of every line + ! attached to a body, rod or point it solves, so ei0_substeps auto leaves those line steps + ! whole (noted once per run); a line with no such end is sub-stepped as usual + IF (mb%has_sys) THEN + IF (ANY(mb%system%lines(:)%cfg%ei0_substeps == CD_EI0_SUBSTEPS_AUTO)) & + WRITE (*, '(A)') ' Note: ei0_substeps auto does not sub-step the EI = 0 lines attached to the '// & + 'bodies, rods and points of the monolithic body/point step (it needs the end reaction and tangent '// & + 'of the whole step); reduce dtM to resolve their rotation and snaps.' + END IF END IF CALL CD_Classify_Dynamic_Completion('multibody dynamic run', nstep, miss_count, max_consecutive_miss, & first_miss_time, last_miss_time, converged, ErrStat, ErrMsg) @@ -27468,16 +27521,44 @@ SUBROUTINE report_model_audit(model, line_id, dt) REAL(wp), INTENT(IN) :: dt REAL(wp), PARAMETER :: EI0_TURN_NOTE = 1.0_wp INTEGER :: ios - IF (model%audit_max_turn > EI0_TURN_NOTE) THEN + LOGICAL :: auto + CHARACTER(200) :: remedy + REAL(wp) :: turn_note + auto = model%cfg%ei0_substeps == CD_EI0_SUBSTEPS_AUTO + IF (auto .AND. model%sub_stats%events > 0) THEN + WRITE (output_unit, '(A,I0,A,I0,A,I0,A,I0,A)', IOSTAT=ios) ' Note: line ', line_id, & + ': ei0_substeps auto solved ', model%sub_stats%events, ' of the ', model%sub_stats%calls, & + ' line step(s) it examined in sub-steps to resolve segment rotation and slack-to-taut snaps (at most ', & + model%sub_stats%max_used, ' sub-steps per step).' + IF (model%sub_stats%capped > 0) WRITE (output_unit, '(A,I0,A,I0,A,I0,A)', IOSTAT=ios) ' Note: line ', & + line_id, ': ', model%sub_stats%capped, ' step(s) needed more than ei0_substep_max = ', & + model%cfg%ei0_substep_max, ' sub-steps; raise it or reduce dtM.' + END IF + IF (auto .AND. model%sub_stats%fallbacks > 0) WRITE (output_unit, '(A,I0,A,I0,A)', IOSTAT=ios) & + ' Note: line ', line_id, ': ', model%sub_stats%fallbacks, & + ' step(s) kept the whole step because a resolving sub-step did not converge.' + ! with ei0_substeps auto a step is solved in sub-steps whose average turn is at most + ! ei0_substep_angle; a single sub-step can turn slightly more + turn_note = EI0_TURN_NOTE + IF (auto) turn_note = 1.1_wp*MAX(EI0_TURN_NOTE, model%cfg%ei0_substep_angle) + IF (model%audit_max_turn > turn_note) THEN + ! per solver step: the sub-steps of a resolved or recovered step count as steps + IF (auto) THEN + remedy = 'steps ei0_substeps auto did not resolve (beyond ei0_substep_max, recovered after a '// & + 'stall, or in a monolithic body or point coupling step): reduce dtM.' + ELSE + remedy = 'set ei0_substeps auto (the default) or reduce dtM.' + END IF WRITE (output_unit, '(A,I0,A,F7.3,A)', IOSTAT=ios) ' Note: line ', line_id, ': a taut segment turned up to ', & - model%audit_max_turn, ' deg in one step; a smaller dtM would resolve the line''s rotation (tension '// & - 'mean and standard-deviation errors of about 1 % and more above 1 deg per step).' + model%audit_max_turn, ' deg in one solver step. Above about 1 deg per step the tension mean and '// & + 'standard deviation err by about 1 % and more, and at about 6 deg per step snap-load peaks come out '// & + '10 to 20 % low with either generalised-alpha blend: '//TRIM(remedy) END IF IF (model%audit_snaps > 0 .AND. model%audit_snap_courant > CD_ONE) THEN WRITE (output_unit, '(A,I0,A,I0,A,ES9.2,A,F0.1,A)', IOSTAT=ios) ' Note: line ', line_id, ': ', & model%audit_snaps, ' segment step(s) went from slack to taut above the initial tension; at dtM =', & dt, ' s the axial wave crosses a segment up to ', model%audit_snap_courant, & - ' times per step, so the snap-load peaks are not resolved in time: confirm peak tensions with a '// & + ' times per solver step, so the snap-load peaks are not resolved in time: confirm peak tensions with a '// & 'smaller dtM.' END IF IF (model%audit_spikes > 1) THEN diff --git a/src/CableDyn_Dynamic.f90 b/src/CableDyn_Dynamic.f90 index e7646397..06274e55 100644 --- a/src/CableDyn_Dynamic.f90 +++ b/src/CableDyn_Dynamic.f90 @@ -82,6 +82,15 @@ MODULE CableDyn_Dynamic !! + alpha_f r(q_n, v_n); .FALSE. evaluates them at the !! blended configuration (q_alpha, v_alpha). The finite-EI !! paths have their own setting. + ! Rotation- and snap-resolved sub-stepping of an EI=0 line model (CD_Step_Model of + ! CableDyn_Model; the kernel step here does not read these). With CD_EI0_SUBSTEPS_AUTO a + ! converged step whose taut segments turned by more than ei0_substep_angle degrees, or in + ! which a segment went from slack to taut with a large tension, is solved again from the + ! same committed state in max(4, ceil(turn/ei0_substep_angle)) equal sub-steps, at most + ! ei0_substep_max; CD_EI0_SUBSTEPS_OFF takes every step as given. + INTEGER :: ei0_substeps = 1 !! CD_EI0_SUBSTEPS_AUTO (1) or CD_EI0_SUBSTEPS_OFF (0) + REAL(wp) :: ei0_substep_angle = 1.0_wp !! largest turn of a taut segment per step, deg, (0, 90] + INTEGER :: ei0_substep_max = 16 !! sub-step cap per step, [2, 1024] END TYPE GenAlphaConfig TYPE :: CD_CableGenAlphaWorkspace @@ -224,6 +233,9 @@ MODULE CableDyn_Dynamic INTEGER, PARAMETER, PUBLIC :: CD_DYN_BADINPUT = 1 INTEGER, PARAMETER, PUBLIC :: CD_DYN_SINGULAR = 2 INTEGER, PARAMETER, PUBLIC :: CD_DYN_ALLOCFAIL = 3 + ! GenAlphaConfig%ei0_substeps + INTEGER, PARAMETER, PUBLIC :: CD_EI0_SUBSTEPS_OFF = 0 + INTEGER, PARAMETER, PUBLIC :: CD_EI0_SUBSTEPS_AUTO = 1 ABSTRACT INTERFACE SUBROUTINE CD_Cable_Dynamic_Load_Proc(q, v, force, jac_q, jac_v, ErrStat, ErrMsg) @@ -2077,7 +2089,8 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) !! For an elastic element T^_1 = T_1: its blend returns at most W_0 over every step (an !! element that ends slack carries the discrete energy gradient W_0/p and returns exactly !! W_0), and the cap acts on a taut end state only when the element turned and - !! T_1 < alpha_f/(1 - alpha_f) T_0. An element slack at t_n keeps the force blend. + !! T_1 < alpha_f/(1 - alpha_f) T_0. An element slack at t_n keeps the force blend, but for + !! the kept share of its dashpot (below). !! N >= W_0/2 always (k e_0 <= T_0), so 4 alpha_f p <= e_0 is a sufficient test of an !! inactive cap. The residual and the tangent are corrected by the difference. !! An element whose axial law a load callback carries (ea = 0, T_0 from start_tension) is @@ -2107,17 +2120,34 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) !! dashpot, the cap is the one above, so the force-blended dashpot of a taut line keeps the !! standard generalised-alpha treatment. The weight is continuous, so is the capped force; !! the tangent carries dT_d,1/dq_{n+1} through v_{n+1} (gamma/(beta dt)). + !! An element with a dashpot that is slack at t_n (T_0 = 0, e_0 <= 0) keeps only + !! alpha_f T_d,0 along t_0, which returns alpha_f T_d,0 p, with no strain energy behind it, + !! when the step reverses or turns its ends against the step-start rate. Its budget is the + !! dashpot's own one-step dissipation W_d = T_d,0 ldot_0 dt, ldot_0 = l0 T_d,0/BA the + !! dashpot's elongation rate at t_n (the axial rate less the paid-out rate l_n l0_dot/l0; + !! the axial rate itself without payout), so W_d > 0 whenever T_d,0 /= 0. When + !! alpha_f T_d,0 p > 0 exceeds W_d + N_d, N_d = max((1 - alpha_f) T_d,1 p_1, 0) the end + !! share's credit (phi = 1: the band of a slack start is empty), the element carries + !! (W_d + N_d)/p instead of alpha_f T_d,0 along t_0, so the kept dashpot share of an + !! element slack at the step start returns at most its own one-step dissipation + !! T_d,0 |ldot_0| dt plus the end share's credit. The capped force grows without bound as + !! p -> 0 (W_d > 0), so the force is continuous there; alpha_f |p| <= |ldot_0| dt is a + !! sufficient test of an inactive cap. The same law covers a compressive T_d,0 (p < 0). REAL(wp), INTENT(IN) :: q_eval(:) REAL(wp), INTENT(INOUT) :: Rout(:) REAL(wp), INTENT(INOUT), OPTIONAL :: effout(:, :), effbandout(:, :) INTEGER :: e, na, nb, i, j, gi(6), fi, fj REAL(wp) :: d1(3), l1, e1, e0, t0, p, p1, num, ln, k0, ten1, cosang, dg, delta, t1(3), g(3), blk(3, 3), sgn - REAL(wp) :: band, phi, dphi, td1, dv(3), dp1(3), dtd1(3), kc - LOGICAL :: taut_end, damped + REAL(wp) :: band, phi, dphi, td1, dv(3), dp1(3), dtd1(3), kc, credit + LOGICAL :: taut_end, damped, slack band = alpha_f/(CD_ONE - alpha_f) DO e = 1, n_elem t0 = tension_n(e) - IF (.NOT. t0 > CD_ZERO) CYCLE + ! an element slack at t_n is capped only for the kept share of a step-start dashpot force + slack = .NOT. t0 > CD_ZERO + IF (slack) THEN + IF (.NOT. (dcoef_n(e) > CD_ZERO .AND. ABS(damp_n(e)) > CD_ZERO)) CYCLE + END IF na = elem_conn(1, e) nb = elem_conn(2, e) d1 = q_eval(3*nb - 2:3*nb) - q_eval(3*na - 2:3*na) @@ -2125,10 +2155,43 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) ! projected shortening p = l_n - t_0 . d_1 (l_n = l0 + e_0); the common case, an element ! that does not release, is decided here without a root p = e0 + (l0(e) - (chord_n(1, e)*d1(1) + chord_n(2, e)*d1(2) + chord_n(3, e)*d1(3))) - ! a damped element whose end state lies below the band edge l0 + band e_0 - damped = dcoef_n(e) > CD_ZERO - IF (damped) damped = d1(1)*d1(1) + d1(2)*d1(2) + d1(3)*d1(3) < (l0(e) + band*e0)**2 - IF (damped) THEN + ! a damped element taut at t_n whose end state lies below the band edge l0 + band e_0 + damped = .FALSE. + IF (.NOT. slack) THEN + damped = dcoef_n(e) > CD_ZERO + IF (damped) damped = d1(1)*d1(1) + d1(2)*d1(2) + d1(3)*d1(3) < (l0(e) + band*e0)**2 + END IF + IF (slack) THEN + ! the kept dashpot share alpha_f T_d,0 returns work only when T_d,0 p > 0, and stays + ! within W_d = T_d,0^2 dt/(BA/l0) while alpha_f |p| <= |ldot_0| dt + IF (.NOT. damp_n(e)*p > CD_ZERO) CYCLE + IF (alpha_f*ABS(p)*dcoef_n(e) <= ABS(damp_n(e))*dt) CYCLE + l1 = NORM2(d1) + IF (.NOT. l1 > CD_ZERO) CYCLE + ln = l0(e) + e0 + t1 = d1/l1 + cosang = t1(1)*chord_n(1, e) + t1(2)*chord_n(2, e) + t1(3)*chord_n(3, e) + p1 = (l1 - ln) + 0.5_wp*ln*((t1(1) - chord_n(1, e))**2 + (t1(2) - chord_n(2, e))**2 + & + (t1(3) - chord_n(3, e))**2) + dv = v_eval(3*nb - 2:3*nb) - v_eval(3*na - 2:3*na) + td1 = dcoef_n(e)*(DOT_PRODUCT(t1, dv) - l1*rl0dot_n(e)) + credit = (CD_ONE - alpha_f)*td1*p1 + num = damp_n(e)*damp_n(e)*dt/dcoef_n(e) + MAX(credit, CD_ZERO) + dg = num/p + IF (ABS(dg) >= alpha_f*ABS(damp_n(e))) CYCLE + delta = dg - alpha_f*damp_n(e) + Rout(3*na - 2:3*na) = Rout(3*na - 2:3*na) - delta*chord_n(:, e) + Rout(3*nb - 2:3*nb) = Rout(3*nb - 2:3*nb) + delta*chord_n(:, e) + IF (.NOT. (PRESENT(effout) .OR. PRESENT(effbandout))) CYCLE + ! d(delta)/d(x_b) = g, d(delta)/d(x_a) = -g: dp/dd_1 = -t_0, and while the credit is + ! positive dp_1/dd_1 and dT_d,1/dx_b as on the taut damped path + g = (num/(p*p))*chord_n(:, e) + IF (credit > CD_ZERO) THEN + dp1 = t1 - (ln/l1)*(chord_n(:, e) - cosang*t1) + dtd1 = dcoef_n(e)*((dv - DOT_PRODUCT(t1, dv)*t1)/l1 + (gamma/(beta*dt) - rl0dot_n(e))*t1) + g = g + ((CD_ONE - alpha_f)/p)*(td1*dp1 + p1*dtd1) + END IF + ELSE IF (damped) THEN IF (.NOT. p > CD_ZERO) CYCLE l1 = NORM2(d1) IF (.NOT. l1 > CD_ZERO) CYCLE diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index 9e3971ad..a3198b82 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -55,8 +55,10 @@ MODULE CableDyn_Model CD_Cable_Added_Mass, CD_Cable_Added_Mass_Matrix, CD_Cable_Added_Mass_Force, & CD_Added_Mass_Element, CD_Added_Mass_Element_Matrix, CD_Added_Mass_Element_Force USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_CableGenAlphaWorkspace, CD_Clear_GenAlpha_Workspace, & - CD_Cable_Initial_Acceleration, CD_Cable_Gen_Alpha_Step, CD_DYN_OK, CD_DYN_ALLOCFAIL + CD_Cable_Initial_Acceleration, CD_Cable_Gen_Alpha_Step, CD_DYN_OK, CD_DYN_ALLOCFAIL, & + CD_EI0_SUBSTEPS_AUTO, CD_EI0_SUBSTEPS_OFF USE CableDyn_Mesh, ONLY: CD_Partition_Free_Dofs, CD_Validate_Connectivity + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 USE CableDyn_Linalg, ONLY: CD_Solve_Dense_As_Banded, CD_Solve_Dense_As_Banded_Multiple, CD_Factor_Banded, & CD_Solve_Factored_Banded_Multiple USE CableDyn_Profile, ONLY: CD_Profile_Count_Line_Step @@ -64,10 +66,12 @@ MODULE CableDyn_Model PRIVATE PUBLIC :: CD_ModelType + PUBLIC :: CD_SubstepStats PUBLIC :: CD_Init_Model PUBLIC :: CD_Init_Line_Model PUBLIC :: CD_Step_Model PUBLIC :: CD_Step_Model_Recovering + PUBLIC :: CD_Get_Model_Substep_Counts PUBLIC :: CD_End_Model PUBLIC :: CD_Model_NCoupledDOF PUBLIC :: CD_Model_NDOF @@ -112,6 +116,44 @@ MODULE CableDyn_Model INTEGER, PARAMETER, PUBLIC :: CD_MODEL_NOT_INITIALIZED = 3 INTEGER, PARAMETER, PUBLIC :: CD_MODEL_ALLOCFAIL = 4 INTEGER, PARAMETER :: MODEL_DEFAULT_MAX_SUBSTEPS = 1024 + ! Rotation- and snap-resolved sub-stepping (CD_Step_Model, cfg%ei0_substeps). The tension + ! scale of a step is the largest step-start tension, floored at SUB_TAUT_FRACTION of the + ! line's initial tension (sub_t_init, the largest at CD_Init_Model): a line slack all over at + ! the step start would otherwise count any segment that ends it barely taut. (Flooring at the + ! initial tension itself raised the snap threshold in the slack phases of the Lozon semitaut + ! line, whose anchor snap peaks then came out up to 29 % high.) A segment that ends the step + ! taut above SUB_TAUT_FRACTION of the scale counts for the turn (the run audit's floor), also + ! when it was slack at the start: + ! counting only segments taut at both ends left the Lozon semitaut anchor snap peaks up to + ! 25 % high. One slack at the step start that ends above SUB_SNAP_FRACTION of the scale is a + ! snap when the step does not resolve its axial wave (dt c/l0 > 1, c from the dynamic axial + ! stiffness; a step that does resolves the snap as given). A step solved in sub-steps takes + ! at least SUB_SNAP_STEPS of them: on the Lozon semitaut line two or three sub-steps of a step + ! that turned 1 to 3 deg left the anchor snap peaks 8 % high on average (up to 22 %), four + ! brought them within 3 % of the converged run. The tensions are those the run audit takes: + ! the dynamic EA times the strain of an elastic segment, the law's tension of a viscoelastic + ! or Syrope one. + REAL(wp), PARAMETER :: SUB_TAUT_FRACTION = 1.0e-3_wp, SUB_SNAP_FRACTION = 0.25_wp + INTEGER, PARAMETER :: SUB_SNAP_STEPS = 4 + + ! The state a line step commits, as the sub-stepping (CD_Step_Model) saves it in its two + ! slots. commit_state_copy holds the one list of that state. + TYPE :: CD_ModelCommitSlot + REAL(wp), ALLOCATABLE :: q(:), v(:), a(:), ve_dl_1(:), syrope_slow(:), syrope_tmax(:) + REAL(wp), ALLOCATABLE :: fr_anchor(:, :) + END TYPE CD_ModelCommitSlot + + ! Diagnostics of the rotation- and snap-resolved sub-stepping (CD_Step_Model): calls counts + ! the steps it examined, events those it solved in sub-steps (max_used the largest count), + ! capped those whose turn needed more than cfg%ei0_substep_max, fallbacks those that returned + ! to the plain step after a sub-step failed, remeasured those whose sub-stepped interval + ! needed more sub-steps and was solved again. Only committed steps count: the line system + ! rolls these back with the line states (CableDyn_System), and a stalled step that + ! CD_Step_Model_Recovering takes again in its rungs (as given) is not counted. + TYPE :: CD_SubstepStats + INTEGER(int64) :: calls = 0, events = 0, capped = 0, fallbacks = 0, remeasured = 0 + INTEGER :: max_used = 1 + END TYPE CD_SubstepStats TYPE :: CD_ModelType !! Persistent positions-only EI=0 model state and immutable mesh/properties. @@ -309,6 +351,31 @@ MODULE CableDyn_Model REAL(wp) :: audit_snap_courant = CD_ZERO INTEGER :: audit_snaps = 0, audit_spikes = 0, audit_spike_elem = 0 REAL(wp) :: audit_spike_time = CD_ZERO, audit_spike_tension = CD_ZERO, audit_spike_ratio = CD_ZERO + ! audit_hmax: the largest single solver step committed since the last audit (the nominal + ! step, or a sub-step of the resolved or the recovering step); the audit measures turns and + ! axial wave crossings per solver step with it. Diagnostics only. + REAL(wp) :: audit_hmax = CD_ZERO + ! Rotation- and snap-resolved sub-stepping (CD_Step_Model): sub_stats its diagnostics and + ! sub_stats_rollback their twin at the last save of the system-rollback state + ! (CableDyn_System). sub_t_init is the line's initial tension, which floors the tension + ! scale of a step (SUB_TAUT_FRACTION of it; the largest segment tension at CD_Init_Model, a + ! parameter of the line, copied with the model). The other sub_* arrays are scratch: + ! sub_slot(1) the committed state at the step start, sub_slot(2) the state the plain step + ! reached, sub_t0 and sub_t1 the segment tensions at the step start and end, and + ! sub_pq/pv/pa the sub-step boundary motion. + TYPE(CD_SubstepStats) :: sub_stats, sub_stats_rollback + REAL(wp) :: sub_t_init = CD_ZERO + ! audit_hmax at the last save of the system-rollback state (CableDyn_System) + REAL(wp) :: audit_hmax_rollback = CD_ZERO + TYPE(CD_ModelCommitSlot) :: sub_slot(2) + REAL(wp), ALLOCATABLE :: sub_t0(:), sub_t1(:), sub_pq(:), sub_pv(:), sub_pa(:) + ! TEST-ONLY hooks of the sub-stepping, never set by a production caller: sub_test_fail > 0 + ! makes sub-step number sub_test_fail of every sub-stepped pass report a failure, and + ! sub_test_repeat solves the first sub-stepped pass twice (the second from the restored + ! committed state), which must not change the result; sub_test_more makes the re-measure of + ! every sub-stepped interval ask for one more sub-step. + INTEGER :: sub_test_fail = 0 + LOGICAL :: sub_test_repeat = .FALSE., sub_test_more = .FALSE. END TYPE CD_ModelType CONTAINS @@ -438,6 +505,17 @@ SUBROUTINE CD_Init_Model(model, q0, v0, elem_conn, l0, ea, rho_a, tension_only, CALL fail(ErrStat, ErrMsg, 'l0, ea, and rho_a must be finite and positive') RETURN END IF + ! the rotation- and snap-resolved sub-stepping settings (CD_Step_Model reads them per step) + IF (cfg%ei0_substeps /= CD_EI0_SUBSTEPS_AUTO .AND. cfg%ei0_substeps /= CD_EI0_SUBSTEPS_OFF) THEN + CALL fail(ErrStat, ErrMsg, 'cfg%ei0_substeps must be CD_EI0_SUBSTEPS_AUTO or CD_EI0_SUBSTEPS_OFF') + RETURN + END IF + IF (.NOT. (CD_Is_Finite(cfg%ei0_substep_angle) .AND. cfg%ei0_substep_angle > CD_ZERO .AND. & + cfg%ei0_substep_angle <= 90.0_wp .AND. cfg%ei0_substep_max >= 2 .AND. & + cfg%ei0_substep_max <= 1024)) THEN + CALL fail(ErrStat, ErrMsg, 'ei0_substep_angle must lie in (0, 90] deg and ei0_substep_max in [2, 1024]') + RETURN + END IF IF (ANY(elem_conn < 1) .OR. ANY(elem_conn > n_dof/3)) THEN CALL fail(ErrStat, ErrMsg, 'elem_conn contains a node index outside q0') RETURN @@ -1262,6 +1340,8 @@ SUBROUTINE CD_Init_Model(model, q0, v0, elem_conn, l0, ea, rho_a, tension_only, RETURN END IF model%initialized = .TRUE. + ! the line's initial tension, the floor of the tension scale of the sub-stepping (sub_count) + model%sub_t_init = initial_tension(model) CONTAINS @@ -1843,12 +1923,442 @@ SUBROUTINE CD_Init_Line_Model(model, anchor, fairlead, line_types, sections, gra END SUBROUTINE CD_Init_Line_Model SUBROUTINE CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & - prescribed_q, prescribed_v, prescribed_a) - !! Advance the persistent model by one generalized-alpha step. Optional - !! prescribed_q/v/a arrays are full model-sized vectors; only entries in - !! model%fixed_dofs are consumed by CableDyn_Dynamic. On successful or stalled - !! dynamics returns, the model owns the returned state. On solver failure, the - !! underlying step contract preserves the previous state. + prescribed_q, prescribed_v, prescribed_a, as_given) + !! Advance the persistent model over dt. Optional prescribed_q/v/a arrays are full + !! model-sized vectors at the end of the step; only entries in model%fixed_dofs are + !! consumed by CableDyn_Dynamic. On successful or stalled dynamics returns, the model owns + !! the returned state. On solver failure, the underlying step contract preserves the + !! previous state. + !! + !! Rotation- and snap-resolved sub-stepping (cfg%ei0_substeps = CD_EI0_SUBSTEPS_AUTO, the + !! default; the settings are checked by CD_Init_Model): the step is solved as given; when it + !! converges and a segment that ends it taut turned by more than cfg%ei0_substep_angle + !! degrees, or a segment slack at its start ends it above SUB_SNAP_FRACTION of the tension + !! scale while the step does not resolve its axial wave (see SUB_SNAP_FRACTION), the + !! interval is solved again from the same committed state in + !! n = max(SUB_SNAP_STEPS, ceil(turn/angle)) equal sub-steps, at most cfg%ei0_substep_max. + !! The trial step under-turns a line whose rotation it does not resolve, so the sub-stepped + !! interval is measured again and, when its turn needs more sub-steps, solved once more with + !! them. The prescribed end motion inside the interval follows the C2 quintic of + !! CD_Step_Model_Recovering and the last sub-step lands on the given end state exactly. The + !! decision depends only on the committed state, the step's inputs and the line's initial + !! tension (a parameter of the line), so a run restarted from a checkpoint repeats it. If a + !! sub-step fails, the plain step's own result is returned. A step of the monolithic junction + !! coupling (the end query armed, CD_Set_Model_EndQuery) is never sub-stepped: its caller + !! needs the end reaction and tangent of the nominal step. as_given = .TRUE. takes the step + !! as given as well: the stall recoveries of CD_Step_Model_Recovering and CD_Step_System, + !! whose sub-steps are themselves part of a recovery, pass it. + TYPE(CD_ModelType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: dt + LOGICAL, INTENT(OUT) :: converged, stalled + INTEGER, INTENT(OUT) :: n_iter, ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: prescribed_q(:), prescribed_v(:), prescribed_a(:) + LOGICAL, INTENT(IN), OPTIONAL :: as_given + INTEGER :: nsub, nsub2, iter_trial + LOGICAL :: has_pres, resolve, capped, capped2, ok + + has_pres = PRESENT(prescribed_q) .AND. PRESENT(prescribed_v) .AND. PRESENT(prescribed_a) + resolve = model%initialized .AND. model%cfg%ei0_substeps == CD_EI0_SUBSTEPS_AUTO .AND. & + .NOT. model%dynamic_workspace%end_request + IF (resolve .AND. PRESENT(as_given)) resolve = .NOT. as_given + ! partial prescribed motion: the plain step reports the input error + IF (resolve) resolve = has_pres .OR. .NOT. (PRESENT(prescribed_q) .OR. PRESENT(prescribed_v) .OR. & + PRESENT(prescribed_a)) + IF (resolve) THEN + resolve = sub_alloc(model, has_pres) + IF (resolve) THEN + CALL sub_store(model, 1) + ! the segment tensions at the step start, for the trigger (sub_count) + CALL sub_tensions_scratch(model, 0) + END IF + END IF + IF (.NOT. resolve) THEN + ! absent optional arguments stay absent + CALL step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & + prescribed_q=prescribed_q, prescribed_v=prescribed_v, prescribed_a=prescribed_a) + IF (ErrStat == CD_MODEL_OK) model%audit_hmax = MAX(model%audit_hmax, dt) + RETURN + END IF + + CALL step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & + prescribed_q=prescribed_q, prescribed_v=prescribed_v, prescribed_a=prescribed_a) + IF (ErrStat /= CD_MODEL_OK) RETURN + model%sub_stats%calls = model%sub_stats%calls + 1 + nsub = 1 + capped = .FALSE. + IF (converged) CALL sub_count(model, dt, nsub, capped) + IF (nsub <= 1) THEN + model%audit_hmax = MAX(model%audit_hmax, dt) + RETURN + END IF + ! keep the plain step's result: it is returned should a sub-step fail + CALL sub_store(model, 2) + iter_trial = n_iter + + ! Solve the interval again from the committed state in nsub sub-steps. The trial step + ! under-turns a line whose rotation it does not resolve, so the sub-stepped interval is + ! measured again: when its turn needs more sub-steps, it is solved once more with them (and + ! the first count is kept should that fail). + CALL run_substeps(nsub, ok) + IF (ok .AND. model%sub_test_repeat) CALL run_substeps(nsub, ok) + IF (ok) THEN + CALL sub_count(model, dt, nsub2, capped2) + IF (model%sub_test_more) nsub2 = MAX(nsub2, MIN(model%cfg%ei0_substep_max, nsub + 1)) + IF (nsub2 > nsub) THEN + model%sub_stats%remeasured = model%sub_stats%remeasured + 1 + CALL run_substeps(nsub2, ok) + IF (ok) THEN + nsub = nsub2 + capped = capped2 + ELSE + CALL run_substeps(nsub, ok) + END IF + END IF + END IF + IF (ok) THEN + converged = .TRUE. + stalled = .FALSE. + ErrStat = CD_MODEL_OK + ErrMsg = '' + model%sub_stats%events = model%sub_stats%events + 1 + IF (capped) model%sub_stats%capped = model%sub_stats%capped + 1 + model%sub_stats%max_used = MAX(model%sub_stats%max_used, nsub) + model%audit_hmax = MAX(model%audit_hmax, dt/REAL(nsub, wp)) + RETURN + END IF + ! a sub-step failed: return the plain step's own (converged) result + CALL sub_load(model, 2) + converged = .TRUE. + stalled = .FALSE. + n_iter = iter_trial + ErrStat = CD_MODEL_OK + ErrMsg = '' + model%sub_stats%fallbacks = model%sub_stats%fallbacks + 1 + model%audit_hmax = MAX(model%audit_hmax, dt) + + CONTAINS + + SUBROUTINE run_substeps(n, ok_run) + !! The interval from the committed state (slot 1) in n equal sub-steps, the prescribed + !! end motion on the C2 quintic of the interval, the last sub-step on the given end state. + INTEGER, INTENT(IN) :: n + LOGICAL, INTENT(OUT) :: ok_run + INTEGER :: k, it_k, es_k + LOGICAL :: conv_k, stall_k + REAL(wp) :: h + CHARACTER(300) :: em_k + CALL sub_load(model, 1) + h = dt/REAL(n, wp) + ok_run = .TRUE. + DO k = 1, n + IF (has_pres) THEN + IF (k == n) THEN + model%sub_pq = prescribed_q + model%sub_pv = prescribed_v + model%sub_pa = prescribed_a + ELSE + CALL quintic_model_boundary_state(model%sub_slot(1)%q, model%sub_slot(1)%v, model%sub_slot(1)%a, & + prescribed_q, prescribed_v, prescribed_a, dt, & + REAL(k, wp)/REAL(n, wp), model%sub_pq, model%sub_pv, model%sub_pa) + END IF + CALL step_model_plain(model, h, conv_k, stall_k, it_k, es_k, em_k, prescribed_q=model%sub_pq, & + prescribed_v=model%sub_pv, prescribed_a=model%sub_pa) + ELSE + CALL step_model_plain(model, h, conv_k, stall_k, it_k, es_k, em_k) + END IF + IF (k == model%sub_test_fail) conv_k = .FALSE. + IF (es_k /= CD_MODEL_OK .OR. .NOT. conv_k) THEN + ok_run = .FALSE. + RETURN + END IF + n_iter = MAX(n_iter, it_k) + END DO + END SUBROUTINE run_substeps + END SUBROUTINE CD_Step_Model + + LOGICAL FUNCTION sub_alloc(model, has_pres) RESULT(ok) + !! Allocate the sub-stepping scratch on first use: two slots of the state a step commits + !! (CD_ModelCommitSlot), the step-start and end segment tensions and the sub-step boundary + !! motion. .FALSE. when it cannot be allocated (the step is then taken as given). + TYPE(CD_ModelType), INTENT(INOUT) :: model + LOGICAL, INTENT(IN) :: has_pres + INTEGER :: istat, k + ok = .FALSE. + istat = 0 + DO k = 1, 2 + ASSOCIATE (s => model%sub_slot(k)) + IF (.NOT. sized(s%q, model%n_dof)) THEN + IF (ALLOCATED(s%q)) DEALLOCATE (s%q, s%v, s%a) + ALLOCATE (s%q(model%n_dof), s%v(model%n_dof), s%a(model%n_dof), STAT=istat) + IF (istat /= 0) RETURN + END IF + IF (model%has_viscoelastic) THEN + IF (.NOT. sized(s%ve_dl_1, SIZE(model%ve_dl_1))) THEN + IF (ALLOCATED(s%ve_dl_1)) DEALLOCATE (s%ve_dl_1) + ALLOCATE (s%ve_dl_1(SIZE(model%ve_dl_1)), STAT=istat) + IF (istat /= 0) RETURN + END IF + END IF + IF (model%has_syrope) THEN + IF (.NOT. sized(s%syrope_slow, SIZE(model%syrope_slow))) THEN + IF (ALLOCATED(s%syrope_slow)) DEALLOCATE (s%syrope_slow, s%syrope_tmax) + ALLOCATE (s%syrope_slow(SIZE(model%syrope_slow)), s%syrope_tmax(SIZE(model%syrope_tmax)), STAT=istat) + IF (istat /= 0) RETURN + END IF + END IF + IF (model%has_seabed_friction) THEN + IF (ALLOCATED(s%fr_anchor)) THEN + IF (SIZE(s%fr_anchor, 1) /= SIZE(model%fr_anchor, 1) .OR. & + SIZE(s%fr_anchor, 2) /= SIZE(model%fr_anchor, 2)) DEALLOCATE (s%fr_anchor) + END IF + IF (.NOT. ALLOCATED(s%fr_anchor)) THEN + ALLOCATE (s%fr_anchor(SIZE(model%fr_anchor, 1), SIZE(model%fr_anchor, 2)), STAT=istat) + IF (istat /= 0) RETURN + END IF + END IF + END ASSOCIATE + END DO + IF (.NOT. sized(model%sub_t0, model%n_elem)) THEN + IF (ALLOCATED(model%sub_t0)) DEALLOCATE (model%sub_t0) + ALLOCATE (model%sub_t0(model%n_elem), STAT=istat) + IF (istat /= 0) RETURN + END IF + IF (.NOT. sized(model%sub_t1, model%n_elem)) THEN + IF (ALLOCATED(model%sub_t1)) DEALLOCATE (model%sub_t1) + ALLOCATE (model%sub_t1(model%n_elem), STAT=istat) + IF (istat /= 0) RETURN + END IF + IF (has_pres) THEN + IF (.NOT. sized(model%sub_pq, model%n_dof)) THEN + IF (ALLOCATED(model%sub_pq)) DEALLOCATE (model%sub_pq, model%sub_pv, model%sub_pa) + ALLOCATE (model%sub_pq(model%n_dof), model%sub_pv(model%n_dof), model%sub_pa(model%n_dof), STAT=istat) + IF (istat /= 0) RETURN + END IF + END IF + ok = .TRUE. + CONTAINS + LOGICAL FUNCTION sized(x, n) RESULT(yes) + REAL(wp), ALLOCATABLE, INTENT(IN) :: x(:) + INTEGER, INTENT(IN) :: n + yes = ALLOCATED(x) + IF (yes) yes = SIZE(x) == n + END FUNCTION sized + END FUNCTION sub_alloc + + SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syrope_tmax, fr_anchor) + !! The one list of the state a line step commits: the kinematics, the viscoelastic dl_1, the + !! Syrope slow strain and running maximum tension, and the friction anchors. to_model = + !! .FALSE. saves the model's state into the arrays given, .TRUE. returns the model to them. + !! Every snapshot of the committed state in this module goes through here (the sub-step + !! slots of CD_Step_Model, save_recovery_state and restore_recovery_state). A state a step + !! comes to commit (such as the segment length of a line under active tension control) is + !! added here, as an optional array its snapshots pass; the rollback of the line system + !! (CableDyn_System: save_line_states, restore_line_states, CD_System_Snapshot and the + !! frame snapshot of CD_Step_System) lists the same state and must follow. An optional array + !! is passed as an allocatable that is allocated with the state it holds, so it is absent + !! (not allocated) exactly when the model does not carry that state. + TYPE(CD_ModelType), INTENT(INOUT) :: model + LOGICAL, INTENT(IN) :: to_model + REAL(wp), INTENT(INOUT) :: q(:), v(:), a(:) + REAL(wp), INTENT(INOUT), OPTIONAL :: ve_dl_1(:), syrope_slow(:), syrope_tmax(:), fr_anchor(:, :) + IF (to_model) THEN + model%q = q + model%v = v + model%a = a + IF (model%has_viscoelastic .AND. PRESENT(ve_dl_1)) model%ve_dl_1 = ve_dl_1 + IF (model%has_syrope .AND. PRESENT(syrope_slow) .AND. PRESENT(syrope_tmax)) THEN + model%syrope_slow = syrope_slow + model%syrope_tmax = syrope_tmax + END IF + IF (model%has_seabed_friction .AND. PRESENT(fr_anchor)) model%fr_anchor = fr_anchor + ELSE + q = model%q + v = model%v + a = model%a + IF (model%has_viscoelastic .AND. PRESENT(ve_dl_1)) ve_dl_1 = model%ve_dl_1 + IF (model%has_syrope .AND. PRESENT(syrope_slow) .AND. PRESENT(syrope_tmax)) THEN + syrope_slow = model%syrope_slow + syrope_tmax = model%syrope_tmax + END IF + IF (model%has_seabed_friction .AND. PRESENT(fr_anchor)) fr_anchor = model%fr_anchor + END IF + END SUBROUTINE commit_state_copy + + SUBROUTINE sub_store(model, slot) + !! Save the state a step commits into slot 1 (the step start) or 2 (the plain step's result). + TYPE(CD_ModelType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: slot + CALL commit_state_copy(model, .FALSE., model%sub_slot(slot)%q, model%sub_slot(slot)%v, model%sub_slot(slot)%a, & + model%sub_slot(slot)%ve_dl_1, model%sub_slot(slot)%syrope_slow, & + model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor) + END SUBROUTINE sub_store + + SUBROUTINE sub_load(model, slot) + !! Return the model to the state saved in slot (sub_store). + TYPE(CD_ModelType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: slot + CALL commit_state_copy(model, .TRUE., model%sub_slot(slot)%q, model%sub_slot(slot)%v, model%sub_slot(slot)%a, & + model%sub_slot(slot)%ve_dl_1, model%sub_slot(slot)%syrope_slow, & + model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor) + END SUBROUTINE sub_load + + SUBROUTINE sub_tensions(model, tension) + !! The segment tensions at the model's committed state as the run audit takes them + !! (CD_Audit_Model_Step): the dynamic EA times the strain of an elastic segment, the law's + !! tension of a viscoelastic or Syrope segment (model_law_tensions; the static EA times the + !! strain where the law cannot be evaluated). + TYPE(CD_ModelType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: tension(:) + INTEGER :: e, na, nb, es + REAL(wp) :: strain + CHARACTER(160) :: em + DO e = 1, model%n_elem + na = model%elem_conn(1, e) + nb = model%elem_conn(2, e) + strain = NORM2(model%q(3*nb - 2:3*nb) - model%q(3*na - 2:3*na))/model%l0(e) - CD_ONE + IF (model%ea_dyn(e) > CD_ZERO) THEN + tension(e) = model%ea_dyn(e)*strain + ELSE + tension(e) = model%ea(e)*strain + END IF + END DO + IF (model%has_viscoelastic .OR. model%has_syrope) CALL model_law_tensions(model, tension, es, em) + END SUBROUTINE sub_tensions + + SUBROUTINE sub_tensions_scratch(model, which) + !! sub_tensions into the scratch of the sub-stepping, sub_t0 (which = 0, the step start) or + !! sub_t1 (1, the step end). The array is moved out of the model while the tensions are + !! evaluated (the law evaluation reads the model), which allocates nothing. + TYPE(CD_ModelType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: which + REAL(wp), ALLOCATABLE :: tension(:) + IF (which == 0) THEN + CALL MOVE_ALLOC(model%sub_t0, tension) + CALL sub_tensions(model, tension) + CALL MOVE_ALLOC(tension, model%sub_t0) + ELSE + CALL MOVE_ALLOC(model%sub_t1, tension) + CALL sub_tensions(model, tension) + CALL MOVE_ALLOC(tension, model%sub_t1) + END IF + END SUBROUTINE sub_tensions_scratch + + REAL(wp) FUNCTION initial_tension(model) RESULT(t_init) + !! The largest segment tension of the model's committed state (sub_tensions), 0 when none + !! is positive: the line's initial tension when CD_Init_Model sets it. + TYPE(CD_ModelType), INTENT(IN) :: model + REAL(wp), ALLOCATABLE :: tension(:) + INTEGER :: istat + t_init = CD_ZERO + ALLOCATE (tension(model%n_elem), STAT=istat) + IF (istat /= 0) RETURN + CALL sub_tensions(model, tension) + IF (CD_All_Finite(tension)) t_init = MAX(CD_ZERO, MAXVAL(tension)) + END FUNCTION initial_tension + + REAL(wp) FUNCTION segment_wave_stiffness(model, e, tension) RESULT(stiff) + !! The axial stiffness of segment e that sets its wave speed: the dynamic EA of an elastic + !! segment, the fast spring of a law (EA_D of the viscoelastic law, alpha + beta*T of the + !! Syrope law at the segment tension T); the static EA if the law's value is unavailable. + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + REAL(wp), INTENT(IN) :: tension + REAL(wp) :: ea_d_eff, ea_1_eff + INTEGER :: es + CHARACTER(200) :: em + stiff = model%ea_dyn(e) + IF (stiff > CD_ZERO) RETURN + stiff = model%ea(e) + IF (model%has_viscoelastic) THEN + IF (model%ve_mode(e) /= 0) THEN + CALL model_viscoelastic_coeffs(model, e, ea_d_eff, ea_1_eff, es, em) + IF (es == CD_MODEL_OK .AND. ea_d_eff > CD_ZERO) stiff = ea_d_eff + RETURN + END IF + END IF + IF (model%has_syrope) THEN + IF (model%syrope_is(e)) & + stiff = model%syrope_type(e)%alpha + model%syrope_type(e)%beta*MAX(tension, CD_ZERO) + END IF + END FUNCTION segment_wave_stiffness + + SUBROUTINE sub_count(model, dt, nsub, capped) + !! The sub-step count of a converged step over dt (model%q) from the committed state (slot 1, + !! its segment tensions in sub_t0): 1, or max(SUB_SNAP_STEPS, ceil(turn/angle)) when + !! turn > angle, at most cfg%ei0_substep_max (capped when the turn needs more), turn the + !! largest chord turn of a segment that ends the step above SUB_TAUT_FRACTION of the tension + !! scale (the largest step-start tension, at least SUB_TAUT_FRACTION of sub_t_init); at least + !! SUB_SNAP_STEPS when a segment slack at the start ends above SUB_SNAP_FRACTION of the scale + !! and its axial wave crosses it more than once in dt. The tensions are those of + !! sub_tensions. The strains use model%l0, the lengths the step itself uses + !! (CD_Update_Model_SegmentLength sets them before the step); a length that changes within + !! the step would need its step-start value for the start state here. + TYPE(CD_ModelType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: dt + INTEGER, INTENT(OUT) :: nsub + LOGICAL, INTENT(OUT) :: capped + REAL(wp), PARAMETER :: DEG = 57.295779513082320876798154814105_wp + INTEGER :: e, na, nb, nmax + REAL(wp) :: d0(3), d1(3), l_s, l_e, scale, te, c, turn, ratio, courant + LOGICAL :: snap + nsub = 1 + capped = .FALSE. + CALL sub_tensions_scratch(model, 1) + scale = MAX(CD_ZERO, SUB_TAUT_FRACTION*model%sub_t_init) + IF (CD_All_Finite(model%sub_t0)) scale = MAX(scale, MAXVAL(model%sub_t0)) + turn = CD_ZERO + snap = .FALSE. + DO e = 1, model%n_elem + na = model%elem_conn(1, e) + nb = model%elem_conn(2, e) + d1 = model%q(3*nb - 2:3*nb) - model%q(3*na - 2:3*na) + l_e = NORM2(d1) + IF (.NOT. l_e > model%l0(e)) CYCLE + te = model%sub_t1(e) + d0 = model%sub_slot(1)%q(3*nb - 2:3*nb) - model%sub_slot(1)%q(3*na - 2:3*na) + l_s = NORM2(d0) + IF (.NOT. snap .AND. l_s <= model%l0(e) .AND. te > SUB_SNAP_FRACTION*scale) THEN + courant = dt*SQRT(segment_wave_stiffness(model, e, te)/model%rho_a(e))/model%l0(e) + IF (courant > CD_ONE) snap = .TRUE. + END IF + IF (te > SUB_TAUT_FRACTION*scale .AND. l_s > CD_ZERO) THEN + c = DOT_PRODUCT(d0, d1)/(l_s*l_e) + turn = MAX(turn, ACOS(MAX(-CD_ONE, MIN(CD_ONE, c)))*DEG) + END IF + END DO + nmax = model%cfg%ei0_substep_max + IF (turn > model%cfg%ei0_substep_angle) THEN + ratio = turn/model%cfg%ei0_substep_angle + IF (ratio > REAL(nmax, wp)) THEN + nsub = nmax + capped = .TRUE. + ELSE + nsub = MIN(nmax, MAX(SUB_SNAP_STEPS, CEILING(ratio))) + END IF + END IF + IF (snap) nsub = MAX(nsub, MIN(SUB_SNAP_STEPS, nmax)) + END SUBROUTINE sub_count + + SUBROUTINE CD_Get_Model_Substep_Counts(model, calls, events, max_used, capped, fallbacks) + !! Diagnostics of the rotation- and snap-resolved sub-stepping (CD_Step_Model, + !! CD_SubstepStats): the steps it examined, those it solved in sub-steps (the largest count + !! used), those whose turn needed more than cfg%ei0_substep_max, and those that kept the + !! plain step after a sub-step failed. + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER(int64), INTENT(OUT) :: calls, events, capped, fallbacks + INTEGER, INTENT(OUT) :: max_used + calls = model%sub_stats%calls + events = model%sub_stats%events + max_used = model%sub_stats%max_used + capped = model%sub_stats%capped + fallbacks = model%sub_stats%fallbacks + END SUBROUTINE CD_Get_Model_Substep_Counts + + SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & + prescribed_q, prescribed_v, prescribed_a) + !! One generalized-alpha step of the model over dt, as given (CD_Step_Model without its + !! resolved sub-stepping). TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: dt LOGICAL, INTENT(OUT) :: converged, stalled @@ -2192,7 +2702,7 @@ SUBROUTINE model_added_mass_band(q, accel, free, kl, ku, M_add_a, M_add_band, dM ErrStat, ErrMsg, need_tangent=need_tangent) ErrStat = as_dyn_callback_status(ErrStat) END SUBROUTINE model_added_mass_band - END SUBROUTINE CD_Step_Model + END SUBROUTINE step_model_plain SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & prescribed_q, prescribed_v, prescribed_a, max_substeps, substeps_used) @@ -2217,7 +2727,8 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt INTEGER :: recovery_cap, nsub, k, es, iter_sub, max_iter_seen LOGICAL :: has_pres, conv_sub, stall_sub, rung_ok - REAL(wp) :: subdt, fraction + REAL(wp) :: subdt, fraction, hmax0 + TYPE(CD_SubstepStats) :: stats0 REAL(wp), ALLOCATABLE :: pq(:), pv(:), pa(:) CHARACTER(300) :: em, first_em @@ -2262,6 +2773,8 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt END IF CALL save_recovery_state(model) + hmax0 = model%audit_hmax + stats0 = model%sub_stats IF (has_pres) THEN CALL CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & prescribed_q=prescribed_q, prescribed_v=prescribed_v, prescribed_a=prescribed_a) @@ -2280,6 +2793,8 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt first_em = ErrMsg CALL restore_recovery_state(model) + ! the stalled attempt is not committed: the rungs that replace it take their steps as given + model%sub_stats = stats0 IF (has_pres) THEN ALLOCATE (pq(model%n_dof), pv(model%n_dof), pa(model%n_dof), STAT=es) IF (es /= 0) THEN @@ -2294,6 +2809,11 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt nsub = 4 DO CALL restore_recovery_state(model) + ! the audit measures the solver steps of the rung that completes + model%audit_hmax = hmax0 + ! the rungs take their sub-steps as given (step_model_plain, as CD_Step_System's halving + ! does with as_given): resolving them as well (sub-steps of sub-steps) left the anchor snap + ! peaks of the Lozon semitaut line 9 % high on average subdt = dt/REAL(nsub, wp) rung_ok = .TRUE. es = CD_MODEL_OK @@ -2308,10 +2828,10 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt pv = prescribed_v pa = prescribed_a END IF - CALL CD_Step_Model(model, subdt, conv_sub, stall_sub, iter_sub, es, em, & - prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + CALL step_model_plain(model, subdt, conv_sub, stall_sub, iter_sub, es, em, & + prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) ELSE - CALL CD_Step_Model(model, subdt, conv_sub, stall_sub, iter_sub, es, em) + CALL step_model_plain(model, subdt, conv_sub, stall_sub, iter_sub, es, em) END IF max_iter_seen = MAX(max_iter_seen, iter_sub) IF (es /= CD_MODEL_OK .OR. .NOT. conv_sub) THEN @@ -2323,6 +2843,7 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt converged = .TRUE. stalled = .FALSE. n_iter = max_iter_seen + model%audit_hmax = MAX(hmax0, subdt) IF (PRESENT(substeps_used)) substeps_used = nsub ErrStat = CD_MODEL_OK ErrMsg = '' @@ -2359,29 +2880,19 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt END SUBROUTINE CD_Step_Model_Recovering SUBROUTINE save_recovery_state(model) + !! Save the committed state into the recovery snapshot (commit_state_copy). TYPE(CD_ModelType), INTENT(INOUT) :: model - model%recovery_q0 = model%q - model%recovery_v0 = model%v - model%recovery_a0 = model%a - IF (model%has_viscoelastic) model%recovery_ve_dl_1 = model%ve_dl_1 - IF (model%has_syrope) THEN - model%recovery_syrope_slow = model%syrope_slow - model%recovery_syrope_tmax = model%syrope_tmax - END IF - IF (model%has_seabed_friction) model%recovery_fr_anchor = model%fr_anchor + CALL commit_state_copy(model, .FALSE., model%recovery_q0, model%recovery_v0, model%recovery_a0, & + model%recovery_ve_dl_1, model%recovery_syrope_slow, model%recovery_syrope_tmax, & + model%recovery_fr_anchor) END SUBROUTINE save_recovery_state SUBROUTINE restore_recovery_state(model) + !! Return the model to the recovery snapshot (commit_state_copy). TYPE(CD_ModelType), INTENT(INOUT) :: model - model%q = model%recovery_q0 - model%v = model%recovery_v0 - model%a = model%recovery_a0 - IF (model%has_viscoelastic) model%ve_dl_1 = model%recovery_ve_dl_1 - IF (model%has_syrope) THEN - model%syrope_slow = model%recovery_syrope_slow - model%syrope_tmax = model%recovery_syrope_tmax - END IF - IF (model%has_seabed_friction) model%fr_anchor = model%recovery_fr_anchor + CALL commit_state_copy(model, .TRUE., model%recovery_q0, model%recovery_v0, model%recovery_a0, & + model%recovery_ve_dl_1, model%recovery_syrope_slow, model%recovery_syrope_tmax, & + model%recovery_fr_anchor) model%ve_dt = CD_ZERO END SUBROUTINE restore_recovery_state @@ -4815,13 +5326,18 @@ SUBROUTINE CD_Audit_Model_Step(model, time, dt, new_spike) REAL(wp), PARAMETER :: TURN_TAUT_FRACTION = 1.0e-3_wp INTEGER, PARAMETER :: SPIKE_MIN_ELEMS = 3 INTEGER :: e, na, nb, istat, es - REAL(wp) :: d(3), ell, strain, u(3), c, line_max, tn + REAL(wp) :: d(3), ell, strain, u(3), c, line_max, tn, h REAL(wp), ALLOCATABLE :: law(:) LOGICAL :: fresh, laws CHARACTER(160) :: em new_spike = .FALSE. IF (.NOT. model%initialized .OR. model%n_elem < 1) RETURN + ! the largest solver step since the last audit (sub-steps of the resolved or recovering + ! step): turns and axial wave crossings are measured per solver step + h = dt + IF (model%audit_hmax > CD_ZERO) h = MIN(dt, model%audit_hmax) + model%audit_hmax = CD_ZERO fresh = .NOT. (ALLOCATED(model%audit_t) .AND. ALLOCATED(model%audit_u) .AND. ALLOCATED(model%audit_now)) IF (.NOT. fresh) fresh = SIZE(model%audit_t, 1) /= model%n_elem IF (fresh) THEN @@ -4881,13 +5397,13 @@ SUBROUTINE CD_Audit_Model_Step(model, time, dt, new_spike) model%audit_t(e, 1) > TURN_TAUT_FRACTION*model%audit_floor .AND. model%audit_t(e, 1) > CD_ZERO) & model%audit_max_turn = MAX(model%audit_max_turn, & ACOS(MAX(-CD_ONE, MIN(CD_ONE, DOT_PRODUCT(u, model%audit_u(:, e)))))* & - (180.0_wp/ACOS(-CD_ONE))) + (180.0_wp/ACOS(-CD_ONE))*(h/dt)) ! slack at the previous state, taut above the initial tension scale now IF (model%audit_t(e, 1) >= CD_ZERO .AND. .NOT. model%audit_t(e, 1) > CD_ZERO .AND. & model%audit_now(e) > model%audit_floor) THEN model%audit_snaps = model%audit_snaps + 1 - c = SQRT(wave_stiffness(e)/model%rho_a(e)) - model%audit_snap_courant = MAX(model%audit_snap_courant, dt*c/model%l0(e)) + c = SQRT(segment_wave_stiffness(model, e, model%audit_now(e))/model%rho_a(e)) + model%audit_snap_courant = MAX(model%audit_snap_courant, h*c/model%l0(e)) END IF END IF model%audit_u(:, e) = u @@ -4926,29 +5442,6 @@ LOGICAL FUNCTION law_element(k) RESULT(is_law) IF (model%has_syrope .AND. .NOT. is_law) is_law = model%syrope_is(k) END FUNCTION law_element - REAL(wp) FUNCTION wave_stiffness(k) RESULT(stiff) - !! The axial stiffness of segment k that sets its wave speed: EA of an elastic segment, - !! the fast spring of a law (EA_D of the viscoelastic law, alpha + beta*T of the Syrope - !! law at the segment tension T); the static EA if the law's value is unavailable. - INTEGER, INTENT(IN) :: k - REAL(wp) :: ea_d_eff, ea_1_eff - INTEGER :: es_k - CHARACTER(200) :: em_k - stiff = model%ea_dyn(k) - IF (stiff > CD_ZERO) RETURN - stiff = model%ea(k) - IF (model%has_viscoelastic) THEN - IF (model%ve_mode(k) /= 0) THEN - CALL model_viscoelastic_coeffs(model, k, ea_d_eff, ea_1_eff, es_k, em_k) - IF (es_k == CD_MODEL_OK .AND. ea_d_eff > CD_ZERO) stiff = ea_d_eff - RETURN - END IF - END IF - IF (model%has_syrope) THEN - IF (model%syrope_is(k)) stiff = model%syrope_type(k)%alpha + & - model%syrope_type(k)%beta*MAX(model%audit_now(k), CD_ZERO) - END IF - END FUNCTION wave_stiffness END SUBROUTINE CD_Audit_Model_Step SUBROUTINE clear_model_audit(model) @@ -4968,6 +5461,14 @@ SUBROUTINE clear_model_audit(model) model%audit_spike_time = CD_ZERO model%audit_spike_tension = CD_ZERO model%audit_spike_ratio = CD_ZERO + model%audit_hmax = CD_ZERO + model%audit_hmax_rollback = CD_ZERO + ! the sub-stepping diagnostics and test hooks start afresh with the model + model%sub_stats = CD_SubstepStats() + model%sub_stats_rollback = CD_SubstepStats() + model%sub_test_fail = 0 + model%sub_test_repeat = .FALSE. + model%sub_test_more = .FALSE. END SUBROUTINE clear_model_audit SUBROUTINE CD_End_Model(model, ErrStat, ErrMsg) @@ -5005,6 +5506,13 @@ SUBROUTINE CD_End_Model(model, ErrStat, ErrMsg) IF (ALLOCATED(model%v_rollback)) DEALLOCATE (model%v_rollback) IF (ALLOCATED(model%a_rollback)) DEALLOCATE (model%a_rollback) IF (ALLOCATED(model%recovery_q0)) DEALLOCATE (model%recovery_q0) + model%sub_slot(1) = CD_ModelCommitSlot() + model%sub_slot(2) = CD_ModelCommitSlot() + IF (ALLOCATED(model%sub_t0)) DEALLOCATE (model%sub_t0) + IF (ALLOCATED(model%sub_t1)) DEALLOCATE (model%sub_t1) + IF (ALLOCATED(model%sub_pq)) DEALLOCATE (model%sub_pq) + IF (ALLOCATED(model%sub_pv)) DEALLOCATE (model%sub_pv) + IF (ALLOCATED(model%sub_pa)) DEALLOCATE (model%sub_pa) IF (ALLOCATED(model%recovery_v0)) DEALLOCATE (model%recovery_v0) IF (ALLOCATED(model%recovery_a0)) DEALLOCATE (model%recovery_a0) IF (ALLOCATED(model%f_ext_rollback)) DEALLOCATE (model%f_ext_rollback) @@ -5159,6 +5667,7 @@ SUBROUTINE CD_Copy_Model(src, dst, ErrStat, ErrMsg) work%added_mass_can = src%added_mass_can work%added_mass_cat = src%added_mass_cat work%cfg = src%cfg + work%sub_t_init = src%sub_t_init CALL copy_int2(src%elem_conn, work%elem_conn, 'elem_conn', ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN @@ -5372,6 +5881,7 @@ SUBROUTINE commit_model_copy(from, to) to%added_mass_can = from%added_mass_can to%added_mass_cat = from%added_mass_cat to%cfg = from%cfg + to%sub_t_init = from%sub_t_init CALL MOVE_ALLOC(from%elem_conn, to%elem_conn) CALL MOVE_ALLOC(from%fixed_dofs, to%fixed_dofs) diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index 73f98480..2abb1d4f 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -40,6 +40,7 @@ MODULE CableDyn_OpenFAST_Aggregate !! generalised-alpha step carries the Init dt, from the mooring columns). USE CableDyn_Precision, ONLY: wp, CD_ZERO, CD_ONE, CD_All_Finite USE CableDyn_FatalReport, ONLY: CD_Fatal_Thread_Init + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 USE CableDyn_Linalg, ONLY: CD_Blas_Runtime_Check, CD_LINALG_OK USE CableDyn_OpenFAST_FMF, ONLY: CD_FMF_ModuleType, CD_FMF_Init_From_System, CD_FMF_NMovingPoints, & CD_FMF_GetPointMesh, CD_FMF_UpdateStates, & @@ -75,7 +76,8 @@ MODULE CableDyn_OpenFAST_Aggregate CD_Rod_ScatterHostPoints, CD_Rod_HostWrench, CD_Rod_Stage, CD_Rod_Unstage, & CD_Deck_Range_Sample_Aggregate, CD_Deck_Range_Write USE CableDyn_RangeOutput, ONLY: CD_RangeSet, CD_Range_End - USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_Get_System_Line_State, & + USE CableDyn_System, ONLY: CD_Get_System_Substep_Counts, CD_System_NLines, CD_System_Line_NDOF, & + CD_Get_System_Line_State, & CD_Update_System_Line_SegmentLength, & CD_Update_System_Line_Hydro_Fields, CD_SYSTEM_OK, & CD_System_NHydroPoints, CD_Get_System_HydroPoint_Positions, & @@ -105,6 +107,7 @@ MODULE CableDyn_OpenFAST_Aggregate PUBLIC :: CD_AGG_CalcOutput PUBLIC :: CD_AGG_End PUBLIC :: CD_AGG_NFailures + PUBLIC :: CD_AGG_Get_Substep_Counts PUBLIC :: CD_AGG_Get_Failure_Flags, CD_AGG_Set_Failure_Flags PUBLIC :: CD_AGG_NCtrlChans, CD_AGG_Apply_LineControl PUBLIC :: CD_AGG_IsInitialized @@ -1767,6 +1770,19 @@ INTEGER FUNCTION CD_AGG_NFailures(self) RESULT(n) IF (ALLOCATED(self%failures)) n = SIZE(self%failures) END FUNCTION CD_AGG_NFailures + SUBROUTINE CD_AGG_Get_Substep_Counts(self, calls, events, max_used, capped, fallbacks) + !! The rotation- and snap-resolved sub-stepping diagnostics of the EI=0 lines of the + !! aggregate (CD_Get_System_Substep_Counts; all zero without EI=0 lines): line steps + !! examined, solved in sub-steps (max_used the largest count), beyond ei0_substep_max, and + !! kept the plain step's result after a sub-step failed. + TYPE(CD_AGG_ModuleType), INTENT(IN) :: self + INTEGER(int64), INTENT(OUT) :: calls, events, capped, fallbacks + INTEGER, INTENT(OUT) :: max_used + calls = 0; events = 0; max_used = 1; capped = 0; fallbacks = 0 + IF (self%has_sys) CALL CD_Get_System_Substep_Counts(self%sys%fast%system, calls, events, max_used, capped, & + fallbacks) + END SUBROUTINE CD_AGG_Get_Substep_Counts + SUBROUTINE CD_AGG_End(self, ErrStat, ErrMsg) !! Release all owned resources. Idempotent by design (CD_FMF_End / CD_HFMF_End are safe !! on uninitialized members). diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index 64ef1782..34dcc24a 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -10,6 +10,7 @@ MODULE CableDyn_System !! bypassing it. Rigid6 bodies and rods are marched over a system by the deck driver. USE CableDyn_Precision, ONLY: wp, CD_ZERO, CD_All_Finite, CD_Is_Finite USE CableDyn_FatalReport, ONLY: CD_Fatal_Thread_Init + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 USE CableDyn_Model, ONLY: CD_ModelType, CD_Model_Is_Initialized, CD_End_Model, & CD_Model_NCoupledDOF, CD_Model_NDOF, CD_Model_NElem, & CD_Get_Model_CoupledDofs, CD_Get_Model_CoupledMotion, & @@ -21,6 +22,7 @@ MODULE CableDyn_System CD_Get_Model_EndNodeTangent, CD_Set_Model_EndQuery, CD_Get_Model_EndQuery, & CD_Update_Model_SegmentLength, & CD_Update_Model_CoupledMotion, CD_Update_Model_Interior_State, CD_Step_Model, & + CD_Get_Model_Substep_Counts, CD_SubstepStats, & CD_Calc_Model_CoupledLoads, CD_Recompute_Model_Acceleration, & CD_Calc_Model_CoupledKinematicDerivatives, & CD_Calc_Model_CoupledAccelDerivative, CD_Update_Model_CoupledAccelDerivative, & @@ -47,6 +49,7 @@ MODULE CableDyn_System PUBLIC :: CD_SystemPointType PUBLIC :: CD_LineEndpointBinding PUBLIC :: CD_System_Fallback_Count + PUBLIC :: CD_Get_System_Substep_Counts PUBLIC :: CD_System_Fallback_Reset PUBLIC :: CD_System_Snapshot PUBLIC :: CD_System_Restore @@ -218,6 +221,9 @@ MODULE CableDyn_System ! Stick-slip seabed friction anchors join the snapshot ((x, y) per node, concatenated ! over the friction lines; sized like snap_q, of which it uses two thirds at most). REAL(wp), ALLOCATABLE :: snap_fr_anchor(:) + ! the sub-stepping diagnostics of every line (CD_SubstepStats): they roll back with the + ! states, so a restored and re-advanced step counts once + TYPE(CD_SubstepStats), ALLOCATABLE :: snap_sub(:) LOGICAL :: snap_valid = .FALSE. END TYPE CD_SystemType @@ -453,6 +459,7 @@ SUBROUTINE CD_End_System(system, ErrStat, ErrMsg) IF (ALLOCATED(system%snap_ve_dl_1)) DEALLOCATE (system%snap_ve_dl_1) IF (ALLOCATED(system%snap_syrope_slow)) DEALLOCATE (system%snap_syrope_slow, system%snap_syrope_tmax) IF (ALLOCATED(system%snap_fr_anchor)) DEALLOCATE (system%snap_fr_anchor) + IF (ALLOCATED(system%snap_sub)) DEALLOCATE (system%snap_sub) system%snap_valid = .FALSE. system%initialized = .FALSE. system%n_lines = 0 @@ -1251,7 +1258,8 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, LOGICAL :: conv2, stall2 CHARACTER(160) :: em REAL(wp), ALLOCATABLE :: q0(:), v0(:), a0(:), qm(:), vm(:), am(:), qs(:), vs(:), as(:) - REAL(wp), ALLOCATABLE :: dl1s(:), slows(:), tmaxs(:), frs(:, :) + REAL(wp), ALLOCATABLE :: dl1s(:), slows(:), tmaxs(:), frs(:, :), hmaxs(:) + TYPE(CD_SubstepStats), ALLOCATABLE :: subs(:) converged = .FALSE. stalled = .FALSE. @@ -1310,13 +1318,22 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, n_team = line_team_size(system) !$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i) NUM_THREADS(n_team) IF(n_team > 1) CALL CD_Fatal_Thread_Init() ! this thread can report its own stack overflow - !$OMP DO SCHEDULE(STATIC) + ! DYNAMIC: a line that is sub-stepped (CD_Step_Model) costs several of its plain steps, so the + ! lines take unequal times; each line's result does not depend on the thread that steps it + !$OMP DO SCHEDULE(DYNAMIC) DO i = 1, system%n_lines + ! the halves of a stall recovery (0 < depth < MAX_SUBDIV) take their steps as given, as the + ! rungs of CD_Step_Model_Recovering do: no rotation- and snap-resolved sub-steps of + ! sub-steps. The plain full-dt rerun at the depth floor (depth = MAX_SUBDIV) steps every line + ! as the nominal step (depth 0) does, so its result is that of the step without the + ! fallback; the junction step (JUNCTION_NO_SUBDIV = MAX_SUBDIV) likewise, its armed lines + ! being taken as given by CD_Step_Model itself CALL CD_Step_Model(system%lines(i), dt, system%line_converged(i), system%line_stalled(i), & system%line_iter(i), system%line_stat(i), system%line_msg(i), & prescribed_q=system%lines(i)%q_prescribed_work, & prescribed_v=system%lines(i)%v_prescribed_work, & - prescribed_a=system%lines(i)%a_prescribed_work) + prescribed_a=system%lines(i)%a_prescribed_work, & + as_given=depth > 0 .AND. depth < MAX_SUBDIV) END DO !$OMP END DO !$OMP END PARALLEL @@ -1375,7 +1392,8 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, IF (system%lines(i)%has_syrope) nsy = nsy + SIZE(system%lines(i)%syrope_slow) IF (CD_Model_Has_Friction(system%lines(i))) nfr = nfr + SIZE(system%lines(i)%fr_anchor, 2) END DO - ALLOCATE (qs(ntot), vs(ntot), as(ntot), dl1s(nve), slows(nsy), tmaxs(nsy), frs(2, nfr)) + ALLOCATE (qs(ntot), vs(ntot), as(ntot), dl1s(nve), slows(nsy), tmaxs(nsy), frs(2, nfr), & + hmaxs(system%n_lines), subs(system%n_lines)) lo = 1 lo_ve = 1 lo_sy = 1 @@ -1385,6 +1403,10 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, qs(lo:hi) = system%lines(i)%q vs(lo:hi) = system%lines(i)%v as(lo:hi) = system%lines(i)%a + ! the run audit's largest solver step and the sub-stepping diagnostics restore with the + ! states, so the halves of a fallback that does not complete leave no trace + hmaxs(i) = system%lines(i)%audit_hmax + subs(i) = system%lines(i)%sub_stats lo = hi + 1 IF (CD_Model_Has_Friction(system%lines(i))) THEN ne = SIZE(system%lines(i)%fr_anchor, 2) @@ -1427,6 +1449,8 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, system%lines(i)%q = qs(lo:hi) system%lines(i)%v = vs(lo:hi) system%lines(i)%a = as(lo:hi) + system%lines(i)%audit_hmax = hmaxs(i) + system%lines(i)%sub_stats = subs(i) lo = hi + 1 IF (CD_Model_Has_Friction(system%lines(i))) THEN ne = SIZE(system%lines(i)%fr_anchor, 2) @@ -1491,7 +1515,7 @@ SUBROUTINE CD_Step_System_Junction(system, dt, q_coupled, v_coupled, a_coupled, LOGICAL, INTENT(IN), OPTIONAL :: level_dofs(:) INTEGER :: i, j, k, lo, nc, nf LOGICAL :: valid, fresh - LOGICAL, ALLOCATABLE :: act(:), lev(:) + LOGICAL, ALLOCATABLE :: act(:), lev(:), armed(:) REAL(wp), ALLOCATABLE :: r(:), kl(:, :) loads = CD_ZERO @@ -1509,6 +1533,11 @@ SUBROUTINE CD_Step_System_Junction(system, dt, q_coupled, v_coupled, a_coupled, END IF fresh = .TRUE. IF (PRESENT(refresh)) fresh = refresh + ! A line with no active junction DOF (both ends on fixed or anchored points) adds nothing to + ! the junction loads and tangent: its end query stays unarmed, so CD_Step_Model sub-steps + ! it as on any other route (its loads at the inactive DOFs are not returned). Every other + ! line is armed and taken as given. + ALLOCATE (armed(system%n_lines)) DO i = 1, system%n_lines lo = system%line_off(i) nc = system%line_off(i + 1) - lo @@ -1520,7 +1549,10 @@ SUBROUTINE CD_Step_System_Junction(system, dt, q_coupled, v_coupled, a_coupled, act(j) = active(system%coupled_dof_map(lo + j - 1)) IF (PRESENT(level_dofs)) lev(j) = level_dofs(system%coupled_dof_map(lo + j - 1)) END DO - IF (PRESENT(levels)) THEN + armed(i) = ANY(act) + IF (.NOT. armed(i)) THEN + CALL CD_Set_Model_EndQuery(system%lines(i), .FALSE.) + ELSE IF (PRESENT(levels)) THEN CALL CD_Set_Model_EndQuery(system%lines(i), .TRUE., act, warm, fresh, levels, lev) ELSE CALL CD_Set_Model_EndQuery(system%lines(i), .TRUE., act, warm, fresh) @@ -1531,6 +1563,7 @@ SUBROUTINE CD_Step_System_Junction(system, dt, q_coupled, v_coupled, a_coupled, JUNCTION_NO_SUBDIV) IF (ErrStat == CD_SYSTEM_OK .AND. converged) THEN DO i = 1, system%n_lines + IF (.NOT. armed(i)) CYCLE lo = system%line_off(i) nc = system%line_off(i + 1) - lo nf = SIZE(system%lines(i)%fixed_dofs) @@ -2940,6 +2973,11 @@ SUBROUTINE save_line_states(system, ErrStat, ErrMsg) system%lines(i)%q_rollback = system%lines(i)%q system%lines(i)%v_rollback = system%lines(i)%v system%lines(i)%a_rollback = system%lines(i)%a + ! the run audit's largest solver step rolls back too: a rolled-back (stalled) full step + ! must not count when its halves are what the line commits + system%lines(i)%audit_hmax_rollback = system%lines(i)%audit_hmax + ! the sub-stepping diagnostics likewise: a rolled-back step is not counted + system%lines(i)%sub_stats_rollback = system%lines(i)%sub_stats ! the viscoelastic dl_1 state advances with every committed line step, so ! it must roll back with q/v/a (a line that stepped can be rolled back ! when a sibling line or the coupled point solve fails) @@ -2967,6 +3005,8 @@ SUBROUTINE restore_line_states(system) system%lines(i)%q = system%lines(i)%q_rollback system%lines(i)%v = system%lines(i)%v_rollback system%lines(i)%a = system%lines(i)%a_rollback + system%lines(i)%audit_hmax = system%lines(i)%audit_hmax_rollback + system%lines(i)%sub_stats = system%lines(i)%sub_stats_rollback IF (system%lines(i)%has_viscoelastic) & system%lines(i)%ve_dl_1 = system%lines(i)%ve_dl_1_rollback IF (system%lines(i)%has_syrope) THEN @@ -3092,6 +3132,10 @@ SUBROUTINE CD_System_Snapshot(system, ErrStat, ErrMsg) RESHAPE(system%lines(i)%fr_anchor, [2*SIZE(system%lines(i)%fr_anchor, 2)]) lo = hi + 1 END DO + IF (.NOT. ALLOCATED(system%snap_sub)) ALLOCATE (system%snap_sub(system%n_lines)) + DO i = 1, system%n_lines + system%snap_sub(i) = system%lines(i)%sub_stats + END DO IF (ALLOCATED(system%points)) system%snap_points = system%points IF (ALLOCATED(system%bindings)) system%snap_bindings = system%bindings IF (ALLOCATED(system%coupled_dof_map)) system%snap_map = system%coupled_dof_map @@ -3155,6 +3199,11 @@ SUBROUTINE CD_System_Restore(system, ErrStat, ErrMsg) [2, SIZE(system%lines(i)%fr_anchor, 2)]) lo = hi + 1 END DO + IF (ALLOCATED(system%snap_sub)) THEN + DO i = 1, system%n_lines + system%lines(i)%sub_stats = system%snap_sub(i) + END DO + END IF IF (ALLOCATED(system%snap_points)) system%points = system%snap_points ! Roll the detach topology back with the states: a failure fired after the ! snapshot un-fires (its row will re-trigger on the re-advance). @@ -3206,6 +3255,26 @@ SUBROUTINE CD_System_Restore(system, ErrStat, ErrMsg) END IF END SUBROUTINE CD_System_Restore + SUBROUTINE CD_Get_System_Substep_Counts(system, calls, events, max_used, capped, fallbacks) + !! The rotation- and snap-resolved sub-stepping diagnostics of the EI=0 lines + !! (CD_Get_Model_Substep_Counts) summed over the lines (max_used: the largest count). + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER(int64), INTENT(OUT) :: calls, events, capped, fallbacks + INTEGER, INTENT(OUT) :: max_used + INTEGER(int64) :: c, e, k, f + INTEGER :: i, m + calls = 0; events = 0; max_used = 1; capped = 0; fallbacks = 0 + IF (.NOT. ALLOCATED(system%lines)) RETURN + DO i = 1, SIZE(system%lines) + CALL CD_Get_Model_Substep_Counts(system%lines(i), c, e, m, k, f) + calls = calls + c + events = events + e + max_used = MAX(max_used, m) + capped = capped + k + fallbacks = fallbacks + f + END DO + END SUBROUTINE CD_Get_System_Substep_Counts + PURE FUNCTION CD_System_Fallback_Count() RESULT(n) !! Subdivision-retry entries since the last CD_System_Fallback_Reset (see the !! module-level tripwire note). diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 9443f1b5..f280770e 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -76,7 +76,7 @@ MODULE CableDyn CD_AGG_Step_Moving, CD_AGG_CalcOutput, CD_AGG_GetMovingPointMesh, & CD_AGG_Snapshot, CD_AGG_Restore, & CD_AGG_NMovingPoints, CD_AGG_NDynamicPoints, CD_AGG_Refresh_PointMesh, & - CD_AGG_NFailures, & + CD_AGG_NFailures, CD_AGG_Get_Substep_Counts, & CD_AGG_HasRigid6, CD_AGG_HasRod, & CD_AGG_Rigid6_MirrorSize, CD_AGG_Get_Rigid6_States, & CD_AGG_Set_Rigid6_States, & @@ -2390,6 +2390,7 @@ END SUBROUTINE CD_CalcContStateDeriv !---------------------------------------------------------------------------------------------------------------------------------- SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 TYPE(CD_InputType) , INTENT(INOUT) :: u TYPE(CD_ParameterType) , INTENT(INOUT) :: p TYPE(CD_ContinuousStateType) , INTENT(INOUT) :: x @@ -2404,6 +2405,9 @@ SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) character(*), parameter :: RoutineName = 'CD_End' INTEGER(IntKi) :: ErrStat2 INTEGER :: hn_step, hn_resid, hn_solve, hn_am, hn_alloc, hn_tan + INTEGER(int64) :: sb_calls, sb_events, sb_capped, sb_fallbacks + INTEGER :: sb_max, sb_ios + CHARACTER(24) :: sb_txt(5) REAL(wp) :: ht_step, ht_resid, ht_eff, ht_solve, ht_am, ht_tan CHARACTER(ErrMsgLen) :: ErrMsg2 @@ -2413,6 +2417,23 @@ SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) IF (ALLOCATED(Inst)) THEN IF (m%CDInst >= 1 .AND. m%CDInst <= SIZE(Inst)) THEN IF (Inst(m%CDInst)%active) THEN + ! the rotation- and snap-resolved sub-steps of the EI=0 lines (ei0_substeps), as the + ! standalone driver reports them + CALL CD_AGG_Get_Substep_Counts( Inst(m%CDInst)%agg, sb_calls, sb_events, sb_max, sb_capped, & + sb_fallbacks ) + IF (sb_events > 0 .OR. sb_fallbacks > 0) THEN + ! 64-bit counts, written here (Num2LStr takes the default integer kind) + WRITE (sb_txt(1), '(I0)', IOSTAT=sb_ios) sb_events + WRITE (sb_txt(2), '(I0)', IOSTAT=sb_ios) sb_calls + WRITE (sb_txt(3), '(I0)', IOSTAT=sb_ios) sb_max + WRITE (sb_txt(4), '(I0)', IOSTAT=sb_ios) sb_capped + WRITE (sb_txt(5), '(I0)', IOSTAT=sb_ios) sb_fallbacks + CALL WrScr( ' CableDyn: ei0_substeps auto solved '//TRIM(sb_txt(1))//' of the '// & + TRIM(sb_txt(2))//' EI = 0 line step(s) it examined in sub-steps (at most '// & + TRIM(sb_txt(3))//' sub-steps per step); '//TRIM(sb_txt(4))// & + ' needed more than ei0_substep_max; '//TRIM(sb_txt(5))// & + ' kept the whole step after a sub-step did not converge.' ) + END IF IF (Inst(m%CDInst)%prof_enabled) THEN CALL WrScr( ' CableDyn profile: init_s='// & TRIM(Num2LStr(REAL(Inst(m%CDInst)%prof_t_init, DbKi)))// & diff --git a/tests/test_deck_driver.f90 b/tests/test_deck_driver.f90 index 75ff7106..ff565bac 100644 --- a/tests/test_deck_driver.f90 +++ b/tests/test_deck_driver.f90 @@ -1655,6 +1655,13 @@ PROGRAM test_deck_driver CALL expect_badinput('deck_badtentol.dat', deck_with_bad_tensile_tolerance(), 'negative tensile tolerance') CALL expect_badinput('deck_badrecovery.dat', deck_with_bad_recovery_cap(), 'non-finite recovery cap') CALL expect_badinput('deck_fracrecovery.dat', deck_with_fractional_recovery_cap(), 'fractional recovery cap') + ! the ei0 sub-stepping options take the Python deck reader's rules: ei0_substep_max is an integer + ! to within 16 ulp whose nearest integer lies in [2, 1024] + CALL expect_badinput('deck_ei0mode.dat', deck_with_ei0_option('on ei0_substeps'), 'invalid ei0_substeps') + CALL expect_badinput('deck_ei0angle.dat', deck_with_ei0_option('0 ei0_substep_angle'), 'zero ei0_substep_angle') + CALL expect_badinput('deck_ei0max.dat', deck_with_ei0_option('1025 ei0_substep_max'), 'ei0_substep_max above 1024') + CALL expect_badinput('deck_ei0maxfr.dat', deck_with_ei0_option('2.5 ei0_substep_max'), 'fractional ei0_substep_max') + CALL expect_badinput('deck_ei0maxbig.dat', deck_with_ei0_option('2048.5 ei0_substep_max'), 'large ei0_substep_max') CALL expect_badinput('deck_body.dat', deck_with_bodies(), 'Rigid6 BODY') CALL expect_badinput('deck_ei.dat', deck_with_finite_ei(), 'finite-EI section') CALL expect_badinput('deck_badgj.dat', deck_with_bad_native_finite_ei(), 'explicit finite-EI') @@ -7170,4 +7177,9 @@ CHARACTER(900) FUNCTION deck_with_fractional_recovery_cap() RESULT(s) '4.5 recovery_max_substeps' END FUNCTION deck_with_fractional_recovery_cap + CHARACTER(900) FUNCTION deck_with_ei0_option(row) RESULT(s) + CHARACTER(*), INTENT(IN) :: row + s = 'badei0'//NEW_LINE('a')//'--- OPTIONS ---'//NEW_LINE('a')//row + END FUNCTION deck_with_ei0_option + END PROGRAM test_deck_driver diff --git a/tests/test_ei0_slack_dynamics.f90 b/tests/test_ei0_slack_dynamics.f90 index 167883b1..195ef517 100644 --- a/tests/test_ei0_slack_dynamics.f90 +++ b/tests/test_ei0_slack_dynamics.f90 @@ -5,8 +5,10 @@ PROGRAM test_ei0_slack_dynamics !! Tension-only (EI = 0) lines that go slack and snap taut, at the default rhoInf = 0.4: !! 1. A light, axially stiff cable (80 kg/m, EA 8e8 N, 115 x 2 m segments) under 3 m / 10 s !! heave at dtM 0.1 s. The configuration-blended step reported 0.61 MN at the fairlead and - !! 20 MN at the anchor against about 0.1 MN (rhoInf 0 and small-step references); the - !! force blend stays below 0.2 MN. + !! 20 MN at the anchor; the force blend stays below 0.2 MN. This undamped EI = 0 deck has + !! no converged snap peak (it rises as dtM falls, to 0.32-0.46 MN at microsecond steps, as + !! single segments rattle); converged finite-EI runs give 0.093 MN at the fairlead and + !! 0.057 MN at the anchor, so the bounds catch a spike or a lost snap, not a reference. !! 2. The same cable at dtM 0.01 s, where the force blend alone still fed a rattle of !! single-step segment spikes (2.3 MN by 24 s) through the energy a release creates; !! with the release cap every segment stays below 0.2 MN. @@ -14,8 +16,10 @@ PROGRAM test_ei0_slack_dynamics !! 1.80 MN at the fairlead (2.69 MN configuration-blended), as at dtM 0.0025 s. !! 4. The run audit of the driver (stdout of the executable given as the first argument): !! the configuration blend (False alpha_force_blend) of case 1 warns of a non-physical - !! tension spike, the force blend does not; rhoInf above 0.95 prints its note; a 10 m - !! sway at dtM 0.2 s prints the segment-turn advisory; the unresolved slack-to-taut + !! tension spike and is not sub-stepped, the force blend does not warn; rhoInf above + !! 0.95 prints its note; a 10 m sway at dtM 0.2 s prints the segment-turn advisory with + !! off ei0_substeps, and with the default auto is sub-stepped instead (reported; the turn + !! per solver step drops from about 6 deg to about 1.3 deg); the unresolved slack-to-taut !! snaps of case 1 print the snap note. !! 5. The Newton tangent of the force-blended step against a central finite difference of its !! residual (the step's probe_q hook), on a three-segment tension-only chain with one fixed @@ -53,6 +57,12 @@ PROGRAM test_ei0_slack_dynamics !! 9. A lightly damped viscoelastic version of the light cable at dtM 0.1 s (the cap on its !! law segments) and a long taut Syrope line in 4 m surge that goes slack: no spike !! warning, and peaks within the band of small-step references. + !! 10. An elastic segment with an axial dashpot that is slack at t_n and whose ends separate + !! (or approach) there, then turn or reverse within the step: the kept dashpot share + !! returns at most the dashpot's one-step dissipation T_d,n |ldot_n| dt plus the end + !! share's credit (it returned many times that before the cap covered slack starts), a + !! slack segment with no step-start dashpot force keeps the plain blend, and the tangent + !! of a capped row matches the finite difference on the banded and the dense path. USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_CableGenAlphaWorkspace, CD_Cable_Gen_Alpha_Step, CD_DYN_OK @@ -87,6 +97,7 @@ PROGRAM test_ei0_slack_dynamics CALL case_law_release_cap() CALL case_law_damped_release() CALL case_damped_elastic_release() + CALL case_slack_dashpot_release() CALL case_load_share_tangent() CALL case_warm_resolve_reuse() CALL case_light_cable_coarse_step() @@ -288,6 +299,28 @@ LOGICAL FUNCTION file_contains(path, needle) RESULT(found) CLOSE (u) END FUNCTION file_contains + REAL(wp) FUNCTION noted_turn(path) RESULT(turn) + !! The turn (deg) of the run audit's segment-turn note in a driver log, 0 without the note. + CHARACTER(*), INTENT(IN) :: path + CHARACTER(*), PARAMETER :: KEY = 'a taut segment turned up to' + INTEGER :: u, ios, i + CHARACTER(4096) :: line + turn = 0.0_wp + OPEN (NEWUNIT=u, FILE=path, STATUS='OLD', ACTION='READ', IOSTAT=ios) + IF (ios /= 0) RETURN + DO + READ (u, '(A)', IOSTAT=ios) line + IF (ios /= 0) EXIT + i = INDEX(line, KEY) + IF (i > 0) THEN + READ (line(i + LEN(KEY):), *, IOSTAT=ios) turn + IF (ios /= 0) turn = -1.0_wp + EXIT + END IF + END DO + CLOSE (u) + END FUNCTION noted_turn + SUBROUTINE echo_tail(path, n) !! Print the last n lines of a log (the reason a driver run stopped). CHARACTER(*), INTENT(IN) :: path @@ -606,6 +639,7 @@ END SUBROUTINE case_viscoelastic_surge SUBROUTINE case_run_audit() LOGICAL :: ok + REAL(wp) :: turn_off, turn_auto CHARACTER(64) :: opts(4) ! the configuration blend of case 1: its spikes are reported once, as a warning. Its ! non-physical spikes make the run chaotic: whether it completes or a later spike stops it @@ -648,20 +682,44 @@ SUBROUTINE case_run_audit() CALL require(ok, 'audit:rhoinf-run') CALL require(file_contains('ei0slack_audit_rho.log', 'Note: rhoInf = 0.990 leaves almost no numerical'), & 'audit:rhoinf-note') - ! a 10 m sway at dtM 0.2 s turns the segments by several degrees per step + ! a 10 m sway at dtM 0.2 s turns the segments by several degrees per step: taken as given + ! (off ei0_substeps) the run notes the turn CALL write_motion('ei0slack_sway.txt', 1, [5.0_wp, 0.0_wp, -14.0_wp], 2, 10.0_wp, 10.0_wp, 10.0_wp, & 0.2_wp, 20.0_wp) opts(1) = '0.2 dtM' opts(2) = '20.0 TMax' opts(3) = 'ei0slack_sway.txt motionFile' - opts(4) = '' + opts(4) = 'off ei0_substeps' CALL write_deck('ei0slack_audit_sway.dat', CABLE, [205.0_wp, 0.0_wp, -80.0_wp], [5.0_wp, 0.0_wp, -14.0_wp], & 230.0_wp, 115, 80.0_wp, '-', opts) CALL run_driver_logged('ei0slack_audit_sway.dat', 'ei0slack_audit_sway', 'ei0slack_audit_sway.log', ok) CALL require(ok, 'audit:sway-run') CALL require(file_contains('ei0slack_audit_sway.log', 'Note: line 1: a taut segment turned up to'), & 'audit:segment-turn-note') + CALL require(file_contains('ei0slack_audit_sway.log', 'set ei0_substeps auto'), 'audit:segment-turn-remedy') CALL require(.NOT. file_contains('ei0slack_audit_sway.log', 'Warning: line'), 'audit:sway-no-warning') + ! the default (auto) sub-steps those steps: the run reports the sub-stepping, and the turn + ! per solver step drops to about 1 deg (the steps recovered after a stall take their four + ! sub-steps as given, so a note may remain for them): 1.27 deg against 6.21 deg taken as + ! given (gfortran, Windows). A step left unresolved turns by the full step's turn, a + ! recovered one by a quarter of it, so half the turn taken as given separates the two + ! without depending on which steps round-off makes stall + opts(4) = '' + CALL write_deck('ei0slack_audit_sway_auto.dat', CABLE, [205.0_wp, 0.0_wp, -80.0_wp], & + [5.0_wp, 0.0_wp, -14.0_wp], 230.0_wp, 115, 80.0_wp, '-', opts) + CALL run_driver_logged('ei0slack_audit_sway_auto.dat', 'ei0slack_audit_sway_auto', & + 'ei0slack_audit_sway_auto.log', ok) + CALL require(ok, 'audit:sway-auto-run') + CALL require(file_contains('ei0slack_audit_sway_auto.log', 'ei0_substeps auto solved'), 'audit:substep-note') + turn_off = noted_turn('ei0slack_audit_sway.log') + turn_auto = noted_turn('ei0slack_audit_sway_auto.log') + WRITE (*, '(A,F7.3,A,F7.3,A)') ' sway at dtM 0.2 s: largest turn per solver step ', turn_off, ' deg (off), ', & + turn_auto, ' deg (auto)' + CALL require(turn_off > 4.0_wp .AND. turn_auto >= 0.0_wp .AND. turn_auto < 0.5_wp*turn_off, & + 'audit:sway-auto-resolved-turn') + ! the configuration blend (paper mode) takes every step as given + CALL require(.NOT. file_contains('ei0slack_audit_cfg.log', 'ei0_substeps auto solved'), & + 'audit:configuration-blend-not-sub-stepped') END SUBROUTINE case_run_audit ! ------------------------------------------------------------------------------------------ @@ -1155,6 +1213,141 @@ SUBROUTINE damped_tangent_case(label, qn, vn, q1, l0, ea, ad, t0) CALL fd_tangent_check(label, qn, vn, z, q1, l0, ea, [2.0_wp, 3.0_wp, 1.5_wp], .FALSE., axial_damping=ad) END SUBROUTINE damped_tangent_case + SUBROUTINE case_slack_dashpot_release() + !! The dashpot segment of case_damped_elastic_release slack at t_n (e_n = -1.6 mm), its far + !! end moving at +-0.05, 0.5 or 2 m/s along the chord (dashpot tension T_d,n = BA rate/l0, a + !! compressive one for the negative rate), turning by 0 to 180 degrees within the step and + !! ending slack or taut. The kept share alpha_f T_d,n t_n returns T_k p (T_k the kept + !! tension the residual carries, p the projected shortening): at most + !! W_d + N_d, W_d = T_d,n ldot_n dt the dashpot's one-step dissipation and + !! N_d = max((1 - alpha_f) T_d,n+1 p_n+1, 0) the end share's credit. Without the cap (no + !! axial_damping) it returns alpha_f T_d,n p, up to 46 times W_d + N_d on these rows (the cap + !! acts where the end share does little work: turns that end near the projection of the + !! step-start chord; a reversal along the chord feeds the end share's dashpot instead). + !! A slack segment with no step-start dashpot + !! force keeps the plain blend, and the tangent matches the finite difference where the + !! cap acts. + REAL(wp), PARAMETER :: L0(3) = [1.0_wp, 1.2_wp, 0.8_wp], EA(3) = [1.0e6_wp, 1.5e6_wp, 0.8e6_wp] + REAL(wp), PARAMETER :: DIRS(3, 3) = RESHAPE([1.0_wp, 0.2_wp, 0.1_wp, 0.3_wp, 1.0_wp, -0.2_wp, & + -0.2_wp, 0.4_wp, 1.0_wp], [3, 3]) + REAL(wp), PARAMETER :: THETA(8) = [0.0_wp, 2.0_wp, 5.0_wp, 20.0_wp, 45.0_wp, 90.0_wp, 135.0_wp, 180.0_wp] + REAL(wp), PARAMETER :: S1(9) = [-0.5_wp, -0.1_wp, -0.01_wp, -2.0e-3_wp, -1.0e-4_wp, 1.0e-4_wp, & + 1.0e-3_wp, 0.01_wp, 0.05_wp] + REAL(wp), PARAMETER :: OFS(5) = [-0.02_wp, -0.003_wp, 0.0_wp, 0.003_wp, 0.02_wp] + REAL(wp), PARAMETER :: RATE(4) = [0.05_wp, 0.5_wp, 2.0_wp, -0.5_wp], DT = 0.05_wp, RHO = 0.4_wp + REAL(wp), PARAMETER :: BA = 2.0e4_wp, AD(3) = [0.0_wp, 0.0_wp, BA] + REAL(wp), PARAMETER :: RHO_TINY(3) = [1.0e-12_wp, 1.0e-12_wp, 1.0e-12_wp] + REAL(wp) :: qn(12), q1(12), vn(12), z(12), v1(12), R(12), Rp(12), K(9, 9), tn(3), u(3), dir(3) + REAL(wp) :: d0(3), d1(3), t1(3), l1, td0, td1, p, p1, am, af, beta, gamma, wd, nd, tk, wk, wu + REAL(wp) :: worst, unc_ratio, unc_excess, dev + INTEGER :: i, j, ir, nact, nrow + CALL reset_chain_load() + cb_dash_elem = 3 + cb_ba_dash = BA + cb_l0_dash = L0(3) + am = (2.0_wp*RHO - 1.0_wp)/(RHO + 1.0_wp) + af = RHO/(RHO + 1.0_wp) + beta = 0.25_wp*(1.0_wp - am + af)**2 + gamma = 0.5_wp - am + af + CALL chain_nodes(DIRS, [0.010_wp, 0.020_wp, -0.002_wp], L0, qn) + z = 0.0_wp + d0 = qn(10:12) - qn(7:9) + tn = d0/NORM2(d0) + u = [tn(2), -tn(1), 0.0_wp] + u = u/NORM2(u) + worst = -HUGE(1.0_wp) + unc_ratio = 0.0_wp + unc_excess = 0.0_wp + nact = 0 + nrow = 0 + DO ir = 1, SIZE(RATE) + vn = 0.0_wp + vn(10:12) = RATE(ir)*tn + td0 = BA*RATE(ir)/L0(3) + wd = td0*RATE(ir)*DT + DO i = 1, SIZE(THETA) + DO j = 1, SIZE(S1) + SIZE(OFS) + dir = COS(THETA(i)*PI/180.0_wp)*tn + SIN(THETA(i)*PI/180.0_wp)*u + IF (j <= SIZE(S1)) THEN + l1 = L0(3)*(1.0_wp + S1(j)) + ELSE + ! the end near the projection of the step-start chord (p_n+1 ~ OFS): a turn whose + ! end share does little work, where the cap acts + l1 = MAX(NORM2(d0)*COS(THETA(i)*PI/180.0_wp) + OFS(j - SIZE(S1)), 0.05_wp*L0(3)) + END IF + q1 = qn + q1(10:12) = qn(7:9) + l1*dir + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., R, K, axial_damping=AD) + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Rp, K) + v1 = gamma/(beta*DT)*(q1 - qn) + (1.0_wp - gamma/beta)*vn + v1(1:3) = 0.0_wp + d1 = q1(10:12) - q1(7:9) + l1 = NORM2(d1) + t1 = d1/l1 + p = NORM2(d0) - DOT_PRODUCT(tn, d1) + p1 = l1 - DOT_PRODUCT(t1, d0) + td1 = BA*DOT_PRODUCT(t1, v1(10:12) - v1(7:9))/L0(3) + nd = MAX((1.0_wp - af)*td1*p1, 0.0_wp) + ! the kept tension: alpha_f T_d,n plus the cap's correction along t_n at node b + tk = af*td0 + DOT_PRODUCT(R(10:12) - Rp(10:12), tn) + wk = tk*p + wu = af*td0*p + nrow = nrow + 1 + IF (MAXVAL(ABS(R(10:12) - Rp(10:12))) > 1.0e-9_wp*ABS(td0)) nact = nact + 1 + worst = MAX(worst, (wk - (wd + nd))/wd) + unc_ratio = MAX(unc_ratio, wu/(wd + nd)) + unc_excess = MAX(unc_excess, (wu - (wd + nd))/wd) + IF (j > SIZE(S1)) CYCLE + IF (THETA(i) == 0.0_wp .AND. S1(j)*RATE(ir) > 0.0_wp) THEN + ! a segment that keeps its direction and moves on at its step-start sense: uncapped + CALL require(MAXVAL(ABS(R(10:12) - Rp(10:12))) == 0.0_wp, 'slack-dashpot:same-sense-uncapped') + END IF + END DO + END DO + END DO + WRITE (*, '(A,I0,A,I0,A,ES10.3,A,ES10.3,A,ES10.3)') ' slack dashpot: cap active at ', nact, ' of ', nrow, & + ' rows; kept-share work over W_d + N_d, / W_d: ', worst, ' (uncapped ', unc_excess, & + '; uncapped / (W_d + N_d) up to ', unc_ratio + CALL require(nact >= 20, 'slack-dashpot:cap-active') + CALL require(unc_ratio > 10.0_wp, 'slack-dashpot:uncapped-exceeds') + CALL require(worst <= 1.0e-9_wp, 'slack-dashpot:bound') + ! a slack segment with no step-start dashpot force (ends at rest along the chord) keeps the + ! plain blend bit for bit, reversed or not + vn = 0.0_wp + vn(10:12) = 0.5_wp*u + q1 = qn + q1(10:12) = qn(7:9) - 0.9_wp*L0(3)*tn + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., R, K, axial_damping=AD) + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Rp, K) + dev = MAXVAL(ABS(R - Rp)) + CALL require(dev == 0.0_wp, 'slack-dashpot:no-start-dashpot-uncapped') + ! the tangent where the cap acts: turning 60 degrees with the end at p_n+1 = 3 mm (end + ! share pushing, no credit) and 20 mm (a positive credit), extending at 0.5 m/s at t_n + vn = 0.0_wp + vn(10:12) = 0.5_wp*tn + dir = COS(PI/3.0_wp)*tn + SIN(PI/3.0_wp)*u + q1 = qn + q1(10:12) = qn(7:9) + (0.5_wp*NORM2(d0) + 3.0e-3_wp)*dir + CALL slack_tangent_case('slack-dashpot-no-credit', qn, vn, q1, L0, EA, AD, BA*0.5_wp/L0(3)) + q1(10:12) = qn(7:9) + (0.5_wp*NORM2(d0) + 2.0e-2_wp)*dir + CALL slack_tangent_case('slack-dashpot-credit', qn, vn, q1, L0, EA, AD, BA*0.5_wp/L0(3)) + CALL reset_chain_load() + END SUBROUTINE case_slack_dashpot_release + + SUBROUTINE slack_tangent_case(label, qn, vn, q1, l0, ea, ad, td0) + !! A capped row of case_slack_dashpot_release: the cap is active, and the tangent matches + !! the finite difference on both paths. + CHARACTER(*), INTENT(IN) :: label + REAL(wp), INTENT(IN) :: qn(12), vn(12), q1(12), l0(3), ea(3), ad(3), td0 + REAL(wp) :: Ra(12), Rb(12), Kd(9, 9), z(12) + z = 0.0_wp + CALL probe_chain(qn, vn, z, q1, l0, ea, [1.0e-12_wp, 1.0e-12_wp, 1.0e-12_wp], .TRUE., Ra, Kd, axial_damping=ad) + CALL probe_chain(qn, vn, z, q1, l0, ea, [1.0e-12_wp, 1.0e-12_wp, 1.0e-12_wp], .TRUE., Rb, Kd) + CALL require(MAXVAL(ABS(Ra(10:12) - Rb(10:12))) > 1.0e-2_wp*ABS(td0), label//':cap-active') + CALL fd_tangent_check(label, qn, vn, z, q1, l0, ea, [2.0_wp, 3.0_wp, 1.5_wp], .TRUE., axial_damping=ad) + CALL fd_tangent_check(label, qn, vn, z, q1, l0, ea, [2.0_wp, 3.0_wp, 1.5_wp], .FALSE., axial_damping=ad) + END SUBROUTINE slack_tangent_case + SUBROUTINE law_cap_config(label, strain_n, strain_1, dirs_trial) CHARACTER(*), INTENT(IN) :: label REAL(wp), INTENT(IN) :: strain_n(3), strain_1(3) @@ -1423,16 +1616,18 @@ SUBROUTINE case_law_slack_runs() REAL(wp) :: fair, anch, seg_min ! the light cable as a lightly damped viscoelastic line, 3 m heave at dtM 0.1 s: anchor ! 8.2e4 to 9.5e4 N and fairlead 0.97e5 to 1.02e5 N at dtM 0.5 to 2.5 ms; without the cap - ! on its law segments 1.45e5 N at the anchor. At 0.1 s the anchor snap is not resolved in - ! time (the run notes it), so its peak depends on round-off: 8.5e4 N with gfortran on - ! Windows, other values on other platforms. The upper bound is the check of the cap; the - ! lower bound only asks that the snap reaches the anchor. + ! on its law segments 1.45e5 N at the anchor, both taking every step as given. At 0.1 s the + ! anchor snap is not resolved in time (the run notes it), so its peak depends on round-off: + ! 8.5e4 N with gfortran on Windows, other values on other platforms. The run takes every + ! step as given (off ei0_substeps), as the 1.45e5 N without the cap was measured, so the + ! upper bound checks the cap against that figure; the lower bound only asks that the snap + ! reaches the anchor. The sub-steps of the default are checked on this law by test_syrope. CALL write_motion('ei0slack_heave_ve.txt', 1, [5.0_wp, 0.0_wp, -14.0_wp], 3, 3.0_wp, 10.0_wp, 10.0_wp, & 0.1_wp, 40.0_wp) opts(1) = '0.1 dtM' opts(2) = '40.0 TMax' opts(3) = 'ei0slack_heave_ve.txt motionFile' - opts(4) = '' + opts(4) = 'off ei0_substeps' CALL write_deck('ei0slack_ve_light.dat', CABLE_VE, [205.0_wp, 0.0_wp, -80.0_wp], [5.0_wp, 0.0_wp, -14.0_wp], & 230.0_wp, 115, 80.0_wp, 't', opts) CALL run_driver_logged('ei0slack_ve_light.dat', 'ei0slack_ve_light', 'ei0slack_ve_light.log', ok) @@ -1447,7 +1642,9 @@ SUBROUTINE case_law_slack_runs() CALL require(fair > 8.0e4_wp .AND. fair < 1.2e5_wp, 've-slack:fairlead-peak') CALL require(.NOT. file_contains('ei0slack_ve_light.log', 'Warning: line'), 've-slack:no-spike-warning') ! a taut Syrope line in 4 m surge that goes slack, dtM 0.1 s: fairlead 1.78 MN at dtM 1 and - ! 2.5 ms + ! 2.5 ms; 1.81 MN with the default sub-steps, 1.64 MN taking every step as given and + ! 1.67 MN with the configuration blend (gfortran, Windows). The bounds catch a spike or a + ! lost snap, not the round-off-dependent peak of the unresolved snap CALL write_syrope_files() CALL write_motion('ei0slack_surge_syr.txt', 1, [5.0_wp, 0.0_wp, -14.0_wp], 1, 4.0_wp, 10.0_wp, 10.0_wp, & 0.1_wp, 40.0_wp) @@ -1459,7 +1656,7 @@ SUBROUTINE case_law_slack_runs() WRITE (*, '(A,ES10.3,A,ES10.3,A)') ' Syrope line, 4 m surge, dtM 0.1 s: FairTen1 max ', fair, & ' N, smallest segment tension ', seg_min, ' N' CALL require(seg_min <= 0.0_wp, 'syrope-slack:goes-slack') - CALL require(fair > 1.5e6_wp .AND. fair < 1.95e6_wp, 'syrope-slack:fairlead-peak') + CALL require(fair > 1.4e6_wp .AND. fair < 2.3e6_wp, 'syrope-slack:fairlead-peak') CALL require(.NOT. file_contains('ei0slack_syrope.log', 'Warning: line'), 'syrope-slack:no-spike-warning') END SUBROUTINE case_law_slack_runs diff --git a/tests/test_model.f90 b/tests/test_model.f90 index da2b20ca..b8063fcd 100644 --- a/tests/test_model.f90 +++ b/tests/test_model.f90 @@ -10,7 +10,7 @@ PROGRAM test_model !! End releases the model cleanly. USE CableDyn_Precision, ONLY: wp USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Init_Bathymetry, CD_End_Bathymetry, CD_BATHY_OK - USE CableDyn_Dynamic, ONLY: GenAlphaConfig + USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_EI0_SUBSTEPS_OFF USE CableDyn_SeabedContact, ONLY: CD_SEABED_CONTACT_BLEND USE CableDyn_Line, ONLY: CD_LineType, CD_LineSection, CD_Build_Line_Mesh, CD_Nodal_Seabed_Stiffness, CD_LINE_OK USE CableDyn_Static, ONLY: CableSolverConfig @@ -27,7 +27,7 @@ PROGRAM test_model CD_Recompute_Model_Acceleration, & CD_Copy_Model, & CD_MODEL_OK, CD_MODEL_BADINPUT, CD_MODEL_SOLVEFAIL, CD_MODEL_NOT_INITIALIZED, & - CD_Update_Model_SegmentLength + CD_Update_Model_SegmentLength, CD_Set_Model_EndQuery USE CableDyn_Loads, ONLY: CD_Assemble_Distributed_Load USE CableDyn_Assemble, ONLY: CD_Assemble_Cable_Mass USE CableDyn_Hydro, ONLY: CD_Cable_Added_Mass_Matrix @@ -47,6 +47,9 @@ PROGRAM test_model CALL case_prescribed_step_updates_state() CALL case_recovery_common_path() CALL case_recovery_subdivision_path() + CALL case_resolved_substeps() + CALL case_substep_paths() + CALL case_substep_snap_only() CALL case_coupled_load_sign() CALL case_coupled_motion_update() CALL case_external_load_update() @@ -521,6 +524,333 @@ SUBROUTINE case_recovery_common_path() CALL CD_End_Model(plain, es, em) END SUBROUTINE case_recovery_common_path + SUBROUTINE case_resolved_substeps() + !! Rotation-resolved sub-stepping of CD_Step_Model (cfg%ei0_substeps auto, the default): a + !! pretensioned 8-segment line whose End B moves on a 0.6 m circle at 2 s (from rest, after a 1 s ramp) turns its + !! segments by several degrees per 0.1 s step. The resolved march solves those steps in + !! sub-steps, lands on the prescribed end state exactly, is closer to a plain march at dt/8 + !! than the plain march at dt, and repeats bit for bit from a copy of its state (a restart). + !! With off, or with an angle no step reaches, every step is the plain step bit for bit; a + !! junction step (end query armed) is never sub-stepped (it matches the plain march to the + !! Newton tolerance: its warm start differs); invalid settings fail at CD_Init_Model. + INTEGER, PARAMETER :: NE = 8, NN = NE + 1, NDOF = 3*NN, NSTEP = 30, NFINE = 8 + REAL(wp), PARAMETER :: DT = 0.1_wp + TYPE(CD_ModelType) :: auto_m, off_m, wide_m, twin_m, junc_m, fine_m, bad_m + TYPE(GenAlphaConfig) :: cfg, bad_cfg + INTEGER :: conn(2, NE), fixed(6), es, n_iter, k, j + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), q0(NDOF), v0(NDOF), f_ext(NDOF) + REAL(wp) :: pq(NDOF), pv(NDOF), pa(NDOF), err_auto, err_off + LOGICAL :: conv, stalled, all_conv, lands, twin_ok + CHARACTER(240) :: em + + CALL straight_cable(NE, conn, l0, ea, rho_a, q0, fixed) + v0 = 0.0_wp + f_ext = 0.0_wp + CALL CD_Init_Model(auto_m, q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'resolved:init: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + CALL CD_Copy_Model(auto_m, off_m, es, em) + off_m%cfg%ei0_substeps = CD_EI0_SUBSTEPS_OFF + CALL CD_Copy_Model(auto_m, wide_m, es, em) + wide_m%cfg%ei0_substep_angle = 90.0_wp + CALL CD_Copy_Model(auto_m, junc_m, es, em) + CALL CD_Copy_Model(off_m, fine_m, es, em) + + all_conv = .TRUE. + lands = .TRUE. + twin_ok = .FALSE. + DO k = 1, NSTEP + CALL circle_end_motion(q0, pq, pv, pa, REAL(k, wp)*DT) + CALL CD_Step_Model(auto_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + lands = lands .AND. ALL(auto_m%q(fixed) == pq(fixed)) .AND. ALL(auto_m%v(fixed) == pv(fixed)) .AND. & + ALL(auto_m%a(fixed) == pa(fixed)) + CALL CD_Step_Model(off_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(wide_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Set_Model_EndQuery(junc_m, .TRUE.) + CALL CD_Step_Model(junc_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + CALL CD_Set_Model_EndQuery(junc_m, .FALSE.) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + DO j = 1, NFINE + CALL circle_end_motion(q0, pq, pv, pa, (REAL(k - 1, wp) + REAL(j, wp)/REAL(NFINE, wp))*DT) + CALL CD_Step_Model(fine_m, DT/REAL(NFINE, wp), conv, stalled, n_iter, es, em, prescribed_q=pq, & + prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + END DO + IF (k == NSTEP/2) THEN + ! a restart: a copy of the committed state continues the march + CALL CD_Copy_Model(auto_m, twin_m, es, em) + CALL require(es == CD_MODEL_OK, 'resolved:copy: '//TRIM(em)) + ELSE IF (k > NSTEP/2) THEN + CALL circle_end_motion(q0, pq, pv, pa, REAL(k, wp)*DT) + CALL CD_Step_Model(twin_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, & + prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + END IF + END DO + twin_ok = ALL(twin_m%q == auto_m%q) .AND. ALL(twin_m%v == auto_m%v) .AND. ALL(twin_m%a == auto_m%a) + err_auto = MAXVAL(ABS(auto_m%q - fine_m%q)) + err_off = MAXVAL(ABS(off_m%q - fine_m%q)) + WRITE (*, '(A,I0,A,I0,A,I0,A,ES10.3,A,ES10.3,A)') ' resolved sub-steps: ', auto_m%sub_stats%events, ' of ', & + auto_m%sub_stats%calls, ' steps (at most ', auto_m%sub_stats%max_used, '); position error against dt/8 ', err_auto, & + ' m (plain ', err_off, ' m)' + CALL require(all_conv, 'resolved:converged') + CALL require(auto_m%sub_stats%events > 0 .AND. auto_m%sub_stats%max_used >= 4, 'resolved:sub-stepped') + CALL require(lands, 'resolved:lands-on-prescribed-end') + CALL require(err_auto < 0.75_wp*err_off, 'resolved:closer-to-fine-march') + CALL require(twin_ok, 'resolved:restart-bit-identical') + CALL require(off_m%sub_stats%calls == 0 .AND. off_m%sub_stats%events == 0, 'resolved:off-not-examined') + CALL require(wide_m%sub_stats%events == 0 .AND. ALL(wide_m%q == off_m%q) .AND. ALL(wide_m%v == off_m%v) .AND. & + ALL(wide_m%a == off_m%a), 'resolved:untriggered-is-plain') + CALL require(junc_m%sub_stats%calls == 0 .AND. MAXVAL(ABS(junc_m%q - off_m%q)) < 1.0e-6_wp, & + 'resolved:junction-not-sub-stepped') + ! the settings are checked once, at CD_Init_Model + bad_cfg = cfg + bad_cfg%ei0_substep_angle = 0.0_wp + CALL CD_Init_Model(bad_m, q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, bad_cfg, es, em) + CALL require(es == CD_MODEL_BADINPUT .AND. INDEX(em, 'ei0_substep_angle') > 0, 'resolved:invalid-angle') + bad_cfg = cfg + bad_cfg%ei0_substep_max = 1025 + CALL CD_Init_Model(bad_m, q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, bad_cfg, es, em) + CALL require(es == CD_MODEL_BADINPUT .AND. INDEX(em, 'ei0_substep_max') > 0, 'resolved:invalid-max') + bad_cfg = cfg + bad_cfg%ei0_substeps = 7 + CALL CD_Init_Model(bad_m, q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, bad_cfg, es, em) + CALL require(es == CD_MODEL_BADINPUT .AND. INDEX(em, 'ei0_substeps') > 0, 'resolved:invalid-mode') + CALL CD_End_Model(auto_m, es, em) + CALL CD_End_Model(off_m, es, em) + CALL CD_End_Model(wide_m, es, em) + CALL CD_End_Model(twin_m, es, em) + CALL CD_End_Model(junc_m, es, em) + CALL CD_End_Model(fine_m, es, em) + CALL CD_End_Model(bad_m, es, em) + END SUBROUTINE case_resolved_substeps + + SUBROUTINE case_substep_paths() + !! The paths of the resolved sub-stepping on a line that carries viscoelastic segments and + !! seabed friction (the 8-segment line of case_resolved_substeps resting 1 cm into a flat + !! seabed, End B on the 0.6 m circle): (1) solving the first sub-stepped pass twice, the + !! second from the restored committed state (TEST-ONLY sub_test_repeat), changes nothing bit + !! for bit, so the restore covers the kinematics, the viscoelastic dl_1 state and the + !! friction anchors; (2) a sub-step that fails (TEST-ONLY sub_test_fail) returns the plain + !! step's own result, the run then equals the run with ei0_substeps off bit for bit; (3) a + !! cap of four sub-steps at a 0.05 deg angle is reached and counted; (4) a re-measured + !! interval that needs more sub-steps (TEST-ONLY sub_test_more: one more) is solved again + !! with them and lands on the prescribed end state. + INTEGER, PARAMETER :: NE = 8, NN = NE + 1, NDOF = 3*NN, NSTEP = 30 + REAL(wp), PARAMETER :: DT = 0.1_wp + INTEGER, PARAMETER :: SUB_MIN = 4 ! the fewest sub-steps of a sub-stepped step + TYPE(CD_ModelType) :: auto_m, rep_m, fb_m, off_m, cap_m, more_m + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, NE), fixed(6), es, n_iter, k + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), q0(NDOF), v0(NDOF), f_ext(NDOF), kn(NN), cn(NN) + REAL(wp) :: ve_ead(NE), ve_ba(NE), ve_bad(NE), pq(NDOF), pv(NDOF), pa(NDOF), dl1_0(NE), fr_0(2, NN) + LOGICAL :: conv, stalled, all_conv, more_lands + CHARACTER(240) :: em + + more_lands = .TRUE. + CALL straight_cable(NE, conn, l0, ea, rho_a, q0, fixed) + v0 = 0.0_wp + f_ext = 0.0_wp + kn = 1.0e4_wp + cn = 1.0e2_wp + ! the even segments are viscoelastic (Es | Ed, Bs | Bd) + ve_ead = 0.0_wp + ve_ba = 0.0_wp + ve_bad = 0.0_wp + ve_ead(2:NE:2) = 2.0e6_wp + ve_ba(2:NE:2) = 1.0e5_wp + ve_bad(2:NE:2) = 1.0e3_wp + CALL CD_Init_Model(auto_m, q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, cfg, es, em, & + seabed_z_floor=0.01_wp, seabed_kn=kn, seabed_cn=cn, seabed_mu=0.5_wp, & + ve_ea_d=ve_ead, ve_ba=ve_ba, ve_ba_d=ve_bad) + CALL require(es == CD_MODEL_OK, 'substep-paths:init: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + dl1_0 = auto_m%ve_dl_1 + fr_0 = auto_m%fr_anchor + CALL CD_Copy_Model(auto_m, rep_m, es, em) + rep_m%sub_test_repeat = .TRUE. + CALL CD_Copy_Model(auto_m, fb_m, es, em) + fb_m%sub_test_fail = 2 + CALL CD_Copy_Model(auto_m, off_m, es, em) + off_m%cfg%ei0_substeps = CD_EI0_SUBSTEPS_OFF + CALL CD_Copy_Model(auto_m, cap_m, es, em) + cap_m%cfg%ei0_substep_angle = 0.05_wp + cap_m%cfg%ei0_substep_max = 4 + CALL CD_Copy_Model(auto_m, more_m, es, em) + more_m%sub_test_more = .TRUE. + all_conv = .TRUE. + DO k = 1, NSTEP + CALL circle_end_motion(q0, pq, pv, pa, REAL(k, wp)*DT) + CALL CD_Step_Model(auto_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(rep_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(fb_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(off_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(cap_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(more_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, & + prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + more_lands = more_lands .AND. ALL(more_m%q(fixed) == pq(fixed)) + END DO + WRITE (*, '(A,I0,A,I0,A,I0,A,I0,A,I0,A)') ' sub-step paths: ', auto_m%sub_stats%events, ' of ', auto_m%sub_stats%calls, & + ' steps sub-stepped, ', auto_m%sub_stats%remeasured, ' re-measured; fallback ', fb_m%sub_stats%fallbacks, & + ', capped ', cap_m%sub_stats%capped, ' steps' + CALL require(all_conv, 'substep-paths:converged') + CALL require(auto_m%sub_stats%events > 0, 'substep-paths:sub-stepped') + CALL require(ANY(auto_m%ve_dl_1 /= dl1_0) .AND. ANY(auto_m%fr_anchor /= fr_0), 'substep-paths:states-move') + CALL require(ALL(rep_m%q == auto_m%q) .AND. ALL(rep_m%v == auto_m%v) .AND. ALL(rep_m%a == auto_m%a) .AND. & + ALL(rep_m%ve_dl_1 == auto_m%ve_dl_1) .AND. ALL(rep_m%fr_anchor == auto_m%fr_anchor), & + 'substep-paths:restore-is-complete') + CALL require(fb_m%sub_stats%events == 0 .AND. fb_m%sub_stats%fallbacks > 0, 'substep-paths:fallback-counted') + CALL require(ALL(fb_m%q == off_m%q) .AND. ALL(fb_m%v == off_m%v) .AND. ALL(fb_m%a == off_m%a) .AND. & + ALL(fb_m%ve_dl_1 == off_m%ve_dl_1) .AND. ALL(fb_m%fr_anchor == off_m%fr_anchor), & + 'substep-paths:fallback-is-the-plain-step') + CALL require(cap_m%sub_stats%capped > 0 .AND. cap_m%sub_stats%max_used == 4, 'substep-paths:cap') + CALL require(more_m%sub_stats%remeasured == more_m%sub_stats%events .AND. more_m%sub_stats%events > 0 .AND. & + more_m%sub_stats%max_used >= SUB_MIN + 1 .AND. more_lands .AND. & + ANY(more_m%q /= auto_m%q), 'substep-paths:re-measured') + CALL CD_End_Model(auto_m, es, em) + CALL CD_End_Model(rep_m, es, em) + CALL CD_End_Model(fb_m, es, em) + CALL CD_End_Model(off_m, es, em) + CALL CD_End_Model(cap_m, es, em) + CALL CD_End_Model(more_m, es, em) + END SUBROUTINE case_substep_paths + + SUBROUTINE case_substep_snap_only() + !! The snap trigger alone, on straight 4-segment lines whose End B is pulled along the line in + !! one 0.05 s step (no turn in any step; the axial wave crosses a segment 15 times per step): + !! (1) a line 5 % slack all over (step-start and initial tension 0) snaps taut and is solved + !! in four sub-steps, and with ei0_substeps off it is taken as given; (2) on a line whose + !! End A half is taut (52.6 kN) and End B half 20 % slack, the taut half recoils and snaps the + !! slack half taut: with End B pulled 0.2 m its segments end at 0.42 of the step-start tension, + !! above a quarter of it (a snap, four sub-steps), with End B held at 0.22, below it (the plain + !! step, bit for bit); (3) on the 5 % slack line made 1000 times heavier + !! the axial wave crosses a segment 0.48 times per step, so the step resolves the snap as + !! given and is not sub-stepped. + INTEGER, PARAMETER :: NE = 4, NN = NE + 1, NDOF = 3*NN + REAL(wp), PARAMETER :: DT = 0.05_wp + TYPE(CD_ModelType) :: auto_m, off_m + INTEGER :: conn(2, NE), fixed(6), es + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), q0(NDOF), pq(NDOF) + REAL(wp) :: t_start, t_end_big, t_end_small + LOGICAL :: ok, auto_ok, off_ok + CHARACTER(240) :: em + + CALL straight_cable(NE, conn, l0, ea, rho_a, q0, fixed) + ! (1) slack all over + l0 = 1.05_wp + CALL snap_pull(conn, l0, ea, rho_a, q0, fixed, DT, 0.5_wp, auto_m, off_m, pq, auto_ok, off_ok) + WRITE (*, '(A,I0,A,I0,A)') ' snap-only trigger, slack line: ', auto_m%sub_stats%events, & + ' step(s) sub-stepped, at most ', auto_m%sub_stats%max_used, ' sub-steps' + CALL require(auto_ok .AND. off_ok, 'snap-only:converged') + CALL require(auto_m%sub_stats%events == 1 .AND. auto_m%sub_stats%max_used == 4, 'snap-only:four-sub-steps') + CALL require(ALL(auto_m%q(fixed) == pq(fixed)), 'snap-only:lands-on-end-state') + CALL require(off_m%sub_stats%events == 0 .AND. ANY(off_m%q /= auto_m%q), 'snap-only:off-takes-the-step') + ! (2) partly taut: the floor is the step-start tension of the taut half + l0(1:2) = 0.95_wp + l0(3:4) = 1.20_wp + t_start = ea(1)*(1.0_wp/0.95_wp - 1.0_wp) + CALL snap_pull(conn, l0, ea, rho_a, q0, fixed, DT, 0.2_wp, auto_m, off_m, pq, auto_ok, off_ok) + t_end_big = slack_half_tension(off_m, ea, l0) + ok = auto_ok .AND. off_ok .AND. auto_m%sub_stats%events == 1 .AND. auto_m%sub_stats%max_used == 4 + CALL snap_pull(conn, l0, ea, rho_a, q0, fixed, DT, 0.0_wp, auto_m, off_m, pq, auto_ok, off_ok) + t_end_small = slack_half_tension(off_m, ea, l0) + WRITE (*, '(A,F6.3,A,F6.3,A)') ' snap-only trigger, partly taut line: the slack half ends at ', & + t_end_big/t_start, ' (End B pulled 0.2 m) and ', t_end_small/t_start, ' (held) of the step-start tension' + CALL require(t_end_big > 0.25_wp*t_start .AND. t_end_small > 0.0_wp .AND. t_end_small < 0.25_wp*t_start, & + 'snap-partly-taut:pulls-cross-the-threshold') + CALL require(ok, 'snap-partly-taut:above-threshold-sub-stepped') + CALL require(auto_ok .AND. off_ok .AND. auto_m%sub_stats%calls == 1 .AND. auto_m%sub_stats%events == 0 .AND. & + ALL(auto_m%q == off_m%q) .AND. ALL(auto_m%v == off_m%v) .AND. ALL(auto_m%a == off_m%a), & + 'snap-partly-taut:below-threshold-plain') + ! (3) a step that resolves the axial wave takes the snap as given + l0 = 1.05_wp + rho_a = 1.0e3_wp*rho_a + CALL snap_pull(conn, l0, ea, rho_a, q0, fixed, DT, 0.5_wp, auto_m, off_m, pq, auto_ok, off_ok) + CALL require(auto_ok .AND. off_ok .AND. auto_m%sub_stats%calls == 1 .AND. auto_m%sub_stats%events == 0 .AND. & + ALL(auto_m%q == off_m%q) .AND. slack_half_tension(off_m, ea, l0) > 0.0_wp, 'snap-resolved-wave:plain') + CALL CD_End_Model(auto_m, es, em) + CALL CD_End_Model(off_m, es, em) + END SUBROUTINE case_substep_snap_only + + SUBROUTINE snap_pull(conn, l0, ea, rho_a, q0, fixed, dt, dx, auto_m, off_m, pq, ok_auto, ok_off) + !! case_substep_snap_only: a fresh pair of models (auto, off) of the straight line at rest, + !! End B pulled along the line by dx in one step of dt. + INTEGER, INTENT(IN) :: conn(:, :), fixed(:) + REAL(wp), INTENT(IN) :: l0(:), ea(:), rho_a(:), q0(:), dt, dx + TYPE(CD_ModelType), INTENT(INOUT) :: auto_m, off_m + REAL(wp), INTENT(OUT) :: pq(:) + LOGICAL, INTENT(OUT) :: ok_auto, ok_off + TYPE(GenAlphaConfig) :: cfg + INTEGER :: n_it, es, n + LOGICAL :: conv, stalled + REAL(wp) :: pv(SIZE(q0)), pa(SIZE(q0)), zero(SIZE(q0)) + CHARACTER(240) :: em + n = SIZE(q0) + zero = 0.0_wp + CALL CD_Init_Model(auto_m, q0, zero, conn, l0, ea, rho_a, .TRUE., zero, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'snap-only:init: '//TRIM(em)) + CALL CD_Copy_Model(auto_m, off_m, es, em) + off_m%cfg%ei0_substeps = CD_EI0_SUBSTEPS_OFF + pq = q0 + pv = 0.0_wp + pa = 0.0_wp + pq(n - 2) = q0(n - 2) + dx + CALL CD_Step_Model(auto_m, dt, conv, stalled, n_it, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + ok_auto = es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(off_m, dt, conv, stalled, n_it, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + ok_off = es == CD_MODEL_OK .AND. conv + END SUBROUTINE snap_pull + + REAL(wp) FUNCTION slack_half_tension(m, ea, l0) RESULT(t_max) + !! case_substep_snap_only: the largest tension of segments 3 and 4 (EA times the strain). + TYPE(CD_ModelType), INTENT(IN) :: m + REAL(wp), INTENT(IN) :: ea(:), l0(:) + INTEGER :: e + t_max = 0.0_wp + DO e = 3, 4 + t_max = MAX(t_max, ea(e)*(NORM2(m%q(3*e + 1:3*e + 3) - m%q(3*e - 2:3*e))/l0(e) - 1.0_wp)) + END DO + END FUNCTION slack_half_tension + + SUBROUTINE circle_end_motion(q0, pq, pv, pa, t) + !! End A held, End B (the last node) on the circle x_B + R r(t) (0, sin wt, 1 - cos wt), + !! R = 0.6 m, period 2 s, r the C2 quintic ramp over the first second, so the motion starts + !! from rest (case_resolved_substeps). + REAL(wp), INTENT(IN) :: q0(:), t + REAL(wp), INTENT(OUT) :: pq(:), pv(:), pa(:) + REAL(wp), PARAMETER :: RADIUS = 0.6_wp, PERIOD = 2.0_wp, RAMP = 1.0_wp + REAL(wp) :: w, u, r, rd, rdd, g(2), gd(2), gdd(2) + INTEGER :: n + n = SIZE(q0) + w = 2.0_wp*ACOS(-1.0_wp)/PERIOD + u = MIN(t/RAMP, 1.0_wp) + r = 10.0_wp*u**3 - 15.0_wp*u**4 + 6.0_wp*u**5 + rd = 0.0_wp + rdd = 0.0_wp + IF (t < RAMP) THEN + rd = (30.0_wp*u**2 - 60.0_wp*u**3 + 30.0_wp*u**4)/RAMP + rdd = (60.0_wp*u - 180.0_wp*u**2 + 120.0_wp*u**3)/RAMP**2 + END IF + g = RADIUS*[SIN(w*t), 1.0_wp - COS(w*t)] + gd = RADIUS*w*[COS(w*t), SIN(w*t)] + gdd = RADIUS*w*w*[-SIN(w*t), COS(w*t)] + pq = q0 + pv = 0.0_wp + pa = 0.0_wp + pq(n - 1:n) = q0(n - 1:n) + r*g + pv(n - 1:n) = rd*g + r*gd + pa(n - 1:n) = rdd*g + 2.0_wp*rd*gd + r*gdd + END SUBROUTINE circle_end_motion + SUBROUTINE case_recovery_subdivision_path() !! Find a bounded, deterministic prescribed-motion increment for which the !! deliberately small nonlinear-iteration allowance rejects the full diff --git a/tests/test_syrope.f90 b/tests/test_syrope.f90 index 25d8054b..31658bc6 100644 --- a/tests/test_syrope.f90 +++ b/tests/test_syrope.f90 @@ -16,7 +16,7 @@ PROGRAM test_syrope CD_Syrope_Slow_At_Mean, CD_Syrope_Check_Range, CD_Syrope_Branch_Divider, & CD_SYROPE_OK, CD_SYROPE_NWC, & CD_SYROPE_WC_LINEAR, CD_SYROPE_WC_QUADRATIC, CD_SYROPE_WC_EXP - USE CableDyn_Dynamic, ONLY: GenAlphaConfig + USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_EI0_SUBSTEPS_OFF USE CableDyn_Static, ONLY: CableSolverConfig USE CableDyn_Line, ONLY: CD_LineType, CD_LineSection USE CableDyn_Model, ONLY: CD_ModelType, CD_Init_Model, CD_Init_Line_Model, CD_Step_Model, CD_End_Model, & @@ -73,6 +73,7 @@ PROGRAM test_syrope CALL case_model_held() CALL case_syrope_accessor_roundtrip() CALL case_model_mixed_ve_syrope() + CALL case_substeps_restore_law_states() CALL case_line_model_syrope() CALL case_admissibility() CALL case_ic_rest_point() @@ -685,6 +686,121 @@ SUBROUTINE case_model_mixed_ve_syrope() CALL CD_Syrope_End(td) END SUBROUTINE case_model_mixed_ve_syrope + SUBROUTINE case_substeps_restore_law_states() + !! The rotation-resolved sub-stepping of a model carrying a Syrope and a viscoelastic + !! element (case_model_mixed_ve_syrope, the viscoelastic element 1000 times stiffer so that + !! its law tension counts as taut against the 0.8 MN of the Syrope element), node 2 free and + !! node 3 driven on a 0.4 m circle at 2 s, so the chords turn by more than a degree per + !! 0.02 s step: solving the first + !! sub-stepped pass twice, the second from the restored committed state (TEST-ONLY + !! sub_test_repeat), changes nothing bit for bit, Syrope slow strain and running maximum and + !! viscoelastic dl_1 included; a failing sub-step (TEST-ONLY sub_test_fail) returns the plain + !! step, the run then equals the run with ei0_substeps off bit for bit. + REAL(wp), PARAMETER :: L0E = 1.0_wp, EPS = 0.026_wp, DL = 0.03_wp, DT = 0.02_wp, R = 0.4_wp + INTEGER, PARAMETER :: NSTEP = 40 + TYPE(CD_SyropeType) :: td, stype(2) + TYPE(CD_ModelType) :: auto_m, rep_m, fb_m, off_m + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, 2), fixed(6), es, k, n_iter + REAL(wp) :: l0(2), eav(2), rho_a(2), q0(9), v0(9), f_ext(9), pq(9), pv(9), pa(9) + REAL(wp) :: ve_ead(2), ve_ba(2), ve_bad(2), sslow(2), stmax(2), w, t, slow0(2), dl0(2) + LOGICAL :: sis(2), conv, stalled, all_conv + CHARACTER(200) :: em + CALL CD_Syrope_Init(td, OWC_EPS, OWC_TEN, CD_SYROPE_WC_LINEAR, 0.6_wp, 0.0_wp, & + ALPHA, BETA, C1, C2, es, em) + CALL require(es == CD_SYROPE_OK, 'substep-law:type-init') + conn(:, 1) = [1, 2] + conn(:, 2) = [2, 3] + l0 = L0E + eav = [1.0e8_wp, 1.0e5_wp] + rho_a = 50.0_wp + q0 = 0.0_wp + q0(4) = L0E*(1.0_wp + EPS) + q0(7) = q0(4) + L0E*(1.0_wp + DL) + v0 = 0.0_wp + f_ext = 0.0_wp + fixed = [1, 2, 3, 7, 8, 9] + sis = [.TRUE., .FALSE.] + stype(1) = td + stype(2) = td + sslow = [0.021_wp, 0.0_wp] + stmax = [2.0e6_wp, 0.0_wp] + ve_ead = [0.0_wp, 4.0e5_wp] + ve_ba = [0.0_wp, 7.0_wp] + ve_bad = [0.0_wp, 3.0_wp] + CALL CD_Init_Model(auto_m, q0, v0, conn, l0, eav, rho_a, .TRUE., f_ext, fixed, cfg, es, em, & + ve_ea_d=ve_ead, ve_ba=ve_ba, ve_ba_d=ve_bad, & + syrope_is=sis, syrope_type=stype, syrope_slow0=sslow, syrope_tmax0=stmax) + CALL require(es == CD_MODEL_OK, 'substep-law:init: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + slow0 = auto_m%syrope_slow + dl0 = auto_m%ve_dl_1 + CALL CD_Copy_Model(auto_m, rep_m, es, em) + rep_m%sub_test_repeat = .TRUE. + CALL CD_Copy_Model(auto_m, fb_m, es, em) + fb_m%sub_test_fail = 1 + CALL CD_Copy_Model(auto_m, off_m, es, em) + off_m%cfg%ei0_substeps = CD_EI0_SUBSTEPS_OFF + w = 2.0_wp*ACOS(-1.0_wp)/2.0_wp + all_conv = .TRUE. + DO k = 1, NSTEP + ! node 3 on the circle q0(7:9) + R ramp(t) (0, sin wt, 1 - cos wt), ramped over the first second + t = REAL(k, wp)*DT + CALL ramped_circle(t, q0, w, R, pq, pv, pa) + CALL CD_Step_Model(auto_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(rep_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(fb_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + CALL CD_Step_Model(off_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + END DO + WRITE (*, '(A,I0,A,I0,A,I0,A)') ' sub-steps with Syrope and viscoelastic states: ', auto_m%sub_stats%events, & + ' of ', auto_m%sub_stats%calls, ' steps sub-stepped, ', fb_m%sub_stats%fallbacks, ' failing-sub-step fallbacks' + CALL require(all_conv, 'substep-law:converged') + CALL require(auto_m%sub_stats%events > 0, 'substep-law:sub-stepped') + CALL require(ANY(auto_m%syrope_slow /= slow0) .AND. ANY(auto_m%ve_dl_1 /= dl0), 'substep-law:states-move') + CALL require(ALL(rep_m%q == auto_m%q) .AND. ALL(rep_m%v == auto_m%v) .AND. ALL(rep_m%a == auto_m%a) .AND. & + ALL(rep_m%syrope_slow == auto_m%syrope_slow) .AND. & + ALL(rep_m%syrope_tmax == auto_m%syrope_tmax) .AND. ALL(rep_m%ve_dl_1 == auto_m%ve_dl_1), & + 'substep-law:restore-is-complete') + CALL require(fb_m%sub_stats%fallbacks > 0 .AND. ALL(fb_m%q == off_m%q) .AND. ALL(fb_m%v == off_m%v) .AND. & + ALL(fb_m%a == off_m%a) .AND. ALL(fb_m%syrope_slow == off_m%syrope_slow) .AND. & + ALL(fb_m%syrope_tmax == off_m%syrope_tmax) .AND. ALL(fb_m%ve_dl_1 == off_m%ve_dl_1), & + 'substep-law:fallback-is-the-plain-step') + CALL CD_End_Model(auto_m, es, em) + CALL CD_End_Model(rep_m, es, em) + CALL CD_End_Model(fb_m, es, em) + CALL CD_End_Model(off_m, es, em) + CALL CD_Syrope_End(td) + END SUBROUTINE case_substeps_restore_law_states + + SUBROUTINE ramped_circle(time, q0, w, R, pq, pv, pa) + !! Node 3 (DOFs 7:9) on the circle q0 + R ramp(t) (0, sin wt, 1 - cos wt), the C2 quintic + !! ramp over the first second (case_substeps_restore_law_states). + REAL(wp), INTENT(IN) :: time, q0(:), w, R + REAL(wp), INTENT(OUT) :: pq(:), pv(:), pa(:) + REAL(wp) :: u, r5, rd, rdd, g(2), gd(2), gdd(2) + u = MIN(time, 1.0_wp) + r5 = 10.0_wp*u**3 - 15.0_wp*u**4 + 6.0_wp*u**5 + rd = 0.0_wp + rdd = 0.0_wp + IF (time < 1.0_wp) THEN + rd = 30.0_wp*u**2 - 60.0_wp*u**3 + 30.0_wp*u**4 + rdd = 60.0_wp*u - 180.0_wp*u**2 + 120.0_wp*u**3 + END IF + g = R*[SIN(w*time), 1.0_wp - COS(w*time)] + gd = R*w*[COS(w*time), SIN(w*time)] + gdd = R*w*w*[-SIN(w*time), COS(w*time)] + pq = q0 + pv = 0.0_wp + pa = 0.0_wp + pq(8:9) = q0(8:9) + r5*g + pv(8:9) = rd*g + r5*gd + pa(8:9) = rdd*g + 2.0_wp*rd*gd + r5*gdd + END SUBROUTINE ramped_circle + SUBROUTINE case_line_model_syrope() !! The line-object build path with the Syrope pass-through: a straight, !! zero-gravity Syrope line built through CD_Init_Line_Model (which runs the diff --git a/validation/experiments/bergdahl/README.md b/validation/experiments/bergdahl/README.md index 1d7a615b..29b3335f 100644 --- a/validation/experiments/bergdahl/README.md +++ b/validation/experiments/bergdahl/README.md @@ -73,7 +73,7 @@ results and the checksum of the executable used. The calculated force is `FairTe at the upper line end. Across the 30 conditions, the cycle maxima have an RMSE of 1.58 N, a mean absolute percentage error of 3.13%, a mean bias of +0.46 N, a Pearson correlation of 0.993 and a Lin concordance coefficient of 0.989. For the two waveform conditions, halving the nominal -element length and the time step changes the mean cycle maximum by no more than 0.52% and +element length and the time step changes the mean cycle maximum by no more than 0.56% and 0.19%, respectively, and the phase-averaged force histories have RMSEs of 5.95% and 2.54% of the measured force range (computed with the executable of the 2026-10-09 record; see `provenance.json`). The waveform CSVs carry the measured phase averages computed from the @@ -86,7 +86,11 @@ modes up to about 2c/l ≈ 3500 rad/s. The force maxima are snap loads, which co step only once the step resolves these modes, roughly dtM ≲ l/(2c) ≈ 0.29 ms (see "Snap loads on slack lines" in the [modelling guide](https://cabledyn.readthedocs.io/en/latest/modeling.html)). At a coarser step the maxima do not settle: at the T = 1.25 s, 0.20 m condition they are -72.2 N at 0.625 ms, against 68.0 N at 0.3125 ms and 67.8 N at 0.15625 ms. Coarse steps also +69.5 N at 0.625 ms (72.2 N with every step taken as given, `off ei0_substeps`), against +68.0 N at 0.3125 ms and 67.8 N at 0.15625 ms. At 0.3125 ms and below the step resolves the +axial wave over a 0.2 m segment, so the rotation- and snap-resolved sub-steps of +`ei0_substeps auto` take no part in the primary matrix (its results equal those taken as +given); the 0.1 m mesh at 0.3125 ms and the 0.625 ms step use them. Coarse steps also leave the maxima sensitive to the Newton tolerance and to small changes in the solver's iteration path. With a 1.25 ms step and a relative tolerance of 1e-5, the five cycle maxima of a condition have standard deviations of up to 1.6 N, their means are 2–15% above the converged diff --git a/validation/experiments/bergdahl/provenance.json b/validation/experiments/bergdahl/provenance.json index 6569d610..9cdba7c6 100644 --- a/validation/experiments/bergdahl/provenance.json +++ b/validation/experiments/bergdahl/provenance.json @@ -1,8 +1,8 @@ { "CableDyn_release": "v0.1.1+dev (unreleased)", - "validation_date": "2026-10-16", + "validation_date": "2026-10-19", "executable_name": "cabledyn.exe", - "executable_sha256": "78a3fed9390fd77392a1dcaec244f79f9174d9e2e94e4b3032fb53c7b8bd4395", + "executable_sha256": "88d2bba2da6fb0801656d4bacd30e9d0e916f768c7047161457edea324274c66", "compiler": "GNU Fortran 16.2.0", "build_type": "Release", "platform": "Windows 11 x86-64", @@ -12,7 +12,7 @@ "completed_cases": 30, "nonlinear_misses": 0, "refinement_cases": 8, - "maximum_spatial_refinement_difference_percent": 0.5236270564721716, + "maximum_spatial_refinement_difference_percent": 0.5580722740928493, "maximum_temporal_refinement_difference_percent": 0.18888172026785752, "force_maxima_sha256": "978889378964c6d6749bc27c11d99d6584956e3c8eac146ae79bf5f7a05e2e95", "aggregate_metrics_sha256": "35d800fa34137a3a1500cbd0081a490bc1b61cf636cfef5a923b5c18947ba1a7", @@ -20,6 +20,6 @@ "waveform_T1p25_sha256": "65c8c846636c378b800bb3c7a95ccd2bde766d789af3cdffce26a2e688e1a134", "waveform_T3p50_sha256": "b3ca65ebfc1d61b5510e54876fc11d1604fc18ffcca3eab523dc7d67f50da4d8", "waveform_metrics_sha256": "2803a57cb7726f966a00e00bf6eb070231b9c702ae67a81685da50991d0adb11", - "waveform_note": "Waveform metrics were computed with the executable of the 2026-10-09 validation (sha256 71090e2e28c9e1d99c5180d05a395ebcc891a77cc5294d315a57c691904745ac); the force-blended EI = 0 step of this development build was not rerun on them because the article supplement's expData.dat, which reduce_bergdahl_waveforms.py reads, was not available. The measured phase averages are those of expData.dat, as carried in the waveform CSVs.", - "refinement_summary_sha256": "b3ef33659ba852ce8b6667032a9f2c44bf0336d988c29c2a80fddc2ab4053859" + "waveform_note": "Waveform metrics were computed with the executable of the 2026-10-09 validation (sha256 71090e2e28c9e1d99c5180d05a395ebcc891a77cc5294d315a57c691904745ac); the development builds since then (the force-blended EI = 0 step and its rotation- and snap-resolved sub-steps) were not rerun on them because the article supplement's expData.dat, which reduce_bergdahl_waveforms.py reads, was not available. The measured phase averages are those of expData.dat, as carried in the waveform CSVs.", + "refinement_summary_sha256": "9039f6c9b91ed2d15d7c609dd8d2300eef34d0363700487a8dfc0a8f15be1087" } diff --git a/validation/experiments/bergdahl/refinement_summary.csv b/validation/experiments/bergdahl/refinement_summary.csv index ddbd61e6..24985b11 100644 --- a/validation/experiments/bergdahl/refinement_summary.csv +++ b/validation/experiments/bergdahl/refinement_summary.csv @@ -1,3 +1,3 @@ period_s,radius_m,force_h0p400_dt0p0003125_N,force_h0p200_dt0p0003125_N,force_h0p100_dt0p0003125_N,force_h0p200_dt0p00015625_N,force_h0p200_dt0p000625_N,spatial_difference_h0p400_dt0p0003125_percent,spatial_difference_h0p200_dt0p0003125_percent,temporal_difference_h0p200_dt0p0003125_percent,temporal_difference_h0p200_dt0p000625_percent -1.25,0.2,68.15018140000001,67.9673104,68.32507899999999,67.8391746,72.2422804,-0.25597862828666473,-0.5236270564721716,0.18888172026785752,6.490506150704244 -3.5,0.2,52.3714018,52.35406759999999,52.345151599999994,52.3533266,53.9582166,0.0501482930083001,0.01703309614638552,0.0014153828383290867,3.0654976564564618 +1.25,0.2,68.15018140000001,67.9673104,68.3487458,67.8391746,69.497535,-0.2905165232746598,-0.5580722740928493,0.18888172026785752,2.4445468415236173 +3.5,0.2,52.3714018,52.35406759999999,52.342603399999994,52.3533266,53.2401192,0.05501904400881702,0.021902234996585834,0.0014153828383290867,1.6938610353749701 diff --git a/validation/experiments/bergdahl/refinement_summary.json b/validation/experiments/bergdahl/refinement_summary.json index f5f934c3..26d26521 100644 --- a/validation/experiments/bergdahl/refinement_summary.json +++ b/validation/experiments/bergdahl/refinement_summary.json @@ -4,7 +4,7 @@ "temporal_reference_time_step_s": 0.00015625, "primary_nominal_element_length_m": 0.2, "primary_time_step_s": 0.0003125, - "maximum_primary_spatial_difference_percent": 0.5236270564721716, + "maximum_primary_spatial_difference_percent": 0.5580722740928493, "maximum_primary_temporal_difference_percent": 0.18888172026785752, "rows": [ { @@ -12,26 +12,26 @@ "radius_m": 0.2, "force_h0p400_dt0p0003125_N": 68.15018140000001, "force_h0p200_dt0p0003125_N": 67.9673104, - "force_h0p100_dt0p0003125_N": 68.32507899999999, + "force_h0p100_dt0p0003125_N": 68.3487458, "force_h0p200_dt0p00015625_N": 67.8391746, - "force_h0p200_dt0p000625_N": 72.2422804, - "spatial_difference_h0p400_dt0p0003125_percent": -0.25597862828666473, - "spatial_difference_h0p200_dt0p0003125_percent": -0.5236270564721716, + "force_h0p200_dt0p000625_N": 69.497535, + "spatial_difference_h0p400_dt0p0003125_percent": -0.2905165232746598, + "spatial_difference_h0p200_dt0p0003125_percent": -0.5580722740928493, "temporal_difference_h0p200_dt0p0003125_percent": 0.18888172026785752, - "temporal_difference_h0p200_dt0p000625_percent": 6.490506150704244 + "temporal_difference_h0p200_dt0p000625_percent": 2.4445468415236173 }, { "period_s": 3.5, "radius_m": 0.2, "force_h0p400_dt0p0003125_N": 52.3714018, "force_h0p200_dt0p0003125_N": 52.35406759999999, - "force_h0p100_dt0p0003125_N": 52.345151599999994, + "force_h0p100_dt0p0003125_N": 52.342603399999994, "force_h0p200_dt0p00015625_N": 52.3533266, - "force_h0p200_dt0p000625_N": 53.9582166, - "spatial_difference_h0p400_dt0p0003125_percent": 0.0501482930083001, - "spatial_difference_h0p200_dt0p0003125_percent": 0.01703309614638552, + "force_h0p200_dt0p000625_N": 53.2401192, + "spatial_difference_h0p400_dt0p0003125_percent": 0.05501904400881702, + "spatial_difference_h0p200_dt0p0003125_percent": 0.021902234996585834, "temporal_difference_h0p200_dt0p0003125_percent": 0.0014153828383290867, - "temporal_difference_h0p200_dt0p000625_percent": 3.0654976564564618 + "temporal_difference_h0p200_dt0p000625_percent": 1.6938610353749701 } ] }