]> SALOME platform Git repositories - modules/homard.git/blob - doc/en/yacs.rst
Salome HOME
Correction schema YCAS pour une frontière discrète.
[modules/homard.git] / doc / en / yacs.rst
1 .. _yacs:
2
3 YACS
4 ####
5 .. index:: single: yacs
6
7 Introduction
8 ************
9
10 Using a YACS scheme allows the coupling between a computation and an adaptation as described into :ref:`intro`. This coupling can be repeated inside a loop as long as a criteria for the convergence is reached for instance. Many ways are available to program a YACS scheme. The solution that is shown here is correct but many others are too!
11
12 Here is the description of a scheme for a computation in which a value is to be stabilized. The computation starts over an initial mesh, then HOMARD makes an adaptation. A new computation is done over this new mesh and its result is analyzed. Depending on this analysis, the coupling goes on or does not. The general look of the scheme is this one:
13
14 .. image:: ../images/yacs_01.png
15    :align: center
16    :alt: yacs - allure générale
17    :width: 512
18    :height: 306
19
20 .. note::
21   Among all the treated data, certain are unchanging: the name of the directory of calculation, the name of the case, the name of the hypothesis of adaptation, etc. It was chosen to impose them 'hard' in the various parameters of service or within the scripts python. We could also define them a priori in a node PresetNode and then pass on them by links. We did not hold this solution because it increases strongly the number of parameters and links attached to every node. It is very penalizing for the legibility of the scheme. The only data which are going to circulate are the ones been imperative by the description of the service and those that evolve during the execution of the scheme.
22
23 The boxes
24 *********
25
26 The main boxes are:
27
28 - DataInit : initialisation of the initial mesh
29 - Etude_Initialisation : launching of the module HOMARD inside SALOME
30 - Boucle_de_convergence : gestion of the loop computation/adaptation
31 - Bilan : final information
32
33 DataInit
34 ========
35 .. image:: ../images/yacs_a_01.png
36    :align: center
37    :alt: DataInit
38    :width: 158
39    :height: 61
40
41 This box is type PresetNode's elementary node. Its only function is to initialize the variable MeshFile that contains the name of the file of the initial mesh.
42
43 .. literalinclude:: ../files/yacs_01.en.xml
44    :lines: 38-42
45
46 Etude_Initialisation
47 ====================
48 The box Etude_Initialisation launches the component HOMARD inside SALOME. It is a block consisted of two parts, that are invariable whatever is the envisaged application:
49
50 - StudyCreation : python node
51 - SetCurrentStudy : service of the component HOMARD
52
53 .. image:: ../images/yacs_b_01.png
54    :align: center
55    :alt: Etude_Initialisation
56    :width: 323
57    :height: 97
58
59 The python node StudyCreation initialize the SALOME study that is given through the output:
60
61 .. literalinclude:: ../files/yacs_01.en.xml
62    :lines: 44-62
63
64 The service SetCurrentStudy connects this study to an instance of HOMARD.
65
66 .. literalinclude:: ../files/yacs_01.en.xml
67    :lines: 63-68
68
69
70 Boucle_de_convergence
71 =====================
72 The box Boucle_de_convergence is type WhileLoop. The condition is initialized in 1: the internal block Alternance_Calcul_HOMARD is executed. Within this block, we calculate and we adapt the mesh; when the process has to stop either as a result of error, or by convergence, the condition passes in 0. The loop ends and we pass in the following box, Bilan.
73
74 .. image:: ../images/yacs_c_01.png
75    :align: center
76    :alt: Boucle
77    :width: 163
78    :height: 93
79
80 Bilan
81 =====
82 .. image:: ../images/yacs_d_01.png
83    :align: center
84    :alt: Bilan
85    :width: 158
86    :height: 63
87
88 This box is a node python that takes in input a character string, MessInfo. If everything passed well, this message is empty. A window QT appears to confirm the convergence. If there was a problem, the message contains messages emitted during the calculations. The window QT shows this message.
89
90 .. literalinclude:: ../files/yacs_01.en.xml
91    :lines: 406-419
92
93
94 Loop for the calculations
95 *************************
96 .. image:: ../images/yacs_c_02.png
97    :align: center
98    :alt: Boucle
99    :width: 338
100    :height: 152
101
102 This box is a block that manages the computation, the adaptation and the analysis.
103
104 Calcul
105 ======
106 .. image:: ../images/yacs_c_03.png
107    :align: center
108    :alt: Calcul
109    :width: 155
110    :height: 87
111
112 This box is a node python that is going to drive the calculation. In input, we find the number of the calculation (0 at first) and the name of the file which contains the mesh on which to calculate. In output, we find an integer which represents the error on this calculation (0 so everything goes well) and a dictionary python gathering the results of the calculation. The body of the node is established by the launch of a script python that activates the calculation.
113
114 .. literalinclude:: ../files/yacs_01.en.xml
115    :lines: 77-103
116
117 In this example, we must define:
118
119 - rep_calc : the directory in which will be executed the calculation.
120 - rep_script : the directory in which is the python that will launch the calculation. This directory is to be added to the PATH. From this directory, we shall import Script from the file ScriptAster.py
121
122 The python Script is programmed as the user wishes it so that the calculation can be made on the current mesh. According to the mode of launch of the code of calculation, we can need other information, as the number of the calculation or the directory of the calculation for example. The freedom is total. In our case, the arguments of input are the name of the file of mesh, the number of the calculation and the directory of calculation. They are given in a list python: ["--rep_calc=rep_calc", "--num=numCalc", "--mesh_file=MeshFile"]
123 ].
124
125 On the other hand the output of the script has to obey the following rule. We get back a code of error, an error message and a dictionary. This dictionary contains necessarily the following keys:
126
127 - "FileName" : the name of the file that contains the results of the calculation
128 - "V_TEST" : the value the convergence of which we want to test
129
130 Adaptation
131 ==========
132 .. image:: ../images/yacs_c_04.png
133    :align: center
134    :alt: Adaptation
135    :width: 661
136    :height: 566
137
138 The box Adaptation is a Switch node driven by the code of error of the previous calculation. If this code is nil, YACS will activate the box Adaptation_HOMARD that will launch the adaptation. If the code is not nil, we pass directly in the box Arret_boucle.
139
140 Adaptation_HOMARD
141 -----------------
142 The first task tries to execute concern the initialization of the data necessary for HOMARD in the box HOMARD_Initialisation. This box is a switch node driven by the number of the calculation. In the starting up, the number is nil and YACS activates the box Iter_1.
143
144 Iter_1
145 ^^^^^^
146 .. image:: ../images/yacs_c_06.png
147    :align: center
148    :alt: Iter_1
149    :width: 481
150    :height: 151
151
152 This box begins by creating the case HOMARD by calling the CreateCase service.
153
154 .. literalinclude:: ../files/yacs_01.en.xml
155    :lines: 208-215
156
157 The name of the case CaseName is imposed on "Calcul". The name of the case MeshName is imposed on "BOX". The parameters of input FileName arise from the output of the previous calculation. The parameter of output is an instance of case.
158
159 .. literalinclude:: ../files/yacs_01.en.xml
160    :lines: 443-446
161
162 .. literalinclude:: ../files/yacs_01.en.xml
163    :lines: 483-486
164
165 The options of this case must be now given. It is made by the node python CaseOptions. It is imperative to give the directory of calculation. We shall look at the description of the functions in :ref:`tui_create_case`. In output, we get back the instance of the iteration corresponding to the initial state of the case.
166
167 .. literalinclude:: ../files/yacs_01.en.xml
168    :lines: 216-228
169
170 Finally, a hypothesis is created by calling the CreateHypothese service. The parameter of output is an instance of hypothese.
171
172 Homard_Exec
173 ^^^^^^^^^^^
174 Once initialized, the adaptation can be calculated. It is the goal of the Homard_Exec box, in the form of a script python.
175
176 .. image:: ../images/yacs_c_09.png
177    :align: center
178    :alt: Homard_Exec
179    :width: 153
180    :height: 141
181
182 The directory of calculation is recovered. The name of the mesh is given.
183
184 .. literalinclude:: ../files/yacs_01.en.xml
185    :lines: 245-250
186
187 ../..
188
189 .. literalinclude:: ../files/yacs_01.en.xml
190    :lines: 325-333
191
192 The hypothesis transmitted in input parameter characterized (look :ref:`tui_create_hypothese`) :
193
194 .. literalinclude:: ../files/yacs_01.en.xml
195    :lines: 254-278
196
197 It is necessary to establish a name for the future iteration. To make sure that the name was never used, one installs a mechanism of incremental naming starting from the name of the initial iteration. As this initial name is the name of the initial mesh, one obtains a succession of names in the form: M_001, M_002, M_003, etc
198
199 .. literalinclude:: ../files/yacs_01.en.xml
200    :lines: 280-290
201
202 The iteration is supplemented : hypothesis, future mesh, field (look :ref:`tui_create_iteration`) :
203
204 .. literalinclude:: ../files/yacs_01.en.xml
205    :lines: 292-311
206
207 The iteration is calculated. If it were correct, variable OK equals 1: one will be able to continue the execution of the scheme. If there were a problem, variable OK equals 0 to mean that calculation must stop; an error message then is given.
208
209 .. literalinclude:: ../files/yacs_01.en.xml
210    :lines: 313-324
211
212 After this execution, the process leaves the Adaptation_HOMARD node, then Adaptation node. One arrives then at the node of analysis.
213
214 Iter_n
215 ^^^^^^
216 .. image:: ../images/yacs_c_07.png
217    :align: center
218    :alt: Iter_n
219    :width: 323
220    :height: 92
221
222 For the following passing in the block of adaptation, it is necessary to recover:
223
224 - the last created iteration: service LastIteration (look :ref:`tui_create_iteration`)
225 - the created hypothesis: service GetHypothesis (look :ref:`tui_create_hypothese`)
226
227 One passes then in the Homard_Exec node to calculate the new mesh.
228
229 Arret_boucle
230 ------------
231 .. image:: ../images/yacs_c_08.png
232    :align: center
233    :alt: Arret_boucle
234    :width: 163
235    :height: 152
236
237 The Arret_boucle block is present to only make forward variables because the input parameters of the nodes must always be filled. It is a very simple python:
238
239 .. literalinclude:: ../files/yacs_01.en.xml
240    :lines: 173-184
241
242 Analyse
243 =======
244 .. image:: ../images/yacs_c_05.png
245    :align: center
246    :alt: Analyse
247    :width: 156
248    :height: 139
249
250 The Analyse block is a script python which ensures the complete control of the process by examining the causes of possible error successively.
251
252 .. literalinclude:: ../files/yacs_01.en.xml
253    :lines: 104-116
254
255 ../..
256
257 .. literalinclude:: ../files/yacs_01.en.xml
258    :lines: 162-170
259
260 One starts by analyzing the return of the computer code:
261
262 .. literalinclude:: ../files/yacs_01.en.xml
263    :lines: 118-123
264
265 Checking of the presence of the name of the result file in the dictionary of the results:
266
267 .. literalinclude:: ../files/yacs_01.en.xml
268    :lines: 125-132
269
270 Checking of convergence. That supposes that the value to be tested is present in the dictionary under the key 'V_TEST'. Here, one set up a test on the variation of the value of one calculation at the other. With the first passage, nothing is tested. In the following passing, one tests if the relative variation is lower than 1 thousandths. One could have set up an absolute test if one had recovered a total level of error for example.
271
272 .. literalinclude:: ../files/yacs_01.en.xml
273    :lines: 134-152
274
275 Lastly, it is checked that a maximum nomber of adaptations is not exceeded:
276
277 .. literalinclude:: ../files/yacs_01.en.xml
278    :lines: 154-159
279
280
281 Use this scheme
282 ***************
283 To reproduce this example, download:
284   * :download:`the scheme <../files/yacs_01.en.xml>`
285   * :download:`an example of python script <../files/yacs_script.py>`
286
287 It should be adapted to simulation considered. In particular, it is necessary:
288
289 - to adjust the names of the files and the directories
290 - to provide a script of launching of calculation respecting the instructions evoked herebefore
291 - to choose the hypothesis of driving of the adaptation
292 - to set up the test of stop
293
294
295
296