1 // Copyright (C) 2007-2013 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 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
21 #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
23 #include "MEDCouplingNormalizedUnstructuredMesh.hxx"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingMemArray.hxx"
30 template<int SPACEDIM,int MESHDIM>
31 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh)
38 template<int SPACEDIM,int MESHDIM>
39 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
41 for(int i=0;i<SPACEDIM;i++)
43 boundingBox[i]=std::numeric_limits<double>::max();
44 boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
46 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
47 const double *ptr=array->getConstPointer();
48 int nbOfPts=array->getNbOfElems()/SPACEDIM;
49 for(int j=0;j<SPACEDIM;j++)
51 const double *work=ptr+j;
52 for(int i=0;i<nbOfPts;i++,work+=SPACEDIM)
54 if(boundingBox[j]>*work)
56 if(boundingBox[j+SPACEDIM]<*work)
57 boundingBox[j+SPACEDIM]=*work;
62 template<int SPACEDIM,int MESHDIM>
63 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
65 return _mesh->getTypeOfCell(eltId);
68 template<int SPACEDIM,int MESHDIM>
69 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
71 return _mesh->getNumberOfNodesInCell(eltId);
74 template<int SPACEDIM,int MESHDIM>
75 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
77 return _mesh->getNumberOfCells();
80 template<int SPACEDIM,int MESHDIM>
81 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
83 return _mesh->getNumberOfNodes();
86 template<int SPACEDIM,int MESHDIM>
87 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
89 return _conn_for_interp;
92 template<int SPACEDIM,int MESHDIM>
93 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
95 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
96 return array->getConstPointer();
99 template<int SPACEDIM,int MESHDIM>
100 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
102 return _conn_index_for_interp;
105 template<int SPACEDIM,int MESHDIM>
106 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
108 delete [] _conn_for_interp;
109 delete [] _conn_index_for_interp;
111 _conn_index_for_interp=0;
114 template<int SPACEDIM,int MESHDIM>
115 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
122 template<int SPACEDIM,int MESHDIM>
123 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
125 int nbOfCell=_mesh->getNumberOfCells();
126 int initialConnSize=_mesh->getNodalConnectivity()->getNbOfElems();
127 _conn_for_interp=new int[initialConnSize-nbOfCell];
128 _conn_index_for_interp=new int[nbOfCell+1];
129 _conn_index_for_interp[0]=0;
130 const int *work_conn=_mesh->getNodalConnectivity()->getConstPointer()+1;
131 const int *work_conn_index=_mesh->getNodalConnectivityIndex()->getConstPointer();
132 int *work_conn_for_interp=_conn_for_interp;
133 int *work_conn_index_for_interp=_conn_index_for_interp;
134 for(int i=0;i<nbOfCell;i++)
136 int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
137 work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
138 work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
140 work_conn+=nbOfValsToCopy+1;
141 work_conn_index_for_interp++;