]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 4 Jan 2010 11:26:34 +0000 (11:26 +0000)
committerageay <ageay>
Mon, 4 Jan 2010 11:26:34 +0000 (11:26 +0000)
src/MEDCoupling/MEDCouplingExtrudedMesh.cxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingExtrudedMesh.hxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingMesh.hxx
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling/MEDCouplingPointSet.hxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/Makefile.am
src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx

diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx
new file mode 100644 (file)
index 0000000..76e23d9
--- /dev/null
@@ -0,0 +1,321 @@
+//  Copyright (C) 2007-2008  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
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include "MEDCouplingExtrudedMesh.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingMemArray.hxx"
+
+#include <limits>
+#include <algorithm>
+#include <functional>
+#include <iterator>
+#include <cmath>
+#include <list>
+#include <set>
+
+using namespace ParaMEDMEM;
+
+MEDCouplingExtrudedMesh *MEDCouplingExtrudedMesh::New(MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception)
+{
+  return new MEDCouplingExtrudedMesh(mesh3D,mesh2D,cell2DId);
+}
+
+MEDCouplingMeshType MEDCouplingExtrudedMesh::getType() const
+{
+  return EXTRUDED;
+}
+
+MEDCouplingExtrudedMesh::MEDCouplingExtrudedMesh(MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception)
+try:_mesh2D(mesh2D),_mesh1D(MEDCouplingUMesh::New()),_mesh3D_ids(0),_cell_2D_id(cell2DId)
+{
+  if(_mesh2D!=0)
+    _mesh2D->incrRef();
+  computeExtrusion(mesh3D);
+}
+catch(INTERP_KERNEL::Exception& ex)
+  {
+  }
+
+bool MEDCouplingExtrudedMesh::isStructured() const
+{
+  return false;
+}
+
+int MEDCouplingExtrudedMesh::getNumberOfCells() const
+{
+  return _mesh2D->getNumberOfCells()*_mesh1D->getNumberOfCells();
+}
+
+int MEDCouplingExtrudedMesh::getNumberOfNodes() const
+{
+  return _mesh2D->getNumberOfNodes();
+}
+
+int MEDCouplingExtrudedMesh::getSpaceDimension() const
+{
+  return 3;
+}
+
+int MEDCouplingExtrudedMesh::getMeshDimension() const
+{
+  return 3;
+}
+
+void MEDCouplingExtrudedMesh::checkCoherency() const throw (INTERP_KERNEL::Exception)
+{
+}
+
+void MEDCouplingExtrudedMesh::getBoundingBox(double *bbox) const
+{
+  double bbox2D[6];
+  _mesh2D->getBoundingBox(bbox2D);
+  const double *nodes1D=_mesh1D->getCoords()->getConstPointer();
+  int nbOfNodes1D=_mesh1D->getNumberOfNodes();
+  double bbox1DMin[3],bbox1DMax[3],tmp[3];
+  std::fill(bbox1DMin,bbox1DMin+3,std::numeric_limits<double>::max());
+  std::fill(bbox1DMax,bbox1DMax+3,-(std::numeric_limits<double>::max()));
+  for(int i=0;i<nbOfNodes1D;i++)
+    {
+      std::transform(nodes1D+3*i,nodes1D+3*(i+1),bbox1DMin,bbox1DMin,std::ptr_fun(fmin));
+      std::transform(nodes1D+3*i,nodes1D+3*(i+1),bbox1DMax,bbox1DMax,std::ptr_fun(fmax));
+    }
+  std::transform(bbox1DMax,bbox1DMax+3,bbox1DMin,tmp,std::minus<double>());
+  int id=std::max_element(tmp,tmp+3)-tmp;
+  bbox[0]=bbox1DMin[0]; bbox[1]=bbox1DMax[0];
+  bbox[2]=bbox1DMin[1]; bbox[3]=bbox1DMax[1];
+  bbox[4]=bbox1DMin[2]; bbox[5]=bbox1DMax[2];
+  bbox[2*id+1]+=tmp[id];
+}
+
+void MEDCouplingExtrudedMesh::updateTime()
+{
+  if(_mesh2D)
+    {
+      updateTimeWith(*_mesh2D);
+    }
+  if(_mesh1D)
+    {
+      updateTimeWith(*_mesh1D);
+    }
+}
+
+MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::getMeasureField(bool) const
+{
+  return 0;
+}
+
+MEDCouplingExtrudedMesh::~MEDCouplingExtrudedMesh()
+{
+  if(_mesh2D)
+    _mesh2D->decrRef();
+  if(_mesh1D)
+    _mesh1D->decrRef();
+  if(_mesh3D_ids)
+    _mesh3D_ids->decrRef();
+}
+
+void MEDCouplingExtrudedMesh::computeExtrusion(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception)
+{
+  const char errMsg1[]="2D mesh is empty unable to compute extrusion !";
+  const char errMsg2[]="Coords between 2D and 3D meshes are not the same ! Try MEDCouplingPointSet::tryToShareSameCoords method";
+  const char errMsg3[]="No chance to find extrusion pattern in mesh3D,mesh2D couple because nbCells3D%nbCells2D!=0 !";
+  if(_mesh2D==0 || mesh3D==0)
+    throw INTERP_KERNEL::Exception(errMsg1);
+  if(_mesh2D->getCoords()!=mesh3D->getCoords())
+    throw INTERP_KERNEL::Exception(errMsg2);
+  if(mesh3D->getNumberOfCells()%_mesh2D->getNumberOfCells()!=0)
+    throw INTERP_KERNEL::Exception(errMsg3);
+  if(!_mesh3D_ids)
+    _mesh3D_ids=DataArrayInt::New();
+  if(!_mesh1D)
+    _mesh1D=MEDCouplingUMesh::New();
+  computeExtrusionAlg(mesh3D);
+}
+
+void MEDCouplingExtrudedMesh::build1DExtrusion(int idIn3DDesc, int newId, int nbOf1DLev, MEDCouplingUMesh *subMesh,
+                                               const int *desc3D, const int *descIndx3D,
+                                               const int *revDesc3D, const int *revDescIndx3D,
+                                               bool computeMesh1D) throw(INTERP_KERNEL::Exception)
+{
+  int nbOf2DCells=_mesh2D->getNumberOfCells();
+  int start=revDescIndx3D[idIn3DDesc];
+  int end=revDescIndx3D[idIn3DDesc+1];
+  if(end-start!=1)
+    {
+      std::ostringstream ost; ost << "Invalid bases 2D mesh specified : 2D cell # " <<  idIn3DDesc;
+      ost << " shared by more than 1 3D cell !!!";
+      throw INTERP_KERNEL::Exception(ost.str().c_str());
+    }
+  int current3DCell=revDesc3D[start];
+  int current2DCell=idIn3DDesc;
+  int *mesh3DIDs=_mesh3D_ids->getPointer();
+  mesh3DIDs[newId]=current3DCell;
+  const int *conn2D=subMesh->getNodalConnectivity()->getConstPointer();
+  const int *conn2DIndx=subMesh->getNodalConnectivityIndex()->getConstPointer();
+  for(int i=1;i<nbOf1DLev;i++)
+    {
+      std::vector<int> conn(conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
+      std::sort(conn.begin(),conn.end());
+      if(computeMesh1D)
+        computeBaryCenterOfFace(conn,i-1);
+      current2DCell=findOppositeFaceOf(current2DCell,current3DCell,conn,
+                                       desc3D,descIndx3D,conn2D,conn2DIndx);
+      start=revDescIndx3D[current2DCell];
+      end=revDescIndx3D[current2DCell+1];
+      if(end-start!=2)
+        {
+          std::ostringstream ost; ost << "Expecting to have 2 3D cells attached to 2D cell " << current2DCell << "!";
+          ost << " : Impossible or call tryToShareSameCoords method !";
+          throw INTERP_KERNEL::Exception(ost.str().c_str());
+        }
+      if(revDesc3D[start]!=current3DCell)
+        current3DCell=revDesc3D[start];
+      else
+        current3DCell=revDesc3D[start+1];
+      mesh3DIDs[i*nbOf2DCells+newId]=current3DCell;
+    }
+  if(computeMesh1D)
+    {
+      std::vector<int> conn(conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
+      std::sort(conn.begin(),conn.end());
+      computeBaryCenterOfFace(conn,nbOf1DLev-1);
+      current2DCell=findOppositeFaceOf(current2DCell,current3DCell,conn,
+                                       desc3D,descIndx3D,conn2D,conn2DIndx);
+      conn.clear();
+      conn.insert(conn.end(),conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
+      std::sort(conn.begin(),conn.end());
+      computeBaryCenterOfFace(conn,nbOf1DLev);
+    }
+}
+
+int MEDCouplingExtrudedMesh::findOppositeFaceOf(int current2DCell, int current3DCell, const std::vector<int>& connSorted,
+                                                const int *desc3D, const int *descIndx3D,
+                                                const int *conn2D, const int *conn2DIndx) throw(INTERP_KERNEL::Exception)
+{
+  int start=descIndx3D[current3DCell];
+  int end=descIndx3D[current3DCell+1];
+  bool found=false;
+  for(const int *candidate2D=desc3D+start;candidate2D!=desc3D+end && !found;candidate2D++)
+    {
+      if(*candidate2D!=current2DCell)
+        {
+          std::vector<int> conn2(conn2D+conn2DIndx[*candidate2D]+1,conn2D+conn2DIndx[*candidate2D+1]);
+          std::sort(conn2.begin(),conn2.end());
+          std::list<int> intersect;
+          std::set_intersection(connSorted.begin(),connSorted.end(),conn2.begin(),conn2.end(),
+                                std::insert_iterator< std::list<int> >(intersect,intersect.begin()));
+          if(intersect.empty())
+            return *candidate2D;
+        }
+    }
+  std::ostringstream ost; ost << "Impossible to find an opposite 2D face of face # " <<  current2DCell;
+  ost << " in 3D cell # " << current3DCell << " : Impossible or call tryToShareSameCoords method !";
+  throw INTERP_KERNEL::Exception(ost.str().c_str());
+}
+
+void MEDCouplingExtrudedMesh::computeBaryCenterOfFace(const std::vector<int>& nodalConnec, int lev1DId)
+{
+  double *zoneToUpdate=_mesh1D->getCoords()->getPointer()+lev1DId*3;
+  std::fill(zoneToUpdate,zoneToUpdate+3,0.);
+  const double *coords=_mesh2D->getCoords()->getConstPointer();
+  for(std::vector<int>::const_iterator iter=nodalConnec.begin();iter!=nodalConnec.end();iter++)
+    std::transform(zoneToUpdate,zoneToUpdate+3,coords+3*(*iter),zoneToUpdate,std::plus<double>());
+  std::transform(zoneToUpdate,zoneToUpdate+3,zoneToUpdate,std::bind2nd(std::multiplies<double>(),(double)(1./nodalConnec.size())));
+}
+
+int MEDCouplingExtrudedMesh::findCorrespCellByNodalConn(const std::vector<int>& nodalConnec, const int *revNodalPtr, const int *revNodalIndxPtr) throw(INTERP_KERNEL::Exception)
+{
+  std::vector<int>::const_iterator iter=nodalConnec.begin();
+  std::set<int> s1(revNodalPtr+revNodalIndxPtr[*iter],revNodalPtr+revNodalIndxPtr[*iter+1]);
+  iter++;
+  for(;iter!=nodalConnec.end();iter++)
+    {
+      std::set<int> s2(revNodalPtr+revNodalIndxPtr[*iter],revNodalPtr+revNodalIndxPtr[*iter+1]);
+      std::set<int> s3;
+      std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::insert_iterator< std::set<int> >(s3,s3.end()));
+      s1=s3;
+    }
+  if(s1.size()==1)
+    return *(s1.begin());
+  std::ostringstream ostr;
+  ostr << "Cell with nodal connec : ";
+  std::copy(nodalConnec.begin(),nodalConnec.end(),std::ostream_iterator<int>(ostr," "));
+  ostr << " is not part of mesh";
+  throw INTERP_KERNEL::Exception(ostr.str().c_str());
+}
+
+void MEDCouplingExtrudedMesh::computeExtrusionAlg(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception)
+{
+  _mesh3D_ids->alloc(mesh3D->getNumberOfCells(),1);
+  int nbOf1DLev=mesh3D->getNumberOfCells()/_mesh2D->getNumberOfCells();
+  _mesh1D->setMeshDimension(1);
+  _mesh1D->allocateCells(nbOf1DLev);
+  int tmpConn[2];
+  for(int i=0;i<nbOf1DLev;i++)
+    {
+      tmpConn[0]=i;
+      tmpConn[1]=i+1;
+      _mesh1D->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,tmpConn);
+    }
+  _mesh1D->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(nbOf1DLev+1,3);
+  _mesh1D->setCoords(myCoords);
+  myCoords->decrRef();
+  DataArrayInt *desc,*descIndx,*revDesc,*revDescIndx;
+  desc=DataArrayInt::New(); descIndx=DataArrayInt::New(); revDesc=DataArrayInt::New(); revDescIndx=DataArrayInt::New();
+  MEDCouplingUMesh *subMesh=mesh3D->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
+  DataArrayInt *revNodal2D,*revNodalIndx2D;
+  revNodal2D=DataArrayInt::New(); revNodalIndx2D=DataArrayInt::New();
+  subMesh->getReverseNodalConnectivity(revNodal2D,revNodalIndx2D);
+  const int *nodal2D=_mesh2D->getNodalConnectivity()->getConstPointer();
+  const int *nodal2DIndx=_mesh2D->getNodalConnectivityIndex()->getConstPointer();
+  const int *revNodal2DPtr=revNodal2D->getConstPointer();
+  const int *revNodalIndx2DPtr=revNodalIndx2D->getConstPointer();
+  const int *descP=desc->getConstPointer();
+  const int *descIndxP=descIndx->getConstPointer();
+  const int *revDescP=revDesc->getConstPointer();
+  const int *revDescIndxP=revDescIndx->getConstPointer();
+  //
+  int nbOf2DCells=_mesh2D->getNumberOfCells();
+  for(int i=0;i<nbOf2DCells;i++)
+    {
+      int idInSubMesh;
+       std::vector<int> nodalConnec(nodal2D+nodal2DIndx[i]+1,nodal2D+nodal2DIndx[i+1]);
+       try
+        {
+          idInSubMesh=findCorrespCellByNodalConn(nodalConnec,revNodal2DPtr,revNodalIndx2DPtr);
+        }
+       catch(INTERP_KERNEL::Exception& e)
+         {
+           std::ostringstream ostr; ostr << "mesh2D cell # " << i << " is not part of any cell of 3D mesh !\n";
+           ostr << e.what();
+           throw INTERP_KERNEL::Exception(ostr.str().c_str());
+         }
+       build1DExtrusion(idInSubMesh,i,nbOf1DLev,subMesh,descP,descIndxP,revDescP,revDescIndxP,i==_cell_2D_id);
+    }
+  //
+  revNodal2D->decrRef();
+  revNodalIndx2D->decrRef();
+  subMesh->decrRef();
+  desc->decrRef();
+  descIndx->decrRef();
+  revDesc->decrRef();
+  revDescIndx->decrRef();
+}
+
diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx
new file mode 100644 (file)
index 0000000..db0d863
--- /dev/null
@@ -0,0 +1,73 @@
+//  Copyright (C) 2007-2008  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
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef __PARAMEDMEM_MEDCOUPLINGEXTRUDEDMESH_HXX__
+#define __PARAMEDMEM_MEDCOUPLINGEXTRUDEDMESH_HXX__
+
+#include "MEDCoupling.hxx"
+#include "MEDCouplingMesh.hxx"
+
+#include <vector>
+
+namespace ParaMEDMEM
+{
+  class DataArrayInt;
+  class DataArrayDouble;
+  class MEDCouplingUMesh;
+  class MEDCouplingFieldDouble;
+
+  class MEDCOUPLING_EXPORT MEDCouplingExtrudedMesh : public MEDCouplingMesh
+  {
+  public:
+    static MEDCouplingExtrudedMesh *New(MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception);
+    MEDCouplingMeshType getType() const;
+    bool isStructured() const;
+    int getNumberOfCells() const;
+    int getNumberOfNodes() const;
+    int getSpaceDimension() const;
+    int getMeshDimension() const;
+    void checkCoherency() const throw (INTERP_KERNEL::Exception);
+    void getBoundingBox(double *bbox) const;
+    void updateTime();
+    MEDCouplingUMesh *getMesh1D() const { return _mesh1D; }
+    DataArrayInt *getMesh3DIds() const { return _mesh3D_ids; }
+    MEDCouplingFieldDouble *getMeasureField(bool) const;
+    static int findCorrespCellByNodalConn(const std::vector<int>& nodalConnec,
+                                          const int *revNodalPtr, const int *revNodalIndxPtr) throw(INTERP_KERNEL::Exception);
+  private:
+    MEDCouplingExtrudedMesh(MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception);
+    void computeExtrusion(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception);
+    void computeExtrusionAlg(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception);
+    void build1DExtrusion(int idIn3DDesc, int newId, int nbOf1DLev, MEDCouplingUMesh *subMesh,
+                          const int *desc3D, const int *descIndx3D,
+                          const int *revDesc3D, const int *revDescIndx3D,
+                          bool computeMesh1D) throw(INTERP_KERNEL::Exception);
+    int findOppositeFaceOf(int current2DCell, int current3DCell, const std::vector<int>& connSorted,
+                           const int *desc3D, const int *descIndx3D,
+                           const int *conn2D, const int *conn2DIndx) throw(INTERP_KERNEL::Exception);
+    void computeBaryCenterOfFace(const std::vector<int>& nodalConnec, int lev1DId);
+    ~MEDCouplingExtrudedMesh();
+  private:
+    MEDCouplingUMesh *_mesh2D;
+    MEDCouplingUMesh *_mesh1D;
+    DataArrayInt *_mesh3D_ids;
+    int _cell_2D_id;
+  };
+}
+
+#endif
index 125b0fafa959af72e3d0b0db2f690c9a54f69c35..cf65062c05a05f380e875e3b1f7dad58b57fd1af 100644 (file)
@@ -30,7 +30,8 @@ namespace ParaMEDMEM
     {
       UNSTRUCTURED = 5,
       UNSTRUCTURED_DESC = 6,
-      CARTESIAN = 7
+      CARTESIAN = 7,
+      EXTRUDED = 8
     } MEDCouplingMeshType;
 
   class MEDCouplingFieldDouble;
index e8dc92f429d48d31c83d4041b0d25fef6b535f53..06b06de8668cae200f89a506786f0d8e263aa94d 100644 (file)
@@ -154,6 +154,18 @@ void MEDCouplingPointSet::translate(const double *vector)
   updateTime();
 }
 
