Salome HOME
640e6b7bf91768b466c14d8bbc063831234f13b0
[tools/medcoupling.git] / src / RENUMBER_Swig / UsersGuideExamplesTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020  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 import sys
22
23 if sys.platform == "win32":
24     from MEDCouplingCompat import *
25 else:
26     from medcoupling import *
27
28 from math import pi, sqrt
29
30 if sys.platform == "win32":
31     import MEDCouplingCompat as MEDCoupling
32 else:
33     import MEDCoupling
34     
35 def build2DTargetMesh_1():
36     targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
37     targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
38     targetMesh=MEDCouplingUMesh.New();
39     targetMesh.setMeshDimension(2);
40     targetMesh.allocateCells(5);
41     targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
42     targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
43     targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
44     targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
45     targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
46     targetMesh.finishInsertingCells();
47     myCoords=DataArrayDouble.New();
48     myCoords.setValues(targetCoords,9,2);
49     targetMesh.setCoords(myCoords);
50     return targetMesh;
51
52     
53 m=build2DTargetMesh_1()
54 #! [UG_Optimization_0]
55 from MEDRenumber import RenumberingFactory
56 ren=RenumberingFactory("BOOST")
57 a,b=m.computeNeighborsOfCells()
58 n2o,_=ren.renumber(a,b)
59 mrenum=m[n2o]
60 #! [UG_Optimization_0]
61
62 #! [UG_Optimization_1]
63 import MEDPartitioner
64 # prepare a MEDPartitioner
65 a,b=m.computeNeighborsOfCells()
66 sk=MEDCouplingSkyLineArray(b,a)
67 g=MEDPartitioner.MEDPartitioner.Graph(sk)
68 # compute partitioning into 4 parts
69 g.partGraph(4)
70 # get the 1st of parts of m
71 procIdOnCells=g.getPartition().getValuesArray()
72 p0=procIdOnCells.findIdsEqual(0)
73 part0=m[p0]
74 #! [UG_Optimization_1]
75 #! [UG_Optimization_2]
76 boundary_nodes_part0=part0.findBoundaryNodes()
77 boundary_cells_part0=p0[part0.getCellIdsLyingOnNodes(boundary_nodes_part0,False)]
78 # starting from knowledge of neighborhood it s possible to know the neighbors of boundary_cells_part0
79 neighbors_boundary_cells_part0=MEDCouplingUMesh.ExtractFromIndexedArrays(boundary_cells_part0,a,b)[0]
80 neighbors_boundary_cells_part0.sort()
81 neighbors_boundary_cells_part0=neighbors_boundary_cells_part0.buildUnique()
82 #
83 layer_of_part0=neighbors_boundary_cells_part0.buildSubstraction(p0)
84 #
85 whole_part_with_layer=DataArrayInt.Aggregate([p0,layer_of_part0])
86 whole_part_with_layer.sort()
87 part0_with_layer=m[whole_part_with_layer]
88 #! [UG_Optimization_2]
89