}
}
+int MEDCouplingCMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+{
+ int ret=getNumberOfCells();
+ int dim=getMeshDimension();
+ switch(type)
+ {
+ case INTERP_KERNEL::NORM_HEXA8:
+ if(dim==3)
+ return ret;
+ case INTERP_KERNEL::NORM_QUAD4:
+ if(dim==2)
+ return ret;
+ case INTERP_KERNEL::NORM_SEG2:
+ if(dim==1)
+ return ret;
+ default:
+ throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingCMesh::getTypeOfCell !");
+ }
+ return 0;
+}
+
void MEDCouplingCMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
{
//not implemented yet
int getNodeIdFromPos(int i, int j, int k) const;
static void getPosFromId(int nodeId, int spaceDim, const int *split, int *res);
INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+ int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const;
DataArrayDouble *getCoordsAt(int i) const throw(INTERP_KERNEL::Exception);
return INTERP_KERNEL::CellModel::getCellModel(tmp).getExtrudedType();
}
+int MEDCouplingExtrudedMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+{
+ int ret=0;
+ int nbOfCells2D=_mesh2D->getNumberOfCells();
+ for(int i=0;i<nbOfCells2D;i++)
+ {
+ INTERP_KERNEL::NormalizedCellType t=_mesh2D->getTypeOfCell(i);
+ if(INTERP_KERNEL::CellModel::getCellModel(t).getExtrudedType()==type)
+ ret++;
+ }
+ return ret*_mesh1D->getNumberOfCells();
+}
+
void MEDCouplingExtrudedMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
{
int nbOfCells2D=_mesh2D->getNumberOfCells();
MEDCouplingExtrudedMesh *clone(bool recDeepCpy) const;
bool isEqual(const MEDCouplingMesh *other, double prec) const;
INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+ int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const;
void checkCoherency() const throw (INTERP_KERNEL::Exception);
return _type->getGaussLocalization(locId);
}
+/*!
+ * This method returns reference to the Gauss localization object corresponding to 'locId' id.
+ * This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) and if several localization ids have been found
+ * for a type.
+ */
+int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneType method !");
+ return _type->getGaussLocalizationIdOfOneType(type);
+}
+
/*!
* This method returns number of Gauss localization available. Implicitely all ids in [0,getNbOfGaussLocalization()) is a valid Gauss localisation id.
* This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss)
const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception);
void clearGaussLocalizations();
MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception);
+ int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception);
int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception);
void getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception);
#include "InterpolationUtils.hxx"
+#include <set>
#include <limits>
#include <algorithm>
#include <functional>
throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
}
+int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+ throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
+}
+
void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
for(int i=0;i<nbCells;i++)
if(m->getTypeOfCell(i)==type)
ptr[i]=id;
+ zipGaussLocalizations();
}
void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector<double>& refCoo,
ptr[*w2]=id;
//
_loc.push_back(elt);
+ zipGaussLocalizations();
}
void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP_KERNEL::Exception)
return locId;
}
+int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+ if(!_discr_per_cell)
+ throw INTERP_KERNEL::Exception("No Gauss localization still set !");
+ std::set<int> ret;
+ int id=0;
+ for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++)
+ if((*iter).getType()==type)
+ ret.insert(id);
+ if(ret.empty())
+ throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
+ if(ret.size()>1)
+ throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
+ return *ret.begin();
+}
+
void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
{
if(locId<0 || locId>=_loc.size())
return ret;
}
+/*!
+ * This method makes the assumption that _discr_per_cell is set.
+ * This method reduces as much as possible number size of _loc.
+ * This method is usefull when several set on same cells has been done and that some Gauss Localization are no more used.
+ */
+void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations()
+{
+ const int *start=_discr_per_cell->getConstPointer();
+ int nbOfTuples=_discr_per_cell->getNumberOfTuples();
+ int *tmp=new int[_loc.size()];
+ std::fill(tmp,tmp+_loc.size(),-2);
+ for(const int *w=start;w!=start+nbOfTuples;w++)
+ if(*w>=0)
+ tmp[*w]=1;
+ int fid=0;
+ for(int i=0;i<_loc.size();i++)
+ if(tmp[i]!=-2)
+ tmp[i]=fid++;
+ if(fid==_loc.size())
+ {//no zip needed
+ delete [] tmp;
+ return;
+ }
+ // zip needed
+ int *start2=_discr_per_cell->getPointer();
+ for(int *w2=start2;w2!=start2+nbOfTuples;w2++)
+ *w2=tmp[*w2];
+ std::vector<MEDCouplingGaussLocalization> tmpLoc;
+ for(int i=0;i<_loc.size();i++)
+ if(tmp[i]!=-2)
+ tmpLoc.push_back(_loc[tmp[i]]);
+ delete [] tmp;
+ _loc=tmpLoc;
+}
+
MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE()
{
}
virtual MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception);
virtual int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception);
virtual int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception);
+ virtual int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
virtual void getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception);
virtual const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception);
virtual ~MEDCouplingFieldDiscretization();
MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception);
int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception);
int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception);
+ int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
void getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception);
const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception);
protected:
MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other);
+ void zipGaussLocalizations();
int getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception);
void checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception);
public:
return true;
}
-double ParaMEDMEM::MEDCouplingGaussLocalization::getRefCoords(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception)
+double ParaMEDMEM::MEDCouplingGaussLocalization::getRefCoord(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception)
{
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type);
int nbNodes=cm.getNumberOfNodes();
* This method sets the comp_th component of ptIdInCell_th point coordinate of reference element of type this->_type.
* @throw if not 0<=ptIdInCell<nbOfNodePerCell or if not 0<=comp<dim
*/
-void ParaMEDMEM::MEDCouplingGaussLocalization::setRefCoords(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception)
+void ParaMEDMEM::MEDCouplingGaussLocalization::setRefCoord(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception)
{
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type);
int nbNodes=cm.getNumberOfNodes();
void pushTinySerializationDblInfo(std::vector<double>& tinyInfo) const;
const double *fillWithValues(const double *vals);
//
- double getRefCoords(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception);
+ const std::vector<double>& getRefCoords() const { return _ref_coord; }
+ double getRefCoord(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception);
+ const std::vector<double>& getGaussCoords() const { return _gauss_coord; }
double getGaussCoord(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception);
+ const std::vector<double>& getWeights() const { return _weight; }
double getWeight(int gaussPtIdInCell, double newVal) const throw(INTERP_KERNEL::Exception);
- void setRefCoords(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception);
+ void setRefCoord(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception);
void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception);
void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception);
//
virtual int getMeshDimension() const = 0;
virtual DataArrayDouble *getCoordinatesAndOwner() const = 0;
virtual DataArrayDouble *getBarycenterAndOwner() const = 0;
+ virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0;
virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0;
virtual void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const = 0;
virtual void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const = 0;
#include <sstream>
#include <numeric>
+#include <cstring>
#include <limits>
#include <list>
return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]];
}
+/*!
+ * Returns nb of cells having the geometric type 'type'.
+ */
+int MEDCouplingUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+{
+ const int *ptI=_nodal_connec_index->getConstPointer();
+ const int *pt=_nodal_connec->getConstPointer();
+ int nbOfCells=getNumberOfCells();
+ int ret=0;
+ for(int i=0;i<nbOfCells;i++)
+ if((INTERP_KERNEL::NormalizedCellType) pt[ptI[i]]==type)
+ ret++;
+ return ret;
+}
+
/*!
* Appends the nodal connectivity in 'conn' of cell with id 'cellId'.
*/
{
checkFullyDefined();
MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
- std::ostringstream stream; stream << PART_OF_NAME << getName();
- ret->setName(stream.str().c_str());
+ std::string name(getName());
+ int sz=strlen(PART_OF_NAME);
+ if(name.length()>=sz)
+ name=name.substr(0,sz);
+ if(name!=PART_OF_NAME)
+ {
+ std::ostringstream stream; stream << PART_OF_NAME << getName();
+ ret->setName(stream.str().c_str());
+ }
+ else
+ ret->setName(getName());
ret->_mesh_dim=_mesh_dim;
ret->setCoords(_coords);
int nbOfElemsRet=end-start;
MEDCOUPLING_EXPORT DataArrayInt *getNodalConnectivity() const { return _nodal_connec; }
MEDCOUPLING_EXPORT DataArrayInt *getNodalConnectivityIndex() const { return _nodal_connec_index; }
MEDCOUPLING_EXPORT INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+ MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const;
MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const;
return (INTERP_KERNEL::NormalizedCellType)desc_connec[desc_connec_index[cellId]+1];
}
+int MEDCouplingUMeshDesc::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+{
+ const int *desc_connec=_desc_connec->getConstPointer();
+ const int *desc_connec_index=_desc_connec_index->getConstPointer();
+ int nbOfCells=getNumberOfCells();
+ int ret=0;
+ for(int i=0;i<nbOfCells;i++)
+ if((INTERP_KERNEL::NormalizedCellType) desc_connec[desc_connec_index[i]]==type)
+ ret++;
+ return ret;
+}
+
void MEDCouplingUMeshDesc::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
{
//not implemented yet.
MEDCOUPLING_EXPORT int getFaceMeshLength() const;
MEDCOUPLING_EXPORT int getMeshDimension() const { return _mesh_dim; }
MEDCOUPLING_EXPORT INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+ MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const;
MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const { return UNSTRUCTURED_DESC; }
CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
+ const int tab3[3]={0,1,2};
+ MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
subMesh->decrRef();
+ name=subMeshSimple2->getName();
+ CPPUNIT_ASSERT(name=="PartOf_Toto");
+ subMeshSimple2->decrRef();
//
mesh->decrRef();
}
self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems());
self.assertEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues());
self.assertEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues());
+ subMesh=subMesh.buildPartOfMySelf(range(3),True);
+ self.assertEqual("PartOf_Toto",subMesh.getName());
pass
def testBuildPartOfMySelfNode(self):
mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
%newobject MEDLoader::ReadFieldDouble;
%newobject MEDLoader::ReadFieldDoubleCell;
%newobject MEDLoader::ReadFieldDoubleNode;
+%newobject MEDLoader::ReadFieldDoubleGauss;
+%newobject MEDLoader::ReadFieldDoubleGaussNE;
class MEDLoader
{
public:
+ static void setEpsilonForNodeComp(double val);
+ static void setCompPolicyForCell(int val);
+ static void setTooLongStrPolicy(int val);
static std::vector<std::string> GetMeshNames(const char *fileName);
static std::vector<std::string> GetMeshGroupsNames(const char *fileName, const char *meshName);
static std::vector<std::string> GetMeshFamilyNames(const char *fileName, const char *meshName);
static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
+ static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
+ static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch);
static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f);