You're reading an old version of this documentation. If you want up-to-date information, please have a look at v0.8.2.
API¶
Subpackages¶
snl_d3d_cec_verify package¶
- class snl_d3d_cec_verify.CaseStudy(dx=1, dy=1, sigma=3, x0=0, x1=18, y0=1, y1=5, bed_level=- 2, dt_max=1, dt_init=1, turb_pos_x=6, turb_pos_y=3, turb_pos_z=- 1, discharge=6.0574, horizontal_eddy_viscosity=1e-06, horizontal_eddy_diffusivity=1e-06, vertical_eddy_viscosity=1e-06, vertical_eddy_diffusivity=1e-06, simulate_turbines=True, horizontal_momentum_filter=True, stats_interval=None, restart_interval=0)¶
Bases:
objectClass for defining variables for single or multiple case studies.
When defining multiple values for multiple variables, the given sequences must be the same length, e.g.:
>>> cases = CaseStudy(dx=[1, 2, 3, 4], ... dy=[4, 5, 6, 7]) >>> print(cases) CaseStudy(dx=[1, 2, 3, 4], dy=[4, 5, 6, 7], sigma=3, ...
The above example will generate an object representing 4 cases, which can then be iterated:
>>> for case in cases: ... print(case) CaseStudy(dx=1, dy=4, ... CaseStudy(dx=2, dy=5, ... CaseStudy(dx=3, dy=6, ... CaseStudy(dx=4, dy=7, ...
- Parameters:
dx (
Union[int,float,Sequence[Union[int,float]]]) – grid spacing in x-direction, in meters. Defaults to1dy (
Union[int,float,Sequence[Union[int,float]]]) – grid spacing in y-direction, in meters. Defaults to1sigma (
Union[int,float,Sequence[Union[int,float]]]) – number of vertical layers, defaults to3x0 (
Union[int,float,Sequence[Union[int,float]]]) – minimum x-value, in metres, defaults to0x1 (
Union[int,float,Sequence[Union[int,float]]]) – maximum x-value, in metres, defaults to18y0 (
Union[int,float,Sequence[Union[int,float]]]) – minimum y-value, in metres, defaults to1y1 (
Union[int,float,Sequence[Union[int,float]]]) – maximum y-value, in metres, defaults to5bed_level (
Union[int,float,Sequence[Union[int,float]]]) – uniform bed level, in metres, defaults to-2dt_max (
Union[int,float,Sequence[Union[int,float]]]) – maximum time step, in seconds. Defaults to1dt_init (
Union[int,float,Sequence[Union[int,float]]]) – initial time step, in seconds. Defaults to1turb_pos_x (
Union[int,float,Sequence[Union[int,float]]]) – turbine x-position, in meters. Defaults to6turb_pos_y (
Union[int,float,Sequence[Union[int,float]]]) – turbine y-position, in meters. Defaults to3turb_pos_z (
Union[int,float,Sequence[Union[int,float]]]) – turbine z-position, in meters. Defaults to-1discharge (
Union[int,float,Sequence[Union[int,float]]]) – inlet boundary discharge, in cubic meters per second. Defaults to6.0574horizontal_eddy_viscosity (
Union[int,float,Sequence[Union[int,float]]]) – uniform horizontal eddy viscosity, in metres squared per second. Defaults to1e-06horizontal_eddy_diffusivity (
Union[int,float,Sequence[Union[int,float]]]) – uniform horizontal eddy diffusivity, in metres squared per second. Defaults to1e-06vertical_eddy_viscosity (
Union[int,float,Sequence[Union[int,float]]]) – uniform vertical eddy viscosity, in metres squared per second. Defaults to1e-06vertical_eddy_diffusivity (
Union[int,float,Sequence[Union[int,float]]]) – uniform vertical eddy diffusivity, in metres squared per second. Defaults to1e-06simulate_turbines (
Union[bool,Sequence[bool]]) – simulate turbines, defaults toTruehorizontal_momentum_filter (
Union[bool,Sequence[bool]]) – use high-order horizontal momentum filter. Defaults toTruestats_interval (
Union[int,float,None,Sequence[Union[int,float,None]]]) – interval for simulation progress output, in seconds of simulation time. Defaults toNonerestart_interval (
Union[int,float,Sequence[Union[int,float]]]) – interval for restart file output, in seconds of simulation time. Defaults to0
- Raises:
ValueError – if variables with multiple values have different lengths
- discharge: Union[int, float, Sequence[Union[int, float]]] = 6.0574¶
inlet boundary discharge, in cubic meters per second
- horizontal_eddy_viscosity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform horizontal eddy viscosity, in metres squared per second
- horizontal_eddy_diffusivity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform horizontal eddy diffusivity, in metres squared per second
- vertical_eddy_viscosity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform vertical eddy viscosity, in metres squared per second
- vertical_eddy_diffusivity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform vertical eddy diffusivity, in metres squared per second
- horizontal_momentum_filter: Union[bool, Sequence[bool]] = True¶
use high-order horizontal momentum filter
- stats_interval: Union[int, float, None, Sequence[Optional[Union[int, float]]]] = None¶
interval for simulation progress output, in seconds
- class snl_d3d_cec_verify.LiveRunner(d3d_bin_path, omp_num_threads=1, relative_input_parts=<factory>)¶
Bases:
objectA wrapper around the
run_dflowfm()function to allow reuse of settings across many Delft3D projects with real time output.Call the LiveRunner object with the project path to execute the Delft3D model and read the output line by line, like a generator
>>> runner = LiveRunner("path/to/Delft3D/src/bin", ... omp_num_threads=8) >>> for line in runner("path/to/project"): ... print(line)
Currently only available for Windows and Linux.
- Parameters:
d3d_bin_path (
Union[str,Path]) – path to thebinfolder generated when compiling Delft3Domp_num_threads (
int) – The number of CPU threads to use, defaults to {omp_num_threads}relative_input_parts (
Optional[List[str]]) – list of components representing the relative path to folder containing the delft3D model files, from the project folder. Set to None to use given path directly. Defaults to["input"]
- __call__(project_path)¶
Run a simulation, given a prepared model, and yield stdout and stdin streams.
- Parameters:
project_path (
Union[str,Path]) – path to Delft3D project folder- Raises:
OSError – if function is called on an unsupported operating system
FileNotFoundError – if the Delft3D entry point or model folder could not be found
RuntimeError – if the Delft3D simulation outputs to stderr, for any reason
- Return type:
- class snl_d3d_cec_verify.MycekStudy(dx=1, dy=1, sigma=3, dt_max=1, dt_init=1, discharge=6.0574, horizontal_eddy_viscosity=1e-06, horizontal_eddy_diffusivity=1e-06, vertical_eddy_viscosity=1e-06, vertical_eddy_diffusivity=1e-06, simulate_turbines=True, horizontal_momentum_filter=True, stats_interval=None, restart_interval=0)¶
Bases:
CaseStudyClass for defining cases corresponding to the Mycek study. Subclass of
CaseStudywith the domain and turbine position fixed.- Parameters:
dx (
Union[int,float,Sequence[Union[int,float]]]) – grid spacing in x-directions, in meters. Defaults to1dy (
Union[int,float,Sequence[Union[int,float]]]) – grid spacing in y-directions, in meters. Defaults to1sigma (
Union[int,float,Sequence[Union[int,float]]]) – number of vertical layers, defaults to3dt_max (
Union[int,float,Sequence[Union[int,float]]]) – maximum time step, in seconds. Defaults to1dt_init (
Union[int,float,Sequence[Union[int,float]]]) – initial time step, in seconds. Defaults to1discharge (
Union[int,float,Sequence[Union[int,float]]]) – inlet boundary discharge, in cubic meters per second. Defaults to6.0574horizontal_eddy_viscosity (
Union[int,float,Sequence[Union[int,float]]]) – uniform horizontal eddy viscosity, in metres squared per second. Defaults to1e-06horizontal_eddy_diffusivity (
Union[int,float,Sequence[Union[int,float]]]) – uniform horizontal eddy diffusivity, in metres squared per second. Defaults to1e-06vertical_eddy_viscosity (
Union[int,float,Sequence[Union[int,float]]]) – uniform vertical eddy viscosity, in metres squared per second. Defaults to1e-06vertical_eddy_diffusivity (
Union[int,float,Sequence[Union[int,float]]]) – uniform vertical eddy diffusivity, in metres squared per second. Defaults to1e-06simulate_turbines (
Union[bool,Sequence[bool]]) – simulate turbines, defaults toTruehorizontal_momentum_filter (
Union[bool,Sequence[bool]]) – use high-order horizontal momentum filter. Defaults toTruestats_interval (
Union[int,float,None,Sequence[Union[int,float,None]]]) – interval for simulation progress output, in seconds of simulation time. Defaults toNonerestart_interval (
Union[int,float,Sequence[Union[int,float]]]) – interval for restart file output, in seconds of simulation time. Defaults to0
- Raises:
ValueError – if variables with multiple values have different lengths
- class snl_d3d_cec_verify.Report(width=None, date_format=None)¶
Bases:
objectClass for creating a report in Pandoc markdown format
The final report can be viewed by printing the Report object, for example:
>>> report = Report(70, "%d %B %Y") >>> report.title = "Test" >>> report.authors = ["Me", "You"] >>> report.date = "1916-04-24" >>> report.content.add_text("Lorem ipsum dolor sit amet, consectetur " ... "adipiscing elit. Maecenas vitae " ... "scelerisque magna.") >>> print(report) 1: % Test 2: % Me; You 3: % 24 April 1916 4: 5: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas 6: vitae scelerisque magna. 7:
Note that line numbers are also printed. The report can also be saved to file, by iterating through each line:
>>> with open("report.md", "wt") as f: ... for line in report: ... f.write(line)
- Parameters:
width (
Optional[int]) – maximum paragraph width, in charactersdate_format (
Optional[str]) – format for document date as passed todatetime.date.strftime()
- content: Content¶
Container for the main body of the document. See the
Contentdocumentation for usage.
- property width¶
The maximum paragraph width, in characters. Set to None for no limit.
- Type:
Optional[int]
- property date_format¶
format for document date as passed to
datetime.date.strftime(). Set to None to use ISO 8601 format- Type:
Optional[str]
- class snl_d3d_cec_verify.Result(project_path, relative_map_parts=None)¶
Bases:
objectClass for capturing the results of executed case studies. Contains metadata from the simulation. Data generated on the grid edges and faces are accessible from the
edgesandfacesattributes.>>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.x_lim (0.0, 18.0)
>>> result.edges.extract_k(-1, 1) geometry u1 n0 n1 0 LINESTRING (1.00000 2.00000, 0.00000 2.00000) -3.662849e-17 0.0 1.0 ...
- Parameters:
- property x_lim¶
Domain limits in the x-direction, in metres
>>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.x_lim (0.0, 18.0)
- property y_lim¶
Domain limits in the y-direction, in metres
>>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.y_lim (1.0, 5.0)
- property times¶
Time steps of the Delft3D simulation
- Type:
numpy.typing.NDArray[numpy.datetime64]
>>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.times array(['2001-01-01T00:00:00.000000000', '2001-01-01T01:00:00.000000000'], dtype='datetime64[ns]')
- class snl_d3d_cec_verify.Runner(d3d_bin_path, omp_num_threads=1, show_stdout=False, relative_input_parts=<factory>)¶
Bases:
objectA wrapper around the
run_dflowfm()function to allow reuse of settings across many Delft3D projects.Call the Runner object with the project path to execute the Delft3D model
>>> runner = Runner("path/to/Delft3D/src/bin", ... omp_num_threads=8) >>> runner("path/to/project")
Currently only available for Windows and Linux.
- Parameters:
d3d_bin_path (
Union[str,Path]) – path to thebinfolder generated when compiling Delft3Domp_num_threads (
int) – The number of CPU threads to use, defaults to {omp_num_threads}show_stdout (
bool) – show Delft3D logging to stdout in console, defaults to {show_stdout}relative_input_parts (
Optional[List[str]]) – list of components representing the relative path to folder containing the delft3D model files, from the project folder. Set to None to use given path directly. Defaults to["input"]
- __call__(project_path)¶
Run a simulation, given a prepared model.
- Parameters:
project_path (
Union[str,Path]) – path to Delft3D project folder- Raises:
OSError – if function is called on an unsupported operating system
FileNotFoundError – if the Delft3D entry point or model folder could not be found
RuntimeError – if the Delft3D simulation outputs to stderr, for any reason
- class snl_d3d_cec_verify.Template(template_path=None, exist_ok=False, no_template=<factory>)¶
Bases:
objectClass for creating Delft3D projects from templates
Utilises the
copier.copy()function to fill the template and thegridfm.write_gridfm_rectangle()function to create the flexible mesh grid. Note that the template files are copied on initialization, therefore changes to the template source will not affect the object’s output.Call a Template object with a length one
CaseStudyobject and a path at which to create a Delft3D project. For example:>>> import pprint >>> import tempfile >>> from pathlib import Path >>> template = Template() >>> with tempfile.TemporaryDirectory() as tmpdirname: ... template(CaseStudy(), tmpdirname) ... inputdir = Path(tmpdirname) / "input" ... pprint.pprint(sorted([x.name for x in inputdir.iterdir()])) ['Discharge.bc', 'FlowFM.mdu', 'FlowFM_bnd.ext', 'FlowFM_net.nc', 'Inlet.pli', 'Outlet.pli', 'WaterLevel.bc', 'curves.trb', 'turbines.ini']
- Parameters:
template_path – path to the Delft3D project template, defaults to
Path("./templates/fm")exist_ok – if True, allow an existing path to be overwritten, defaults to
Falseno_template – variables to ignore in the given
CaseStudyobjects when filling templates, defaults to["dx", "dy"]
- __call__(case, project_path, exist_ok=None)¶
Create a new Delft3D project from the given
CaseStudyobject, at the given path.Note that boolean values are converted to integers and Nones are converted to empty strings.
- Parameters:
- Raises:
ValueError – if the given
CaseStudyobject is not length one or iftemplate_pathdoes not existFileExistsError – if the project path exists, but
exist_okis False
- template_path: InitVar[StrOrPath] = None¶
- class snl_d3d_cec_verify.Validate(case=None, data_dir=None)¶
Bases:
objectStore for
TransectobjectsPrint the object to see the descriptions and indices of the stored
Transectobjects.>>> validate = Validate() >>> print(validate) Validate(0: Centreline velocity 1: Axial velocity at $x^*=5$)
>>> validate[0].to_xarray() <xarray.DataArray '$u_0$' (dim_0: 10)> array([0.40064647, 0.40064647, 0.39288889, 0.38189899, 0.39806061, 0.44460606, 0.49309091, 0.54610101, 0.56614141, 0.60622222]) Coordinates: $z$ ... 0 $x$ (dim_0) float64 0.84 1.4 2.1 2.8 3.5 4.2 4.9 5.6 6.3 7.0 $y$ (dim_0) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Use a
CaseStudyobject to translate the origin of the transects to the turbine position.>>> from snl_d3d_cec_verify import MycekStudy >>> case = MycekStudy() >>> validate = Validate(case) >>> validate[0].to_xarray() <xarray.DataArray '$u_0$' (dim_0: 10)> array([0.40064647, 0.40064647, 0.39288889, 0.38189899, 0.39806061, 0.44460606, 0.49309091, 0.54610101, 0.56614141, 0.60622222]) Coordinates: $z$ ... -1 $x$ (dim_0) float64 6.84 7.4 8.1 8.8 9.5 10.2 10.9 11.6 12.3 13.0 $y$ (dim_0) float64 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 ...
- Parameters:
case – Case study from which to get turbine position
data_dir – path to folder containing YAML files representing transects. Each file must have the
attrs.descriptionkey set. Defaults toPath("./mycek2014")
- Raises:
FileNotFoundError – if
data_diris not a directory