nimphs.operators.utils
Modules
nimphs.operators.utils.material
- class MaterialUtils
Bases:
object
Utility functions to generate materials for the both modules.
- classmethod generate_preview(obj: Object, name: str = 'NIMPHS_preview_material') None
Generate or update the preview material.
This generates the following node tree:
{Vertex color}[color] >>> [image]{Separate RBG}[R, G, B] >>> [color]{Principled BSDF}
- Parameters
obj (Object) -- object on which to apply the material
name (str, optional) -- name of the material. Defaults to "NIMPHS_preview_material".
- class OpenfoamMaterialUtils
Bases:
MaterialUtils
Utility functions to generate materials for the OpenFOAM module.
- class TelemacMaterialUtils
Bases:
MaterialUtils
Utility functions to generate materials for the TELEMAC module.
nimphs.operators.utils.mesh
- class OpenfoamMeshUtils
Bases:
object
Utility functions for generating meshes for the OpenFOAM module.
- classmethod clip(mesh: UnstructuredGrid, clip: NIMPHS_OpenfoamClipProperty) Optional[PolyData]
Generate clipped surface.
- Parameters
mesh (UnstructuredGrid) -- mesh
clip (NIMPHS_OpenfoamClipProperty) -- clip settings
- Returns
PolyData
- Return type
Union[PolyData, None]
- classmethod faces(surface: PolyData) Optional[ndarray]
Get faces array of an extracted surface.
- Parameters
surface (PolyData) -- extracted surface
- Returns
faces array
- Return type
np.ndarray
- classmethod vertices(file_data: OpenfoamFileData, clip: Optional[NIMPHS_OpenfoamClipProperty] = None) tuple[Optional[numpy.ndarray], Union[pyvista.core.pointset.PolyData, numpy.ndarray]]
Generate vertices and extracted surface of the given OpenFOAM file.
- Parameters
file_data (NIMPHS_OpenfoamFileData) -- file data
clip (NIMPHS_OpenfoamClipProperty, optional) -- clip settings. Defaults to None.
- Returns
vertices, extracted surface
- Return type
tuple[Union[np.ndarray, None], Union[PolyData, np.ndarray]]
- class TelemacMeshUtils
Bases:
object
Utility functions for generating meshes for the TELEMAC module.
- classmethod vertices(file_data: TelemacFileData, offset: int = 0, type: str = 'BOTTOM') Optional[ndarray]
Generate vertices of the mesh.
If the selected file is a 2D simulation, you can precise which part of the mesh you want ('BOTTOM' or 'WATER_DEPTH'). If the file is a 3D simulation, you can precise an offset for data reading (this offsets is somehow the id of the plane to generate).
- Parameters
file_data (NIMPHS_TelemacFileData) -- file data
offset (int, optional) -- offset for data reading (id of the plane for 3D simulations). Defaults to 0.
type (str, optional) -- name of the variable to use as z-values. Defaults to 'BOTTOM'.
- Returns
vertices
- Return type
Union[np.ndarray, None]
- classmethod vertices_LI(obj: Object, file_data: TelemacFileData, time_info: InterpInfo, offset: int = 0) ndarray
Generate linearly interpolated vertices of the mesh.
- Parameters
obj (Object) -- object
file_data (NIMPHS_TelemacFileData) -- file data
time_info (InterpInfo) -- time information
offset (int, optional) -- offset for data reading (id of the plane for 3D simulations). Defaults to 0.
- Returns
vertices
- Return type
np.ndarray
nimphs.operators.utils.object
- class ObjectUtils
Bases:
object
Utility functions for generating objects for both modules.
- classmethod generate(vertices: ndarray, faces: ndarray, name: str, new: bool = False) Object
Generate an object and its mesh using the given vertices and faces.
If it already exists, clear object data and use the given data as new data.
- Parameters
vertices (np.ndarray) -- vertices, must have the following shape: (n, 3)
faces (np.ndarray) -- faces, must have the following shape: (n, 3)
name (str) -- name of the object
new (bool) -- force to generate a new object
- Returns
generated object
- Return type
Object
- classmethod setup_streaming_sequence(obj: Object, op: NIMPHS_CreateStreamingSequence, file_path: str) None
Generate streaming sequence settings for all modules.
- Parameters
obj (Object) -- sequence object
op (NIMPHS_CreateStreamingSequence) -- operator
file_path (str) -- file path
- class OpenfoamObjectUtils
Bases:
ObjectUtils
Utility functions for generating/updating meshes for the OpenFOAM module.
- classmethod add_mesh_to_sequence(obj: Object, bmesh: Mesh) int
Add a mesh to an OpenFOAM 'mesh sequence'.
- Parameters
obj (Object) -- sequence object
bmesh (Mesh) -- mesh to add to the sequence
- Returns
mesh id in the sequence
- Return type
int
- classmethod mesh_for_sequence(file_data: OpenfoamFileData, op: NIMPHS_OT_OpenfoamCreateMeshSequence) Optional[Mesh]
Generate mesh data for the 'create mesh sequence' process.
- Parameters
file_data (NIMPHS_OpenfoamFileData) -- file data
op (NIMPHS_OT_OpenfoamCreateMeshSequence) -- operator
- Returns
generated mesh
- Return type
Union[Mesh, None]
- classmethod step_create_mesh_sequence(context: Context, op: NIMPHS_OT_OpenfoamCreateMeshSequence) None
Run one step of 'create mesh sequence' for the OpenFOAM module.
- Parameters
context (Context) -- context
op (NIMPHS_OT_OpenfoamCreateMeshSequence) -- operator
- Raises
error -- error on generating mesh for sequence
ValueError -- generated mesh is None
- classmethod streaming_sequence_obj(context: Context, obj: Object, name: str) Object
Generate the base object for an OpenFOAM 'streaming sequence'.
- Parameters
obj (Object) -- selected object
name (str) -- name of the sequence
- Returns
generated object
- Return type
Object
- classmethod update_streaming_sequence(scene: Scene, obj: Object, time_point: int) None
Update the given OpenFOAM sequence object.
- Parameters
scene (Scene) -- scene
obj (Object) -- sequence object
time_point (int) -- time point
- class TelemacObjectUtils
Bases:
ObjectUtils
Utility functions for generating/updating objects for the TELEMAC module.
- classmethod add_shape_key(obj: Object, vertices: ndarray, name: str, frame: int, end: bool) None
Add a shape key to the object using the given vertices. It also set a keyframe with value = 1.0 at the given frame and add keyframes at value = 0.0 around the frame (-1 and +1).
- Parameters
obj (Object) -- object to receive the new shape key
vertices (np.ndarray) -- new vertices values
name (str) -- name of the shape key
frame (int) -- the frame on which the keyframe is inserted
end (bool) -- indicate if this the shape key to add is the last one. Defaults to False.
- classmethod base(file_data: TelemacFileData, name: str, point_data: Union[NIMPHS_PointDataSettings, str] = '') list[bpy.types.Object]
Generate objects using settings defined by the user. This function generates objects and vertex colors.
If the file is a 2D simulation, this will generate two objects ("Bottom" and "Water depth"). If the file is a 3D simulation, this will generate one object per plane.
- Parameters
file_data (NIMPHS_TelemacFileData) -- file data
name (str) -- name to give to the objects
point_data (Union[NIMPHS_PointDataSettings, str], optional) -- point data settings. Defaults to "".
- Returns
generated objects
- Return type
list[Object]
- classmethod sequence(context: Context, obj: Object, name: str, shape_keys: bool = False) Optional[Object]
Generate base object for a TELEMAC sequence.
- Parameters
context (Context) -- context
obj (Object) -- source object to copy data
name (str) -- name to give to the sequence
shape_keys (bool, optional) -- indicate whether to generate the 'Basis' shape key. Defaults to False.
- Returns
generated sequence object
- Return type
Union[Object, None]
- classmethod step_create_mesh_sequence(context: Context, op: NIMPHS_OT_TelemacCreateMeshSequence) None
Run one step of 'create mesh sequence' for the TELEMAC module.
- Parameters
context (Context) -- context
op (NIMPHS_OT_TelemacCreateMeshSequence) -- operator
- classmethod update_mesh_sequence(bmesh: Mesh, file_data: TelemacFileData, offset: int, point_data: NIMPHS_PointDataSettings, time_info: InterpInfo) None
Update the given TELEMAC 'mesh sequence' child object.
- Parameters
bmesh (Mesh) -- blender mesh
file_data (NIMPHS_TelemacFileData) -- file data
offset (int, optional) -- offset for data reading (id of the plane for 3D simulations). Defaults to 0.
point_data (NIMPHS_PointDataSettings) -- point data
time_info (InterpInfo) -- time information
- classmethod update_streaming_sequence(obj: Object, child: Object, file_data: TelemacFileData, frame: int, offset: int) None
Update the mesh of the given 'child' object from a TELEMAC 'streaming sequence' object.
- Parameters
obj (Object) -- sequence object
child (Object) -- child object of the sequence
file_data (NIMPHS_TelemacFileData) -- file data
frame (int) -- frame
offset (int) -- offset for data reading (id of the plane for 3D simulations).
nimphs.operators.utils.others
- remap_array(input: ndarray, out_min: float = 0.0, out_max: float = 1.0, in_min: float = -inf, in_max: float = inf) ndarray
Remap values of the given array.
- Parameters
input (np.ndarray) -- input array to remap
out_min (float, optional) -- minimum value to output. Defaults to 0.0.
out_max (float, optional) -- maximum value to output. Defaults to 1.0.
in_min (float, optional) -- minimum value of the input. Defaults to -np.inf.
in_max (float, optional) -- maximum value of the input. Defaults to np.inf.
- Returns
output array
- Return type
np.ndarray
nimphs.operators.utils.sequence
- update_openfoam_streaming_sequences(scene: Scene) None
Update all OpenFOAM 'streaming sequence' objects of the scene.
- Parameters
scene (Scene) -- scene
- update_telemac_mesh_sequences(scene: Scene) None
Update all TELEMAC 'mesh sequence' objects.
- Parameters
scene (Scene) -- scene
- update_telemac_streaming_sequences(scene: Scene) None
Update all TELEMAC 'streaming sequence' objects of the scene.
- Parameters
scene (Scene) -- scene
nimphs.operators.utils.vertex_color
- class OpenfoamVertexColorUtils
Bases:
VertexColorUtils
Utility functions for generating vertex colors for the OpenFOAM module.
- classmethod prepare(bmesh: Mesh, point_data: Union[NIMPHS_PointDataSettings, str], file_data: OpenfoamFileData) VertexColorInformation
Prepare point data to generate vertex colors.
- Parameters
bmesh (Mesh) -- blender mesh
point_data (Union[NIMPHS_PointDataSettings, str]) -- point data settings
file_data (NIMPHS_OpenfoamFileData) -- file data
- Returns
vertex colors groups, color data, number of vertices
- Return type
- class TelemacVertexColorUtils
Bases:
VertexColorUtils
Utility functions for generating vertex colors for the TELEMAC module.
- classmethod prepare(bmesh: Mesh, point_data: Union[NIMPHS_PointDataSettings, str], file_data: TelemacFileData, offset: int = 0) VertexColorInformation
Prepare point data to generate vertex colors.
- Parameters
bmesh (Mesh) -- blender mesh
point_data (Union[NIMPHS_PointDataSettings, str]) -- point data settings
file_data (NIMPHS_TelemacFileData) -- file data
offset (int, optional) -- offset for data reading (id of the plane for 3D simulations). Defaults to 0.
- Returns
point data information to generate vertex colors
- Return type
- classmethod prepare_LI(bmesh: Mesh, point_data: NIMPHS_PointDataSettings, file_data: TelemacFileData, time_info: InterpInfo, offset: int = 0) VertexColorInformation
Prepare point data for linear interpolation of TELEMAC sequences.
- Parameters
bmesh (Mesh) -- blender mesh
point_data (NIMPHS_PointDataSettings) -- point data settings
file_data (NIMPHS_TelemacFileData) -- file data
time_info (InterpInfo) -- time information
offset (int, optional) -- offset for data reading (id of the plane for 3D simulations). Defaults to 0.
- Returns
point data information to generate vertex colors
- Return type
- class VertexColorInformation(nb_vertex_indices: int = 0)
Bases:
object
Utility class which hold information on vertex colors to generate.
- groups() tuple[list[str], list[list[int]]]
Generate vertex colors groups.
- Returns
name of the group, indices of point data
- Return type
tuple[list[str], list[list[int]]]
- is_empty() bool
Indicate whether 'names' array is empty.
- Returns
state
- Return type
bool
- class VertexColorUtils
Bases:
object
Utility functions for generating vertex colors for both modules.
- classmethod generate(bmesh: Mesh, data: VertexColorInformation) None
Generate vertex colors for the given mesh.
- Parameters
bmesh (Mesh) -- mesh on which to add vertex colors
data (VertexColorInformation) -- point data information to generate vertex colors
nimphs.operators.utils.volume
- class TelemacMeshForVolume(path: str, plane_interp_steps: int, time_interp_steps: int)
Bases:
object
Data structure which holds information on the TELEMAC object.
- get_point_data(names: list[str]) ndarray
Get point data if variable found in the given list of names.
- Parameters
names (list[str]) -- list of possible names
- Raises
NameError -- if names not found in variables list
- Returns
point data
- Return type
np.ndarray
- interpolate_plane_data(data: ndarray) ndarray
Linearly interpolates given data to generate 'fake' planes.
- Parameters
data (np.ndarray) -- point data to interpolate.
- Returns
interpolated data.
- Return type
np.ndarray
- set_time_point(time_point: int, interp_time_step: int = 0) None
Update data according to the given time point. Linearly interpolates data in time if needed.
- Parameters
time_point (int) -- time point to read
interp_time_step (int, optional) -- time step of interpolated time point. Defaults to 0.
time_steps (int, optional) -- number of time steps between each time point. Defaults to 0.
- class TelemacVolume(mesh: TelemacMeshForVolume, nb_threads: int, use_multproc: bool, use_cuda: bool, vx_size: tuple[float, float, float] = (0, 0, 0), dimensions: tuple[float, float, float] = (0, 0, 0), show_details: bool = False)
Bases:
object
Object which handles the process of generating a volume from a TELEMAC object.
- clear_data() None
Clear volume data and allocate new memory.
- export_time_point(mesh: TelemacMeshForVolume, point_data: list[str], file_name: str) None
Generate and export volume for the current time point.
- Parameters
mesh (TelemacMeshForVolume) -- mesh
point_data (list[str]) -- point data to use as density
file_name (str) -- file name
- fill(mesh: TelemacMeshForVolume, point_data: list[str]) None
Set the density of each voxel using the given data.
- Parameters
mesh (TelemacMeshForVolume) -- mesh data
point_data (list[str]) -- name of point data to use as density
- fill_with_cpu(data: ndarray, mesh: TelemacMeshForVolume)
Set density of each voxel using an algorithm with runs on the CPU.
- Parameters
data (np.ndarray) -- point data
mesh (TelemacMeshForVolume) -- mesh information
- fill_with_gpu(data: ndarray, mesh: TelemacMeshForVolume)
Set density of each voxel using an algorithm with runs on the GPU.
- Parameters
data (np.ndarray) -- point data
mesh (TelemacMeshForVolume) -- mesh information
- prepare_voxels(mesh: TelemacMeshForVolume) None
Prepare voxels information (compute zcols, zmin, zmax).
- Parameters
mesh (TelemacMeshForVolume) -- mesh information
- prepare_voxels_for_cpu(xmin, xmax, ymin, ymax, plane_indices, mesh: TelemacMeshForVolume, mode: str = 'SEQUENTIAL')
Prepare voxels information to be computed using the CPU.
- Parameters
xmin (np.ndarray) -- min x coordinates of voxels
xmax (np.ndarray) -- max x coordinates of voxels
ymin (np.ndarray) -- min y coordinates of voxels
ymax (np.ndarray) -- max y coordinates of voxels
plane_indices (np.ndarray) -- plane indices
mesh (TelemacMeshForVolume) -- mesh
mode (str, optional) -- execution mode, enum in ['SEQUENTIAL', 'PARALLEL_CPU', 'PARALLEL_GPU']. Defaults to 'SEQUENTIAL'.
- prepare_voxels_for_gpu(xmin, xmax, ymin, ymax, plane_indices, mesh: TelemacMeshForVolume, mode: str = 'SEQUENTIAL')
Prepare voxels information to be computed using the GPU.
- Parameters
xmin (np.ndarray) -- min x coordinates of voxels
xmax (np.ndarray) -- max x coordinates of voxels
ymin (np.ndarray) -- min y coordinates of voxels
ymax (np.ndarray) -- max y coordinates of voxels
plane_indices (np.ndarray) -- plane indices
mesh (TelemacMeshForVolume) -- mesh
mode (str, optional) -- execution mode, enum in ['NORMAL', 'PARALLEL_CPU', 'PARALLEL_GPU']. Defaults to 'SEQUENTIAL'.
- save_as_vdb(grid_name: str, file_name: str) None
Save volume data as .vdb file.
- Parameters
grid_name (str) -- name of density variable
file_name (str) -- file name
- fill_volume_cpu(volume: ndarray, data: ndarray, vxids: ndarray, xyids: ndarray, z_coords: ndarray, zcols: ndarray, zmin: ndarray, zmax: ndarray, start: int, end: int, dim: tuple[float, float, float]) None
Fill volume density using given data (runs for one CPU thread).
- Parameters
volume (np.ndarray) -- volume (destination array)
data (np.ndarray) -- point data to use as density
vxids (np.ndarray) -- voxel '(x, y, z)' indices
xyids (np.ndarray) -- voxel 'xy' indices
z_coords (np.ndarray) -- z vertices coordinates
zcols (np.ndarray) -- z columns
zmin (np.ndarray) -- min z coordinates of voxels
zmax (np.ndarray) -- max z coordinates of voxels
start (int) -- start index
end (int) -- end index
dim (tuple[float, float, float]) -- volume dimensions
Make raw shared array from given data and information.
- Parameters
data (np.ndarray) -- data to put in the array
ctype (str) -- ctype. Enum in ['i', 'd'].
shape (int) -- shape of the array
- Returns
shared array
- Return type
RawArray
- prepare_voxels_cpu(zcols: list, xmin: ndarray, xmax: ndarray, ymin: ndarray, ymax: ndarray, x_coords: ndarray, y_coords: ndarray, plane_indices: ndarray, start: int, end: int, dim: tuple[float, float, float]) None
Prepare voxels information (runs for one thread).
- Parameters
zcols (list) -- z columns (destination array)
xmin (np.ndarray) -- min x coordinates of voxels
xmax (np.ndarray) -- max x coordinates of voxels
ymin (np.ndarray) -- min y coordinates of voxels
ymax (np.ndarray) -- max y coordinates of voxels
x_coords (np.ndarray) -- x vertices coordinates
y_coords (np.ndarray) -- y vertices coordinates
plane_indices (np.ndarray) -- indices of all available planes
start (int) -- start index
end (int) -- end index
dim (tuple[float, float, float]) -- volume dimensions