Salome HOME
Documentation update with features and review corrections
[modules/adao.git] / src / daComposant / daAlgorithms / InterpolationByReducedModelTask.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 import numpy
24 from daCore import BasicObjects
25 from daAlgorithms.Atoms import ecweim
26
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
29     def __init__(self):
30         BasicObjects.Algorithm.__init__(self, "INTERPOLATIONBYREDUCEDMODEL")
31         self.defineRequiredParameter(
32             name     = "ReducedBasis",
33             default  = [],
34             typecast = numpy.array,
35             message  = "Base réduite, 1 vecteur par colonne",
36         )
37         self.defineRequiredParameter(
38             name     = "OptimalLocations",
39             default  = [],
40             typecast = tuple,
41             message  = "Liste des indices ou noms de positions optimales de mesure selon l'ordre interne d'un vecteur de base",  # noqa: E501
42         )
43         self.defineRequiredParameter(
44             name     = "ObservationsAlreadyRestrictedOnOptimalLocations",
45             default  = True,
46             typecast = bool,
47             message  = "Stockage des mesures restreintes a priori aux positions optimales de mesure ou non",
48         )
49         self.defineRequiredParameter(
50             name     = "StoreSupplementaryCalculations",
51             default  = [],
52             typecast = tuple,
53             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
54             listval  = [
55                 "Analysis",
56                 "ReducedCoordinates",
57             ]
58         )
59         self.requireInputArguments(
60             mandatory= ("Y",),
61             optional = (),
62         )
63         self.setAttributes(
64             tags=(
65                 "Reduction",
66                 "Interpolation",
67             ),
68             features=(
69                 "DerivativeFree",
70             ),
71         )
72
73     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
74         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
75         #
76         # --------------------------
77         __rb = self._parameters["ReducedBasis"]
78         __ip = self._parameters["OptimalLocations"]
79         if len(__ip) != __rb.shape[1]:
80             raise ValueError("The number of optimal measurement locations (%i) and the dimension of the RB (%i) has to be the same."%(len(__ip), __rb.shape[1]))  # noqa: E501
81         #
82         # Nombre de pas identique au nombre de pas d'observations
83         if hasattr(Y, "stepnumber"):
84             duration = Y.stepnumber()
85         else:
86             duration = 2
87         #
88         for step in range(0, duration - 1):
89             #
90             # La boucle sur les mesures permet une interpolation par jeu de mesure,
91             # sans qu'il y ait de lien entre deux jeux successifs de mesures.
92             #
93             # Important : les observations sont données sur tous les points
94             # possibles ou déjà restreintes aux points optimaux de mesure, mais
95             # ne sont utilisés qu'aux points optimaux
96             if hasattr(Y, "store"):
97                 _Ynpu = numpy.ravel( Y[step + 1] ).reshape((-1, 1))
98             else:
99                 _Ynpu = numpy.ravel( Y ).reshape((-1, 1))
100             if self._parameters["ObservationsAlreadyRestrictedOnOptimalLocations"]:
101                 __rm = _Ynpu
102             else:
103                 __rm = _Ynpu[__ip]
104             #
105             # Interpolation
106             ecweim.EIM_online(self, __rb, __rm, __ip)
107         # --------------------------
108         #
109         self._post_run(HO, EM)
110         return 0
111
112 # ==============================================================================
113 if __name__ == "__main__":
114     print("\n AUTODIAGNOSTIC\n")