# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-from MEDCoupling import *
+
+import sys
+if sys.platform == "win32":
+ from MEDCouplingCompat import *
+else:
+ from MEDCoupling import *
import unittest
from math import pi,e,sqrt,cos,sin
from datetime import datetime
self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-12))
self.assertEqual(e1, mapResToInit.getValues())
self.assertEqual(e2, mapResToRef.getValues())
+ pass
def testIntersect2DMeshes8(self):
""" Quadratic precision values were improperly reset before testing colinearities
self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
self.assertEqual(e1, mapResToInit.getValues())
self.assertEqual(e2, mapResToRef.getValues())
+ pass
+
+ def testIntersect2DMeshes9(self):
+ """ Last part of the intersection algorithm was not properly dealing with residual cells when
+ it was a quad polygon just made of 2 edges. Was throwing an exception. """
+ eps = 1e-6
+ back = MEDCouplingUMesh('crh7_rse1', 2)
+ coo = DataArrayDouble([(71.6187499999999915,-10.6521000000000008),(71.0937370510802538,-12.6114750000000022),(71.4852218317702608,-11.6663471329955062),(72.0541666666666600,-10.6521000000000008),(71.8364583333333258,-10.6521000000000008),(71.4708189456447371,-12.8291833333333365),(71.2822779983625026,-12.7203291666666694),(71.9058020353005816,-11.7790412588839590)])
+ back.setCoords(coo)
+ c = DataArrayInt([32, 1, 0, 3, 5, 2, 4, 7, 6])
+ cI = DataArrayInt([0, 9])
+ back.setConnectivity(c, cI)
+ tool = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(71.5737767246627783,-14.0122818133993299),(72.5920244490449136,-7.0390015370978469),(47.7780086628800404,-4.6328708831306278)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 1, 0, 2])
+ cI = DataArrayInt([0, 4])
+ tool.setConnectivity(c, cI)
+
+ result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+ exp_coo = [71.61874999999999, -10.6521, 71.09373705108025, -12.611475000000002, 71.48522183177026, -11.666347132995506, 72.05416666666666, -10.6521, 71.83645833333333, -10.6521, 71.47081894564474, -12.829183333333336, 71.2822779983625, -12.72032916666667, 71.90580203530058, -11.779041258883959, 71.57377672466278, -14.01228181339933, 72.59202444904491, -7.039001537097847, 47.77800866288004, -4.632870883130628, 72.05352566581652, -10.726810361986129, 71.8931109163297, -11.825380957175156, 71.71347100577636, -12.340536509586565, 71.2822779983625, -12.72032916666667, 71.48522183177026, -11.666347132995508, 71.83645833333333, -10.6521, 72.0540064135051, -10.689456555884437, 71.97331829107311, -11.276095659580642, 72.0084757809432, -11.281229403333473, 71.97331829107311, -11.276095659580642]
+ c = [32, 12, 5, 1, 0, 3, 11, 13, 14, 15, 16, 17, 18, 32, 11, 12, 19, 20]
+ cI = [0, 13, 18]
+ e1 = [0, 0]
+ e2 = [0, -1]
+ valuesExpected = DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
+ self.assertEqual(c, result.getNodalConnectivity().getValues())
+ self.assertEqual(cI, result.getNodalConnectivityIndex().getValues())
+ self.assertEqual(e1, res2Back.getValues())
+ self.assertEqual(e2, res2Tool.getValues())
+ pass
+
+ def testIntersect2DMeshes10(self):
+ """ Edge::sortIdAbs() was merging points too agressively. This is not the job of the intersector,
+ user should call mergeNodes afterwards. Was throwing an exception later in the algorithm because
+ it had to deal with a degenerated cell.
+ """
+ eps = 1e-6
+ back = MEDCouplingUMesh('crh7_rse1', 2)
+ coo = DataArrayDouble([(-31.31375453845049250,-32.51281383633234157),(-31.69083643301495812,-32.73052216966566874),(-31.50229548573272353,-32.62166800299900871),(-31.53146287178381968,-32.88989573089681073),(-31.62164061609212951,-32.82069991397399633),(-31.42260870511715609,-32.70135478361457615)])
+ back.setCoords(coo)
+ c = DataArrayInt([32, 0, 3, 1, 5, 4, 2])
+ cI = DataArrayInt([0, 7])
+ back.setConnectivity(c, cI)
+ tool = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(-29.70769086373595513,-38.08598700945959337),(-27.13627518201525746,-36.53626696210140778),(-35.49132481798474714,-28.48933303789858940)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 0, 2, 1])
+ cI = DataArrayInt([0, 4])
+ tool.setConnectivity(c, cI)
+
+ result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+# print result.getCoords().getValues()
+# print result.getNodalConnectivity().getValues()
+# print result.getNodalConnectivityIndex().getValues()
+# print res2Back.getValues()
+# print res2Tool.getValues()
+ exp_coo = [-31.313754538450493, -32.51281383633234, -31.690836433014958, -32.73052216966567, -31.502295485732724, -32.62166800299901, -31.53146287178382, -32.88989573089681, -31.62164061609213, -32.820699913973996, -31.422608705117156, -32.701354783614576, -29.707690863735955, -38.08598700945959, -27.136275182015257, -36.53626696210141, -35.49132481798475, -28.48933303789859, -31.31376565042576, -32.51283308283808, -31.313773979690932, -32.51282506073775, -31.42261426110479, -32.70136440686744, -31.62164061609211, -32.82069991397398, -31.502305206352943, -32.62167361520171, -31.313769815058347, -32.51282907178791]
+ c = [32, 9, 3, 1, 10, 11, 12, 13, 14, 5, 10, 0, 9]
+ cI = [0, 9, 13]
+ e1 = [0, 0]
+ e2 = [0, -1]
+ valuesExpected = DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
+ self.assertEqual(c, result.getNodalConnectivity().getValues())
+ self.assertEqual(cI, result.getNodalConnectivityIndex().getValues())
+ self.assertEqual(e1, res2Back.getValues())
+ self.assertEqual(e2, res2Tool.getValues())
+ pass
def testSwig2Intersect2DMeshesQuadra1(self):
import cmath
m5.mergeNodes(eps)
# Check coordinates:
self.assertTrue(m3.getCoords().isEqual(m5.getCoords(), eps))
+ pass
def testIntersect2DMeshesTmp7(self):
eps = 1.0e-8
self.assertEqual(connI_tgt, m_intersec.getNodalConnectivityIndex().getValues())
self.assertEqual(res1_tgt, resToM1.getValues())
self.assertEqual(res2_tgt, resToM2.getValues())
+ pass
def testIntersect2DMeshesTmp8(self):
""" Arc of circle #5 in m2 was wrongly linearized and this was crashing the intersector. """
self.assertEqual(map2.getValues(), [0])
pass
+ def testIntersect2DMeshesTmp9(self):
+ """ Tricky case: two triangular shapes intersecting, but not perfectly, at their tips. Several issues fixed:
+ - Bug fix: seg seg intersector epsilon is to be taken absolutely for colinearity test (even for very small vectors
+ we don't want to have false positive on colinearity. So go back to a comparison with an angle.)
+ - when intersecting nodes are merged, they were not properly added on pol2.
+ - bug fix in compute residual: the stop condition is really on pol1Zip only.
+ - correcting polygons with flat corners, they were crashing residual computation
+ """
+ eps = 1.0e-6 # This is the key parameter. DO NOT CHANGE IT.
+ back = MEDCouplingUMesh('crh8_rse3', 2)
+ coo = DataArrayDouble([(-31.313754538446631,-32.512813836330515),(-31.531462871779969,-32.135731941766032),(-31.422608705113298,-32.324272889048274),(-31.690836433011114,-32.295105502997181),(-31.621640616088342,-32.204927758688783),(-31.502295485728872,-32.403959669663848)])
+ back.setCoords(coo)
+ c = DataArrayInt([32, 0, 3, 1, 5, 4, 2])
+ cI = DataArrayInt([0, 7])
+ back.setConnectivity(c, cI)
+
+ tool = MEDCouplingUMesh('TA-536193G_expl_20181022_merged', 2)
+ coo = DataArrayDouble([(-29.918137808525149,-26.883223901634544),(-32.919909136264039,-26.939612990540404),(-27.866900000000001,-28.016680435212603),(-31.313800000000001,-32.512799999999999),(-27.866900000000001,-28.933918793630923)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 1, 0, 3, 5, 0, 2, 3, 5, 4, 3, 2])
+ cI = DataArrayInt([0, 4, 8, 12])
+ tool.setConnectivity(c, cI)
+
+ inter, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+
+ self.assertEqual(inter.getNodalConnectivity().getValues(), [5, 14, 13, 11, 12, 5, 13, 15, 11, 32, 12, 3, 1, 14, 16, 17, 18, 19, 5, 15, 0, 11])
+ self.assertEqual(inter.getNodalConnectivityIndex().getValues(), [0, 5, 9, 18, 22])
+ self.assertEqual(res2Back.getValues(), [0, 0, 0, 0])
+ self.assertEqual(res2Tool.getValues(), [0, 1, -1, -1])
+ pass
+
+# def testIntersect2DMeshesTmp10(self):
+# """ Fixing issues when one of the quadratic point of the tool mesh also serves as a regular point somewhere else.
+# WARNING : the tool mesh is not conform, but this was NOT the initial cause of the problem """
+# eps = 1.0e-6
+# back = MEDCouplingUMesh('layer_1', 2)
+# coo = DataArrayDouble([(0.000000000000000,0.000000000000000),(0.000000000000007,113.449999999999960),(113.449999999999960,0.000000000000000),(80.221264325613788,80.221264325613788),(0.000000000000003,56.724999999999980),(56.724999999999980,0.000000000000000)])
+# back.setCoords(coo)
+# c = DataArrayInt([32, 0, 1, 2, 4, 3, 5])
+# cI = DataArrayInt([0, 7])
+# back.setConnectivity(c, cI)
+#
+# tool = MEDCouplingUMesh('layer_2', 2)
+# coo = DataArrayDouble([(35.499999704817512,0.000000000000011),(35.413523784223756,2.476354817916448),(35.478374361065050,1.238932132335084),(35.563158391762734,2.486818288978067),(35.649999999999999,0.000000000000000),(35.628282983230761,1.244167057444159),(35.488341087993248,2.481586553447257),(35.575000000000003,0.000000000000000),(35.154516440325750,4.940645084082323),(35.305526997492230,3.710760415787641),(35.154516440325743,-4.940645084082338),(34.960674956295250,-6.164510258681856),(35.413523784223763,-2.476354817916429),(35.305526997492230,-3.710760415787643),(35.563158391762734,-2.486818288978048),(35.488341087993248,-2.481586553447238),(35.478374361018354,-1.238932133672371),(35.628282983230761,-1.244167057444150)])
+# tool.setCoords(coo)
+# c = DataArrayInt([32, 0, 1, 3, 4, 2, 6, 5, 7, # 32, 6, 7, 9, 10, 8, 12, 11, 13
+# 32, 12, 0, 4, 14, 16, 7, 17, 15, # 32, 18, 6, 10, 20, 22, 13, 23, 21
+# 32, 8, 1, 12, 10, 9, 0, 13, 11]) # 32, 14, 7, 18, 16, 15, 6, 19, 17
+# cI = DataArrayInt([0, 9, 18, 27])
+# tool.setConnectivity(c, cI)
+# result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+# result.writeVTK("/tmp/toto.vtu")
+#
+# self.assertEqual(result.getNodalConnectivity().getValues(), [32, 10, 6, 7, 9, 25, 26, 27, 28, 32, 6, 0, 24, 14, 7, 29, 30, 31, 32, 33, 32, 24, 1, 2, 10, 9, 7, 6, 7, 14, 34, 35, 36, 37, 38, 39, 40, 41, 42])
+# self.assertEqual(result.getNodalConnectivityIndex().getValues(), [0, 9, 20, 39])
+# self.assertEqual(res2Back.getValues(), [0, 0, 0])
+# self.assertEqual(res2Tool.getValues(), [0, 2, -1])
+# pass
+
def testSwig2Intersect2DMeshWith1DLine1(self):
"""A basic test with no colinearity between m1 and m2."""
i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,13,20,27])))
pass
+ def testSwig2Conformize2D6(self):
+ """ Was raising an internal error on the tiny cell #1. SegSegIntersector was faulty (eps misinterpreted)."""
+ eps=1.0e-6
+ mesh = MEDCouplingUMesh('Intersect2D', 2)
+ coo = DataArrayDouble([(-8.575398341058831,39.144034061751867),(-7.163839075265572,39.460696499553713),(-8.555240716524352,39.000452491656162),(-8.575381177420400,39.143911806168589),(-8.575389759239616,39.143972933960228),(-8.565310946972376,39.072182148912376),(-8.429007892596994,39.323429450193125),(-7.276475921428452,39.552916149667766),(-7.853580170499488,39.442382740946520),(-8.501337660834821,39.233025525494369),(-8.451698830704938,39.023021732647329),(-8.575293095466966,39.143931102458232),(-7.321160265208347,39.250835031152391),(-7.193377962393479,39.421292562742188),(-8.503477261299500,39.011771463728323),(-7.257269113800913,39.336063796947286),(-8.575337136449106,39.143921454338184),(-8.513495963085951,39.083476417552781),(-7.178608518829526,39.440994531147950),(-8.575345718262898,39.143982582105053),(-7.887252103212342,39.141010366774864),(-7.885555090015171,39.288688127112323),(-7.223911296170824,39.502221445493511)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([32, 2, 3, 11, 10, 5, 16, 17, 14, 32, 3, 0, 11, 4, 19, 16, 32, 13, 12, 10, 11, 15, 20, 17, 21, 32, 7, 1, 13, 11, 0, 6, 22, 18, 21, 19, 9, 8])
+ cI = DataArrayInt([0, 9, 16, 25, 38])
+ mesh.setConnectivity(c, cI)
+
+ mesh.conformize2D(eps) # internal error was here
+
+ c2, cI2 = mesh.getNodalConnectivity().getValues(), mesh.getNodalConnectivityIndex().getValues()
+ self.assertEqual(c2, c.getValues())
+ self.assertEqual(cI2, cI.getValues())
+ pass
+
def testSwig2Conformize3D1(self):
""" Simple test where no edge merge is required, only face merging (first part of the algo) """
mesh = MEDCouplingUMesh('merge', 3)