|
| 1 | +"""Formulation of the burgers problem.""" |
| 2 | + |
| 3 | +import torch |
| 4 | +from pina._src.problem.time_dependent_problem import TimeDependentProblem |
| 5 | +from pina._src.domain.cartesian_domain import CartesianDomain |
| 6 | +from pina._src.problem.spatial_problem import SpatialProblem |
| 7 | +from pina._src.condition.condition import Condition |
| 8 | +from pina._src.core.utils import check_consistency |
| 9 | +from pina._src.equation.equation import Equation |
| 10 | +from pina._src.equation.zoo.fixed_value import FixedValue |
| 11 | +from pina._src.equation.zoo.burgers_equation import BurgersEquation |
| 12 | + |
| 13 | + |
| 14 | +def initial_condition(input_, output_): |
| 15 | + """ |
| 16 | + Definition of the initial condition of the burgers problem. |
| 17 | +
|
| 18 | + :param LabelTensor input_: The input data of the problem. |
| 19 | + :param LabelTensor output_: The output data of the problem. |
| 20 | + :return: The residual of the initial condition. |
| 21 | + :rtype: LabelTensor |
| 22 | + """ |
| 23 | + return output_ + torch.sin(torch.pi * input_["x"]) |
| 24 | + |
| 25 | + |
| 26 | +class BurgersProblem(TimeDependentProblem, SpatialProblem): |
| 27 | + r""" |
| 28 | + Implementation of the burgers problem in the spatial interval |
| 29 | + :math:`[-1, 1]` and temporal interval :math:`[0, 1]`. |
| 30 | +
|
| 31 | + .. seealso:: |
| 32 | +
|
| 33 | + **Original reference**: Raissi M., Perdikaris P., Karniadakis G. E. |
| 34 | + (2017). |
| 35 | + *Physics Informed Deep Learning (Part I): Data-driven Solutions of |
| 36 | + Nonlinear Partial Differential Equations*. |
| 37 | + DOI: `10.48550 <https://doi.org/10.48550/arXiv.1711.10561>`_. |
| 38 | +
|
| 39 | + :Example: |
| 40 | +
|
| 41 | + >>> problem = BurgersProblem() |
| 42 | + """ |
| 43 | + |
| 44 | + output_variables = ["u"] |
| 45 | + spatial_domain = CartesianDomain({"x": [-1, 1]}) |
| 46 | + temporal_domain = CartesianDomain({"t": [0, 1]}) |
| 47 | + |
| 48 | + domains = { |
| 49 | + "D": spatial_domain.update(temporal_domain), |
| 50 | + "t0": spatial_domain.update(CartesianDomain({"t": 0})), |
| 51 | + "boundary": spatial_domain.partial().update(temporal_domain), |
| 52 | + } |
| 53 | + |
| 54 | + conditions = { |
| 55 | + "boundary": Condition(domain="boundary", equation=FixedValue(0.0)), |
| 56 | + "t0": Condition(domain="t0", equation=Equation(initial_condition)), |
| 57 | + } |
| 58 | + |
| 59 | + def __init__(self, nu=0): |
| 60 | + """ |
| 61 | + Initialization of the :class:`BurgersProblem` class. |
| 62 | +
|
| 63 | + :param nu: The viscosity coefficient. |
| 64 | + :type nu: float | int |
| 65 | + :raises ValueError: If ``nu`` is not a float or an int. |
| 66 | + :raises ValueError: If ``nu`` is negative. |
| 67 | + """ |
| 68 | + super().__init__() |
| 69 | + |
| 70 | + # Check consistency |
| 71 | + check_consistency(nu, (float, int)) |
| 72 | + if nu < 0: |
| 73 | + raise ValueError( |
| 74 | + "The viscosity ``nu`` must be a non-negative float or int." |
| 75 | + ) |
| 76 | + |
| 77 | + self.conditions["D"] = Condition( |
| 78 | + domain="D", equation=BurgersEquation(nu) |
| 79 | + ) |
0 commit comments