Salome HOME
Documentation update and method improvement
[modules/adao.git] / src / daComposant / daAlgorithms / InterpolationByReducedModelTask.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2023 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",
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(tags=(
64             "Reduction",
65             "Interpolation",
66             ))
67
68     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
69         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
70         #
71         #--------------------------
72         __rb = self._parameters["ReducedBasis"]
73         __ip = self._parameters["OptimalLocations"]
74         if len(__ip) != __rb.shape[1]:
75             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]))
76         #
77         # Nombre de pas identique au nombre de pas d'observations
78         if hasattr(Y,"stepnumber"):
79             duration = Y.stepnumber()
80         else:
81             duration = 2
82         #
83         for step in range(0,duration-1):
84             #
85             # La boucle sur les mesures permet une interpolation par jeu de mesure,
86             # sans qu'il y ait de lien entre deux jeux successifs de mesures.
87             #
88             # Important : les observations sont données sur tous les points
89             # possibles ou déjà restreintes aux points optimaux de mesure, mais
90             # ne sont utilisés qu'aux points optimaux
91             if hasattr(Y,"store"):
92                 _Ynpu = numpy.ravel( Y[step+1] ).reshape((-1,1))
93             else:
94                 _Ynpu = numpy.ravel( Y ).reshape((-1,1))
95             if self._parameters["ObservationsAlreadyRestrictedOnOptimalLocations"]:
96                 __rm = _Ynpu
97             else:
98                 __rm = _Ynpu[__ip]
99             #
100             # Interpolation
101             ecweim.EIM_online(self, __rb, __rm, __ip)
102         #--------------------------
103         #
104         self._post_run(HO)
105         return 0
106
107 # ==============================================================================
108 if __name__ == "__main__":
109     print('\n AUTODIAGNOSTIC\n')