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)¶
Class 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. Applies to the'fm'model only. Defaults to1dt_init (
Union[int,float,Sequence[Union[int,float]]]) – initial time step, in seconds. For the'structured'model, this is the fixed time step. 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. Applies to the'fm'model only. Defaults toTruestats_interval (
Union[int,float,None,Sequence[Union[int,float,None]]]) – interval for simulation progress output, in seconds of simulation time. Applies to the'fm'model only. 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
- dt_max: Union[int, float, Sequence[Union[int, float]]] = 1¶
maximum time step, in seconds. Applies to the
'fm'model only
- 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
- restart_interval: Union[int, float, Sequence[Union[int, float]]] = 0¶
interval for restart file output, in seconds
- get_case(index=0)¶
Return a unit case study, from the given index
- classmethod from_yaml(path)¶
Create a new instance from a YAML file
- to_yaml(path)¶
Export object as a YAML file
- class snl_d3d_cec_verify.LiveRunner(d3d_bin_path, omp_num_threads=1)¶
A class for running Delft3D models which allow reuse of settings across multiple projects with real time output. Automatically detects if the model uses a flexible or structured mesh and then calls the appropriate function from the
runnerpackage.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:
- __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 file could not be found (or is not unique)
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)¶
Class 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. Applies to the'fm'model only. Defaults to1dt_init (
Union[int,float,Sequence[Union[int,float]]]) – initial time step, in seconds. For the'structured'model, this is the fixed time step. 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. Applies to the'fm'model only. Defaults toTruestats_interval (
Union[int,float,None,Sequence[Union[int,float,None]]]) – interval for simulation progress output, in seconds of simulation time. Applies to the'fm'model only. 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
- dt_max: Union[int, float, Sequence[Union[int, float]]] = 1¶
maximum time step, in seconds. Applies to the
'fm'model only
- fields = ['dx', 'dy', 'sigma', 'x0', 'x1', 'y0', 'y1', 'bed_level', 'dt_max', 'dt_init', 'turb_pos_x', 'turb_pos_y', 'turb_pos_z', 'discharge', 'horizontal_eddy_viscosity', 'horizontal_eddy_diffusivity', 'vertical_eddy_viscosity', 'vertical_eddy_diffusivity', 'simulate_turbines', 'horizontal_momentum_filter', 'stats_interval', 'restart_interval']¶
- classmethod from_yaml(path)¶
Create a new instance from a YAML file
- get_case(index=0)¶
Return a unit case study, from the given index
- horizontal_eddy_diffusivity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform horizontal eddy diffusivity, in metres squared per second
- horizontal_eddy_viscosity: Union[int, float, Sequence[Union[int, float]]] = 1e-06¶
uniform horizontal eddy viscosity, in metres squared per second
- is_equal(other, ignore_fields=None)¶
Test equality of another object
Use the
ignore_fieldsargument to ignore fields when comparingCaseStudyobjects:>>> case = CaseStudy(dx=1) >>> other = CaseStudy(dx=2) >>> other.is_equal(case, ignore_fields=["dx"]) True
- restart_interval: Union[int, float, Sequence[Union[int, float]]] = 0¶
interval for restart file output, in seconds
- to_yaml(path)¶
Export object as a YAML file
- class snl_d3d_cec_verify.Report(width=None, date_format=None)¶
Class 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)¶
Class for capturing the results of executed case studies. Contains metadata from the simulation. Automatically detects if the model uses a flexible or structured mesh and then populates edge and face data in the
edgesandfacesattributes, where appropriate.>>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.x_lim (0.0, 18.0)
>>> result.edges.extract_sigma(-1, 0.5) geometry u1 ... n0 n1 0 LINESTRING (0.00000 1.00000, 0.00000 2.00000) 9.753143e-01 ... 1.0 -0.0 ...
- property x_lim: Tuple[float, float]¶
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: Tuple[float, float]¶
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: ndarray[Any, dtype[datetime64]]¶
Time steps of the Delft3D simulation
>>> 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]')
- Return type:
- class snl_d3d_cec_verify.Runner(d3d_bin_path, omp_num_threads=1, show_stdout=False)¶
A class for running Delft3D models which allow reuse of settings across multiple projects. Automatically detects if the model uses a flexible or structured mesh and then calls the appropriate function from the
runnerpackage.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:
- __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 file could not be found (or is not unique)
RuntimeError – if the Delft3D simulation outputs to stderr, for any reason
- class snl_d3d_cec_verify.Template(template_type='fm', template_path=None, exist_ok=False, no_template=<factory>)¶
Class for creating Delft3D projects from templates
Utilises the
copierandgridsubpackages to generate Delft3D models from templates and type-specific grid generation routines. 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 flexible-mesh 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']
Note that for the
'structured'model, if the turbine is located on a grid line then it will be shifted very slightly in order to avoid a bug in SNL-Delft3D-CEC.- Parameters:
template_type –
type of Delft3D project to generate. Valid options are:
'fm': create a flexible mesh model'structured': create a structured mesh model
Defaults to
'fm'template_path – optional path to the Delft3D project template
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"]
- Raises:
ValueError – if
template_typehas an invalid value
- __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)¶
Store for
TransectobjectsPrint the object to see the descriptions and indices of the stored
Transectobjects.>>> validate = Validate() >>> print(validate) Validate(0: Centreline velocity (3\% TI) 1: Centreline velocity (15\% TI) 2: Axial velocity at $x^*=5$ (3\% TI) 3: Axial velocity at $x^*=5$ (15\% TI) 4: Centreline turbulence intensity (3\% TI) 5: Centreline turbulence intensity (15\% TI))
>>> 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