+void MEDCouplingPointSet::tryToShareSameCoords(MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception)
+{
+  if(_coords==other._coords)
+    return ;
+  if(!_coords)
+    throw INTERP_KERNEL::Exception("Current instance has no coords whereas other has !");
+  if(!other._coords)
+    throw INTERP_KERNEL::Exception("Other instance has no coords whereas current has !");
+  if(!_coords->isEqual(*other._coords,epsilon))
+    throw INTERP_KERNEL::Exception("Coords are not the same !");
+}
+
 MEDCouplingPointSet *MEDCouplingPointSet::buildInstanceFromMeshType(MEDCouplingMeshType type)
 {
   switch(type)
index 984b3cd2039f6c03d0e24011305312ef94cdd650..7308d40f32655e6226303d1b8c8d4b96b6833cfc 100644 (file)
@@ -47,6 +47,7 @@ namespace ParaMEDMEM
     void zipCoords();
     void rotate(const double *center, const double *vector, double angle);
     void translate(const double *vector);
+    void tryToShareSameCoords(MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception);
     static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type);
     virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const = 0;
     virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0;
index 01790c40854f2615a1f3c67e3df3dd97ea810235..155d469bc6deeb77c453bc20ce5631565af87c3f 100644 (file)
@@ -441,7 +441,7 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfNode(const int *start, c
       std::set<int> locMerge;
       std::insert_iterator< std::set<int> > it(locMerge,locMerge.begin());
       std::set_intersection(connOfCell.begin(),connOfCell.end(),fastFinder.begin(),fastFinder.end(),it);
-      if((int)locMerge.size()==refLgth && fullyIn || locMerge.size()!=0 && !fullyIn)
+      if(((int)locMerge.size()==refLgth && fullyIn) || (locMerge.size()!=0 && !fullyIn))
         cellIdsKept.push_back(i);
     }
   return buildPartOfMySelf(&cellIdsKept[0],&cellIdsKept[0]+cellIdsKept.size(),true);
