Skip to content

Commit

Permalink
Merge pull request #258 from snek5000/simplify-example-solvers
Browse files Browse the repository at this point in the history
Simplify the implementation of the example solvers
  • Loading branch information
paugier committed Dec 20, 2022
2 parents 3731a70 + 2609f1c commit bebbe99
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Need more reasons to use snek5000?
[Snakemake](https://snakemake.readthedocs.io/en/stable/) functions and [how
to write Jinja
templates](https://jinja.palletsprojects.com/en/2.11.x/templates/) (which are
not so hard, btw)
[not so hard](https://snek5000.readthedocs.io/en/latest/how-to/templates.html), btw)

</details>

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/snek5000-canonical/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ snek5000.solvers =
where=src

[options.package_data]
snek5000_canonical = templates/*.j2, *.usr.f, *.par.cfg, Snakefile, etc/*.yml
snek5000_canonical = *.usr.f, *.par.cfg, Snakefile, etc/*.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OutputCanonical(OutputBase):

@classmethod
def _set_info_solver_classes(cls, classes):
"""Set the the classes for info_solver.classes.Output
"""Set the classes for info_solver.classes.Output
NOTE: This method is optional, and only required if custom classes are
to be set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ class SimulCanonical(SimulNek):

InfoSolver = InfoSolverCanonical

@classmethod
def _complete_params_with_default(cls, params):
"""Add missing default parameters."""
params = super()._complete_params_with_default(params)
# Extend with new default parameters here, for example:

# params.nek.velocity._set_attrib("advection", True)
return params

@classmethod
def create_default_params(cls):
"""Set default values of parameters as given in reference
Expand All @@ -50,6 +41,10 @@ def create_default_params(cls):
params = super().create_default_params()
# Re-define default values for parameters here, if necessary
# following ``canonical.par``, ``canonical.box`` and ``SIZE`` files

# Extend with new default parameters here, for example:
# params.nek.velocity._set_attrib("advection", True)

return params


Expand Down
2 changes: 1 addition & 1 deletion docs/examples/snek5000-tgv/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ snek5000.solvers =
where=src

[options.package_data]
snek5000_tgv = templates/*.j2, *.usr.f, *.par.cfg, Snakefile, etc/*.yml
snek5000_tgv = *.usr.f, *.par.cfg, Snakefile, etc/*.yml
2 changes: 1 addition & 1 deletion docs/examples/snek5000-tgv/src/snek5000_tgv/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def makefile_usr_sources(self):

@classmethod
def _set_info_solver_classes(cls, classes):
"""Set the the classes for info_solver.classes.Output"""
"""Set the classes for info_solver.classes.Output"""
super()._set_info_solver_classes(classes)

classes._set_child(
Expand Down
6 changes: 2 additions & 4 deletions docs/examples/snek5000-tgv/src/snek5000_tgv/solver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from math import pi
from pathlib import Path

from snek5000.info import InfoSolverMake
from snek5000.params import complete_params_from_par_file
Expand Down Expand Up @@ -46,11 +47,8 @@ def create_default_params(cls):
params.oper._record_nek_user_params({"Lx": 1})

# Read defaults for `params.nek` from `tgv.par.cfg` (original code)
info_solver = cls.info_solver # cls.InfoSolver()
output_cls = info_solver.import_classes()["Output"]
root = output_cls.get_path_solver_package()
complete_params_from_par_file(
params, root / f"{info_solver.short_name}.par.cfg"
params, Path(__file__).parent / f"{cls.info_solver.short_name}.par.cfg"
)

# Boundary conditions
Expand Down
7 changes: 2 additions & 5 deletions docs/how-to/read-write-par-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Snek5000 is capable of parsing existing `*.par` files. This is shown in the

```{code-block} python
---
emphasize-lines: 15-17
emphasize-lines: 12-14
---
from snek5000.solvers.base import SimulNek
from snek5000.params import complete_params_from_par_file
Expand All @@ -18,11 +18,8 @@ class SimulTGV(SimulNek):
...
# Read defaults for `params.nek` from `tgv.par.cfg` (original code)
info_solver = cls.info_solver # cls.InfoSolver()
output_cls = info_solver.import_classes()["Output"]
root = output_cls.get_path_solver_package()
complete_params_from_par_file(
params, root / f"{info_solver.short_name}.par.cfg"
params, Path(__file__).parent / f"{cls.info_solver.short_name}.par.cfg"
)
```

Expand Down
4 changes: 1 addition & 3 deletions docs/tuto_packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ repository) like this::
      ├── __init__.py
      ├── canonical.usr.f
      ├── output.py
      ├── solver.py
      └── templates
  └── __init__.py
      └── solver.py

You can copy the directory `docs/examples/snek5000-canonical
<https://github.com/snek5000/snek5000/tree/main/docs/examples/snek5000-canonical>`_
Expand Down

0 comments on commit bebbe99

Please sign in to comment.