| Name | triangle-cubature JSON |
| Version |
1.1.0
JSON |
| download |
| home_page | None |
| Summary | cubature rules on triangles |
| upload_time | 2024-08-26 12:53:23 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.9.18 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Triangle Cubature Rules
This repo serves as a collection of well-tested triangle cubature rules,
i.e. numerical integration schemes for integrals of the form
$$
\int_K f(x, y) ~\mathrm{d}x ~\mathrm{d}y,
$$
where $K \subset \mathbb{R}^2$ is a triangle.
All cubature rules are based on [1].
## Usage
Using the cubature schemes is fairly simple.
```python
from triangle_cubature.cubature_rule import CubatureRuleEnum
from triangle_cubature.integrate import integrate_on_mesh
from triangle_cubature.integrate import integrate_on_triangle
import numpy as np
# specifying the mesh
coordinates = np.array([
[0., 0.],
[1., 0.],
[1., 1.],
[0., 1.]
])
elements = np.array([
[0, 1, 2],
[0, 2, 3]
], dtype=int)
# defining the function to be integrated
# NOTE the function must be able to handle coordinates as array
# of shape (N, 2)
def constant(coordinates: np.ndarray):
"""returns 1"""
return np.ones(coordinates.shape[0])
# integrating over the whole mesh
integral_on_mesh = integrate_on_mesh(
f=constant,
coordinates=coordinates,
elements=elements,
cubature_rule=CubatureRuleEnum.MIDPOINT)
# integrating over a single triangle, e.g.
# in this case, the "first" element of the mesh
integral_on_triangle = integrate_on_triangle(
f=constant,
triangle=coordinates[elements[0], :],
cubature_rule=CubatureRuleEnum.MIDPOINT)
print(f'Integral value on mesh: {integral_on_mesh}')
print(f'Integral value on triangle: {integral_on_triangle}')
```
## Available Rules
The available cubature rules can be found in `triangle_cubature/cubature_rule.py`.
- `CubatureRuleEnum.MIDPOINT`
- degree of exactness: 1
- Ref: [1]
- `CubatureRuleEnum.LAUFFER_LINEAR`
- degree of exactness: 1
- Ref: [1]
- `CubatureRuleEnum.SMPLX1`
- degree of exactness: 2
- Ref: [1]
## (Unit) Tests
To run auto tests, you do
```sh
python -m unittest discover tests/auto/
```
> The unit tests use `sympy` to verify the degree of exactness of the
> implemented cubature rules, i.e. creates random polynomials $p_d$ of the
> expected degree of exactness $d$ and compares the exact result of
> $\int_K p_d(x, y) ~\mathrm{d}x ~\mathrm{d}y$ to the value obtained
> with the cubature rule at hand.
## References
- [1] Stenger, Frank.
'Approximate Calculation of Multiple Integrals (A. H. Stroud)'.
SIAM Review 15, no. 1 (January 1973): 234-35.
https://doi.org/10.1137/1015023. p. 306-315
Raw data
{
"_id": null,
"home_page": null,
"name": "triangle-cubature",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9.18",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Raphael Leu <raphaelleu95@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/97/56/528ef421a0af9b6e27b36bdc3fba5c86e3632405a3e7eb766d6c554f7872/triangle_cubature-1.1.0.tar.gz",
"platform": null,
"description": "# Triangle Cubature Rules\nThis repo serves as a collection of well-tested triangle cubature rules,\ni.e. numerical integration schemes for integrals of the form\n\n$$\n\\int_K f(x, y) ~\\mathrm{d}x ~\\mathrm{d}y,\n$$\n\nwhere $K \\subset \\mathbb{R}^2$ is a triangle.\nAll cubature rules are based on [1].\n\n## Usage\nUsing the cubature schemes is fairly simple.\n\n```python\nfrom triangle_cubature.cubature_rule import CubatureRuleEnum\nfrom triangle_cubature.integrate import integrate_on_mesh\nfrom triangle_cubature.integrate import integrate_on_triangle\nimport numpy as np\n\n# specifying the mesh\ncoordinates = np.array([\n [0., 0.],\n [1., 0.],\n [1., 1.],\n [0., 1.]\n])\n\nelements = np.array([\n [0, 1, 2],\n [0, 2, 3]\n], dtype=int)\n\n\n# defining the function to be integrated\n# NOTE the function must be able to handle coordinates as array\n# of shape (N, 2)\ndef constant(coordinates: np.ndarray):\n \"\"\"returns 1\"\"\"\n return np.ones(coordinates.shape[0])\n\n\n# integrating over the whole mesh\nintegral_on_mesh = integrate_on_mesh(\n f=constant,\n coordinates=coordinates,\n elements=elements,\n cubature_rule=CubatureRuleEnum.MIDPOINT)\n\n# integrating over a single triangle, e.g.\n# in this case, the \"first\" element of the mesh\nintegral_on_triangle = integrate_on_triangle(\n f=constant,\n triangle=coordinates[elements[0], :],\n cubature_rule=CubatureRuleEnum.MIDPOINT)\n\nprint(f'Integral value on mesh: {integral_on_mesh}')\nprint(f'Integral value on triangle: {integral_on_triangle}')\n\n```\n\n## Available Rules\nThe available cubature rules can be found in `triangle_cubature/cubature_rule.py`.\n\n- `CubatureRuleEnum.MIDPOINT`\n - degree of exactness: 1\n - Ref: [1]\n- `CubatureRuleEnum.LAUFFER_LINEAR`\n - degree of exactness: 1\n - Ref: [1]\n- `CubatureRuleEnum.SMPLX1`\n - degree of exactness: 2\n - Ref: [1]\n\n## (Unit) Tests\nTo run auto tests, you do\n```sh\npython -m unittest discover tests/auto/\n```\n\n> The unit tests use `sympy` to verify the degree of exactness of the\n> implemented cubature rules, i.e. creates random polynomials $p_d$ of the \n> expected degree of exactness $d$ and compares the exact result of\n> $\\int_K p_d(x, y) ~\\mathrm{d}x ~\\mathrm{d}y$ to the value obtained\n> with the cubature rule at hand.\n\n## References\n- [1] Stenger, Frank.\n 'Approximate Calculation of Multiple Integrals (A. H. Stroud)'.\n SIAM Review 15, no. 1 (January 1973): 234-35.\n https://doi.org/10.1137/1015023. p. 306-315\n",
"bugtrack_url": null,
"license": null,
"summary": "cubature rules on triangles",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/leuraph/triangle_cubature",
"Issues": "https://github.com/leuraph/triangle_cubature/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "266fb60d49cca2b8d490d8feb1eb619a2f74d2e8db90c49c23ba1bc260bf53d8",
"md5": "59011e049003b1a0f95474cf049bcd38",
"sha256": "3312866404f24bcdd392b02d95a33ddb67648dbb1620f4c184f74a36ec47875e"
},
"downloads": -1,
"filename": "triangle_cubature-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "59011e049003b1a0f95474cf049bcd38",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.18",
"size": 6593,
"upload_time": "2024-08-26T12:53:22",
"upload_time_iso_8601": "2024-08-26T12:53:22.092100Z",
"url": "https://files.pythonhosted.org/packages/26/6f/b60d49cca2b8d490d8feb1eb619a2f74d2e8db90c49c23ba1bc260bf53d8/triangle_cubature-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9756528ef421a0af9b6e27b36bdc3fba5c86e3632405a3e7eb766d6c554f7872",
"md5": "d0046fc72dec39c66b6049b449265745",
"sha256": "7dec2ae1915723693e36a2afdd4b547473b164d246d6616296f953764efa27cc"
},
"downloads": -1,
"filename": "triangle_cubature-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "d0046fc72dec39c66b6049b449265745",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.18",
"size": 5337,
"upload_time": "2024-08-26T12:53:23",
"upload_time_iso_8601": "2024-08-26T12:53:23.504577Z",
"url": "https://files.pythonhosted.org/packages/97/56/528ef421a0af9b6e27b36bdc3fba5c86e3632405a3e7eb766d6c554f7872/triangle_cubature-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-26 12:53:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "leuraph",
"github_project": "triangle_cubature",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "triangle-cubature"
}