dpivsoft.Postprocessing¶
- dpivsoft.Postprocessing.vorticity(x, y, u, v, method)[source]¶
Vorticity omega = dv/dx - du/dy¶
Calculates the vorticity of a vector field u,v in a domain x,y, by different methods. The methods are described in Markus Raffel, Christian E. Willert, Steven T. Wereley, Jürgen Kompenhans Experimental Fluid Mechanics Particle image velocimetry: a practical guide [2nd ed.] Springer-Verlag
WARNING: Only works for equispaced data with x and y produced by meshgrid.
- The output is omega of size
leastsq = (Nx-4)*(Ny-4) centered = (Nx-2)*(Ny-2) richardson = (Nx-4)*(Ny-4) circulation = (Nx-2)*(Ny-2) curl = (Nx-2)*(Ny-2)
Parras Universidad de Malaga (2014)
- dpivsoft.Postprocessing.vortex_profile(xo, yo, rmax, x, y, u, v, xv, yv, omega, nr, ntheta)[source]¶
Vortex data
Inputs:¶
- xo: float
x position of the vortex center
- yo: float
y position of the vortex center
- rmax: float
Radious of the polar grid to
- x: 2d float array
x meshgrid
- y: 2d float array
y meshgrid
- omega: 2d float array
vorticty on the x,y meshgrid
- nr: float
number of points to interpolate along the radious on the polar grid
- n:theta
number of points to interpolate along the angle on the polar grid
Outputs:¶
- R: float array
radious of the interpolated polar grid
- utheta_mean: float array
mean azimuthal velocity along the radious of the interpolated polar grid
- omega_mean: float array
mean azimuthal velocity along the radious of the interpolated polar grid
- gamma_mean: float array
mean azimuthal velocity along the radious of the interpolated polar grid
- dpivsoft.Postprocessing.walls_vorticity(xx, yy, pos_x, pos_y, x, y, u, v, omega)[source]¶
Modify vorticy over the walls of an object. The derivatives to obtain the curl, are done in forward diferences following the surface normal vector direction.
Inputs:¶
- xx: float array
x points along object surface
- yy: float array
y points along object surface
- pos_x: float array
x index of points on object surface
- pos_y: float array
y index of points on object surface
- x: 2d float array
x meshgrid
- y: 2d float array
y meshgrid
- u: 2d float array
velocity in x direction of the field
- v: 2d float array
velocity in y direction of the field
- omega: 2d float array
vorticity on the x,y meshgrid
Outputs:¶
- omega: 2d float array
fixed vorticity on the x,y meshgrid
- dpivsoft.Postprocessing.divergence(x, y, u, v)[source]¶
Return divergence of the 2D flow, which for a incompressible flow should be zero
Inputs:¶
- x: 2d float array
x meshgrid
- y: 2d float array
y meshgrid
- u: 2d float array
velocity in x direction of the field
- v: 2d float array
velocity in y direction of the field
Inputs:¶
- flow_divergence: 2d float array
divergence of the 2d flow
- dpivsoft.Postprocessing.stream_lines(x, y, u, v)[source]¶
Plot streamlines of the computed 2d flow
Inputs:¶
- x: 2d float array
x meshgrid
- y: 2d float array
y meshgrid
- u: 2d float array
velocity in x direction of the field
- v: 2d float array
velocity in y direction of the field
- dpivsoft.Postprocessing.ImpulseMethod(x, y, u, v, omega, rho, Vsol, mu, solid_points, t, accel=0)[source]¶
Obtain forces over an object using Vortical impulse method, described by J.-Z. Wu, X.-Y. Lu, and L.-X. Zhuang. Integral force acting on a body due to local flow structures. J. Fluid Mech., 576:265286, 2007. AIAA J., 19:432–441, 1981. This formulation is based on the one presented in Martín-Alcántara, A., & Fernandez-Feria, R. (2019). Assessment of two vortex formulations for computing forces of a flapping foil at high Reynolds numbers. Physical Review Fluids, 4(2), 024702. but written in dimensional version. The reference frame must be always centered in the object. In case of an accelerated reference frame, it is taken into account by accel.
Inputs:¶
- x: 2D float array
X-coordinates of the mesh grid over the flow field.
- y: 2D float array
Y-coordinates of the mesh grid over the flow field.
- u: 2D float array
Velocity field in the x-direction, defined on the x, y grid.
- v: 2D float array
Velocity field in the y-direction, defined on the x, y grid.
- omega: 2D float array
Vorticity field on the same x, y grid.
- rho: float
Fluid density. This is a constant value for the entire domain.
- Vsol: float
Volume of the solid object immersed in the fluid. Used for calculating forces due to added mass, etc.
- mu: float
Dynamic viscosity of the fluid. Also constant throughout the domain.
- solid_points: list of coordinates tuples
Coordinates or mask identifying the solid object within the fluid as a list of (x, y) tuples
- t: 1D float array
Time vector. Each element corresponds to a frame or timestep in the simulation or measurement.
- accel: 2D float array
Instantaneous acceleration in x and y direction of the moving reference frame (centered on the object). Shape (N,2)
Outputs:¶
- F_v: 2D foat array
Term of vortex force. Size (N,2), for x and y components.
- F_i: 2D float array
Impulse term of the force. Size (N,2), for x and y components.
- Fsol: 2D float array
Force integrated over the volume of the object. Size (N,2), for x and y components.
- F_oe: 2D float array
Contribution to the total force of the vorticity leaving the control volume. Size (N,2), for x and y components.
- F_mu: 2D float array
Viscous contribution to the force of vorticity leaving the control volume. Size (N,2), for x and y components.
- dpivsoft.Postprocessing.ProjectionMethod(x, y, u, v, omega, grad_phi, rho, mu, solid_points, added_m=array([0., 0.]), accel=0)[source]¶
Obtain forces over an object using projection method. The formulation used is from C.-C. Chang. Potential flow and forces for the incompressible viscous flow. Proc. R. Soc. A-Math. Phys. Engng Sci., 437:517–525, 1992. This formulation is based on the one presented in Martín-Alcántara, A., & Fernandez-Feria, R. (2019). Assessment of two vortex formulations for computing forces of a flapping foil at high Reynolds numbers. Physical Review Fluids, 4(2), 024702. but written in dimensional version. The reference frame must be centered in the object and accelerations on it are taken into account by accel.
Inputs:¶
- x: 2D float array
X-coordinates of the mesh grid over the flow field.
- y: 2D float array
Y-coordinates of the mesh grid over the flow field.
- u: 2D float array
Velocity field in the x-direction, defined on the x, y grid.
- v: 2D float array
Velocity field in the y-direction, defined on the x, y grid.
- omega: 2D float array
Vorticity field on the same x, y grid.
- grad_phi: 4D float array
Gradients of the two projection potentials, given by solving ∇2 ϕ = 0 , ns · ∇ϕ = −ns dimension of (2,2,y,x) with grad_phi[i,j] = dϕ_i/dx_j, arranged like:
[ϕ_xx, ϕ_xy] [ϕ_yx, ϕ_yy]
- rho: float
Fluid density. This is a constant value for the entire domain.
- mu: float
Dynamic viscosity of the fluid. Also constant throughout the domain.
- solid_points: list of coordinates tuples
Coordinates or mask identifying the solid object within the fluid as a list of (x, y) tuples
- t: 1D float array
Time vector. Each element corresponds to a frame or timestep in the simulation or measurement.
- added_m: float list
added mass tensor obtained from integrating ϕ(∂ϕ/∂n)dS along the solid surface. Only needed if accelerated reference frame.
- accel: 2D float array
Instantaneous acceleration in x and y direction of the moving reference frame (centered on the object). Shape (N,2)
Outputs:¶
- F: 2D float array
Total force over the object. Size (N,2), for x and y components.
- Fv: 2D float array
Vortical contribution to force. Size (N,2), for x and y components.
- Fmu: 2D float array
Viscous contribution to force. Size (N,2), for x and y components.
- dpivsoft.Postprocessing.Surface_projection(xx, yy, pos_x, pos_y, grad_phi, omega, mu)[source]¶
Compute the viscous vortex-force contribution on a solid surface for the projection method.
The object boundary is defined by ordered points (xx, yy) and their corresponding mesh indices (pos_x, pos_y). Normal vectors are estimated along the path, and the viscous contribution is integrated using Simpson’s rule.
Inputs:¶
- xx, yy: 1D float arrays
Ordered coordinates of the object boundary.
- pos_x, pos_y: 1D int arrays
Mesh indices corresponding to the boundary coordinates.
- x, y: 2D float arrays
Mesh grid coordinates (used only for consistency).
- grad_phi: 4D float array
Hessian of the potential function, shape (2, 2, ny, nx).
- omega: 3D float array
Vorticity field over time, shape (ny, nx, nt).
- mu: float
Dynamic viscosity of the fluid.
Outputs:¶
- Fx: 1D float array
x-component of the viscous surface force over time.
- Fy: 1D float array
y-component of the viscous surface force over time.
- dpivsoft.Postprocessing.Object(x, y, points, res=4)[source]¶
Generate a binary mask and extract ordered boundary coordinates of a 2D object defined by a polygon within a structured mesh. The function identifies which mesh nodes lie inside the polygon, detects the boundary via dilation, and reorders the perimeter points to form a continuous path using a nearest-neighbor graph.
Inputs:¶
- x: 2D float array
X-coordinates of the mesh grid.
- y: 2D float array
Y-coordinates of the mesh grid.
- points: array-like
(x, y) coordinates defining the polygonal shape of the object.
- res: int, optional
Decimal precision for rounding mesh coordinates (default = 4).
Outputs:¶
- x: 1D float array
Ordered x-coordinates of boundary points.
- y: 1D float array
Ordered y-coordinates of boundary points.
- posx: 1D int array
Mesh x-indices of boundary points.
- posy: 1D int array
Mesh y-indices of boundary points.
- mesh: 2D uint8 array
Binary mask of the domain (0 = solid, 1 = fluid).
- dpivsoft.Postprocessing.ControlVolume(x, y, u, v, rho, mu, t, accel=0, p=0)[source]¶
Compute hydrodynamic forces on a 2D body using the Control Volume method, based on the integral formulation of the momentum equation applied to a moving volume enclosing the body. This method follows the approach described in:
FERIA, Ramón Fernández; CASANOVA, J. Ortega. Mecánica de fluidos. Servicio de Publicaciones e Intercambio Científico de la Universidad de Málaga, 2001.
The implementation assumes a 2D incompressible flow over a domain defined by the (x, y) mesh, with velocity fields u and v. The control volume encloses the object and may be moving or accelerating. The total force is computed from several contributing terms: the unsteady and convective momentum flux, pressure contribution, viscous stresses, and added-mass effect if the reference frame is non-inertial.
The reference frame must always be centered on the object. In case of a moving or accelerated frame, the added-mass correction is applied using accel.
Inputs:¶
- x: 2D float array
X-coordinates of the mesh grid over the flow field.
- y: 2D float array
Y-coordinates of the mesh grid over the flow field.
- u: 3D float array
X-component of the velocity field over time. Shape (nx, ny, nt).
- v: 3D float array
Y-component of the velocity field over time. Shape (nx, ny, nt).
- rho: float
Fluid density (assumed constant).
- mu: float
Dynamic viscosity of the fluid (assumed constant).
- t: 1D float array
Time vector. Each entry corresponds to a timestep.
- accel: float or 2D float array, optional
Acceleration of the reference frame. If scalar, assumed zero contribution. If array of shape (nt, 2), it is used for added mass correction.
- p: 2D float array or float, optional
Pressure field (same shape as u and v) or scalar zero if not used.
Outputs:¶
- F_v: 2D float array
Convective momentum flux contribution to total force. Shape (nt, 2).
- F_i: 2D float array
Local (unsteady) momentum contribution. Shape (nt, 2).
- Fsol: 2D float array
Added-mass term due to acceleration of the control volume. Shape (nt, 2).
- F_oe: 2D float array
Net outflow of momentum across control volume boundaries. Shape (nt, 2).
- F_mu: 2D float array
Viscous stress contribution to the force. Shape (nt, 2).
- dpivsoft.Postprocessing.FieldDerivatives(rho, dx, dy, u, v, accel, mu, dt)[source]¶
Compute the spatial/temporal velocity derivatives and the pressure gradient field for the Control Volume method.
Spatial derivatives use central finite differences (which crops one node off each spatial border); time derivatives are central in the interior and one-sided at the first/last frame. The pressure gradient is obtained from the incompressible momentum equation
∇p = mu·∇²u - rho·(u·∇)u - rho·∂u/∂ton the cropped domain.Inputs:¶
- rho: float
Fluid density.
- dx, dy: float
Grid spacing in x and y.
- u, v: 3D float array
Velocity components over time, shape (ny, nx, nt).
- accel: float or 2D float array
Reference-frame acceleration (unused here; kept for signature consistency with the caller).
- mu: float
Dynamic viscosity.
- dt: float
Time step between frames.
Outputs:¶
- Gradx, Grady: 3D float array
x and y components of the pressure gradient on the cropped (interior) domain, shape (ny-2, nx-2, nt).
- u, v: 3D float array
Velocity components cropped to the interior domain.
- dudx, dudy, dvdx, dvdy: 3D float array
First spatial derivatives of the velocity on the interior domain.