partially fix documentation (#80)
This commit is contained in:
12
docs/source/_rst/abstractproblem.rst
Normal file
12
docs/source/_rst/abstractproblem.rst
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
AbstractProblem
|
||||||
|
===========
|
||||||
|
.. currentmodule:: pina.problem.abstract_problem
|
||||||
|
|
||||||
|
.. automodule:: pina.problem.abstract_problem
|
||||||
|
|
||||||
|
.. autoclass:: AbstractProblem
|
||||||
|
:members:
|
||||||
|
:private-members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
:noindex:
|
||||||
@@ -10,5 +10,9 @@ Code Documentation
|
|||||||
FeedForward <fnn.rst>
|
FeedForward <fnn.rst>
|
||||||
DeepONet <deeponet.rst>
|
DeepONet <deeponet.rst>
|
||||||
ContinuousConv <convolution.rst>
|
ContinuousConv <convolution.rst>
|
||||||
|
MultiFeedForward <multifeedforward.rst>
|
||||||
|
AbstractProblem <abstractproblem.rst>
|
||||||
|
SpatialProblem <spatialproblem.rst>
|
||||||
|
TimeDependentProblem <timedepproblem.rst>
|
||||||
Operators <operators.rst>
|
Operators <operators.rst>
|
||||||
Plotter <plotter.rst>
|
Plotter <plotter.rst>
|
||||||
12
docs/source/_rst/multifeedforward.rst
Normal file
12
docs/source/_rst/multifeedforward.rst
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
MultiFeedForward
|
||||||
|
===========
|
||||||
|
.. currentmodule:: pina.model.multi_feed_forward
|
||||||
|
|
||||||
|
.. automodule:: pina.model.multi_feed_forward
|
||||||
|
|
||||||
|
.. autoclass:: MultiFeedForward
|
||||||
|
:members:
|
||||||
|
:private-members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
:noindex:
|
||||||
12
docs/source/_rst/parametricproblem.rst
Normal file
12
docs/source/_rst/parametricproblem.rst
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
ParametricProblem
|
||||||
|
===========
|
||||||
|
.. currentmodule:: pina.problem.parametric_problem
|
||||||
|
|
||||||
|
.. automodule:: pina.problem.parametric_problem
|
||||||
|
|
||||||
|
.. autoclass:: ParametricProblem
|
||||||
|
:members:
|
||||||
|
:private-members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
:noindex:
|
||||||
12
docs/source/_rst/spatialproblem.rst
Normal file
12
docs/source/_rst/spatialproblem.rst
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
SpatialProblem
|
||||||
|
===========
|
||||||
|
.. currentmodule:: pina.problem.spatial_problem
|
||||||
|
|
||||||
|
.. automodule:: pina.problem.spatial_problem
|
||||||
|
|
||||||
|
.. autoclass:: SpatialProblem
|
||||||
|
:members:
|
||||||
|
:private-members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
:noindex:
|
||||||
12
docs/source/_rst/timedepproblem.rst
Normal file
12
docs/source/_rst/timedepproblem.rst
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
TimeDependentProblem
|
||||||
|
===========
|
||||||
|
.. currentmodule:: pina.problem.timedep_problem
|
||||||
|
|
||||||
|
.. automodule:: pina.problem.timedep_problem
|
||||||
|
|
||||||
|
.. autoclass:: TimeDependentProblem
|
||||||
|
:members:
|
||||||
|
:private-members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
:noindex:
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
|
"""Module for Multi FeedForward model"""
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from .feed_forward import FeedForward
|
from .feed_forward import FeedForward
|
||||||
|
|
||||||
|
|
||||||
class MultiFeedForward(torch.nn.Module):
|
class MultiFeedForward(torch.nn.Module):
|
||||||
|
"""
|
||||||
|
:param dict dff_dict: dictionary of FeedForward networks.
|
||||||
|
"""
|
||||||
def __init__(self, dff_dict):
|
def __init__(self, dff_dict):
|
||||||
'''
|
"""
|
||||||
'''
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
if not isinstance(dff_dict, dict):
|
if not isinstance(dff_dict, dict):
|
||||||
|
|||||||
@@ -1,10 +1,26 @@
|
|||||||
|
""" Module for AbstractProblem class """
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
class AbstractProblem(metaclass=ABCMeta):
|
class AbstractProblem(metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
The abstract `AbstractProblem` class. All the class defining a PINA Problem
|
||||||
|
should be inheritied from this class.
|
||||||
|
|
||||||
|
In the definition of a PINA problem, the fundamental elements are:
|
||||||
|
the output variables, the condition(s), and the domain(s) where the
|
||||||
|
conditions are applied.
|
||||||
|
"""
|
||||||
@property
|
@property
|
||||||
def input_variables(self):
|
def input_variables(self):
|
||||||
|
"""
|
||||||
|
The input variables of the AbstractProblem, whose type depends on the
|
||||||
|
type of domain (spatial, temporal, and parameter).
|
||||||
|
|
||||||
|
:return: the input variables of self
|
||||||
|
:rtype: list
|
||||||
|
|
||||||
|
"""
|
||||||
variables = []
|
variables = []
|
||||||
|
|
||||||
if hasattr(self, 'spatial_variables'):
|
if hasattr(self, 'spatial_variables'):
|
||||||
@@ -20,7 +36,13 @@ class AbstractProblem(metaclass=ABCMeta):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def domain(self):
|
def domain(self):
|
||||||
|
"""
|
||||||
|
The domain(s) where the conditions of the AbstractProblem are valid.
|
||||||
|
|
||||||
|
:return: the domain(s) of self
|
||||||
|
:rtype: list (if more than one domain are defined),
|
||||||
|
`Span` domain (of only one domain is defined)
|
||||||
|
"""
|
||||||
domains = [
|
domains = [
|
||||||
getattr(self, f'{t}_domain')
|
getattr(self, f'{t}_domain')
|
||||||
for t in ['spatial', 'temporal', 'parameter']
|
for t in ['spatial', 'temporal', 'parameter']
|
||||||
@@ -46,9 +68,15 @@ class AbstractProblem(metaclass=ABCMeta):
|
|||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def output_variables(self):
|
def output_variables(self):
|
||||||
|
"""
|
||||||
|
The output variables of the problem.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def conditions(self):
|
def conditions(self):
|
||||||
|
"""
|
||||||
|
The conditions of the problem.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,9 +1,45 @@
|
|||||||
|
"""Module for the ParametricProblem class"""
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from .abstract_problem import AbstractProblem
|
from .abstract_problem import AbstractProblem
|
||||||
|
|
||||||
|
|
||||||
class ParametricProblem(AbstractProblem):
|
class ParametricProblem(AbstractProblem):
|
||||||
|
"""
|
||||||
|
The class for the definition of parametric problems, i.e., problems
|
||||||
|
with parameters among the input variables.
|
||||||
|
|
||||||
|
Here's an example of a spatial parametric ODE problem, i.e., a spatial
|
||||||
|
ODE problem with an additional parameter `alpha` as coefficient of the
|
||||||
|
derivative term.
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
>>> from pina.problem import SpatialProblem, ParametricProblem
|
||||||
|
>>> from pina.operators import grad
|
||||||
|
>>> from pina import Condition, Span
|
||||||
|
>>> import torch
|
||||||
|
|
||||||
|
>>> class ParametricODE(SpatialProblem, ParametricProblem):
|
||||||
|
|
||||||
|
>>> output_variables = ['u']
|
||||||
|
>>> spatial_domain = Span({'x': [0, 1]})
|
||||||
|
>>> parameter_domain = Span({'alpha': {1, 10}})
|
||||||
|
|
||||||
|
>>> def ode_equation(input_, output_):
|
||||||
|
>>> u_x = grad(output_, input_, components=['u'], d=['x'])
|
||||||
|
>>> u = output_.extract(['u'])
|
||||||
|
>>> alpha = input_.extract(['alpha'])
|
||||||
|
>>> return alpha * u_x - u
|
||||||
|
|
||||||
|
>>> def initial_condition(input_, output_):
|
||||||
|
>>> value = 1.0
|
||||||
|
>>> u = output_.extract(['u'])
|
||||||
|
>>> return u - value
|
||||||
|
|
||||||
|
>>> conditions = {
|
||||||
|
>>> 'x0': Condition(Span({'x': 0, 'alpha':[1, 10]}), initial_condition),
|
||||||
|
>>> 'D': Condition(Span({'x': [0, 1], 'alpha':[1, 10]}), ode_equation)}
|
||||||
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def parameter_domain(self):
|
def parameter_domain(self):
|
||||||
|
|||||||
@@ -1,14 +1,53 @@
|
|||||||
|
"""Module for the SpatialProblem class"""
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from .abstract_problem import AbstractProblem
|
from .abstract_problem import AbstractProblem
|
||||||
|
|
||||||
|
|
||||||
class SpatialProblem(AbstractProblem):
|
class SpatialProblem(AbstractProblem):
|
||||||
|
"""
|
||||||
|
The class for the definition of spatial problems, i.e., for problems
|
||||||
|
with spatial input variables.
|
||||||
|
|
||||||
|
Here's an example of a spatial 1-dimensional ODE problem.
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
>>> from pina.problem import SpatialProblem
|
||||||
|
>>> from pina.operators import grad
|
||||||
|
>>> from pina import Condition, Span
|
||||||
|
>>> import torch
|
||||||
|
|
||||||
|
>>> class SimpleODE(SpatialProblem):
|
||||||
|
|
||||||
|
>>> output_variables = ['u']
|
||||||
|
>>> spatial_domain = Span({'x': [0, 1]})
|
||||||
|
|
||||||
|
>>> def ode_equation(input_, output_):
|
||||||
|
>>> u_x = grad(output_, input_, components=['u'], d=['x'])
|
||||||
|
>>> u = output_.extract(['u'])
|
||||||
|
>>> return u_x - u
|
||||||
|
|
||||||
|
>>> def initial_condition(input_, output_):
|
||||||
|
>>> value = 1.0
|
||||||
|
>>> u = output_.extract(['u'])
|
||||||
|
>>> return u - value
|
||||||
|
|
||||||
|
>>> conditions = {
|
||||||
|
>>> 'x0': Condition(Span({'x': 0.}), initial_condition),
|
||||||
|
>>> 'D': Condition(Span({'x': [0, 1]}), ode_equation)}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def spatial_domain(self):
|
def spatial_domain(self):
|
||||||
|
"""
|
||||||
|
The spatial domain of the problem.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def spatial_variables(self):
|
def spatial_variables(self):
|
||||||
|
"""
|
||||||
|
The spatial input variables of the problem.
|
||||||
|
"""
|
||||||
return self.spatial_domain.variables
|
return self.spatial_domain.variables
|
||||||
|
|||||||
@@ -1,14 +1,62 @@
|
|||||||
|
"""Module for the TimeDependentProblem class"""
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from .abstract_problem import AbstractProblem
|
from .abstract_problem import AbstractProblem
|
||||||
|
|
||||||
|
|
||||||
class TimeDependentProblem(AbstractProblem):
|
class TimeDependentProblem(AbstractProblem):
|
||||||
|
"""
|
||||||
|
The class for the definition of time-dependent problems, i.e., for problems
|
||||||
|
depending on time.
|
||||||
|
|
||||||
|
Here's an example of a 1D wave problem.
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
>>> from pina.problem import SpatialProblem, TimeDependentProblem
|
||||||
|
>>> from pina.operators import grad, nabla
|
||||||
|
>>> from pina import Condition, Span
|
||||||
|
>>> import torch
|
||||||
|
|
||||||
|
>>> class Wave(TimeDependentSpatialProblem):
|
||||||
|
|
||||||
|
>>> output_variables = ['u']
|
||||||
|
>>> spatial_domain = Span({'x': [0, 3]})
|
||||||
|
>>> temporal_domain = Span({'t': [0, 1]})
|
||||||
|
|
||||||
|
>>> def wave_equation(input_, output_):
|
||||||
|
>>> u_t = grad(output_, input_, components=['u'], d=['t'])
|
||||||
|
>>> u_tt = grad(u_t, input_, components=['dudt'], d=['t'])
|
||||||
|
>>> nabla_u = nabla(output_, input_, components=['u'], d=['x'])
|
||||||
|
>>> return nabla_u - u_tt
|
||||||
|
|
||||||
|
>>> def nil_dirichlet(input_, output_):
|
||||||
|
>>> value = 0.0
|
||||||
|
>>> return output_.extract(['u']) - value
|
||||||
|
|
||||||
|
>>> def initial_condition(input_, output_):
|
||||||
|
>>> u_expected = (-3*torch.sin(2*torch.pi*input_.extract(['x']))
|
||||||
|
>>> + 5*torch.sin(8/3*torch.pi*input_.extract(['x'])))
|
||||||
|
>>> u = output_.extract(['u'])
|
||||||
|
>>> return u - u_expected
|
||||||
|
|
||||||
|
>>> conditions = {
|
||||||
|
>>> 't0': Condition(Span({'x': [0, 3], 't':0}), initial_condition),
|
||||||
|
>>> 'gamma1': Condition(Span({'x':0, 't':[0, 1]}), nil_dirichlet),
|
||||||
|
>>> 'gamma2': Condition(Span({'x':3, 't':[0, 1]}), nil_dirichlet),
|
||||||
|
>>> 'D': Condition(Span({'x': [0, 3], 't':[0, 1]}), wave_equation)}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def temporal_domain(self):
|
def temporal_domain(self):
|
||||||
|
"""
|
||||||
|
The temporal domain of the problem.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temporal_variable(self):
|
def temporal_variable(self):
|
||||||
|
"""
|
||||||
|
The time variable of the problem.
|
||||||
|
"""
|
||||||
return self.temporal_domain.variables
|
return self.temporal_domain.variables
|
||||||
|
|||||||
Reference in New Issue
Block a user