1 // Copyright (C) 2007-2008 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 "MemArray.hxx"
27 template<int SPACEDIM,int MESHDIM>
28 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh)
35 template<int SPACEDIM,int MESHDIM>
36 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
38 for(int i=0;i<SPACEDIM;i++)
40 boundingBox[i]=std::numeric_limits<double>::max();
41 boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
43 ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
44 const double *ptr=array->getPointer();
45 int nbOfPts=array->getNbOfElems()/SPACEDIM;
46 for(int j=0;j<SPACEDIM;j++)
48 const double *work=ptr+j;
49 for(int i=0;i<nbOfPts;i++,work+=SPACEDIM)
51 if(boundingBox[j]>*work)
53 if(boundingBox[j+SPACEDIM]<*work)
54 boundingBox[j+SPACEDIM]=*work;
59 template<int SPACEDIM,int MESHDIM>
60 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
62 return _mesh->getTypeOfCell(eltId);
65 template<int SPACEDIM,int MESHDIM>
66 unsigned char MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
68 return _mesh->getNumberOfNodesInCell(eltId);
71 template<int SPACEDIM,int MESHDIM>
72 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
74 return _mesh->getNumberOfCells();
77 template<int SPACEDIM,int MESHDIM>
78 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
80 return _mesh->getNumberOfNodes();
83 template<int SPACEDIM,int MESHDIM>
84 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
86 return _conn_for_interp;
89 template<int SPACEDIM,int MESHDIM>
90 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
92 ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
93 return array->getPointer();
96 template<int SPACEDIM,int MESHDIM>
97 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
99 return _conn_index_for_interp;
102 template<int SPACEDIM,int MESHDIM>
103 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::ReleaseTempArrays()
105 delete [] _conn_for_interp;
106 delete [] _conn_index_for_interp;
108 _conn_index_for_interp=0;
111 template<int SPACEDIM,int MESHDIM>
112 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
119 template<int SPACEDIM,int MESHDIM>
120 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
122 int nbOfCell=_mesh->getNumberOfCells();
123 int initialConnSize=_mesh->getNodalConnectivity()->getNbOfElems();
124 _conn_for_interp=new int[initialConnSize-nbOfCell];
125 _conn_index_for_interp=new int[nbOfCell+1];
126 _conn_index_for_interp[0]=0;
127 const int *work_conn=_mesh->getNodalConnectivity()->getPointer()+1;
128 const int *work_conn_index=_mesh->getNodalConnectivityIndex()->getPointer();
129 int *work_conn_for_interp=_conn_for_interp;
130 int *work_conn_index_for_interp=_conn_index_for_interp;
131 for(int i=0;i<nbOfCell;i++)
133 int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
134 work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
135 work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
137 work_conn+=nbOfValsToCopy+1;
138 work_conn_index_for_interp++;