1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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)
21 #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
22 #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
24 #include "MEDCouplingNormalizedUnstructuredMesh.hxx"
26 #include "MEDCouplingUMesh.hxx"
27 #include "MEDCoupling1GTUMesh.hxx"
28 #include "MEDCouplingMemArray.hxx"
32 template<int SPACEDIM,int MESHDIM>
33 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingPointSet *mesh):_mesh(mesh)
40 template<int SPACEDIM,int MESHDIM>
41 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
43 for(int i=0;i<SPACEDIM;i++)
45 boundingBox[i]=std::numeric_limits<double>::max();
46 boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
48 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
49 const double *ptr=array->getConstPointer();
50 int nbOfPts=array->getNbOfElems()/SPACEDIM;
51 for(int j=0;j<SPACEDIM;j++)
53 const double *work=ptr+j;
54 for(int i=0;i<nbOfPts;i++,work+=SPACEDIM)
56 if(boundingBox[j]>*work)
58 if(boundingBox[j+SPACEDIM]<*work)
59 boundingBox[j+SPACEDIM]=*work;
64 template<int SPACEDIM,int MESHDIM>
65 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
67 return _mesh->getTypeOfCell(eltId);
70 template<int SPACEDIM,int MESHDIM>
71 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
73 return _mesh->getNumberOfNodesInCell(eltId);
76 template<int SPACEDIM,int MESHDIM>
77 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
79 return _mesh->getNumberOfCells();
82 template<int SPACEDIM,int MESHDIM>
83 int MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
85 return _mesh->getNumberOfNodes();
88 template<int SPACEDIM,int MESHDIM>
89 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
91 return _conn_for_interp;
94 template<int SPACEDIM,int MESHDIM>
95 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
97 const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
98 return array->getConstPointer();
101 template<int SPACEDIM,int MESHDIM>
102 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
104 return _conn_index_for_interp;
107 template<int SPACEDIM,int MESHDIM>
108 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
110 delete [] _conn_for_interp;
111 delete [] _conn_index_for_interp;
113 _conn_index_for_interp=0;
116 template<int SPACEDIM,int MESHDIM>
117 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
124 template<int SPACEDIM,int MESHDIM>
125 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
127 const ParaMEDMEM::MEDCouplingUMesh *m1(dynamic_cast<const ParaMEDMEM::MEDCouplingUMesh *>(_mesh));
130 int nbOfCell=m1->getNumberOfCells();
131 int initialConnSize=m1->getNodalConnectivity()->getNbOfElems();
132 _conn_for_interp=new int[initialConnSize-nbOfCell];
133 _conn_index_for_interp=new int[nbOfCell+1];
134 _conn_index_for_interp[0]=0;
135 const int *work_conn=m1->getNodalConnectivity()->getConstPointer()+1;
136 const int *work_conn_index=m1->getNodalConnectivityIndex()->getConstPointer();
137 int *work_conn_for_interp=_conn_for_interp;
138 int *work_conn_index_for_interp=_conn_index_for_interp;
139 for(int i=0;i<nbOfCell;i++)
141 int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
142 work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
143 work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
145 work_conn+=nbOfValsToCopy+1;
146 work_conn_index_for_interp++;
150 const ParaMEDMEM::MEDCoupling1DGTUMesh *m2(dynamic_cast<const ParaMEDMEM::MEDCoupling1DGTUMesh *>(_mesh));
153 int nbOfCell(m2->getNumberOfCells());
154 _conn_index_for_interp=new int[nbOfCell+1];
155 const int *conni(m2->getNodalConnectivityIndex()->begin());
156 std::copy(conni,conni+nbOfCell+1,_conn_index_for_interp);
157 _conn_for_interp=new int[m2->getNodalConnectivity()->getNumberOfTuples()];
158 std::copy(m2->getNodalConnectivity()->begin(),m2->getNodalConnectivity()->end(),_conn_for_interp);
161 const ParaMEDMEM::MEDCoupling1SGTUMesh *m3(dynamic_cast<const ParaMEDMEM::MEDCoupling1SGTUMesh *>(_mesh));
164 int nbOfCell(m3->getNumberOfCells()),nbNodesPerCell(m3->getNumberOfNodesPerCell());
165 _conn_index_for_interp=new int[nbOfCell+1]; _conn_index_for_interp[0]=0;
166 int *work(_conn_index_for_interp);
167 for(int i=0;i<nbOfCell;i++,work++)
168 work[1]=work[0]+nbNodesPerCell;
169 _conn_for_interp=new int[m3->getNodalConnectivity()->getNumberOfTuples()];
170 std::copy(m3->getNodalConnectivity()->begin(),m3->getNodalConnectivity()->end(),_conn_for_interp);
173 throw INTERP_KERNEL::Exception("MEDCouplingNormalizedUnstructuredMesh::prepare : Unrecognized unstructured mesh ! Type must be in MEDCouplingUMesh, MEDCoupling1DGTUMesh, MEDCoupling1SGTUMesh !");