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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,8 @@ if(Python3_Interpreter_FOUND)
endif()

# TMax = 0 checks the static start of a dynamic deck: vesselMotion and motionFile records
# that outlast TMax, RangeStart at TMax = 0, and the hint of a deck without dtM and TMax.
# that outlast TMax, RangeStart at TMax = 0, a deck of each route without dtM, and the hint of a
# deck without dtM and TMax.
add_test(NAME static_check
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_static_check.py
--exe $<TARGET_FILE:cabledyn>
Expand Down
3 changes: 2 additions & 1 deletion doc/file_formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ whole multiple of ``dtM``. The file is checked against this grid:
(``time is outside the dtM/TMax grid``). Write times with enough digits to hit the
grid exactly. A file may run past ``TMax``: its rows after ``TMax`` are checked
(on the ``dtM`` grid, to within ``100·ε·max(1, time)``) and not used, so a long
record serves a shorter run and ``TMax = 0`` checks the static start.
record serves a shorter run and ``TMax = 0`` checks the static start. At ``TMax = 0``
without ``dtM`` the grid is the ``t = 0`` row and later rows are not checked.
* Every eligible point needs exactly one row at every grid time. A repeated
point/time pair is rejected (``duplicate row for point <id> at this time``). A
missing pair is rejected once the whole file has been read (``motionFile must
Expand Down
10 changes: 5 additions & 5 deletions doc/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Clock and initial condition
- real, s
- absent (static-only)
- finite, > 0. In the standalone driver ``dtM`` and ``TMax`` are given together or not at
all
all; only ``TMax = 0``, which marches no step, needs no ``dtM``
- standalone step; OpenFAST targets ``0.1`` s when absent, rounds it to at least one whole
glue ``DT``, and reports the value used
- ``0.05 dtM``
Expand All @@ -272,7 +272,7 @@ Clock and initial condition
- finite, ≥ 0 and an integer multiple of ``dtM``. ``TMax = 0`` runs the dynamic
initialisation and writes the ``t = 0`` row: the static start of a dynamic deck, checked
with every other option kept (motion records longer than ``TMax`` and a later
``RangeStart`` included)
``RangeStart`` included), with or without ``dtM``
- standalone only; OpenFAST uses the host ``TMax``. Do not copy the host duration into a
coupled deck
- ``600.0 TMax``
Expand Down Expand Up @@ -841,11 +841,11 @@ cables, Rigid6 bodies or rods.
Standalone versus OpenFAST checklist
------------------------------------

For a standalone static calculation, omit both ``dtM`` and ``TMax`` or set a deliberate pair with
``TMax=0`` when exercising the dynamic initialisation route. For standalone dynamics, provide
For a standalone static calculation, omit both ``dtM`` and ``TMax`` or set ``TMax=0`` (``dtM`` is
then optional) when exercising the dynamic initialisation route. For standalone dynamics, provide
both and ensure ``TMax/dtM`` is integral. ``current``, ``waves``, ``motionFile``, a positive
``frictionMu``, rods, bodies, ``Connect``/``Free`` points, and finite-EI sections (outside a mixed
deck) all need the ``dtM``/``TMax`` pair. File paths are resolved relative to the deck and may use
deck) all need the ``dtM``/``TMax`` pair or ``TMax=0``. File paths are resolved relative to the deck and may use
ordinary nested paths longer than the 64-character deck-identifier limit.

