Salome HOME
8dbd7bdb181be95b970856ad1222273874a36b15
[modules/homard.git] / doc / tutorials.rst
1 Exemples
2 ========
3 .. index:: single: exemple
4 .. index:: single: python
5
6 On trouvera ici les instructions python pour quelques configurations caractéristiques. Les fichiers de données associés sont téléchargeables. Il faut penser à modifier le contenu de la variable ``dircase`` : c'est le répertoire dans lequel les fichiers med auront été enregistrés. C'est dans ce répertoire que seront écrits les fichiers résultant des adaptations successives.
7
8 Raffinement uniforme
9 """"""""""""""""""""
10 .. index:: single: raffinement;uniforme
11
12 On fera ici trois raffinements uniformes successifs du maillage contenu dans le fichier ``tutorial_1.00.med``. Quelques remarques :
13   * la même hypothèse est utilisée à chaque itération
14   * le maillage produit porte toujours le même nom. Cela ne pose pas de problème car il est stocké dans des fichiers différents.
15
16  ::
17
18   dircase = "/tmp"
19   #
20   # Hypothesis "Hypo_0"
21   # ===================
22   Hypo_0 = homard.CreateHypothesis('Hypo_0')
23   Hypo_0.SetAdapRefinUnRef(-1, 1, 0)
24   #
25   # Case "Case_0"
26   # =============
27   Case_0 = homard.CreateCase('Case_0', 'MAILL', dircase+'/tutorial_1.00.med')
28   Case_0.SetDirName(dircase)
29   Case_0.SetConfType(1)
30   #
31   # Iterations
32   # ==========
33   # Iteration "Iter_0"
34   Iter_0 = homard.CreateIteration('Iter_0', Case_0.GetIter0Name())
35   Iter_0.SetMeshName('MESH')
36   Iter_0.SetMeshFile(dircase+'/maill.01.med')
37   homard.AssociateIterHypo('Iter_0', 'Hypo_0')
38   codret = homard.Compute('Iter_0', 1)
39
40   # Iteration "Iter_1"
41   Iter_1 = homard.CreateIteration('Iter_1', 'Iter_0')
42   Iter_1.SetMeshName('MESH')
43   Iter_1.SetMeshFile(dircase+'/maill.02.med')
44   homard.AssociateIterHypo('Iter_1', 'Hypo_0')
45   codret = homard.Compute('Iter_1', 1)
46
47   # Iteration "Iter_2"
48   Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
49   Iter_2.SetMeshName('MESH')
50   Iter_2.SetMeshFile(dircase+'/maill.03.med')
51   homard.AssociateIterHypo('Iter_2', 'Hypo_0')
52   codret = homard.Compute('Iter_2', 1)
53
54 .. note::
55   Téléchargement des fichiers
56
57   * :download:`maillage initial<files/tutorial_1.00.med.gz>`
58   * :download:`commandes python<files/tutorial_1.py>`
59
60
61 Raffinement par des zones
62 """""""""""""""""""""""""
63 .. index:: single: zone
64
65 On procède ici au raffinement selon des zones. Pour passer du maillage initial au maillage 'M_1', on utilise une boîte encadrant le plan z=1 et une sphère centrée sur l'origine de rayon 1.05. Puis pour passer du maillage 'M_1' au maillage 'M_2', on remplace la sphère par une boîte encadrant le cube de côté 0.5, pointant sur l'origine. On notera que le type de raffinement n'a pas été précisé ; par défaut, il sera donc conforme.
66 ::
67
68   dircase = "/tmp"
69   #
70   # Creation of the zones
71   # =====================
72   # Box "Zone_0"
73   Zone_0 = homard.CreateZoneBox('Zone_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
74   #
75   # Sphere "Zone_1"
76   Zone_1 = homard.CreateZoneSphere('Zone_1', 0., 0., 0., 1.05)
77   #
78   # Box "Zone_2"
79   Zone_2 = homard.CreateZoneBox('Zone_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
80   #
81   # Hypothesis "Hypo_0"
82   # ===================
83   Hypo_0 = homard.CreateHypothesis('Hypo_0')
84   Hypo_0.SetAdapRefinUnRef(0, 1, 0)
85   homard.AssociateHypoZone('Zone_1', 'Hypo_0')
86   homard.AssociateHypoZone('Zone_0', 'Hypo_0')
87   #
88   # Hypothesis "Hypo_1"
89   # ===================
90   Hypo_1 = homard.CreateHypothesis('Hypo_1')
91   Hypo_1.SetAdapRefinUnRef(0, 1, 0)
92   homard.AssociateHypoZone('Zone_0', 'Hypo_1')
93   homard.AssociateHypoZone('Zone_2', 'Hypo_1')
94   #
95   # Case "Case_0"
96   # =============
97   Case_0 = homard.CreateCase('Case_0', 'MZERO', dircase+'/tutorial_2.00.med')
98   Case_0.SetDirName(dircase)
99   #
100   # Iteration "Iter_0"
101   # ==================
102   Iter_0 = homard.CreateIteration('Iter_0', Case_0.GetIter0Name())
103   Iter_0.SetMeshName('M_1')
104   Iter_0.SetMeshFile(dircase+'/maill.01.med')
105   homard.AssociateIterHypo('Iter_0', 'Hypo_0')
106   codret = homard.Compute('Iter_0', 1)
107   #
108   # Iteration "Iter_1"
109   # ==================
110   Iter_1 = homard.CreateIteration('Iter_1', 'Iter_0')
111   Iter_1.SetMeshName('M_2')
112   Iter_1.SetMeshFile(dircase+'/maill.02.med')
113   homard.AssociateIterHypo('Iter_1', 'Hypo_1')
114   codret = homard.Compute('Iter_1', 1)
115
116 .. note::
117   Téléchargement des fichiers
118
119   * :download:`maillage initial<files/tutorial_2.00.med.gz>`
120   * :download:`commandes python<files/tutorial_2.py>`
121
122
123 Raffinement selon un champ
124 """"""""""""""""""""""""""
125 .. index:: single: champ
126
127 On procède ici au raffinement selon un champ. Les hypothèses servent à définir le nom du champ et les seuils de raffinement/déraffinement. La donnée du fichier et des instants est faite dans l'itération. Des champs sur les noeuds ou sur les mailles sont interpolés.
128 Pour adapter le maillage H_1 issu de l'itération Iter_1, deux variantes sont appliquées. Dans la première, Iter_2, le champ est un champ scalaire d'indicateurs d'erreur et on découpe les 1.5% de mailles où l'erreur est la plus grande. Dans la seconde variante, Iter_2_bis, on se base sur un champ vectoriel et on examine le saut de ce vecteur entre une maille et ses voisines : on découpera là où la norme infinie de ce saut est supérieure au seuil absolu de 0.0001.
129 ::
130
131   dircase = "/tmp"
132   #
133   # Hypothesis "Hypo_0vers1"
134   # ========================
135   Hypo_0vers1 = homard.CreateHypothesis('Hypo_0vers1')
136   Hypo_0vers1.SetAdapRefinUnRef(1, 1, 0)
137   # Characterization of the field
138   Hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
139   Hypo_0vers1.SetUseComp(0)
140   Hypo_0vers1.AddComp('ERREST          ')
141   Hypo_0vers1.SetRefinThr(3, 1.0)
142   Hypo_0vers1.SetTypeFieldInterp(2)
143   Hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
144   Hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
145   #
146   # Hypothesis "Hypo_1vers2"
147   # ========================
148   Hypo_1vers2 = homard.CreateHypothesis('Hypo_1vers2')
149   Hypo_1vers2.SetAdapRefinUnRef(1, 1, 1)
150   # Characterization of the field
151   Hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
152   Hypo_1vers2.SetUseComp(0)
153   Hypo_1vers2.AddComp('ERREST          ')
154   Hypo_1vers2.SetRefinThr(3, 1.5)
155   Hypo_1vers2.SetUnRefThr(3, 6.)
156   Hypo_1vers2.SetTypeFieldInterp(2)
157   Hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
158   Hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
159   #
160   # Hypothesis "Hypo_1vers2_bis"
161   # ============================
162   Hypo_1vers2_bis = homard.CreateHypothesis('Hypo_1vers2_bis')
163   Hypo_1vers2_bis.SetAdapRefinUnRef(1, 1, 1)
164   # Characterization of the field
165   Hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
166   Hypo_1vers2_bis.SetUseComp(1)
167   Hypo_1vers2_bis.AddComp('DX')
168   Hypo_1vers2_bis.AddComp('DY')
169   Hypo_1vers2_bis.AddComp('DZ')
170   Hypo_1vers2_bis.SetRefinThr(1, 0.0001)
171   Hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
172   Hypo_1vers2_bis.SetTypeFieldInterp(0)
173   #
174   # Case "Case_1"
175   # =============
176   Case_1 = homard.CreateCase('Case_1', 'G_0', dircase+'/tutorial_3.00.med')
177   Case_1.SetDirName(dircase)
178   #
179   # Iteration "Iter_1"
180   # ==================
181   Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name())
182   Iter_1.SetMeshName('H_1')
183   Iter_1.SetMeshFile(dircase+'/maill.01.med')
184   Iter_1.SetFieldFile(dircase+'/tutorial_3.00.med')
185   Iter_1.SetTimeStepRank( 1, 1)
186   homard.AssociateIterHypo('Iter_1', 'Hypo_0vers1')
187   codret = homard.Compute('Iter_1', 1)
188   #
189   # Iteration "Iter_2"
190   # ==================
191   Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
192   Iter_2.SetMeshName('H_2')
193   Iter_2.SetMeshFile(dircase+'/maill.02.med')
194   Iter_2.SetFieldFile(dircase+'/tutorial_3.01.med')
195   Iter_2.SetTimeStepRank(1, 1)
196   homard.AssociateIterHypo('Iter_2', 'Hypo_1vers2')
197   codret = homard.Compute('Iter_2', 1)
198   #
199   # Iteration "Iter_2_bis"
200   # ======================
201   Iter_2_bis = homard.CreateIteration('Iter_2_bis', 'Iter_1')
202   Iter_2_bis.SetMeshName('H_2_bis')
203   Iter_2_bis.SetMeshFile(dircase+'/maill.02.bis.med')
204   Iter_2_bis.SetFieldFile(dircase+'/tutorial_3.01.med')
205   Iter_2_bis.SetTimeStepRank(1, 1)
206   homard.AssociateIterHypo('Iter_2_bis', 'Hypo_1vers2_bis')
207   codret = homard.Compute('Iter_2_bis', 1)
208
209 .. note::
210   Téléchargement des fichiers
211
212   * :download:`maillage et champ étape 0<files/tutorial_3.00.med.gz>`
213   * :download:`maillage et champ étape 1<files/tutorial_3.01.med.gz>`
214   * :download:`commandes python<files/tutorial_3.py>`
215
216
217 Suivi de frontières courbes
218 """""""""""""""""""""""""""
219 .. index:: single: champ
220
221 On teste ici le suivi des frontières courbes : des frontières analytiques pour décrire les différentes surfaces des tuyaux et une frontière discrète pour décrire les lignes d'intersection des deux tuyaux. Le pilotage du raffinement est le suivant : raffinement uniforme de toutes les mailles contenues dans des groupes désignés.
222 ::
223  
224   dircase = "/tmp"
225   #
226   # Creation of the boundaries
227   # ==========================
228   Boundary_1 = homard.CreateBoundaryDi('intersection', 'PIQUAGE', dircase+'/tutorial_4.fr.med')
229   #
230   Boundary_2 = homard.CreateBoundaryCylinder('cyl_1_ext', 0.0, 25., -25., 25., 50., 75., 100.)
231   #
232   Boundary_3 = homard.CreateBoundaryCylinder('cyl_2_ext', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
233   #
234   Boundary_4 = homard.CreateBoundaryCylinder('cyl_1_int', 0.0, 25., -25., 25., 50., 75., 75.)
235   #
236   Boundary_5 = homard.CreateBoundaryCylinder('cyl_2_int', 17.5, -2.5, -12.5, -100., -75., -25., 25.)
237   #
238   # Hypothesis "Hypo"
239   # ===================
240   # Creation of the hypothesis Hypo_1
241   Hypo_1 = homard.CreateHypothesis('Hypo_1')
242   Hypo_1.SetAdapRefinUnRef(-1, 1, 0)
243   Hypo_1.AddGroup('T1_INT_I')
244   Hypo_1.AddGroup('T1_INT_O')
245   Hypo_1.AddGroup('T2_INT')
246   # Creation of the hypothesis Hypo_2
247   Hypo_2 = homard.CreateHypothesis('Hypo_2')
248   Hypo_2.SetAdapRefinUnRef(-1, 1, 0)
249   Hypo_2.AddGroup('T1_EXT_I')
250   Hypo_2.AddGroup('T1_EXT_O')
251   Hypo_2.AddGroup('T2_EXT')
252   #
253   # Case "Case"
254   # =============
255   Case = homard.CreateCase('Case', 'PIQUAGE', dircase+'/tutorial_4.00.med')
256   Case.SetDirName(dircase)
257   Case.AddBoundaryGroup( 'intersection', '' )
258   Case.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_I' )
259   Case.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_O' )
260   Case.AddBoundaryGroup( 'cyl_2_ext', 'T2_EXT' )
261   Case.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_I' )
262   Case.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_O' )
263   Case.AddBoundaryGroup( 'cyl_2_int', 'T2_INT' )
264   #
265   # Creation of the iterations
266   # ==========================
267   # Creation of the iteration Iter_1
268   Iter_1 = homard.CreateIteration('Iter_1', Case.GetIter0Name() )
269   Iter_1.SetMeshName('PIQUAGE_1')
270   Iter_1.SetMeshFile(dircase+'/maill.01.med')
271   homard.AssociateIterHypo('Iter_1', 'Hypo_1')
272   codret = homard.Compute('Iter_1', 1)
273   # Creation of the iteration Iter_2
274   Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1' )
275   Iter_2.SetMeshName('PIQUAGE_2')
276   Iter_2.SetMeshFile(dircase+'/maill.02.med')
277   homard.AssociateIterHypo('Iter_2', 'Hypo_2')
278   codret = homard.Compute('Iter_2', 1)
279
280 .. note::
281   Téléchargement des fichiers
282
283   * :download:`maillage initial<files/tutorial_4.00.med.gz>`
284   * :download:`maillage de la frontière discrète<files/tutorial_4.fr.med.gz>`
285   * :download:`commandes python<files/tutorial_4.py>`
286
287
288 Instructions spécifiques au 2D
289 """"""""""""""""""""""""""""""
290 .. index:: single: 2D
291
292 Les instructions pour adapter un maillage 2D sont exactement identiques à celles nécessaires à l'adaptation d'un maillage 3D. La seule exception concerne le raffinement selon des zones géométriques : des fonctions différentes sont utilisées pour pouvoir définir des zones 2D. On donne alors les coordonnées 2D des zones, en précisant l'orientation du plan du maillage.
293 Dans le cas présenté ici, on raffine une première fois toutes les mailles contenues dans un disque percé, puis dans une seconde itération, toutes les mailles contenues dans un rectangle. On notera l'utilisation du suivi des frontières circulaires du domaine.
294 ::
295
296   dircase = "/tmp"
297   #
298   # Creation of the boundaries
299   # ==========================
300   # Creation of the discrete boundary Boun_1
301   Boun_1 = homard.CreateBoundaryDi('Boun_1', 'MAIL_EXT', dircase+'/tutorial_5.fr.med')
302   #
303   # Creation of the zones
304   # =====================
305   # Creation of the disk with hole enveloppe
306   enveloppe = homard.CreateZoneDiskWithHole( 'enveloppe', 0., 0., 250., 193., 1 )
307   # Creation of the rectangle quart_sup
308   quart_sup = homard.CreateZoneBox2D( 'quart_sup', 0., 250., 0., 250., 1 )
309   #
310   # Hypothesis
311   # ==========
312   # Creation of the hypothesis Hypo_1
313   Hypo_1 = homard.CreateHypothesis('Hypo_1')
314   Hypo_1.SetAdapRefinUnRef(0, 1, 0)
315   homard.AssociateHypoZone('enveloppe', 'Hypo_1')
316   # Creation of the hypothesis Hypo_2
317   Hypo_2 = homard.CreateHypothesis('Hypo_2')
318   Hypo_2.SetAdapRefinUnRef(0, 1, 0)
319   homard.AssociateHypoZone('quart_sup', 'Hypo_2')
320   #
321   # Case "Case_1"
322   # =============
323   Case_1 = homard.CreateCase('Case_1', 'COEUR_2D', dircase+'/tutorial_5.00.med')
324   Case_1.SetDirName(dircase)
325   Case_1.SetConfType(3)
326   Case_1.AddBoundaryGroup('Boun_1', '')
327   #
328   # Iteration "Iter_1"
329   # ==================
330   Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name())
331   Iter_1.SetMeshName('COEUR_2D_01')
332   Iter_1.SetMeshFile(dircase+'/maill.01.med')
333   homard.AssociateIterHypo('Iter_1', 'Hypo_1')
334   codret = homard.Compute('Iter_1', 1)
335   #
336   # Iteration "Iter_2"
337   # ==================
338   Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
339   Iter_2.SetMeshName('COEUR_2D_02')
340   Iter_2.SetMeshFile(dircase+'/maill.02.med')
341   homard.AssociateIterHypo('Iter_2', 'Hypo_2')
342   result = homard.Compute('Iter_2', 1)
343
344 .. note::
345   Téléchargement des fichiers
346
347   * :download:`maillage initial<files/tutorial_5.00.med.gz>`
348   * :download:`maillage de la frontière discrète<files/tutorial_5.fr.med.gz>`
349   * :download:`commandes python<files/tutorial_5.py>`
350
351
352 .. toctree::
353    :maxdepth: 2