Salome HOME
Fix: getCellsContainingPoints() in case of polyhedron with a face containing colinear...
[tools/medcoupling.git] / src / MEDCoupling_Swig / UsersGuideExamplesTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024  CEA, EDF
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
22 import sys
23 from medcoupling import *
24 from math import pi, sqrt
25
26 # ! [PySnippetUMeshStdBuild1_1]
27 coords=[-0.3,-0.3,0.,   0.2,-0.3,0.,   0.7,-0.3,0.,   -0.3,0.2,0.,   0.2,0.2,0.,
28         0.7,0.2,0.,    -0.3,0.7,0.,    0.2,0.7,0.,     0.7,0.7,0. ]
29 nodalConnPerCell=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
30 # ! [PySnippetUMeshStdBuild1_1]
31 # ! [PySnippetUMeshStdBuild1_2]
32 mesh=MEDCouplingUMesh("My2DMesh",2)
33 # ! [PySnippetUMeshStdBuild1_2]
34 # ! [PySnippetUMeshStdBuild1_3]
35 mesh.allocateCells(5)#You can put more than 5 if you want but not less.
36 # adding cells
37 mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[:4])
38 mesh.insertNextCell(NORM_TRI3,nodalConnPerCell[4:7])
39 mesh.insertNextCell(NORM_TRI3,nodalConnPerCell[7:10])
40 mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[10:14])
41 mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[14:])
42 # compacting
43 mesh.finishInsertingCells()
44 # ! [PySnippetUMeshStdBuild1_3]
45 # ! [PySnippetUMeshStdBuild1_4]
46 coordsArr=DataArrayDouble(coords,9,3)#here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
47 mesh.setCoords(coordsArr)#coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
48 # ! [PySnippetUMeshStdBuild1_4]
49 # ! [PySnippetUMeshStdBuild1_5]
50 mesh.checkConsistencyLight()
51 # ! [PySnippetUMeshStdBuild1_5]
52
53 # ! [PySnippetCMeshStdBuild1_1]
54 XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] # 9 values along X
55 YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007] # 7 values along Y
56 arrX=DataArrayDouble(XCoords)
57 arrX.setInfoOnComponent(0,"X [m]")
58 arrY=DataArrayDouble(YCoords)
59 arrY.setInfoOnComponent(0,"Y [m]")
60 # ! [PySnippetCMeshStdBuild1_1]
61 # ! [PySnippetCMeshStdBuild1_2]
62 mesh=MEDCouplingCMesh("My2D_CMesh")
63 mesh.setCoords(arrX,arrY)
64 # ! [PySnippetCMeshStdBuild1_2]
65
66 nodalConnPerCell=list(range(4*4))
67 # ! [GU_MEDCoupling1SGTUMesh_0]
68 mesh=MEDCoupling1SGTUMesh("myQuadMesh",NORM_QUAD4)
69 mesh.allocateCells(3)
70 mesh.insertNextCell(nodalConnPerCell[:4])
71 mesh.insertNextCell(nodalConnPerCell[4:8])
72 mesh.insertNextCell(nodalConnPerCell[8:12])
73 # ! [GU_MEDCoupling1SGTUMesh_0]
74
75 # ! [GU_MEDCoupling1SGTUMesh_1]
76 polymesh=MEDCoupling1DGTUMesh("myPolyhedra",NORM_POLYHED)
77 polymesh.allocateCells(1)
78 polymesh.insertNextCell([0,1,2,3,-1,7,6,5,4,-1,0,4,5,1,-1,1,5,6,2,-1,3,2,6,7,-1,0,3,7,4])
79 # ! [GU_MEDCoupling1SGTUMesh_1]
80
81 #! [UG_DataArrayDouble_0]
82 d=DataArrayDouble([1,2,3,4,5,6],3,2)
83 #! [UG_DataArrayDouble_0]
84 #! [UG_DataArrayDouble_1]
85 d=DataArrayDouble([(1,2),(3,4),(5,6)])
86 #! [UG_DataArrayDouble_1]
87 #! [UG_DataArrayDouble_2]
88 d=DataArrayDouble([(1,2,3),(4,5,6)])
89 #! [UG_DataArrayDouble_2]
90 #! [UG_DataArrayDouble_3]
91 d.rearrange(2)
92 #! [UG_DataArrayDouble_3]
93 #! [UG_DataArrayDouble_4]
94 i=DataArrayInt([(1,2,3),(4,5,6)])
95 f=DataArrayFloat([(1,2,3),(4,5,6)])
96 #! [UG_DataArrayDouble_4]
97
98 #! [UG_MEDCouplingCurveLinearMesh_0]
99 m=MEDCouplingCurveLinearMesh("myCurveLinearMesh")
100 m.setNodeGridStructure([2,3])
101 #! [UG_MEDCouplingCurveLinearMesh_0]
102 #! [UG_MEDCouplingCurveLinearMesh_1]
103 coords=DataArrayDouble([0.,0., 2.,0., 0.,1., 1.9,1.1, 0.3,1.9, 2.2,2.1],6,2)
104 coords.setInfoOnComponents(["X [m]","Y [m]"])
105 m.setCoords(coords)
106 #! [UG_MEDCouplingCurveLinearMesh_1]
107 #! [UG_MEDCouplingCurveLinearMesh_2]
108 m.checkConsistencyLight()
109 #! [UG_MEDCouplingCurveLinearMesh_2]
110
111 XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22];  arrX=DataArrayDouble(XCoords)
112 YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007];  arrY=DataArrayDouble(YCoords)
113 mesh=MEDCouplingCMesh("My2D_CMesh")
114 mesh.setCoords(arrX,arrY)
115 #! [UG_MEDCouplingFieldDouble_0]
116 fieldOnCells=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
117 fieldOnCells.setName("MyTensorFieldOnCellOneTime")
118 fieldOnCells.setMesh(mesh)
119 #! [UG_MEDCouplingFieldDouble_0]
120 #! [UG_MEDCouplingFieldDouble_1]
121 fieldOnCells.setTimeUnit("ms") # Time unit is ms.
122 fieldOnCells.setTime(4.22,2,-1) # Time attached is 4.22 ms, iteration id is 2 and order id (or sub iteration id) is -1
123 #! [UG_MEDCouplingFieldDouble_1]
124 #! [UG_MEDCouplingFieldDouble_2]
125 array=DataArrayDouble()
126 array.alloc(fieldOnCells.getMesh().getNumberOfCells(),2) # Implicitly fieldOnCells will be a 2 components field.
127 array.fillWithValue(7.)
128 fieldOnCells.setArray(array)
129 fieldOnCells.checkConsistencyLight()
130 # fieldOnCells is now usable
131 # ...
132 #! [UG_MEDCouplingFieldDouble_2]
133 #
134 #! [UG_MEDCouplingFieldDouble_3]
135 fieldOnNodes=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
136 fieldOnNodes.setName("MyScalarFieldOnNodeOneTime")
137 fieldOnNodes.setMesh(mesh)
138 fieldOnNodes.setTimeUnit("ms") # Time unit is ms.
139 fieldOnNodes.setTime(4.22,2,-1) # Time attached is 4.22 ms, iteration id is 2 and order id (or sub iteration id) is -1
140 array=DataArrayDouble()
141 array.alloc(fieldOnNodes.getMesh().getNumberOfNodes(),1) # Implicitly fieldOnNodes will be a 1 component field.
142 array.fillWithValue(7.)
143 fieldOnNodes.setArray(array)
144 fieldOnNodes.checkConsistencyLight()
145 # fieldOnNodes is now usable
146 # ...
147 #! [UG_MEDCouplingFieldDouble_3]
148 field=fieldOnCells
149 #! [UG_MEDCouplingFieldDouble_4]
150 print(mesh.getHeapMemorySizeStr())
151 print(field.getHeapMemorySizeStr())
152 print(array.getHeapMemorySizeStr())
153 #! [UG_MEDCouplingFieldDouble_4]
154
155 f=fieldOnCells
156 nbComp=3
157 val=5.
158 #! [UG_MEDCouplingFieldDouble_5]
159 f.applyFunc(nbComp,val)
160 #! [UG_MEDCouplingFieldDouble_5]
161 #! [UG_MEDCouplingFieldDouble_6]
162 f.applyFunc(1,"sqrt(X*X+Y*Y+Z*Z)")
163 #! [UG_MEDCouplingFieldDouble_6]
164 f.applyFunc(nbComp,val)
165 #! [UG_MEDCouplingFieldDouble_7]
166 f.applyFunc(4,"IVec*y+JVec*x+KVec*z+LVec*sqrt(x*x+y*y+z*z)")
167 #! [UG_MEDCouplingFieldDouble_7]
168
169 field=fieldOnCells
170 #! [UG_MEDCouplingFieldDouble_8]
171 points=DataArrayDouble([(0.,0.),(1,1)])
172 values=field.getValueOnMulti(points)
173 #! [UG_MEDCouplingFieldDouble_8]
174 #! [UG_MEDCouplingFieldDouble_9]
175 field.integral(True)
176 field.integral(0,True)
177 #! [UG_MEDCouplingFieldDouble_9]
178 field.applyFunc(6,1.)
179 #! [UG_MEDCouplingFieldDouble_10]
180 assert(field.getNumberOfComponents()==6)
181 diviatorfield=field.deviator()
182 #! [UG_MEDCouplingFieldDouble_10]
183
184
185 from MEDCouplingDataForTest import MEDCouplingDataForTest
186 mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
187 #! [UG_MEDCouplingGaussPointField_0]
188 fieldGauss=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
189 fieldGauss.setMesh(mesh);
190 fieldGauss.setName("MyFirstFieldOnGaussPoint");
191 fieldGauss.setTimeUnit("ms") # Time unit is ms.
192 fieldGauss.setTime(4.22,2,-1) # Time attached is 4.22 ms, iteration id is 2 and order id (or sub iteration id) is -1
193 #! [UG_MEDCouplingGaussPointField_0]
194 #! [UG_MEDCouplingGaussPointField_1]
195 tria3CooRef=[ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 ]
196 tria3CooGauss=[ 0.1, 0.8, 0.2, 0.7 ]
197 wg3=[0.3,0.3];
198 fieldGauss.setGaussLocalizationOnType(NORM_TRI3,tria3CooRef,tria3CooGauss,wg3);
199 #
200 quad4CooRef=[-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0]
201 quad4CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 ]
202 wg4=[0.3,0.3,0.3,0.3];
203 fieldGauss.setGaussLocalizationOnType(NORM_QUAD4,quad4CooRef,quad4CooGauss,wg4);
204 #! [UG_MEDCouplingGaussPointField_1]
205 #! [UG_MEDCouplingGaussPointField_2]
206 nbTuples=mesh.getNumberOfCellsWithType(NORM_TRI3)*len(wg3)+mesh.getNumberOfCellsWithType(NORM_QUAD4)*len(wg4)
207 array=DataArrayDouble.New();
208 values=[float(i+1) for i in range(nbTuples)]
209 array.setValues(values,nbTuples,1);
210 fieldGauss.setArray(array);
211 fieldGauss.checkConsistencyLight();
212 #! [UG_MEDCouplingGaussPointField_2]
213
214 from MEDCouplingDataForTest import MEDCouplingDataForTest
215 m=MEDCouplingDataForTest.build2DTargetMesh_1();
216 Ids=list(range(1,3))
217 #! [UG_ExtractForMeshes_0]
218 part=m[Ids]
219 #! [UG_ExtractForMeshes_0]
220 #! [UG_ExtractForMeshes_1]
221 subNodeIds=part.computeFetchedNodeIds()
222 #! [UG_ExtractForMeshes_1]
223 #! [UG_ExtractForMeshes_2]
224 m.getCoords()[subNodeIds]
225 #! [UG_ExtractForMeshes_2]
226 #! [UG_ExtractForMeshes_3]
227 part.zipCoords()
228 #! [UG_ExtractForMeshes_3]
229 #! [UG_ExtractForMeshes_4]
230 o2n=part.zipCoordsTraducer()
231 #! [UG_ExtractForMeshes_4]
232
233 m2=MEDCouplingDataForTest.build3DExtrudedUMesh_1()[0]
234 #! [UG_ExtractForMeshes_5]
235 bn = m2.findBoundaryNodes()
236 #! [UG_ExtractForMeshes_5]
237 #! [UG_ExtractForMeshes_6]
238 bc = m2.getCellIdsLyingOnNodes(bn,False)
239 #! [UG_ExtractForMeshes_6]
240
241 #! [UG_ExtractForMeshes_7]
242 m2.translate([1.,2.,3.])
243 #! [UG_ExtractForMeshes_7]
244 #! [UG_ExtractForMeshes_8]
245 m2.getCoords()[:]+=DataArrayDouble([1.,2.,3.],1,3)
246 #! [UG_ExtractForMeshes_8]
247 import math
248 #! [UG_ExtractForMeshes_9]
249 m2.rotate([1,2,1],[0,1,0],math.pi/3)
250 #! [UG_ExtractForMeshes_9]
251 #! [UG_ExtractForMeshes_10]
252 MEDCouplingPointSet.Rotate3DAlg([1,2,1],[0,1,0],math.pi/3,m2.getCoords())
253 #! [UG_ExtractForMeshes_10]
254
255 #! [UG_ExtractForMeshes_11]
256 volPerCell=m2.getMeasureField(True)
257 #! [UG_ExtractForMeshes_11]
258 #! [UG_ExtractForMeshes_12]
259 volPerCell.getArray().accumulate()
260 #! [UG_ExtractForMeshes_12]
261 t1=-1
262 #! [UG_ExtractForMeshes_13]
263 part=volPerCell.getArray().findIdsGreaterOrEqualTo(t1)
264 #! [UG_ExtractForMeshes_13]
265 #! [UG_ExtractForMeshes_14]
266 m2[part]
267 #! [UG_ExtractForMeshes_14]
268 #! [UG_ExtractForMeshes_15]
269 centers=m2.computeCellCenterOfMass()
270 #! [UG_ExtractForMeshes_15]
271 #! [UG_ExtractForMeshes_16]
272 (centers*volPerCell.getArray()).accumulate()/DataArrayDouble(volPerCell.accumulate())
273 #! [UG_ExtractForMeshes_16]
274
275 #! [UG_ExtractForMeshes_17]
276 m2.scale( [1,2,4], 6. )
277 #! [UG_ExtractForMeshes_17]
278
279 #! [UG_ExtractForMeshes_18]
280 ortho_field=m.buildOrthogonalField()
281 #! [UG_ExtractForMeshes_18]
282
283 #! [UG_ExtractForMeshes_19]
284 ibc=m2.computeIsoBarycenterOfNodesPerCell()
285 #! [UG_ExtractForMeshes_19]
286
287 #! [UG_ExtractForMeshes_20]
288 # make a structured mesh 1x5
289 coords=DataArrayDouble(list(range(6)))
290 cmesh=MEDCouplingCMesh("cmesh")
291 cmesh.setCoords(coords,coords[:2])
292
293 # make a mesh with two zones
294 zmesh=cmesh.buildUnstructured()[0,1,3,4]
295
296 # get cells ids of zones
297 zoneArrays=zmesh.partitionBySpreadZone()
298 print([ ids.getValues() for ids in zoneArrays])
299 #! [UG_ExtractForMeshes_20]
300
301 coordsArr=DataArrayDouble(list(range(6)))
302 mesh2d=MEDCouplingCMesh("mesh2d")
303 mesh2d.setCoords(coordsArr,coordsArr[:2])
304 mesh2d=mesh2d.buildUnstructured()
305 mesh1d=MEDCouplingCMesh("mesh1d")
306 mesh1d.setCoords(coordsArr,coordsArr[:1])
307 mesh1d=mesh1d.buildUnstructured()
308 mesh1d.rotate( [2.3,0], math.radians( 25 ))
309 mesh1d.translate( [0.2,0.4] )
310 #! [UG_ExtractForMeshes_21]
311 m2d,m1d,a2d,a1d=MEDCouplingUMesh.Intersect2DMeshWith1DLine( mesh2d, mesh1d, 1e-12 )
312 #! [UG_ExtractForMeshes_21]
313 #print ("a2d",a2d.getValues())
314 #print (a1d.getValues())
315
316 mesh1=mesh2d.deepCopy()
317 mesh1.rotate( [2.3,0], math.radians( 25 ))
318 mesh2=mesh2d
319 #! [UG_ExtractForMeshes_22]
320 m,a1,a2=MEDCouplingUMesh.Intersect2DMeshes( mesh1, mesh2, 1e-12 )
321 #! [UG_ExtractForMeshes_22]
322
323
324 points=DataArrayDouble([(0,0,0)])
325 mesh=m2.computeSkin()
326 #! [UG_ExtractForMeshes_23]
327 dist,cells=mesh.distanceToPoints(points)
328 #! [UG_ExtractForMeshes_23]
329
330 arr=DataArrayDouble([1,2,3,4,5,6],3,2)
331 a,b=2,5
332 #! [UG_ExtractForArrays_0]
333 tupleIds = arr[:,0].findIdsInRange(a,b)
334 #! [UG_ExtractForArrays_0]
335 c,d=0,7
336 #! [UG_ExtractForArrays_1]
337 tupleIds1 = arr.magnitude().findIdsInRange(c,d)
338 #! [UG_ExtractForArrays_1]
339 #! [UG_ExtractForArrays_2]
340 tupleIds2 = DataArrayInt.buildSubstraction(tupleIds,tupleIds1)
341 #! [UG_ExtractForArrays_2]
342
343 valsArr1=DataArrayDouble(list(range(9*2)),9,2)
344 field4 = MEDCouplingFieldDouble(ON_NODES)
345 field4.setArray(valsArr1)
346 mesh=MEDCouplingCMesh("My2D_CMesh")
347 coo=DataArrayDouble([0,1,2])
348 mesh.setCoords(coo,coo)
349 field4.setMesh(mesh)
350 ids4=[1,2]
351 #! [UG_ExtractForFields_0]
352 subField = field4[ids4]
353 #! [UG_ExtractForFields_0]
354
355 m4=MEDCouplingCMesh("box")
356 coo=DataArrayDouble(list(range(7)))
357 m4.setCoords(coo[:5],coo[:5],coo)
358 m4=m4.buildUnstructured()
359 valsArr1=m4.computeCellCenterOfMass()
360 valsArr1.applyFunc(1,"sqrt(X*X+Y*Y+Z*Z)")
361 field5 = MEDCouplingFieldDouble(ON_CELLS)
362 field5.setArray(valsArr1)
363 field5.setMesh(m4)
364 #! [UG_ExtractForFields_1]
365 origin=[0,0,2]
366 normvec=[-1,-1,6]
367 slice5=field5.extractSlice3D(origin,normvec,1e-10)
368 #! [UG_ExtractForFields_1]
369
370 from MEDCouplingDataForTest import MEDCouplingDataForTest
371 m1=MEDCouplingDataForTest.build2DTargetMesh_1();
372 m2=m1
373 eps=1e-12
374 #! [UG_MeshComparison_0]
375 m1.isEqual(m2,eps)
376 #! [UG_MeshComparison_0]
377 #! [UG_MeshComparison_1]
378 m1.isEqualWithoutConsideringStr(m2,eps)
379 #! [UG_MeshComparison_1]
380
381 arr=DataArrayDouble(5) ; arr.iota()
382 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
383 m=m.buildUnstructured()
384 m1=m.deepCopy()
385 arr=DataArrayInt([0,3,1,4,2])
386 m2=m1[arr]
387 #! [UG_MeshComparison_2]
388 a,_=m1.checkGeoEquivalWith(m2,20,1e-12)
389 assert(m1[a].isEqualWithoutConsideringStr(m2,1e-12))
390 #! [UG_MeshComparison_2]
391 m3=m1
392 m3.translate([100.,0])
393 m1=MEDCouplingUMesh.MergeUMeshes([m3,m])
394 m2=MEDCouplingUMesh.MergeUMeshes([m,m3])
395 #! [UG_MeshComparison_3]
396 a,b=m1.checkGeoEquivalWith(m2,12,1e-12)
397 m2.renumberNodes(b,len(b))
398 assert(m1[a].isEqualWithoutConsideringStr(m2,1e-12))
399 #! [UG_MeshComparison_3]
400
401
402 coords = [0.,2.,4.]
403 coordsArr=DataArrayDouble(coords,3,1)
404 m4=MEDCouplingCMesh()
405 m4.setCoords(coordsArr,coordsArr,coordsArr)
406 m4=m4.buildUnstructured()
407 field1 = m4.fillFromAnalytic(ON_NODES,1,"x+y")
408 pts = [0.5,0.5,0.5,1.,1,1.]
409 #! [UG_CommonHandlingMesh_0]
410 assert(field1.getTypeOfField()==ON_NODES)
411 field1.getMesh().simplexize(PLANAR_FACE_5)
412 field1.getValueOnMulti(pts)
413 #! [UG_CommonHandlingMesh_0]
414
415 from MEDCouplingDataForTest import MEDCouplingDataForTest
416 m2=MEDCouplingDataForTest.build2DTargetMesh_1();
417 m2.changeSpaceDimension(3);
418 m1=MEDCouplingDataForTest.buildCU1DMesh_U();
419 m1.changeSpaceDimension(3);
420 center=[0.,0.,0.]
421 vector=[0.,1.,0.]
422 m1.rotate(center,vector,-pi/2.);
423 #! [UG_CommonHandlingMesh_1]
424 m3=m2.buildExtrudedMesh(m1,0);
425 #! [UG_CommonHandlingMesh_1]
426
427 #! [UG_CommonHandlingMesh_2]
428 m5=MEDCouplingUMesh.MergeUMeshes([m3,m4])
429 #! [UG_CommonHandlingMesh_2]
430
431 #! [UG_CommonHandlingMesh_3]
432 m1.convertLinearCellsToQuadratic(0)
433 #! [UG_CommonHandlingMesh_3]
434
435 #! [UG_CommonHandlingMesh_4]
436 skin = m1.computeSkin()
437 #! [UG_CommonHandlingMesh_4]
438 #! [UG_CommonHandlingMesh_5]
439 #bc = m1.getCellIdsLyingOnNodes(bn,False)
440 #! [UG_CommonHandlingMesh_5]
441
442 mesh3d=m3
443 #! [UG_CommonHandlingMesh_6]
444 mesh1d,d,di,r,ri=mesh3d.explodeIntoEdges()
445 #! [UG_CommonHandlingMesh_6]
446 #! [UG_CommonHandlingMesh_7]
447 mesh2d,d,di,r,ri=mesh3d.buildDescendingConnectivity()
448 #! [UG_CommonHandlingMesh_7]
449
450 mesh2d=MEDCouplingCMesh()
451 mesh2d.setCoords(coordsArr,coordsArr)
452 mesh2d=mesh2d.buildUnstructured()
453 eps=1e-12
454 #! [UG_CommonHandlingMesh_8]
455 changedCells=mesh2d.conformize2D(eps)
456 #! [UG_CommonHandlingMesh_8]
457
458 #! [UG_CommonHandlingMesh_9]
459 mesh2d.duplicateNodes([3,4])
460 #! [UG_CommonHandlingMesh_9]
461
462 m1d=MEDCouplingCMesh()
463 m1d.setCoords(coordsArr)
464 m1d=m1d.buildUnstructured()
465 #! [UG_CommonHandlingMesh_10]
466 m1d.renumberCells(m1d.orderConsecutiveCells1D().invertArrayN2O2O2N(m1d.getNumberOfCells()))
467 #! [UG_CommonHandlingMesh_10]
468
469 skin=m3.computeSkin()
470 #! [UG_CommonHandlingMesh_11]
471 vec=[0,0,-1]
472 skin.orientCorrectly2DCells(vec,False)
473 #! [UG_CommonHandlingMesh_11]
474
475 #! [UG_CommonHandlingMesh_11_1]
476 skin.orientCorrectly2DCells( None )
477 #! [UG_CommonHandlingMesh_11_1]
478
479 #! [UG_CommonHandlingMesh_11_2]
480 refCells = [ 0,2,4 ]
481 objCells = [ 1,3,5,6,7,8, 20 ]
482 refGroup = skin.buildPartOfMySelf( refCells )
483 objGroup = skin.buildPartOfMySelf( objCells )
484 objGroup.orientCorrectly2DCells( refGroup )
485 skin.setPartOfMySelf( objCells, objGroup )
486 #! [UG_CommonHandlingMesh_11_2]
487
488 #! [UG_CommonHandlingMesh_12]
489 m3.orientCorrectlyPolyhedrons()
490 #! [UG_CommonHandlingMesh_12]
491
492 #! [UG_CommonHandlingMesh_13]
493 m3.renumberCells(m3.rearrange2ConsecutiveCellTypes())
494 m3.sortCellsInMEDFileFrmt()
495 #! [UG_CommonHandlingMesh_13]
496
497 m=MEDCouplingCMesh()
498 m.setCoords(coordsArr[:2],coordsArr[:2])
499 m=m.buildUnstructured()
500 #! [UG_CommonHandlingMesh_14]
501 m.renumberNodes([2,1,0,-1],3)
502 #! [UG_CommonHandlingMesh_14]
503
504 #! [UG_CommonHandlingMesh_15]
505 mtet,n2ocells,np=m3.tetrahedrize(PLANAR_FACE_5)
506 #! [UG_CommonHandlingMesh_15]
507 #! [UG_CommonHandlingMesh_16]
508 m.mergeNodes(1e-12)
509 #! [UG_CommonHandlingMesh_16]
510
511
512 #! [UG_Projection_0]
513 srcCoo=DataArrayDouble([(0,0),(1,0),(3,0),(0,1),(1,1),(3,1)])
514 src=MEDCouplingUMesh("src",2)
515 src.setCoords(srcCoo)
516 src.allocateCells()
517 src.insertNextCell(NORM_QUAD4,[0,3,4,1])
518 src.insertNextCell(NORM_QUAD4,[1,4,5,2])
519 #
520 trgCoo=DataArrayDouble([(0.5,0.5),(1.5,0.5),(1.5,1.5)])
521 trg=MEDCouplingUMesh("trg",2)
522 trg.setCoords(trgCoo)
523 trg.allocateCells()
524 trg.insertNextCell(NORM_TRI3,[0,2,1])
525 #! [UG_Projection_0]
526 from MEDCouplingRemapper import MEDCouplingRemapper
527 #! [UG_Projection_1]
528 rem=MEDCouplingRemapper()
529 rem.prepare(src,trg,"P0P0")
530 print(rem.getCrudeMatrix())
531 #! [UG_Projection_1]
532 #! [UG_Projection_2]
533 srcF=MEDCouplingFieldDouble(ON_CELLS)
534 srcF.setMesh(src)
535 srcF.setArray(DataArrayDouble([3,4]))
536 srcF.setNature(IntensiveMaximum)
537 #
538 trgF=rem.transferField(srcF,-1)
539 #! [UG_Projection_2]
540 #! [UG_Projection_3]
541 rem=MEDCouplingRemapper()
542 rem.prepare(src,trg,"P0P1")
543 print(rem.getCrudeMatrix())
544 #! [UG_Projection_3]
545 #! [UG_Projection_4]
546 rem=MEDCouplingRemapper()
547 rem.prepare(src,trg,"P1P0")
548 print(rem.getCrudeMatrix())
549 #! [UG_Projection_4]
550
551
552 #! [UG_Projection_5]
553 coo=DataArrayDouble([(0.,0.,0.), (1,0,0), (0,1,0)])
554 src=MEDCouplingUMesh("src",2)
555 src.setCoords(coo)
556 src.allocateCells(1)
557 src.insertNextCell(NORM_TRI3,[0,1,2])
558 tgt = src.deepCopy()
559 rem=MEDCouplingRemapper()
560 rem.prepare(src,tgt,"P0P0")
561 print(rem.getCrudeMatrix())
562 #! [UG_Projection_5]
563 #! [UG_Projection_6]
564 src.translate([0,0,1e-3])
565 rem.prepare(src,tgt,"P0P0")
566 print(rem.getCrudeMatrix())
567 #! [UG_Projection_6]
568 #! [UG_Projection_7]
569 rem.setBoundingBoxAdjustmentAbs( 1e-3 )
570 rem.prepare(src,tgt,"P0P0")
571 print(rem.getCrudeMatrix())
572 #! [UG_Projection_7]
573
574 import math
575 #! [UG_Projection_8]
576 src.rotate([0,0,0],[0,1,0],math.pi/4)
577 rem.prepare(src,tgt,"P0P0")
578 print(rem.getCrudeMatrix())
579 #! [UG_Projection_8]
580 #! [UG_Projection_9]
581 rem.setMaxDistance3DSurfIntersect( 0.1 )
582 rem.prepare(src,tgt,"P0P0")
583 print(rem.getCrudeMatrix())
584 #! [UG_Projection_9]
585
586 #! [UG_Projection_10]
587 rem.setMaxDistance3DSurfIntersect( -1 ) # switch it off
588 rem.setMinDotBtwPlane3DSurfIntersect( 0.8 )
589 rem.prepare(src,tgt,"P0P0")
590 print(rem.getCrudeMatrix())
591 #! [UG_Projection_10]