From: ageay Date: Wed, 10 Jul 2013 15:19:20 +0000 (+0000) Subject: With omniorbpy it will be better.... X-Git-Tag: B4KillOfAutomake~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=84be5c335fc1bace9be13dcaae925e222c04c629;p=modules%2Fmed.git With omniorbpy it will be better.... --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index e189f32be..573ce9f55 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -609,3 +609,28 @@ void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other) throw( setDescription(other->_desc.c_str()); } } + +/*! + * This method computes the number of tuples a DataArrayDouble instance should have to build a correct MEDCouplingFieldDouble instance starting from a + * submesh of a virtual mesh on which a substraction per type had been applied regarding the spatial discretization in \a this. + * + * For spatial discretization \b not equal to ON_GAUSS_NE this method will make the hypothesis that any positive entity id in \a code \a idsPerType is valid. + * So in those cases attribute \a _mesh of \a this is ignored. + * + * For spatial discretization equal to ON_GAUSS_NE \a _mesh attribute will be taken into account. + * + * The input code is those implemented in MEDCouplingUMesh::splitProfilePerType. + * + * \param [in] code - a code with format described above. + * \param [in] idsPerType - a list of subparts + * \throw If \a this has no spatial discretization set. + * \throw If input code point to invalid zones in spatial discretization. + * \throw If spatial discretization in \a this requires a mesh and those mesh is invalid (null,...) + */ +int MEDCouplingField::getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingFieldDiscretization *t(_type); + if(!t) + throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfTuplesExpectedRegardingCode : no spatial discretization set !"); + return t->getNumberOfTuplesExpectedRegardingCode(_mesh,code,idsPerType); +} diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index ed37178f7..52a2b92c0 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -85,6 +85,8 @@ namespace ParaMEDMEM const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); void updateTime() const; std::size_t getHeapMemorySize() const; + // for MED file RW + int getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); virtual void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCouplingField(TypeOfField type); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index bb7587bc3..ec5661169 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -479,6 +479,41 @@ int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *m return mesh->getNumberOfCells(); } +/*! + * mesh is not used here. It is not a bug ! + */ +int MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + return ret; +} + int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { if(!mesh) @@ -684,6 +719,41 @@ int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMe return mesh->getNumberOfNodes(); } +/*! + * mesh is not used here. It is not a bug ! + */ +int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + return ret; +} + int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { if(!mesh) @@ -789,7 +859,7 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(co /*! * This method returns a tuple ids selection from cell ids selection [start;end). - * This method is called by MEDCouplingFieldDiscretizationP0::buildSubMeshData to return parameter \b di. + * This method is called by MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData to return parameter \b di. * Here for P1 only nodes fetched by submesh of mesh[startCellIds:endCellIds) is returned ! * * \return a newly allocated array containing ids to select into the DataArrayDouble of the field. @@ -1248,6 +1318,47 @@ const char *MEDCouplingFieldDiscretizationGauss::getRepr() const return REPR; } +/*! + * mesh is not used here. It is not a bug ! + */ +int MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + if(!_discr_per_cell || _discr_per_cell->isAllocated() || _discr_per_cell->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode"); + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + if(ret!=_discr_per_cell->getNumberOfTuples()) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " cells whereas discretization percell array lgth is " << _discr_per_cell->getNumberOfTuples() << " !"; + } + return getNumberOfTuples(0);//0 is not an error ! It is to be sure that input mesh is not used +} + int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const throw(INTERP_KERNEL::Exception) { int ret=0; @@ -1925,6 +2036,44 @@ bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFie return ret; } +int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : NULL input mesh !"); + if(ret!=mesh->getNumberOfCells()) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " number of cells should be " << mesh->getNumberOfCells() << " !"; + } + return getNumberOfTuples(mesh); +} + int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { if(!mesh) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 962f6fd8c..84b39ca47 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -59,6 +59,7 @@ namespace ParaMEDMEM virtual MEDCouplingFieldDiscretization *clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const; virtual std::string getStringRepr() const = 0; virtual const char *getRepr() const = 0; + virtual int getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) = 0; virtual int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const = 0; virtual DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const = 0; @@ -120,6 +121,7 @@ namespace ParaMEDMEM std::string getStringRepr() const; const char *getRepr() const; bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const; + int getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; @@ -150,6 +152,7 @@ namespace ParaMEDMEM { public: int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); + int getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, @@ -230,6 +233,7 @@ namespace ParaMEDMEM std::string getStringRepr() const; const char *getRepr() const; std::size_t getHeapMemorySize() const; + int getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; @@ -297,6 +301,7 @@ namespace ParaMEDMEM std::string getStringRepr() const; const char *getRepr() const; bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const; + int getNumberOfTuplesExpectedRegardingCode(const MEDCouplingMesh *mesh, const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const;