floer 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- floer/__about__.py +4 -0
- floer/__init__.py +3 -0
- floer/model.py +297 -0
- floer-1.0.0.dist-info/METADATA +50 -0
- floer-1.0.0.dist-info/RECORD +7 -0
- floer-1.0.0.dist-info/WHEEL +4 -0
- floer-1.0.0.dist-info/licenses/LICENCE.txt +18 -0
floer/__about__.py
ADDED
floer/__init__.py
ADDED
floer/model.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import math
|
|
3
|
+
import operator
|
|
4
|
+
from typing import Self
|
|
5
|
+
|
|
6
|
+
import attrs
|
|
7
|
+
import numpy as np
|
|
8
|
+
from numpy.typing import ArrayLike
|
|
9
|
+
|
|
10
|
+
_2PI = 2 * np.pi
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@attrs.define(frozen=True)
|
|
14
|
+
class Ocean:
|
|
15
|
+
"""The fluid bearing ice floes.
|
|
16
|
+
|
|
17
|
+
This class encapsulates the properties of an incompressible ocean of
|
|
18
|
+
constant depth and given density.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
depth : float
|
|
23
|
+
Ocean depth, in m.
|
|
24
|
+
density : float
|
|
25
|
+
Ocean density, in kg m^-3.
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
depth: float
|
|
30
|
+
density: float = 1025
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@attrs.frozen
|
|
34
|
+
class _Subdomain:
|
|
35
|
+
"""A segment localised in space.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
left_edge : float
|
|
40
|
+
Coordinate of the left edge of the domain, in m.
|
|
41
|
+
length : float
|
|
42
|
+
Length of the domain, in m.
|
|
43
|
+
|
|
44
|
+
Attributes
|
|
45
|
+
----------
|
|
46
|
+
right_edge : float
|
|
47
|
+
Coordinate of the right edge of the domain, in m.
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
left_edge: float
|
|
52
|
+
length: float
|
|
53
|
+
|
|
54
|
+
@functools.cached_property
|
|
55
|
+
def right_edge(self) -> float:
|
|
56
|
+
return self.left_edge + self.length
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@attrs.define(frozen=True)
|
|
60
|
+
class Ice:
|
|
61
|
+
"""A container for ice mechanical properties.
|
|
62
|
+
|
|
63
|
+
Ice is modelled as an elastic thin plate, with prescribed density,
|
|
64
|
+
thickness, Poisson's ratio and Young's modulus. Its fracture under bending
|
|
65
|
+
is considered either through the lens of Griffith's fracture mechanics, or
|
|
66
|
+
through the framework of strain failure commonly used in the sea ice
|
|
67
|
+
modelling community. The fracture toughness is relevant to the former,
|
|
68
|
+
while the strain threshold is relevant to the latter. Ice is considered
|
|
69
|
+
translationally invariant in one horizontal direction, so that its
|
|
70
|
+
quadratic moment of area is given per unit length in that direction.
|
|
71
|
+
|
|
72
|
+
Parameters
|
|
73
|
+
----------
|
|
74
|
+
density : float
|
|
75
|
+
Density, in kg m^-3.
|
|
76
|
+
poissons_ratio : float
|
|
77
|
+
Poisson's ratio.
|
|
78
|
+
thickness : float
|
|
79
|
+
Ice thickness, in m.
|
|
80
|
+
youngs_modulus : float
|
|
81
|
+
Scalar Young's modulus, in Pa.
|
|
82
|
+
|
|
83
|
+
Attributes
|
|
84
|
+
----------
|
|
85
|
+
quad_moment : float
|
|
86
|
+
Quadratic moment of area, in m^3.
|
|
87
|
+
flex_rigidity : float
|
|
88
|
+
Flexural rigidity in, N m.
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
poissons_ratio: float
|
|
93
|
+
thickness: float
|
|
94
|
+
youngs_modulus: float
|
|
95
|
+
density: float = 922.5
|
|
96
|
+
# frac_toughness: float | None = None
|
|
97
|
+
# strain_threshold: float | None = None
|
|
98
|
+
|
|
99
|
+
@functools.cached_property
|
|
100
|
+
def quad_moment(self) -> float:
|
|
101
|
+
return self.thickness**3 / (12 * (1 - self.poissons_ratio**2))
|
|
102
|
+
|
|
103
|
+
@functools.cached_property
|
|
104
|
+
def flex_rigidity(self) -> float:
|
|
105
|
+
return self.quad_moment * self.youngs_modulus
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@attrs.define
|
|
109
|
+
class FloatingIce:
|
|
110
|
+
"""An extension of `Ice` to represent properties due to buyoancy.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
ice : Ice
|
|
115
|
+
The ice that floats.
|
|
116
|
+
draught : float
|
|
117
|
+
Immersed ice thickness at rest, in m.
|
|
118
|
+
dbd : float
|
|
119
|
+
Depth below draught, height of the water column underneath the ice at
|
|
120
|
+
rest, in m.
|
|
121
|
+
elastic_length_pow4 : float
|
|
122
|
+
Characteristic elastic length scale, raised to the 4th power, in m^4.
|
|
123
|
+
|
|
124
|
+
Attributes
|
|
125
|
+
----------
|
|
126
|
+
elastic_length : float
|
|
127
|
+
Characteristic elastic length scale, in m.
|
|
128
|
+
freeboard : float
|
|
129
|
+
Emerged ice thickness at rest, in m.
|
|
130
|
+
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
ice: Ice
|
|
134
|
+
draught: float
|
|
135
|
+
dbd: float
|
|
136
|
+
elastic_length_pow4: float
|
|
137
|
+
|
|
138
|
+
@classmethod
|
|
139
|
+
def from_ice_ocean(cls, ice: Ice, ocean: Ocean, gravity: float) -> FloatingIce:
|
|
140
|
+
"""Build an instance by combining properties of existing objects.
|
|
141
|
+
|
|
142
|
+
Parameters
|
|
143
|
+
----------
|
|
144
|
+
ice : Ice
|
|
145
|
+
ocean : Ocean
|
|
146
|
+
gravity : float
|
|
147
|
+
Strengh of the local gravitational field, in m s^-2.
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
FloatingIce
|
|
152
|
+
|
|
153
|
+
"""
|
|
154
|
+
draught = ice.density / ocean.density * ice.thickness
|
|
155
|
+
dbd = ocean.depth - draught
|
|
156
|
+
# NOTE: as the 4th power of the elastic length scale arises naturally,
|
|
157
|
+
# we prefer using it to instantiate the class and computing the length
|
|
158
|
+
# scale when needed, over using the length scale for instantiation and
|
|
159
|
+
# recomputing the fourth power from it, as the latter approach can lead
|
|
160
|
+
# to substantial numerical imprecision.
|
|
161
|
+
el_lgth_pow4 = ice.flex_rigidity / (ocean.density * gravity)
|
|
162
|
+
return cls(
|
|
163
|
+
ice,
|
|
164
|
+
draught,
|
|
165
|
+
dbd,
|
|
166
|
+
elastic_length_pow4=el_lgth_pow4,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
@functools.cached_property
|
|
170
|
+
def elastic_length(self) -> float:
|
|
171
|
+
return math.pow(self.elastic_length_pow4, 0.25)
|
|
172
|
+
|
|
173
|
+
@functools.cached_property
|
|
174
|
+
def freeboard(self) -> float:
|
|
175
|
+
return self.ice.thickness - self.draught
|
|
176
|
+
|
|
177
|
+
@functools.cached_property
|
|
178
|
+
def _elastic_number(self) -> float:
|
|
179
|
+
"""Reciprocal of the Characteristic elastic length scale.
|
|
180
|
+
|
|
181
|
+
Returns
|
|
182
|
+
-------
|
|
183
|
+
float
|
|
184
|
+
Elastic number in m^-1
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
return 1 / self.elastic_length
|
|
188
|
+
|
|
189
|
+
@functools.cached_property
|
|
190
|
+
def _red_elastic_number(self) -> float:
|
|
191
|
+
"""Characteristic elastic number scaled by 1/sqrt(2).
|
|
192
|
+
|
|
193
|
+
Returns
|
|
194
|
+
-------
|
|
195
|
+
float
|
|
196
|
+
Reduced elastic number, in m^-1
|
|
197
|
+
|
|
198
|
+
"""
|
|
199
|
+
return 1 / (math.sqrt(2) * self.elastic_length)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# TODO: docstring inheritance
|
|
203
|
+
@attrs.define(kw_only=True)
|
|
204
|
+
class Floe(_Subdomain):
|
|
205
|
+
"""An ice floe localised in space.
|
|
206
|
+
|
|
207
|
+
Parameters
|
|
208
|
+
----------
|
|
209
|
+
ice : Ice
|
|
210
|
+
The mechanical properties of the floe.
|
|
211
|
+
|
|
212
|
+
"""
|
|
213
|
+
|
|
214
|
+
ice: Ice
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@attrs.frozen(init=False)
|
|
218
|
+
class DiscreteSpectrum:
|
|
219
|
+
"""Container for a discretised spectrum.
|
|
220
|
+
|
|
221
|
+
This class allows for building a forcing from the linear
|
|
222
|
+
superposition of harmonic waves.
|
|
223
|
+
|
|
224
|
+
Attributes
|
|
225
|
+
----------
|
|
226
|
+
amplitudes : np.ndarray
|
|
227
|
+
A 1D array of amplitudes, in m.
|
|
228
|
+
frequencies : np.ndarray
|
|
229
|
+
A 1D array of frequencies, in Hz.
|
|
230
|
+
phases : np.ndarray
|
|
231
|
+
A 1D array of phases, in rad.
|
|
232
|
+
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
amplitudes: np.ndarray[tuple[int], np.dtype[np.float64]]
|
|
236
|
+
frequencies: np.ndarray[tuple[int], np.dtype[np.float64]]
|
|
237
|
+
phases: np.ndarray[tuple[int], np.dtype[np.float64]]
|
|
238
|
+
|
|
239
|
+
def __init__(
|
|
240
|
+
self, amplitudes: ArrayLike, frequencies: ArrayLike, phases: ArrayLike = 0.0
|
|
241
|
+
):
|
|
242
|
+
|
|
243
|
+
# np.ravel to force precisely 1D-arrays
|
|
244
|
+
# Promote the map to list so the iterator can be used several times.
|
|
245
|
+
# Eventual phases are modulo'd to 2pi rad.
|
|
246
|
+
args = [
|
|
247
|
+
_arr.astype(np.float64)
|
|
248
|
+
for _arr in map(np.ravel, (amplitudes, frequencies, phases))
|
|
249
|
+
]
|
|
250
|
+
(size,) = np.broadcast_shapes(*(arr.shape for arr in args))
|
|
251
|
+
|
|
252
|
+
# If size is one, all the arguments are scalar and the "spectrum" is
|
|
253
|
+
# monochromatic. Otherwise, there is at least one argument with
|
|
254
|
+
# different components. The eventual other arguments with a single
|
|
255
|
+
# component are repeated so that the three arrays have the same size.
|
|
256
|
+
if size != 1:
|
|
257
|
+
for i, arr in enumerate(args):
|
|
258
|
+
if arr.size == 0:
|
|
259
|
+
raise ValueError(f"The spectral argument {i} is empty.")
|
|
260
|
+
if arr.size == 1:
|
|
261
|
+
args[i] = args[i] * np.ones(size)
|
|
262
|
+
|
|
263
|
+
# Remove entries corresponding to nan in any of the array
|
|
264
|
+
nan_mask = functools.reduce(operator.or_, (np.isnan(arr) for arr in args))
|
|
265
|
+
args = [arr[~nan_mask] for arr in args]
|
|
266
|
+
# Sort arrays by the frequency values
|
|
267
|
+
sk = np.argsort(args[1])
|
|
268
|
+
_amplitudes, _frequencies, _phases = (arr[sk] for arr in args)
|
|
269
|
+
_phases = _phases % _2PI
|
|
270
|
+
|
|
271
|
+
self.__attrs_init__(_amplitudes, _frequencies, _phases)
|
|
272
|
+
|
|
273
|
+
@classmethod
|
|
274
|
+
def from_periods(
|
|
275
|
+
cls, amplitudes: ArrayLike, periods: ArrayLike, phases: ArrayLike = 0.0
|
|
276
|
+
) -> Self:
|
|
277
|
+
return cls(amplitudes, 1 / np.ravel(periods), phases)
|
|
278
|
+
|
|
279
|
+
@functools.cached_property
|
|
280
|
+
def periods(self) -> np.ndarray[tuple[int]]:
|
|
281
|
+
return 1 / self.frequencies
|
|
282
|
+
|
|
283
|
+
@functools.cached_property
|
|
284
|
+
def angular_frequencies(self) -> np.ndarray[tuple[int]]:
|
|
285
|
+
return self.frequencies * _2PI
|
|
286
|
+
|
|
287
|
+
@functools.cached_property
|
|
288
|
+
def _ang_freqs_pow2(self) -> np.ndarray[tuple[int], np.dtype[np.floating]]:
|
|
289
|
+
return self.angular_frequencies**2
|
|
290
|
+
|
|
291
|
+
@functools.cached_property
|
|
292
|
+
def nf(self) -> int:
|
|
293
|
+
return len(self.frequencies)
|
|
294
|
+
|
|
295
|
+
@functools.cached_property
|
|
296
|
+
def energy(self) -> float:
|
|
297
|
+
return np.sum(self.amplitudes**2) / 2
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: floer
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Building blocks for floe models to rest upon.
|
|
5
|
+
Project-URL: Documentation, https://gitlab.com/tartopohm/floer#readme
|
|
6
|
+
Project-URL: Issues, https://gitlab.com/tartopohm/floer/issues
|
|
7
|
+
Project-URL: Source, https://gitlab.com/tartopohm/floer
|
|
8
|
+
Author-email: Nicolas Mokus <nmks@tuta.io>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENCE.txt
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Oceanography
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: attrs
|
|
25
|
+
Requires-Dist: numpy>=2
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# floer
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/floer)
|
|
31
|
+
[](https://pypi.org/project/floer)
|
|
32
|
+
|
|
33
|
+
Building blocks for floe models to rest upon.
|
|
34
|
+
|
|
35
|
+
-----
|
|
36
|
+
|
|
37
|
+
## Table of Contents
|
|
38
|
+
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [Licence](#licence)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```console
|
|
45
|
+
pip install floer
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Licence
|
|
49
|
+
|
|
50
|
+
`floer` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) licence.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
floer/__about__.py,sha256=TMURWsaPuMBkGSakVpIBAuOUgSlZMPJLv-7wdruf-b0,123
|
|
2
|
+
floer/__init__.py,sha256=0aBGviVU3m-8qr_dv3YrKqwUjoE-gfMU31tTPxRM014,101
|
|
3
|
+
floer/model.py,sha256=W-CqgqIhY1hH0Rgd2qadKKor49HNgpTmYhAGoASRgO8,8371
|
|
4
|
+
floer-1.0.0.dist-info/METADATA,sha256=VAuyCamQ2jdqm2wllHATwDJLxpdUZp3Eh8_6KGNZnIo,1613
|
|
5
|
+
floer-1.0.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
6
|
+
floer-1.0.0.dist-info/licenses/LICENCE.txt,sha256=YqaZGwUj9GQ5iyrMMMKRqxfKnRehJ5gOLdgXI6UDZjQ,1093
|
|
7
|
+
floer-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Nicolas Mokus <nmks@tuta.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|