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