From: karadaniz Date: Mon, 4 Mar 2024 12:56:46 +0000 (+0100) Subject: [spns#34841] Intersect2DMeshWith1DLine: Add test-case X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fspns_34841_intersect2DMeshWith1DLine;p=tools%2Fmedcoupling.git [spns#34841] Intersect2DMeshWith1DLine: Add test-case --- diff --git a/src/MEDCoupling_Swig/MEDCoupling2DInsterct1DCrossedLines.py b/src/MEDCoupling_Swig/MEDCoupling2DInsterct1DCrossedLines.py new file mode 100644 index 000000000..558682f2a --- /dev/null +++ b/src/MEDCoupling_Swig/MEDCoupling2DInsterct1DCrossedLines.py @@ -0,0 +1,73 @@ +import os +import numpy as np +import medcoupling as mc +import MEDLoader as ml + +SPNS_34841_ROOT_DIR='/tmp' + +def buildMesh2D(): + targetMesh = ml.MEDCouplingUMesh("MyMesh2D",2) + targetMesh.allocateCells(1) + targetCoords = [0., 0., 1., 0., 1., 1., 0., 1.] + myCoords = ml.DataArrayDouble(targetCoords, 4,2) + myCoords.setInfoOnComponents(["X","Y"]) + + targetMesh.setCoords(myCoords) + targetMesh.insertNextCell(ml.NORM_QUAD4,[ 0, 1, 2, 3]) + targetMesh.finishInsertingCells() + targetMesh.checkConsistency() + + meshMEDFile = ml.MEDFileUMesh() + meshMEDFile.setMeshAtLevel(0,targetMesh) + meshMEDFile.write(os.path.join(SPNS_34841_ROOT_DIR,'SingleMesh2D.med'),2) + return targetMesh + +def buildMesh1D(): + targetMesh = ml.MEDCouplingUMesh.New() + targetMesh.setName("MyMesh1D") + targetMesh.setMeshDimension(1) + targetMesh.allocateCells(5) + targetCoords = np.arange(6*2, dtype=float) + + # first horizontal edge + targetCoords[0]= float( 0.); targetCoords[1]= float( 0.5); #0 + targetCoords[2]= float( 0.5); targetCoords[3]= float( 0.5); #1 + targetMesh.insertNextCell(ml.NORM_SEG2,2, [0, 1]) + # second horizontal edge + targetCoords[4]= float( 1.); targetCoords[5]= float( 0.5); #2 + targetMesh.insertNextCell(ml.NORM_SEG2,2, [1, 2]) + # first vertical edge + targetCoords[6]= float( 0.5); targetCoords[7]= float( 1.); #3 + targetMesh.insertNextCell(ml.NORM_SEG2,2, [3, 1]) + # second vertical edge + targetCoords[8]= float( 0.5); targetCoords[9]= float( 0.0); #4 + targetMesh.insertNextCell(ml.NORM_SEG2,2, [1, 4]) + # third vertical edge + targetCoords[10]= float( 0.5); targetCoords[11]= float( 0.); #5 + targetMesh.insertNextCell(ml.NORM_SEG2,2, [1, 5]) + # finish + targetMesh.finishInsertingCells() + + myCoords = ml.DataArrayDouble(targetCoords.tolist(), 6,2) + myCoords.setInfoOnComponents(["X","Y"]) + targetMesh.setCoords(myCoords) + targetMesh.checkConsistency() + meshMEDFile = ml.MEDFileUMesh() + meshMEDFile.setMeshAtLevel(0,targetMesh) + meshMEDFile.write(os.path.join(SPNS_34841_ROOT_DIR,'Single_Mesh1D.med'),2) + return targetMesh + +if __name__ == '__main__': + + single2DMesh = buildMesh2D() + single1DMesh = buildMesh1D() + + meshMEDFile = ml.MEDFileUMesh() + meshMEDFile.setMeshAtLevel(0,single1DMesh) + meshMEDFile.write(os.path.join(SPNS_34841_ROOT_DIR,'reduced_1D.med'),2) + + # INTERSECTION + partition, _, _, _ = mc.MEDCouplingUMesh.Intersect2DMeshWith1DLine(single2DMesh, single1DMesh, 1e-8) + meshMEDFile = ml.MEDFileUMesh() + meshMEDFile.setMeshAtLevel(0,partition) + meshMEDFile.write(os.path.join(SPNS_34841_ROOT_DIR,'reduced_partition.med'),2) \ No newline at end of file