Skip to content

Commit

Permalink
Saigre/pyfeelpp (#183)
Browse files Browse the repository at this point in the history
* write doc about :
- parameters
- petsc vectors
- petsc matrix
Write documentation on python x feel++ modules #151
[ci skip]

* add documentation about parameters

see commit feelpp/feelpp@9512e77
[ci skip]

* add documentation about ModelProperties in python #151

* add documentation about functions wrapped in feelpp/feelpp@84a845d

* up doc about `feelpp.mor._mor.ParameterSpace.New`
[ci skip]

* update doc according to feelpp/feelpp@2f3b94a
  • Loading branch information
thomas-saigre authored Mar 27, 2022
1 parent 5e70bfb commit 7e16abe
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/user/modules/python/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*** xref:pyfeelpp/discr.adoc[Creating a function space and interpolating]
*** xref:pyfeelpp/filters.adoc[Exporting results for visualisation]
** xref:pyfeelpptoolboxes/index.adoc[{pyfeelpptb}]
*** xref:pyfeelpptoobloxes/modelproperties.adoc[Model Properties]
*** xref:pyfeelpptoolboxes/heat.adoc[Heat Transfer]
*** xref:pyfeelpptoolboxes/electric.adoc[Electrostatic]
*** xref:pyfeelpptoolboxes/fluid.adoc[Fluid Mechanics]
Expand All @@ -13,4 +14,4 @@
*** xref:pyfeelppmor/parameters.adoc[Parameters]
*** xref:pyfeelppmor/parametersSpace.adoc[Parameter space]
*** xref:pyfeelppmor/petscDouble.adoc[PETSc vector and matrix]
*** xref:pyfeelppmor/reducedbasis.adoc[Python module `reducedbasis`]
*** xref:pyfeelppmor/reducedbasis.adoc[Python module `reducedbasis`]
22 changes: 21 additions & 1 deletion docs/user/modules/python/pages/pyfeelppmor/parameterSpace.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,35 @@ Dmu = model.parameterSpace()

== Methods


* `element(broadcast: bool = True, apply_log: bool = False) -> feelpp.mor._mor.ParameterSpaceElement` : return a parameter from the space :
- `broadcast` : share the parameter to all processors
- `apply_log` : log random chosen parameter

* `sampling() -> feelpp.mor._mor.ParameterSpaceSampling`

* `mumin() -> feelpp.mor._mor.ParameterSpaceElement` : return an element with the minimal values.

* `mumax() -> feelpp.mor._mor.ParameterSpaceElement` : return an element with the maximal values.
fpp

* `dimension() -> int` : return the dimension of the space

* `parameterNamed(name: str)` -> `float` : return the parameter named `str`

* `parameterNames(name: str)` -> `list` : return the list of the name of the parameters



== Static method

* `New(feelpp._models.ModelParameters, arg1: feelpp._core.WorldComm)`: constructor using a model parameters loaded from a JSON file (see xref:../pyfeelpptoolboxes/modelproperties.adoc[ModelParameters]).

.Create a `parameterSpace` from `ModelParameters`
[source,python]
----
modelParameters = heatBox.modelProperties().parameters() # for instance
Dmu = feelpp.mor._mor.ParameterSpace.New(modelParameters, feelpp.Environment.worldCommPtr())
----


* `create(arg0: int) -> feelpp.mor._mor.ParameterSpace` : return a `ParameterSpace` of a dimension `arg0`.
3 changes: 3 additions & 0 deletions docs/user/modules/python/pages/pyfeelppmor/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Class `ParameterSpaceElement` (more precisely `feelpp.mor._mor.ParameterSpaceElement`). Contains the parameters of the problem.


.Get a parameter from the model (see xref:pyfeelppmor/reducedbasis.adoc[this page])
[source,python]
----
Expand All @@ -26,6 +27,8 @@ mu = [4.37e+00,2.92e+00,1.17e+00,8.75e+05,5.28e+05,2.83e+01]

* `parameterNamed(name: str)` -> `float` : return the parameter named `str`

* `parameterNames(name: str)` -> `list` : return the list of the name of the parameters

* `setParameter(i: int, value: float)` : set the _i_-th to `value`

* `setParameterNamed(name: str, value: float)` : set the parameter `name` to `value`
Expand Down
147 changes: 147 additions & 0 deletions docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
= Model Properties


== Class `ModelProperties`

This class gathers the properties of the model, that can be set from a JSON file.

* `__init__(filename: str = '', directoryLibExpr: str = '', worldComm: feelpp._core.WorldComm, prefix: str = '') -> None` : initialize `ModelProperties`.
* `materials() -> feelpp._models.ModelMaterials` : get the materials of the model (see section <<Class `ModelMaterials`,below>>).
* `parameters(self: feelpp._models.ModelProperties) -> feelpp._models.ModelParameters` : get parameters of the model (see <<Class `ModelParameters`,below>>).



If a model is already loaded in the environment, for example with a toolbox `heatBox`, a way to get the instance of `ModelProperties` is

[source, python]
----
m = heatBox.modelProperties()
----


== Class `ModelMaterials`

This class gathers the different materials present in the model.

* `__getitem__(str) -> feelpp._models.ModelMaterial` : returns the <<Class `ModelMaterial`,`ModelMaterial`>> named `str`. If `mo` is the instance of `ModelMaterials`, the material `s` is called with the command `mo[s]`.

* `__init__(self: feelpp._models.ModelMaterials, worldComm: feelpp._core.WorldComm) -> None`

* `__iter__() -> iterator` : returns an iterator on the matrials (for a `for` loop for instance : `for mat in mo: ...`)

* `__len__() -> int` : returns the number of materials in the model.

* `__str__() -> str` : print the list of materials of the model

* `at(arg0: str) -> feelpp._models.ModelMaterial` : `mo.at(s)` is equivalent to `mo[s]`.

* `clear(self: Dict[str, feelpp._models.ModelMaterial]) -> None`

* `items() -> iterator` : equivalent to `__getitem__`

* `setParameterValues(arg0: Dict[str, float]) -> None`


== Class `ModelMaterial`

* `__getitem__(self: feelpp._models.ModelMaterial, arg0: str) -> str`

* `__init__(self: feelpp._models.ModelMaterial) -> None`

* `__str__(self: feelpp._models.ModelMaterial) -> str`

* `getString(self: feelpp._models.ModelMaterial, arg0: str) -> str` : returns the string from key if the value is a string

* `hasProperty(self: feelpp._models.ModelMaterial, arg0: str) -> bool`
: returns ``True`` of the property exists, ``False`` otherwise

* `hasPropertyConstant(self: feelpp._models.ModelMaterial, arg0: str) -> bool` : returns ``True`` if the property exists and is constant, ``False`` otherwise

* `hasPropertyScalar(self: feelpp._models.ModelMaterial, arg0: str) -> bool` : returns ``True`` if the property exists and is a scalar expression, ``False`` otherwise

* `propertyConstant(self: feelpp._models.ModelMaterial, arg0: str) -> float` : return the value of the constant property

* `setParameterValues(self: feelpp._models.ModelMaterial, arg0: Dict[str, float]) -> None` : set parameter values from a map of string/double pairs

* `setProperty(self: feelpp._models.ModelMaterial, arg0: str, arg1: str) -> None` : set a property to an expression. The expression can involve symbols, see the documentation.

Example of usage of the functions described above :
[source, python]
----
>>> m = heatBox.modelProperties()
>>> mos = m.materials()
>>> mo = mo['Marker']
>>> print(mo)
Post
. markers: Post
. physics:
. properties:
{Cp, 1.4e+06}
{Cp, 1400000.000000}
{k, k_0:k_0}
{rho, 1}
{rho, 1.000000}
>>> mo.hasProperty('Cp')
`True`
>>> mo.hasProertry('kappa')
`False`
>>>
>>> mo.setProperty('Cp', 'Cp_param:Cp_param')
>>> mm['Cp']
'Cp_param:Cp_param'
----


== Class `ModelParameters`

This class gathers all the parameters used in the model.

* `__init__(self: feelpp._models.ModelParameters, worldComm: feelpp._core.WorldComm) -> None`

* `__iter__() -> iterator`

* `__len__() -> int`

* `__str__() -> str`

* `at(arg0: str) -> feelpp._models.ModelParameter`

* `clear(self: Dict[str, feelpp._models.ModelParameter]) -> None`

* `setParameterValues(arg0: Dict[str, float]) -> None` : set parameter values from a map of string/double pairs

* `toParameterValues(self: feelpp._models.ModelParameters) -> Dict[str, float]` : get a dictionary from the map of parameter values


== Class `ModelParameter`

* `__init__(self: feelpp._models.ModelParameter) -> None`

* `__str__(self: feelpp._models.ModelParameter) -> str`

* `description(self: feelpp._models.ModelParameter) -> str` : get description

* `hasFitInterpolator(self: feelpp._models.ModelParameter) -> bool` : return `True` if the parameter has a fit interpolator, `False` otherwise

* `hasMinMax(self: feelpp._models.ModelParameter) -> bool` : check if the parameter has min and max values

* `max(self: feelpp._models.ModelParameter) -> float` : get maximal value

* `min(self: feelpp._models.ModelParameter) -> float` : get minimal value

NOTE: For the two last functions, if a parameter has no max or min, the returned valued will be `0`.


* `name(self: feelpp._models.ModelParameter) -> str` name of the parameter

* `setMax(self: feelpp._models.ModelParameter, arg0: float) -> None` : set maximal value

* `setMin(self: feelpp._models.ModelParameter, arg0: float) -> None` : set minimal value

* `setParameterValues(self: feelpp._models.ModelParameter, arg0: Dict[str, float]) -> None` : set parameter values from a map of string/double pairs

* `setValue(self: feelpp._models.ModelParameter, arg0: float) -> None` : set value of the parameter

* `type(self: feelpp._models.ModelParameter) -> str` : type of the parameter: value, expression, fit

* `value(self: feelpp._models.ModelParameter) -> float` : value of the parameter

0 comments on commit 7e16abe

Please sign in to comment.