|
| 1 | +""" |
| 2 | +====================================== |
| 3 | +Example 8: Fluctuation Field Generation |
| 4 | +====================================== |
| 5 | +
|
| 6 | +This example demonstrates the utilities for generating synthetic turbulence, which can be either |
| 7 | +from a pre-trained DRD model, or based on some well-known spectra models. ``DRDMannTurb`` |
| 8 | +provides several utilities for plotting the resulting fields through Plotly, which can be done |
| 9 | +in several contexts as well as utilities for saving to VTK for downstream analysis in, e.g., |
| 10 | +ParaView. |
| 11 | +
|
| 12 | +""" |
| 13 | + |
| 14 | +####################################################################################### |
| 15 | +# .. centered:: |
| 16 | +# This example may take a few seconds to load. Please be patient if using |
| 17 | +# Plotly, as it requires some time to render 3D graphics. |
| 18 | +# |
| 19 | + |
| 20 | +####################################################################################### |
| 21 | +# Import packages |
| 22 | +# --------------- |
| 23 | +# |
| 24 | +# First, we import the packages we need for this example. |
| 25 | +from pathlib import Path |
| 26 | + |
| 27 | +import numpy as np |
| 28 | +import torch |
| 29 | + |
| 30 | +from drdmannturb.fluctuation_generation import ( |
| 31 | + FluctuationFieldGenerator, |
| 32 | +) |
| 33 | + |
| 34 | +path = Path().resolve() |
| 35 | + |
| 36 | +device = "cuda" if torch.cuda.is_available() else "cpu" |
| 37 | + |
| 38 | +if torch.cuda.is_available(): |
| 39 | + torch.set_default_tensor_type("torch.cuda.FloatTensor") |
| 40 | + |
| 41 | +####################################################################################### |
| 42 | +# Setting Physical Parameters |
| 43 | +# --------------------------- |
| 44 | +# Here, we set the physical parameters of the environment in which the synthetic wind field is generated: |
| 45 | +# the friction velocity :math:`u_\mathrm{red} = 11.4` roughness height :math:`z_0=0.02` and reference height |
| 46 | +# of :math:`90`. The physical domain is determined by dimensions in 3D as well as the discretization |
| 47 | +# size (grid levels) in each dimension. |
| 48 | +z0 = 0.02 |
| 49 | +zref = 90 |
| 50 | +uref = 11.4 |
| 51 | +ustar = uref * 0.41 / np.log(zref / z0) |
| 52 | +plexp = 0.2 # power law exponent |
| 53 | +windprofiletype = "PL" # choosing power law, use log with "LOG" here instead |
| 54 | + |
| 55 | +L = 0.593 * zref |
| 56 | +Gamma = 3.89 |
| 57 | +sigma = 0.052 |
| 58 | + |
| 59 | +Lx = 1024 |
| 60 | +Ly = 256 |
| 61 | +Lz = 256 |
| 62 | + |
| 63 | +nBlocks = 2 |
| 64 | +grid_dimensions = np.array([Lx, Ly, Lz]) |
| 65 | + |
| 66 | +grid_levels = np.array([6, 4, 4]) |
| 67 | + |
| 68 | +seed = None |
| 69 | + |
| 70 | +####################################################################################### |
| 71 | +# Generating Fluctuation Field from Mann Model |
| 72 | +# -------------------------------------------- |
| 73 | +# Fluctuation fields are generated block-by-block, rather than over the domain entirely. |
| 74 | +# Please see section V, B of the original DRD paper for further discussion. Here, we will use 4 blocks. |
| 75 | + |
| 76 | +Type_Model = "Mann" ### 'Mann', 'VK', 'DRD' |
| 77 | + |
| 78 | +####################################################################################### |
| 79 | +# Physical Parameters |
| 80 | +# ------------------- |
| 81 | +# The Mann model requires three parameters, length scale, time scale, and spectrum amplitude scale, |
| 82 | +# which are defined above |
| 83 | +# |
| 84 | +gen_mann = FluctuationFieldGenerator( |
| 85 | + ustar, |
| 86 | + zref, |
| 87 | + grid_dimensions, |
| 88 | + grid_levels, |
| 89 | + length_scale=L, |
| 90 | + time_scale=Gamma, |
| 91 | + energy_spectrum_scale=sigma, |
| 92 | + model="Mann", |
| 93 | + seed=seed, |
| 94 | + blend_num=0, |
| 95 | +) |
| 96 | + |
| 97 | +fluctuation_field_mann = gen_mann.generate(1, zref, uref, z0, windprofiletype, plexp) |
0 commit comments