Salome HOME
Extending sampling control and output
[modules/adao.git] / src / daComposant / daAlgorithms / Atoms / eosg.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 __doc__ = """
24     Ensemble Of Simulations Generation
25 """
26 __author__ = "Jean-Philippe ARGAUD"
27
28 import numpy, logging
29 import daCore.NumericObjects
30
31 # ==============================================================================
32 def eosg(selfA, Xb, HO, outputEOX = False):
33     """
34     Ensemble Of Simulations Generation
35     """
36     #
37     __seed = numpy.random.get_state()
38     sampleList = daCore.NumericObjects.BuildComplexSampleList(
39         selfA._parameters["SampleAsnUplet"],
40         selfA._parameters["SampleAsExplicitHyperCube"],
41         selfA._parameters["SampleAsMinMaxStepHyperCube"],
42         selfA._parameters["SampleAsIndependantRandomVariables"],
43         Xb,
44         )
45     #
46     # ----------
47     if selfA._parameters["SetDebug"]:
48         CUR_LEVEL = logging.getLogger().getEffectiveLevel()
49         logging.getLogger().setLevel(logging.DEBUG)
50         print("===> Beginning of evaluation, activating debug\n")
51         print("     %s\n"%("-"*75,))
52     #
53     Hm = HO["Direct"].appliedTo
54     EOS = Hm(
55         sampleList,
56         argsAsSerie = True,
57         returnSerieAsArrayMatrix = True,
58         )
59     #
60     if selfA._parameters["SetDebug"]:
61         print("\n     %s\n"%("-"*75,))
62         print("===> End evaluation, deactivating debug if necessary\n")
63         logging.getLogger().setLevel(CUR_LEVEL)
64     # ----------
65     #
66     if outputEOX or selfA._toStore("EnsembleOfStates"):
67         # Attention la liste s'épuise donc il faut la recréer
68         numpy.random.set_state(__seed)
69         sampleList = daCore.NumericObjects.BuildComplexSampleList(
70             selfA._parameters["SampleAsnUplet"],
71             selfA._parameters["SampleAsExplicitHyperCube"],
72             selfA._parameters["SampleAsMinMaxStepHyperCube"],
73             selfA._parameters["SampleAsIndependantRandomVariables"],
74             Xb,
75             )
76         # Il faut passer la liste en tuple/list pour stack
77         EOX = numpy.stack(tuple(sampleList), axis=1)
78         assert EOX.shape[1] == EOS.shape[1], "  Error of number of states in Ensemble Of Simulations Generation"
79     if selfA._toStore("EnsembleOfStates"):
80         selfA.StoredVariables["EnsembleOfStates"].store( EOX )
81     if selfA._toStore("EnsembleOfSimulations"):
82         selfA.StoredVariables["EnsembleOfSimulations"].store( EOS )
83     #
84     if outputEOX:
85         return EOX, EOS
86     else:
87         return EOS
88
89 # ==============================================================================
90 if __name__ == "__main__":
91     print('\n AUTODIAGNOSTIC\n')