Enhancing Equations

- add init file
- add docs
- fixing bug System of equation, replace torch.stack with torch.hstack
- add tests
This commit is contained in:
Dario Coscia
2023-06-28 11:49:14 +02:00
committed by Nicola Demo
parent 09f04008b5
commit b9ddea827b
6 changed files with 234 additions and 11 deletions

View File

@@ -6,6 +6,18 @@ from ..operators import grad, div, nabla
class FixedValue(Equation):
def __init__(self, value, components=None):
"""
Fixed Value Equation class. This class can be
used to enforced a fixed value for a specific
condition, e.g. Dirichlet Boundary conditions.
:param float value: Value to be mantained fixed.
:param list(str) components: the name of the output
variables to calculate the gradient for. It should
be a subset of the output labels. If ``None``,
all the output variables are considered.
Default is ``None``.
"""
def equation(input_, output_):
if components is None:
return output_ - value
@@ -16,6 +28,22 @@ class FixedValue(Equation):
class FixedGradient(Equation):
def __init__(self, value, components=None, d=None):
"""
Fixed Gradient Equation class. This class can be
used to enforced a fixed gradient for a specific
condition.
:param float value: Value to be mantained fixed.
:param list(str) components: the name of the output
variables to calculate the gradient for. It should
be a subset of the output labels. If ``None``,
all the output variables are considered.
Default is ``None``.
:param list(str) d: the name of the input variables on
which the gradient is calculated. d should be a subset
of the input labels. If ``None``, all the input variables
are considered. Default is ``None``.
"""
def equation(input_, output_):
return grad(output_, input_, components=components, d=d) - value
super().__init__(equation)
@@ -24,6 +52,22 @@ class FixedGradient(Equation):
class FixedFlux(Equation):
def __init__(self, value, components=None, d=None):
"""
Fixed Flux Equation class. This class can be
used to enforced a fixed flux for a specific
condition.
:param float value: Value to be mantained fixed.
:param list(str) components: the name of the output
variables to calculate the flux for. It should
be a subset of the output labels. If ``None``,
all the output variables are considered.
Default is ``None``.
:param list(str) d: the name of the input variables on
which the flux is calculated. d should be a subset
of the input labels. If ``None``, all the input variables
are considered. Default is ``None``.
"""
def equation(input_, output_):
return div(output_, input_, components=components, d=d) - value
super().__init__(equation)
@@ -32,6 +76,21 @@ class FixedFlux(Equation):
class Laplace(Equation):
def __init__(self, components=None, d=None):
"""
Laplace Equation class. This class can be
used to enforced a Laplace equation for a specific
condition (force term set to zero).
:param list(str) components: the name of the output
variables to calculate the flux for. It should
be a subset of the output labels. If ``None``,
all the output variables are considered.
Default is ``None``.
:param list(str) d: the name of the input variables on
which the flux is calculated. d should be a subset
of the input labels. If ``None``, all the input variables
are considered. Default is ``None``.
"""
def equation(input_, output_):
return nabla(output_, input_, components=components, d=d)
super().__init__(equation)