dpivsoft.meshTools

dpivsoft.meshTools.body_options(tmr, name='spline', c=1, points=[])[source]

Build the inner (immersed-body) boundary of a Gmsh model.

Adds the geometry of the solid body as a closed curve loop that the fluid mesh will wrap around. The shape is selected by name.

Parameters:
  • tmr (float) – Target mesh element size along the body boundary.

  • name ({'spline', 'polygon', 'circle'}, optional) – Body geometry. ‘polygon’ joins points with straight lines, ‘spline’ fits a closed B-spline through points, ‘circle’ builds a circle of diameter c.

  • c (float, optional) – Circle diameter (only used when name == 'circle').

  • points (list of (x, y, z), optional) – Boundary points defining the body (‘polygon’/’spline’).

Returns:

  • cl_inner (int) – Gmsh curve-loop tag of the closed body boundary.

  • obj_lines (list of int) – Gmsh tags of the individual boundary curves.

dpivsoft.meshTools.mesh_generator(obj, dirSave, c=1, size=3, tm=0.1, tmr=0.01, points=[], elementOrder=1, filename='mesh.msh', visualize=1)[source]

Generate a 2D triangular mesh of a square fluid domain with an immersed body and write it to a Gmsh .msh file.

The domain is a square of half-width c * size centred on the origin with the body removed from its interior. Three physical groups are tagged for the FEM solver: “outbound” (outer edges), “object” (body boundary) and “fluid” (surface).

Parameters:
  • obj (str) – Body geometry passed to body_options (‘spline’/’polygon’/’circle’).

  • dirSave (str) – Directory where the mesh file is written.

  • c (float, optional) – Characteristic body size (diameter/chord).

  • size (float, optional) – Domain half-width as a multiple of c.

  • tm (float, optional) – Target element size on the outer boundary (tm) and on the body boundary (tmr).

  • tmr (float, optional) – Target element size on the outer boundary (tm) and on the body boundary (tmr).

  • points (list of (x, y, z), optional) – Boundary points defining the body.

  • elementOrder (int, optional) – Lagrange element order (1 = P1, 2 = P2).

  • filename (str, optional) – Output mesh file name.

  • visualize (int, optional) – If nonzero, open the interactive Gmsh viewer before writing.

Returns:

The mesh is written to dirSave/filename.

Return type:

None

dpivsoft.meshTools.projection_FEM_Solver(path, dirSave, fileName='mesh', visualize=1)[source]

Solve the two auxiliary projection-potential problems on a mesh.

Solves the potential phi for unit motion in x and in y (each a Laplace problem with a Neumann body BC, see FEM_Solver), stacks the two solutions and their gradients, and computes the added-mass tensor. Optionally plots and saves the result as an .npz.

These projection potentials are the auxiliary fields of the vorticity-based force estimation (Fernández-Feria projection method).

Parameters:
  • path (str) – Path to the input mesh file (read with meshio).

  • dirSave (str or None) – Directory to save the .npz result; if not a string, nothing is written.

  • fileName (str, optional) – Base name of the saved .npz file.

  • visualize (int, optional) – If nonzero, plot the potential and gradient fields.

Returns:

  • mesh (skfem.Mesh) – The loaded finite-element mesh.

  • mesh_cell (np.ndarray) – Node coordinates, shape (num_nodes, 2).

  • mesh_elem (np.ndarray) – Element-centre coordinates, shape (num_elements, 2).

  • phi (np.ndarray) – Projection potentials, shape (2, num_nodes) for x and y motion.

  • grad_phi (np.ndarray) – Potential gradients at element centres, shape (2, 2, num_elements).

  • added_mass (np.ndarray) – 2x2 added-mass tensor.

dpivsoft.meshTools.FEM_Solver(mesh, direction)[source]

Solve one projection-potential Laplace problem on the mesh.

Solves ∇²φ = 0 with a Neumann condition n·∇φ = -n·direction on the body (“object” boundary) and a Dirichlet condition φ = 0 on the outer (“outbound”) boundary, using P1 elements. The nodal gradient is recovered by area-unweighted averaging of the surrounding element gradients.

