pc package¶
pc.grad1Filter module¶
-
class
pc.grad1Filter.Grad1Filter2d(dx, dy, kernel_size=3)¶ Bases:
torch.nn.modules.module.ModuleSobel filter to estimate 1st-order gradient in horizontal & vertical directions for a 2D image
- Parameters
dx (float) – Spatial discretization on x-axis
dy (float) – Spatial discretization on y-axis
kernel_size (int, optional) – Kernel size for gradient approximation, defaults to 3
- Raises
ValueError – If kernel_size is not 3 or 5
-
training: bool¶
-
xGrad(u)¶ Computes the gradient of the image in the x direction
- Parameters
u (torch.Tensor) – [B, 1, H, W] Input feature
- Returns
ux: [B, 1, H, W] x-gradient feature
- Return type
torch.Tensor
- Note
Does not compute edge gradients correctly
-
yGrad(u)¶ Computes the gradient of the image in the y direction
- Parameters
u (torch.Tensor) – [B, 1, H, W] Input feature to compute gradient
- Returns
uy: [B, 1, H, W] y-gradient feature
- Return type
torch.Tensor
- Note
Does not compute edge gradients correctly
pc.grad2Filter module¶
-
class
pc.grad2Filter.Grad2Filter2d(dx, dy, kernel_size=3)¶ Bases:
torch.nn.modules.module.ModuleSobel filter to estimate 2nd-order gradient in horizontal & vertical directions for a 2D image
- Parameters
dx (float) – Spatial discretization on x-axis
dy (float) – Spatial discretization on y-axis
kernel_size (int, optional) – Kernel size for gradient approximation, defaults to 3
- Raises
ValueError – If kernel_size is not 3 or 5
-
laplaceGrad(u)¶ Computes the laplacian, u_xx + u_yy
- Parameters
u (torch.Tensor) – [B, 1, H, W] Input feature
- Returns
u_lap: [B, 1, H, W] laplacian
- Return type
torch.Tensor
- Note
Does not compute edge gradients correctly
-
training: bool¶
-
xGrad(u)¶ Computes the gradient of the image in the x direction
- Parameters
u (torch.Tensor) – [B, 1, H, W] Input feature
- Returns
uxx: [B, 1, H, W] 2nd-order x-gradient feature
- Return type
torch.Tensor
- Note
Does not compute edge gradients correctly
-
yGrad(u)¶ Computes the gradient of the image in the y direction
- Parameters
u (torch.Tensor) – [B, 1, H, W] input feature to compute gradient
- Returns
uyy: [B, 1, H, W] 2nd-order y-gradient feature
- Return type
torch.Tensor
- Note
Does not compute edge gradients correctly
pc.physicsConstrained module¶
-
class
pc.physicsConstrained.PhysConstrainedLES(dx, dy, rho=1.0, grad_kernels=[3, 3])¶ Bases:
torch.nn.modules.module.ModuleComputing residual base losses for the Navier-Stokes equations
- Parameters
dx (float) – Spatial discretization on x-axis
dy (float) – Spatial discretization on y-axis
rho (float, optional) – Density of fluid, defaults to 1.0
grad_kernels (list, optional) – List of kernel sizes for 1st and 2nd order gradients, defaults to [3, 3]
-
calcDivergence(uPred, scale=True)¶ Calculates the divergence of a velocity field
- Parameters
uPred (torch.Tensor) – [B, 2, H, W] Input velocity field
scale (bool, optional) – Scale the residual by dx, defaults to True
- Returns
ustar: [B, 1, H, W] Divergence field
- Return type
torch.Tensor
- Note
Residual is not calculated on edges where gradients are not correct
-
calcPressurePoisson(uPred, pPred, scale=True)¶ Calcs residual of the pressure poisson equation
- Parameters
uPred (torch.Tensor) – [B, 2, H, W] Input velocity field
uPred – [B, 1, H, W] Input pressure field
scale (bool, optional) – Scale the residual by cell area (dx*dy), defaults to True
- Returns
pstar: [B, 1, H, W] Divergence field
- Return type
torch.Tensor
- Note
Residual is not calculated on edges where gradients are not correct
- Note
A good reference for additional information http://www.thevisualroom.com/poisson_for_pressure.html
-
training: bool¶