1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2023 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 Ensemble Of Simulations Generation
26 __author__ = "Jean-Philippe ARGAUD"
28 import numpy, logging, copy
29 import daCore.NumericObjects
31 # ==============================================================================
32 def eosg(selfA, Xb, HO, outputEOX = False, assumeNoFailure = True):
34 Ensemble Of Simulations Generation
37 sampleList = daCore.NumericObjects.BuildComplexSampleList(
38 selfA._parameters["SampleAsnUplet"],
39 selfA._parameters["SampleAsExplicitHyperCube"],
40 selfA._parameters["SampleAsMinMaxStepHyperCube"],
41 selfA._parameters["SampleAsMinMaxLatinHyperCube"],
42 selfA._parameters["SampleAsIndependantRandomVariables"],
44 selfA._parameters["SetSeed"],
47 if hasattr(sampleList,"__len__") and len(sampleList) == 0:
48 if outputEOX: return numpy.array([[]]), numpy.array([[]])
49 else: return numpy.array([[]])
51 if outputEOX or selfA._toStore("EnsembleOfStates"):
52 EOX = numpy.stack(tuple(copy.copy(sampleList)), axis=1)
55 if selfA._parameters["SetDebug"]:
56 CUR_LEVEL = logging.getLogger().getEffectiveLevel()
57 logging.getLogger().setLevel(logging.DEBUG)
58 print("===> Beginning of evaluation, activating debug\n")
59 print(" %s\n"%("-"*75,))
61 Hm = HO["Direct"].appliedTo
66 returnSerieAsArrayMatrix = True,
73 returnSerieAsArrayMatrix = True,
75 except: # Reprise séquentielle sur erreur de calcul
77 for state in sampleList:
78 if numpy.any(numpy.isin((None, numpy.nan), state)):
79 EOS.append( () ) # Résultat vide
82 EOS.append( Hm(state) )
83 __s = numpy.asarray(EOS[-1]).size
85 EOS.append( () ) # Résultat vide
86 for i, resultat in enumerate(EOS):
87 if len(resultat) == 0: # Résultat vide
88 EOS[i] = numpy.nan*numpy.ones(__s)
89 EOS = numpy.stack(EOS, axis=1)
91 if selfA._parameters["SetDebug"]:
92 print("\n %s\n"%("-"*75,))
93 print("===> End evaluation, deactivating debug if necessary\n")
94 logging.getLogger().setLevel(CUR_LEVEL)
97 if selfA._toStore("EnsembleOfStates"):
98 if EOX.shape[1] != EOS.shape[1]:
99 raise ValueError("Numbers of states (=%i) and snapshots (=%i) has to be the same!"%(EOX.shape[1], EOS.shape[1]))
100 selfA.StoredVariables["EnsembleOfStates"].store( EOX )
101 if selfA._toStore("EnsembleOfSimulations"):
102 selfA.StoredVariables["EnsembleOfSimulations"].store( EOS )
105 if EOX.shape[1] != EOS.shape[1]:
106 raise ValueError("Numbers of states (=%i) and snapshots (=%i) has to be the same!"%(EOX.shape[1], EOS.shape[1]))
111 # ==============================================================================
112 if __name__ == "__main__":
113 print('\n AUTODIAGNOSTIC\n')