index ecc67602bb53f76996b7de53dea3b88c31c7771d..f77485572e307afe2740b55b5c62c63621a4111d 100644 (file)
@@ -35,7 +35,7 @@ MEDCouplingCMesh.hxx MEDCouplingTimeDiscretization.hxx
 MEDCouplingFieldDiscretization.hxx MEDCouplingPointSet.hxx                                        \
 MEDCouplingUMeshDesc.hxx MEDCouplingNatureOfField.hxx                                             \
 MEDCouplingNormalizedCartesianMesh.hxx MEDCouplingNormalizedCartesianMesh.txx                     \
-MEDCouplingRemapper.hxx
+MEDCouplingRemapper.hxx MEDCouplingExtrudedMesh.hxx
 
 # Libraries targets
 
@@ -44,7 +44,8 @@ dist_libmedcoupling_la_SOURCES = \
        MEDCouplingUMesh.cxx  MEDCouplingMemArray.cxx  MEDCouplingTimeLabel.cxx   \
        MEDCouplingCMesh.cxx MEDCouplingTimeDiscretization.cxx                    \
        MEDCouplingFieldDiscretization.cxx MEDCouplingRefCountObject.cxx          \
-       MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx
+       MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx                          \
+       MEDCouplingExtrudedMesh.cxx
 
 libmedcoupling_la_LDFLAGS= 
 
