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)
21 #include "MEDCoupling1GTUMesh.hxx"
23 using namespace ParaMEDMEM;
25 MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const char *meshName, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
27 if(type==INTERP_KERNEL::NORM_ERROR)
28 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
29 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
31 return MEDCoupling1SGTUMesh::New(meshName,type);
32 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : not implemented yet !");
35 const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception)
40 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getCellModelEnum() const throw(INTERP_KERNEL::Exception)
45 int MEDCoupling1GTUMesh::getMeshDimension() const
47 return (int)_cm.getDimension();
51 * This method returns a newly allocated array containing cell ids (ascendingly sorted) whose geometric type are equal to type.
52 * This method does not throw exception if geometric type \a type is not in \a this.
53 * This method throws an INTERP_KERNEL::Exception if meshdimension of \b this is not equal to those of \b type.
54 * The coordinates array is not considered here.
56 * \param [in] type the geometric type
57 * \return cell ids in this having geometric type \a type.
59 DataArrayInt *MEDCoupling1GTUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
61 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
62 if(type==getCellModelEnum())
63 ret->alloc(getNumberOfCells(),1);
71 * Returns nb of cells having the geometric type \a type. No throw if no cells in \a this has the geometric type \a type.
73 int MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
75 return type==getCellModelEnum()?getNumberOfCells():0;
79 * Returns a type of a cell by its id.
80 * \param [in] cellId - the id of the cell of interest.
81 * \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type.
82 * \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ).
84 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(int cellId) const
86 if(cellId>=0 && cellId<getNumberOfCells())
87 return getCellModelEnum();
88 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << getNumberOfCells() << ") !";
89 throw INTERP_KERNEL::Exception(oss.str().c_str());
93 * Returns a set of all cell types available in \a this mesh.
94 * \return std::set<INTERP_KERNEL::NormalizedCellType> - the set of cell types.
95 * \warning this method does not throw any exception even if \a this is not defined.
97 std::set<INTERP_KERNEL::NormalizedCellType> MEDCoupling1GTUMesh::getAllGeoTypes() const
99 std::set<INTERP_KERNEL::NormalizedCellType> ret;
100 ret.insert(getCellModelEnum());
105 * This method expects that \a this is sorted by types. If not an exception will be thrown.
106 * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how
107 * \a this is composed in cell types.
108 * The returned array is of size 3*n where n is the number of different types present in \a this.
109 * For every k in [0,n] ret[3*k+2]==0 because it has no sense here.
110 * This parameter is kept only for compatibility with other methode listed above.
112 std::vector<int> MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
114 std::vector<int> ret(3);
115 ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=0;
120 * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in \a profile it returns a list of sub-profiles sorted by geo type.
121 * The result is put in the array \a idsPerType. In the returned parameter \a code, foreach i \a code[3*i+2] refers (if different from -1) to a location into the \a idsPerType.
122 * This method has 1 input \a profile and 3 outputs \a code \a idsInPflPerType and \a idsPerType.
124 * \param [out] code is a vector of size 3*n where n is the number of different geometric type in \a this \b reduced to the profile \a profile. \a code has exactly the same semantic than in MEDCouplingUMesh::checkTypeConsistencyAndContig method.
125 * \param [out] idsInPflPerType is a vector of size of different geometric type in the subpart defined by \a profile of \a this ( equal to \a code.size()/3). For each i,
126 * \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0]
127 * \param [out] idsPerType is a vector of size of different sub profiles needed to be defined to represent the profile \a profile for a given geometric type.
128 * This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile.
130 * \warning for performance reasons no deep copy will be performed, if \a profile can been used as this in output parameters \a idsInPflPerType and \a idsPerType.
132 * \throw if \a profile has not exactly one component. It throws too, if \a profile contains some values not in [0,getNumberOfCells()) or if \a this is not fully defined
134 void MEDCoupling1GTUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
137 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile is NULL !");
138 if(profile->getNumberOfComponents()!=1)
139 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile should have exactly one component !");
140 int nbOfCells=getNumberOfCells();