For ``CompMooring = 5``, OpenFAST owns gravity, density, flat depth, platform motion, run duration,
Expand Down
7 changes: 4 additions & 3 deletions doc/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ Clock, motion, and environment
* - Message
- Cause and fix
* - ``dynamic run requires both dtM and TMax options``
- the standalone driver needs both or neither. Add the missing one.
- the standalone driver needs both or neither. Add the missing one; ``TMax = 0``, a check of
the static start, needs no ``dtM``.
* - ``OPTIONS TMax must be an integer multiple of dtM``
- choose ``TMax = n·dtM`` exactly (for example ``dtM = 0.05``, ``TMax = 600``).
* - ``standalone OPTION current requires dtM and TMax`` (likewise ``waves``, ``motionFile``,
``frictionMu``, ``RODS``, ``Rigid6 BODY``, ``Point3 BODY``, ``Connect``/``Free`` points,
``finite-EI section (EI>0)``)
- these features act only in a dynamic march. Add ``dtM``/``TMax``, or remove the feature for
a static calculation. A mixed ``EI = 0`` + finite-EI deck may run static without them. A
- these features act only in a dynamic march. Add ``dtM``/``TMax``, ``TMax = 0`` to check the
static start, or remove the feature for a static calculation. A mixed ``EI = 0`` + finite-EI deck may run static without them. A
coupled (caller-driven) deck takes its clock from the host, so ``current`` and ``frictionMu``
need no ``dtM`` there.
* - ``OPTION waves requires WtrDpth``
Expand Down
12 changes: 10 additions & 2 deletions python/cabledyn/deck_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
_MOTION_SOURCE_KEYWORDS = ("motionfile", "vesselmotion", "vesselrao")
# Native STATIC_CHECK_HINT: appended to the errors that ask a standalone deck without TMax for
# the march (those naming one of the cues).
_STATIC_CHECK_HINT = "; to check a dynamic deck's static start only, give dtM with TMax = 0"
_STATIC_CHECK_HINT = "; to check a dynamic deck's static start only, give TMax = 0"
_STATIC_CHECK_CUES = ("dtM and TMax", "requires dtM", "require dtM", "dynamic deck (TMax)")
_END_CONNECTION_ENDS = {
"a": "a",
Expand Down Expand Up @@ -2505,7 +2505,14 @@ def effective(key: str, default: float) -> float:
)
has_dtm = "dtm" in option_by_key
has_tmax = "tmax" in option_by_key
if not self.caller_driven and has_dtm != has_tmax:
# native parse_deck: a static check marches no step, so standalone TMax = 0 needs no dtM
static_check = (
not self.caller_driven
and has_tmax
and not has_dtm
and _native_float(option_by_key["tmax"].values[0]) == 0.0
)
if not self.caller_driven and has_dtm != has_tmax and not static_check:
raise DeckFormatError(
f"{self._label}: standalone dynamic run requires both dtM and TMax options"
)
Expand All @@ -2525,6 +2532,7 @@ def effective(key: str, default: float) -> float:
raise DeckFormatError(
f"{self._label}: OPTION TMax must be an integer multiple of dtM"
)
has_dtm = has_dtm or static_check
# MoorDyn-C WaveKin 3/7 and Currents 1/2/5 (native read_moordyn_c_kinematics): component
# waves and a current profile or grid read from fixed-name files in the deck folder.
# The coupled aggregate takes its water kinematics from the host and rejects both.
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_deck_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ def test_host_route_does_not_relax_deck_owned_kinematics_clock(tmp_path, option_
with pytest.raises(DeckFormatError, match=message) as err:
DeckFile.read(path, caller_driven=caller_driven)
# the standalone error says how to check the deck's static start; the host route's not
assert ("give dtM with TMax = 0" in str(err.value)) is not caller_driven
assert ("give TMax = 0" in str(err.value)) is not caller_driven


def test_current_needs_the_deck_clock_only_on_the_standalone_route(tmp_path):
Expand Down
84 changes: 84 additions & 0 deletions python/tests/test_deck_native_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,3 +1813,87 @@ def test_mixed_route_currents_get_the_native_verdict(rows, tmp_path):
assert python_accepts == (completed.returncode != 1), completed.stdout + completed.stderr
if python_accepts:
assert "mixed standalone aggregate" in completed.stdout, completed.stdout


# A static check: TMax = 0 and no dtM.
_CHECK = _edit(_HELD, ("0.1 dtM\n10.0 TMax\n", "0.0 TMax\n"))
_CHECK_MIXED = _edit(_MIXED, ("0.1 dtM\n10.0 TMax\n", "0.0 TMax\n"))
_CHECK_FINITE = _edit(
_CHECK, ("chain 0.252 390.0 1.674e9 -1.0 0.0 ", "chain 0.252 390.0 1.674e9 -1.0 1.0e6 ")
)


@pytest.mark.parametrize(
"rows",
[
(),
("uniform 1 0 0 current",),
("airy 2 8 0 waves",),
("0.3 frictionMu",),
("m.txt motionFile",),
("v.txt vesselMotion", "0|0|0 vesselRef"),
],
)
def test_static_check_needs_no_dtm(rows):
DeckFile.from_text(_options(_CHECK, *rows))
DeckFile.from_text(_options(_CHECK_FINITE, *rows))
if "airy 2 8 0 waves" not in rows:
DeckFile.from_text(_options(_CHECK_MIXED, *rows))


def test_static_check_takes_a_negative_zero_tmax_and_no_other():
DeckFile.from_text(_edit(_CHECK, ("0.0 TMax", "-0.0 TMax")))
_rejects(_edit(_CHECK, ("0.0 TMax", "1.0e-9 TMax")), "dynamic run requires both dtM and TMax")
_rejects(_edit(_CHECK, ("0.0 TMax", "10.0 TMax")), "dynamic run requires both dtM and TMax")


def test_static_check_leaves_the_host_clock_rules_alone():
# a host marches a caller-driven deck: its TMax says nothing about the deck-owned kinematics
DeckFile.from_text(_CHECK, caller_driven=True)
_rejects(_options(_CHECK, "airy 2 8 0 waves"), "waves requires dtM", caller_driven=True)
_rejects(_options(_CHECK, "m.txt motionFile"), "motionFile requires dtM", caller_driven=True)


def test_a_lone_dtm_says_how_to_check_the_static_start():
_rejects(_edit(_HELD, ("10.0 TMax\n", "")), "requires both dtM and TMax.*give TMax = 0")


@pytest.mark.skipif(
not _PARITY_DRIVER or not Path(_PARITY_DRIVER).is_file(),
reason="set CABLEDYN_TEST_DRIVER to a built native driver to run the native clock parity",
)
@pytest.mark.parametrize(
("text", "accepted"),
[
(_CHECK, True),
(_options(_CHECK, "uniform 1 0 0 current"), True),
(_options(_CHECK, "airy 2 8 0 waves"), True),
(_options(_CHECK, "0.3 frictionMu"), True),
(_CHECK_FINITE, True),
(_options(_CHECK_FINITE, "uniform 1 0 0 current"), True),
(_CHECK_MIXED, True),
(_options(_CHECK_MIXED, "uniform 0.5 0 0 current"), True),
(_edit(_CHECK, ("0.0 TMax", "-0.0 TMax")), True),
(_edit(_CHECK, ("0.0 TMax", "1.0 TMax")), False),
(_edit(_CHECK_MIXED, ("0.0 TMax", "1.0 TMax")), False),
(_edit(_HELD, ("10.0 TMax\n", "")), False),
],
)
def test_static_check_clock_gets_the_native_verdict(text, accepted, tmp_path):
try:
DeckFile.from_text(text)
python_accepts = True
except DeckFormatError:
python_accepts = False
deck = tmp_path / "check.dat"
deck.write_text(text, encoding="utf-8")
completed = subprocess.run(
[_PARITY_DRIVER, str(deck), str(tmp_path / "check")],
capture_output=True,
text=True,
cwd=tmp_path,
timeout=600,
check=False,
)
assert python_accepts == accepted
assert (completed.returncode == 0) == accepted, completed.stdout + completed.stderr
32 changes: 29 additions & 3 deletions src/CableDyn_DeckDriver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ MODULE CableDyn_DeckDriver
INTEGER, PARAMETER :: MOTION_PAST_TMAX = -1
! appended to the dtM/TMax-required errors of a standalone deck without TMax
CHARACTER(*), PARAMETER :: STATIC_CHECK_HINT = &
'; to check a dynamic deck''s static start only, give dtM with TMax = 0'
'; to check a dynamic deck''s static start only, give TMax = 0'
! The step a standalone TMax = 0 deck without dtM is built with. It marches no step, so no
! result depends on the value (DeckOptions static_check_clock).
REAL(wp), PARAMETER :: STATIC_CHECK_DT = CD_ONE
INTEGER, PARAMETER :: MOTION_POINT_ROWS = 0, MOTION_VESSEL_FILE = 1, MOTION_VESSEL_RAO = 2
! Largest WaterKin WaveKinMod-1 record (TMax/dtWave samples) reduced to Fourier components.
REAL(wp), PARAMETER :: MAX_WAVE_SAMPLES = 1.0e6_wp
Expand Down Expand Up @@ -680,6 +683,9 @@ MODULE CableDyn_DeckDriver
LOGICAL :: has_wtrdpth = .FALSE.
LOGICAL :: has_bathymetry_file = .FALSE.
LOGICAL :: has_dtm = .FALSE., has_tmax = .FALSE.
! A static check without dtM: a standalone deck with TMax = 0 and no dtM runs the TMax = 0
! route on the nominal STATIC_CHECK_DT, so has_dtm is set; the deck itself gives no step.
LOGICAL :: static_check_clock = .FALSE.
LOGICAL :: has_motion_file = .FALSE.
! Source of the prescribed motion when has_motion_file: MOTION_POINT_ROWS (motionFile),
! MOTION_VESSEL_FILE (vesselMotion 6-DOF record) or MOTION_VESSEL_RAO (vesselRAO table
Expand Down Expand Up @@ -846,6 +852,9 @@ MODULE CableDyn_DeckDriver
! CONNECTIONS Pretwist of those ends; has_roll when some row gives one.
LOGICAL :: has_roll = .FALSE.
REAL(wp), ALLOCATABLE :: roll(:, :)
! A static check without dtM (DeckOptions static_check_clock): the grid is the t = 0 row, and
! a later record row is not used, whatever its time step.
LOGICAL :: start_row_only = .FALSE.
END TYPE

TYPE :: DriverProgress
Expand Down Expand Up @@ -1384,7 +1393,7 @@ SUBROUTINE CD_Init_Deck_System(deck_path, system, dtM, gravity, rho_water, ErrSt
RETURN
END IF
END IF
dtM = MERGE(opts%dtM, CD_ZERO, opts%has_dtm)
dtM = MERGE(opts%dtM, CD_ZERO, opts%has_dtm .AND. .NOT. opts%static_check_clock)
gravity = opts%g
rho_water = opts%rhoW
IF (deck_has_finite_ei(types, sections)) THEN
Expand Down Expand Up @@ -8276,6 +8285,8 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi
CALL static_strain_note(agg%init_lines(il)%line_id, agg%init_lines(il)%fair_tension, sections, types, opts, &
strain_note)
IF (LEN_TRIM(strain_note) > 0) CALL append_note_line(agg%init_lines(il)%note, strain_note)
! a run that marches no step has no time step to advise on
IF (static_only) CYCLE
CALL axial_period_note(agg%init_lines(il)%line_id, dt, sections, types, strain_note)
IF (LEN_TRIM(strain_note) > 0) CALL append_note_line(agg%init_lines(il)%note, strain_note)
END DO
Expand Down Expand Up @@ -8741,7 +8752,8 @@ SUBROUTINE CD_Deck_Query_dtM(deck_path, dtM, has_dtm, ErrStat, ErrMsg, env_gravi
host_coupled_objects=.NOT. scan_standalone)
IF (ErrStat /= CD_DECKDRV_OK) RETURN
IF (PRESENT(n_bodies_rods)) n_bodies_rods = SIZE(bodies) + SIZE(rods)
has_dtm = opts%has_dtm
! the deck's own step: the nominal step of a static check is no clock for a caller to march on
has_dtm = opts%has_dtm .AND. .NOT. opts%static_check_clock
IF (has_dtm) dtM = opts%dtM
IF (PRESENT(has_tmax)) has_tmax = opts%has_tmax
IF (PRESENT(tmax)) THEN
Expand Down Expand Up @@ -12934,6 +12946,15 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti
CALL normalize_stock_endpoint_order(points, lines, sections, types)
tors_marched = ext_march
IF (PRESENT(static_run)) tors_marched = ext_march .AND. .NOT. static_run
! A static check marches no step, so it needs no dtM: on the routes no caller marches
! (.NOT. tors_marched: the standalone ones, the mixed aggregate's static_run among them)
! TMax = 0 alone asks for it. A host's clock is its own.
IF ((.NOT. tors_marched) .AND. opts%has_tmax .AND. .NOT. opts%has_dtm .AND. opts%tmax >= CD_ZERO .AND. &
.NOT. opts%tmax > CD_ZERO) THEN
opts%has_dtm = .TRUE.
opts%dtM = STATIC_CHECK_DT
opts%static_check_clock = .TRUE.
END IF
CALL resolve_one_end_torsion(types, bodies, rods, points, lines, sections, opts, tors_marched)
CALL finalize_and_validate(types, bodies, rod_types, rods, points, lines, sections, opts, channels, ext_march, &
static_finite_ok, ErrStat, ErrMsg, channel_lines)
Expand Down Expand Up @@ -34444,6 +34465,7 @@ SUBROUTINE read_motion_file(path, points, opts, motion, ErrStat, ErrMsg, include
IF (PRESENT(include_body_points)) accept_body_points = include_body_points
read_roll = .FALSE.
IF (PRESENT(with_roll)) read_roll = with_roll
motion%start_row_only = opts%static_check_clock
CALL grid_step_count(opts%tmax, opts%dtM, nstep, grid_ok)
IF (.NOT. grid_ok .OR. nstep < 0) THEN
CALL fail(ErrStat, ErrMsg, 'motionFile needs finite dtM > 0 and TMax >= 0 with a representable step count')
Expand Down Expand Up @@ -40280,6 +40302,10 @@ INTEGER FUNCTION motion_grid_index(t, dt, motion, tol) RESULT(it)
TYPE(MotionTable), INTENT(IN) :: motion
INTEGER :: k
it = 0
IF (motion%start_row_only .AND. t > tol) THEN
it = MOTION_PAST_TMAX
RETURN
END IF
IF (.NOT. ABS(t/dt) < MAX_GRID_STEPS) RETURN
k = NINT(t/dt)
IF (k < 0) RETURN
Expand Down
48 changes: 45 additions & 3 deletions tests/test_static_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
1 s run, with the range graph of that row;
* RangeStart after a TMax > 0 is still refused;
* without dtM and TMax the deck stops on its first dynamic input, and the message says to
give dtM with TMax = 0.
give TMax = 0.

and on one deck of each route (EI = 0 and finite-EI lines, the mixed aggregate, the multibody
march, deck current and waves, vesselMotion, vesselRAO and motionFile records):

* TMax = 0 needs no dtM: the deck runs, on records off any step, and writes the output of the
run with dtM byte for byte;
* a positive TMax without dtM is still refused as a dynamic run.

usage: test_static_check.py --exe <cabledyn> --examples <examples dir> --output <dir>
"""
Expand All @@ -29,7 +36,12 @@
from pathlib import Path

FAILURES: list[str] = []
HINT = "to check a dynamic deck's static start only, give dtM with TMax = 0"
HINT = "to check a dynamic deck's static start only, give TMax = 0"
# one deck of each route of a static check
ROUTES = ("dynamic_chain_held", "dynamic_chain_current", "dynamic_chain_waves", "lazy_wave_buoyancy_modules",
"iea15mw_umaine_mixed_cabledyn", "mixed_body_rods_points", "rigid6_buoy", "rod_moored_spar",
"connect_weighted_point", "lazy_wave_vessel_motion", "lazy_wave_vessel_rao",
"lozon_gomex80_power_cable_motion")


def check(ok: bool, message: str) -> None:
Expand Down Expand Up @@ -116,7 +128,28 @@ def case(exe: str, examples: Path, out: Path, deck_name: str, record: str, keywo

p_none = run(exe, work, "none", set_option(set_option(text, "TMax", None), "dtM", None))
check(p_none.returncode != 0 and HINT in p_none.stderr,
f"{deck_name}: without dtM and TMax the message says to give dtM with TMax = 0")
f"{deck_name}: without dtM and TMax the message says to give TMax = 0")


def no_dtm(exe: str, work: Path, deck_name: str) -> None:
"""The deck at TMax = 0 with and without dtM, and at a positive TMax (past any RangeStart) without dtM."""
text = (work / f"{deck_name}.dat").read_text(encoding="utf-8")
zero = set_option(text, "TMax", "0.0")
p_with = run(exe, work, f"{deck_name}_with", zero)
p_none = run(exe, work, f"{deck_name}_none", set_option(zero, "dtM", None))
check(p_with.returncode == 0 and p_none.returncode == 0,
f"{deck_name}: TMax = 0 runs with and without dtM (exit {p_with.returncode}, {p_none.returncode})")
if p_none.returncode != 0:
print(p_none.stderr[-1500:])
return
log = p_none.stdout + p_none.stderr
check("dynamic run" not in log and "dtM =" not in log,
f"{deck_name}: and says nothing of a dynamic run or a time step")
same = (work / f"{deck_name}_with.out").read_bytes() == (work / f"{deck_name}_none.out").read_bytes()
check(same, f"{deck_name}: and writes the same output byte for byte")
p_late = run(exe, work, f"{deck_name}_late", set_option(set_option(text, "TMax", "1000.0"), "dtM", None))
check(p_late.returncode == 1 and "dynamic run requires both dtM and TMax" in p_late.stderr,
f"{deck_name}: a positive TMax without dtM is still refused (exit {p_late.returncode})")


def main() -> int:
Expand All @@ -134,6 +167,15 @@ def main() -> int:
"vesselMotion")
case(args.exe, examples, out, "lozon_gomex80_power_cable_motion", "data/lozon/gomex80_heave_3m_12s_dt005.txt",
"motionFile")
work = out / "no_dtm"
shutil.copytree(examples, work)
# the mixed aggregate on a vessel record
mixed = (work / "iea15mw_umaine_mixed_cabledyn.dat").read_text(encoding="utf-8")
record = "data/vessel/vessel_surge_heave_pitch_12s_dt005.txt vesselMotion"
(work / "mixed_vessel_motion.dat").write_text(
set_option(mixed, "TMax", f"{record}\n0|0|0 vesselRef\n0.0"), encoding="utf-8", newline="\n")
for deck_name in (*ROUTES, "mixed_vessel_motion"):
no_dtm(args.exe, work, deck_name)
print(f"{len(FAILURES)} failure(s)")
return 1 if FAILURES else 0

Expand Down
Loading