Salome HOME
Merge branch 'master' into gdd/python3_dev
[modules/med.git] / doc / tut / medcoupling / partition.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # This illustrates how to make a mesh partition using the value of a
22 # field defined on this mesh (for example to extract the cells where
23 # the field takes a value greater than a threshold L.
24 # (Anthony Geay, nov. 2012)
25
26 # WRN: this use case does not require a med input file because the
27 # data (mesh and field) to work with are created from scratch. 
28
29 from MEDCoupling import *
30
31 # =======================================================
32 # Creation of the input data (mesh and field) 
33 # =======================================================
34 #
35 # We prepare the input field from scratch instead of load it from a
36 # file, but there is no difference
37 from MEDCouplingDataForTest import MEDCouplingDataForTest
38 m3D=MEDCouplingDataForTest.build3DTargetMesh_1()
39 m3D.setName("m3D")
40 a=DataArrayDouble.New([1.,1.,1.,-1.,-1.,-1.,-1.,-1.])
41 field=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
42 field.setMesh(m3D)
43 field.setArray(a)
44 field.checkConsistencyLight()
45 field.setName("f")
46
47 # Save the field (and associated mesh) 
48 from MEDLoader import MEDLoader
49 MEDLoader.WriteField("partition_input.med",field,True)
50
51 # =======================================================
52 # Determine the border skin mesh
53 # =======================================================
54 #
55 # We have to determine the 2D mesh that delimits the volume where the
56 # field is greater than a threshold L from the volume where the field
57 # is lower than this threshold (in this example L=0).
58 #
59 # WRN: This works in SALOME V660 only
60 #
61 # _T1A
62 L=0.
63 arr = field.getArray()
64 ids = arr.findIdsInRange(L,1e300)
65 m3DSub = field.getMesh()[ids]
66 skin = m3DSub.computeSkin()
67 MEDLoader.WriteUMesh("partition_skin.med",skin,True);
68 # _T1B
69
70 # =======================================================
71 # Compare to the result in SALOME V650
72 # =======================================================
73 # SALOME V650 requires a more complicated syntax.
74 m2D,desc,descI,revDesc,revDescI=m3DSub.buildDescendingConnectivity()
75 numberOf3DVolSharing=revDescI.deltaShiftIndex()
76 ids2D=numberOf3DVolSharing.findIdsEqual(1)
77 skin_V650=m2D[ids2D]
78 # We can check if the two skins are identical
79 print("Are two meshes equal between V660 and V650 ?",skin.isEqual(skin_V650,1e-12))