X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingBasicsTest6.py;h=620ea27517b6da1af10b070d5f109ae026279426;hb=b307fa3ee9c6d9e08082e2ccc832b28a17fd6d2c;hp=c8d34125e5f0f523e7067f2a57c2f1096f88a2ff;hpb=19e5224535682ba1d891e3df47527b0acb535098;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py index c8d34125e..620ea2751 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2017 CEA/DEN, EDF R&D +# Copyright (C) 2017-2021 CEA/DEN, EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,12 @@ # 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 @@ -189,8 +194,7 @@ class MEDCouplingBasicsTest6(unittest.TestCase): a1.rearrange(3) self.assertRaises(InterpKernelException,a1.findIdForEach,b1) # a1 is not single component pass - - @unittest.skipUnless(IsCXX11Compiled(),"requires C++11") + def testAttractSeg3MidPtsAroundNodes1(self): """ Test of MEDCouplingUMesh.attractSeg3MidPtsAroundNodes methods """ ptsExpToBeModified=DataArrayInt([95,96,97,98,101,103,104,106,108,110]) @@ -211,7 +215,187 @@ class MEDCouplingBasicsTest6(unittest.TestCase): ptsPosExp=DataArrayDouble([6.+a,3.+b,3.+a,6.+a,3.,3.+b,6.+b,3.+b,3.+b,7.,3.+b,3.+b,6.+a,6.+a,3.+a,6.+b,6.+a,3.+b,7.,6.+a,3.+b,6.+a,7.,3.+b,6.+a,3.+b,3.,6.+a,6.+a,3.],10,3) self.assertTrue(m.getCoords()[ptsExpToBeModified].isEqual(ptsPosExp,1e-12)) pass - + + def testRenumberNodesInConnOpt(self): + """ Test of MEDCouplingPointSet.renumberNodesInConn with map as input coming from DataArrayInt.invertArrayN2O2O2NOptimized + """ + m=MEDCouplingUMesh("mesh",2) + m.allocateCells() + m.insertNextCell(NORM_QUAD4,[10000,10002,10001,10003]) + coo=DataArrayDouble([(0,0),(1,1),(1,0),(0,1)]) + m.setCoords(coo) + m.checkConsistencyLight() + # + d=DataArrayInt([10000,10001,10002,10003]) + myMap=d.invertArrayN2O2O2NOptimized() + myMap2=d.giveN2OOptimized() + m.checkConsistencyLight() + # + m.renumberNodesInConn(myMap) # <- test is here for UMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,0,2,1,3]))) + m.renumberNodesInConn(myMap2) # <- test is here for UMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,10000,10002,10001,10003]))) + # + m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) + m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003])) + m.setCoords(coo) + m.checkConsistencyLight() + m.renumberNodesInConn(myMap) # <- test is here for 1SGTUMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3]))) + # + m=MEDCoupling1DGTUMesh("mesh",NORM_POLYGON) + m.setCoords(coo) + m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003]),DataArrayInt([0,4])) + m.checkConsistencyLight() + m.renumberNodesInConn(myMap) # <- test is here for 1DGTUMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3]))) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4]))) + pass + + def testSeg2bGP(self): + """Test of Gauss points on SEG2 using SEG2B style as ref coords + """ + coo=DataArrayDouble([[0.,0.,0.],[1.,1.,1.]]) + m=MEDCouplingUMesh("mesh",1) ; m.setCoords(coo) + m.allocateCells() + # the cell description is exactly those described in the description of HEXA27 in MED file 3.0.7 documentation + m.insertNextCell(NORM_SEG2,[0,1]) + refCoo=[0.,1.] + weights=[0.8,0.1,0.1] + gCoords=[0.2,0.5,0.9] + fGauss=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fGauss.setName("fGauss") + fGauss.setMesh(m) + fGauss.setGaussLocalizationOnType(NORM_SEG2,refCoo,gCoords,weights) + arr=DataArrayDouble(fGauss.getNumberOfTuplesExpected()) ; arr.iota() + fGauss.setArray(arr) + fGauss.checkConsistencyLight() + arrOfDisc=fGauss.getLocalizationOfDiscr() + self.assertTrue(arrOfDisc.isEqual(DataArrayDouble([0.2,0.2,0.2,0.5,0.5,0.5,0.9,0.9,0.9],3,3),1e-12)) + pass + + def testUMeshGetCellsContainingPtOn2DNonDynQuadraticCells(self): + """getCellsContainingPoint is now dealing curves of quadratic 2D elements. +This test is a mesh containing 2 QUAD8 cells. The input point is located at a special loc. +If true geometry (with curve as edges) is considered the result of getCellsContainingPoint is not the same as if only linear part of cells is considered.""" + coords=DataArrayDouble([-0.9428090415820631,0.9428090415820631,-1.06066017177982,1.06066017177982,-1.1785113019775801,1.1785113019775801,-1.2963624321753402,1.2963624321753402,-1.4142135623731,1.41421356237309,-0.7653668647301801,1.8477590650225701,-0.6378057206084831,1.53979922085214,-0.510244576486786,1.23183937668172,-0.701586292669331,1.6937791429373599,-0.574025148547635,1.38581929876693,-0.9259503883660041,1.38578268717091,-0.740760310692803,1.10862614973673,-1.1111404660392,1.66293922460509],13,2) + m=MEDCouplingUMesh("mesh",2) + m.setCoords(coords) + m.allocateCells() + m.insertNextCell(NORM_QUAD8,[4,2,6,5,3,10,8,12]) + m.insertNextCell(NORM_QUAD8,[2,0,7,6,1,11,9,10]) + # + zePt=DataArrayDouble([-0.85863751450784975,1.4203162316045934],1,2) + a,b=m.getCellsContainingPoints(zePt,1e-12) + self.assertTrue(b.isEqual(DataArrayInt([0,1]))) + self.assertTrue(a.isEqual(DataArrayInt([1]))) # <- test is here. 0 if only linear parts are considered. + # + a,b=m.getCellsContainingPointsLinearPartOnlyOnNonDynType(zePt,1e-12) + self.assertTrue(b.isEqual(DataArrayInt([0,1]))) + self.assertTrue(a.isEqual(DataArrayInt([0]))) # <- like before + pass + + def testComputeIntegralOfSeg2IntoTri3_1(self): + seg2 = [(90453.702115782813, 36372.66281307926), (90457.969790110554, 36373.365088601546)] + tri3 = [(90466.90625, 36376.9375), (90446.5, 36404), (90453.1875, 36365.75)] + a,b=DataArrayDouble.ComputeIntegralOfSeg2IntoTri3(seg2,tri3) + self.assertEqual(len(a),3) + self.assertAlmostEqual(a[0],0.2460689650955214,12) + self.assertAlmostEqual(a[1],0.10875598777133343,12) + self.assertAlmostEqual(a[2],0.6451750471331451,12) + self.assertAlmostEqual(b,4.32507052854159,12) + pass + + def testRemoveDegenerated1DCells1(self): + m=MEDCoupling1SGTUMesh("mesh",NORM_SEG2) + conn=DataArrayInt([1,2, 3,4, 5,5, 5,6, 6,6, 6,7, 19,19, 7,8]) + m.setNodalConnectivity(conn) # no coords set. It s not a bug. removeDegenerated1DCells doesn't care + m=m.buildUnstructured() + aa=m.getNodalConnectivity().getHiddenCppPointer() + self.assertTrue(m.removeDegenerated1DCells()) # <- test is here + bb=m.getNodalConnectivity().getHiddenCppPointer() + self.assertNotEqual(aa,bb) + expConn=DataArrayInt([1,1,2,1,3,4,1,5,6,1,6,7,1,7,8]) + expConnI=DataArrayInt.Range(0,16,3) + self.assertTrue(m.getNodalConnectivity().isEqual(expConn)) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(expConnI)) + self.assertTrue(not m.removeDegenerated1DCells()) + cc=m.getNodalConnectivity().getHiddenCppPointer() + self.assertEqual(bb,cc) + self.assertTrue(m.getNodalConnectivity().isEqual(expConn)) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(expConnI)) + pass + + def testMergeFieldsOnGauss1(self): + mName="mesh" + fieldName="field" + # + _a=0.446948490915965; + _b=0.091576213509771; + _p1=0.11169079483905; + _p2=0.0549758718227661; + refCoo1=[ 0.,0., 1.,0., 0.,1. ] + gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, + 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ] + wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ] + # + refCoo2=[ -1.,-1., 1.,-1., 1.,1., -1.,1. ] + gsCoo2=[0.1,0.1, 0.2,0.2, 0.5,0.5, 0.6,0.6, 0.7,0.7] + wg2=[0.1,0.2,0.3,0.4,0.5] + # + coo=DataArrayDouble([0,0,1,0,2,0,0,1,1,1,2,1,0,2,1,2,2,2],9,2) + m1=MEDCouplingUMesh(mName,2) + m1.allocateCells() ; m1.setCoords(coo) + m1.insertNextCell(NORM_TRI3,[1,4,2]) + m1.insertNextCell(NORM_TRI3,[4,5,2]) + m1.insertNextCell(NORM_QUAD4,[4,7,8,5]) + f1=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f1.setName(fieldName) + f1.setMesh(m1) + f1.setGaussLocalizationOnType(NORM_TRI3,refCoo1,gsCoo1,wg1) + f1.setGaussLocalizationOnType(NORM_QUAD4,refCoo2,gsCoo2,wg2) + arr=DataArrayDouble(f1.getNumberOfTuplesExpected()) + arr.iota() + f1.setArray(arr) + f1.checkConsistencyLight() + # + m2=MEDCouplingUMesh(mName,2) + m2.allocateCells() ; m2.setCoords(coo) + m2.insertNextCell(NORM_QUAD4,[0,3,4,1]) + m2.insertNextCell(NORM_QUAD4,[3,6,7,4]) + ################### + self.assertTrue(f1.getMesh().getCoords().isEqual(m2.getCoords(),1e-12)) + f1.getMesh().setCoords(m2.getCoords()) + # + f2=MEDCouplingFieldDouble(ON_GAUSS_PT) + f2.setMesh(m2) + for gt in m2.getAllGeoTypes(): # on recopie les localisation en utilisant f1 + glt=f1.getGaussLocalizationIdOfOneType(gt) + gloc=f1.getGaussLocalization(glt) + f2.setGaussLocalizationOnType(gt,gloc.getRefCoords(),gloc.getGaussCoords(),gloc.getWeights()) + arr2=DataArrayDouble(f2.getNumberOfTuplesExpected()) + arr2[:]=0 + f2.setArray(arr2) + f2.checkConsistencyLight() + # + fout1=MEDCouplingFieldDouble.MergeFields([f1,f2]) + fout2=MEDCouplingFieldDouble.MergeFields(f1,f2) + # + fOut=MEDCouplingFieldDouble(ON_GAUSS_PT) + mOut=MEDCouplingUMesh.MergeUMeshes([f1.getMesh(),m2]) + mOut.setName(f1.getMesh().getName()) + fOut.setMesh(mOut) + for gt in f1.getMesh().getAllGeoTypes(): # on recopie les localisation en utilisant f1 + glt=f1.getGaussLocalizationIdOfOneType(gt) + gloc=f1.getGaussLocalization(glt) + fOut.setGaussLocalizationOnType(gt,gloc.getRefCoords(),gloc.getGaussCoords(),gloc.getWeights()) + fOut.setArray(DataArrayDouble.Aggregate([f1.getArray(),arr2])) + fOut.checkConsistencyLight() + fOut.setName(f1.getName()) + fOut.getMesh().setName(f1.getMesh().getName()) + # + self.assertTrue(fout1.isEqual(fOut,1e-12,1e-12)) + self.assertTrue(fout2.isEqual(fOut,1e-12,1e-12)) + pass + pass if __name__ == '__main__':