NVIDIA Modulus Sym (Latest Release)
Sym (Latest Release)

Modulus Sym Equations and Utils

Advection diffusion equation Reference: https://en.wikipedia.org/wiki/Convection%E2%80%93diffusion_equation

class modulus.sym.eq.pdes.advection_diffusion.AdvectionDiffusion(T='T', D='D', Q=0, rho='rho', dim=3, time=False, mixed_form=False)[source]

Bases: PDE

Advection diffusion equation

Parameters
  • T (str) – The dependent variable.

  • D (float, Sympy Symbol/Expr, str) – Diffusivity. If D is a str then it is converted to Sympy Function of form ‘D(x,y,z,t)’. If ‘D’ is a Sympy Symbol or Expression then this is substituted into the equation.

  • Q (float, Sympy Symbol/Expr, str) – The source term. If Q is a str then it is converted to Sympy Function of form ‘Q(x,y,z,t)’. If ‘Q’ is a Sympy Symbol or Expression then this is substituted into the equation. Default is 0.

  • rho (float, Sympy Symbol/Expr, str) – The density. If rho is a str then it is converted to Sympy Function of form ‘rho(x,y,z,t)’. If ‘rho’ is a Sympy Symbol or Expression then this is substituted into the equation to allow for compressible Navier Stokes.

  • dim (int) – Dimension of the diffusion equation (1, 2, or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is False.

  • mixed_form (bool) – If True, use the mixed formulation of the wave equation.

Examples

Copy
Copied!
            

>>> ad = AdvectionDiffusion(D=0.1, rho=1.) >>> ad.pprint() advection_diffusion: u*T__x + v*T__y + w*T__z - 0.1*T__x__x - 0.1*T__y__y - 0.1*T__z__z >>> ad = AdvectionDiffusion(D='D', rho=1, dim=2, time=True) >>> ad.pprint() advection_diffusion: -D*T__x__x - D*T__y__y + u*T__x + v*T__y - D__x*T__x - D__y*T__y + T__t

Basic equations

class modulus.sym.eq.pdes.basic.Curl(vector, curl_name=['u', 'v', 'w'])[source]

Bases: PDE

del cross vector operator

Parameters
  • vector (tuple of 3 Sympy Exprs, floats, ints or strings) – This will be the vector to take the curl of.

  • curl_name (tuple of 3 strings) – These will be the output names of the curl operations.

Examples

Copy
Copied!
            

>>> c = Curl((0,0,'phi'), ('u','v','w')) >>> c.pprint() u: phi__y v: -phi__x w: 0

class modulus.sym.eq.pdes.basic.GradNormal(T, dim=3, time=True)[source]

Bases: PDE

Implementation of the gradient boundary condition

Parameters
  • T (str) – The dependent variable.

  • dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

Examples

Copy
Copied!
            

>>> gn = ns = GradNormal(T='T') >>> gn.pprint() normal_gradient_T: normal_x*T__x + normal_y*T__y + normal_z*T__z

class modulus.sym.eq.pdes.basic.NormalDotVec(vec=['u', 'v', 'w'])[source]

Bases: PDE

Normal dot velocity

Parameters

dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

Diffusion equation

class modulus.sym.eq.pdes.diffusion.Diffusion(T='T', D='D', Q=0, dim=3, time=True, mixed_form=False)[source]

Bases: PDE

Diffusion equation

Parameters
  • T (str) – The dependent variable.

  • D (float, Sympy Symbol/Expr, str) – Diffusivity. If D is a str then it is converted to Sympy Function of form ‘D(x,y,z,t)’. If ‘D’ is a Sympy Symbol or Expression then this is substituted into the equation.

  • Q (float, Sympy Symbol/Expr, str) – The source term. If Q is a str then it is converted to Sympy Function of form ‘Q(x,y,z,t)’. If ‘Q’ is a Sympy Symbol or Expression then this is substituted into the equation. Default is 0.

  • dim (int) – Dimension of the diffusion equation (1, 2, or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

  • mixed_form (bool) – If True, use the mixed formulation of the diffusion equations.

Examples

Copy
Copied!
            

>>> diff = Diffusion(D=0.1, Q=1, dim=2) >>> diff.pprint() diffusion_T: T__t - 0.1*T__x__x - 0.1*T__y__y - 1 >>> diff = Diffusion(T='u', D='D', Q='Q', dim=3, time=False) >>> diff.pprint() diffusion_u: -D*u__x__x - D*u__y__y - D*u__z__z - Q - D__x*u__x - D__y*u__y - D__z*u__z

class modulus.sym.eq.pdes.diffusion.DiffusionInterface(T_1, T_2, D_1, D_2, dim=3, time=True)[source]

Bases: PDE

Matches the boundary conditions at an interface

Parameters
  • T_1 (str) – Dependent variables to match the boundary conditions at the interface.

  • T_2 (str) – Dependent variables to match the boundary conditions at the interface.

  • D_1 (float) – Diffusivity at the interface.

  • D_2 (float) – Diffusivity at the interface.

  • dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

Example

Copy
Copied!
            

>>> diff = DiffusionInterface('theta_s', 'theta_f', 0.1, 0.05, dim=2) >>> diff.pprint() diffusion_interface_dirichlet_theta_s_theta_f: -theta_f + theta_s diffusion_interface_neumann_theta_s_theta_f: -0.05*normal_x*theta_f__x + 0.1*normal_x*theta_s__x - 0.05*normal_y*theta_f__y + 0.1*normal_y*theta_s__y

Maxwell’s equation

class modulus.sym.eq.pdes.electromagnetic.MaxwellFreqReal(ux='ux', uy='uy', uz='uz', k=1.0, mixed_form=False)[source]

Bases: PDE

Frequency domain Maxwell’s equation

Parameters
  • ux (str) – Ex

  • uy (str) – Ey

  • uz (str) – Ez

  • k (float, Sympy Symbol/Expr, str) – Wave number. If k is a str then it is converted to Sympy Function of form ‘k(x,y,z,t)’. If ‘k’ is a Sympy Symbol or Expression then this is substituted into the equation.

  • mixed_form (bool) – If True, use the mixed formulation of the diffusion equations.

class modulus.sym.eq.pdes.electromagnetic.PEC(ux='ux', uy='uy', uz='uz', dim=3)[source]

Bases: PDE

Perfect Electric Conduct BC for

Parameters
  • ux (str) – Ex

  • uy (str) – Ey

  • uz (str) – Ez

  • dim (int) – Dimension of the equations (2, or 3). Default is 3.

class modulus.sym.eq.pdes.electromagnetic.SommerfeldBC(ux='ux', uy='uy', uz='uz')[source]

Bases: PDE

Frequency domain ABC, Sommerfeld radiation condition Only for real part Equation: ‘n x _curl(E) = 0’

Parameters
  • ux (str) – Ex

  • uy (str) – Ey

  • uz (str) – Ez

Equations related to linear elasticity

class modulus.sym.eq.pdes.linear_elasticity.LinearElasticity(E=None, nu=None, lambda_=None, mu=None, rho=1, dim=3, time=False)[source]

Bases: PDE

Linear elasticity equations. Use either (E, nu) or (lambda_, mu) to define the material properties.

Parameters
  • E (float, Sympy Symbol/Expr, str) – The Young’s modulus

  • nu (float, Sympy Symbol/Expr, str) – The Poisson’s ratio

  • lambda (float, Sympy Symbol/Expr, str) – Lamé’s first parameter

  • mu (float, Sympy Symbol/Expr, str) – Lamé’s second parameter (shear modulus)

  • rho (float, Sympy Symbol/Expr, str) – Mass density.

  • dim (int) – Dimension of the linear elasticity (2 or 3). Default is 3.

Example

Copy
Copied!
            

>>> elasticity_equations = LinearElasticity(E=10, nu=0.3, dim=2) >>> elasticity_equations.pprint() navier_x: -13.4615384615385*u__x__x - 3.84615384615385*u__y__y - 9.61538461538461*v__x__y navier_y: -3.84615384615385*v__x__x - 13.4615384615385*v__y__y - 9.61538461538461*u__x__y stress_disp_xx: -sigma_xx + 13.4615384615385*u__x + 5.76923076923077*v__y stress_disp_yy: -sigma_yy + 5.76923076923077*u__x + 13.4615384615385*v__y stress_disp_xy: -sigma_xy + 3.84615384615385*u__y + 3.84615384615385*v__x equilibrium_x: -sigma_xx__x - sigma_xy__y equilibrium_y: -sigma_xy__x - sigma_yy__y traction_x: normal_x*sigma_xx + normal_y*sigma_xy traction_y: normal_x*sigma_xy + normal_y*sigma_yy

class modulus.sym.eq.pdes.linear_elasticity.LinearElasticityPlaneStress(E=None, nu=None, lambda_=None, mu=None, rho=1, time=False)[source]

Bases: PDE

Linear elasticity plane stress equations. Use either (E, nu) or (lambda_, mu) to define the material properties.

Parameters
  • E (float, Sympy Symbol/Expr, str) – The Young’s modulus

  • nu (float, Sympy Symbol/Expr, str) – The Poisson’s ratio

  • lambda (float, Sympy Symbol/Expr, str) – Lamé’s first parameter.

  • mu (float, Sympy Symbol/Expr, str) – Lamé’s second parameter (shear modulus)

  • rho (float, Sympy Symbol/Expr, str) – Mass density.

Example

Copy
Copied!
            

>>> plane_stress_equations = LinearElasticityPlaneStress(E=10, nu=0.3) >>> plane_stress_equations.pprint() stress_disp_xx: -sigma_xx + 10.989010989011*u__x + 3.2967032967033*v__y stress_disp_yy: -sigma_yy + 3.2967032967033*u__x + 10.989010989011*v__y stress_disp_xy: -sigma_xy + 3.84615384615385*u__y + 3.84615384615385*v__x equilibrium_x: -sigma_xx__x - sigma_xy__y equilibrium_y: -sigma_xy__x - sigma_yy__y traction_x: normal_x*sigma_xx + normal_y*sigma_xy traction_y: normal_x*sigma_xy + normal_y*sigma_yy

Equations related to Navier Stokes Equations

class modulus.sym.eq.pdes.navier_stokes.CompressibleIntegralContinuity(rho=1, vec=['u', 'v', 'w'])[source]

Bases: PDE

Compressible Integral Continuity

Parameters
  • rho (float, Sympy Symbol/Expr, str) – The density of the fluid. If rho is a str then it is converted to Sympy Function of form ‘rho(x,y,z,t)’. If ‘rho’ is a Sympy Symbol or Expression then this is substituted into the equation to allow for compressibility. Default is 1.

  • dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

class modulus.sym.eq.pdes.navier_stokes.Curl(vector, curl_name=['u', 'v', 'w'])[source]

Bases: PDE

del cross vector operator

Parameters
  • vector (tuple of 3 Sympy Exprs, floats, ints or strings) – This will be the vector to take the curl of.

  • curl_name (tuple of 3 strings) – These will be the output names of the curl operations.

Examples

Copy
Copied!
            

>>> c = Curl((0,0,'phi'), ('u','v','w')) >>> c.pprint() u: phi__y v: -phi__x w: 0

class modulus.sym.eq.pdes.navier_stokes.FluxContinuity(T='T', D='D', rho=1, vec=['u', 'v', 'w'])[source]

Bases: PDE

Flux Continuity for arbitrary variable. Includes advective and diffusive flux

Parameters
  • T (str) – The dependent variable.

  • rho (float, Sympy Symbol/Expr, str) – The density of the fluid. If rho is a str then it is converted to Sympy Function of form ‘rho(x,y,z,t)’. If ‘rho’ is a Sympy Symbol or Expression then this is substituted into the equation to allow for compressibility. Default is 1.

  • dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

class modulus.sym.eq.pdes.navier_stokes.GradNormal(T, dim=3, time=True)[source]

Bases: PDE

Implementation of the gradient boundary condition

Parameters
  • T (str) – The dependent variable.

  • dim (int) – Dimension of the equations (1, 2, or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

Examples

Copy
Copied!
            

>>> gn = ns = GradNormal(T='T') >>> gn.pprint() normal_gradient_T: normal_x*T__x + normal_y*T__y + normal_z*T__z

class modulus.sym.eq.pdes.navier_stokes.NavierStokes(nu, rho=1, dim=3, time=True, mixed_form=False)[source]

Bases: PDE

Compressible Navier Stokes equations Reference: https://turbmodels.larc.nasa.gov/implementrans.html

Parameters
  • nu (float, Sympy Symbol/Expr, str) – The kinematic viscosity. If nu is a str then it is converted to Sympy Function of form nu(x,y,z,t). If nu is a Sympy Symbol or Expression then this is substituted into the equation. This allows for variable viscosity.

  • rho (float, Sympy Symbol/Expr, str) – The density of the fluid. If rho is a str then it is converted to Sympy Function of form ‘rho(x,y,z,t)’. If ‘rho’ is a Sympy Symbol or Expression then this is substituted into the equation to allow for compressible Navier Stokes. Default is 1.

  • dim (int) – Dimension of the Navier Stokes (2 or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

  • mixed_form (bool) – If True, use the mixed formulation of the Navier-Stokes equations.

Examples

Copy
Copied!
            

>>> ns = NavierStokes(nu=0.01, rho=1, dim=2) >>> ns.pprint() continuity: u__x + v__y momentum_x: u*u__x + v*u__y + p__x + u__t - 0.01*u__x__x - 0.01*u__y__y momentum_y: u*v__x + v*v__y + p__y + v__t - 0.01*v__x__x - 0.01*v__y__y >>> ns = NavierStokes(nu='nu', rho=1, dim=2, time=False) >>> ns.pprint() continuity: u__x + v__y momentum_x: -nu*u__x__x - nu*u__y__y + u*u__x + v*u__y - 2*nu__x*u__x - nu__y*u__y - nu__y*v__x + p__x momentum_y: -nu*v__x__x - nu*v__y__y + u*v__x + v*v__y - nu__x*u__y - nu__x*v__x - 2*nu__y*v__y + p__y

Screened Poisson Distance Equation taken from, https://www.researchgate.net/publication/266149392_Dynamic_Distance-Based_Shape_Features_for_Gait_Recognition, Equation 6 in paper.

class modulus.sym.eq.pdes.signed_distance_function.ScreenedPoissonDistance(distance='normal_distance', tau=0.1, dim=3)[source]

Bases: PDE

Screened Poisson Distance

Parameters
  • distance (str) – A user-defined variable for distance. Default is “normal_distance”.

  • tau (float) – A small, positive parameter. Default is 0.1.

  • dim (int) – Dimension of the Screened Poisson Distance (1, 2, or 3). Default is 3.

Example

Copy
Copied!
            

>>> s = ScreenedPoissonDistance(tau=0.1, dim=2) >>> s.pprint() screened_poisson_normal_distance: -normal_distance__x**2 + 0.316227766016838*normal_distance__x__x - normal_distance__y**2 + 0.316227766016838*normal_distance__y__y + 1

Zero Equation Turbulence model References: https://www.eureka.im/954.html https://knowledge.autodesk.com/support/cfd/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/SimCFD-Learning/files/GUID-BBA4E008-8346-465B-9FD3-D193CF108AF0-htm.html

class modulus.sym.eq.pdes.turbulence_zero_eq.ZeroEquation(nu, max_distance, rho=1, dim=3, time=True)[source]

Bases: PDE

Zero Equation Turbulence model

Parameters
  • nu (float) – The kinematic viscosity of the fluid.

  • max_distance (float) – The maximum wall distance in the flow field.

  • rho (float, Sympy Symbol/Expr, str) – The density. If rho is a str then it is converted to Sympy Function of form ‘rho(x,y,z,t)’. If ‘rho’ is a Sympy Symbol or Expression then this is substituted into the equation. Default is 1.

  • dim (int) – Dimension of the Zero Equation Turbulence model (2 or 3). Default is 3.

  • time (bool) – If time-dependent equations or not. Default is True.

Example

Copy
Copied!
            

>>> zeroEq = ZeroEquation(nu=0.1, max_distance=2.0, dim=2) >>> kEp.pprint() nu: sqrt((u__y + v__x)**2 + 2*u__x**2 + 2*v__y**2) *Min(0.18, 0.419*normal_distance)**2 + 0.1

Wave equation Reference: https://en.wikipedia.org/wiki/Wave_equation

class modulus.sym.eq.pdes.wave_equation.HelmholtzEquation(u, k, dim=3, mixed_form=False)[source]

Bases: PDE

class modulus.sym.eq.pdes.wave_equation.WaveEquation(u='u', c='c', dim=3, time=True, mixed_form=False)[source]

Bases: PDE

Wave equation

Parameters
  • u (str) – The dependent variable.

  • c (float, Sympy Symbol/Expr, str) – Wave speed coefficient. If c is a str then it is converted to Sympy Function of form ‘c(x,y,z,t)’. If ‘c’ is a Sympy Symbol or Expression then this is substituted into the equation.

  • dim (int) – Dimension of the wave equation (1, 2, or 3). Default is 2.

  • time (bool) – If time-dependent equations or not. Default is True.

  • mixed_form (bool) – If True, use the mixed formulation of the wave equation.

Examples

Copy
Copied!
            

>>> we = WaveEquation(c=0.8, dim=3) >>> we.pprint() wave_equation: u__t__t - 0.64*u__x__x - 0.64*u__y__y - 0.64*u__z__z >>> we = WaveEquation(c='c', dim=2, time=False) >>> we.pprint() wave_equation: -c**2*u__x__x - c**2*u__y__y - 2*c*c__x*u__x - 2*c*c__y*u__y

class modulus.sym.eq.phy_informer.PhysicsInformer(required_outputs: List[str], equations: PDE, grad_method: str, fd_dx: Union[float, List[float]] = 0.001, bounds: List[float] = [6.283185307179586, 6.283185307179586, 6.283185307179586], compute_connectivity: bool = True, device: Optional[str] = None)[source]

Bases: object

A utility to compute the residual of a Partial Differential Equation (PDE). Given the equations and required_outputs, this utility constructs the computational graph, including computing of the derivatives to output the residuals.

This utility computes the spatial grads automatically. Currently the spatial grads are computed using “autodiff”, “meshless_finite_difference”, “finite_difference”, “spectral”, and “least_squares” methods. All the other gradients (such as gradients w.r.t. time) will have to be manually included in the input_dict to the forward call.

Parameters
  • required_outputs (List[str]) – Required keys in the output dictionary. To find the available outputs of a PDE, you can use the .pprint() method.

  • equations (PDE) – Equation to use for computing the residual. The equation must be in the form of Modulus Sym’s PDE. For more details, refer: https://docs.nvidia.com/deeplearning/modulus/modulus-sym/user_guide/features/nodes.html#equations. Custom PDEs are also supported. For details refer: https://docs.nvidia.com/deeplearning/modulus/modulus-sym/user_guide/features/nodes.html#custom-pdes

  • grad_method (str) –

    Gradient method to use. Currently below methods are supported, which can be selected based on the model output format:

    autodiff: The spatial gradients are computed using automatic differentiation. Ideal for networks dealing with point-clouds and fully-differentiable networks. The .forward call requires input dict with the relevant variables in [N, 1] shape along with entry for “coordinates” in [N, m] shape where m is the dimensionality of the input (1/2/3 based on 1D, 2D and 3D). Note: the coordinates tensor must have requires_grad set to True and the model outputs need to be connected to the coordinates in the computational graph. meshless_finite_difference: The spatial gradients are computed using meshless finite difference. Ideal for use with point-clouds. For details refer: https://docs.nvidia.com/deeplearning/modulus/modulus-sym/user_guide/features/performance.html#meshless-finite-derivatives. The .forward call requires input dict with the relevant variables in [N, 1] shape along with the same variables executed at the stencil points. Stencil points are defined by the following convention:

    ”u>>x::1”: u(i+1, j) “u>>x::-1”: u(i-1, j) “u>>x::1&&y::1”: u(i+1, j+1) “u>>x::-1&&y::-1”: u(i-1, j-1) etc.

    finite_difference: The spatial gradients are computed using finite difference assuming regular grid. Ideal for use with regular grids / images. The .forward call requires input dict with the relevant variables in [N, 1, H, W, D] for 3D, [N, 1, H, W] for 2D and [N, 1, H] for 1D. spectral: The spatial gradients are computed using FFTs. Note: this can lead to boundary artifacts for non-periodic signals. Ideal for use with regular grids / images. The .forward call requires input dict with the relevant variables in [N, 1, H, W, D] for 3D, [N, 1, H, W] for 2D and [N, 1, H] for 1D. least_squares: The spatial gradients are computed using Least Squares technique. Ideal for use with mesh based representations. All values are computed at the nodes. The .forward call requires input dict with the relevant variables in [N, 1] shape along with entry for “coordinates” in [N, m] shape where m is the dimensionality of the input (1/2/3 based on 1D, 2D and 3D), “node_ids”, “edges” and “connectivity_tensor”. The “node_ids” and “edges” can directly derived from the graph representation (for example for dgl graph, by running graph.nodes() and graph.edges()). For computing connectivity tensor, refer: modulus.sym.eq.spatial_grads.spatial_grads.compute_connectivity_tensor

  • fd_dx (Union[float, List[float]], optional) – dx to be used for meshless finite difference and regular finite difference calculation. If float, the same value is used across all dimensions, by default 0.001

  • bounds (List[float], optional) – bounds to be used for spectral derivatives, by default [2 * np.pi, 2 * np.pi, 2 * np.pi]

  • compute_connectivity (bool, optional) – Wether to compute the connectivity tensor during forward pass (only applies for least squares method), by default True. Set to false if this can be computed as a part of the dataloader.

  • device (Optional[str], optional) – The device to use for computation. Options are “cuda” or “cpu”. If not specified, the computation defaults to “cpu”.

Examples

Copy
Copied!
            

>>> import torch >>> from modulus.sym.eq.pdes.navier_stokes import NavierStokes >>> from modulus.sym.eq.phy_informer import PhysicsInformer >>> ns = NavierStokes(nu=0.1, rho=1.0, dim=2, time=True) >>> phy_inf = PhysicsInformer( ... required_outputs=["continuity", "momentum_x"], ... equations=ns, ... grad_method="finite_difference" ... ) >>> tensor = torch.rand(1, 1, 10, 10) # [N, 1, H, W] >>> sorted(phy_inf.required_inputs) ... ['p', 'u', 'u__t', 'v'] >>> out_dict = phy_inf.forward({"u": tensor, "v": tensor, "u__t": tensor, "p": tensor}) >>> out_dict.keys() dict_keys(['continuity', 'momentum_x']) >>> out_dict["continuity"].shape torch.Size([1, 1, 10, 10])

forward(inputs)[source]

Forward pass

property required_inputs

Find the required inputs

class modulus.sym.eq.spatial_grads.spatial_grads.GradientCalculator(device: Optional[str] = None)[source]

Bases: object

Unified Gradient calculator class.

Parameters

device (Optional[str], optional) – The device to use for computation. Options are “cuda” or “cpu”. If not specified, the computation defaults to “cpu”.

Examples

Copy
Copied!
            

>>> import torch >>> from modulus.sym.eq.spatial_grads.spatial_grads import GradientCalculator >>> coords = torch.rand(10, 3).requires_grad_(True) >>> u = coords[:, 0:1] ** 2 * coords[:, 1:2] ** 3 * coords[:, 2:3] ** 4 >>> grad_calculator = GradientCalculator() >>> input_dict = {"coordinates": coords, "u": u} >>> grad_u_autodiff = grad_calculator.compute_gradients( ... input_dict, ... method_name="autodiff", ... invar="u" ... ) >>> sorted(grad_u_autodiff.keys()) ['u__x', 'u__y', 'u__z'] >>> grad_u_autodiff = grad_calculator.compute_gradients( ... input_dict, ... method_name="autodiff", ... order=2, ... return_mixed_derivs=True, ... invar="u" ... ) >>> sorted(grad_u_autodiff.keys()) ['u__x__x', 'u__x__y', 'u__x__z', 'u__y__x', 'u__y__y', 'u__y__z', 'u__z__x', 'u__z__y', 'u__z__z']

compute_gradients(input_dict, method_name=None, invar=None, **kwargs)[source]

Compute the gradients

get_gradient_module(method_name, invar, **kwargs)[source]

Return the gradient module

class modulus.sym.eq.spatial_grads.spatial_grads.GradientsAutoDiff(invar: str, dim: int = 3, order: int = 1, return_mixed_derivs: bool = False)[source]

Bases: Module

Compute spatial derivatives using Automatic differentiation.

Parameters
  • invar (str) – Variable whose gradients are computed.

  • dim (int, optional) – Dimensionality of the input (1D, 2D, or 3D), by default 3

  • order (int, optional) – Order of the derivatives, by default 1 which returns the first order derivatives (e.g. u__x, u__y, u__z). Max order 2 is supported.

  • return_mixed_derivs (bool, optional) – Whether to include mixed derivatives such as u__x__y, by default False

forward(input_dict)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class modulus.sym.eq.spatial_grads.spatial_grads.GradientsFiniteDifference(invar: str, dx: Union[float, int, List[float]], dim: int = 3, order: int = 1, return_mixed_derivs: bool = False)[source]

Bases: Module

Compute spatial derivatives using Finite Differentiation. The gradients are computed using 2nd order finite difference stencils using convolution operation.

Parameters
  • invar (str) – Variable whose gradients are computed.

  • dx (Union[Union[float, int]]) – dx for the finite difference calculation.

  • dim (int, optional) – Dimensionality of the input (1D, 2D, or 3D), by default 3

  • order (int, optional) – Order of the derivatives, by default 1 which returns the first order derivatives (e.g. u__x, u__y, u__z). Max order 2 is supported.

  • return_mixed_derivs (bool, optional) – Whether to include mixed derivatives such as u__x__y, by default False

forward(input_dict)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class modulus.sym.eq.spatial_grads.spatial_grads.GradientsLeastSquares(invar: str, dim: int = 3, order: int = 1, return_mixed_derivs: bool = False)[source]

Bases: Module

Compute spatial derivatives using Least Squares technique modified to compute gradients on nodes.

Reference: https://scientific-sims.com/cfdlab/Dimitri_Mavriplis/HOME/assets/papers/aiaa20033986.pdf

Parameters
  • invar (str) – Variable whose gradients are computed.

  • dim (int, optional) – Dimensionality of the input (2D, or 3D), by default 3

  • order (int, optional) – Order of the derivatives, by default 1 which returns the first order derivatives (e.g. u__x, u__y, u__z). Max order 2 is supported.

  • return_mixed_derivs (bool, optional) – Whether to include mixed derivatives such as u__x__y, by default False

forward(input_dict)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class modulus.sym.eq.spatial_grads.spatial_grads.GradientsMeshlessFiniteDifference(invar: str, dx: Union[float, int], dim: int = 3, order: int = 1, return_mixed_derivs: bool = False)[source]

Bases: Module

Compute spatial derivatives using Meshless Finite Differentiation. The gradients are computed using 2nd order finite difference stencils. For more details, refer: https://docs.nvidia.com/deeplearning/modulus/modulus-sym/user_guide/features/performance.html#meshless-finite-derivatives

Parameters
  • invar (str) – Variable whose gradients are computed.

  • dx (Union[Union[float, int]]) – dx for the finite difference calculation.

  • dim (int, optional) – Dimensionality of the input (1D, 2D, or 3D), by default 3

  • order (int, optional) – Order of the derivatives, by default 1 which returns the first order derivatives (e.g. u__x, u__y, u__z). Max order 2 is supported.

  • return_mixed_derivs (bool, optional) – Whether to include mixed derivatives such as u__x__y, by default False

forward(input_dict)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class modulus.sym.eq.spatial_grads.spatial_grads.GradientsSpectral(invar: str, ell: Union[float, int], dim: int = 3, order: int = 1, return_mixed_derivs: bool = False)[source]

Bases: Module

Compute spatial derivatives using Spectral Differentiation using FFTs.

Parameters
  • invar (str) – Variable whose gradients are computed.

  • ell (Union[Union[float, int]]) – bounds for the domain.

  • dim (int, optional) – Dimensionality of the input (1D, 2D, or 3D), by default 3

  • order (int, optional) – Order of the derivatives, by default 1 which returns the first order derivatives (e.g. u__x, u__y, u__z). Max order 2 is supported.

  • return_mixed_derivs (bool, optional) – Whether to include mixed derivatives such as u__x__y, by default False

forward(input_dict)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

modulus.sym.eq.spatial_grads.spatial_grads.compute_connectivity_tensor(nodes, edges)[source]

Compute connectivity tensor for given nodes and edges.

Parameters
  • nodes – Node ids of the nodes in the mesh in [N, 1] format. Where N is the number of nodes.

  • edges – Edges of the mesh in [M, 2] format. Where M is the number of edges.

Returns

Tensor containing neighbor nodes for each node. Each node is made to have same neighbors by finding the max neighbors and adding (0, 0) for points with fewer neighbors.

Return type

torch.Tensor

modulus.sym.eq.spatial_grads.spatial_grads.compute_stencil2d(coords, model, dx, return_mixed_derivs=False)[source]

Compute 2D stencil required for MFD

modulus.sym.eq.spatial_grads.spatial_grads.compute_stencil3d(coords, model, dx, return_mixed_derivs=False)[source]

Compute 3D stencil required for MFD

Previous Modulus Sym Geometry
Next Modulus Sym Models
© Copyright 2023, NVIDIA Modulus Team. Last updated on Sep 24, 2024.