diff --git a/docs/user/modules/python/nav.adoc b/docs/user/modules/python/nav.adoc index 7b1225a6b..995cc3e7a 100644 --- a/docs/user/modules/python/nav.adoc +++ b/docs/user/modules/python/nav.adoc @@ -6,7 +6,6 @@ *** xref:pyfeelpp/discr.adoc[] *** xref:pyfeelpp/integrals.adoc[Computing integrals] *** xref:pyfeelpp/filters.adoc[Exporting results for visualisation] -*** xref:pyfeelpp/modelproperties.adoc[Model Properties] ** xref:pyfeelpptoolboxes/index.adoc[{pyfeelpptb}] *** xref:pyfeelpptoolboxes/modelproperties.adoc[Model Properties] *** xref:pyfeelpptoolboxes/heat.adoc[Heat Transfer] @@ -14,10 +13,9 @@ *** xref:pyfeelpptoolboxes/fluid.adoc[Fluid Mechanics] *** xref:pyfeelpptoolboxes/solid.adoc[Solid Mechanics] ** xref:pyfeelppmor/index.adoc[{pyfeelppmor}] -*** xref:pyfeelppmor/parameters.adoc[Parameters] *** xref:pyfeelppmor/parameterSpace.adoc[Parameter space] +*** xref:pyfeelppmor/parameters.adoc[Parameters] *** xref:pyfeelppmor/petscDouble.adoc[PETSc vector and matrix] *** xref:pyfeelppmor/toolboxmor.adoc[Toolbox MOR] *** xref:pyfeelppmor/reducedbasis.adoc[Python module `reducedbasis`] -**** xref:pyfeelppmor/reducedbasis/reducedbasis.adoc[Offline stage] -**** xref:pyfeelppmor/reducedbasis/reducedbasis.adoc[Online stage] +**** xref:pyfeelppmor/reducedbasis_offline.adoc[Offline stage] diff --git a/docs/user/modules/python/pages/pyfeelpp/filters.adoc b/docs/user/modules/python/pages/pyfeelpp/filters.adoc index 1080976f6..d0943ee56 100644 --- a/docs/user/modules/python/pages/pyfeelpp/filters.adoc +++ b/docs/user/modules/python/pages/pyfeelpp/filters.adoc @@ -24,30 +24,30 @@ app = feelpp.Environment(["myapp"],config=feelpp.localRepository("")) # <1> [source,python] ---- -app.setLogVerbosityLevel(0) # <0> +app.setLogVerbosityLevel(0) # <1> geofilename=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0] -mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), name=geofilename, h=0.1, verbose=1) # <1> -Xh=feelpp.functionSpace(mesh=mesh,space="Pch",order=1) # <2> -P0h=feelpp.functionSpace(mesh=mesh,space="Pdh",order=0) # <3> -u=Xh.element() # <4> -u.on(range=feelpp.elements(mesh), expr=feelpp.expr("sin(2*pi*x)*cos(pi*y):x:y")) # <5> -e = feelpp.exporter(mesh=mesh) # <6> -e.addScalar("a_scalar", 1.) # <7> -e.addP1c("u",u) # <8> -e.addP0d("pid",feelpp.pid( P0h )) # <9> -e.save() # <10> +mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), name=geofilename, h=0.1, verbose=1) # <2> +Xh=feelpp.functionSpace(mesh=mesh,space="Pch",order=1) # <3> +P0h=feelpp.functionSpace(mesh=mesh,space="Pdh",order=0) # <4> +u=Xh.element() # <5> +u.on(range=feelpp.elements(mesh), expr=feelpp.expr("sin(2*pi*x)*cos(pi*y):x:y")) # <6> +e = feelpp.exporter(mesh=mesh) # <7> +e.addScalar("a_scalar", 1.) # <8> +e.addP1c("u",u) # <9> +e.addP0d("pid",feelpp.pid( P0h )) # <10> +e.save() # <11> ---- -<0> The verbosity level is set to 0 (only `VLOG(level)` with `level <= 0` are displayed) -<1> The mesh is loaded from the {uri-github-feelpp} repository -<2> The function space stem:[X_h] is built from the mesh stem:[mesh] and the space stem:[Pch] and order stem:[1] -<3> The function space stem:[P0_h] is built from the mesh stem:[mesh] and the space stem:[Pdh] and order stem:[0] -<4> The element stem:[u] is built from the function space stem:[X_h] -<5> The element stem:[u] is interpolated with the expression stem:[{sin(2*pi*x)*cos(pi*y)}:x:y] -<6> The exporter is built from the mesh stem:[mesh] -<7> The scalar stem:[a_scalar] is added to the exporter stem:[e] -<8> The element stem:[u] is added to the exporter stem:[e] -<9> The element stem:[pid] is added to the exporter stem:[e] -<10> The exporter stem:[e] is saved to the disk +<1> The verbosity level is set to 0 (only `VLOG(level)` with `level <= 0` are displayed) +<2> The mesh is loaded from the {uri-github-feelpp} repository +<3> The function space stem:[X_h] is built from the mesh `mesh` and the space `Pch` and order `1` +<4> The function space stem:[P0_h] is built from the mesh `mesh` and the space `Pdh` and order `0` +<5> The element `u` is built from the function space `Xh` +<6> The element `u` is interpolated with the expression `{sin(2*pi*x)*cos(pi*y)}:x:y` +<7> The exporter is built from the mesh `mesh` +<8> The scalar `a_scalar` is added to the exporter `e` +<9> The element `u` is added to the exporter `e` +<10> The element `pid` is added to the exporter `e` +<11> The exporter `e` is saved to the disk [%collapsible.result] @@ -59,7 +59,7 @@ e.save() # <10> ---- ==== -The results are stored in the directory `feelppdb`` and can be visualized with {paraview-website} or {ensight}. +The results are stored in the directory `feelppdb` and can be visualized with {paraview-website} or {ensight}. INFO: The file `exports/ensightgold/myapp/myapp.case` can be opened directly in {paraview} or {ensight} to visualize the mesh and the fields. diff --git a/docs/user/modules/python/pages/pyfeelpp/mesh.adoc b/docs/user/modules/python/pages/pyfeelpp/mesh.adoc index bbf0be930..026708769 100644 --- a/docs/user/modules/python/pages/pyfeelpp/mesh.adoc +++ b/docs/user/modules/python/pages/pyfeelpp/mesh.adoc @@ -208,4 +208,4 @@ i1 = [3.24282386], i2 = [149.465], i3 = [0.] == Next steps - [x] xref:pyfeelpp/discr.adoc[Manipulate functions and function spaces] -- [x] Export to paraview +- [x] xref:pyfeelpp/filters.adoc[Export to paraview] diff --git a/docs/user/modules/python/pages/pyfeelpp/modelproperties.adoc b/docs/user/modules/python/pages/pyfeelpp/modelproperties.adoc deleted file mode 100644 index 6649c39e1..000000000 --- a/docs/user/modules/python/pages/pyfeelpp/modelproperties.adoc +++ /dev/null @@ -1,148 +0,0 @@ -= 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 <>). -* `setup(self: feelpp._models.ModelProperties, arg0: str) -> None` : setup from a filename - - - -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 diff --git a/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_offline.adoc b/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_offline.adoc index 68755f3b6..ba0707545 100644 --- a/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_offline.adoc +++ b/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_offline.adoc @@ -38,7 +38,7 @@ This part can be run in parallel. |name of the case |`generate_basis` -|dim` +|`dim` |dimension of the case (must be `2` or `3`) |_mandatory_ @@ -59,7 +59,6 @@ This part can be run in parallel. |`False` |=== -WARNING: The time-dependant case it net yet functionnal... [[Algorithms]] @@ -71,15 +70,15 @@ WARNING: The time-dependant case it net yet functionnal... |=== |Value|Algorithm|Description -|0 +|`0` |From sample |Generates a basis of size stem:[N=]`train-size` elements, [log-]randomly taken in the space. -|1 +|`1` |Greedy algorithm |Run the greedy algorithm on a train set of element of size `train-size`. This algorithm also stores the evolution of the maximal error bound at each step. -|2 +|`2` |POD generation |Takes the largest POD modes from a basis of size `train-size`. The resulting basis will have a size stem:[N\leqslant]`train-size`. This algorithm also stores the evolution of the maximal error bound at each step. @@ -96,7 +95,7 @@ Here is a description of the generated files : - `Qa` : Size of the decomposition of stem:[A(\mu)] - `Qf` : Size of the decomposition of stem:[F(\mu)] - `QLk` : Sizes of the decompositions of stem:[L_k(\mu)] for stem:[k\in\{1,n_\text{output}\}], gathers in a list. - - `N_output` : Number pof output described in the JSON (`CRBOutput`) + - `N_output` : Number of output described in the JSON (`CRBOutput`) - `output_names` : names of those outputs - `N` : Size of the reduced basis - `path` : Path where `h5` file is stored @@ -128,7 +127,7 @@ config = generateBasisConfig(dim, config_file, time_dependant, odir, case, algo, The description and the default values of those parameters are descirbed <>. -If `odir` contains `$name`, this expression will be replaced by the _name_ of the case, defined by concatenation `{case}-np_{nproc}`, where `case` is the name of the case given in the configuration, and `nproc` is the number of processors where the simulation is run. +If `odir` contains `$name`, this expression will be replaced by the _name_ of the case, defined by concatenation `-np_`, where `case` is the name of the case given in the configuration, and `nproc` is the number of processors where the simulation is run. [[files]] diff --git a/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_online.adoc b/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_online.adoc deleted file mode 100644 index 1112cd0ef..000000000 --- a/docs/user/modules/python/pages/pyfeelppmor/reducedbasis_online.adoc +++ /dev/null @@ -1,155 +0,0 @@ -= Usage of Feelpp / Mor : Online part - -:stem: latexmath - -== Load the generated basis - -The following pieces of code can be unsed in a sequential script, or even in a notebook for vizualisation. - -NOTE: The following code is meant to be used for a basis created with the script xref:pyfeelppmor/reducedbasis_offline.adoc[`generete_basis.py`]. - -.Load the packages -[source, python] ----- -import sys, os -import numpy as np -import feelpp -import feelpp.mor.reducedbasis.reducedbasis as rb -from feelpp.toolboxes.heat import * -from feelpp.toolboxes.core import * -from feelpp.mor import * ----- - -.Set the environment -[source, python] ----- -config_file = "path" <1> -odir = "path" <2> -dim = 2 <3> -time_dependant = False - -name = "name" <4> -NCORES = ncores <5> - - -config = feelpp.globalRepository(f"generate_basis-{name}") -sys.argv = ['generate-basis'] -o = toolboxes_options("heat") -o.add(makeToolboxMorOptions()) - -e = feelpp.Environment(sys.argv, opts=o, config=config) ----- - -<1> Path to the cfg file used to generate the basis -<2> Path to the directory where the offline basis is stored -<3> Dimension of the case (`2` or `3`) -<4> Name of the case used on the script generate_basis -<5> Number of cores used to generate the basis - - -To load the parameters used to generete the space, we have to ensure taht we are in the same directory as during the offline phasis. The corresponding directory should be like : -``` -/generated_basis-/np_/ -``` - -To do so, we can use the following code : - -[soucre, python] ----- -cwd = os.getcwd() -os.chdir(cwd.replace('np_1', f'np_{NCORES}')) ----- - - -.Set the toolboxmor model, necessary to run online computation -[source, python] ----- -feelpp.Environment.setConfigFile(casefile) - -heatBox = heat(dim=dim, order=1) -heatBox.init() - -model = toolboxmor(name=name, dim=dim, time_dependent=time_dependant) -model.setFunctionSpaces( Vh=heatBox.spaceTemperature() ) - -def assembleDEIM(mu): - for i in range(0,mu.size()): - heatBox.addParameterInModelProperties(mu.parameterName(i), mu(i)) - heatBox.updateParameterValues() - return heatBox.assembleRhs() - -def assembleMDEIM(mu): - for i in range(0,mu.size()): - heatBox.addParameterInModelProperties(mu.parameterName(i), mu(i)) - heatBox.updateParameterValues() - return heatBox.assembleMatrix() - -model.setAssembleDEIM(fct=assembleDEIM) -model.setAssembleMDEIM(fct=assembleMDEIM) - -model.initModel() ----- - -NOTE: During the initialisation of the toolboxmor `model`, directories paths are created. They sould be the same as the one described xref:reducedbasis_offline.adoc#files[here]. - - -[source, python] ----- -heatBoxDEIM = heat(dim=dim, order=1) -meshDEIM = model.getDEIMReducedMesh() -heatBoxDEIM.setMesh(meshDEIM) -heatBoxDEIM.init() - -heatBoxMDEIM = heat(dim=dim, order=1) -meshMDEIM = model.getMDEIMReducedMesh() -heatBoxMDEIM.setMesh(meshMDEIM) -heatBoxMDEIM.init() - -def assembleOnlineDEIM(mu): - for i in range(0,mu.size()): - heatBoxDEIM.addParameterInModelProperties(mu.parameterName(i),mu(i)) - heatBoxDEIM.updateParameterValues() - return heatBoxDEIM.assembleRhs() - -def assembleOnlineMDEIM(mu): - for i in range(0,mu.size()): - heatBoxMDEIM.addParameterInModelProperties(mu.parameterName(i),mu(i)) - heatBoxMDEIM.updateParameterValues() - return heatBoxMDEIM.assembleMatrix() - -model.setOnlineAssembleDEIM(assembleOnlineDEIM) -model.setOnlineAssembleMDEIM(assembleOnlineMDEIM) - -model.postInitModel() -model.setInitialized(True) ----- - -.Load the generated basis -[source, python] ----- -basis = rb.reducedbasis(None) -basis.loadReducedBasis('/reducedbasis.json', model) <1> ----- - -<1> Path to the json file, generated in the xref:pyfeelppmor/reducedbasis_offline.adoc[offline stage]. - - -== Run online computations - -The space of parameters can be retreived with this line - -[source, python] ----- -Dmu = model.parameterSpace() ----- - -The resulting object `Dmu` is a `parameterSpace`, see the dedicated xref:pyfeelppmor/parameterSpace.adoc[documentation page], and the one about xref:pyfeelppmor/parameters.adoc[parameters] - - -.Get offline solution -[source, python] ----- -uN,sN = basisSample.getSolutions(mu, k=k) ----- - -The integer `k` corresponds to the output desired in stem:[[|1, n_\text{outputs}|\]. If `-1` is given, then the compliant output is computed. diff --git a/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc b/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc index b69d29d29..af4238112 100644 --- a/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc +++ b/docs/user/modules/python/pages/pyfeelpptoolboxes/modelproperties.adoc @@ -5,9 +5,10 @@ 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`. +* `\\__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 <>). +* `setup(self: feelpp._models.ModelProperties, arg0: str) -> None` : setup from a filename @@ -23,15 +24,15 @@ m = heatBox.modelProperties() 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]`. +* `\\__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` +* `\\__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: ...`) +* `\\__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. +* `\\__len__() -> int` : returns the number of materials in the model. -* `__str__() -> str` : print the list of materials of 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]`. @@ -44,11 +45,11 @@ This class gathers the different materials present in the model. == Class `ModelMaterial` -* `__getitem__(self: feelpp._models.ModelMaterial, arg0: str) -> str` +* `\\__getitem__(self: feelpp._models.ModelMaterial, arg0: str) -> str` -* `__init__(self: feelpp._models.ModelMaterial) -> None` +* `\\__init__(self: feelpp._models.ModelMaterial) -> None` -* `__str__(self: feelpp._models.ModelMaterial) -> str` +* `\\__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 @@ -96,13 +97,13 @@ Post This class gathers all the parameters used in the model. -* `__init__(self: feelpp._models.ModelParameters, worldComm: feelpp._core.WorldComm) -> None` +* `\\__init__(self: feelpp._models.ModelParameters, worldComm: feelpp._core.WorldComm) -> None` -* `__iter__() -> iterator` +* `\\__iter__() -> iterator` -* `__len__() -> int` +* `\\__len__() -> int` -* `__str__() -> str` +* `\\__str__() -> str` * `at(arg0: str) -> feelpp._models.ModelParameter` @@ -115,9 +116,9 @@ This class gathers all the parameters used in the model. == Class `ModelParameter` -* `__init__(self: feelpp._models.ModelParameter) -> None` +* `\\__init__(self: feelpp._models.ModelParameter) -> None` -* `__str__(self: feelpp._models.ModelParameter) -> str` +* `\\__str__(self: feelpp._models.ModelParameter) -> str` * `description(self: feelpp._models.ModelParameter) -> str` : get description