]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Wed, 1 Dec 2010 09:27:14 +0000 (09:27 +0000)
committerageay <ageay>
Wed, 1 Dec 2010 09:27:14 +0000 (09:27 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index bc8750b1442957623b4cf9df0fb4806819fe389a..cf6aa2a1dcde4c3694aec3a9d80f0827f8b1ff8f 100644 (file)
@@ -86,7 +86,7 @@ bool DataArray::areInfoEquals(const DataArray& other) const
 
 void DataArray::reprWithoutNameStream(std::ostream& stream) const
 {
-  stream << "Nb of components : "<< getNumberOfComponents() << "\n";
+  stream << "Number of components : "<< getNumberOfComponents() << "\n";
   stream << "Info of these components : ";
   for(std::vector<std::string>::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++)
     stream << "\"" << *iter << "\"   ";
index be045a618ec785dcdebe76510daa6c27714dc9b3..9db650a542ce7662c776b709e3c22f5b27d10743 100644 (file)
@@ -2069,13 +2069,14 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslation(const MEDCoupli
 {
   int oldNbOfNodes=getNumberOfNodes();
   int nbOf1DCells=mesh1D->getNumberOfCells();
+  int spaceDim=getSpaceDimension();
   DataArrayDouble *ret=DataArrayDouble::New();
   std::vector<bool> isQuads;
   int nbOfLevsInVec=isQuad?2*nbOf1DCells+1:nbOf1DCells+1;
-  ret->alloc(oldNbOfNodes*nbOfLevsInVec,3);
+  ret->alloc(oldNbOfNodes*nbOfLevsInVec,spaceDim);
   double *retPtr=ret->getPointer();
   const double *coords=getCoords()->getConstPointer();
-  double *work=std::copy(coords,coords+3*oldNbOfNodes,retPtr);
+  double *work=std::copy(coords,coords+spaceDim*oldNbOfNodes,retPtr);
   std::vector<int> v;
   std::vector<double> c;
   double vec[3];
@@ -2088,17 +2089,17 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslation(const MEDCoupli
       c.resize(0);
       mesh1D->getCoordinatesOfNode(v[isQuad?2:1],c);
       mesh1D->getCoordinatesOfNode(v[0],c);
-      std::transform(c.begin(),c.begin()+3,c.begin()+3,vec,std::minus<double>());
+      std::transform(c.begin(),c.begin()+spaceDim,c.begin()+spaceDim,vec,std::minus<double>());
       for(int j=0;j<oldNbOfNodes;j++)
-        work=std::transform(vec,vec+3,retPtr+3*(i*oldNbOfNodes+j),work,std::plus<double>());
+        work=std::transform(vec,vec+spaceDim,retPtr+spaceDim*(i*oldNbOfNodes+j),work,std::plus<double>());
       if(isQuad)
         {
           c.resize(0);
           mesh1D->getCoordinatesOfNode(v[1],c);
           mesh1D->getCoordinatesOfNode(v[0],c);
-          std::transform(c.begin(),c.begin()+3,c.begin()+3,vec,std::minus<double>());
+          std::transform(c.begin(),c.begin()+spaceDim,c.begin()+spaceDim,vec,std::minus<double>());
           for(int j=0;j<oldNbOfNodes;j++)
-            work=std::transform(vec,vec+3,retPtr+3*(i*oldNbOfNodes+j),work,std::plus<double>());
+            work=std::transform(vec,vec+spaceDim,retPtr+spaceDim*(i*oldNbOfNodes+j),work,std::plus<double>());
         }
     }
   ret->copyStringInfoFrom(*getCoords());
@@ -2130,6 +2131,8 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(con
     throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D : not implemented for quadratic cells !");
   int oldNbOfNodes=getNumberOfNodes();
   int nbOf1DCells=mesh1D->getNumberOfCells();
+  if(nbOf1DCells<2)
+    throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D : impossible to detect any angle of rotation ! Change extrusion policy 1->0 !");
   DataArrayDouble *ret=DataArrayDouble::New();
   int nbOfLevsInVec=nbOf1DCells+1;
   ret->alloc(oldNbOfNodes*nbOfLevsInVec,2);
index 2d5614869a60134c72a4c9806e8bdca3be5a9059..50adf47ac2943b69870f9df2147e6c4789c70552 100644 (file)
@@ -156,6 +156,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testGetNodeIdsNearPoints1 );
     CPPUNIT_TEST( testFieldCopyTinyAttrFrom1 );
     CPPUNIT_TEST( testExtrudedMesh5 );
+    CPPUNIT_TEST( testExtrudedMesh6 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -340,6 +341,7 @@ namespace ParaMEDMEM
     void testGetNodeIdsNearPoints1();
     void testFieldCopyTinyAttrFrom1();
     void testExtrudedMesh5();
+    void testExtrudedMesh6();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 279740819807ad0b6f79a9bd8cdae9154dcc6516..4ce40a70e6594903c94510e34828235d22941ec7 100644 (file)
@@ -3352,6 +3352,9 @@ void MEDCouplingBasicsTest::testFieldCopyTinyAttrFrom1()
   f2->decrRef();
 }
 
+/*!
+ * 1D -> 2D extrusion with rotation
+ */
 void MEDCouplingBasicsTest::testExtrudedMesh5()
 {
   const double coo1[4]={0.,1.,2.,3.5};
@@ -3409,3 +3412,54 @@ void MEDCouplingBasicsTest::testExtrudedMesh5()
   b->decrRef();
   a->decrRef();
 }
+
+/*!
+ * 1D -> 2D extrusion without rotation
+ */
+void MEDCouplingBasicsTest::testExtrudedMesh6()
+{
+  const double coo1[4]={0.,1.,2.,3.5};
+  DataArrayDouble *a=DataArrayDouble::New();
+  a->alloc(4,1);
+  std::copy(coo1,coo1+4,a->getPointer());
+  MEDCouplingCMesh *b=MEDCouplingCMesh::New();
+  b->setCoordsAt(0,a);
+  MEDCouplingUMesh *c=b->buildUnstructured();
+  CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
+  c->changeSpaceDimension(2);
+  //
+  DataArrayDouble *d=DataArrayDouble::New();
+  d->alloc(5,1);
+  d->iota();
+  MEDCouplingCMesh *e=MEDCouplingCMesh::New();
+  e->setCoordsAt(0,d);
+  MEDCouplingUMesh *f=e->buildUnstructured();
+  DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
+  f->setCoords(d2);
+  f->changeSpaceDimension(2);
+  //
+  const double center[2]={0.,0.};
+  f->rotate(center,0,M_PI/3);
+  MEDCouplingUMesh *g=c->buildExtrudedMeshFromThis(f,0);
+  g->checkCoherency();
+  const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 };
+  MEDCouplingFieldDouble *f1=g->getMeasureField(true);
+  for(int i=0;i<12;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
+  
+  const double expected2[]={0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414};
+  DataArrayDouble *f2=g->getBarycenterAndOwner();
+  for(int i=0;i<24;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
+  //
+  f1->decrRef();
+  f2->decrRef();
+  g->decrRef();
+  f->decrRef();
+  e->decrRef();
+  d->decrRef();
+  d2->decrRef();
+  c->decrRef();
+  b->decrRef();
+  a->decrRef();
+}
index 97bd6c5c5858cf1a5154bcca5a694a75abbfbcf3..4e56ef238134d4850ed5eaf3daebb07a6ca2f323 100644 (file)
@@ -5005,6 +5005,42 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             pass
         #
         pass
+
+    def testExtrudedMesh6(self):
+        coo1=[0.,1.,2.,3.5]
+        a=DataArrayDouble.New();
+        a.setValues(coo1,4,1);
+        b=MEDCouplingCMesh.New();
+        b.setCoordsAt(0,a);
+        c=b.buildUnstructured();
+        self.assertEqual(1,c.getSpaceDimension());
+        c.changeSpaceDimension(2);
+        #
+        d=DataArrayDouble.New();
+        d.alloc(5,1);
+        d.iota();
+        e=MEDCouplingCMesh.New();
+        e.setCoordsAt(0,d);
+        f=e.buildUnstructured();
+        d2=f.getCoords().applyFunc("x*x/2");
+        f.setCoords(d2);
+        f.changeSpaceDimension(2);
+        #
+        center=[0.,0.]
+        f.rotate(center,[],pi/3);
+        g=c.buildExtrudedMeshFromThis(f,0);
+        g.checkCoherency();
+        expected1=[ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 ]
+        f1=g.getMeasureField(True);
+        for i in xrange(12):
+            self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),12);
+            pass
+        expected2=[0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414]
+        f2=g.getBarycenterAndOwner();
+        for i in xrange(24):
+            self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),12);
+            pass
+        pass
     
     def setUp(self):
         pass