index 859d72037db82a6b6ba14a4ba371b7a7f6e6f970..8a5d4b9260e56e933af0ad3fa5b9da884ad18f26 100644 (file)
@@ -18,6 +18,7 @@
 //
 #include "MEDCouplingBasicsTest.hxx"
 #include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingExtrudedMesh.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingMemArray.hxx"
 #include "Interpolation2D.txx"
@@ -856,6 +857,36 @@ void MEDCouplingBasicsTest::testBuildSubMeshData()
   targetMesh->decrRef();
 }
 
+void MEDCouplingBasicsTest::testExtrudedMesh1()
+{
+  MEDCouplingUMesh *mesh2D=0;
+  MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
+  MEDCouplingExtrudedMesh *ext=MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,1);
+  CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
+  CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
+  DataArrayInt *ids3D=ext->getMesh3DIds();
+  const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
+  CPPUNIT_ASSERT_EQUAL(18,ids3D->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,ids3D->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
+  MEDCouplingUMesh *mesh1D=ext->getMesh1D();
+  CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
+  CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
+  const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
+  DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
+  CPPUNIT_ASSERT_EQUAL(4,mesh1DCoords->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(3,mesh1DCoords->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
+  DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
+  CPPUNIT_ASSERT_EQUAL(9,conn1D->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,conn1D->getNumberOfComponents());
+  const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
+  CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
+  ext->decrRef();
+  mesh3D->decrRef();
+  mesh2D->decrRef();
+}
+
 void MEDCouplingBasicsTest::test2DInterpP0P0_1()
 {
   MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
@@ -3210,6 +3241,82 @@ MEDCouplingUMesh *MEDCouplingBasicsTest::build3DTargetMesh_1()
   return targetMesh;
 }
 
+MEDCouplingUMesh *MEDCouplingBasicsTest::build3DExtrudedUMesh_1(MEDCouplingUMesh *&mesh2D)
+{
+  double coords[180]={
+    0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
+    3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
+    0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1.,
+    3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
+    0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2.,
+    3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
+    0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3.,
+    3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
+
+  int conn[354]={
+    // 0
+    0,11,1,3,15,26,16,18,   1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17,
+    1,6,5,3,16,21,20,18,   13,10,9,6,28,25,24,21,
+    11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23,
+    7,12,14,13,22,27,29,28,
+    // 1
+    15,26,16,18,30,41,31,33,   16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32,
+    16,21,20,18,31,36,35,33,   28,25,24,21,43,40,39,36,
+    26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38,
+    22,27,29,28,37,42,44,43,
+    // 2
+    30,41,31,33,45,56,46,48,  31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
+    31,36,35,33,46,51,50,48,  43,40,39,36,58,55,54,51,
+    41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
+    37,42,44,43,52,57,59,58
+  };
+  int conn2[28]={7,12,14,13, 11,8,7,4,2,1, 13,10,9,6, 1,6,5,3, 1,2,4,7,13,6, 0,11,1,3};
+  //
+  MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
+  ret->setMeshDimension(3);
+  ret->allocateCells(18);
+  //
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
+  //
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
+  //
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
+  ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
+  ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
+  //
+  ret->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(60,3);
+  std::copy(coords,coords+180,myCoords->getPointer());
+  ret->setCoords(myCoords);
+  //
+  mesh2D=MEDCouplingUMesh::New();
+  mesh2D->setMeshDimension(2);
+  mesh2D->allocateCells(6);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_POLYGON,6,conn2+4);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+10);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+14);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_POLYGON,6,conn2+18);
+  mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+24);
+  mesh2D->setCoords(myCoords);
+  myCoords->decrRef();
+  return ret;
+}
+
 double MEDCouplingBasicsTest::sumAll(const std::vector< std::map<int,double> >& matrix)
 {
   double ret=0.;
index 8d299a81fae7e9b89c369a75a2dce119dfcb3dd0..e99db013c90b2d59afd37bd75b7b5ab29f3d8b71 100644 (file)
@@ -49,6 +49,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testEqualFieldDouble );
     CPPUNIT_TEST( testNatureChecking );
     CPPUNIT_TEST( testBuildSubMeshData );
+    CPPUNIT_TEST( testExtrudedMesh1 );
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_2 );
@@ -117,6 +118,7 @@ namespace ParaMEDMEM
     void testEqualFieldDouble();
     void testNatureChecking();
     void testBuildSubMeshData();
+    void testExtrudedMesh1();
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
     void test2DInterpP0P0PL_2();
@@ -183,6 +185,7 @@ namespace ParaMEDMEM
     MEDCouplingUMesh *build3DSurfTargetMesh_2();
     MEDCouplingUMesh *build3DSourceMesh_1();
     MEDCouplingUMesh *build3DTargetMesh_1();
+    MEDCouplingUMesh *build3DExtrudedUMesh_1(MEDCouplingUMesh *&mesh2D);
     double sumAll(const std::vector< std::map<int,double> >& matrix);
   };
 }