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