layercake-model 1.0.7b0__tar.gz → 1.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/PKG-INFO +5 -5
  2. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/README.md +3 -3
  3. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/__init__.py +1 -1
  4. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/base.py +4 -4
  5. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/bakery/cake.py +8 -2
  6. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/basis/spherical_harmonics.py +1 -1
  7. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake_model.egg-info/PKG-INFO +5 -5
  8. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake_model.egg-info/SOURCES.txt +1 -0
  9. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/pyproject.toml +3 -3
  10. layercake_model-1.0.8/test/test_RP1982_qgs_numerical_simpson.py +336 -0
  11. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/LICENSE.txt +0 -0
  12. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/equation.py +0 -0
  13. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/symbolic/__init__.py +0 -0
  14. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/symbolic/expressions.py +0 -0
  15. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/symbolic/operators.py +0 -0
  16. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/__init__.py +0 -0
  17. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/constant.py +0 -0
  18. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/gradient.py +0 -0
  19. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/jacobian.py +0 -0
  20. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/linear.py +0 -0
  21. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/operations.py +0 -0
  22. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/terms/operators.py +0 -0
  23. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/arithmetic/utils.py +0 -0
  24. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/bakery/__init__.py +0 -0
  25. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/bakery/layers.py +0 -0
  26. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/basis/__init__.py +0 -0
  27. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/basis/base.py +0 -0
  28. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/basis/centered_planar_fourier.py +0 -0
  29. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/basis/planar_fourier.py +0 -0
  30. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/formatters/__init__.py +0 -0
  31. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/formatters/base.py +0 -0
  32. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/formatters/fortran.py +0 -0
  33. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/formatters/julia.py +0 -0
  34. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/formatters/python.py +0 -0
  35. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/inner_products/__init__.py +0 -0
  36. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/inner_products/definition.py +0 -0
  37. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/__init__.py +0 -0
  38. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/commutativity.py +0 -0
  39. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/integration.py +0 -0
  40. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/matrix.py +0 -0
  41. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/parallel.py +0 -0
  42. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/symbolic_tensor.py +0 -0
  43. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/utils/tensor.py +0 -0
  44. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/__init__.py +0 -0
  45. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/coordinate.py +0 -0
  46. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/field.py +0 -0
  47. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/parameter.py +0 -0
  48. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/systems.py +0 -0
  49. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/utils.py +0 -0
  50. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake/variables/variable.py +0 -0
  51. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake_model.egg-info/dependency_links.txt +0 -0
  52. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake_model.egg-info/requires.txt +0 -0
  53. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/layercake_model.egg-info/top_level.txt +0 -0
  54. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/setup.cfg +0 -0
  55. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/test/test_RP1982_qgs_numerical.py +0 -0
  56. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/test/test_RP1982_qgs_symbolic.py +0 -0
  57. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/test/test_base.py +0 -0
  58. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/test/test_maooam_qgs_numerical.py +0 -0
  59. {layercake_model-1.0.7b0 → layercake_model-1.0.8}/test/test_maooam_qgs_symbolic.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: layercake_model
3
- Version: 1.0.7b0
3
+ Version: 1.0.8
4
4
  Summary: A framework to design systems of partial differential equations (PDEs), and convert them to ordinary differential equations (ODEs) via Galerkin-type expansions.
5
5
  Author-email: Jonathan Demaeyer <jodemaey@meteo.be>, Oisín Hamilton <ush.hamilton@gmail.com>
6
6
  License-Expression: BSD-3-Clause
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Programming Language :: Python :: 3.14
17
17
  Classifier: Operating System :: OS Independent
18
- Classifier: Development Status :: 4 - Beta
18
+ Classifier: Development Status :: 5 - Production/Stable
19
19
  Classifier: Intended Audience :: Science/Research
20
20
  Classifier: Topic :: Scientific/Engineering
21
21
  Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
@@ -33,7 +33,7 @@ Dynamic: license-file
33
33
 
34
34
  # LayerCake
35
35
 
36
- > “Welcome to the layer cake son.”
36
+ > “Welcome to the layer cake...”
37
37
  >
38
38
  > -- *Michael Gambon - Layer Cake (2004)*
