From: ageay Date: Wed, 13 Feb 2013 07:52:46 +0000 (+0000) Subject: MEDCouplingFieldDouble::copyAllTinyAttrFrom X-Git-Tag: V6_main_FINAL~360 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e4ae3b9ac9f035c5256225d412b97621bf68884e;p=tools%2Fmedcoupling.git MEDCouplingFieldDouble::copyAllTinyAttrFrom --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index da93e7a6e..7a11d759d 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -395,3 +395,15 @@ int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL: else throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfMeshPlacesExpected : Empty mesh !"); } + +/*! + * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason). + */ +void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception) +{ + if(other) + { + setName(other->_name.c_str()); + setDescription(other->_desc.c_str()); + } +} diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 6dbe8bfdd..06f5f5969 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -50,6 +50,7 @@ namespace ParaMEDMEM virtual bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception); virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + virtual void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); const ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } void setName(const char *name) { _name=name; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index f2fb7e1bd..03d44c8d0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -176,13 +176,13 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfT /*! * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason). */ -void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception) { - if(other) + MEDCouplingField::copyTinyStringsFrom(other); + const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + if(otherC) { - setName(other->_name.c_str()); - setDescription(other->_desc.c_str()); - _time_discr->copyTinyStringsFrom(*other->_time_discr); + _time_discr->copyTinyStringsFrom(*otherC->_time_discr); } } @@ -196,6 +196,13 @@ void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *othe { _time_discr->copyTinyAttrFrom(*other->_time_discr); } + +} + +void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception) +{ + copyTinyStringsFrom(other); + copyTinyAttrFrom(other); } std::string MEDCouplingFieldDouble::simpleRepr() const diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 3b275f9de..da5e01ba0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -38,8 +38,9 @@ namespace ParaMEDMEM void setTimeUnit(const char *unit); const char *getTimeUnit() const; void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception); - void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 01e5d0319..033fe91b2 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -138,7 +138,7 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFiel if(_src_method!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(_target_method.c_str()),srcField->getTimeDiscretization()); - ret->copyTinyAttrFrom(srcField); + ret->copyAllTinyAttrFrom(srcField); ret->setNature(srcField->getNature()); ret->setMesh(_target_mesh); transfer(srcField,ret,dftValue); @@ -150,7 +150,7 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::reverseTransferField(const MEDCoupl if(_target_method!=targetField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(_src_method.c_str()),targetField->getTimeDiscretization()); - ret->copyTinyAttrFrom(targetField); + ret->copyAllTinyAttrFrom(targetField); ret->setNature(targetField->getNature()); ret->setMesh(_src_mesh); reverseTransfer(ret,targetField,dftValue); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 8f47503cf..08f54bc23 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -6353,6 +6353,7 @@ namespace ParaMEDMEM virtual bool areCompatibleForMerge(const MEDCouplingField *other) const throw(INTERP_KERNEL::Exception); virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); + virtual void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); void setName(const char *name) throw(INTERP_KERNEL::Exception); const char *getDescription() const throw(INTERP_KERNEL::Exception); @@ -6503,8 +6504,8 @@ namespace ParaMEDMEM void setTimeUnit(const char *unit); const char *getTimeUnit() const; void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception); - void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 6472477ec..b22ebf533 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -40,7 +40,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass array.setValues(ptr,sourceMesh.getNumberOfCells(),1); srcField.setArray(array); + srcField.setName("abc") ; srcField.setDescription("def") + srcField.setTime(7.7,9,10) trgfield=remapper.transferField(srcField,4.57); + self.assertEqual("abc",trgfield.getName()) + self.assertEqual("def",trgfield.getDescription()) + a,b,c=trgfield.getTime() + self.assertAlmostEqual(7.7,a,14) + self.assertEqual(b,9) + self.assertEqual(c,10) values=trgfield.getArray().getValues(); valuesExpected=[7.5 ,7. ,7.,8.,7.5]; for i in xrange(targetMesh.getNumberOfCells()): @@ -330,10 +338,17 @@ class MEDCouplingBasicsTest(unittest.TestCase): f.setArray(f.getArray()[n2o]) f.checkCoherency() f.setNature(ConservativeVolumic) + f.setTime(5.6,7,8) + f.setName("toto") ; f.setDescription("aDescription") p=MEDCouplingRemapper() p.setP1P0BaryMethod(True) p.prepare(um,um,"P1P0") fNode=p.reverseTransferField(f,1e300) + self.assertEqual("toto",fNode.getName()) + self.assertEqual("aDescription",fNode.getDescription()) + a,b,c=fNode.getTime() + self.assertAlmostEqual(5.6,a,14) + self.assertEqual(7,b) ; self.assertEqual(8,c) # integExpected=34.328125 self.assertAlmostEqual(fNode.integral(False)[0],integExpected,14)