From 7e16abe633f44b85486c5ca71debaba974c9fd4c Mon Sep 17 00:00:00 2001 From: Thomas Saigre <60920471+thomas-saigre@users.noreply.github.com> Date: Sun, 27 Mar 2022 16:32:40 +0200 Subject: [PATCH] Saigre/pyfeelpp (#183) * write doc about : - parameters - petsc vectors - petsc matrix Write documentation on python x feel++ modules #151 [ci skip] * add documentation about parameters see commit https://github.com/feelpp/feelpp/commit/9512e771590a6a6bd1f7261bee32d08d294921d7 [ci skip] * add documentation about ModelProperties in python #151 * add documentation about functions wrapped in feelpp/feelpp@84a845d8a696d8b6f0f44bf805cda3b006711968 * up doc about `feelpp.mor._mor.ParameterSpace.New` [ci skip] * update doc according to feelpp/feelpp@2f3b94aca6062ed6dd334795d677ba1b85bd48db --- docs/user/modules/python/nav.adoc | 3 +- .../pages/pyfeelppmor/parameterSpace.adoc | 22 ++- .../python/pages/pyfeelppmor/parameters.adoc | 3 + .../pyfeelpptoolboxes/modelproperties.adoc | 147 ++++++++++++++++++ 4 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc diff --git a/docs/user/modules/python/nav.adoc b/docs/user/modules/python/nav.adoc index 14ad6465c..d1934989f 100644 --- a/docs/user/modules/python/nav.adoc +++ b/docs/user/modules/python/nav.adoc @@ -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] @@ -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`] \ No newline at end of file +*** xref:pyfeelppmor/reducedbasis.adoc[Python module `reducedbasis`] diff --git a/docs/user/modules/python/pages/pyfeelppmor/parameterSpace.adoc b/docs/user/modules/python/pages/pyfeelppmor/parameterSpace.adoc index 00b99aa02..7304a8a6b 100644 --- a/docs/user/modules/python/pages/pyfeelppmor/parameterSpace.adoc +++ b/docs/user/modules/python/pages/pyfeelppmor/parameterSpace.adoc @@ -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`. \ No newline at end of file diff --git a/docs/user/modules/python/pages/pyfeelppmor/parameters.adoc b/docs/user/modules/python/pages/pyfeelppmor/parameters.adoc index bb52c5f1d..067dc18a6 100644 --- a/docs/user/modules/python/pages/pyfeelppmor/parameters.adoc +++ b/docs/user/modules/python/pages/pyfeelppmor/parameters.adoc @@ -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] ---- @@ -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` diff --git a/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc b/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc new file mode 100644 index 000000000..b69d29d29 --- /dev/null +++ b/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc @@ -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 <>). +* `parameters(self: feelpp._models.ModelProperties) -> feelpp._models.ModelParameters` : get parameters of the model (see <>). + + + +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 <> 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 \ No newline at end of file