39
39
 
@@ -51,7 +51,7 @@ and convert them to ordinary differential equations (ODEs) via Galerkin-type exp
51
51
  LayerCake allows you to construct systems of PDEs, and to specify coordinate systems and basis functions to build
52
52
  the corresponding ODE systems.
53
53
  To build these systems, LayerCake relies heavily on the [Sympy](https://www.sympy.org/) symbolic computation framework.
54
- The output of this procedure is either a [Numbaified](https://numba.pydata.org/) Python callable,
54
+ The output of this procedure is either a [Numba-accelerated](https://numba.pydata.org/) Python callable,
55
55
  or a list of symbolic ODE tendencies that can be integrated in any of the supported languages
56
56
  (Fortran, Julia and Python for the moment). These two kinds of output allow for the study of the computed models with
57
57
  the modern tools available in all these languages.
@@ -137,7 +137,7 @@ Check the YAML file [environment.yml](https://raw.githubusercontent.com/Climdyn/
137
137
 
138
138
  ## Contributing
139
139
 
140
- LayerCake is in beta development phase, bug reports and tests of the features are welcome.
140
+ Bug reports and tests of the features of LayerCake are welcome.
141
141
  Please simply raise an issue on [Github](https://github.com/Climdyn/LayerCake/issues).
142
142
 
143
143
  If you want to contribute actively to the development, please contact the main authors.
@@ -1,6 +1,6 @@
1
1
  # LayerCake
2
2
 
3
- > “Welcome to the layer cake son.”
3
+ > “Welcome to the layer cake...”
4
4
  >
5
5
  > -- *Michael Gambon - Layer Cake (2004)*
6
6
 
@@ -18,7 +18,7 @@ and convert them to ordinary differential equations (ODEs) via Galerkin-type exp
18
18
  LayerCake allows you to construct systems of PDEs, and to specify coordinate systems and basis functions to build
19
19
  the corresponding ODE systems.
20
20
  To build these systems, LayerCake relies heavily on the [Sympy](https://www.sympy.org/) symbolic computation framework.
21
- The output of this procedure is either a [Numbaified](https://numba.pydata.org/) Python callable,
21
+ The output of this procedure is either a [Numba-accelerated](https://numba.pydata.org/) Python callable,
22
22
  or a list of symbolic ODE tendencies that can be integrated in any of the supported languages
23
23
  (Fortran, Julia and Python for the moment). These two kinds of output allow for the study of the computed models with
24
24
  the modern tools available in all these languages.
@@ -104,7 +104,7 @@ Check the YAML file [environment.yml](https://raw.githubusercontent.com/Climdyn/
104
104
 
105
105
  ## Contributing
106
106
 
107
- LayerCake is in beta development phase, bug reports and tests of the features are welcome.
107
+ Bug reports and tests of the features of LayerCake are welcome.
108
108
  Please simply raise an issue on [Github](https://github.com/Climdyn/LayerCake/issues).
109
109
 
110
110
  If you want to contribute actively to the development, please contact the main authors.
@@ -13,4 +13,4 @@ __all__ = ['Parameter', 'ParameterField', 'FunctionField', 'Field', 'Expression'
13
13
  'OperatorTerm', 'ProductOfTerms', 'AdditionOfTerms', 'LinearTerm', 'ConstantTerm', 'Equation', 'Laplacian', 'D',
14
14
  'Layer', 'Cake']
15
15
 
16
- __version__ = '1.0.7b0'
16
+ __version__ = '1.0.8'
@@ -355,7 +355,7 @@ class SingleArithmeticTerm(ArithmeticTerms):
355
355
  Holds the symbolic representation of the term and his decomposition on given function basis.
356
356
 
357
357
  More precisely, models a term in the partial differential equation as a linear functional :math:`\\pm \\, T[\\psi](u_1, u_2)`,
358
- where :math:`\\psi` is the field solution of the equation, and the :math:`u_1, u_2` are the coordinates of the model.
358
+ where :math:`\\psi` is a given field, and the :math:`u_1, u_2` are the coordinates of the model.
359
359
  Upon decomposition on function basis, it can be represented as a tensor
360
360
 
361
361
  .. math:: \\mathcal{T}_{i_1, i_2} = \\left\\langle \\phi_{i_1} , \\pm \\, T[\\eta_{i_2}] \\right\\rangle
@@ -367,7 +367,7 @@ class SingleArithmeticTerm(ArithmeticTerms):
367
367
  Parameters
368
368
  ----------
369
369
  field: ~field.Field or ~field.ParameterField
370
- A field appearing in the partial differential equation.
370
+ The field on which the term is acting.
371
371
  inner_product_definition: InnerProductDefinition, optional
372
372
  Object defining the integral representation of the inner product that is used to compute the term representation on a given function basis.
373
373
  If not provided, it will use the inner product definition found in the `field` object.
@@ -384,7 +384,7 @@ class SingleArithmeticTerm(ArithmeticTerms):
384
384
  Attributes
385
385
  ----------
386
386
  field: ~field.Field or ~field.ParameterField
387
- The field appearing in the partial differential equation.
387
+ The field on which the term is acting.
388
388
  name: str
389
389
  Name of the term. Must be defined in subclasses.
390
390
  sign: int
@@ -561,7 +561,7 @@ class OperationOnTerms(ArithmeticTerms):
561
561
  .. math:: \\mathcal{T}_{j, k_{1,1}, \\ldots, k_{1,j_1}, \\ldots, k_{l,1}, \\ldots, k_{l,{j_l}}} = \\left\\langle \\phi_{j} , \\pm \\, \\bigwedge_{i=1}^l T_i\\left[\\left(\\eta^i_1\\right)_{k_{i,1}}, \\ldots, \\left(\\eta^i_{j_i}\\right)_{k_{i,j_i}}\\right] \\right\\rangle
562
562
 
563
563
  where the :math:`\\phi_j`'s are basis functions provided by the user, and the :math:`\\left(\\eta^i_j\\right)_k`'s are basis functions on which
564
- the fields :math:`\\psi^i_j`'s are decomposed. :math:`\\langle \\, , \\rangle` is the inner provided by the user.
564
+ the fields :math:`\\psi^i_j`'s are decomposed. :math:`\\langle \\, , \\rangle` is the inner product provided by the user.
565
565
  The rank :math:`r` of this kind of term (and its tensor rank) is thus :math:`1+\\sum_{i=1}^l j_i`.
566
566
 
567
567
  Parameters
@@ -356,11 +356,11 @@ class Cake(object):
356
356
  .. math:: \\dot{\\boldsymbol{x}} = \\boldsymbol{f}(\\boldsymbol{x})
357
357
 
358
358
  It returns also the linearized tendencies
359
- :math:`\\boldsymbol{\\mathrm{J}} \\equiv \\boldsymbol{\\mathrm{D}f} = \\frac{\\partial \\boldsymbol{f}}{\\partial \\boldsymbol{x}}`
359
+ :math:`\\boldsymbol{\\mathrm{D}f} = \\frac{\\partial \\boldsymbol{f}}{\\partial \\boldsymbol{x}}`
360
360
  (Jacobian matrix).
361
361
 
362
362
  Depending on whether the tendencies tensor is symbolic or numerical, it will return either
363
- `Numbafied <https://numba.pydata.org/>`_ callable for the functions :math:`\\boldsymbol{f}` and :math:`J`,
363
+ `Numba-accelerated <https://numba.pydata.org/>`_ callable for the functions :math:`\\boldsymbol{f}` and :math:`\\boldsymbol{\\mathrm{D}f}`,
364
364
  or list of strings defining each tendency in a computing language selected by the user.
365
365
 
366
366
  Parameters
@@ -387,6 +387,12 @@ class Cake(object):
387
387
  If the tendencies tensor is numerical, the numba-jitted linearized tendencies function.
388
388
  If the tendencies tensor is symbolic, or if `force_symbolic` is `True`, the list of linearized tendencies string in the selected target language,
389
389
  along with the list of parameters appearing in them.
390
+
391
+ Notes
392
+ -----
393
+ The signature of the returned functions :math:`\\boldsymbol{f}` and :math:`\\boldsymbol{\\mathrm{D}f}` is :math:`\\boldsymbol{f}(t, \\boldsymbol{x})`
394
+ and :math:`\\boldsymbol{\\mathrm{D}f}(t, \\boldsymbol{x})` where :math:`t` is an unused parameter representing the time, and :math:`\\boldsymbol{x}` is
395
+ the state vector of the system, an array of dimension (:attr:`ndim`,).
390
396
  """
391
397
  if self.tensor is not None:
392
398
 
@@ -34,7 +34,7 @@ class SphericalHarmonicsBasis(SymbolicBasis):
34
34
  Type of truncation to use.
35
35
  Default to `"T"` for a triangular truncature.
36
36
  exclude_constant_term: bool, optional
37
- Whether the spherical harmonics corresponding to a constant should be discarded.
37
+ Whether the spherical harmonics corresponding to a constant field should be discarded.
38
38
  Default to `True`.
39
39
  use_num_factorial: bool, optional
40
40
  Use a numerical factorial instead of a symbolic one. Might speed up computations in certain cases.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: layercake_model
3
- Version: 1.0.7b0
3
+ Version: 1.0.8
4
4
  Summary: A framework to design systems of partial differential equations (PDEs), and convert them to ordinary differential equations (ODEs) via Galerkin-type expansions.
5
5
  Author-email: Jonathan Demaeyer <jodemaey@meteo.be>, Oisín Hamilton <ush.hamilton@gmail.com>
6
6
  License-Expression: BSD-3-Clause
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Programming Language :: Python :: 3.14
17
17
  Classifier: Operating System :: OS Independent
18
- Classifier: Development Status :: 4 - Beta
18
+ Classifier: Development Status :: 5 - Production/Stable
19
19
  Classifier: Intended Audience :: Science/Research
20
20
  Classifier: Topic :: Scientific/Engineering
21
21
  Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
@@ -33,7 +33,7 @@ Dynamic: license-file
33
33
 
34
34
  # LayerCake
35
35
 
36
- > “Welcome to the layer cake son.”
36
+ > “Welcome to the layer cake...”
37
37
  >
38
38
  > -- *Michael Gambon - Layer Cake (2004)*
39
39
 
@@ -51,7 +51,7 @@ and convert them to ordinary differential equations (ODEs) via Galerkin-type exp
51
51
  LayerCake allows you to construct systems of PDEs, and to specify coordinate systems and basis functions to build
52
52
  the corresponding ODE systems.
53
53
  To build these systems, LayerCake relies heavily on the [Sympy](https://www.sympy.org/) symbolic computation framework.
54
- The output of this procedure is either a [Numbaified](https://numba.pydata.org/) Python callable,
54
+ The output of this procedure is either a [Numba-accelerated](https://numba.pydata.org/) Python callable,
55
55
  or a list of symbolic ODE tendencies that can be integrated in any of the supported languages
56
56
  (Fortran, Julia and Python for the moment). These two kinds of output allow for the study of the computed models with
57
57
  the modern tools available in all these languages.
@@ -137,7 +137,7 @@ Check the YAML file [environment.yml](https://raw.githubusercontent.com/Climdyn/
137
137
 
138
138
  ## Contributing
139
139
 
140
- LayerCake is in beta development phase, bug reports and tests of the features are welcome.
140
+ Bug reports and tests of the features of LayerCake are welcome.
141
141
  Please simply raise an issue on [Github](https://github.com/Climdyn/LayerCake/issues).
142
142
 
143
143
  If you want to contribute actively to the development, please contact the main authors.
@@ -50,6 +50,7 @@ layercake_model.egg-info/dependency_links.txt
50
50
  layercake_model.egg-info/requires.txt
51
51
  layercake_model.egg-info/top_level.txt
52
52
  test/test_RP1982_qgs_numerical.py
53
+ test/test_RP1982_qgs_numerical_simpson.py
53
54
  test/test_RP1982_qgs_symbolic.py
54
55
  test/test_base.py
55
56
  test/test_maooam_qgs_numerical.py
@@ -7,7 +7,7 @@ requires = ["setuptools", "wheel"]
7
7
  [project]
8
8
  requires-python = ">=3.10"
9
9
  name = "layercake_model"
10
- version = "1.0.7-beta"
10
+ version = "1.0.8"
11
11
  description = "A framework to design systems of partial differential equations (PDEs), and convert them to ordinary differential equations (ODEs) via Galerkin-type expansions. "
12
12
  readme = "README.md"
13
13
  authors = [
@@ -25,8 +25,8 @@ classifiers = [
25
25
  "Programming Language :: Python :: 3.13",
26
26
  "Programming Language :: Python :: 3.14",
27
27
  "Operating System :: OS Independent",
28
- "Development Status :: 4 - Beta",
29
- # "Development Status :: 5 - Production/Stable",
28
+ # "Development Status :: 4 - Beta",
29
+ "Development Status :: 5 - Production/Stable",
30
30
  "Intended Audience :: Science/Research",
31
31
  "Topic :: Scientific/Engineering",
32
32
  "Topic :: Scientific/Engineering :: Atmospheric Science",
@@ -0,0 +1,336 @@
1
+
2
+ import sys
3
+ import os
4
+
5
+ import unittest
6
+ import numpy as np
7
+ from sympy import symbols, Symbol
8
+
9
+ from qgs.params.params import QgParams
10
+ from qgs.inner_products import analytic
11
+ from qgs.tensors.qgtensor import QgsTensor
12
+
13
+
14
+ path = os.path.abspath('./')
15
+ base = os.path.basename(path)
16
+ if base == 'test':
17
+ sys.path.extend([os.path.abspath('../')])
18
+ else:
19
+ sys.path.extend([path])
20
+
21
+ from layercake.basis.planar_fourier import contiguous_channel_basis
22
+ from layercake.variables.parameter import Parameter
23
+ from layercake.inner_products.definition import StandardSymbolicInnerProductDefinition
24
+ from layercake.variables.field import Field, ParameterField
25
+ from layercake.arithmetic.terms.jacobian import vorticity_advection, Jacobian
26
+ from layercake.arithmetic.terms.operators import OperatorTerm
27
+ from layercake.arithmetic.terms.operations import AdditionOfTerms
28
+ from layercake.arithmetic.terms.linear import LinearTerm
29
+ from layercake.arithmetic.equation import Equation
30
+ from layercake.arithmetic.symbolic.operators import Laplacian, D
31
+ from layercake.bakery.layers import Layer
32
+ from layercake.bakery.cake import Cake
33
+
34
+ from test.test_base import TestQgsBase
35
+
36
+ import layercake.utils.integration
37
+ layercake.utils.integration.numerical_method = 'dblquad'
38
+ # layercake.utils.integration.numerical_method = 'simpson'
39
+ # layercake.utils.integration.integration_kwargs = {'n': 5}
40
+
41
+
42
+ real_eps = 20 * np.finfo(np.float64).eps
43
+
44
+
45
+ class State:
46
+
47
+ qgs_tensor = None
48
+ layercake_cake = None
49
+
50
+
51
+ class TestRP1982QgsNumerical(TestQgsBase):
52
+
53
+ def test_against_qgs(self):
54
+ self.__class__.state = State()
55
+ self.check_lists(self.qgs_outputs, self.layercake_outputs)
56
+
57
+ def test_jacobian_against_qgs(self):
58
+ self.check_lists(self.qgs_jacobian_outputs, self.layercake_jacobian_outputs)
59
+
60
+ def qgs_outputs(self, output_func=None):
61
+
62
+ if output_func is None:
63
+ self.qgs_values.clear()
64
+ tfunc = self.save_qgs
65
+ else:
66
+ tfunc = output_func
67
+
68
+ # Computing qgs version of the RP1982 tensor:
69
+ # Setting RP1982 default parameters:
70
+ # Model parameters instantiation with some non-default specs
71
+ params = QgParams({'phi0_npi': np.deg2rad(50.) / np.pi, 'hd': 0.045})
72
+ # Mode truncation at the wavenumber 2 in both x and y spatial coordinate
73
+ params.set_atmospheric_channel_fourier_modes(2, 2)
74
+ # Setting the orography depth and the meridional temperature gradient
75
+ params.ground_params.set_orography(0.2, 1)
76
+ params.atemperature_params.set_thetas(0.1, 0)
77
+
78
+ aip = analytic.AtmosphericAnalyticInnerProducts(params)
79
+
80
+ self.state.qgs_tensor = QgsTensor(params=params, atmospheric_inner_products=aip)
81
+
82
+ for coo, val in zip(self.state.qgs_tensor.tensor.coords.T, self.state.qgs_tensor.tensor.data):
83
+ _string_format(tfunc, 'tensor', coo, val)
84
+
85
+ def qgs_jacobian_outputs(self, output_func=None):
86
+
87
+ if output_func is None:
88
+ self.qgs_values.clear()
89
+ tfunc = self.save_qgs
90
+ else:
91
+ tfunc = output_func
92
+
93
+ for coo, val in zip(self.state.qgs_tensor.jacobian_tensor.coords.T, self.state.qgs_tensor.jacobian_tensor.data):
94
+ _string_format(tfunc, 'tensor', coo, val)
95
+
96
+ def layercake_outputs(self, output_func=None):
97
+
98
+ if output_func is None:
99
+ self.layercake_values.clear()
100
+ tfunc = self.save_layercake
101
+ else:
102
+ tfunc = output_func
103
+
104
+ # Computing qgs version of the RP1982 tensor:
105
+ # Setting RP1982 default parameters:
106
+ ##########################
107
+
108
+ # Characteristic length scale (L_y / pi)
109
+ L_symbol = Symbol('L')
110
+ L = Parameter(1591549.4309189534, symbol=L_symbol, units='[m]')
111
+
112
+ # Domain aspect ratio
113
+ n_symbol = Symbol('n')
114
+ n = Parameter(1.3, symbol=n_symbol)
115
+
116
+ # Coriolis parameter at the middle of the domain
117
+ f0_symbol = Symbol('f_0')
118
+ f0 = Parameter(1.032e-4, symbol=f0_symbol, units='[s^-1]')
119
+
120
+ # Pressure difference between the two atmospheric layers
121
+ deltap_symbol = Symbol('Δp')
122
+ deltap = Parameter(5.e4, symbol=deltap_symbol, units='[Pa]')
123
+
124
+ # Static stability of the atmosphere
125
+ sigma_symbol = Symbol('σ')
126
+ sigma = Parameter(2.1581898457499433e-06, symbol=sigma_symbol, units='[m^2][s^-2][Pa^-2]')
127
+
128
+ # Meridional gradient of the Coriolis parameter at phi_0
129
+ beta_symbol = Symbol(u'β')
130
+ beta = Parameter(1.3594204385792041e-11, symbol=beta_symbol, units='[m^-1][s^-1]')
131
+
132
+ # atmosphere bottom friction coefficient
133
+ kd_symbol = Symbol('k_d')
134
+ kd = Parameter(1.032e-05, symbol=kd_symbol, units='[s^-1]')
135
+
136
+ # Atmosphere internal friction coefficient
137
+ kdp_symbol = Symbol("k_d'")
138
+ kdp = Parameter(1.032e-06, symbol=kdp_symbol, units='[s^-1]')
139
+
140
+ # Newtonian cooling parameters
141
+ hd_symbol = symbols('hd')
142
+ hd = Parameter(4.644e-06, symbol=hd_symbol, units='[s^-1]')
143
+
144
+ # Defining the domain
145
+ ######################
146
+
147
+ parameters = [n]
148
+ atmospheric_basis = contiguous_channel_basis(2, 2, parameters)
149
+ s = StandardSymbolicInnerProductDefinition(coordinate_system=atmospheric_basis.coordinate_system)
150
+ # coordinates
151
+ x = atmospheric_basis.coordinate_system.coordinates_symbol_as_list[0]
152
+ y = atmospheric_basis.coordinate_system.coordinates_symbol_as_list[1]
153
+
154
+ # Derived (non-dimensional) parameters
155
+ #######################################
156
+
157
+ sigma_nondim = Parameter((sigma * deltap ** 2) / (L ** 2 * f0 ** 2), symbol=sigma_symbol, units='')
158
+ beta_nondim = Parameter(beta * L / f0, symbol=beta_symbol, units='')
159
+ a_symbol = symbols('a')
160
+ a = Parameter(2 / sigma_nondim, symbol=a_symbol)
161
+ kd_deriv = Parameter(0.5 * kd / f0, symbol=kd_symbol)
162
+ kdp_deriv = Parameter(2 * kdp / f0, symbol=kdp_symbol)
163
+ hd_deriv = Parameter(a * hd / f0, symbol=hd_symbol, units='')
164
+
165
+ # Orography (non-dimensional)
166
+
167
+ hh = np.zeros(len(atmospheric_basis))
168
+ hh[1] = 0.2
169
+ h = ParameterField('h', u'h', hh, atmospheric_basis, s)
170
+
171
+ # Equilibrium temperature
172
+ rr = np.zeros(len(atmospheric_basis))
173
+ rr[0] = 0.1
174
+ Tf = ParameterField('T', u'T', rr, atmospheric_basis, s)
175
+
176
+ # Defining the fields
177
+ #######################
178
+ p = u'ψ'
179
+ psi = Field("psi", p, atmospheric_basis, s, units="[m^2][s^-2]", latex=r'\psi')
180
+ tt = u'θ'
181
+ theta = Field("theta", tt, atmospheric_basis, s, units="[m^2][s^-2]", latex=r'\theta')
182
+
183
+ # --------------------------------
184
+ #
185
+ # Barotropic field equation
186
+ #
187
+ # --------------------------------
188
+
189
+ # Defining the equation and LHS
190
+ # Laplacian
191
+ vorticity = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system)
192
+ barotropic_equation = Equation(psi, lhs_terms=vorticity)
193
+
194
+ # Defining the advection term
195
+ advection_term1 = vorticity_advection(psi, psi, atmospheric_basis.coordinate_system, sign=-1)
196
+ advection_term2 = vorticity_advection(theta, theta, atmospheric_basis.coordinate_system, sign=-1)
197
+
198
+ barotropic_equation.add_rhs_terms(advection_term1)
199
+ barotropic_equation.add_rhs_terms(advection_term2)
200
+
201
+ # adding an orographic term
202
+ g = 0.5 # must be divided by 2
203
+ gamma = symbols(u'γ')
204
+ gammap = Parameter(g, symbol=gamma)
205
+
206
+ orographic_term1 = Jacobian(psi, h, atmospheric_basis.coordinate_system, sign=-1, prefactors=(gammap, gammap))
207
+ orographic_term2 = Jacobian(theta, h, atmospheric_basis.coordinate_system, sign=1, prefactors=(gammap, gammap))
208
+
209
+ barotropic_equation.add_rhs_terms(orographic_term1)
210
+ barotropic_equation.add_rhs_terms(orographic_term2)
211
+
212
+ # adding the beta term
213
+ beta_term = OperatorTerm(psi, D, x, prefactor=beta_nondim, sign=-1)
214
+
215
+ barotropic_equation.add_rhs_term(beta_term)
216
+
217
+ # adding the friction with the ground
218
+ friction = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system, prefactor=kd_deriv, sign=-1)
219
+ barotropic_equation.add_rhs_term(friction)
220
+
221
+ ofriction = OperatorTerm(theta, Laplacian, atmospheric_basis.coordinate_system, prefactor=kd_deriv)
222
+ barotropic_equation.add_rhs_term(ofriction)
223
+
224
+ # --------------------------------
225
+ #
226
+ # Baroclinic field equation
227
+ #
228
+ # --------------------------------
229
+
230
+ # Defining the equation and LHS
231
+ # Laplacian
232
+ vorticity = OperatorTerm(theta, Laplacian, atmospheric_basis.coordinate_system)
233
+
234
+ lin_lhs = LinearTerm(theta, prefactor=a, sign=-1)
235
+ lhs = AdditionOfTerms(lin_lhs, vorticity)
236
+ baroclinic_equation = Equation(theta, lhs_terms=lhs)
237
+
238
+ # Defining the advection terms
239
+ advection_term1 = vorticity_advection(psi, theta, atmospheric_basis.coordinate_system, sign=-1)
240
+ advection_term2 = vorticity_advection(theta, psi, atmospheric_basis.coordinate_system, sign=-1)
241
+
242
+ baroclinic_equation.add_rhs_terms(advection_term1)
243
+ baroclinic_equation.add_rhs_terms(advection_term2)
244
+
245
+ # adding an orographic term
246
+ orographic_term1 = Jacobian(psi, h, atmospheric_basis.coordinate_system, sign=1, prefactors=(gammap, gammap))
247
+ orographic_term2 = Jacobian(theta, h, atmospheric_basis.coordinate_system, sign=-1, prefactors=(gammap, gammap))
248
+
249
+ baroclinic_equation.add_rhs_terms(orographic_term1)
250
+ baroclinic_equation.add_rhs_terms(orographic_term2)
251
+
252
+ # adding the beta term
253
+ beta_term = OperatorTerm(theta, D, x, prefactor=beta_nondim, sign=-1)
254
+ baroclinic_equation.add_rhs_term(beta_term)
255
+
256
+ # adding the friction with the ground
257
+ friction = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system, prefactor=kd_deriv, sign=1)
258
+ baroclinic_equation.add_rhs_term(friction)
259
+
260
+ ofriction = OperatorTerm(theta, Laplacian, atmospheric_basis.coordinate_system, prefactor=kd_deriv, sign=-1)
261
+ baroclinic_equation.add_rhs_term(ofriction)
262
+
263
+ # adding the atmospheric friction
264
+ ground_friction = OperatorTerm(theta, Laplacian, atmospheric_basis.coordinate_system, prefactor=kdp_deriv, sign=-1)
265
+ baroclinic_equation.add_rhs_term(ground_friction)
266
+
267
+ # adding jacobian from thermal wind relation
268
+ thermal = Jacobian(psi, theta, atmospheric_basis.coordinate_system, prefactors=(a, a))
269
+ baroclinic_equation.add_rhs_terms(thermal)
270
+
271
+ # adding Newtonian cooling
272
+ equilibrium_temperature = LinearTerm(Tf, prefactor=hd_deriv, sign=-1)
273
+ newt = LinearTerm(theta, prefactor=hd_deriv, sign=1)
274
+
275
+ baroclinic_equation.add_rhs_terms((newt, equilibrium_temperature))
276
+
277
+ # --------------------------------
278
+ #
279
+ # Constructing the layer
280
+ #
281
+ # --------------------------------
282
+
283
+ layer = Layer()
284
+ layer.add_equation(barotropic_equation)
285
+ layer.add_equation(baroclinic_equation)
286
+
287
+ # --------------------------------
288
+ #
289
+ # Constructing the cake
290
+ #
291
+ # --------------------------------
292
+
293
+ cake = Cake()
294
+ cake.add_layer(layer)
295
+
296
+ # --------------------------------
297
+ #
298
+ # Computing the tensor
299
+ #
300
+ # --------------------------------
301
+
302
+ cake.compute_tensor(True, True, compute_inner_products_kwargs={'timeout': True}
303
+ )
304
+ cake.print_tensor_to_file('gauss_test.ref')
305
+
306
+ self.state.layercake_cake = cake
307
+ tensor = cake.tensor
308
+
309
+ for coo, val in zip(tensor.coords.T, tensor.data):
310
+ _string_format(tfunc, 'tensor', coo, val)
311
+
312
+ def layercake_jacobian_outputs(self, output_func=None):
313
+
314
+ if output_func is None:
315
+ self.layercake_values.clear()
316
+ tfunc = self.save_layercake
317
+ else:
318
+ tfunc = output_func
319
+
320
+ tensor = self.state.layercake_cake.jacobian_tensor
321
+
322
+ for coo, val in zip(tensor.coords.T, tensor.data):
323
+ _string_format(tfunc, 'tensor', coo, val)
324
+
325
+
326
+ def _string_format(func, symbol, indices, value):
327
+ if abs(value) >= real_eps:
328
+ s = symbol
329
+ for i in indices:
330
+ s += "[" + str(i) + "]"
331
+ s += " = % .5E" % value
332
+ func(s)
333
+
334
+
335
+ if __name__ == "__main__":
336
+ unittest.main()