Skip to content

Commit

Permalink
Updating all docstrings, preparing the documentation for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe N. Schuch committed Aug 19, 2020
1 parent 2ac1fb6 commit 897ad6a
Show file tree
Hide file tree
Showing 8 changed files with 2,392 additions and 1,021 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.1] - 2020-08-17
## [0.1.3] - 2020-08-17
### Added
- Unittest for observations and validations at [parameters.py](./xcompact3d_toolbox/parameters.py), by [@fschuch](https://github.com/fschuch).

Expand All @@ -24,5 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support to *Sandbox Flow Configuration* (see [fschuch/Xcompact3d](https://github.com/fschuch/Xcompact3d/)), by [@fschuch](https://github.com/fschuch).
- Ahmed body as benchmark geometry, mirror and plotting tools, by [@momba98](https://github.com/momba98).

[Unreleased]: https://github.com/fschuch/xcompact3d_toolbox/compare/v0.0.0...HEAD
[Unreleased]: https://github.com/fschuch/xcompact3d_toolbox/compare/v0.1.3...HEAD
[0.1.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.0...v0.1.3
[0.0.0]: https://github.com/fschuch/xcompact3d_toolbox/releases/tag/v0.0.0
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Xcompact3d Toolbox

![Build Status](https://github.com/fschuch/xcompact3d_toolbox/workflows/Python%20package/badge.svg)
[![PyPI version](https://badge.fury.io/py/xcompact3d-toolbox.svg)](https://badge.fury.io/py/xcompact3d-toolbox)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

It is a Python package designed to handle the pre and postprocessing of
the high-order Navier-Stokes solver Xcompact3d. It aims to help users and
code developers with a set of tools and automated processes.

**Xcompact3d Toolbox** is still in pre-release, be aware that new features are
going to be added to it and the current features may change with no further notice.

The physical and computational parameters are built on top of [traitlets](https://traitlets.readthedocs.io/en/stable/index.html),
a framework that lets Python classes have attributes with type checking, dynamically calculated default values, and ‘on change’ callbacks.
In addition to [ipywidgets](https://ipywidgets.readthedocs.io/en/latest/) for an user friendly interface.
Expand Down
112 changes: 55 additions & 57 deletions tests/unit/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import traitlets
from xcompact3d_toolbox.parameters import Parameters

class test_parameters(unittest.TestCase):

class test_parameters(unittest.TestCase):
def test_io(self):

prm1 = Parameters()
Expand All @@ -13,71 +13,68 @@ def test_io(self):
prm2.read()

for name in prm1.trait_names():
if name == 'i3d':
if name == "_i3d":
continue
with self.subTest(name=name):
self.assertEqual(
getattr(prm1, name),
getattr(prm2, name)
)
self.assertEqual(getattr(prm1, name), getattr(prm2, name))

def test_observe_resolution_and_BC(self):

prm = Parameters()

for dim in 'x y z'.split():
for dim in "x y z".split():
with self.subTest(dim=dim):
# Default Values
self.assertEqual(getattr(prm, f'n{dim}'), 17)
self.assertEqual(getattr(prm, f'd{dim}'), 0.0625)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
self.assertEqual(getattr(prm, f"n{dim}"), 17)
self.assertEqual(getattr(prm, f"d{dim}"), 0.0625)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# New nx should change just dx
setattr(prm, f'n{dim}', 201)
self.assertEqual(getattr(prm, f'n{dim}'), 201)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"n{dim}", 201)
self.assertEqual(getattr(prm, f"n{dim}"), 201)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# New xlx should change just dx
setattr(prm, f'{dim}l{dim}', 5.0)
self.assertEqual(getattr(prm, f'n{dim}'), 201)
self.assertEqual(getattr(prm, f'd{dim}'), 0.025)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 5.0)
setattr(prm, f"{dim}l{dim}", 5.0)
self.assertEqual(getattr(prm, f"n{dim}"), 201)
self.assertEqual(getattr(prm, f"d{dim}"), 0.025)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 5.0)
# New dx should change just xlx
setattr(prm, f'd{dim}', 0.005)
self.assertEqual(getattr(prm, f'n{dim}'), 201)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"d{dim}", 0.005)
self.assertEqual(getattr(prm, f"n{dim}"), 201)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# One side to periodic
setattr(prm, f'ncl{dim}1', 0)
self.assertEqual(getattr(prm, f'ncl{dim}1'), 0)
self.assertEqual(getattr(prm, f'ncl{dim}n'), 0)
self.assertEqual(getattr(prm, f'ncl{dim}'), True)
self.assertEqual(getattr(prm, f'n{dim}'), 200)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"ncl{dim}1", 0)
self.assertEqual(getattr(prm, f"ncl{dim}1"), 0)
self.assertEqual(getattr(prm, f"ncl{dim}n"), 0)
self.assertEqual(getattr(prm, f"_ncl{dim}"), True)
self.assertEqual(getattr(prm, f"n{dim}"), 200)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# End back
setattr(prm, f'ncl{dim}1', 1)
self.assertEqual(getattr(prm, f'ncl{dim}1'), 1)
self.assertEqual(getattr(prm, f'ncl{dim}n'), 1)
self.assertEqual(getattr(prm, f'ncl{dim}'), False)
self.assertEqual(getattr(prm, f'n{dim}'), 201)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"ncl{dim}1", 1)
self.assertEqual(getattr(prm, f"ncl{dim}1"), 1)
self.assertEqual(getattr(prm, f"ncl{dim}n"), 1)
self.assertEqual(getattr(prm, f"_ncl{dim}"), False)
self.assertEqual(getattr(prm, f"n{dim}"), 201)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# Other side to periodic
setattr(prm, f'ncl{dim}n', 0)
self.assertEqual(getattr(prm, f'ncl{dim}1'), 0)
self.assertEqual(getattr(prm, f'ncl{dim}n'), 0)
self.assertEqual(getattr(prm, f'ncl{dim}'), True)
self.assertEqual(getattr(prm, f'n{dim}'), 200)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"ncl{dim}n", 0)
self.assertEqual(getattr(prm, f"ncl{dim}1"), 0)
self.assertEqual(getattr(prm, f"ncl{dim}n"), 0)
self.assertEqual(getattr(prm, f"_ncl{dim}"), True)
self.assertEqual(getattr(prm, f"n{dim}"), 200)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)
# End back
setattr(prm, f'ncl{dim}n', 2)
self.assertEqual(getattr(prm, f'ncl{dim}1'), 2)
self.assertEqual(getattr(prm, f'ncl{dim}n'), 2)
self.assertEqual(getattr(prm, f'ncl{dim}'), False)
self.assertEqual(getattr(prm, f'n{dim}'), 201)
self.assertEqual(getattr(prm, f'd{dim}'), 0.005)
self.assertEqual(getattr(prm, f'{dim}l{dim}'), 1.0)
setattr(prm, f"ncl{dim}n", 2)
self.assertEqual(getattr(prm, f"ncl{dim}1"), 2)
self.assertEqual(getattr(prm, f"ncl{dim}n"), 2)
self.assertEqual(getattr(prm, f"_ncl{dim}"), False)
self.assertEqual(getattr(prm, f"n{dim}"), 201)
self.assertEqual(getattr(prm, f"d{dim}"), 0.005)
self.assertEqual(getattr(prm, f"{dim}l{dim}"), 1.0)

def test_validate_mesh(self):

Expand All @@ -86,27 +83,28 @@ def test_validate_mesh(self):
prm = Parameters()

# To small grid
for dim in 'x y z'.split():
for dim in "x y z".split():
with self.subTest(dim=dim):
with self.assertRaises(traitlets.TraitError):
setattr(prm, f'n{dim}', 8)
setattr(prm, f"n{dim}", 8)

# Invalid grid not periodic
for dim in 'x y z'.split():
for dim in "x y z".split():
for i in range(possible_mesh[-1]):
with self.subTest(dim=dim, i=i):
if i not in possible_mesh:
with self.assertRaises(traitlets.TraitError):
setattr(prm, f'n{dim}', i)
setattr(prm, f"n{dim}", i)

# Invalid grid Periodic
for dim in 'x y z'.split():
setattr(prm, f'ncl{dim}1', 0)
for dim in "x y z".split():
setattr(prm, f"ncl{dim}1", 0)
for i in range(possible_mesh_p[-1]):
with self.subTest(dim=dim, i=i):
if i not in possible_mesh_p:
with self.assertRaises(traitlets.TraitError):
setattr(prm, f'n{dim}', i)
setattr(prm, f"n{dim}", i)


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 897ad6a

Please sign in to comment.