diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc4c055..d5d89754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -138,6 +138,69 @@ All notable changes to CableDyn are recorded in this file. The format follows is still unstable on the refined mesh stops as before. Decks that solved before give the same results. `tests/data/lazy_wave_touchdown_torsion_coarse.dat` is the regression case, solved with each route first. +- A finite-EI line over a bathymetry that is not a plane along its chord no longer fails its + statics on a few centimetres of roughness. The catenary seed is laid on the plane fitted to + the bathymetry along the chord, which need not pass through the anchor, and it was rejected + as soon as a node dipped about 1e-6 of the line length below that plane. The + catenary-continuation route then stopped at once, and the mesh-sequenced fallback often ended + on a kinked branch ("unresolved/kinked equilibrium"). In a sweep of a chain on a rough + seabed, 39 of 96 runs on a 25 m survey grid failed this way, at every roughness from 2 cm to + 0.5 m. The seed is now measured against the actual bed: a node deeper below it than its + static penalty penetration (submerged weight over `kBot` × `Diam` × length) is lifted onto + the bed, a shallower one is left to the contact solve, and the continuation, which queries + the full surface, settles the contact. The equilibrium is audited, tested for stability and + checked for kinks as before. A line too long for the fitted plane is also walked into place + from a retreated anchor over such a bathymetry (the moved anchor kept at its height above + the bed under it); as the bed can hold the excess length in its dips, a failed walk there + is not reported as proof that the line is too long, and the mesh-sequenced route still runs. + All 192 finite-EI runs of the sweep now solve, within 1 % of the fairlead force on a mesh + four times finer and 0.8 % of the `EI = 0` line. Decks over a flat seabed or a planar + bathymetry are unchanged, and so are all shipped examples and test decks. A deck over a + non-planar bathymetry that solved before can now take the catenary-continuation route + instead of the mesh-sequenced one, or start from a seed lifted out of a bump: in the sweep + 29 of 153 such runs changed, the fairlead force by at most 0.03 % and the anchor tension by + at most 2.2 % (on 0.5 m roughness, where the anchor tension of the same deck differs by up + to 13 % on a mesh four times finer). The decks `ROUGH_1001` to `ROUGH_1003` of the cable + statics matrix (with mesh twins) are the regression cases. +- A line resting in a trench, a valley or a pit of a gridded bathymetry now has a static + equilibrium. Along every interior grid line the bilinear surface has a crease, and a node on + it took the normal of one adjacent cell, so a node that had to rest in a concave crease was + pushed back across it from either side and had no equilibrium. An `EI = 0` chain whose + frictionless tension falls to zero inside a trench (its excess length resting slack at the + bottom) failed with "no admissible static equilibrium", and so did a grounded run on a + two-dimensional rough seabed, which slides sideways into a valley along a grid line; a + finite-EI line on such a seabed could fail its first dynamic step. Each crease is now + rounded within a band of half-width 5 % of the smaller grid spacing next to its line, by + the cubic fillet `J (d - |u|)^3 / (6 d^2)` of the slope jump `J` across the line, applied as + a tensor product in both directions, so that the surface is twice continuously + differentiable. It moves the surface by at most `|J| d / 6` along one line (1.7 cm for a + slope jump of 0.2 on a 10 m grid; at a crossing of two lines the two roundings add), and a + grid that is exactly planar, and every patch without a crease (one that would move the + surface by less than 1 µm), keep the bilinear surface bit for bit; the rounding errors of a + plane written to two or three decimals are themselves creases and are rounded by a fraction + of a millimetre. In a band the elastic contact force is the gradient of the penalty + potential of the normal penetration (up to the twist of a bilinear cell, which the tangent + leaves out as before), with its Hessian as the tangent, in the statics and the dynamics + alike. Every bathymetry query uses + this surface, the Python `Bathymetry` and its seabed clearance included. A `Fixed` point at + the tabulated depth of a creased grid node rests on the seabed and is placed on the rounded + surface. In the statics campaign the `EI = 0` decks on bathymetry solve 40 of 43 (32 + before; the three left have anchors below the seabed), a 30 m trench now solves at every + depth from 2 m to 30 m (5 of 11 before), with the anchor tension `w` times the trench depth + as for a chain piled at the bottom (the fairlead tension within 0.15 % of the same trench + sampled with a level bottom cell, on a mesh four times finer), and the `EI = 0` rough-seabed + sweep solves 192 of 192 (191). Decks over a flat seabed or a planar bathymetry are unchanged, and so are all shipped + examples and test decks. Decks over creased bathymetries that solved before change: the + fairlead tension by at most 0.04 % (0.4 % for an `EI = 0` run that settles in another valley + of a two-dimensional rough seabed), the anchor tension by up to 8.5 %. The rounding removes + horizontal reactions of the one-sided normals: on a 2 m trench the two ends' horizontal + forces now agree to 0.02 % (1.2 % before), and the anchor tension of a finite-EI line on a + rough two-dimensional seabed is half as far from the one on a mesh four times finer. The + decks `trench_touchdown_pile`, `trench_grounded_run_pile` and `rough2d_seabed` of the `EI = 0` + statics robustness matrix are the regression cases, with an independent nodal force balance + on the rounded surface. When the anchor walk of a finite-EI line over a non-planar bathymetry + reaches a state that is rejected, the failure no longer states that the line is too long for + its span to hang as a catenary, which is proven over a planar seabed only. ## [0.1.1] - 2026-10-09 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d28801b..57752120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2054,6 +2054,23 @@ add_test(NAME driver_lazy_wave_planar_refined_quiet -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_driver_output.cmake) set_tests_properties(driver_lazy_wave_planar_refined_quiet PROPERTIES LABELS "fortran;driver;integration;static") +# A Fixed anchor in a crease of a bathymetry grid: at the tabulated depth it rests on the seabed +# and is placed on the rounded surface; 1 cm below the rounded surface, between it and the grid +# surface but within the seabed tolerance of neither, it is rejected. +add_test(NAME driver_anchor_crease_tabulated + COMMAND ${CMAKE_COMMAND} -DDRIVER=$ -DEXPECT_RC=0 + "-DARGS=${CMAKE_CURRENT_SOURCE_DIR}/tests/data/anchor_crease_tabulated.dat|tabulated" + "-DMUST_NOT=lies below the seabed" + -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/driver_anchor_crease_tabulated + -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_driver_output.cmake) +set_tests_properties(driver_anchor_crease_tabulated PROPERTIES LABELS "fortran;driver;static;seabed") +add_test(NAME driver_anchor_crease_between + COMMAND ${CMAKE_COMMAND} -DDRIVER=$ -DEXPECT_RC=1 + "-DARGS=${CMAKE_CURRENT_SOURCE_DIR}/tests/data/anchor_crease_between.dat|between" + "-DMUST_MATCH=POINT 2 .Fixed. lies below the seabed" + -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/driver_anchor_crease_between + -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_driver_output.cmake) +set_tests_properties(driver_anchor_crease_between PROPERTIES LABELS "fortran;driver;static;seabed") # The same pair with the buoyant stretch built from discrete ATTACHMENTS: the hand-off check runs # on the discrete equilibrium the attachment polish gives. add_test(NAME driver_lazy_wave_planar_coarse_att_note diff --git a/doc/file_formats.rst b/doc/file_formats.rst index 5958c113..4915efae 100644 --- a/doc/file_formats.rst +++ b/doc/file_formats.rst @@ -343,7 +343,12 @@ Validation ``16·ε`` relative. * Rows may come in any order. Grid spacing does not have to be uniform. -The seabed is interpolated bilinearly within each grid cell. On a slope the +The seabed is interpolated bilinearly within each grid cell, and the creases of that +surface along the interior grid lines are rounded within a band of half-width 5 % of +the smaller grid spacing next to each line (a cubic fillet that makes the surface +twice continuously differentiable; see :doc:`theory`). The rounding moves the surface +by at most a sixth of the slope jump across the line times the band half-width, and +leaves a planar grid and every patch without a crease exactly bilinear. On a slope the frictionless contact force acts along the surface normal, and its stiffness includes the slope of that surface. Outside the grid, depth is clamped to the value at the nearest edge. diff --git a/doc/python_postprocessing.rst b/doc/python_postprocessing.rst index b74ff64f..c9bd0a82 100644 --- a/doc/python_postprocessing.rst +++ b/doc/python_postprocessing.rst @@ -465,7 +465,8 @@ Clearance :func:`cabledyn.seabed_clearance` returns the vertical clearance ``z - z_floor(x, y)`` of every node at every sample, less an optional ``radius``, above a flat seabed (pass its elevation, ``-WtrDpth``) or a :class:`~cabledyn.Bathymetry` read with :func:`cabledyn.read_bathymetry` from -the deck's ``x y depth`` file (bilinear, clamped at the grid edges, as in the solver). It +the deck's ``x y depth`` file (bilinear with its creases rounded, clamped at the grid edges, as +in the solver). It reproduces the solver's ``Clearance`` range graph. The :class:`~cabledyn.SeabedClearance` reports the minimum with its time, node, and arc length, a profile at any time, and a range graph. diff --git a/doc/theory.rst b/doc/theory.rst index e19b426e..f8dee70b 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -790,12 +790,59 @@ A vertical axis (no horizontal projection) takes :math:`\mu_n`. An equal pair runs the isotropic law unchanged. A structured bathymetry grid gives :math:`z_\text{floor}(x, y)` by bilinear interpolation, -clamped to the nearest edge outside the grid. On a sloped patch the elastic contact is +clamped to the nearest edge outside the grid, with the creases of that surface rounded. +Along every interior grid line the bilinear surface has a crease: its slope across the line +jumps by :math:`J` (the second difference of the tabulated depths). A node that must rest in a +concave crease, a valley along a grid line or the bottom of a pit, takes the normal of one cell +or the other and has no static equilibrium there; a slack chain piled at the bottom of a +trench and a frictionless grounded run slid sideways into a valley both end there. Each +crease is therefore rounded within a band of half-width :math:`\delta_k`, 5 % of the smaller +grid spacing next to line :math:`k`. Along one axis the interpolant :math:`g(x)` becomes + +.. math:: + + \tilde g(x) = g(x) + J_k\,h(x - x_k), \qquad + h(u) = \frac{(\delta_k - |u|)^3}{6\,\delta_k^2} \quad (|u| < \delta_k), \qquad h = 0 \text{ elsewhere}. + +:math:`h'(0^+) - h'(0^-) = -1` cancels the slope jump, and :math:`h`, :math:`h'` and :math:`h''` +vanish at :math:`|u| = \delta_k`, so :math:`\tilde g` is :math:`C^2`. Its curvature +:math:`J_k (\delta_k - |u|)/\delta_k^2` has the sign of the jump, so a valley stays convex and +gains no spurious pit. The surface is the tensor product of the two rounded interpolants, +:math:`z_\text{floor} = f + h_x J_x(y) + h_y \big(J_y(x) + h_x M\big)`, with :math:`f` the +bilinear surface, :math:`J_x(y)` the jumps of the grid rows across the :math:`x` line +interpolated linearly along it, :math:`J_y(x)` likewise, and :math:`M` the mixed second +difference of the grid where two lines cross. Its height, gradient and curvature are +continuous everywhere within the grid. Outside the bands it is the bilinear surface, and +inside the band of one line it moves by at most :math:`|J|\,\delta/6`; where two bands +cross the two roundings and the mixed term add. A 0.2 slope jump on a 10 m grid moves +it by 1.7 cm, within the static penetration of a chain (``w/(kBot Diam)``, 11 cm for a +120 mm chain at ``kBot = 1e5``). A crease that would move the surface by less than 1 µm is not +rounded: an exactly planar grid and every patch without a crease keep the bilinear surface +exactly. A plane written to two or three decimals has creases of the size of its rounding, +which are rounded by a fraction of a millimetre. The grid edges are not rounded, and outside the grid the +surface stays level. Every height and gradient query uses this one surface: the contact of +the ``EI = 0`` and the Hermite path, statics and dynamics, the friction frame and capacity, +the seabed clearance and touchdown outputs, and the Python post-processing +(``cabledyn.Bathymetry``). The friction capacity uses the normal force :math:`f_n^{(k)}(g/s)`; +inside a band it leaves out the curvature term of the contact force below, of the order of +the penetration times the curvature. A ``Fixed`` point placed at the +tabulated depth of a creased grid node lies up to :math:`|J|\,\delta/6` below the rounded +surface; it rests on the seabed and is placed on the rounded surface. + +On a sloped patch the elastic contact is frictionless and normal to the surface, on the ``EI = 0`` and the Hermite path alike: with :math:`s = \sqrt{1 + z_{,x}^2 + z_{,y}^2}` the force is :math:`f_n^{(k)}(g/s)\,\mathbf{n}`, :math:`\mathbf{n} = (-z_{,x}, -z_{,y}, 1)/s`, and its tangent -:math:`f_n^{(k)\prime}\,\mathbf{n}\mathbf{n}^{\mathsf T}` (the grid curvature is not -differentiated); on a level floor this is exactly the vertical law above. Its damping acts on +:math:`f_n^{(k)\prime}\,\mathbf{n}\mathbf{n}^{\mathsf T}` (the twist of a bilinear cell is not +differentiated); on a level floor this is exactly the vertical law above. Inside a crease band, +where the surface curves, the elastic force is the gradient of the penalty potential +:math:`E(g/s)` of the normal penetration, :math:`-f_n^{(k)}\,\partial(g/s)/\partial\mathbf{q}`: +the normal force plus :math:`f_n^{(k)}\,g\,\nabla s/s^2`, a term of the order of the +penetration times the curvature, and its tangent is the Hessian of that potential (third +derivatives of the surface left out). The static energy minimisation then agrees with the +force up to the twist of the bilinear cell, which is left out of the tangent as on a sloped +patch, and a node held in a rounded valley by its curvature has a consistent stiffness. Its +damping acts on the velocity along :math:`\mathbf{n}`, and a friction capacity is :math:`\mu` times its magnitude. The static solve and the dynamics use the same law, so a grounded run on a slope rests at a static equilibrium of the march; its tension changes along the slope by the weight @@ -882,7 +929,14 @@ mesh-sequenced route described below first and this route as its fallback): declared seabed plane (flat ``WtrDpth``, or the least-squares plane of a structured bathymetry along the chord) or hung in mid-water when there is no seabed. The solve runs in the vertical plane of the chord, translated to the anchor, so a translated or rotated deck gives the same - numbers to round-off. When the only catenary through the endpoints passes below a planar + numbers to round-off. Over a bathymetry that is not a plane along the chord (a surveyed + seabed with roughness, bumps or dips), the seed laid on the fitted plane meets the actual bed + wherever the bed rises above that plane: every seed node deeper below the actual bed than its + static penalty penetration (nodal submerged weight over the nodal contact stiffness + ``kBot`` :math:`\times` ``Diam`` :math:`\times` length) is lifted onto the bed, and the + continuation below, which queries the full surface, settles the contact. Such a seed is + never rejected for its penetration; the equilibrium it leads to is audited like any other. + When the only catenary through the endpoints passes below a planar seabed (flat, or a structured bathymetry whose profile under the chord is straight), the line is too long for its span to hang as a catenary. Without buoyant sections the line is a convex curve between the chord and the seabed, so it cannot be longer than the path down to @@ -899,7 +953,11 @@ mesh-sequenced route described below first and this route as its fallback): short of the anchor (the bow snaps through, or the line would have to lie on itself), or the bathymetry does not continue its plane behind the anchor, the run stops and names the geometry: no admissible planar equilibrium clear of the seabed was found, the line being too - long for its span to hang as a catenary, with where the walk stopped. A walked state that + long for its span to hang as a catenary, with where the walk stopped. A line too long for + the plane fitted to a non-planar bathymetry is walked the same way, the moved anchor kept + at its height above the bed under it and the seed draped as above; as such a bed can hold + the excess length in its dips, a failed walk there proves nothing, and the mesh-sequenced + route runs before the run stops. A walked state that the audit below rejects (self-contact, instability) hands over to the mesh-sequenced route, and is named the same way when that finds none; with ``tensile_safety True`` a walked state in compression is rejected by name (a bow held by bending is compressed). diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index fbfe63b2..9fd5209f 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -453,6 +453,17 @@ but a few geometries are genuinely hard: exist: the surplus must fold or form another contact region. CableDyn rejects a resulting element-localized wad through the curvature safety check. This is not fixed by relaxing Newton tolerances; revise the physical support/contact model or geometry. +- **A line resting in a trench, valley or pit of a gridded bathymetry.** A frictionless grounded + run's tension :math:`T = T_0 + w\,(z - z_0)` falls with depth. In a trench deep enough it reaches + zero, and an ``EI = 0`` line then rests slack at the bottom with its excess length piled there; + the anchor tension of the run rising from the pile is :math:`w` times the depth of the trench + below the anchor, whatever the line length. On a two-dimensional rough bed the run slides + sideways into the valleys. Both rest in the creases of the bilinear grid, which the solver + rounds over 5 % of the grid spacing (see :doc:`theory`) so that a node has an equilibrium + there. A pile appears in the static profile as coincident nodes with zero tension and large + turning angles; a finite-EI line carries compression there instead, which the driver notes. + With 5 m elements on steep trench walls the end tensions of a pile still change by about 1 % + on a mesh four times finer: refine the line over the trench when they matter. - **A twisted finite-EI line.** ``torsion continuation stalled at Phi = ... (target ...)`` reports the imposed twist the static ramp reached: beyond it the line has no nearby static equilibrium on the path, typically because a loop is forming (hockling), which needs a diff --git a/python/cabledyn/clearance.py b/python/cabledyn/clearance.py index f587c545..e4f6d01e 100644 --- a/python/cabledyn/clearance.py +++ b/python/cabledyn/clearance.py @@ -63,6 +63,11 @@ # (sample, segment, segment) entries, bounding the temporary memory. _CHUNK = 250_000 _PLAIN_NUMBER = re.compile(r"[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?") +# Crease rounding of the bathymetry surface, as in the solver (CableDyn_Bathymetry): band +# half-width as a fraction of the smaller grid spacing next to a line, and the smallest +# surface change [m] a crease must make to be rounded. +_CREASE_FRACTION = 0.05 +_CREASE_MIN_HEIGHT = 1.0e-6 def _readonly(values: npt.ArrayLike, dtype: Any = np.float64) -> npt.NDArray[Any]: @@ -83,8 +88,12 @@ class Bathymetry: """A structured seabed: water depth on a rectangular ``x``-``y`` grid. The seabed elevation is ``z_floor = -depth``. Between grid points it is - bilinear in each cell; outside the grid it takes the value at the nearest - grid edge, as in the solver. + bilinear in each cell, with the creases of that surface along the interior + grid lines rounded within a narrow band (the C2 fillet of the solver: a + crease with slope jump ``J`` is moved by ``J (delta - |u|)^3 / (6 delta^2)`` at + distance ``|u| < delta`` from its line, ``delta`` five per cent of the smaller + spacing next to it); outside the grid it takes the value at the nearest grid + edge, as in the solver. Attributes ---------- @@ -153,12 +162,68 @@ def depth_at(self, x: npt.ArrayLike, y: npt.ArrayLike) -> npt.NDArray[Any]: ix, tx = _cell(self.x, qx) iy, ty = _cell(self.y, qy) d = self.depth - return np.asarray( + bilinear = ( (1.0 - tx) * (1.0 - ty) * d[ix, iy] + tx * (1.0 - ty) * d[ix + 1, iy] + (1.0 - tx) * ty * d[ix, iy + 1] + tx * ty * d[ix + 1, iy + 1] ) + return np.asarray(bilinear - self._crease_rounding(qx, qy, ix, iy, tx, ty)) + + def _crease_rounding( + self, + qx: npt.NDArray[Any], + qy: npt.NDArray[Any], + ix: npt.NDArray[Any], + iy: npt.NDArray[Any], + tx: npt.NDArray[Any], + ty: npt.NDArray[Any], + ) -> npt.NDArray[Any]: + """Rise of the rounded surface over the bilinear one (zero outside the bands). + + ``hx Jx(y) + hy (Jy(x) + hx M)``: ``J`` the slope jumps of the grid rows + (columns) across the line, interpolated linearly along it, ``M`` the mixed + second difference at a crossing of two lines, ``h`` the fillet. + """ + kx, hx = _crease_band(self.x, ix, qx) + ky, hy = _crease_band(self.y, iy, qy) + z = -self.depth + rise = np.zeros(np.shape(qx)) + on_x = kx >= 0 + on_y = ky >= 0 + if not (np.any(on_x) or np.any(on_y)): + return rise + kxs = np.clip(kx, 1, self.x.size - 2) + kys = np.clip(ky, 1, self.y.size - 2) + dlx = _CREASE_FRACTION * np.minimum( + self.x[kxs] - self.x[kxs - 1], self.x[kxs + 1] - self.x[kxs] + ) + dly = _CREASE_FRACTION * np.minimum( + self.y[kys] - self.y[kys - 1], self.y[kys + 1] - self.y[kys] + ) + + def jump_x(j: npt.NDArray[Any]) -> npt.NDArray[Any]: + jump = (z[kxs + 1, j] - z[kxs, j]) / (self.x[kxs + 1] - self.x[kxs]) - ( + z[kxs, j] - z[kxs - 1, j] + ) / (self.x[kxs] - self.x[kxs - 1]) + return np.where(np.abs(jump) * dlx / 6.0 > _CREASE_MIN_HEIGHT, jump, 0.0) + + def jump_y(i: npt.NDArray[Any]) -> npt.NDArray[Any]: + jump = (z[i, kys + 1] - z[i, kys]) / (self.y[kys + 1] - self.y[kys]) - ( + z[i, kys] - z[i, kys - 1] + ) / (self.y[kys] - self.y[kys - 1]) + return np.where(np.abs(jump) * dly / 6.0 > _CREASE_MIN_HEIGHT, jump, 0.0) + + jx = (1.0 - ty) * jump_x(iy) + ty * jump_x(iy + 1) + jy = (1.0 - tx) * jump_y(ix) + tx * jump_y(ix + 1) + mxy = (jump_x(kys + 1) - jump_x(kys)) / (self.y[kys + 1] - self.y[kys]) - ( + jump_x(kys) - jump_x(kys - 1) + ) / (self.y[kys] - self.y[kys - 1]) + mxy = np.where( + on_x & on_y & (np.abs(mxy) * dlx * dly / 36.0 > _CREASE_MIN_HEIGHT), mxy, 0.0 + ) + rise = np.where(on_x, hx * jx, 0.0) + np.where(on_y, hy * (jy + hx * mxy), 0.0) + return np.asarray(rise) def floor(self, x: npt.ArrayLike, y: npt.ArrayLike) -> npt.NDArray[Any]: """Return the seabed elevation ``z_floor = -depth`` at points ``(x, y)``. @@ -190,6 +255,31 @@ def _cell( return index, np.clip(fraction, 0.0, 1.0) +def _crease_band( + axis: npt.NDArray[Any], index: npt.NDArray[Any], query: npt.NDArray[Any] +) -> tuple[npt.NDArray[Any], npt.NDArray[Any]]: + """Interior grid line whose crease band holds each query (-1: none) and the fillet there. + + The fillet is ``(delta - |u|)^3 / (6 delta^2)``, ``u`` the distance from the line and + ``delta`` the band half-width; a query outside the grid lies in no band. + """ + n = axis.size + inside = (query >= axis[0]) & (query <= axis[-1]) + line = np.full(np.shape(query), -1) + fillet = np.zeros(np.shape(query)) + for k in (index, index + 1): + interior = inside & (k >= 1) & (k <= n - 2) & (line < 0) + ks = np.clip(k, 1, max(n - 2, 1)) + if n < 3: + continue + delta = _CREASE_FRACTION * np.minimum(axis[ks] - axis[ks - 1], axis[ks + 1] - axis[ks]) + u = np.abs(query - axis[ks]) + hit = interior & (u < delta) + line = np.where(hit, k, line) + fillet = np.where(hit, (delta - u) ** 3 / (6.0 * delta * delta), fillet) + return line, fillet + + def _strip_comment(text: str) -> str: """Strip ``#``/``!`` comments and a ``--`` comment that starts a token.""" cut = len(text) diff --git a/python/tests/test_clearance.py b/python/tests/test_clearance.py index 860c6f43..d237fc14 100644 --- a/python/tests/test_clearance.py +++ b/python/tests/test_clearance.py @@ -132,6 +132,43 @@ def test_bathymetry_is_bilinear_and_clamped_outside_the_grid(): bathymetry.floor(math.nan, 0.0) +def test_bathymetry_rounds_the_creases_of_the_grid_as_the_solver(): + # a crease of slope jump J = -1 at x = 10 (level, then deepening 1 m per metre); the band + # half-width is 5 % of the smaller spacing, 0.5 m, and the fillet J (delta - |u|)^3/(6 delta^2) + crease = Bathymetry( + [0.0, 10.0, 20.0], [0.0, 1.0], [[100.0, 100.0], [100.0, 100.0], [110.0, 110.0]] + ) + np.testing.assert_allclose( + crease.depth_at([10.0, 10.2, 9.6, 9.5, 5.0, 10.5], 0.3), + [100.0 + 0.5 / 6.0, 100.218, 100.0 + 0.001 / 1.5, 100.0, 100.0, 100.5], + rtol=0.0, + atol=1e-12, + ) + # continuous height and slope across the line and at the band edges + for x0 in (10.0, 9.5, 10.5): + a, b = crease.depth_at([x0 - 1e-7, x0 + 1e-7], 0.5) + assert abs(a - b) < 2.1e-7 # the slope there is at most 1 + slope = crease.depth_at([x0 - 2e-4, x0 - 1e-4, x0 + 1e-4, x0 + 2e-4], 0.5) + assert abs((slope[1] - slope[0]) - (slope[3] - slope[2])) < 1e-6 + # a planar grid (here written to six decimals) is not rounded: bit-identical bilinear + x = np.array([0.0, 10.0, 25.0, 30.0]) + y = np.array([-5.0, 8.0, 20.0]) + plane = np.round(388.949782 + 0.0732 * x[:, None] - 0.0417 * y[None, :], 6) + planar = Bathymetry(x, y, plane) + qx, qy = np.meshgrid(np.linspace(-1.0, 31.0, 97), np.linspace(-6.0, 21.0, 55)) + ix = np.clip(np.searchsorted(x, qx, side="right") - 1, 0, x.size - 2) + iy = np.clip(np.searchsorted(y, qy, side="right") - 1, 0, y.size - 2) + tx = np.clip((qx - x[ix]) / (x[ix + 1] - x[ix]), 0.0, 1.0) + ty = np.clip((qy - y[iy]) / (y[iy + 1] - y[iy]), 0.0, 1.0) + bilinear = ( + (1.0 - tx) * (1.0 - ty) * plane[ix, iy] + + tx * (1.0 - ty) * plane[ix + 1, iy] + + (1.0 - tx) * ty * plane[ix, iy + 1] + + tx * ty * plane[ix + 1, iy + 1] + ) + assert np.array_equal(planar.depth_at(qx, qy), bilinear) + + @pytest.mark.parametrize( ("x", "y", "depth", "message"), [ diff --git a/src/CableDyn_Bathymetry.f90 b/src/CableDyn_Bathymetry.f90 index 1c8bc912..6c5db76a 100644 --- a/src/CableDyn_Bathymetry.f90 +++ b/src/CableDyn_Bathymetry.f90 @@ -6,9 +6,15 @@ MODULE CableDyn_Bathymetry !! water-depth queries. The grid stores positive water depth below still-water !! level at monotone x/y coordinates; the seabed elevation is z_floor = -depth. !! Queries clamp to the nearest grid edge outside the supplied domain and use - !! bilinear interpolation inside each cell. Contact is a frictionless penalty force - !! along the local upward surface normal at the normal penetration; its tangent holds - !! the surface gradient fixed over the node (the bilinear curvature is omitted). + !! bilinear interpolation inside each cell, with the creases of that surface along the + !! interior grid lines rounded to C2 within a narrow band (crease_blend): a node resting + !! in a valley or pit of the grid then meets a continuous normal, and has an + !! equilibrium there. Outside the bands, and wherever the grid has no crease, the + !! surface is exactly bilinear. Contact is a frictionless penalty force along the + !! local upward surface normal at the normal penetration; its tangent holds the + !! surface gradient fixed over the node (the twist of a bilinear cell is omitted). In a + !! crease band the force is the gradient of the penalty potential of the normal + !! penetration and its tangent that potential's Hessian (CD_Seabed_Normal_Contact). USE CableDyn_Precision, ONLY: wp, CD_ZERO, CD_All_Finite, CD_Is_Finite USE CableDyn_SeabedContact, ONLY: CD_Seabed_Normal_Contact IMPLICIT NONE @@ -21,8 +27,17 @@ MODULE CableDyn_Bathymetry PUBLIC :: CD_Bathymetry_Depth PUBLIC :: CD_Bathymetry_Floor PUBLIC :: CD_Bathymetry_Floor_Gradient + PUBLIC :: CD_Bathymetry_Grid_Floor + PUBLIC :: CD_Bathymetry_Rotate_Curvature PUBLIC :: CD_Bathymetry_Seabed_Load INTEGER, PARAMETER, PUBLIC :: CD_BATHY_OK = 0, CD_BATHY_BADINPUT = 1, CD_BATHY_ALLOCFAIL = 2 + ! Crease rounding (see crease_blend): band half-width as a fraction of the smaller grid + ! spacing next to the line, and the smallest surface change [m] a crease must make to be + ! rounded (below it the grid is treated as uncreased there: an exactly planar grid stays + ! exactly bilinear; the rounding errors of a plane written to two or three decimals are + ! creases above it and are rounded by a fraction of a millimetre). + REAL(wp), PARAMETER, PUBLIC :: CD_BATHY_CREASE_FRACTION = 0.05_wp + REAL(wp), PARAMETER, PUBLIC :: CD_BATHY_CREASE_MIN_HEIGHT = 1.0e-6_wp TYPE :: CD_BathymetryType INTEGER :: nx = 0, ny = 0 @@ -156,24 +171,58 @@ SUBROUTINE CD_Bathymetry_Floor(bathy, xq, yq, z_floor, ErrStat, ErrMsg) CALL floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) END SUBROUTINE CD_Bathymetry_Floor - SUBROUTINE CD_Bathymetry_Floor_Gradient(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) + SUBROUTINE CD_Bathymetry_Grid_Floor(bathy, xq, yq, z_floor, ErrStat, ErrMsg) + !! Seabed elevation of the grid itself at a horizontal location: the bilinear + !! interpolation of the tabulated depths, without the crease rounding of + !! CD_Bathymetry_Floor. For checking an input point against the surveyed depths only + !! (a point at the tabulated depth of a creased grid node lies on this surface, within + !! a fraction of the band width of the rounded one); every contact, gradient and output + !! query uses CD_Bathymetry_Floor. + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + REAL(wp), INTENT(IN) :: xq, yq + REAL(wp), INTENT(OUT) :: z_floor + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp) :: dfdx, dfdy + CALL floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, rounded=.FALSE.) + END SUBROUTINE CD_Bathymetry_Grid_Floor + + SUBROUTINE CD_Bathymetry_Floor_Gradient(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, crease_curvature) !! Return seabed elevation and horizontal gradients dz_floor/dx, dz_floor/dy. + !! crease_curvature (optional): the second derivatives (z_xx, z_xy, z_yy) of the crease + !! rounding at the point (zero outside the crease bands), for a contact tangent that + !! follows the rounded surface; the twist of the bilinear cells is not included. TYPE(CD_BathymetryType), INTENT(IN) :: bathy REAL(wp), INTENT(IN) :: xq, yq REAL(wp), INTENT(OUT) :: z_floor, dfdx, dfdy INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: crease_curvature(3) - CALL floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) + CALL floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, curvature=crease_curvature) END SUBROUTINE CD_Bathymetry_Floor_Gradient + PURE FUNCTION CD_Bathymetry_Rotate_Curvature(curv_g, cs) RESULT(curv_l) + !! Surface curvature (z_xx, z_xy, z_yy) of the global frame expressed in a frame turned + !! by the angle of cs = (cos, sin) about z (global x = cos xl - sin yl, y = sin xl + + !! cos yl): H_l = R^T H_g R, as the gradient turns to g_l = R^T g_g. + REAL(wp), INTENT(IN) :: curv_g(3), cs(2) + REAL(wp) :: curv_l(3) + REAL(wp) :: hg(2, 2), r(2, 2), hl(2, 2) + hg = RESHAPE([curv_g(1), curv_g(2), curv_g(2), curv_g(3)], [2, 2]) + r = RESHAPE([cs(1), cs(2), -cs(2), cs(1)], [2, 2]) + hl = MATMUL(TRANSPOSE(r), MATMUL(hg, r)) + curv_l = [hl(1, 1), 0.5_wp*(hl(1, 2) + hl(2, 1)), hl(2, 2)] + END FUNCTION CD_Bathymetry_Rotate_Curvature + SUBROUTINE CD_Bathymetry_Seabed_Load(bathy, nodes, k_n, f, k_resid, ErrStat, ErrMsg) !! Variable-elevation penalty contact against the bathymetry surface. !! For node i, g_i = z_floor(x_i,y_i) - z_i is the vertical penetration. The contact !! is frictionless: the force acts along the local upward surface normal with the !! shared C1 touchdown law evaluated at the normal penetration (CD_Seabed_Normal_Contact; !! exactly the vertical law on a level patch). The residual tangent is the node's - !! -d(force)/dq block, F' n n^T. + !! -d(force)/dq block, F' n n^T; in a crease band the force and tangent follow the + !! rounded surface (the gradient and Hessian of the penalty potential there). TYPE(CD_BathymetryType), INTENT(IN) :: bathy REAL(wp), INTENT(IN) :: nodes(:, :) REAL(wp), INTENT(IN) :: k_n(:) @@ -183,7 +232,7 @@ SUBROUTINE CD_Bathymetry_Seabed_Load(bathy, nodes, k_n, f, k_resid, ErrStat, Err CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER :: n_nodes, i, ix, iz - REAL(wp) :: z_floor, dfdx, dfdy, gap, fvec(3), jac(3, 3) + REAL(wp) :: z_floor, dfdx, dfdy, gap, fvec(3), jac(3, 3), curv(3) f = CD_ZERO k_resid = CD_ZERO @@ -216,23 +265,27 @@ SUBROUTINE CD_Bathymetry_Seabed_Load(bathy, nodes, k_n, f, k_resid, ErrStat, Err END IF DO i = 1, n_nodes - CALL floor_eval(bathy, nodes(1, i), nodes(2, i), z_floor, dfdx, dfdy, ErrStat, ErrMsg) + CALL floor_eval(bathy, nodes(1, i), nodes(2, i), z_floor, dfdx, dfdy, ErrStat, ErrMsg, curvature=curv) IF (ErrStat /= CD_BATHY_OK) RETURN gap = z_floor - nodes(3, i) ix = 3*i - 2 iz = ix + 2 - CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, k_n(i), fvec, jac) + CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, k_n(i), fvec, jac, curvature=curv) f(ix:iz) = fvec k_resid(ix:iz, ix:iz) = jac END DO END SUBROUTINE CD_Bathymetry_Seabed_Load - SUBROUTINE floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) + SUBROUTINE floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, rounded, curvature) + !! The seabed surface and its gradient: bilinear in each cell, its creases rounded + !! (crease_blend) unless rounded is .FALSE. (CD_Bathymetry_Grid_Floor). TYPE(CD_BathymetryType), INTENT(IN) :: bathy REAL(wp), INTENT(IN) :: xq, yq REAL(wp), INTENT(OUT) :: z_floor, dfdx, dfdy INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: rounded + REAL(wp), INTENT(OUT), OPTIONAL :: curvature(3) INTEGER :: ix, iy REAL(wp) :: tx, ty @@ -242,6 +295,7 @@ SUBROUTINE floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) z_floor = CD_ZERO dfdx = CD_ZERO dfdy = CD_ZERO + IF (PRESENT(curvature)) curvature = CD_ZERO ErrStat = CD_BATHY_OK ErrMsg = '' IF (.NOT. CD_Bathymetry_Is_Initialized(bathy)) THEN @@ -266,8 +320,199 @@ SUBROUTINE floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg) (1.0_wp - tx)*ty*f01 + tx*ty*f11 IF (.NOT. clamp_x) dfdx = ((1.0_wp - ty)*(f10 - f00) + ty*(f11 - f01))/dx IF (.NOT. clamp_y) dfdy = ((1.0_wp - tx)*(f01 - f00) + tx*(f11 - f10))/dy + IF (PRESENT(rounded)) THEN + IF (.NOT. rounded) RETURN + END IF + IF (bathy%nx > 2 .OR. bathy%ny > 2) & + CALL crease_blend(bathy, xq, yq, ix, iy, tx, ty, clamp_x, clamp_y, z_floor, dfdx, dfdy, curvature) END SUBROUTINE floor_eval + SUBROUTINE crease_blend(bathy, xq, yq, ix, iy, tx, ty, clamp_x, clamp_y, z_floor, dfdx, dfdy, curvature) + !! Rounding of the creases of the bilinear surface (see the module header). The + !! surface is the tensor product of the two axes' piecewise-linear interpolants; each + !! interpolant has a slope jump J_k at an interior grid line k, which is rounded within + !! the band |u| < delta_k (u the distance from the line, delta_k = + !! CD_BATHY_CREASE_FRACTION times the smaller adjacent spacing) by adding J_k h(u), with + !! h(u) = (delta_k - |u|)^3/(6 delta_k^2): h'(0+) - h'(0-) = -1 cancels the slope jump, + !! and h, h' and h'' vanish at |u| = delta_k, so the rounded interpolant is C2 (its + !! curvature J (delta - |u|)/delta^2 has the sign of the jump: a valley stays convex). + !! Applied in both directions, the surface is f + h_x J_x(y) + h_y (J_y(x) + h_x M), + !! with J_x(y) the jumps of the grid rows across the x line interpolated linearly in y, + !! J_y(x) likewise, and M the mixed second difference of the grid at the crossing of + !! the two lines (the jump of J_x across the y line). It is the tensor product of C2 + !! interpolants, so its height, gradient and curvature are continuous everywhere + !! within the grid; it equals the bilinear surface outside the bands and moves it by + !! at most |J| delta/6. A jump that would + !! move the surface by less than CD_BATHY_CREASE_MIN_HEIGHT (a plane rounded to the + !! digits of its file) counts as none, so a planar grid and every patch without a + !! crease are exactly bilinear. The grid edges are not rounded (outside the grid the + !! surface is held level). + !! curvature (optional): (z_xx, z_xy, z_yy) of the rounding terms; left unchanged + !! (zero) outside the bands. + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + REAL(wp), INTENT(IN) :: xq, yq, tx, ty + INTEGER, INTENT(IN) :: ix, iy + LOGICAL, INTENT(IN) :: clamp_x, clamp_y + REAL(wp), INTENT(INOUT) :: z_floor, dfdx, dfdy + REAL(wp), INTENT(INOUT), OPTIONAL :: curvature(3) + INTEGER :: kx, ky + REAL(wp) :: u, v, dlx, dly, hx, hxp, hxpp, hy, hyp, hypp, jx0, jx1, jy0, jy1, jxm, jxc, jxn, mxy + REAL(wp) :: jx, jxp, jy, jyp, c + LOGICAL :: on_x, on_y, on_m + + kx = 0 + ky = 0 + u = CD_ZERO + v = CD_ZERO + dlx = CD_ZERO + dly = CD_ZERO + IF (.NOT. clamp_x) CALL crease_band(bathy%x, ix, xq, kx, u, dlx) + IF (.NOT. clamp_y) CALL crease_band(bathy%y, iy, yq, ky, v, dly) + IF (kx == 0 .AND. ky == 0) RETURN + hx = CD_ZERO + hxp = CD_ZERO + hxpp = CD_ZERO + jx0 = CD_ZERO + jx1 = CD_ZERO + on_x = .FALSE. + on_m = .FALSE. + IF (kx > 0) THEN + CALL crease_fillet(u, dlx, kx == ix, hx, hxp, hxpp) + CALL x_jump(bathy, kx, iy, dlx, jx0, on_x) + CALL x_jump(bathy, kx, iy + 1, dlx, jx1, on_m) + on_x = on_x .OR. on_m + END IF + hy = CD_ZERO + hyp = CD_ZERO + hypp = CD_ZERO + jy0 = CD_ZERO + jy1 = CD_ZERO + on_y = .FALSE. + mxy = CD_ZERO + on_m = .FALSE. + IF (ky > 0) THEN + CALL crease_fillet(v, dly, ky == iy, hy, hyp, hypp) + CALL y_jump(bathy, ix, ky, dly, jy0, on_y) + CALL y_jump(bathy, ix + 1, ky, dly, jy1, on_m) + on_y = on_y .OR. on_m + on_m = .FALSE. + IF (kx > 0) THEN + ! the jump of J_x across the y line: its rows ky-1, ky and ky+1 + CALL x_jump(bathy, kx, ky - 1, dlx, jxm, on_m) + CALL x_jump(bathy, kx, ky, dlx, jxc, on_m) + CALL x_jump(bathy, kx, ky + 1, dlx, jxn, on_m) + mxy = (jxn - jxc)/(bathy%y(ky + 1) - bathy%y(ky)) - (jxc - jxm)/(bathy%y(ky) - bathy%y(ky - 1)) + on_m = ABS(mxy)*dlx*dly/36.0_wp > CD_BATHY_CREASE_MIN_HEIGHT + IF (.NOT. on_m) mxy = CD_ZERO + END IF + END IF + IF (on_x) THEN + jx = (1.0_wp - ty)*jx0 + ty*jx1 + jxp = CD_ZERO + IF (.NOT. clamp_y) jxp = (jx1 - jx0)/(bathy%y(iy + 1) - bathy%y(iy)) + z_floor = z_floor + hx*jx + dfdx = dfdx + hxp*jx + dfdy = dfdy + hx*jxp + IF (PRESENT(curvature)) THEN + curvature(1) = curvature(1) + hxpp*jx + curvature(2) = curvature(2) + hxp*jxp + END IF + END IF + IF (on_y .OR. on_m) THEN + jy = (1.0_wp - tx)*jy0 + tx*jy1 + jyp = CD_ZERO + IF (.NOT. clamp_x) jyp = (jy1 - jy0)/(bathy%x(ix + 1) - bathy%x(ix)) + c = jy + hx*mxy + z_floor = z_floor + hy*c + dfdx = dfdx + hy*(jyp + hxp*mxy) + dfdy = dfdy + hyp*c + IF (PRESENT(curvature)) THEN + curvature(1) = curvature(1) + hy*hxpp*mxy + curvature(2) = curvature(2) + hyp*(jyp + hxp*mxy) + curvature(3) = curvature(3) + hypp*c + END IF + END IF + END SUBROUTINE crease_blend + + PURE SUBROUTINE crease_band(axis, i0, q, k, u, dl) + !! The interior grid line k whose crease band |q - axis(k)| < dl holds q (0: none), for + !! q in the cell [axis(i0), axis(i0+1)]; u = q - axis(k). + REAL(wp), INTENT(IN) :: axis(:), q + INTEGER, INTENT(IN) :: i0 + INTEGER, INTENT(OUT) :: k + REAL(wp), INTENT(OUT) :: u, dl + k = 0 + u = CD_ZERO + dl = CD_ZERO + IF (i0 > 1) THEN + dl = CD_BATHY_CREASE_FRACTION*MIN(axis(i0) - axis(i0 - 1), axis(i0 + 1) - axis(i0)) + u = q - axis(i0) + IF (u < dl) THEN + k = i0 + RETURN + END IF + END IF + IF (i0 + 1 < SIZE(axis)) THEN + dl = CD_BATHY_CREASE_FRACTION*MIN(axis(i0 + 1) - axis(i0), axis(i0 + 2) - axis(i0 + 1)) + u = q - axis(i0 + 1) + IF (-u < dl) THEN + k = i0 + 1 + RETURN + END IF + END IF + u = CD_ZERO + dl = CD_ZERO + END SUBROUTINE crease_band + + PURE SUBROUTINE crease_fillet(u, dl, after, h, hp, hpp) + !! h(u) = (dl - |u|)^3/(6 dl^2) and its first and second derivatives; after: the query + !! cell lies after the line (u >= 0), so that at u = 0 the first derivative is the + !! one-sided value of that cell. + REAL(wp), INTENT(IN) :: u, dl + LOGICAL, INTENT(IN) :: after + REAL(wp), INTENT(OUT) :: h, hp, hpp + REAL(wp) :: r + r = dl - ABS(u) + h = r**3/(6.0_wp*dl*dl) + hp = r*r/(2.0_wp*dl*dl) + IF (after) hp = -hp + hpp = r/(dl*dl) + END SUBROUTINE crease_fillet + + PURE SUBROUTINE x_jump(bathy, k, j, dl, jump, active) + !! Slope jump of grid row j across the interior x line k (right slope less left + !! slope of z_floor = -depth); zero, and active unchanged, when the fillet of width dl + !! would move the surface by no more than CD_BATHY_CREASE_MIN_HEIGHT. active is set otherwise. + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + INTEGER, INTENT(IN) :: k, j + REAL(wp), INTENT(IN) :: dl + REAL(wp), INTENT(OUT) :: jump + LOGICAL, INTENT(INOUT) :: active + jump = (bathy%depth(k, j) - bathy%depth(k + 1, j))/(bathy%x(k + 1) - bathy%x(k)) - & + (bathy%depth(k - 1, j) - bathy%depth(k, j))/(bathy%x(k) - bathy%x(k - 1)) + IF (ABS(jump)*dl/6.0_wp > CD_BATHY_CREASE_MIN_HEIGHT) THEN + active = .TRUE. + ELSE + jump = CD_ZERO + END IF + END SUBROUTINE x_jump + + PURE SUBROUTINE y_jump(bathy, i, k, dl, jump, active) + !! Slope jump of grid column i across the interior y line k (see x_jump). + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + INTEGER, INTENT(IN) :: i, k + REAL(wp), INTENT(IN) :: dl + REAL(wp), INTENT(OUT) :: jump + LOGICAL, INTENT(INOUT) :: active + jump = (bathy%depth(i, k) - bathy%depth(i, k + 1))/(bathy%y(k + 1) - bathy%y(k)) - & + (bathy%depth(i, k - 1) - bathy%depth(i, k))/(bathy%y(k) - bathy%y(k - 1)) + IF (ABS(jump)*dl/6.0_wp > CD_BATHY_CREASE_MIN_HEIGHT) THEN + active = .TRUE. + ELSE + jump = CD_ZERO + END IF + END SUBROUTINE y_jump + SUBROUTINE locate_axis(axis, q, i0, t, clamped) REAL(wp), INTENT(IN) :: axis(:), q INTEGER, INTENT(OUT) :: i0 diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index f51d51c5..b57ea388 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -40,7 +40,7 @@ MODULE CableDyn_DeckDriver CD_STATIC_OK, CD_STATIC_BADINPUT USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Init_Bathymetry, CD_End_Bathymetry, & CD_Bathymetry_Is_Initialized, CD_Bathymetry_Floor, & - CD_Bathymetry_Floor_Gradient, CD_BATHY_OK + CD_Bathymetry_Floor_Gradient, CD_Bathymetry_Grid_Floor, CD_BATHY_OK USE CableDyn_Line, ONLY: CD_LineType, CD_LineSection, CD_Build_Line_Mesh, & CD_Nodal_Seabed_Stiffness, CD_LINE_OK USE CableDyn_Catenary, ONLY: CD_Catenary_Seed, CD_CAT_OK, CD_CAT_NOSEED @@ -1548,7 +1548,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, REAL(wp) :: saddle_res CHARACTER(320) :: saddle_notes LOGICAL :: primary_done, primary_inadmissible, tolerance_note, stable, kink_refined, sequence_done - LOGICAL :: primary_walked, walk_rejected + LOGICAL :: primary_walked, walk_rejected, primary_walk_planar ! Why the bow behind the fairlead was not reached (bow_route), blank when not tried. CHARACTER(1024) :: bow_msg, refine_msg ! Set when the deck-mesh equilibrium failed the stability test and the refined one passed. @@ -2003,6 +2003,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, sym_broken = .FALSE. planar_unstable = .FALSE. walk_rejected = .FALSE. + primary_walk_planar = .TRUE. saddle_tol_note = .FALSE. saddle_kink = .FALSE. saddle_stab = .FALSE. @@ -2393,13 +2394,14 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, static_tol, l0_am, ea_am, ei_am, w_am, q_static, curv, fixed_am, & applied_scale, diag, res, iters, es, em, primary_inadmissible, & tolerance_note, kink_refined, bathymetry=bathymetry, cur_obj=cur_obj, & - walked=primary_walked) + walked=primary_walked, walk_planar=primary_walk_planar) ELSE CALL hermite_static_primary(anchor, fairlead, l0, ea, ei, w, diam, dry_b, fixed_dofs, contact_enabled, & contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, opts, & static_tol, l0_am, ea_am, ei_am, w_am, q_static, curv, fixed_am, & applied_scale, diag, res, iters, es, em, primary_inadmissible, & - tolerance_note, kink_refined, cur_obj=cur_obj, walked=primary_walked) + tolerance_note, kink_refined, cur_obj=cur_obj, walked=primary_walked, & + walk_planar=primary_walk_planar) END IF IF (es == CD_HCSTAT_OK) THEN ! adaptive_mesh refines while the resolution screen is fragile, up to its cap; an @@ -2556,6 +2558,17 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, '. Catenary-continuation route: '//TRIM(short_message(primary_msg, 360))// & '. Mesh-sequenced route: '//TRIM(short_message(sequence_msg, 360))); RETURN END IF + ! Over a seabed that is not planar under the line the walk started from the plane + ! fitted to it: that the line cannot hang as a catenary is not proven there. + IF (walk_rejected .AND. .NOT. primary_walk_planar) THEN + CALL fail_solve(ErrStat, ErrMsg, 'finite-EI cable static solve found no admissible equilibrium over '// & + 'the bathymetry: no catenary clears the plane fitted to the bathymetry along the chord, '// & + 'and the anchor walk toward an equilibrium held by the bending stiffness did not reach '// & + 'an accepted state ('// & + TRIM(short_message(primary_msg, 360))//'); mesh-sequenced route: '// & + TRIM(short_message(sequence_msg, 240))//'; check the line length and the seabed under it') + RETURN + END IF IF (walk_rejected) THEN CALL fail_solve(ErrStat, ErrMsg, 'finite-EI cable static solve found no admissible planar equilibrium '// & 'clear of the seabed: the net-heavy line is too long for its span to hang as a catenary, '// & @@ -4092,7 +4105,7 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia endconn_mode, opts, static_tol, l0_am, ea_am, ei_am, w_am, q_static, & curv, fixed_am, applied_scale, diag, res, iters, ErrStat, ErrMsg, & inadmissible, tolerance_note, kink_refined, bathymetry, refined_pass, & - cur_obj, walked, fold_walk, stability_refine) + cur_obj, walked, fold_walk, stability_refine, walk_planar) !! Primary finite-EI static route of a deck cable (the OrcaFlex/MoorPy practice of !! "catenary statics, then full statics"): !! @@ -4100,7 +4113,9 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia !! segments (signed submerged weight, so buoyancy sections are included), on the !! declared seabed plane -- flat WtrDpth, or the plane fitted to a structured !! bathymetry along the chord -- with the anchor at its actual height, or as a - !! line hung in mid-water when no seabed is declared; + !! line hung in mid-water when no seabed is declared; over a bathymetry that is + !! not a plane along the chord, the seed nodes deeper below the actual bed than + !! their static penalty penetration are draped onto it (drape_seed_on_bed); !! 2. trace the bending-stiffness family EI(lambda) = lambda*EI from a stiffness !! fraction whose bending length is below the element length up to lambda = 1 !! (CD_HermiteCable_Static_Solve_Continuation), with every load at full value; @@ -4113,7 +4128,9 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia !! ErrStat follows CD_HCSTAT_*. inadmissible is set when no catenary clears the seabed !! (a heavy line longer than its horizontal span plus rise on a planar seabed) and the !! anchor walk (seed_walk, walk_anchor) reached no equilibrium held by the bending - !! stiffness either; callers fail closed naming the geometry, without fallback. + !! stiffness either; callers fail closed naming the geometry, without fallback. Over a + !! non-planar bathymetry the walk also runs (the excess length may rest in the dips of + !! the bed), but its failure proves nothing and leaves inadmissible unset. !! walked (optional) is set when the returned state was reached by that walk. !! fold_walk (optional, flat seabed): trace the bow behind the fairlead instead. The anchor is !! moved to the far side of the fairlead, where the line hangs as a lazy wave whose arch @@ -4158,6 +4175,9 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: cur_obj ! Set when the returned state was reached by walking the anchor (see seed_walk). LOGICAL, INTENT(OUT), OPTIONAL :: walked + ! Whether the seabed under the line is planar (see planar_bed): a failed walk proves + ! the line too long for its span only then. + LOGICAL, INTENT(OUT), OPTIONAL :: walk_planar ! Trace the bow behind the fairlead (see fold_walk above). LOGICAL, INTENT(IN), OPTIONAL :: fold_walk ! Go straight to the refined repetition (see stability_refine above). @@ -4182,11 +4202,11 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia CHARACTER(400) :: walk_msg_c REAL(wp) :: walk_d, a_seed(3) CHARACTER(512) :: walk_msg - LOGICAL :: tensile, refine_all, planar_bed + LOGICAL :: tensile, refine_all, planar_bed, walk_needed REAL(wp) :: h_target REAL(wp) :: origin(2), a_l(3), f_l(3), seabed_z, seabed_slope, horizontal_tension, grounded_length REAL(wp) :: lambda0, ratio, span(2), span_len, t, xg, yg, zf, sx, sz, sxx, sxz, xl, yl - REAL(wp) :: res_cont, cont_tol, phi, penetration, zfit(NFIT), fit_misfit, fine_limit + REAL(wp) :: res_cont, cont_tol, phi, penetration, zfit(NFIT), fit_misfit, fine_limit, seed_bed, anchor_bed REAL(wp), ALLOCATABLE :: pos(:), q_seed(:), q_cont(:), curv_cont(:), knnode(:), tdir(:, :), stretch(:) CHARACTER(512) :: em @@ -4196,6 +4216,7 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia tolerance_note = .FALSE. kink_refined = .FALSE. IF (PRESENT(walked)) walked = .FALSE. + IF (PRESENT(walk_planar)) walk_planar = .TRUE. fold = .FALSE. IF (PRESENT(fold_walk)) fold = fold_walk applied_scale = 1 @@ -4260,15 +4281,28 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia ! 1. exact elastic catenary seed (anchor = node 1, fairlead = node nnode) planar_bed = .NOT. PRESENT(bathymetry) .OR. & fit_misfit <= 1.0e-6_wp*MAX(CD_ONE, SUM(l0), ABS(seabed_z)) + IF (PRESENT(walk_planar)) walk_planar = planar_bed + ! Bed height under the anchor (a non-planar bathymetry; see the anchor walk). + anchor_bed = seabed_z + IF (contact_enabled .AND. .NOT. planar_bed) THEN + xg = frame_cs(1)*a_l(1) - frame_cs(2)*a_l(2) + yg = frame_cs(2)*a_l(1) + frame_cs(1)*a_l(2) + CALL CD_Bathymetry_Floor(bathymetry, xg, yg, anchor_bed, es, em) + IF (es /= CD_BATHY_OK) THEN + ErrStat = CD_HCSTAT_NOCONVERGE + ErrMsg = 'bathymetry query for the catenary seed failed: '//TRIM(em); RETURN + END IF + END IF ALLOCATE (pos(3*nnode), q_seed(6*nnode)) ! A line too long for its span has no EI = 0 (catenary) equilibrium clear of the seabed, ! but its bending stiffness can hold one (a bow in the vertical plane carrying the excess ! length). Such a state is reached by displacement control, as a line is laid: the ! anchor is moved back along the chord until the catenary exists, the line is solved - ! there, and the anchor is walked back to its position (walk_anchor below). Over a - ! planar seabed (flat, or a structured bathymetry that is a plane along the chord and - ! behind the anchor), on which the walked anchor keeps its height above the bed. - walk_ok = contact_enabled .AND. planar_bed + ! there, and the anchor is walked back to its position (walk_anchor below). The walked + ! anchor keeps its height above the bed: on the plane continued behind the anchor over + ! a planar seabed (flat, or a structured bathymetry that is a plane along the chord and + ! behind the anchor), on the bathymetry itself otherwise. + walk_ok = contact_enabled span_len = NORM2(a_l(1:2) - f_l(1:2)) IF (span_len <= 1.0e-6_wp*SUM(l0)) walk_ok = .FALSE. ! The bow behind the fairlead is traced over a flat seabed only (the bed must continue @@ -4294,23 +4328,37 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia a_seed(3) = a_l(3) - seabed_slope*walk_d ! The bow behind the fairlead: the anchor mirrored about the fairlead, as far back. IF (fold) a_seed(1:2) = f_l(1:2) + (span_len + walk_d)*(f_l(1:2) - a_l(1:2))/span_len - IF (PRESENT(bathymetry)) THEN + END IF + seed_bed = seabed_z - seabed_slope*walk_d + IF (k_walk > 0 .AND. PRESENT(bathymetry)) THEN + xg = frame_cs(1)*a_seed(1) - frame_cs(2)*a_seed(2) + yg = frame_cs(2)*a_seed(1) + frame_cs(1)*a_seed(2) + CALL CD_Bathymetry_Floor(bathymetry, xg, yg, zf, es, em) + IF (planar_bed) THEN ! The bathymetry must continue the plane behind the anchor (it is held flat past ! the edge of its grid). - xg = frame_cs(1)*a_seed(1) - frame_cs(2)*a_seed(2) - yg = frame_cs(2)*a_seed(1) + frame_cs(1)*a_seed(2) - CALL CD_Bathymetry_Floor(bathymetry, xg, yg, zf, es, em) IF (es /= CD_BATHY_OK .OR. ABS(zf - (seabed_z - seabed_slope*walk_d)) > & 1.0e-6_wp*MAX(CD_ONE, SUM(l0), ABS(seabed_z))) THEN CALL walk_failed('the bathymetry does not continue its plane behind the anchor, where the '// & 'bending-supported equilibrium would be traced from') RETURN END IF + ELSE + IF (es /= CD_BATHY_OK) THEN + CALL walk_failed('the bathymetry behind the anchor, where the bending-supported equilibrium '// & + 'would be traced from, could not be queried ('//TRIM(em)//')') + RETURN + END IF + ! Any other bathymetry: the walked anchor keeps its height above the bed under it, + ! and the catenary seed is laid from there along the fitted slope (and draped onto + ! the bed below; see drape_seed_on_bed). + a_seed(3) = zf + (a_l(3) - anchor_bed) + seed_bed = zf END IF END IF IF (contact_enabled) THEN CALL CD_Catenary_Seed(a_seed, f_l, l0, ea, w, pos, horizontal_tension, grounded_length, es, em, & - seabed_z=seabed_z - seabed_slope*walk_d, seabed_slope=seabed_slope) + seabed_z=seed_bed, seabed_slope=seabed_slope) ELSE CALL CD_Catenary_Seed(a_seed, f_l, l0, ea, w, pos, horizontal_tension, grounded_length, es, em, & suspended=.TRUE.) @@ -4318,19 +4366,33 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia IF (es /= CD_CAT_OK) THEN ErrStat = CD_HCSTAT_NOCONVERGE ErrMsg = 'catenary seed unavailable: '//TRIM(em) - ! Proven for a planar seabed under the line: a flat one, or a bathymetry whose profile - ! in the vertical plane of the line is straight (a uniform slope along the chord). - inadmissible = es == CD_CAT_NOSEED .AND. contact_enabled .AND. planar_bed .AND. & - ALL(w >= CD_ZERO) .AND. ANY(w > CD_ZERO) + ! A net-heavy line too long to lie in the vertical plane over the seabed plane: the + ! anchor walk traces the equilibrium its bending stiffness holds. That no catenary + ! equilibrium exists is proven for a planar seabed under the line only: a flat one, + ! or a bathymetry whose profile in the vertical plane of the line is straight (a + ! uniform slope along the chord). Over any other bathymetry the excess length may + ! rest in its dips, and the mesh-sequenced route still runs when the walk fails. + walk_needed = es == CD_CAT_NOSEED .AND. contact_enabled .AND. ALL(w >= CD_ZERO) .AND. ANY(w > CD_ZERO) + inadmissible = walk_needed .AND. planar_bed IF (k_walk == 0) walk_msg = ErrMsg - IF (walk_ok .AND. (inadmissible .OR. k_walk > 0)) CYCLE seed_walk + IF (walk_ok .AND. (walk_needed .OR. k_walk > 0)) CYCLE seed_walk RETURN END IF ! A catenary that closes the endpoints only by passing through the seabed is not an ! equilibrium. On a planar bed (flat, or a bathymetry whose profile under the chord is ! straight) this means that no in-plane EI = 0 equilibrium clears the bed: the - ! (net-heavy) line is too long for its span to hang as a catenary. - IF (contact_enabled) THEN + ! (net-heavy) line is too long for its span to hang as a catenary. Over any other + ! bathymetry the seed, laid on the plane fitted along the chord, meets the actual bed + ! wherever that rises above the plane (roughness, a bump or a ridge under the line): + ! those nodes are draped onto the bed instead (drape_seed_on_bed), and the bending- + ! stiffness continuation, which queries the full surface, settles the contact. + IF (contact_enabled .AND. .NOT. planar_bed) THEN + CALL drape_seed_on_bed(es, em) + IF (es /= CD_BATHY_OK) THEN + ErrStat = CD_HCSTAT_NOCONVERGE + ErrMsg = 'bathymetry query for the catenary seed failed: '//TRIM(em); RETURN + END IF + ELSE IF (contact_enabled) THEN penetration = CD_ZERO DO i = 1, nnode ! bed height along the chord, measured from the anchor toward the fairlead (signed: @@ -4580,9 +4642,36 @@ SUBROUTINE walk_failed(reason) CHARACTER(*), INTENT(IN) :: reason ErrStat = CD_HCSTAT_NOCONVERGE ErrMsg = TRIM(walk_msg)//'; '//TRIM(reason) - inadmissible = .TRUE. + ! Proven only over a planar seabed (see seed_walk); over any other bathymetry the + ! mesh-sequenced route still runs. + inadmissible = planar_bed END SUBROUTINE walk_failed + SUBROUTINE drape_seed_on_bed(es_d, em_d) + !! Drape the catenary seed pos, laid on the plane fitted along the chord to a non-planar + !! bathymetry, onto the actual bed: every interior node deeper below the bed than its + !! static penalty penetration (nodal submerged weight over the nodal contact stiffness + !! kBot*Diam*length) is lifted onto it; a node within that depth stays where the seed + !! put it, as the contact solve would settle it there. The ends stay held. + INTEGER, INTENT(OUT) :: es_d + CHARACTER(*), INTENT(OUT) :: em_d + INTEGER :: kk + REAL(wp) :: zb, xq, yq, kn, wn, sink + es_d = CD_BATHY_OK + em_d = '' + DO kk = 2, nnode - 1 + xq = frame_cs(1)*pos(3*kk - 2) - frame_cs(2)*pos(3*kk - 1) + yq = frame_cs(2)*pos(3*kk - 2) + frame_cs(1)*pos(3*kk - 1) + CALL CD_Bathymetry_Floor(bathymetry, xq, yq, zb, es_d, em_d) + IF (es_d /= CD_BATHY_OK) RETURN + kn = 0.5_wp*opts%kbot*(diam(kk - 1)*l0(kk - 1) + diam(kk)*l0(kk)) + wn = 0.5_wp*(w(kk - 1)*l0(kk - 1) + w(kk)*l0(kk)) + sink = CD_ZERO + IF (kn > CD_ZERO) sink = MAX(wn, CD_ZERO)/kn + IF (pos(3*kk) < zb - sink) pos(3*kk) = zb + END DO + END SUBROUTINE drape_seed_on_bed + SUBROUTINE walk_anchor() !! Displacement control of a line too long for its span: q_cont is its equilibrium !! with the anchor at a_seed, walk_d back along the chord; the anchor is moved back to @@ -4615,8 +4704,9 @@ SUBROUTINE walk_anchor() REAL(wp) :: tw, dt, dt_prev, a_cur(3), a_new(3), res_w, wgt, tol_w INTEGER :: it_w, es_w, k, total_it LOGICAL :: have_prev, energy, folded, fold_now - REAL(wp) :: fit, path_len, r_td(2), p, up(3), tl - INTEGER :: k_td, kk + REAL(wp) :: fit, path_len, r_td(2), p, up(3), tl, xb_w, yb_w, zb_w + INTEGER :: k_td, kk, es_b + CHARACTER(512) :: em_b CHARACTER(512) :: em_w ALLOCATE (q_try(6*nnode), q_new(6*nnode), q_prev(6*nnode), sref(nnode), curv_w(nnode)) sref(1) = CD_ZERO @@ -4691,8 +4781,22 @@ SUBROUTINE walk_anchor() path_len = NORM2(a_l - a_seed) IF (k_td > 1) dt = MIN(dt, MAX(WALK_DT_MIN, -fit/path_len)) END IF - a_cur = a_seed + tw*(a_l - a_seed) + a_cur = q_cont(1:3) a_new = a_seed + (tw + dt)*(a_l - a_seed) + ! Over a non-planar bathymetry the walked anchor follows the bed under it at the + ! anchor's own height above the bed (a straight path would cut through a ridge or + ! leave a dip); it ends at a_l, where that height is the deck's. + IF (.NOT. planar_bed .AND. PRESENT(bathymetry)) THEN + xb_w = frame_cs(1)*a_new(1) - frame_cs(2)*a_new(2) + yb_w = frame_cs(2)*a_new(1) + frame_cs(1)*a_new(2) + CALL CD_Bathymetry_Floor(bathymetry, xb_w, yb_w, zb_w, es_b, em_b) + IF (es_b /= CD_BATHY_OK) THEN + iters = iters + total_it + CALL walk_failed('the bathymetry under the walked anchor could not be queried ('//TRIM(em_b)//')') + RETURN + END IF + a_new(3) = zb_w + (a_l(3) - anchor_bed) + END IF IF (have_prev) THEN q_try = q_cont + (q_cont - q_prev)*(dt/dt_prev) ELSE @@ -13003,18 +13107,25 @@ SUBROUTINE reverse_line_sections(sections, line_id) END DO END SUBROUTINE reverse_line_sections - SUBROUTINE check_fixed_point_above_seabed(pt, z_floor, what, ErrStat, ErrMsg) + SUBROUTINE check_fixed_point_above_seabed(pt, z_floor, what, ErrStat, ErrMsg, z_grid) !! A Fixed point (anchor) must sit on or above the seabed. A point below it pins the !! attached line inside the penalty seabed, which is not a physical configuration !! (MoorDyn v2 rejects an anchor below the water depth the same way). An anchor within !! the practical seabed tolerance max(1 mm, 1e-5 |z_floor|) of the seabed, above or !! below (tabulated depths, rounded deck coordinates), rests on the seabed: its z is set !! to the seabed elevation. Further below is rejected. + !! z_grid (bathymetry): the bilinear surface of the tabulated depths, which the rounding + !! of a crease moves by up to a sixth of its slope jump times the band half-width (the + !! roundings of two lines add where their bands cross); an + !! anchor at the tabulated depth (within the tolerance of z_grid) rests on the seabed as + !! well and is placed on the rounded surface z_floor. An anchor between the two surfaces + !! but near neither is treated by its distance to z_floor alone. TYPE(DeckPoint), INTENT(INOUT) :: pt REAL(wp), INTENT(IN) :: z_floor CHARACTER(*), INTENT(IN) :: what INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: z_grid CHARACTER(32) :: zs, fs, ts REAL(wp) :: tol @@ -13025,6 +13136,12 @@ SUBROUTINE check_fixed_point_above_seabed(pt, z_floor, what, ErrStat, ErrMsg) pt%pos(3) = z_floor RETURN END IF + IF (PRESENT(z_grid)) THEN + IF (ABS(pt%pos(3) - z_grid) <= tol*(CD_ONE + 1.0e-9_wp)) THEN + pt%pos(3) = z_floor + RETURN + END IF + END IF IF (pt%pos(3) > z_floor) RETURN WRITE (zs, '(G0.8)') pt%pos(3) WRITE (fs, '(G0.8)') z_floor @@ -13044,7 +13161,7 @@ SUBROUTINE check_fixed_points_on_bathymetry(points, bathymetry, ErrStat, ErrMsg) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER :: i, es - REAL(wp) :: z_floor + REAL(wp) :: z_floor, z_grid CHARACTER(160) :: em ErrStat = 0; ErrMsg = '' @@ -13052,8 +13169,10 @@ SUBROUTINE check_fixed_points_on_bathymetry(points, bathymetry, ErrStat, ErrMsg) IF (TRIM(points(i)%ptype) /= 'fixed') CYCLE CALL CD_Bathymetry_Floor(bathymetry, points(i)%pos(1), points(i)%pos(2), z_floor, es, em) IF (es /= CD_BATHY_OK) CYCLE + CALL CD_Bathymetry_Grid_Floor(bathymetry, points(i)%pos(1), points(i)%pos(2), z_grid, es, em) + IF (es /= CD_BATHY_OK) CYCLE CALL check_fixed_point_above_seabed(points(i), z_floor, 'the bathymetry seabed at its (x, y), z', & - ErrStat, ErrMsg) + ErrStat, ErrMsg, z_grid=z_grid) IF (ErrStat /= 0) RETURN END DO END SUBROUTINE check_fixed_points_on_bathymetry diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 006360ff..c039dd69 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -68,9 +68,10 @@ MODULE CableDyn_HermiteCableDynamic USE CableDyn_SeabedContact, ONLY: CD_Seabed_Normal_Law, CD_Seabed_Contact_Gate, CD_SEABED_CONTACT_BLEND, & CD_Seabed_Friction_Stick_Slip, CD_Seabed_Friction_Aniso, & CD_Seabed_Friction_Mu_Dir, CD_FRICTION_STICK_SLIP, CD_Seabed_End_Support, & - CD_Seabed_End_Element_Share + CD_Seabed_End_Element_Share, CD_Seabed_Normal_Contact USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Bathymetry_Is_Initialized, & - CD_Bathymetry_Floor_Gradient, CD_End_Bathymetry, CD_BATHY_OK + CD_Bathymetry_Floor_Gradient, CD_End_Bathymetry, CD_BATHY_OK, & + CD_Bathymetry_Rotate_Curvature USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & CD_HermiteTorsion_Compliance, CD_HermiteTorsion_Validate, CD_HTORS_OK, & CD_HTORS_MAX_STEP, CD_HermiteTorsionWorkType, CD_HermiteTorsion_Work_Init, & @@ -4526,6 +4527,7 @@ SUBROUTINE CD_HermiteCable_Dyn_End_Force(model, node, force, ErrStat, ErrMsg) REAL(wp) :: qe(12), ve(12), fe(12), fdrag(12), fdamp(12), energy, fdry(4), kdry(4, 4), r3(3), gate, gate_gap REAL(wp) :: dry_wl, dry_b, dry_r, gap, normal, normal_gap, z_floor, xg, yg, gxg, gyg REAL(wp) :: gx, gy, sfac, nvec(3), vn, rk(3), jrel(3, 3), jtan(3, 3) + REAL(wp) :: curv_e(3), fcrease_e(3), kcrease_e(3, 3) INTEGER :: e, i0, iz, zslot, es, k LOGICAL :: dry, has_jac CHARACTER(200) :: em2 @@ -4586,12 +4588,21 @@ SUBROUTINE CD_HermiteCable_Dyn_End_Force(model, node, force, ErrStat, ErrMsg) IF (model%has_contact_bathymetry) THEN xg = model%contact_frame_c*model%q(iz - 2) - model%contact_frame_s*model%q(iz - 1) yg = model%contact_frame_s*model%q(iz - 2) + model%contact_frame_c*model%q(iz - 1) - CALL CD_Bathymetry_Floor_Gradient(model%contact_bathymetry, xg, yg, z_floor, gxg, gyg, es, em2) + CALL CD_Bathymetry_Floor_Gradient(model%contact_bathymetry, xg, yg, z_floor, gxg, gyg, es, em2, & + crease_curvature=curv_e) IF (es /= CD_BATHY_OK) THEN ErrStat = CD_HCDYN_NOCONVERGE; ErrMsg = 'CD_HermiteCable_Dyn_End_Force: '//TRIM(em2); RETURN END IF gx = model%contact_frame_c*gxg + model%contact_frame_s*gyg gy = -model%contact_frame_s*gxg + model%contact_frame_c*gyg + ! the elastic force in a rounded crease (see assemble_contact) + IF (ANY(ABS(curv_e) > CD_ZERO)) THEN + CALL crease_contact_increment(z_floor - model%q(iz), gx, gy, model%contact_kn(node), & + CD_Bathymetry_Rotate_Curvature(curv_e, [model%contact_frame_c, & + model%contact_frame_s]), & + fcrease_e, kcrease_e) + r3 = r3 - fcrease_e + END IF END IF ! frictionless: along the upward floor normal, at the normal penetration and velocity sfac = SQRT(CD_ONE + gx*gx + gy*gy) @@ -5817,6 +5828,8 @@ SUBROUTINE assemble_contact(model, q_cfg, v_cfg, want_residual, want_tangent, Er REAL(wp) :: sfac, nvec(3), vn, dnormal_dv(3) REAL(wp) :: d_fr(2), mu_c REAL(wp) :: ffr(2), dfr_dd(2, 2), dfr_dc(2) + REAL(wp) :: curv_g(3), curv_l(3), fcrease(3), kcrease(3, 3) + LOGICAL :: creased CHARACTER(200) :: em ErrStat = CD_HCDYN_OK; ErrMsg = '' @@ -5831,15 +5844,25 @@ SUBROUTINE assemble_contact(model, q_cfg, v_cfg, want_residual, want_tangent, Er xl = q_cfg(ix); yl = q_cfg(iy) xg = model%contact_frame_c*xl - model%contact_frame_s*yl yg = model%contact_frame_s*xl + model%contact_frame_c*yl - CALL CD_Bathymetry_Floor_Gradient(model%contact_bathymetry, xg, yg, z_floor, gxg, gyg, es, em) + CALL CD_Bathymetry_Floor_Gradient(model%contact_bathymetry, xg, yg, z_floor, gxg, gyg, es, em, & + crease_curvature=curv_g) IF (es /= CD_BATHY_OK) THEN ErrStat = CD_HCDYN_NOCONVERGE; ErrMsg = 'bathymetry query failed: '//TRIM(em); RETURN END IF ! Chain the global floor gradient through the inverse local-to-global heading. gx = model%contact_frame_c*gxg + model%contact_frame_s*gyg gy = -model%contact_frame_s*gxg + model%contact_frame_c*gyg + creased = ANY(ABS(curv_g) > CD_ZERO) ELSE z_floor = model%seabed_z + creased = .FALSE. + END IF + ! In a rounded crease of the bathymetry the elastic force is the gradient of the + ! penalty potential of the static solve (CD_Seabed_Normal_Contact with the curvature): + ! its departure from the normal force F n, and its tangent, are added below. + IF (creased) THEN + curv_l = CD_Bathymetry_Rotate_Curvature(curv_g, [model%contact_frame_c, model%contact_frame_s]) + CALL crease_contact_increment(z_floor - q_cfg(iz), gx, gy, model%contact_kn(i), curv_l, fcrease, kcrease) END IF sfac = SQRT(CD_ONE + gx*gx + gy*gy) @@ -5869,6 +5892,16 @@ SUBROUTINE assemble_contact(model, q_cfg, v_cfg, want_residual, want_tangent, Er END DO END DO END IF + IF (creased) THEN + IF (want_residual) model%ws_R(ix:iz) = model%ws_R(ix:iz) - fcrease + IF (want_tangent) THEN + DO jc = 1, 3 + DO jr = 1, 3 + CALL scatter_contact_band(model%ws_Kb, ix + jr - 1, ix + jc - 1, kcrease(jr, jc)) + END DO + END DO + END IF + END IF IF (.NOT. model%fr_active) CYCLE ! Stick-slip friction spring to the committed anchor (CD_Seabed_Friction_Stick_Slip): @@ -5902,6 +5935,19 @@ SUBROUTINE assemble_contact(model, q_cfg, v_cfg, want_residual, want_tangent, Er END DO END SUBROUTINE assemble_contact + PURE SUBROUTINE crease_contact_increment(gap_v, gx, gy, kn, curv, fdelta, kdelta) + !! Elastic contact force and residual tangent of a node in a rounded bathymetry crease + !! (CD_Seabed_Normal_Contact with the surface curvature) less those of the normal + !! force F n at the same point: the increment added to the normal-force assembly. + REAL(wp), INTENT(IN) :: gap_v, gx, gy, kn, curv(3) + REAL(wp), INTENT(OUT) :: fdelta(3), kdelta(3, 3) + REAL(wp) :: fp(3), kp(3, 3) + CALL CD_Seabed_Normal_Contact(gap_v, gx, gy, kn, fdelta, kdelta, curvature=curv) + CALL CD_Seabed_Normal_Contact(gap_v, gx, gy, kn, fp, kp) + fdelta = fdelta - fp + kdelta = kdelta - kp + END SUBROUTINE crease_contact_increment + LOGICAL FUNCTION held_end_floor_support(model, q_cfg, iend, support, dsupport, inode, nin) RESULT(held) !! Floor reaction carrying the weight of the end element at line end iend (1: node 1, !! 2: node nn) of a model with seabed contact, per unit weight: the floor's normal share diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index ff182a3b..72b20cdc 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -45,7 +45,8 @@ MODULE CableDyn_HermiteCableStatic CD_Seabed_Friction_Aniso, CD_Seabed_Friction_Mu_Dir, CD_FRICTION_SPRING, & CD_Seabed_Normal_Contact, CD_Seabed_End_Support, CD_Seabed_End_Element_Share USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Bathymetry_Is_Initialized, & - CD_Bathymetry_Floor, CD_Bathymetry_Floor_Gradient, CD_BATHY_OK + CD_Bathymetry_Floor, CD_Bathymetry_Floor_Gradient, CD_BATHY_OK, & + CD_Bathymetry_Rotate_Curvature USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Drag_Element, CD_HCDYN_OK USE CableDyn_Hydro, ONLY: CD_Current_Profile_Velocity, CD_HYDRO_OK USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & @@ -1062,6 +1063,7 @@ RECURSIVE SUBROUTINE newton_step(rnorm, es, em, do_update) LOGICAL, INTENT(IN) :: do_update REAL(wp) :: qe(12) REAL(wp) :: pen, dqnorm, z_floor, gxg, gyg, gx, gy, xg, yg, normal, normal_gap, kn_eff + REAL(wp) :: curv_g(3), curv_l(3) REAL(wp) :: step_scale, trial_norm, row_scale, column_scale, merit, trial_merit, merit_base, diag_floor REAL(wp) :: gradient_component, column_norm2, fdry(4), kdry(4, 4), e_term ! Frictionless contact on a sloped floor: the force along the upward surface normal @@ -1219,15 +1221,18 @@ RECURSIVE SUBROUTINE newton_step(rnorm, es, em, do_update) DO a = 1, nn gi = 6*(a - 1) + 3 gx = CD_ZERO; gy = CD_ZERO; z_floor = seabed_z + curv_l = CD_ZERO IF (use_bathymetry) THEN xg = contact_cs(1)*q(gi - 2) - contact_cs(2)*q(gi - 1) yg = contact_cs(2)*q(gi - 2) + contact_cs(1)*q(gi - 1) - CALL CD_Bathymetry_Floor_Gradient(bathymetry, xg, yg, z_floor, gxg, gyg, es2, em2) + CALL CD_Bathymetry_Floor_Gradient(bathymetry, xg, yg, z_floor, gxg, gyg, es2, em2, crease_curvature=curv_g) IF (es2 /= CD_BATHY_OK) THEN es = CD_HCSTAT_NOCONVERGE; em = 'bathymetry query failed: '//TRIM(em2); RETURN END IF gx = contact_cs(1)*gxg + contact_cs(2)*gyg gy = -contact_cs(2)*gxg + contact_cs(1)*gyg + ! the curvature of a rounded crease, turned into the solve frame like the gradient + IF (ANY(ABS(curv_g) > CD_ZERO)) curv_l = CD_Bathymetry_Rotate_Curvature(curv_g, contact_cs) END IF pen = z_floor - q(gi) ! The penetration normal to the floor is pen/sfac (sfac = 1 on a level floor). @@ -1250,7 +1255,7 @@ RECURSIVE SUBROUTINE newton_step(rnorm, es, em, do_update) kn_eff = contact_kn(a) IF (use_bathymetry) THEN ! Frictionless: the force acts along the upward normal of the (sloped) floor. - CALL CD_Seabed_Normal_Contact(pen, gx, gy, kn_eff, fcon, jcon) + CALL CD_Seabed_Normal_Contact(pen, gx, gy, kn_eff, fcon, jcon, curvature=curv_l) e_term = seabed_potential(pen/sfac, kn_eff) pi_total = pi_total + e_term pi_abs = pi_abs + e_term diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index b2eb699f..4d2855c9 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -3622,7 +3622,7 @@ SUBROUTINE CD_Get_Model_EndNodeTangent(model, coupled_slot, k_block, c_block, Er REAL(wp), INTENT(OUT), OPTIONAL :: kv_neighbour(3) INTEGER :: e, node, d0, idx(6), i REAL(wp) :: q2(6), chord(3), ell, tang(3), tt(3, 3), strain, material, tension, ke(3, 3), v_other(3) - REAL(wp) :: z_floor, dfdx, dfdy, gap, fvec(3), jac3(3, 3), damp_force, damp_dgap, damp_dvz + REAL(wp) :: z_floor, dfdx, dfdy, gap, fvec(3), jac3(3, 3), damp_force, damp_dgap, damp_dvz, curv_end(3) k_block = CD_ZERO c_block = CD_ZERO IF (PRESENT(kv_neighbour)) kv_neighbour = CD_ZERO @@ -3683,7 +3683,8 @@ SUBROUTINE CD_Get_Model_EndNodeTangent(model, coupled_slot, k_block, c_block, Er IF (model%has_seabed) THEN ! the end node's seabed contact (its neighbour is the fixed seabed, so no kv term) IF (model%has_bathymetry) THEN - CALL model_floor_gradient(model, model%q(d0), model%q(d0 + 1), z_floor, dfdx, dfdy, ErrStat, ErrMsg) + CALL model_floor_gradient(model, model%q(d0), model%q(d0 + 1), z_floor, dfdx, dfdy, ErrStat, ErrMsg, & + curvature=curv_end) IF (ErrStat /= CD_MODEL_OK) THEN k_block = CD_ZERO c_block = CD_ZERO @@ -3694,9 +3695,10 @@ SUBROUTINE CD_Get_Model_EndNodeTangent(model, coupled_slot, k_block, c_block, Er z_floor = model%seabed_z_floor dfdx = CD_ZERO dfdy = CD_ZERO + curv_end = CD_ZERO END IF gap = z_floor - model%q(d0 + 2) - CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, model%seabed_kn(node), fvec, jac3) + CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, model%seabed_kn(node), fvec, jac3, curvature=curv_end) k_block = k_block + jac3 IF (model%has_seabed_damping) THEN BLOCK @@ -5603,7 +5605,7 @@ SUBROUTINE model_contributor_load_banded(model, q, v, free, kl, ku, force, jac_q REAL(wp) :: gap, normal, g(2), z_floor, dfdx, dfdy, tangent, dn_dv(3), dfc(2), nvec(3), vn LOGICAL :: sloped REAL(wp) :: d_fr(2), mu_c - REAL(wp) :: damp_force, damp_dgap, damp_dvz + REAL(wp) :: damp_force, damp_dgap, damp_dvz, curv_n(3) REAL(wp) :: q2(6), v2(6), f2(6), jq2(6, 6), jv2(6, 6), ea_d_eff, ea_1_eff, syr_tm, syr_ds LOGICAL :: free_map_ready REAL(wp) :: fluid2(3, 2), accel2(3, 2), wl2(2), dfdv(2, 2) @@ -5654,21 +5656,22 @@ SUBROUTINE model_contributor_load_banded(model, q, v, free, kl, ku, force, jac_q iy = 3*i - 1 iz = 3*i IF (model%has_bathymetry) THEN - CALL model_floor_gradient(model, q(ix), q(iy), z_floor, dfdx, dfdy, ErrStat, ErrMsg) + CALL model_floor_gradient(model, q(ix), q(iy), z_floor, dfdx, dfdy, ErrStat, ErrMsg, curvature=curv_n) IF (ErrStat /= CD_MODEL_OK) RETURN ELSE z_floor = model%seabed_z_floor dfdx = CD_ZERO dfdy = CD_ZERO + curv_n = CD_ZERO END IF gap = z_floor - q(iz) - IF (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO) THEN + IF (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO .OR. ANY(ABS(curv_n) > CD_ZERO)) THEN ! sloped seabed: frictionless contact along the surface normal (the static ! initializer uses the same law, so the initial condition is an equilibrium) BLOCK REAL(wp) :: fvec(3), jac3(3, 3) INTEGER :: ra, cb - CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, model%seabed_kn(i), fvec, jac3) + CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, model%seabed_kn(i), fvec, jac3, curvature=curv_n) force(ix:iz) = force(ix:iz) + fvec DO cb = 1, 3 DO ra = 1, 3 @@ -5917,11 +5920,11 @@ SUBROUTINE model_contributor_force(model, q, v, force, ErrStat, ErrMsg, end_node IF (model%has_bathymetry) THEN ! sloped seabed: frictionless contact along the surface normal BLOCK - REAL(wp) :: fvec(3), jac3(3, 3), gx, gy - CALL model_floor_gradient(model, q(ix), q(iy), z_floor, gx, gy, ErrStat, ErrMsg) + REAL(wp) :: fvec(3), jac3(3, 3), gx, gy, curv(3) + CALL model_floor_gradient(model, q(ix), q(iy), z_floor, gx, gy, ErrStat, ErrMsg, curvature=curv) IF (ErrStat /= CD_MODEL_OK) RETURN - IF (ABS(gx) > CD_ZERO .OR. ABS(gy) > CD_ZERO) THEN - CALL CD_Seabed_Normal_Contact(z_floor - q(iz), gx, gy, model%seabed_kn(i), fvec, jac3) + IF (ABS(gx) > CD_ZERO .OR. ABS(gy) > CD_ZERO .OR. ANY(ABS(curv) > CD_ZERO)) THEN + CALL CD_Seabed_Normal_Contact(z_floor - q(iz), gx, gy, model%seabed_kn(i), fvec, jac3, curvature=curv) force(slot(ix):slot(iz)) = force(slot(ix):slot(iz)) + fvec CYCLE END IF @@ -6321,17 +6324,20 @@ SUBROUTINE validate_seabed_friction(model, q, v, force, ErrStat, ErrMsg) END IF END SUBROUTINE validate_seabed_friction - SUBROUTINE model_floor_gradient(model, x, y, z_floor, dfdx, dfdy, ErrStat, ErrMsg) + SUBROUTINE model_floor_gradient(model, x, y, z_floor, dfdx, dfdy, ErrStat, ErrMsg, curvature) !! Seabed elevation and gradient of the model's bathymetry, with the bathymetry status - !! mapped to the model's (CD_MODEL_BADINPUT on a failed query). + !! mapped to the model's (CD_MODEL_BADINPUT on a failed query). curvature (optional): + !! the curvature of the crease rounding (CD_Bathymetry_Floor_Gradient). TYPE(CD_ModelType), INTENT(IN) :: model REAL(wp), INTENT(IN) :: x, y REAL(wp), INTENT(OUT) :: z_floor, dfdx, dfdy INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: curvature(3) INTEGER :: es CHARACTER(160) :: em - CALL CD_Bathymetry_Floor_Gradient(model%bathymetry, x, y, z_floor, dfdx, dfdy, es, em) + CALL CD_Bathymetry_Floor_Gradient(model%bathymetry, x, y, z_floor, dfdx, dfdy, es, em, & + crease_curvature=curvature) IF (es == CD_BATHY_OK) THEN ErrStat = CD_MODEL_OK ErrMsg = '' diff --git a/src/CableDyn_SeabedContact.f90 b/src/CableDyn_SeabedContact.f90 index 301647a1..30c079c9 100644 --- a/src/CableDyn_SeabedContact.f90 +++ b/src/CableDyn_SeabedContact.f90 @@ -54,7 +54,7 @@ PURE SUBROUTINE CD_Seabed_Normal_Law(gap, stiffness, force, dforce_dgap) END IF END SUBROUTINE CD_Seabed_Normal_Law - PURE SUBROUTINE CD_Seabed_Normal_Contact(gap, dfdx, dfdy, stiffness, force, jac) + PURE SUBROUTINE CD_Seabed_Normal_Contact(gap, dfdx, dfdy, stiffness, force, jac, curvature) !! Frictionless penalty contact with a locally planar seabed z = f(x, y) of gradient !! (dfdx, dfdy). ``gap = f(x, y) - z`` is the vertical penetration; the penetration !! normal to the surface is gap/s, s = sqrt(1 + dfdx^2 + dfdy^2), and the contact force @@ -63,9 +63,17 @@ PURE SUBROUTINE CD_Seabed_Normal_Contact(gap, dfdx, dfdy, stiffness, force, jac) !! the vertical law. ``jac`` is the residual tangent -d(force)/dq = F'(gap/s) n n^T !! (the surface gradient is held fixed over the node, i.e. the bathymetry curvature !! term is omitted). + !! curvature (optional): the second derivatives (f_xx, f_xy, f_yy) of a curved patch of + !! the surface (the rounding of a bathymetry crease). Where it is nonzero the force is + !! the gradient of the penalty potential E(g) of the normal penetration g = gap/s, + !! force = -F(g) dg/dq with dg/dq = (f_x, f_y, -1)/s - gap grad(s)/s^2 (the normal + !! force F n plus F gap grad(s)/s^2, a term of the order of the penetration times the + !! curvature), and jac is the Hessian F' dg dg^T + F d2g/dq2 of that potential (third + !! derivatives of the surface left out), so that the static energy and the force agree. REAL(wp), INTENT(IN) :: gap, dfdx, dfdy, stiffness REAL(wp), INTENT(OUT) :: force(3), jac(3, 3) - REAL(wp) :: s, normal(3), magnitude, dmag + REAL(wp), INTENT(IN), OPTIONAL :: curvature(3) + REAL(wp) :: s, normal(3), magnitude, dmag, hm(2, 2), grad(2), ds(3), dgap(3), dg(3), d2s(2, 2) INTEGER :: a, b s = SQRT(CD_ONE + dfdx*dfdx + dfdy*dfdy) @@ -77,6 +85,24 @@ PURE SUBROUTINE CD_Seabed_Normal_Contact(gap, dfdx, dfdy, stiffness, force, jac) jac(a, b) = dmag*normal(a)*normal(b) END DO END DO + IF (.NOT. PRESENT(curvature)) RETURN + IF (.NOT. ANY(ABS(curvature) > CD_ZERO)) RETURN + hm = RESHAPE([curvature(1), curvature(2), curvature(2), curvature(3)], [2, 2]) + grad = [dfdx, dfdy] + ds = CD_ZERO + ds(1:2) = MATMUL(hm, grad)/s + dgap = [dfdx, dfdy, -CD_ONE] + dg = dgap/s - gap*ds/(s*s) + force = -magnitude*dg + ! d2s/dq2 on (x, y), third derivatives of the surface left out + d2s = (MATMUL(hm, hm) - RESHAPE([ds(1)*ds(1), ds(2)*ds(1), ds(1)*ds(2), ds(2)*ds(2)], [2, 2]))/s + DO b = 1, 3 + DO a = 1, 3 + jac(a, b) = dmag*dg(a)*dg(b) + magnitude*(-dgap(b)*ds(a) - dgap(a)*ds(b) + & + 2.0_wp*gap*ds(a)*ds(b)/s)/(s*s) + END DO + END DO + jac(1:2, 1:2) = jac(1:2, 1:2) + magnitude*(hm/s - gap*d2s/(s*s)) END SUBROUTINE CD_Seabed_Normal_Contact PURE SUBROUTINE CD_Seabed_Contact_Gate(gap, gate, dgate_dgap) diff --git a/src/CableDyn_Static.f90 b/src/CableDyn_Static.f90 index e5257f21..19aa16c8 100644 --- a/src/CableDyn_Static.f90 +++ b/src/CableDyn_Static.f90 @@ -867,7 +867,7 @@ SUBROUTINE eval_seabed(qe, f_contact, add_tangent, es_out, em_out) INTEGER, INTENT(OUT) :: es_out CHARACTER(*), INTENT(OUT) :: em_out INTEGER :: i, ix, iy, iz, a, b - REAL(wp) :: z_floor, dfdx, dfdy, gap, tangent, fvec(3), jac(3, 3), normal_i + REAL(wp) :: z_floor, dfdx, dfdy, gap, tangent, fvec(3), jac(3, 3), normal_i, curv(3), tang_n f_contact = CD_ZERO es_out = 0 @@ -876,8 +876,10 @@ SUBROUTINE eval_seabed(qe, f_contact, add_tangent, es_out, em_out) ix = 3*i - 2 iy = ix + 1 iz = ix + 2 + curv = CD_ZERO IF (bathymetry_active) THEN - CALL CD_Bathymetry_Floor_Gradient(bathymetry, qe(ix), qe(iy), z_floor, dfdx, dfdy, es_out, em_out) + CALL CD_Bathymetry_Floor_Gradient(bathymetry, qe(ix), qe(iy), z_floor, dfdx, dfdy, es_out, em_out, & + crease_curvature=curv) IF (es_out /= CD_BATHY_OK) RETURN ELSE z_floor = z_floor_local @@ -885,7 +887,7 @@ SUBROUTINE eval_seabed(qe, f_contact, add_tangent, es_out, em_out) dfdy = CD_ZERO END IF gap = z_floor - qe(iz) - IF (.NOT. (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO)) THEN + IF (.NOT. (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO .OR. ANY(ABS(curv) > CD_ZERO))) THEN ! level floor: the normal is vertical (the historical flat-floor evaluation) CALL CD_Seabed_Normal_Law(gap, kn(i), f_contact(iz), tangent) IF (add_tangent) CALL add_band(iz, iz, tangent) @@ -895,11 +897,21 @@ SUBROUTINE eval_seabed(qe, f_contact, add_tangent, es_out, em_out) END IF CYCLE END IF - CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, kn(i), fvec, jac) + ! (the tangent follows the rounding of a bathymetry crease; zero curvature elsewhere) + CALL CD_Seabed_Normal_Contact(gap, dfdx, dfdy, kn(i), fvec, jac, curvature=curv) f_contact(ix:iz) = fvec ! on a slope the capacity follows the magnitude of the normal reaction (its - ! dependence on the position is left out of the tangent) - IF (friction_active) CALL add_friction(qe, f_contact, add_tangent, i, NORM2(fvec), CD_ZERO) + ! dependence on the position is left out of the tangent); in a crease band the + ! elastic force also carries the curvature term of the potential, so the capacity + ! is the scalar normal law there, as on the Hermite path and in the dynamics + IF (friction_active) THEN + IF (ANY(ABS(curv) > CD_ZERO)) THEN + CALL CD_Seabed_Normal_Law(gap/SQRT(CD_ONE + dfdx*dfdx + dfdy*dfdy), kn(i), normal_i, tang_n) + ELSE + normal_i = NORM2(fvec) + END IF + CALL add_friction(qe, f_contact, add_tangent, i, normal_i, CD_ZERO) + END IF IF (.NOT. add_tangent) CYCLE DO b = 1, 3 DO a = 1, 3 @@ -1228,7 +1240,7 @@ SUBROUTINE CD_Static_Friction_Anchors(q, current, seabed_kn, anchors, ErrStat, E REAL(wp), INTENT(IN), OPTIONAL :: seabed_z_floor TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry INTEGER :: n_nodes, i, es - REAL(wp) :: z_floor, dfdx, dfdy, normal, tangent, fvec(3), jac(3, 3), f(2), dfd(2, 2), dfc(2) + REAL(wp) :: z_floor, dfdx, dfdy, normal, tangent, fvec(3), jac(3, 3), f(2), dfd(2, 2), dfc(2), curv(3) CHARACTER(120) :: em ErrStat = CD_STATIC_OK ErrMsg = '' @@ -1251,8 +1263,10 @@ SUBROUTINE CD_Static_Friction_Anchors(q, current, seabed_kn, anchors, ErrStat, E z_floor = CD_ZERO dfdx = CD_ZERO dfdy = CD_ZERO + curv = CD_ZERO IF (PRESENT(bathymetry)) THEN - CALL CD_Bathymetry_Floor_Gradient(bathymetry, q(3*i - 2), q(3*i - 1), z_floor, dfdx, dfdy, es, em) + CALL CD_Bathymetry_Floor_Gradient(bathymetry, q(3*i - 2), q(3*i - 1), z_floor, dfdx, dfdy, es, em, & + crease_curvature=curv) IF (es /= CD_BATHY_OK) THEN CALL fail(ErrStat, ErrMsg, 'friction anchors: bathymetry query failed: '//TRIM(em)) RETURN @@ -1262,9 +1276,15 @@ SUBROUTINE CD_Static_Friction_Anchors(q, current, seabed_kn, anchors, ErrStat, E ELSE RETURN END IF - IF (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO) THEN - CALL CD_Seabed_Normal_Contact(z_floor - q(3*i), dfdx, dfdy, seabed_kn(i), fvec, jac) - normal = NORM2(fvec) + IF (ABS(dfdx) > CD_ZERO .OR. ABS(dfdy) > CD_ZERO .OR. ANY(ABS(curv) > CD_ZERO)) THEN + IF (ANY(ABS(curv) > CD_ZERO)) THEN + ! a crease band: the scalar normal law, as in the static residual + CALL CD_Seabed_Normal_Law((z_floor - q(3*i))/SQRT(CD_ONE + dfdx*dfdx + dfdy*dfdy), seabed_kn(i), & + normal, tangent) + ELSE + CALL CD_Seabed_Normal_Contact(z_floor - q(3*i), dfdx, dfdy, seabed_kn(i), fvec, jac) + normal = NORM2(fvec) + END IF ELSE CALL CD_Seabed_Normal_Law(z_floor - q(3*i), seabed_kn(i), normal, tangent) END IF @@ -2106,7 +2126,7 @@ SUBROUTINE CD_Static_Line_End_Forces(q, elem_conn, l0, ea, f_ext, tension_only, INTEGER :: n_dof, n_nodes, n_elem, k, e, a, b, node, es REAL(wp), ALLOCATABLE :: fint(:) - REAL(wp) :: zf, gx, gy, fvec(3), jac(3, 3), f2(6), jq2(6, 6), jv2(6, 6), va(3), vb(3), de, cn, ct, wla, wlb + REAL(wp) :: zf, gx, gy, fvec(3), jac(3, 3), curv(3), f2(6), jq2(6, 6), jv2(6, 6), va(3), vb(3), de, cn, ct, wla, wlb CHARACTER(200) :: em INTEGER :: ends(2) @@ -2139,8 +2159,10 @@ SUBROUTINE CD_Static_Line_End_Forces(q, elem_conn, l0, ea, f_ext, tension_only, IF (PRESENT(seabed_kn) .AND. (PRESENT(seabed_z_floor) .OR. PRESENT(bathymetry))) THEN DO k = 1, 2 node = ends(k) + curv = CD_ZERO IF (PRESENT(bathymetry)) THEN - CALL CD_Bathymetry_Floor_Gradient(bathymetry, q(3*node - 2), q(3*node - 1), zf, gx, gy, es, em) + CALL CD_Bathymetry_Floor_Gradient(bathymetry, q(3*node - 2), q(3*node - 1), zf, gx, gy, es, em, & + crease_curvature=curv) IF (es /= CD_BATHY_OK) THEN CALL fail(ErrStat, ErrMsg, 'end forces: '//TRIM(em)) RETURN @@ -2150,7 +2172,7 @@ SUBROUTINE CD_Static_Line_End_Forces(q, elem_conn, l0, ea, f_ext, tension_only, gx = CD_ZERO gy = CD_ZERO END IF - CALL CD_Seabed_Normal_Contact(zf - q(3*node), gx, gy, seabed_kn(node), fvec, jac) + CALL CD_Seabed_Normal_Contact(zf - q(3*node), gx, gy, seabed_kn(node), fvec, jac, curvature=curv) fint(3*node - 2:3*node) = fint(3*node - 2:3*node) + fvec END DO END IF diff --git a/tests/data/anchor_crease_between.dat b/tests/data/anchor_crease_between.dat new file mode 100644 index 00000000..a5a54460 --- /dev/null +++ b/tests/data/anchor_crease_between.dat @@ -0,0 +1,31 @@ +--------------------- CableDyn Input File ------------------------------------ +Fixed anchor 1 cm below the rounded valley floor, between it and the grid surface but within tolerance of neither: rejected +--------------------- LINE TYPES --------------------------------------------- +TypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-) +chain 0.12 300.0 1.2e9 -1 0 1.2 0.4 1 0 +--------------------- POINTS ------------------------------------------------- +ID Type X Y Z +(-) (-) (m) (m) (m) +1 Coupled 0.0 0.0 -20.0 +2 Fixed 300.0 0.0 -119.9933 +--------------------- LINES -------------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +--------------------- SECTIONS ----------------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 chain 350.0 35 +--------------------- OPTIONS ------------------------------------------------ +9.80665 g +1025.0 rhoW +bathy_v_valley.txt bathymetryFile +1.0e5 kBot +1.0e4 cBot +0.05 dtM +0.0 TMax +--------------------- OUTPUTS ------------------------------------------------ +FairTen1 +AnchTen1 +--------------------- END ---------------------------------------------------- diff --git a/tests/data/anchor_crease_tabulated.dat b/tests/data/anchor_crease_tabulated.dat new file mode 100644 index 00000000..cb51ec8a --- /dev/null +++ b/tests/data/anchor_crease_tabulated.dat @@ -0,0 +1,31 @@ +--------------------- CableDyn Input File ------------------------------------ +Fixed anchor at the tabulated depth of a creased grid node (V valley): rests on the seabed, placed on the rounded surface +--------------------- LINE TYPES --------------------------------------------- +TypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-) +chain 0.12 300.0 1.2e9 -1 0 1.2 0.4 1 0 +--------------------- POINTS ------------------------------------------------- +ID Type X Y Z +(-) (-) (m) (m) (m) +1 Coupled 0.0 0.0 -20.0 +2 Fixed 300.0 0.0 -120.0 +--------------------- LINES -------------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +--------------------- SECTIONS ----------------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 chain 350.0 35 +--------------------- OPTIONS ------------------------------------------------ +9.80665 g +1025.0 rhoW +bathy_v_valley.txt bathymetryFile +1.0e5 kBot +1.0e4 cBot +0.05 dtM +0.0 TMax +--------------------- OUTPUTS ------------------------------------------------ +FairTen1 +AnchTen1 +--------------------- END ---------------------------------------------------- diff --git a/tests/data/bathy_v_valley.txt b/tests/data/bathy_v_valley.txt new file mode 100644 index 00000000..69535adb --- /dev/null +++ b/tests/data/bathy_v_valley.txt @@ -0,0 +1,103 @@ +# x y depth: a V valley along y, deepest (120 m) at x = 300 m, slopes +-0.1 +0.0 -50.0 90.000000 +0.0 50.0 90.000000 +10.0 -50.0 91.000000 +10.0 50.0 91.000000 +20.0 -50.0 92.000000 +20.0 50.0 92.000000 +30.0 -50.0 93.000000 +30.0 50.0 93.000000 +40.0 -50.0 94.000000 +40.0 50.0 94.000000 +50.0 -50.0 95.000000 +50.0 50.0 95.000000 +60.0 -50.0 96.000000 +60.0 50.0 96.000000 +70.0 -50.0 97.000000 +70.0 50.0 97.000000 +80.0 -50.0 98.000000 +80.0 50.0 98.000000 +90.0 -50.0 99.000000 +90.0 50.0 99.000000 +100.0 -50.0 100.000000 +100.0 50.0 100.000000 +110.0 -50.0 101.000000 +110.0 50.0 101.000000 +120.0 -50.0 102.000000 +120.0 50.0 102.000000 +130.0 -50.0 103.000000 +130.0 50.0 103.000000 +140.0 -50.0 104.000000 +140.0 50.0 104.000000 +150.0 -50.0 105.000000 +150.0 50.0 105.000000 +160.0 -50.0 106.000000 +160.0 50.0 106.000000 +170.0 -50.0 107.000000 +170.0 50.0 107.000000 +180.0 -50.0 108.000000 +180.0 50.0 108.000000 +190.0 -50.0 109.000000 +190.0 50.0 109.000000 +200.0 -50.0 110.000000 +200.0 50.0 110.000000 +210.0 -50.0 111.000000 +210.0 50.0 111.000000 +220.0 -50.0 112.000000 +220.0 50.0 112.000000 +230.0 -50.0 113.000000 +230.0 50.0 113.000000 +240.0 -50.0 114.000000 +240.0 50.0 114.000000 +250.0 -50.0 115.000000 +250.0 50.0 115.000000 +260.0 -50.0 116.000000 +260.0 50.0 116.000000 +270.0 -50.0 117.000000 +270.0 50.0 117.000000 +280.0 -50.0 118.000000 +280.0 50.0 118.000000 +290.0 -50.0 119.000000 +290.0 50.0 119.000000 +300.0 -50.0 120.000000 +300.0 50.0 120.000000 +310.0 -50.0 119.000000 +310.0 50.0 119.000000 +320.0 -50.0 118.000000 +320.0 50.0 118.000000 +330.0 -50.0 117.000000 +330.0 50.0 117.000000 +340.0 -50.0 116.000000 +340.0 50.0 116.000000 +350.0 -50.0 115.000000 +350.0 50.0 115.000000 +360.0 -50.0 114.000000 +360.0 50.0 114.000000 +370.0 -50.0 113.000000 +370.0 50.0 113.000000 +380.0 -50.0 112.000000 +380.0 50.0 112.000000 +390.0 -50.0 111.000000 +390.0 50.0 111.000000 +400.0 -50.0 110.000000 +400.0 50.0 110.000000 +410.0 -50.0 109.000000 +410.0 50.0 109.000000 +420.0 -50.0 108.000000 +420.0 50.0 108.000000 +430.0 -50.0 107.000000 +430.0 50.0 107.000000 +440.0 -50.0 106.000000 +440.0 50.0 106.000000 +450.0 -50.0 105.000000 +450.0 50.0 105.000000 +460.0 -50.0 104.000000 +460.0 50.0 104.000000 +470.0 -50.0 103.000000 +470.0 50.0 103.000000 +480.0 -50.0 102.000000 +480.0 50.0 102.000000 +490.0 -50.0 101.000000 +490.0 50.0 101.000000 +500.0 -50.0 100.000000 +500.0 50.0 100.000000 diff --git a/tests/data/cable_statics_matrix.json b/tests/data/cable_statics_matrix.json index 9dbfcde3..f96d6514 100644 --- a/tests/data/cable_statics_matrix.json +++ b/tests/data/cable_statics_matrix.json @@ -1526,5 +1526,91 @@ "reference": "OrcaFlex 11.6 unseeded statics (bow behind the fairlead)" } } + }, + { + "id": "ROUGH_1001", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1001\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 10000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 520 52\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -100 100.007047\n-100 100 100.007047\n-75 -100 100.013966\n-75 100 100.013966\n-50 -100 99.993963\n-50 100 99.993963\n-25 -100 100.017103\n-25 100 100.017103\n0 -100 99.998565\n0 100 99.998565\n25 -100 100.005372\n25 100 100.005372\n50 -100 100.017680\n50 100 100.017680\n75 -100 99.999703\n75 100 99.999703\n100 -100 100.018500\n100 100 100.018500\n125 -100 100.002654\n125 100 100.002654\n150 -100 100.017206\n150 100 100.017206\n175 -100 100.016371\n175 100 100.016371\n200 -100 100.003019\n200 100 100.003019\n225 -100 99.986926\n225 100 99.986926\n250 -100 100.015048\n250 100 100.015048\n275 -100 100.011070\n275 100 100.011070\n300 -100 99.994903\n300 100 99.994903\n325 -100 99.982092\n325 100 99.982092\n350 -100 99.996916\n350 100 99.996916\n375 -100 100.004133\n375 100 100.004133\n400 -100 99.980950\n400 100 99.980950\n425 -100 100.018137\n425 100 100.018137\n450 -100 100.000000\n450 100 100.000000\n475 -100 100.008416\n475 100 100.008416\n500 -100 100.014230\n500 100 100.014230\n525 -100 100.015288\n525 100 100.015288\n550 -100 100.007661\n550 100 100.007661\n575 -100 99.987355\n575 100 99.987355\n600 -100 100.012771\n600 100 100.012771\n", + "lines": { + "1": { + "oracle_tfair": [ + 243723.25360260083 + ], + "lambda_over_length": 0.003076732677984292 + } + }, + "why": "2 cm roughness on a 25 m survey grid along the chord: the catenary seed laid on the plane fitted along the chord dips below the actual bed and was rejected" + }, + { + "id": "ROUGH_1001__x4", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1001\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 10000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 520 208\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -100 100.007047\n-100 100 100.007047\n-75 -100 100.013966\n-75 100 100.013966\n-50 -100 99.993963\n-50 100 99.993963\n-25 -100 100.017103\n-25 100 100.017103\n0 -100 99.998565\n0 100 99.998565\n25 -100 100.005372\n25 100 100.005372\n50 -100 100.017680\n50 100 100.017680\n75 -100 99.999703\n75 100 99.999703\n100 -100 100.018500\n100 100 100.018500\n125 -100 100.002654\n125 100 100.002654\n150 -100 100.017206\n150 100 100.017206\n175 -100 100.016371\n175 100 100.016371\n200 -100 100.003019\n200 100 100.003019\n225 -100 99.986926\n225 100 99.986926\n250 -100 100.015048\n250 100 100.015048\n275 -100 100.011070\n275 100 100.011070\n300 -100 99.994903\n300 100 99.994903\n325 -100 99.982092\n325 100 99.982092\n350 -100 99.996916\n350 100 99.996916\n375 -100 100.004133\n375 100 100.004133\n400 -100 99.980950\n400 100 99.980950\n425 -100 100.018137\n425 100 100.018137\n450 -100 100.000000\n450 100 100.000000\n475 -100 100.008416\n475 100 100.008416\n500 -100 100.014230\n500 100 100.014230\n525 -100 100.015288\n525 100 100.015288\n550 -100 100.007661\n550 100 100.007661\n575 -100 99.987355\n575 100 99.987355\n600 -100 100.012771\n600 100 100.012771\n", + "lines": { + "1": { + "oracle_tfair": [ + 243723.25360260083 + ], + "lambda_over_length": 0.003076732677984292 + } + }, + "mesh_of": "ROUGH_1001" + }, + { + "id": "ROUGH_1002", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1002\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 10000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 520 52\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -50 100.479050\n-100 -25 99.956298\n-100 0 100.218847\n-100 25 100.234886\n-100 50 99.714902\n-75 -50 99.578038\n-75 -25 100.102743\n-75 0 99.621920\n-75 25 99.882227\n-75 50 100.389703\n-50 -50 100.372150\n-50 -25 99.618689\n-50 0 99.582234\n-50 25 99.722486\n-50 50 100.328091\n-25 -50 99.524724\n-25 -25 99.725183\n-25 0 99.607237\n-25 25 99.627638\n-25 50 100.023425\n0 -50 99.683432\n0 -25 99.909443\n0 0 100.233186\n0 25 100.222996\n0 50 99.915038\n25 -50 100.286135\n25 -25 100.072508\n25 0 100.326960\n25 25 99.748882\n25 50 99.869124\n50 -50 100.080335\n50 -25 100.445894\n50 0 100.118340\n50 25 99.974702\n50 50 99.750958\n75 -50 99.781334\n75 -25 99.715787\n75 0 100.486365\n75 25 100.386585\n75 50 100.394562\n100 -50 100.028569\n100 -25 100.208384\n100 0 99.796489\n100 25 99.981570\n100 50 99.645541\n125 -50 99.920140\n125 -25 99.752703\n125 0 99.599977\n125 25 100.419444\n125 50 99.596683\n150 -50 100.312931\n150 -25 100.199579\n150 0 99.590054\n150 25 99.985153\n150 50 100.495864\n175 -50 100.486862\n175 -25 100.063301\n175 0 100.271809\n175 25 100.208675\n175 50 99.791773\n200 -50 100.049937\n200 -25 100.096940\n200 0 99.894056\n200 25 100.318999\n200 50 99.944214\n225 -50 100.249489\n225 -25 99.564686\n225 0 99.944886\n225 25 99.544437\n225 50 100.146835\n250 -50 100.372658\n250 -25 100.043461\n250 0 100.065392\n250 25 100.122490\n250 50 99.729051\n275 -50 99.886257\n275 -25 100.078519\n275 0 100.146282\n275 25 99.880062\n275 50 99.977378\n300 -50 99.830789\n300 -25 100.054298\n300 0 100.175973\n300 25 99.827767\n300 50 100.184997\n325 -50 100.348974\n325 -25 100.036438\n325 0 100.480373\n325 25 99.809500\n325 50 100.419563\n350 -50 99.681901\n350 -25 99.863435\n350 0 100.316853\n350 25 99.532582\n350 50 100.114491\n375 -50 100.371317\n375 -25 100.443995\n375 0 100.182182\n375 25 99.845560\n375 50 99.832293\n400 -50 100.131142\n400 -25 99.566722\n400 0 99.528134\n400 25 100.381660\n400 50 100.126901\n425 -50 99.662861\n425 -25 99.928740\n425 0 99.789076\n425 25 100.369287\n425 50 99.786241\n450 -50 100.000000\n450 -25 100.000000\n450 0 100.000000\n450 25 100.000000\n450 50 100.000000\n475 -50 100.224425\n475 -25 100.243785\n475 0 99.818759\n475 25 99.752101\n475 50 100.021113\n500 -50 99.899723\n500 -25 100.093981\n500 0 99.828157\n500 25 100.294504\n500 50 99.920302\n525 -50 99.636143\n525 -25 100.274531\n525 0 100.395030\n525 25 100.181164\n525 50 100.046519\n550 -50 100.371789\n550 -25 100.433795\n550 0 99.509263\n550 25 99.987695\n550 50 99.518982\n575 -50 99.833524\n575 -25 99.741834\n575 0 99.961382\n575 25 100.177299\n575 50 100.360849\n600 -50 99.760829\n600 -25 99.511736\n600 0 100.499046\n600 25 100.282120\n600 50 100.050342\n", + "lines": { + "1": { + "oracle_tfair": [ + 243723.25360260083 + ], + "lambda_over_length": 0.003076732677984292 + } + }, + "why": "0.5 m roughness on a 25 m grid in both directions (the catenary seed meets the actual bed)" + }, + { + "id": "ROUGH_1002__x4", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1002\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 10000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 520 208\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -50 100.479050\n-100 -25 99.956298\n-100 0 100.218847\n-100 25 100.234886\n-100 50 99.714902\n-75 -50 99.578038\n-75 -25 100.102743\n-75 0 99.621920\n-75 25 99.882227\n-75 50 100.389703\n-50 -50 100.372150\n-50 -25 99.618689\n-50 0 99.582234\n-50 25 99.722486\n-50 50 100.328091\n-25 -50 99.524724\n-25 -25 99.725183\n-25 0 99.607237\n-25 25 99.627638\n-25 50 100.023425\n0 -50 99.683432\n0 -25 99.909443\n0 0 100.233186\n0 25 100.222996\n0 50 99.915038\n25 -50 100.286135\n25 -25 100.072508\n25 0 100.326960\n25 25 99.748882\n25 50 99.869124\n50 -50 100.080335\n50 -25 100.445894\n50 0 100.118340\n50 25 99.974702\n50 50 99.750958\n75 -50 99.781334\n75 -25 99.715787\n75 0 100.486365\n75 25 100.386585\n75 50 100.394562\n100 -50 100.028569\n100 -25 100.208384\n100 0 99.796489\n100 25 99.981570\n100 50 99.645541\n125 -50 99.920140\n125 -25 99.752703\n125 0 99.599977\n125 25 100.419444\n125 50 99.596683\n150 -50 100.312931\n150 -25 100.199579\n150 0 99.590054\n150 25 99.985153\n150 50 100.495864\n175 -50 100.486862\n175 -25 100.063301\n175 0 100.271809\n175 25 100.208675\n175 50 99.791773\n200 -50 100.049937\n200 -25 100.096940\n200 0 99.894056\n200 25 100.318999\n200 50 99.944214\n225 -50 100.249489\n225 -25 99.564686\n225 0 99.944886\n225 25 99.544437\n225 50 100.146835\n250 -50 100.372658\n250 -25 100.043461\n250 0 100.065392\n250 25 100.122490\n250 50 99.729051\n275 -50 99.886257\n275 -25 100.078519\n275 0 100.146282\n275 25 99.880062\n275 50 99.977378\n300 -50 99.830789\n300 -25 100.054298\n300 0 100.175973\n300 25 99.827767\n300 50 100.184997\n325 -50 100.348974\n325 -25 100.036438\n325 0 100.480373\n325 25 99.809500\n325 50 100.419563\n350 -50 99.681901\n350 -25 99.863435\n350 0 100.316853\n350 25 99.532582\n350 50 100.114491\n375 -50 100.371317\n375 -25 100.443995\n375 0 100.182182\n375 25 99.845560\n375 50 99.832293\n400 -50 100.131142\n400 -25 99.566722\n400 0 99.528134\n400 25 100.381660\n400 50 100.126901\n425 -50 99.662861\n425 -25 99.928740\n425 0 99.789076\n425 25 100.369287\n425 50 99.786241\n450 -50 100.000000\n450 -25 100.000000\n450 0 100.000000\n450 25 100.000000\n450 50 100.000000\n475 -50 100.224425\n475 -25 100.243785\n475 0 99.818759\n475 25 99.752101\n475 50 100.021113\n500 -50 99.899723\n500 -25 100.093981\n500 0 99.828157\n500 25 100.294504\n500 50 99.920302\n525 -50 99.636143\n525 -25 100.274531\n525 0 100.395030\n525 25 100.181164\n525 50 100.046519\n550 -50 100.371789\n550 -25 100.433795\n550 0 99.509263\n550 25 99.987695\n550 50 99.518982\n575 -50 99.833524\n575 -25 99.741834\n575 0 99.961382\n575 25 100.177299\n575 50 100.360849\n600 -50 99.760829\n600 -25 99.511736\n600 0 100.499046\n600 25 100.282120\n600 50 100.050342\n", + "lines": { + "1": { + "oracle_tfair": [ + 243723.25360260083 + ], + "lambda_over_length": 0.003076732677984292 + } + }, + "mesh_of": "ROUGH_1002" + }, + { + "id": "ROUGH_1003", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1003\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 1000000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 545 109\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -100 100.007047\n-100 100 100.007047\n-75 -100 100.013966\n-75 100 100.013966\n-50 -100 99.993963\n-50 100 99.993963\n-25 -100 100.017103\n-25 100 100.017103\n0 -100 99.998565\n0 100 99.998565\n25 -100 100.005372\n25 100 100.005372\n50 -100 100.017680\n50 100 100.017680\n75 -100 99.999703\n75 100 99.999703\n100 -100 100.018500\n100 100 100.018500\n125 -100 100.002654\n125 100 100.002654\n150 -100 100.017206\n150 100 100.017206\n175 -100 100.016371\n175 100 100.016371\n200 -100 100.003019\n200 100 100.003019\n225 -100 99.986926\n225 100 99.986926\n250 -100 100.015048\n250 100 100.015048\n275 -100 100.011070\n275 100 100.011070\n300 -100 99.994903\n300 100 99.994903\n325 -100 99.982092\n325 100 99.982092\n350 -100 99.996916\n350 100 99.996916\n375 -100 100.004133\n375 100 100.004133\n400 -100 99.980950\n400 100 99.980950\n425 -100 100.018137\n425 100 100.018137\n450 -100 100.000000\n450 100 100.000000\n475 -100 100.008416\n475 100 100.008416\n500 -100 100.014230\n500 100 100.014230\n525 -100 100.015288\n525 100 100.015288\n550 -100 100.007661\n550 100 100.007661\n575 -100 99.987355\n575 100 99.987355\n600 -100 100.012771\n600 100 100.012771\n", + "lines": { + "1": { + "oracle_tfair": [], + "lambda_over_length": 0.013625839599843271 + } + }, + "why": "a line 5 m longer than its span plus rise over the rough seabed: the anchor walk traces the equilibrium its bending stiffness holds (FairTen within 0.01 % of the flat-seabed walk)" + }, + { + "id": "ROUGH_1003__x2", + "expect": "admissible", + "deck": "--------------------- CableDyn Input File ---------------------------\nROUGH_1003\n--------------------- LINE TYPES ------------------------------------\nTypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t\n(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-)\nchain 0.216 286.56 1229760000 -1 1000000 1.37 0.64 1 0\n--------------------- POINTS ----------------------------------------\nID Type X Y Z\n(-) (-) (m) (m) (m)\n1 Coupled 0 0 -10\n2 Fixed 450 0 -100\n--------------------- LINES -----------------------------------------\nID NodeA NodeB Outputs\n(-) (-) (-) (-)\n1 1 2 -\n--------------------- SECTIONS --------------------------------------\nLineID LineType Length NumSegs\n(-) (-) (m) (-)\n1 chain 545 218\n--------------------- OPTIONS ---------------------------------------\n9.80665 g\n1025.0 rhoW\nbathy.txt bathymetryFile\n100000 kBot\n1.0e4 cBot\n0.05 dtM\n0.0 TMax\n--------------------- OUTPUTS ---------------------------------------\n\"FairTen1\"\n\"AnchTen1\"\n--------------------- need this line --------------------------------\n", + "bathy": "# x y depth\n-100 -100 100.007047\n-100 100 100.007047\n-75 -100 100.013966\n-75 100 100.013966\n-50 -100 99.993963\n-50 100 99.993963\n-25 -100 100.017103\n-25 100 100.017103\n0 -100 99.998565\n0 100 99.998565\n25 -100 100.005372\n25 100 100.005372\n50 -100 100.017680\n50 100 100.017680\n75 -100 99.999703\n75 100 99.999703\n100 -100 100.018500\n100 100 100.018500\n125 -100 100.002654\n125 100 100.002654\n150 -100 100.017206\n150 100 100.017206\n175 -100 100.016371\n175 100 100.016371\n200 -100 100.003019\n200 100 100.003019\n225 -100 99.986926\n225 100 99.986926\n250 -100 100.015048\n250 100 100.015048\n275 -100 100.011070\n275 100 100.011070\n300 -100 99.994903\n300 100 99.994903\n325 -100 99.982092\n325 100 99.982092\n350 -100 99.996916\n350 100 99.996916\n375 -100 100.004133\n375 100 100.004133\n400 -100 99.980950\n400 100 99.980950\n425 -100 100.018137\n425 100 100.018137\n450 -100 100.000000\n450 100 100.000000\n475 -100 100.008416\n475 100 100.008416\n500 -100 100.014230\n500 100 100.014230\n525 -100 100.015288\n525 100 100.015288\n550 -100 100.007661\n550 100 100.007661\n575 -100 99.987355\n575 100 99.987355\n600 -100 100.012771\n600 100 100.012771\n", + "lines": { + "1": { + "oracle_tfair": [], + "lambda_over_length": 0.013625839599843271 + } + }, + "mesh_of": "ROUGH_1003" } ] diff --git a/tests/test_bathymetry.f90 b/tests/test_bathymetry.f90 index 64420b66..b3a0b2cf 100644 --- a/tests/test_bathymetry.f90 +++ b/tests/test_bathymetry.f90 @@ -4,12 +4,15 @@ PROGRAM test_bathymetry !! Unit tests for the structured bathymetry service and variable-elevation !! seabed contact tangent. These tests are self-contained analytical checks: - !! bilinear interpolation on a plane, edge clamping, and fail-closed validation. + !! bilinear interpolation on a plane, edge clamping, fail-closed validation, and the + !! C2 rounding of the creases of a non-planar grid. USE CableDyn_Precision, ONLY: wp USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Init_Bathymetry, CD_End_Bathymetry, & CD_Bathymetry_Depth, CD_Bathymetry_Floor, & CD_Bathymetry_Floor_Gradient, CD_Bathymetry_Seabed_Load, & - CD_Bathymetry_Is_Initialized, CD_BATHY_OK, CD_BATHY_BADINPUT + CD_Bathymetry_Is_Initialized, CD_BATHY_OK, CD_BATHY_BADINPUT, & + CD_Bathymetry_Grid_Floor, CD_Bathymetry_Rotate_Curvature, & + CD_BATHY_CREASE_FRACTION USE CableDyn_SeabedContact, ONLY: CD_SEABED_CONTACT_BLEND USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN IMPLICIT NONE @@ -21,6 +24,9 @@ PROGRAM test_bathymetry CALL case_variable_seabed_contact_tangent() CALL case_variable_seabed_tangent_fd() CALL case_fail_closed_inputs() + CALL case_crease_rounding_c2() + CALL case_crease_rounding_planar_exact() + CALL case_crease_contact_tangent_fd() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -255,6 +261,200 @@ SUBROUTINE case_fail_closed_inputs() CALL CD_End_Bathymetry(bathy) END SUBROUTINE case_fail_closed_inputs + SUBROUTINE init_creased_bathy(bathy) + !! A non-planar grid with creases along every interior line (non-uniform spacing). + TYPE(CD_BathymetryType), INTENT(OUT) :: bathy + REAL(wp) :: x(5), y(4), depth(5, 4) + INTEGER :: i, j, es + CHARACTER(160) :: em + x = [0.0_wp, 10.0_wp, 25.0_wp, 30.0_wp, 42.0_wp] + y = [-5.0_wp, 8.0_wp, 20.0_wp, 26.0_wp] + DO j = 1, SIZE(y) + DO i = 1, SIZE(x) + depth(i, j) = 100.0_wp + 2.0_wp*SIN(0.37_wp*x(i) + 0.11_wp*y(j)) + & + 1.5_wp*COS(0.23_wp*y(j) - 0.05_wp*x(i)) + 0.1_wp*REAL(MOD(3*i + 5*j, 7), wp) + END DO + END DO + CALL CD_Init_Bathymetry(bathy, x, y, depth, es, em) + CALL expect_es(es, CD_BATHY_OK, 'crease:init') + END SUBROUTINE init_creased_bathy + + SUBROUTINE floor_at(bathy, x, y, z, g) + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + REAL(wp), INTENT(IN) :: x, y + REAL(wp), INTENT(OUT) :: z, g(2) + INTEGER :: es + CHARACTER(160) :: em + CALL CD_Bathymetry_Floor_Gradient(bathy, x, y, z, g(1), g(2), es, em) + CALL expect_es(es, CD_BATHY_OK, 'crease:query') + END SUBROUTINE floor_at + + SUBROUTINE case_crease_rounding_c2() + !! The rounded surface is C2: height, gradient and the curvatures z_xx and z_yy are + !! continuous across every interior grid line (at a crossing as well) and at the edges + !! of the bands; the gradient is the derivative of the height and the curvature that + !! of the gradient (central differences); outside the bands the surface is the + !! bilinear one, bit for bit; inside a band it moves by at most a sixth of the slope + !! jump times the band half-width. + TYPE(CD_BathymetryType) :: bathy + REAL(wp), PARAMETER :: EPS = 1.0e-9_wp, H = 1.0e-5_wp + REAL(wp), PARAMETER :: LINES_X(3) = [10.0_wp, 25.0_wp, 30.0_wp], LINES_Y(2) = [8.0_wp, 20.0_wp] + REAL(wp), PARAMETER :: ALONG_X(4) = [3.0_wp, 8.0_wp, 8.1_wp, 19.95_wp] + REAL(wp), PARAMETER :: ALONG_Y(4) = [4.0_wp, 10.0_wp, 9.8_wp, 29.9_wp] + REAL(wp) :: za, zb, ga(2), gb(2), zg, z, g(2), gp(2), gm(2), zp, zm, curv(3), delta, dz, ca(3), cb(3) + REAL(wp) :: pts(2, 6), zpp, zpm, zmp, zmm, twist + INTEGER :: k, j, es + CHARACTER(160) :: em + + CALL init_creased_bathy(bathy) + ! across the x lines, away from and at the crossings with the y lines + DO k = 1, SIZE(LINES_X) + DO j = 1, SIZE(ALONG_X) + CALL CD_Bathymetry_Floor_Gradient(bathy, LINES_X(k) - EPS, ALONG_X(j), za, ga(1), ga(2), es, em, & + crease_curvature=ca) + CALL CD_Bathymetry_Floor_Gradient(bathy, LINES_X(k) + EPS, ALONG_X(j), zb, gb(1), gb(2), es, em, & + crease_curvature=cb) + CALL require(ABS(za - zb) <= 1.0e-8_wp, 'crease:x-line height continuous') + CALL require(MAXVAL(ABS(ga - gb)) <= 1.0e-6_wp, 'crease:x-line gradient continuous') + CALL require(ABS(ca(1) - cb(1)) <= 1.0e-5_wp .AND. ABS(ca(3) - cb(3)) <= 1.0e-5_wp, & + 'crease:x-line curvature continuous') + END DO + END DO + DO k = 1, SIZE(LINES_Y) + DO j = 1, SIZE(ALONG_Y) + CALL CD_Bathymetry_Floor_Gradient(bathy, ALONG_Y(j), LINES_Y(k) - EPS, za, ga(1), ga(2), es, em, & + crease_curvature=ca) + CALL CD_Bathymetry_Floor_Gradient(bathy, ALONG_Y(j), LINES_Y(k) + EPS, zb, gb(1), gb(2), es, em, & + crease_curvature=cb) + CALL require(ABS(za - zb) <= 1.0e-8_wp, 'crease:y-line height continuous') + CALL require(MAXVAL(ABS(ga - gb)) <= 1.0e-6_wp, 'crease:y-line gradient continuous') + CALL require(ABS(ca(1) - cb(1)) <= 1.0e-5_wp .AND. ABS(ca(3) - cb(3)) <= 1.0e-5_wp, & + 'crease:y-line curvature continuous') + END DO + END DO + ! at the band edge of the x line 25 (half-width 5 % of the smaller spacing, 5 m) + delta = CD_BATHY_CREASE_FRACTION*5.0_wp + CALL CD_Bathymetry_Floor_Gradient(bathy, 25.0_wp + delta - EPS, 3.0_wp, za, ga(1), ga(2), es, em, & + crease_curvature=ca) + CALL CD_Bathymetry_Floor_Gradient(bathy, 25.0_wp + delta + EPS, 3.0_wp, zb, gb(1), gb(2), es, em, & + crease_curvature=cb) + CALL require(ABS(za - zb) <= 1.0e-8_wp .AND. MAXVAL(ABS(ga - gb)) <= 1.0e-6_wp .AND. & + MAXVAL(ABS(ca - cb)) <= 1.0e-5_wp, 'crease:band edge C2') + ! outside every band (and outside the grid): exactly the bilinear surface + pts = RESHAPE([5.0_wp, 2.0_wp, 17.0_wp, 14.0_wp, 27.5_wp, 23.0_wp, 36.0_wp, 0.0_wp, -3.0_wp, 14.0_wp, & + 50.0_wp, 30.0_wp], [2, 6]) + DO j = 1, SIZE(pts, 2) + CALL floor_at(bathy, pts(1, j), pts(2, j), z, g) + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j), pts(2, j), zg, es, em) + CALL require(z == zg, 'crease:outside the bands the surface is bilinear') + END DO + ! gradient and curvature against central differences inside bands and at crossings + pts = RESHAPE([10.2_wp, 3.0_wp, 24.9_wp, 14.0_wp, 4.0_wp, 7.7_wp, 29.92_wp, 20.1_wp, 10.1_wp, 8.2_wp, & + 25.05_wp, 19.97_wp], [2, 6]) + DO j = 1, SIZE(pts, 2) + CALL CD_Bathymetry_Floor_Gradient(bathy, pts(1, j), pts(2, j), z, g(1), g(2), es, em, crease_curvature=curv) + CALL floor_at(bathy, pts(1, j) + H, pts(2, j), zp, gp) + CALL floor_at(bathy, pts(1, j) - H, pts(2, j), zm, gm) + CALL require(ABS((zp - zm)/(2.0_wp*H) - g(1)) <= 1.0e-6_wp, 'crease:dz/dx') + ! the rounding's curvature: the bilinear part of z_xx is zero within a cell + CALL require(ABS((gp(1) - gm(1))/(2.0_wp*H) - curv(1)) <= 1.0e-4_wp*MAX(1.0_wp, ABS(curv(1))), & + 'crease:z_xx') + CALL floor_at(bathy, pts(1, j), pts(2, j) + H, zp, gp) + CALL floor_at(bathy, pts(1, j), pts(2, j) - H, zm, gm) + CALL require(ABS((zp - zm)/(2.0_wp*H) - g(2)) <= 1.0e-6_wp, 'crease:dz/dy') + CALL require(ABS((gp(2) - gm(2))/(2.0_wp*H) - curv(3)) <= 1.0e-4_wp*MAX(1.0_wp, ABS(curv(3))), & + 'crease:z_yy') + ! z_xy of the rounding: the y-derivative of z_x less the twist of the bilinear cell, + ! which the curvature leaves out (a four-point difference of the bilinear surface) + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j) + H, pts(2, j) + H, zpp, es, em) + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j) + H, pts(2, j) - H, zpm, es, em) + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j) - H, pts(2, j) + H, zmp, es, em) + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j) - H, pts(2, j) - H, zmm, es, em) + twist = (zpp - zpm - zmp + zmm)/(4.0_wp*H*H) + CALL require(ABS((gp(1) - gm(1))/(2.0_wp*H) - twist - curv(2)) <= 1.0e-4_wp*MAX(1.0_wp, ABS(curv(2))), & + 'crease:z_xy') + CALL CD_Bathymetry_Grid_Floor(bathy, pts(1, j), pts(2, j), zg, es, em) + dz = ABS(z - zg) + ! slope jumps below 1 here: a band of half-width <= 0.6 m moves the surface by < 0.1 m + CALL require(dz > 0.0_wp .AND. dz <= 0.1_wp, 'crease:bounded rounding inside a band') + END DO + ! the turned curvature is the Hessian in the turned frame (90 degrees: xx <-> yy) + curv = CD_Bathymetry_Rotate_Curvature([1.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 1.0_wp]) + CALL require(ABS(curv(1)) <= 1.0e-15_wp .AND. ABS(curv(2)) <= 1.0e-15_wp .AND. & + ABS(curv(3) - 1.0_wp) <= 1.0e-15_wp, 'crease:turned curvature') + CALL CD_End_Bathymetry(bathy) + END SUBROUTINE case_crease_rounding_c2 + + SUBROUTINE case_crease_rounding_planar_exact() + !! A planar grid has no crease: the surface and its gradient are the bilinear ones bit + !! for bit everywhere, inside the bands too, also for a plane written to six decimals. + TYPE(CD_BathymetryType) :: bathy + REAL(wp) :: x(4), y(3), depth(4, 3), z, zg, g(2), curv(3), xq, yq + INTEGER :: i, j, k, es + CHARACTER(160) :: em + x = [0.0_wp, 10.0_wp, 25.0_wp, 30.0_wp] + y = [-5.0_wp, 8.0_wp, 20.0_wp] + DO k = 1, 2 + DO j = 1, SIZE(y) + DO i = 1, SIZE(x) + depth(i, j) = 388.949782_wp + 0.0732_wp*x(i) - 0.0417_wp*y(j) + IF (k == 2) depth(i, j) = ANINT(depth(i, j)*1.0e6_wp)/1.0e6_wp + END DO + END DO + CALL CD_Init_Bathymetry(bathy, x, y, depth, es, em) + CALL expect_es(es, CD_BATHY_OK, 'planar:init') + DO j = 0, 40 + DO i = 0, 40 + xq = -1.0_wp + 32.0_wp*REAL(i, wp)/40.0_wp + 0.01_wp*REAL(MOD(j, 3), wp) + yq = -6.0_wp + 27.0_wp*REAL(j, wp)/40.0_wp + CALL CD_Bathymetry_Floor_Gradient(bathy, xq, yq, z, g(1), g(2), es, em, crease_curvature=curv) + CALL CD_Bathymetry_Grid_Floor(bathy, xq, yq, zg, es, em) + CALL require(z == zg .AND. ALL(curv == 0.0_wp), 'planar:bit-identical bilinear surface') + END DO + END DO + ! on the lines themselves (inside every band) + CALL CD_Bathymetry_Floor(bathy, 10.0_wp, 8.0_wp, z, es, em) + CALL CD_Bathymetry_Grid_Floor(bathy, 10.0_wp, 8.0_wp, zg, es, em) + CALL require(z == zg, 'planar:bit-identical at a crossing') + END DO + CALL CD_End_Bathymetry(bathy) + END SUBROUTINE case_crease_rounding_planar_exact + + SUBROUTINE case_crease_contact_tangent_fd() + !! In a band (at a crossing of two lines) the contact force is the gradient of the + !! penalty potential of the rounded surface, and its residual tangent the Hessian: + !! k_resid(:, j) = -d f/d q_j against central differences (to 1 % of the largest + !! entry: the tangent leaves out the third derivatives of the surface, a term of the + !! order of the force times the penetration times d(curvature)/dq), and symmetric. + TYPE(CD_BathymetryType) :: bathy + REAL(wp) :: nodes(3, 1), kn(1), f0(3), fp(3), fm(3), kres(3, 3), kbase(3, 3), fd_col(3), trial(3, 1), z + REAL(wp) :: h + INTEGER :: es, j + CHARACTER(160) :: em + CALL init_creased_bathy(bathy) + CALL CD_Bathymetry_Floor(bathy, 10.1_wp, 8.15_wp, z, es, em) + nodes(:, 1) = [10.1_wp, 8.15_wp, z - 0.05_wp] + kn = [2.0e4_wp] + h = 1.0e-6_wp + CALL CD_Bathymetry_Seabed_Load(bathy, nodes, kn, f0, kres, es, em) + CALL expect_es(es, CD_BATHY_OK, 'crease-fd:base') + kbase = kres + DO j = 1, 3 + trial = nodes + trial(j, 1) = trial(j, 1) + h + CALL CD_Bathymetry_Seabed_Load(bathy, trial, kn, fp, kres, es, em) + trial = nodes + trial(j, 1) = trial(j, 1) - h + CALL CD_Bathymetry_Seabed_Load(bathy, trial, kn, fm, kres, es, em) + fd_col = -(fp - fm)/(2.0_wp*h) + CALL require(MAXVAL(ABS(kbase(:, j) - fd_col)) <= 1.0e-2_wp*MAXVAL(ABS(kbase)), 'crease-fd:kcol') + END DO + ! the node is in contact (the tangent above is not trivially zero) + CALL require(ABS(f0(3)) > 0.0_wp, 'crease-fd:in contact') + CALL require(MAXVAL(ABS(kbase - TRANSPOSE(kbase))) <= 1.0e-9_wp*MAXVAL(ABS(kbase)), 'crease-fd:symmetric') + CALL CD_End_Bathymetry(bathy) + END SUBROUTINE case_crease_contact_tangent_fd + SUBROUTINE expect_vec_fd(got, want, label) REAL(wp), INTENT(IN) :: got(:), want(:) CHARACTER(*), INTENT(IN) :: label diff --git a/tests/test_cable_statics_matrix.py b/tests/test_cable_statics_matrix.py index 769be723..b1be2c32 100644 --- a/tests/test_cable_statics_matrix.py +++ b/tests/test_cable_statics_matrix.py @@ -6,7 +6,7 @@ A deterministic sample of finite-EI (cubic-Hermite) cable decks drawn from a seeded robustness study: lazy waves (single and modular buoyancy, some floating at the surface), steep and lazy-S waves, heavy catenaries, lines hung in mid-water, sloped -structured seabeds, azimuthal layouts, rotationally restrained hang-offs, current and +and rough structured seabeds, azimuthal layouts, rotationally restrained hang-offs, current and friction options, mixed mooring + cable decks, refined meshes, and metamorphic twins (translated, rotated, anchor-first, split sections, constant-depth grid). Every deck is run through the standalone driver and checked against its committed expectation: diff --git a/tests/test_statics_robustness.py b/tests/test_statics_robustness.py index 96a28e11..465a8ca1 100644 --- a/tests/test_statics_robustness.py +++ b/tests/test_statics_robustness.py @@ -5,11 +5,13 @@ A deterministic sample of the regimes a mooring designer meets -- grounded catenary, semi-taut, taut, fully suspended, multi-section composite, nearly taut, slack (the H -> 0 limit), vertical, -anchors just off the seabed, sloped seabed, fine meshes, soft seabed, steady current, one- and -two-segment lines, and Free/Connect points -- is written as cabledyn decks and solved by the -production executable. Every case must converge with no compressed element and an independent -nodal force balance (tensions, lumped weight, penalty seabed along the local normal, Morison -drag). Cases with a continuous elastic-catenary solution also match it (element tensions and the +anchors just off the seabed, sloped seabed, gridded seabeds with a trench or 2D roughness (their +creases rounded as in the solver), fine meshes, soft seabed, steady current, one- and two-segment +lines, and Free/Connect points -- is written as cabledyn decks and solved by the production +executable. Every case must converge with no compressed element and an independent nodal force +balance (tensions, lumped weight, penalty seabed along the local normal, or in a rounded crease +the gradient of its penalty potential, Morison drag); a trench deep enough to hold the excess +length slack at its bottom must show it, with the anchor tension of the run rising from there. Cases with a continuous elastic-catenary solution also match it (element tensions and the line-end forces FairTen/AnchTen); a subset is run through both the static-only and the dynamic (TMax = 0) route, which must report the same end tensions; an anchor genuinely below the seabed must be rejected with a clear message. @@ -239,7 +241,16 @@ def nodal_balance(case, root): s = math.sqrt(1 + gx * gx + gy * gy) pen = (zf - P[i, 2]) / s if pen > 0: - F[i] += kn[i] * pen * np.array([-gx, -gy, 1.0]) / s + hess = case["floor_hess"](P[i, 0], P[i, 1]) if "floor_hess" in case else None + if hess is None: + F[i] += kn[i] * pen * np.array([-gx, -gy, 1.0]) / s + else: + # in a rounded crease: the gradient of the penalty potential of the + # normal penetration g = (zf - z)/s, force = -k g dg/dq + fxx, fxy, fyy = hess + ds = np.array([gx * fxx + gy * fxy, gx * fxy + gy * fyy, 0.0]) / s + dg = np.array([gx, gy, -1.0]) / s - (zf - P[i, 2]) * ds / s**2 + F[i] -= kn[i] * pen * dg if "current" in case: # a depth profile is sampled at each node's own elevation (as the dynamics do) vel = [case["current"](z) for z in P[:, 2]] @@ -261,11 +272,67 @@ def nodal_balance(case, root): return worst +# ------------------------------------------------------------------ rounded bathymetry +class RoundedGrid: + """The solver's seabed of a structured grid, written independently in basis form. + + z(x, y) = sum_ij z_ij phi_i(x) psi_j(y), with phi_i the hat functions of the x grid whose + kinks at the interior grid lines are rounded by the cubic fillet J (d - |u|)^3 / (6 d^2) + (J the slope jump of the hat there, d = 5 % of the smaller spacing next to the line); + likewise psi_j. Gradient and curvature by central differences of z. Data creases that + would move the surface by less than 1 micrometre are not rounded in the solver; the + grids used here have none. + """ + + def __init__(self, xs, ys, z): + self.xs, self.ys, self.z = np.asarray(xs, float), np.asarray(ys, float), np.asarray(z, float) + + @staticmethod + def _basis(axis, q): + n = axis.size + q = min(max(q, axis[0]), axis[-1]) + phi = np.zeros(n) + i = min(max(int(np.searchsorted(axis, q, side="right")) - 1, 0), n - 2) + t = (q - axis[i]) / (axis[i + 1] - axis[i]) + phi[i], phi[i + 1] = 1.0 - t, t + for k in range(1, n - 1): + d = 0.05 * min(axis[k] - axis[k - 1], axis[k + 1] - axis[k]) + u = abs(q - axis[k]) + if u >= d: + continue + h = (d - u) ** 3 / (6.0 * d * d) + # slope jumps of the hats at line k: hat k-1, k and k+1 + phi[k - 1] += h * (1.0 / (axis[k] - axis[k - 1])) + phi[k] += h * (-1.0 / (axis[k] - axis[k - 1]) - 1.0 / (axis[k + 1] - axis[k])) + phi[k + 1] += h * (1.0 / (axis[k + 1] - axis[k])) + return phi + + def height(self, x, y): + return float(self._basis(self.xs, x) @ self.z @ self._basis(self.ys, y)) + + def floor(self, x, y, h=1.0e-5): + gx = (self.height(x + h, y) - self.height(x - h, y)) / (2 * h) + gy = (self.height(x, y + h) - self.height(x, y - h)) / (2 * h) + return self.height(x, y), gx, gy + + def hess(self, x, y, h=1.0e-4): + z0 = self.height(x, y) + fxx = (self.height(x + h, y) - 2 * z0 + self.height(x - h, y)) / h**2 + fyy = (self.height(x, y + h) - 2 * z0 + self.height(x, y - h)) / h**2 + fxy = (self.height(x + h, y + h) - self.height(x + h, y - h) - self.height(x - h, y + h) + + self.height(x - h, y - h)) / (4 * h * h) + # a bilinear cell has no z_xx or z_yy: the contact there is the normal force + return (fxx, fxy, fyy) if abs(fxx) > 1e-3 or abs(fyy) > 1e-3 else None + + def rows(self): + return [(float(x), float(y), float(-self.z[i, j])) for i, x in enumerate(self.xs) for j, y in enumerate(self.ys)] + + # ------------------------------------------------------------------ case builders CASES: list[dict] = [] # The matrix is seeded, so the designs the oracle can close are fixed: a change in the # oracle, the seed or the case table that drops cases must fail, not shrink the matrix. -EXPECTED_CASES = 71 +EXPECTED_CASES = 74 def single(name, t, L, nseg, fair, anch, depth=None, kbot=1.0e5, extra=(), oracle=True, slope=None, @@ -400,6 +467,28 @@ def floor(x, y, th=th): grid = [(x, y, 70.0 - math.tan(th) * x) for x in (-200.0, 900.0) for y in (-300.0, 300.0)] single("slope_fold_%+.1fdeg" % deg, chain12, length, nseg, (97.0, 0.0, -1.0), (0.0, 0.0, -70.0), bathy=grid, floor=floor, slope=th, oracle=False) + # --- a gridded seabed with valleys (the creases of the bilinear grid rounded by the + # solver): a 30 m Gaussian trench under the touchdown, and in the grounded run, deep + # enough that the frictionless run's tension T = T0 + w (z - z0) falls to zero inside it + # and the excess length rests slack at the bottom (the anchor tension is then w times the + # trench depth below the anchor); and a +-0.5 m random seabed on a 10 m grid in both + # directions, whose valleys the frictionless grounded run slides sideways into --- + xs = [-100.0 + 5.0 * k for k in range(141)] + for tag, xc, n_seg in (("touchdown", 200.0, 104), ("grounded_run", 350.0, 104)): + trench = RoundedGrid(xs, [-100.0, 100.0], + [[-100.0 - 30.0 * math.exp(-((x - xc) / 40.0) ** 2)] * 2 for x in xs]) + za = trench.height(450.0, 0.0) + c = single("trench_%s_pile" % tag, chain12, 520.0, n_seg, (0.0, 0.0, -10.0), (450.0, 0.0, za), + bathy=trench.rows(), floor=trench.floor, oracle=False) + c["floor_hess"] = trench.hess + c["pile_dz"] = za - trench.height(xc, 0.0) + rr = random.Random(20261015) + xs = [-100.0 + 10.0 * k for k in range(71)] + ys = [-100.0 + 10.0 * k for k in range(21)] + rough = RoundedGrid(xs, ys, [[-100.0 if x == 450.0 else -100.0 + rr.uniform(-0.5, 0.5) for _ in ys] for x in xs]) + c = single("rough2d_seabed", chain12, 520.0, 104, (0.0, 0.0, -10.0), (450.0, 0.0, -100.0), bathy=rough.rows(), + floor=rough.floor, oracle=False) + c["floor_hess"] = rough.hess # --- a soft seabed (kBot = 1e3): the grounded run sinks ~4 m, and the line only fits its # span because of that penetration --- wire_soft = line_type("wiresoft", "wire", 0.10) @@ -482,6 +571,14 @@ def evaluate(case, exe): check(bal < BALANCE_TOL, "%s: nodal force balance %.3g" % (name, bal)) if case.get("point_case"): check_points(case, row) + if case.get("pile_dz"): + # a slack element at the bottom of the trench, and the anchor tension of the grounded + # run that rises from a zero tension there: w times the trench depth below the anchor + T = read_tensions(os.path.join(d, "o.Line1.t.out")) + w = next(iter(case["types"].values()))["w"] + check(T.min() <= 0.0, "%s: the excess length rests slack at the bottom of the trench" % name) + check(abs(row["AnchTen1"] - w * case["pile_dz"]) < 0.02 * w * case["pile_dz"], + "%s: AnchTen %.6g vs w*depth %.6g" % (name, row["AnchTen1"], w * case["pile_dz"])) if case.get("fair_ref"): # slack line: the hanging leg carries about its own weight w*h (the discrete grounded # run keeps a small horizontal tension), never a compressed strut or zero