Parameters:
  • mesh (skfem.Mesh) – Finite-element mesh with “object” and “outbound” boundaries.

  • direction (sequence of float) – Unit motion direction, e.g. [1, 0] for x or [0, 1] for y.

Returns:

  • mesh_cell (np.ndarray) – Node coordinates, shape (num_nodes, 2).

  • mesh_elem (np.ndarray) – Element-centre coordinates, shape (num_elements, 2).

  • phi (np.ndarray) – Potential at each node, shape (num_nodes,).

  • grad_phi (np.ndarray) – Potential gradient at element centres, shape (2, num_elements).

dpivsoft.meshTools.compute_added_mass(mesh, phi)[source]

Compute the 2x2 added-mass tensor from the projection potentials.

Each entry is the surface integral over the body boundary M[i, j] = -∮ n_i φ_j dS, where φ_j is the potential for unit motion in direction j.

Parameters:
  • mesh (skfem.Mesh) – Mesh with an “object” boundary.

  • phi (np.ndarray) – Projection potentials, shape (2, num_nodes).

Returns:

M – 2x2 added-mass tensor.

Return type:

np.ndarray

dpivsoft.meshTools.plotPhiResults(mesh, phi, grad_phi)[source]

Plot the projection potentials and their gradient components.

Draws the two potentials phi_x, phi_y on one figure and the four gradient components on a second figure.

Parameters:
  • mesh (skfem.Mesh) – The finite-element mesh.

  • phi (np.ndarray) – Projection potentials, shape (2, num_nodes).

  • grad_phi (np.ndarray) – Potential gradients, shape (2, 2, num_elements).

dpivsoft.meshTools.plot_mesh(mesh)[source]

Scatter-plot the mesh nodes coloured by physical region.

Outbound-boundary nodes are drawn in blue, body (“object”) nodes in red, and all remaining interior nodes in gray. Expects a meshio mesh with “line3” (P2) boundary cells tagged 102 (outbound) and 103 (object).

Parameters:

mesh (meshio.Mesh) – Mesh with gmsh:physical cell data on its “line3” cells.

dpivsoft.meshTools.projectionMesh2Grid(mesh_elem, grad_phi, X, Y, points, method='linear')[source]

Interpolate the potential-gradient field from the mesh to a grid.

Resamples the element-centre gradients grad_phi onto the regular (X, Y) grid and masks out points inside the body (via Postprocessing.Object).

Parameters:
  • mesh_elem (np.ndarray) – Element-centre coordinates, shape (num_elements, 2).

  • grad_phi (np.ndarray) – Potential gradients at element centres, shape (2, 2, num_elements).

  • X (np.ndarray) – Target grid coordinates.

  • Y (np.ndarray) – Target grid coordinates.

  • points (list of (x, y, z)) – Body boundary points, used to build the interior mask.

  • method (str, optional) – griddata interpolation method (‘linear’ by default).

Returns:

  • Phi (np.ndarray) – Zero-initialised potential array, shape (2, w, h) (placeholder; only the gradient is interpolated here).

  • gradPhi (np.ndarray) – Interpolated, body-masked gradients, shape (2, 2, w, h).

dpivsoft.meshTools.Read_Mesh(dirRes)[source]

Load a directory of PIV result .npz files into stacked arrays.

Reads every file in dirRes (sorted), stacking the velocity, pressure and vorticity fields along a time axis. Pressure defaults to zero when absent; vorticity is computed with the ‘circulation’ method (and the fields cropped by one cell on each side) when not stored.

Parameters:

dirRes (str) – Directory of .npz result files (this changes the working directory).

Returns:

  • X, Y (np.ndarray) – Grid coordinates.

  • U, V (np.ndarray) – Velocity components, shape (rows, cols, num_files).

  • Omega (np.ndarray) – Vorticity, same shape.

  • P (np.ndarray) – Pressure, same shape.

  • Name (list of str) – Sorted list of the loaded file names.