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 #include "MEDCouplingUMesh.hxx"
20 #include "CellModel.hxx"
24 using namespace ParaMEDMEM;
26 MEDCouplingUMesh *MEDCouplingUMesh::New()
28 return new MEDCouplingUMesh;
31 void MEDCouplingUMesh::updateTime()
35 updateTimeWith(*_nodal_connec);
37 if(_nodal_connec_index)
39 updateTimeWith(*_nodal_connec_index);
43 updateTimeWith(*_coords);
47 MEDCouplingUMesh::MEDCouplingUMesh():_iterator(-1),_mesh_dim(-1),
48 _nodal_connec(0),_nodal_connec_index(0),_coords(0)
52 void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
54 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
56 if(INTERP_KERNEL::CellModel::getCellModel(*iter).getDimension()!=_mesh_dim)
58 std::ostringstream message;
59 message << "Mesh invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter);
60 throw INTERP_KERNEL::Exception(message.str().c_str());
65 void MEDCouplingUMesh::setMeshDimension(unsigned meshDim)
71 void MEDCouplingUMesh::allocateCells(int nbOfCells)
73 if(_nodal_connec_index)
75 _nodal_connec_index->decrRef();
79 _nodal_connec->decrRef();
82 _nodal_connec_index=DataArrayInt::New();
83 _nodal_connec_index->alloc(nbOfCells+1,1);
84 int *pt=_nodal_connec_index->getPointer();
86 _nodal_connec=DataArrayInt::New();
87 _nodal_connec->alloc(2*nbOfCells,1);
93 void MEDCouplingUMesh::setCoords(DataArrayDouble *coords)
95 if( coords != _coords )
106 void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell)
108 int *pt=_nodal_connec_index->getPointer();
109 int idx=pt[_iterator];
111 _nodal_connec->writeOnPlace(idx,type,nodalConnOfCell,size);
113 pt[++_iterator]=idx+size+1;
116 void MEDCouplingUMesh::finishInsertingCells()
118 int *pt=_nodal_connec_index->getPointer();
119 int idx=pt[_iterator];
121 _nodal_connec->reAlloc(idx);
122 _nodal_connec_index->reAlloc(_iterator+1);
126 INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::getTypeOfCell(int cellId) const
128 int *ptI=_nodal_connec_index->getPointer();
129 int *pt=_nodal_connec->getPointer();
130 return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]];
133 int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const
135 int *ptI=_nodal_connec_index->getPointer();
136 return ptI[cellId+1]-ptI[cellId]-1;
139 void MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes)
141 if(_nodal_connec!=conn)
144 _nodal_connec->decrRef();
147 _nodal_connec->incrRef();
149 if(_nodal_connec_index!=connIndex)
151 if(_nodal_connec_index)
152 _nodal_connec_index->decrRef();
153 _nodal_connec_index=connIndex;
154 if(_nodal_connec_index)
155 _nodal_connec_index->incrRef();
161 MEDCouplingUMesh::~MEDCouplingUMesh()
164 _nodal_connec->decrRef();
165 if(_nodal_connec_index)
166 _nodal_connec_index->decrRef();
171 void MEDCouplingUMesh::computeTypes()
173 if(_nodal_connec && _nodal_connec_index)
176 const int *conn=_nodal_connec->getPointer();
177 const int *connIndex=_nodal_connec_index->getPointer();
178 int nbOfElem=_nodal_connec_index->getNbOfElems()-1;
179 for(const int *pt=connIndex;pt!=connIndex+nbOfElem;pt++)
180 _types.insert((INTERP_KERNEL::NormalizedCellType)conn[*pt]);
184 bool MEDCouplingUMesh::isStructured() const
189 int MEDCouplingUMesh::getNumberOfCells() const
191 if(_nodal_connec_index)
193 return _nodal_connec_index->getNumberOfTuples()-1;
197 throw INTERP_KERNEL::Exception("Unable to get number of cells because no coordinates specified !");
200 int MEDCouplingUMesh::getNumberOfNodes() const
203 return _coords->getNumberOfTuples();
205 throw INTERP_KERNEL::Exception("Unable to get number of nodes because no coordinates specified !");
208 int MEDCouplingUMesh::getSpaceDimension() const
211 return _coords->getNumberOfComponents();
213 throw INTERP_KERNEL::Exception("Unable to get space dimension because no coordinates specified !");
216 int MEDCouplingUMesh::getMeshLength() const
218 return _nodal_connec->getNbOfElems();