1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
20 #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
22 #include "MEDCouplingNormalizedUnstructuredMesh.hxx"
24 #include "MEDCouplingUMesh.hxx"
25 #include "MEDCouplingMemArray.hxx"
29 template<int SPACEDIM,int MESHDIM>
30 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh)
37 template<int SPACEDIM,int MESHDIM>
38 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
40 for(int i=0;i<SPACEDIM;i++)
42 boundingBox[i]=std::numeric_limits<double>::max();
43 boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
45 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
46 const double *ptr=array->getConstPointer();
47 int nbOfPts=array->getNbOfElems()/SPACEDIM;
48 for(int j=0;j<SPACEDIM;j++)
50 const double *work=ptr+j;
51 for(int i=0;i<nbOfPts;i++,work+=SPACEDIM)
53 if(boundingBox[j]>*work)
55 if(boundingBox[j+SPACEDIM]<*work)
56 boundingBox[j+SPACEDIM]=*work;
61 template<int SPACEDIM,int MESHDIM>
62 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
64 return _mesh->getTypeOfCell(eltId);
67 template<int SPACEDIM,int MESHDIM>
68 unsigned char MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
70 return _mesh->getNumberOfNodesInCell(eltId);
73 template<int SPACEDIM,int MESHDIM>
74 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
76 return _mesh->getNumberOfCells();
79 template<int SPACEDIM,int MESHDIM>
80 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
82 return _mesh->getNumberOfNodes();
85 template<int SPACEDIM,int MESHDIM>
86 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
88 return _conn_for_interp;
91 template<int SPACEDIM,int MESHDIM>
92 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
94 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
95 return array->getConstPointer();
98 template<int SPACEDIM,int MESHDIM>
99 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
101 return _conn_index_for_interp;
104 template<int SPACEDIM,int MESHDIM>
105 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
107 delete [] _conn_for_interp;
108 delete [] _conn_index_for_interp;
110 _conn_index_for_interp=0;
113 template<int SPACEDIM,int MESHDIM>
114 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
121 template<int SPACEDIM,int MESHDIM>
122 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
124 int nbOfCell=_mesh->getNumberOfCells();
125 int initialConnSize=_mesh->getNodalConnectivity()->getNbOfElems();
126 _conn_for_interp=new int[initialConnSize-nbOfCell];
127 _conn_index_for_interp=new int[nbOfCell+1];
128 _conn_index_for_interp[0]=0;
129 const int *work_conn=_mesh->getNodalConnectivity()->getConstPointer()+1;
130 const int *work_conn_index=_mesh->getNodalConnectivityIndex()->getConstPointer();
131 int *work_conn_for_interp=_conn_for_interp;
132 int *work_conn_index_for_interp=_conn_index_for_interp;
133 for(int i=0;i<nbOfCell;i++)
135 int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
136 work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
137 work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
139 work_conn+=nbOfValsToCopy+1;
140 work_conn_index_for_interp++;