From 865eac01b8bdd7a4494afd632f23ac6a1fcc0c88 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 30 Dec 2015 18:54:49 +0100 Subject: [PATCH] Now deal with Cylindric, Spheric coordinates for UMesh, CLMesh, And only Cylindric for CMesh (MED file extension needed). --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 2 +- src/MEDCoupling/MEDCouplingCMesh.cxx | 28 +- src/MEDCoupling/MEDCouplingCMesh.hxx | 3 + src/MEDCoupling/MEDCouplingMemArray.cxx | 82 ++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 9 + src/MEDCoupling/MEDCouplingMesh.hxx | 1 + .../MEDCouplingBasicsTest5.py | 37 ++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 14 +- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 9 + src/MEDLoader/MEDFileMesh.cxx | 171 +++++++-- src/MEDLoader/MEDFileMesh.hxx | 11 +- src/MEDLoader/MEDFileMeshLL.cxx | 127 ++++++- src/MEDLoader/MEDFileMeshLL.hxx | 12 +- src/MEDLoader/Swig/MEDLoaderCommon.i | 6 + src/MEDLoader/Swig/MEDLoaderTest3.py | 105 ++++++ src/MEDLoader/Swig/MEDLoaderTest4.py | 334 ++++++++++++++++-- 16 files changed, 831 insertions(+), 120 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 38eae7a7e..cea42c447 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -2163,7 +2163,7 @@ MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const std::string& name, const INTERP { } -MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn) +MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn_indx(other._conn_indx),_conn(other._conn) { if(recDeepCpy) { diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 597b682a6..c0771916e 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -21,6 +21,9 @@ #include "MEDCouplingCMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" #include #include @@ -81,7 +84,7 @@ MEDCouplingCMesh *MEDCouplingCMesh::New() MEDCouplingCMesh *MEDCouplingCMesh::New(const std::string& meshName) { - MEDCouplingCMesh *ret=new MEDCouplingCMesh; + MEDCouplingCMesh *ret(new MEDCouplingCMesh); ret->setName(meshName); return ret; } @@ -96,6 +99,20 @@ MEDCouplingCMesh *MEDCouplingCMesh::clone(bool recDeepCpy) const return new MEDCouplingCMesh(*this,recDeepCpy); } +MEDCouplingCurveLinearMesh *MEDCouplingCMesh::buildCurveLinear() const +{ + checkCoherency(); + int dim(getSpaceDimension()); + MEDCouplingAutoRefCountObjectPtr ret(MEDCouplingCurveLinearMesh::New()); + ret->MEDCouplingStructuredMesh::operator=(*this); + INTERP_KERNEL::AutoPtr ngs(new int[dim]); + getNodeGridStructure(ngs); + ret->setNodeGridStructure(ngs,ngs+dim); + MEDCouplingAutoRefCountObjectPtr coo(getCoordinatesAndOwner()); + ret->setCoords(coo); + return ret.retn(); +} + void MEDCouplingCMesh::updateTime() const { if(_x_array) @@ -679,11 +696,10 @@ MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) */ DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const { - DataArrayDouble *ret=DataArrayDouble::New(); - int spaceDim=getSpaceDimension(); - int nbNodes=getNumberOfNodes(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + int spaceDim(getSpaceDimension()),nbNodes(getNumberOfNodes()); ret->alloc(nbNodes,spaceDim); - double *pt=ret->getPointer(); + double *pt(ret->getPointer()); int tmp[3]; getSplitNodeValues(tmp); const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)}; @@ -700,7 +716,7 @@ DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const for(int j=0;j getDirectChildrenWithNull() const; diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 72d3a1fe3..709fd85cd 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -3567,14 +3567,14 @@ DataArrayDouble *DataArrayDouble::accumulatePerChunck(const int *bgOfIndex, cons DataArrayDouble *DataArrayDouble::fromPolarToCart() const { checkAllocated(); - int nbOfComp=getNumberOfComponents(); + int nbOfComp(getNumberOfComponents()); if(nbOfComp!=2) throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !"); - int nbOfTuple=getNumberOfTuples(); - DataArrayDouble *ret=DataArrayDouble::New(); + int nbOfTuple(getNumberOfTuples()); + DataArrayDouble *ret(DataArrayDouble::New()); ret->alloc(nbOfTuple,2); - double *w=ret->getPointer(); - const double *wIn=getConstPointer(); + double *w(ret->getPointer()); + const double *wIn(getConstPointer()); for(int i=0;ialloc(getNumberOfTuples(),3); - double *w=ret->getPointer(); - const double *wIn=getConstPointer(); + double *w(ret->getPointer()); + const double *wIn(getConstPointer()); for(int i=0;ialloc(getNumberOfTuples(),3); - double *w=ret->getPointer(); - const double *wIn=getConstPointer(); + double *w(ret->getPointer()); + const double *wIn(getConstPointer()); for(int i=0;i ret; + switch(atOfThis) + { + case AX_CART: + ret=deepCpy(); + case AX_CYL: + if(nbOfComp==3) + { + ret=fromCylToCart(); + break; + } + if(nbOfComp==2) + { + ret=fromPolarToCart(); + break; + } + else + throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : For AX_CYL, number of components must be in [2,3] !"); + case AX_SPHER: + if(nbOfComp==3) + { + ret=fromSpherToCart(); + break; + } + if(nbOfComp==2) + { + ret=fromPolarToCart(); + break; + } + else + throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : For AX_CYL, number of components must be in [2,3] !"); + default: + throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : not recognized axis type ! Only AX_CART, AX_CYL and AX_SPHER supported !"); + } + ret->copyStringInfoFrom(*this); + return ret.retn(); +} + /*! * Computes the doubly contracted product of every tensor defined by the tuple of \a this * array contating 6 components. @@ -3658,7 +3708,7 @@ DataArrayDouble *DataArrayDouble::fromSpherToCart() const DataArrayDouble *DataArrayDouble::doublyContractedProduct() const { checkAllocated(); - int nbOfComp=getNumberOfComponents(); + int nbOfComp(getNumberOfComponents()); if(nbOfComp!=6) throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !"); DataArrayDouble *ret=DataArrayDouble::New(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 201b7601e..66bbb6bd9 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -33,6 +33,14 @@ namespace ParaMEDMEM { + typedef enum + { + AX_CART = 3, + AX_CYL = 4, + AX_SPHER = 5 + } MEDCouplingAxisType; + // -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! -- + template class MEDCouplingPointer { @@ -323,6 +331,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *fromPolarToCart() const; MEDCOUPLING_EXPORT DataArrayDouble *fromCylToCart() const; MEDCOUPLING_EXPORT DataArrayDouble *fromSpherToCart() const; + MEDCOUPLING_EXPORT DataArrayDouble *cartesianize(MEDCouplingAxisType atOfThis) const; MEDCOUPLING_EXPORT DataArrayDouble *doublyContractedProduct() const; MEDCOUPLING_EXPORT DataArrayDouble *determinant() const; MEDCOUPLING_EXPORT DataArrayDouble *eigenValues() const; diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index b4a20e705..b748be981 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_unit=unit; } MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_unit; } MEDCOUPLING_EXPORT virtual MEDCouplingMesh *deepCpy() const = 0; + MEDCOUPLING_EXPORT virtual MEDCouplingMesh *clone(bool recDeepCpy) const = 0; MEDCOUPLING_EXPORT virtual MEDCouplingMeshType getType() const = 0; MEDCOUPLING_EXPORT bool isStructured() const; MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingMesh *other); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 5e4dc9a4e..cd110a899 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4214,6 +4214,43 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertTrue(d.isEqual(DataArrayInt([0]))) # <- bug was here pass + def testSwig2Cartesianize1(self): + """Test of engine of cartesianize mechanism in medcoupling""" + # cyl 2D + arr=DataArrayDouble([(3,0.2),(2,1.6)]) ; arr.setInfoOnComponents(["A","BB"]) + arr2=arr.cartesianize(AX_CYL) + arr2_exp=DataArrayDouble([(2.940199733523725,0.5960079923851836),(-0.05839904460257763,1.9991472060830102)]) ; arr2_exp.setInfoOnComponents(["A","BB"]) + self.assertTrue(arr2_exp.isEqual(arr2,1e-14)) + # spher 2D + arr3=arr.cartesianize(AX_SPHER) + self.assertTrue(arr2_exp.isEqual(arr3,1e-14)) + # cyl 3D + arr=DataArrayDouble([(3,0.2,7.1),(2,1.6,12.3)]) ; arr.setInfoOnComponents(["A","BB","CCC"]) + arr4=arr.cartesianize(AX_CYL) + arr4_exp=DataArrayDouble([(2.940199733523725,0.5960079923851836,7.1),(-0.05839904460257763,1.9991472060830102,12.3)]) ; arr4_exp.setInfoOnComponents(["A","BB","CCC"]) + self.assertTrue(arr4_exp.isEqual(arr4,1e-14)) + # spher 3D + arr=DataArrayDouble([(3,0.2,0.5),(2,1.3,5.8)]) ; arr.setInfoOnComponents(["A","BB","CCC"]) + arr5=arr.cartesianize(AX_SPHER) + arr5_exp=DataArrayDouble([(0.5230462208645272,0.2857414527616764,2.940199733523725),(1.706499157790973,-0.8953424658735863,0.5349976572491747)]) ; arr5_exp.setInfoOnComponents(["A","BB","CCC"]) + self.assertTrue(arr5_exp.isEqual(arr5,1e-14)) + # + m=MEDCouplingCMesh() ; m.setName("aa") ; m.setDescription("bbb") ; m.setTime(4.125,5,6) ; m.setTimeUnit("ms") + arrX=DataArrayDouble([0,1,2]) ; arrX.setInfoOnComponent(0,"ccc") + arrY=DataArrayDouble([3,4,5,6]) ; arrY.setInfoOnComponent(0,"dddd") + m.setCoords(arrX,arrY) + m2=m.buildCurveLinear() + # + self.assertTrue(isinstance(m2,MEDCouplingCurveLinearMesh)) + self.assertEqual(m2.getName(),"aa") + self.assertEqual(m2.getDescription(),"bbb") + self.assertEqual(m2.getTime(),[4.125,5,6]) + self.assertEqual(m2.getTimeUnit(),"ms") + m2c_exp=DataArrayDouble([(0.,3.),(1.,3.),(2.,3.),(0.,4.),(1.,4.),(2.,4.),(0.,5.),(1.,5.),(2.,5.),(0.,6.),(1.,6.),(2.,6.)]) ; m2c_exp.setInfoOnComponents(["ccc","dddd"]) + self.assertTrue(m2.getCoords().isEqual(m2c_exp,1e-14)) + self.assertEqual(m2.getNodeGridStructure(),(3,4)) + pass + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 8f1717456..6a6f64d0e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -230,6 +230,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getValueOnMulti; %newobject ParaMEDMEM::MEDCouplingFieldTemplate::New; %newobject ParaMEDMEM::MEDCouplingMesh::deepCpy; +%newobject ParaMEDMEM::MEDCouplingMesh::clone; %newobject ParaMEDMEM::MEDCouplingMesh::checkDeepEquivalOnSameNodesWith; %newobject ParaMEDMEM::MEDCouplingMesh::checkTypeConsistencyAndContig; %newobject ParaMEDMEM::MEDCouplingMesh::computeNbOfNodesPerCell; @@ -270,7 +271,6 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::New; %newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivity; %newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex; -%newobject ParaMEDMEM::MEDCouplingUMesh::clone; %newobject ParaMEDMEM::MEDCouplingUMesh::__iter__; %newobject ParaMEDMEM::MEDCouplingUMesh::cellsByType; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity; @@ -347,14 +347,13 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::ComputeCornersGhost; %newobject ParaMEDMEM::MEDCouplingCMesh::New; -%newobject ParaMEDMEM::MEDCouplingCMesh::clone; %newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt; +%newobject ParaMEDMEM::MEDCouplingCMesh::buildCurveLinear; %newobject ParaMEDMEM::MEDCouplingIMesh::New; %newobject ParaMEDMEM::MEDCouplingIMesh::asSingleCell; %newobject ParaMEDMEM::MEDCouplingIMesh::buildWithGhost; %newobject ParaMEDMEM::MEDCouplingIMesh::convertToCartesian; %newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::New; -%newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::clone; %newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::getCoords; %newobject ParaMEDMEM::MEDCouplingMultiFields::New; %newobject ParaMEDMEM::MEDCouplingMultiFields::deepCpy; @@ -554,7 +553,8 @@ namespace ParaMEDMEM std::string getTimeUnit() const; virtual MEDCouplingMeshType getType() const throw(INTERP_KERNEL::Exception); bool isStructured() const throw(INTERP_KERNEL::Exception); - virtual MEDCouplingMesh *deepCpy() const; + virtual MEDCouplingMesh *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingMesh *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); virtual bool isEqual(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); virtual void checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); @@ -1758,7 +1758,6 @@ namespace ParaMEDMEM public: static MEDCouplingUMesh *New() throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *New(const char *meshName, int meshDim) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *clone(bool recDeepCpy) const; void checkCoherency() const throw(INTERP_KERNEL::Exception); void setMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); @@ -3320,6 +3319,8 @@ namespace ParaMEDMEM } }; + class MEDCouplingCurveLinearMesh; + //== MEDCouplingCMesh class MEDCouplingCMesh : public ParaMEDMEM::MEDCouplingStructuredMesh @@ -3327,11 +3328,11 @@ namespace ParaMEDMEM public: static MEDCouplingCMesh *New() throw(INTERP_KERNEL::Exception); static MEDCouplingCMesh *New(const std::string& meshName) throw(INTERP_KERNEL::Exception); - MEDCouplingCMesh *clone(bool recDeepCpy) const; void setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY=0, const DataArrayDouble *coordsZ=0) throw(INTERP_KERNEL::Exception); void setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); + MEDCouplingCurveLinearMesh *buildCurveLinear() const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingCMesh() throw(INTERP_KERNEL::Exception) { @@ -3375,7 +3376,6 @@ namespace ParaMEDMEM public: static MEDCouplingCurveLinearMesh *New() throw(INTERP_KERNEL::Exception); static MEDCouplingCurveLinearMesh *New(const std::string& meshName) throw(INTERP_KERNEL::Exception); - MEDCouplingCurveLinearMesh *clone(bool recDeepCpy) const; void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); %extend { MEDCouplingCurveLinearMesh() throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 3e4010867..e47f1e1f2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -181,6 +181,7 @@ %newobject ParaMEDMEM::DataArrayDouble::fromPolarToCart; %newobject ParaMEDMEM::DataArrayDouble::fromCylToCart; %newobject ParaMEDMEM::DataArrayDouble::fromSpherToCart; +%newobject ParaMEDMEM::DataArrayDouble::cartesianize; %newobject ParaMEDMEM::DataArrayDouble::getDifferentValues; %newobject ParaMEDMEM::DataArrayDouble::findClosestTupleId; %newobject ParaMEDMEM::DataArrayDouble::computeNbOfInteractionsWith; @@ -203,6 +204,13 @@ namespace ParaMEDMEM { + typedef enum + { + AX_CART = 3, + AX_CYL = 4, + AX_SPHER = 5 + } MEDCouplingAxisType; + class DataArray : public RefCountObject, public TimeLabel { public: @@ -580,6 +588,7 @@ namespace ParaMEDMEM DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromSpherToCart() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *cartesianize(MEDCouplingAxisType atOfThis) const throw(INTERP_KERNEL::Exception); DataArrayDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); DataArrayDouble *determinant() const throw(INTERP_KERNEL::Exception); DataArrayDouble *eigenValues() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index f9ac17e96..6c5bd3afe 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -39,7 +39,7 @@ using namespace ParaMEDMEM; const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO"; -MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true) +MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true),_axis_type(AX_CART) { } @@ -87,7 +87,8 @@ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, MEDFileMeshReadSelect MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dt,it; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2); + ParaMEDMEM::MEDCouplingAxisType dummy3; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); MEDCouplingAutoRefCountObjectPtr ret; switch(meshType) { @@ -140,7 +141,8 @@ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, const std::string& mN MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dummy0,dummy1; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2); + ParaMEDMEM::MEDCouplingAxisType dummy3; + MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2); MEDCouplingAutoRefCountObjectPtr ret; switch(meshType) { @@ -2176,7 +2178,8 @@ MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, MEDFileMeshReadSele int dt,it; ParaMEDMEM::MEDCouplingMeshType meshType; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2); + ParaMEDMEM::MEDCouplingAxisType dummy3; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); return new MEDFileUMesh(fid,ms.front(),dt,it,mrs); } @@ -2247,7 +2250,7 @@ std::vector MEDFileUMesh::getDirectChildrenWithNull() c MEDFileMesh *MEDFileUMesh::shallowCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMesh(*this)); return ret.retn(); } @@ -2258,7 +2261,7 @@ MEDFileMesh *MEDFileUMesh::createNewEmpty() const MEDFileMesh *MEDFileUMesh::deepCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMesh(*this)); ret->deepCpyEquivalences(*this); if((const DataArrayDouble*)_coords) ret->_coords=_coords->deepCpy(); @@ -2457,7 +2460,8 @@ void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType meshType; int dummy0,dummy1; std::string dummy2; - int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2)); + ParaMEDMEM::MEDCouplingAxisType dummy3; + int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2)); if(meshType!=UNSTRUCTURED) { std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !"; @@ -2571,7 +2575,9 @@ void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, ParaMEDMEM::MEDCouplingMeshType meshType; int dummy0,dummy1; std::string dummy2; - int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2)); + ParaMEDMEM::MEDCouplingAxisType axType; + int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2)); + setAxType(axType); if(meshType!=UNSTRUCTURED) { std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !"; @@ -2637,7 +2643,7 @@ void MEDFileUMesh::writeLL(med_idt fid) const MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } - MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit)); + MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxType()),comp,unit)); if(_univ_wr_status) MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa)); std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE)); @@ -3140,6 +3146,28 @@ void MEDFileUMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, con } } +MEDFileMesh *MEDFileUMesh::cartesianize() const +{ + if(getAxType()==AX_CART) + { + incrRef(); + return const_cast(this); + } + else + { + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMesh(*this)); + const DataArrayDouble *coords(_coords); + if(!coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::cartesianize : coordinates are null !"); + MEDCouplingAutoRefCountObjectPtr coordsCart(_coords->cartesianize(getAxType())); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=ret->_ms.begin();it!=ret->_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)) + *it=(*it)->shallowCpyUsingCoords(coordsCart); + ret->_coords=coordsCart; + return ret.retn(); + } +} + /*! * Returns the optional numbers of mesh entities of a given dimension transformed using * DataArrayInt::invertArrayN2O2O2N(). @@ -3581,6 +3609,8 @@ void MEDFileUMesh::setCoords(DataArrayDouble *coords) { if(!coords) throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !"); + if(coords==(DataArrayDouble *)_coords) + return ; coords->checkAllocated(); int nbOfTuples=coords->getNumberOfTuples(); _coords=coords; @@ -4208,21 +4238,22 @@ void MEDFileUMesh::serialize(std::vector& tinyDouble, std::vector& forceComputationOfParts(); tinyDouble.clear(); tinyInt.clear(); tinyStr.clear(); bigArraysI.clear(); bigArrayD=0; std::vector layer0; - layer0.push_back(_order); //0 i - layer0.push_back(_iteration);//1 i - layer0.push_back(getSpaceDimension());//2 i + layer0.push_back(getAxType());//0 i + layer0.push_back(_order); //1 i + layer0.push_back(_iteration);//2 i + layer0.push_back(getSpaceDimension());//3 i tinyDouble.push_back(_time);//0 d tinyStr.push_back(_name);//0 s tinyStr.push_back(_desc_name);//1 s for(int i=0;igetInfoOnComponent(i)); - layer0.push_back((int)_families.size());//3 i <- key info aa layer#0 + layer0.push_back((int)_families.size());//4 i <- key info aa layer#0 for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) { tinyStr.push_back((*it).first); layer0.push_back((*it).second); } - layer0.push_back((int)_groups.size());//3+aa i <- key info bb layer#0 + layer0.push_back((int)_groups.size());//4+aa i <- key info bb layer#0 for(std::map >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++) { layer0.push_back((int)(*it0).second.size()); @@ -4230,7 +4261,7 @@ void MEDFileUMesh::serialize(std::vector& tinyDouble, std::vector& for(std::vector::const_iterator it1=((*it0).second).begin();it1!=((*it0).second).end();it1++) tinyStr.push_back(*it1); } - // sizeof(layer0)==3+aa+1+bb layer#0 + // sizeof(layer0)==4+aa+1+bb layer#0 bigArrayD=_coords;// 0 bd bigArraysI.push_back(_fam_coords);// 0 bi bigArraysI.push_back(_num_coords);// 1 bi @@ -4275,6 +4306,7 @@ void MEDFileUMesh::unserialize(std::vector& tinyDouble, std::vector std::reverse(tinyStr.begin(),tinyStr.end()); std::reverse(bigArraysI.begin(),bigArraysI.end()); // + setAxType((MEDCouplingAxisType)layer0.back()); layer0.pop_back(); _order=layer0.back(); layer0.pop_back(); _iteration=layer0.back(); layer0.pop_back(); int spaceDim(layer0.back()); layer0.pop_back(); @@ -5947,7 +5979,8 @@ MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSele int dt,it; ParaMEDMEM::MEDCouplingMeshType meshType; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2); + ParaMEDMEM::MEDCouplingAxisType dummy3; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); return new MEDFileCMesh(fid,ms.front(),dt,it,mrs); } @@ -6028,7 +6061,7 @@ std::string MEDFileCMesh::advancedRepr() const MEDFileMesh *MEDFileCMesh::shallowCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileCMesh(*this)); return ret.retn(); } @@ -6039,7 +6072,7 @@ MEDFileMesh *MEDFileCMesh::createNewEmpty() const MEDFileMesh *MEDFileCMesh::deepCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileCMesh(*this)); ret->deepCpyEquivalences(*this); if((const MEDCouplingCMesh*)_cmesh) ret->_cmesh=static_cast(_cmesh->deepCpy()); @@ -6113,7 +6146,8 @@ void MEDFileCMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, ParaMEDMEM::MEDCouplingMeshType meshType; int dummy0,dummy1; std::string dtunit; - int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit); + ParaMEDMEM::MEDCouplingAxisType axType; + int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit); if(meshType!=CARTESIAN) { std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !"; @@ -6121,6 +6155,7 @@ void MEDFileCMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, } MEDFileCMeshL2 loaderl2; loaderl2.loadAll(fid,mid,mName,dt,it); + setAxType(loaderl2.getAxType()); MEDCouplingCMesh *mesh=loaderl2.getMesh(); mesh->incrRef(); _cmesh=mesh; @@ -6157,6 +6192,28 @@ void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) _cmesh=m; } +MEDFileMesh *MEDFileCMesh::cartesianize() const +{ + if(getAxType()==AX_CART) + { + incrRef(); + return const_cast(this); + } + else + { + const MEDCouplingCMesh *cmesh(getMesh()); + if(!cmesh) + throw INTERP_KERNEL::Exception("MEDFileCMesh::cartesianize : impossible to turn into cartesian because the mesh is null !"); + MEDCouplingAutoRefCountObjectPtr clmesh(cmesh->buildCurveLinear()); + MEDCouplingAutoRefCountObjectPtr coords(clmesh->getCoords()->cartesianize(getAxType())); + clmesh->setCoords(coords); + MEDCouplingAutoRefCountObjectPtr ret(MEDFileCurveLinearMesh::New()); + ret->MEDFileStructuredMesh::operator=(*this); + ret->setMesh(clmesh); + return ret.retn(); + } +} + void MEDFileCMesh::writeLL(med_idt fid) const { INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -6176,10 +6233,11 @@ void MEDFileCMesh::writeLL(med_idt fid) const MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } + // MED_CARTESIAN and not MEDFileMeshL2::TraduceAxisTypeRev(getAxType()) ! Yes it is not a bug. The discrimination is done in MEDmeshGridTypeWr. MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit)); if(_univ_wr_status) MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa)); - MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CARTESIAN_GRID)); + MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MEDFileMeshL2::TraduceAxisTypeRevStruct(getAxType()))); for(int i=0;igetCoordsAt(i); @@ -6218,8 +6276,9 @@ MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dt,it; ParaMEDMEM::MEDCouplingMeshType meshType; + ParaMEDMEM::MEDCouplingAxisType dummy3; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2); + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); return new MEDFileCurveLinearMesh(fid,ms.front(),dt,it,mrs); } @@ -6244,7 +6303,7 @@ std::vector MEDFileCurveLinearMesh::getDirectChildrenWi MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCurveLinearMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileCurveLinearMesh(*this)); return ret.retn(); } @@ -6255,7 +6314,7 @@ MEDFileMesh *MEDFileCurveLinearMesh::createNewEmpty() const MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCurveLinearMesh(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileCurveLinearMesh(*this)); ret->deepCpyEquivalences(*this); if((const MEDCouplingCurveLinearMesh*)_clmesh) ret->_clmesh=static_cast(_clmesh->deepCpy()); @@ -6342,6 +6401,30 @@ void MEDFileCurveLinearMesh::setMesh(MEDCouplingCurveLinearMesh *m) _clmesh=m; } +MEDFileMesh *MEDFileCurveLinearMesh::cartesianize() const +{ + if(getAxType()==AX_CART) + { + incrRef(); + return const_cast(this); + } + else + { + const MEDCouplingCurveLinearMesh *mesh(getMesh()); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::cartesianize : impossible to turn into cartesian because the mesh is null !"); + const DataArrayDouble *coords(mesh->getCoords()); + if(!coords) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::cartesianize : coordinate pointer in mesh is null !"); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileCurveLinearMesh(*this)); + MEDCouplingAutoRefCountObjectPtr mesh2(mesh->clone(false)); + MEDCouplingAutoRefCountObjectPtr coordsCart(coords->cartesianize(getAxType())); + mesh2->setCoords(coordsCart); + ret->setMesh(mesh2); + return ret.retn(); + } +} + const MEDCouplingStructuredMesh *MEDFileCurveLinearMesh::getStructuredMesh() const { synchronizeTinyInfoOnLeaves(); @@ -6385,7 +6468,7 @@ void MEDFileCurveLinearMesh::writeLL(med_idt fid) const MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } - MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit)); + MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxType()),comp,unit)); if(_univ_wr_status) MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa)); MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CURVILINEAR_GRID)); @@ -6403,7 +6486,9 @@ void MEDFileCurveLinearMesh::loadLL(med_idt fid, const std::string& mName, int d ParaMEDMEM::MEDCouplingMeshType meshType; int dummy0,dummy1; std::string dtunit; - int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit); + ParaMEDMEM::MEDCouplingAxisType axType; + int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit); + setAxType(axType); if(meshType!=CURVE_LINEAR) { std::ostringstream oss; oss << "Trying to load as curve linear an existing mesh with name '" << mName << "' that is NOT curve linear !"; @@ -6484,6 +6569,19 @@ bool MEDFileMeshMultiTS::changeNames(const std::vector< std::pair >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + { + MEDFileMesh *cur(*it); + if(cur) + { + MEDCouplingAutoRefCountObjectPtr ccur(cur->cartesianize());// Attention ! Do not wrap these two lines because memory leak ! + *it=ccur; + } + } +} + MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const { if(_mesh_one_ts.empty()) @@ -6578,7 +6676,8 @@ try int dt,it; ParaMEDMEM::MEDCouplingMeshType meshType; std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2); + ParaMEDMEM::MEDCouplingAxisType dummy3; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); loadFromFile(fileName,ms.front()); } catch(INTERP_KERNEL::Exception& e) @@ -6680,16 +6779,6 @@ std::vector MEDFileMeshes::getMeshesNames() const } return ret; } -/*const MEDFileJoints* MEDFileMeshes::getJoints() const -{ - const MEDFileJoints *ret=_joints; - if(!ret) - { - std::ostringstream oss; oss << "MEDFileMeshes::getJoints : joints is not defined !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - return ret; -}*/ bool MEDFileMeshes::changeNames(const std::vector< std::pair >& modifTab) { @@ -6703,6 +6792,16 @@ bool MEDFileMeshes::changeNames(const std::vector< std::pair >::iterator it=_meshes.begin();it!=_meshes.end();it++) + { + MEDFileMeshMultiTS *cur(*it); + if(cur) + cur->cartesianizeMe(); + } +} + void MEDFileMeshes::resize(int newSize) { _meshes.resize(newSize); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index fd7992c40..acbf042b1 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -67,6 +67,8 @@ namespace ParaMEDMEM MEDLOADER_EXPORT double getTimeValue() const { return _time; } MEDLOADER_EXPORT void setTimeUnit(const std::string& unit) { _dt_unit=unit; } MEDLOADER_EXPORT std::string getTimeUnit() const { return _dt_unit; } + MEDLOADER_EXPORT void setAxType(MEDCouplingAxisType at) { _axis_type=at; } + MEDLOADER_EXPORT MEDCouplingAxisType getAxType() const { return _axis_type; } MEDLOADER_EXPORT std::vector getAllGeoTypes() const; MEDLOADER_EXPORT virtual int getNumberOfNodes() const = 0; MEDLOADER_EXPORT virtual int getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const = 0; @@ -86,6 +88,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const = 0; MEDLOADER_EXPORT virtual std::vector getDistributionOfTypes(int meshDimRelToMax) const; MEDLOADER_EXPORT virtual void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const = 0; + MEDLOADER_EXPORT virtual MEDFileMesh *cartesianize() const = 0; // MEDLOADER_EXPORT bool areFamsEqual(const MEDFileMesh *other, std::string& what) const; MEDLOADER_EXPORT bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const; @@ -217,6 +220,7 @@ namespace ParaMEDMEM mutable std::string _univ_name; bool _univ_wr_status; std::string _desc_name; + MEDCouplingAxisType _axis_type; MEDCouplingAutoRefCountObjectPtr _joints; MEDCouplingAutoRefCountObjectPtr _equiv; protected: @@ -266,6 +270,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT std::vector getGeoTypesAtLevel(int meshDimRelToMax) const; MEDLOADER_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const; MEDLOADER_EXPORT void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const; + MEDLOADER_EXPORT MEDFileMesh *cartesianize() const; MEDLOADER_EXPORT std::vector getNonEmptyLevels() const; MEDLOADER_EXPORT std::vector getNonEmptyLevelsExt() const; MEDLOADER_EXPORT std::vector getFamArrNonEmptyLevelsExt() const; @@ -443,6 +448,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT void clearNonDiscrAttributes() const; MEDLOADER_EXPORT const MEDCouplingCMesh *getMesh() const; MEDLOADER_EXPORT void setMesh(MEDCouplingCMesh *m); + MEDLOADER_EXPORT MEDFileMesh *cartesianize() const; private: ~MEDFileCMesh() { } const MEDCouplingStructuredMesh *getStructuredMesh() const; @@ -474,6 +480,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT void clearNonDiscrAttributes() const; MEDLOADER_EXPORT const MEDCouplingCurveLinearMesh *getMesh() const; MEDLOADER_EXPORT void setMesh(MEDCouplingCurveLinearMesh *m); + MEDLOADER_EXPORT MEDFileMesh *cartesianize() const; private: ~MEDFileCurveLinearMesh() { } MEDFileCurveLinearMesh(); @@ -498,12 +505,13 @@ namespace ParaMEDMEM MEDLOADER_EXPORT std::string getName() const; MEDLOADER_EXPORT void setName(const std::string& newMeshName); MEDLOADER_EXPORT bool changeNames(const std::vector< std::pair >& modifTab); + MEDLOADER_EXPORT void cartesianizeMe(); MEDLOADER_EXPORT MEDFileMesh *getOneTimeStep() const; MEDLOADER_EXPORT void write(med_idt fid) const; MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const; MEDLOADER_EXPORT void setOneTimeStep(MEDFileMesh *mesh1TimeStep); MEDLOADER_EXPORT MEDFileJoints *getJoints() const; - MEDLOADER_EXPORT void setJoints( MEDFileJoints* joints ); + MEDLOADER_EXPORT void setJoints(MEDFileJoints* joints); private: ~MEDFileMeshMultiTS() { } void loadFromFile(const std::string& fileName, const std::string& mName); @@ -534,6 +542,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT MEDFileMesh *getMeshWithName(const std::string& mname) const; MEDLOADER_EXPORT std::vector getMeshesNames() const; MEDLOADER_EXPORT bool changeNames(const std::vector< std::pair >& modifTab); + MEDLOADER_EXPORT void cartesianizeMe(); // MEDLOADER_EXPORT void resize(int newSize); MEDLOADER_EXPORT void pushMesh(MEDFileMesh *mesh); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 22626830a..92dd11f20 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -56,7 +56,7 @@ std::vector MEDFileMeshL2::getDirectChildrenWithNull() return std::vector(); } -int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) +int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, ParaMEDMEM::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1) { med_mesh_type type_maillage; char maillage_description[MED_COMMENT_SIZE+1]; @@ -76,6 +76,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para INTERP_KERNEL::AutoPtr axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit)); + dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit)); std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)); ms.push_back(cur); @@ -92,6 +93,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para std::copy(ms.begin(),ms.end(),std::ostream_iterator(oss,", ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); } + axType=TraduceAxisType(axistype); switch(type_maillage) { case MED_UNSTRUCTURED_MESH: @@ -109,13 +111,16 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para case MED_CURVILINEAR_GRID: meshType=CURVE_LINEAR; break; + case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader + meshType=CARTESIAN; + break; default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); } break; } default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !"); } med_int numdt,numit; med_float dtt; @@ -147,7 +152,10 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i return dtt; } -std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) +/*! + * non static and non const method because _description, _dt_unit... are set in this method. + */ +std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, ParaMEDMEM::MEDCouplingAxisType& axType, int& nstep, int& Mdim) { med_mesh_type type_maillage; med_int spaceDim; @@ -162,6 +170,7 @@ std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, &stype,&nstep,&axistype,axisname,axisunit)!=0) throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !"); MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med. + axType=TraduceAxisType(axistype); switch(type_maillage) { case MED_UNSTRUCTURED_MESH: @@ -179,13 +188,16 @@ std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, case MED_CURVILINEAR_GRID: meshType=CURVE_LINEAR; break; + case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader + meshType=CARTESIAN; + break; default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); } break; } default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !"); } // std::vector infosOnComp(naxis); @@ -364,11 +376,68 @@ bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famN std::map::iterator it1(zeMap.find(*it)); if(it1!=zeMap.end()) *it=(*it1).second; - } - + } return true; } +ParaMEDMEM::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at) +{ + switch(at) + { + case MED_CARTESIAN: + return AX_CART; + case MED_CYLINDRICAL: + return AX_CYL; + case MED_SPHERICAL: + return AX_SPHER; + case MED_UNDEF_AXIS_TYPE: + return AX_CART; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !"); + } +} + +ParaMEDMEM::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt) +{ + switch(gt) + { + case MED_CARTESIAN_GRID: + return AX_CART; + case MED_POLAR_GRID: + return AX_CYL; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !"); + } +} + +med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(ParaMEDMEM::MEDCouplingAxisType at) +{ + switch(at) + { + case AX_CART: + return MED_CARTESIAN; + case AX_CYL: + return MED_CYLINDRICAL; + case AX_SPHER: + return MED_SPHERICAL; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !"); + } +} + +med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(ParaMEDMEM::MEDCouplingAxisType at) +{ + switch(at) + { + case AX_CART: + return MED_CARTESIAN_GRID; + case AX_CYL: + return MED_POLAR_GRID; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : only Cartesian and Cylindrical supported by MED file !"); + } +} + MEDFileUMeshL2::MEDFileUMeshL2() { } @@ -379,7 +448,8 @@ std::vector MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, co _name.set(mName.c_str()); int nstep; ParaMEDMEM::MEDCouplingMeshType meshType; - std::vector ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim)); + ParaMEDMEM::MEDCouplingAxisType dummy3; + std::vector ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim)); if(nstep==0) { Mdim=-4; @@ -620,7 +690,7 @@ bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const return true; } -MEDFileCMeshL2::MEDFileCMeshL2() +MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART) { } @@ -630,7 +700,8 @@ void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int int nstep; int Mdim; ParaMEDMEM::MEDCouplingMeshType meshType; - std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim); + ParaMEDMEM::MEDCouplingAxisType dummy3; + std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim); if(meshType!=CARTESIAN) throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !"); _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); @@ -639,8 +710,9 @@ void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int // med_grid_type gridtype; MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype)); - if(gridtype!=MED_CARTESIAN_GRID) - throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !"); + if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID) + throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !"); + _ax_type=TraduceAxisTypeStruct(gridtype); _cmesh=MEDCouplingCMesh::New(); for(int i=0;i infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim); + ParaMEDMEM::MEDCouplingAxisType dummy3; + std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim); if(meshType!=CURVE_LINEAR) throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !"); _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); @@ -850,9 +923,17 @@ std::vector MEDFileUMeshSplitL1::getDirectChildrenWithN return ret; } +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMeshSplitL1(*this)); + ret->_m_by_types.shallowCpyMeshes(); + ret->_m_by_types.setCoords(coords); + return ret.retn(); +} + MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMeshSplitL1(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMeshSplitL1(*this)); ret->_m_by_types=_m_by_types.deepCpy(coords); if((const DataArrayInt *)_fam) ret->_fam=_fam->deepCpy(); @@ -1697,6 +1778,22 @@ MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDoub return ret; } +void MEDFileUMeshAggregateCompute::shallowCpyMeshes() +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *elt(*it); + if(elt) + { + MEDCouplingAutoRefCountObjectPtr elt2(elt->clone(false)); + *it=DynamicCastSafe(elt2); + } + } + const MEDCouplingUMesh *m(_m); + if(m) + _m=m->clone(false); +} + bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const { const MEDCouplingUMesh *m1(getUmesh()); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 9a8f0e8e3..f40ccf1ab 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -53,13 +53,17 @@ namespace ParaMEDMEM int getOrder() const { return _order; } double getTime() const { return _time; } MEDCouplingAutoRefCountObjectPtr getPartDefOfCoo() const { return _part_coords; } - std::vector getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim); - static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1); + std::vector getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, ParaMEDMEM::MEDCouplingAxisType& axType, int& nstep, int& Mdim); + static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, ParaMEDMEM::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1); static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it); static void ReadFamiliesAndGrps(med_idt fid, const std::string& mname, std::map& fams, std::map >& grps, MEDFileMeshReadSelector *mrs); static void WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map& fams, const std::map >& grps, int tooLongStrPol); static bool RenameFamiliesFromFileToMem(std::vector< std::string >& famNames); static bool RenameFamiliesFromMemToFile(std::vector< std::string >& famNames); + static ParaMEDMEM::MEDCouplingAxisType TraduceAxisType(med_axis_type at); + static ParaMEDMEM::MEDCouplingAxisType TraduceAxisTypeStruct(med_grid_type gt); + static med_axis_type TraduceAxisTypeRev(ParaMEDMEM::MEDCouplingAxisType at); + static med_grid_type TraduceAxisTypeRevStruct(ParaMEDMEM::MEDCouplingAxisType at); private: typedef bool (*RenameFamiliesPatternFunc)(std::vector< std::string >&); static void RenameFamiliesPatternInternal(std::vector< std::pair > > >& crudeFams, RenameFamiliesPatternFunc func); @@ -121,10 +125,12 @@ namespace ParaMEDMEM MEDFileCMeshL2(); void loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it); MEDCouplingCMesh *getMesh() { return _cmesh; } + ParaMEDMEM::MEDCouplingAxisType getAxType() const { return _ax_type; } private: static med_data_type GetDataTypeCorrespondingToSpaceId(int id); private: MEDCouplingAutoRefCountObjectPtr _cmesh; + ParaMEDMEM::MEDCouplingAxisType _ax_type; }; class MEDFileCLMeshL2 : public MEDFileStrMeshL2 @@ -178,6 +184,7 @@ namespace ParaMEDMEM std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const; + void shallowCpyMeshes(); bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const; void clearNonDiscrAttributes() const; void synchronizeTinyInfo(const MEDFileMesh& master) const; @@ -213,6 +220,7 @@ namespace ParaMEDMEM void setName(const std::string& name); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; + MEDFileUMeshSplitL1 *shallowCpyUsingCoords(DataArrayDouble *coords) const; MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const; void setCoords(DataArrayDouble *coords); bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index db8a4aa1a..45f7ef9e8 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -101,6 +101,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileMesh::getAllFamiliesIdsReferenced; %newobject ParaMEDMEM::MEDFileMesh::computeAllFamilyIdsInUse; %newobject ParaMEDMEM::MEDFileMesh::getEquivalences; +%newobject ParaMEDMEM::MEDFileMesh::cartesianize; %newobject ParaMEDMEM::MEDFileData::getJoints; %newobject ParaMEDMEM::MEDFileStructuredMesh::getImplicitFaceMesh; %newobject ParaMEDMEM::MEDFileUMesh::New; @@ -883,6 +884,8 @@ namespace ParaMEDMEM double getTimeValue() const; void setTimeUnit(const std::string& unit); std::string getTimeUnit() const; + void setAxType(MEDCouplingAxisType at); + MEDCouplingAxisType getAxType() const; virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception); virtual int getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); virtual bool hasImplicitPart() const throw(INTERP_KERNEL::Exception); @@ -893,6 +896,7 @@ namespace ParaMEDMEM virtual std::vector getNumArrNonEmptyLevelsExt() const throw(INTERP_KERNEL::Exception); virtual std::vector getNameArrNonEmptyLevelsExt() const throw(INTERP_KERNEL::Exception); virtual std::vector getDistributionOfTypes(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + virtual MEDFileMesh *cartesianize() const throw(INTERP_KERNEL::Exception); std::vector getNonEmptyLevels() const throw(INTERP_KERNEL::Exception); std::vector getNonEmptyLevelsExt() const throw(INTERP_KERNEL::Exception); void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception); @@ -1510,6 +1514,7 @@ namespace ParaMEDMEM std::string getName() const throw(INTERP_KERNEL::Exception); void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception); void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception); + void cartesianizeMe() throw(INTERP_KERNEL::Exception); %extend { MEDFileMeshMultiTS() @@ -1573,6 +1578,7 @@ namespace ParaMEDMEM void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception); + void cartesianizeMe() throw(INTERP_KERNEL::Exception); %extend { MEDFileMeshes() diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 9bacf90f9..b50dae798 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4077,6 +4077,13 @@ class MEDLoaderTest(unittest.TestCase): st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL) mm2=cPickle.loads(st) self.assertTrue(mm.isEqual(mm2,1e-12)[0]) + self.assertEqual(mm.getAxType(),AX_CART) + # + mm.setAxType(AX_CYL) + st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL) + mm2=cPickle.loads(st) + self.assertTrue(mm.isEqual(mm2,1e-12)[0]) + self.assertEqual(mm2.getAxType(),AX_CYL) pass def testMEDFileFieldsLoadSpecificEntities1(self): @@ -4740,6 +4747,104 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too ! pass + def testCartesianizer1(self): + """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """ + # UMesh non cart + arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured() + mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts() ; mm.setAxType(AX_CYL) #<- important + d0=DataArrayInt(16) ; d0[:]=0 + d1=DataArrayInt(9) ; d1[:]=0 + mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0) + mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms") + ref0=mm.getCoords().getHiddenCppPointer() + ref1=mm[0].getNodalConnectivity().getHiddenCppPointer() + self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer()) + ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer() + ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer() + self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer()) + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileUMesh)) + self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer()) + self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important + self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important + self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer()) + self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer()) + self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important + self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important + self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important + self.assertEqual(mm2.getName(),mm.getName()) + self.assertEqual(mm2.getDescription(),mm.getDescription()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit()) + self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames()) + self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames()) + self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()]) + self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important + self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important + # UMesh cart + mm.setAxType(AX_CART) + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileUMesh)) + self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization + # CurveLinearMesh non cart + arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear() + mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important + mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0) + mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms") + ref0=mm.getMesh().getCoords().getHiddenCppPointer() + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh)) + self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer()) + self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important + self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important + self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure()) + self.assertEqual(mm2.getName(),mm.getName()) + self.assertEqual(mm2.getDescription(),mm.getDescription()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit()) + self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames()) + self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames()) + self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()]) + self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important + self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important + # CurveLinearMesh cart + mm.setAxType(AX_CART) + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh)) + self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization + # CMesh non cart + arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) + mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important + mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0) + mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms") + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh)) + self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure()) + self.assertEqual(mm2.getName(),mm.getName()) + self.assertEqual(mm2.getDescription(),mm.getDescription()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTime(),mm.getTime()) + self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit()) + self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames()) + self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames()) + self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()]) + self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important + self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) + self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important + # CMesh cart + mm.setAxType(AX_CART) + mm2=mm.cartesianize() # the trigger + self.assertTrue(isinstance(mm2,MEDFileCMesh)) + self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization + pass + pass if __name__ == "__main__": diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index 706b63b09..b7c17377a 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -149,7 +149,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,m1,mm,fs,f,fCell0,fCell1 ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) # False is important to not read the values fields.removeFieldsWithoutAnyTimeStep() refMem=fields.getHeapMemorySize() @@ -365,7 +365,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,m1,mm,fs,f,fCell0,fCell1 ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -531,7 +531,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,m1,mm,fs,f,fCell0,fCell1 ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -786,7 +786,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -918,7 +918,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1084,7 +1084,7 @@ class MEDLoaderTest4(unittest.TestCase): fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0) del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1293,7 +1293,7 @@ class MEDLoaderTest4(unittest.TestCase): fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0) del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1492,7 +1492,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1640,7 +1640,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs1,fs2,fs3,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1773,7 +1773,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs1,fs2,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1876,7 +1876,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs0,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -1971,7 +1971,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs0,fs1,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2088,7 +2088,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs0 ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2244,7 +2244,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs0 ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2406,7 +2406,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) ffs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2598,7 +2598,7 @@ class MEDLoaderTest4(unittest.TestCase): # mms.write(fname,2) ; mts.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2674,7 +2674,7 @@ class MEDLoaderTest4(unittest.TestCase): f3.setName(fieldName3) MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2790,7 +2790,7 @@ class MEDLoaderTest4(unittest.TestCase): f3.setName(fieldName3) MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -2860,7 +2860,7 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue(v.isEqual(vExp1[i],1e-12)) pass ## Now same exercise but with a different load strategy. All is load directly. - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname) # here all is read, the SauvReader (or other Reader) is emulated fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] @@ -2964,7 +2964,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) ff.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3148,7 +3148,7 @@ class MEDLoaderTest4(unittest.TestCase): fs.appendGlobs(fmts3,1e-12) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3349,7 +3349,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3461,7 +3461,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fmts0.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3566,7 +3566,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fmts0.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3674,7 +3674,7 @@ class MEDLoaderTest4(unittest.TestCase): m.write(fname,2) fmts.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) # false is absolutely necessary for the test fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -3888,7 +3888,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4003,7 +4003,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() self.assertEqual(fields[0].getMeshName(),"mesh") @@ -4149,7 +4149,7 @@ class MEDLoaderTest4(unittest.TestCase): mm.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4287,7 +4287,7 @@ class MEDLoaderTest4(unittest.TestCase): fGauss.setArray(arrGauss) MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,fGauss) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4395,7 +4395,7 @@ class MEDLoaderTest4(unittest.TestCase): cc.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4505,7 +4505,7 @@ class MEDLoaderTest4(unittest.TestCase): cc.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4605,7 +4605,7 @@ class MEDLoaderTest4(unittest.TestCase): cc.write(fname,2) fs.write(fname,0) ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4709,7 +4709,7 @@ class MEDLoaderTest4(unittest.TestCase): MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,fCell0) pass ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4801,7 +4801,7 @@ class MEDLoaderTest4(unittest.TestCase): a0Exp=mm.getCoords().deepCpy() del m,mm,fs0,fs1,f,fNode ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4917,7 +4917,8 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes() # here we reproduce what is done by ParaMEDFileMeshes.ParaNew ms.pushMesh(MEDFileUMesh.LoadPartOf(fname,"Mesh",[NORM_QUAD4],[0,2,1],-1,-1)); - ms[0].zipCoords() + ms[0].zipCoords() + ms.cartesianizeMe() # fields=MEDFileFields.LoadPartOf(fname,False,ms); fields.removeFieldsWithoutAnyTimeStep() @@ -5038,7 +5039,7 @@ class MEDLoaderTest4(unittest.TestCase): ff1.write(fname,0) ff4.write(fname,0) ### - ms=MEDFileMeshes(fname) + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() fields=MEDFileFields(fname,False) fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -5114,6 +5115,267 @@ class MEDLoaderTest4(unittest.TestCase): pass pass + def test37(self): + """ Introduction of non cartesian meshes management. Here cylindrical.""" + fname="ForMEDReader37.med" + meshName="mesh" + description="Cylindrical grid" + comps=["X [cm]","Y [cm]","Z [cm]"] + arrX=DataArrayDouble(3) ; arrX.iota() ; arrX*=0.8 ; arrX.setInfoOnComponent(0,comps[0]) + arrY=DataArrayDouble(4) ; arrY.iota() ; arrY*=pi/(len(arrY)-1) ; arrY.setInfoOnComponent(0,comps[1]) + arrZ=DataArrayDouble(5) ; arrZ.iota() ; arrZ*=1.6 ; arrZ-=8. ; arrZ.setInfoOnComponent(0,comps[2]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY,arrZ) ; m.setName(meshName) + mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setDescription(description) + mm.setAxType(AX_CYL) # the test is here ! + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setName("Field") + arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota() ; arr*=0.1 ; f.setArray(arr) ; f.checkCoherency() + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(ff) + # + ms=MEDFileMeshes() ; ms.pushMesh(mm) + fields=MEDFileFields() ; fields.pushField(fmts) + #ms.write(fname,2) ; fields.write(fname,0) + # WARNING for the moment we do not reread fname ! It is not a hidden bug it is just to wait EF control. Coming soon. + ms.cartesianizeMe() + # + fields.removeFieldsWithoutAnyTimeStep() + fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] + allFMTSLeavesToDisplay=[] + for fields in fields_per_mesh: + allFMTSLeavesToDisplay2=[] + for fmts in fields: + tmp=fmts.splitDiscretizations() + for itmp in tmp: + self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType()) + pass + allFMTSLeavesToDisplay2+=tmp + pass + allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2) + pass + # + self.assertEqual(len(allFMTSLeavesToDisplay),1) + self.assertEqual(len(allFMTSLeavesToDisplay[0]),1) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) + allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + fcscp=allFMTSLeavesPerCommonSupport1[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev))# <- hehe it is a CurveLinear no more a CMesh ! + a,b,c=mml2.buildVTUArrays() + self.assertTrue(c)# the array is thoose in structure + ref_a=DataArrayDouble([0.,0.,-8.,0.8,0.,-8.,1.6,0.,-8.,0.,0.,-8.,0.4,0.6928203230275509,-8.,0.8,1.3856406460551018,-8.,-0.,0.,-8.,-0.4,0.692820323027551,-8.,-0.8,1.385640646055102,-8.,-0.,0.,-8.,-0.8,0.,-8.,-1.6,0.,-8.,0.,0.,-6.4,0.8,0.,-6.4,1.6,0.,-6.4,0.,0.,-6.4,0.4,0.6928203230275509,-6.4,0.8,1.3856406460551018,-6.4,-0.,0.,-6.4,-0.4,0.692820323027551,-6.4,-0.8,1.385640646055102,-6.4,-0.,0.,-6.4,-0.8,0.,-6.4,-1.6,0.,-6.4,0.,0.,-4.8,0.8,0.,-4.8,1.6,0.,-4.8,0.,0.,-4.8,0.4,0.6928203230275509,-4.8,0.8,1.3856406460551018,-4.8,-0.,0.,-4.8,-0.4,0.692820323027551,-4.8,-0.8,1.385640646055102,-4.8,-0.,0.,-4.8,-0.8,0.,-4.8,-1.6,0.,-4.8,0.,0.,-3.2,0.8,0.,-3.2,1.6,0.,-3.2,0.,0.,-3.2,0.4,0.6928203230275509,-3.2,0.8,1.3856406460551018,-3.2,-0.,0.,-3.2,-0.4,0.692820323027551,-3.2,-0.8,1.385640646055102,-3.2,-0.,0.,-3.2,-0.8,0.,-3.2,-1.6,0.,-3.2,0.,0.,-1.6,0.8,0.,-1.6,1.6,0.,-1.6,0.,0.,-1.6,0.4,0.6928203230275509,-1.6,0.8,1.3856406460551018,-1.6,-0.,0.,-1.6,-0.4,0.692820323027551,-1.6,-0.8,1.385640646055102,-1.6,-0.,0.,-1.6,-0.8,0.,-1.6,-1.6,0.,-1.6],60,3) + ref_a.setInfoOnComponents(comps) + self.assertTrue(a.isEqual(ref_a,1e-14)) + self.assertEqual(b,[3,4,5]) + for i in xrange(1): + ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i] + fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst) + ffCell.loadArraysIfNecessary() + v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray()) + self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer()) + self.assertTrue(v.isEqual(DataArrayDouble([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3]),1e-14)) + pass + pass + + def test38(self): + """ Introduction of non cartesian meshes management. Here spherical.""" + fname="ForMEDReader38.med" + meshName="mesh" + description="Spherical grid" + comps=["X [cm]","Y [cm]","Z [cm]"] + arrX=DataArrayDouble(3) ; arrX.iota() ; arrX*=0.8 ; arrX.setInfoOnComponent(0,comps[0]) + arrY=DataArrayDouble(4) ; arrY.iota() ; arrY*=pi/(len(arrY)-1) ; arrY.setInfoOnComponent(0,comps[1]) + arrZ=DataArrayDouble(5) ; arrZ.iota() ; arrZ*=2*pi/(len(arrZ)-1) ; arrZ.setInfoOnComponent(0,comps[2]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY,arrZ) ; m.setName(meshName) + mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setDescription(description) + mm.setAxType(AX_SPHER) # the test is here ! + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setName("Field") + arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota() ; arr*=0.1 ; f.setArray(arr) ; f.checkCoherency() + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(ff) + # + ms=MEDFileMeshes() ; ms.pushMesh(mm) + fields=MEDFileFields() ; fields.pushField(fmts) + #ms.write(fname,2) ; fields.write(fname,0) + # WARNING for the moment we do not reread fname ! It is not a hidden bug it is just to wait EF control. Coming soon. + ms.cartesianizeMe() + # + fields.removeFieldsWithoutAnyTimeStep() + fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] + allFMTSLeavesToDisplay=[] + for fields in fields_per_mesh: + allFMTSLeavesToDisplay2=[] + for fmts in fields: + tmp=fmts.splitDiscretizations() + for itmp in tmp: + self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType()) + pass + allFMTSLeavesToDisplay2+=tmp + pass + allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2) + pass + # + self.assertEqual(len(allFMTSLeavesToDisplay),1) + self.assertEqual(len(allFMTSLeavesToDisplay[0]),1) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) + allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + fcscp=allFMTSLeavesPerCommonSupport1[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev)) + a,b,c=mml2.buildVTUArrays() + self.assertTrue(c)# the array is thoose in structure + ref_a=DataArrayDouble([0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.,0.6928203230275509,0.4,0.,1.3856406460551018,0.8,0.,0.,-0.,0.,0.692820323027551,-0.4,0.,1.385640646055102,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,0.,0.,-0.,0.,0.8,-0.,0.,1.6,-0.,0.,0.,-0.6928203230275509,0.,0.4,-1.3856406460551018,0.,0.8,-0.,0.,-0.,-0.692820323027551,0.,-0.4,-1.385640646055102,0.,-0.8,-0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,-0.,0.,-0.,-0.,0.8,-0.,-0.,1.6,-0.,-0.,0.,0.,-0.6928203230275509,0.4,0.,-1.3856406460551018,0.8,-0.,-0.,-0.,0.,-0.692820323027551,-0.4,0.,-1.385640646055102,-0.8,-0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,-0.,0.,0.,-0.,0.8,0.,-0.,1.6,0.,-0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,-0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6],60,3) + ref_a.setInfoOnComponents(comps) + self.assertTrue(a.isEqual(ref_a,1e-14)) + self.assertEqual(b,[3,4,5]) + for i in xrange(1): + ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i] + fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst) + ffCell.loadArraysIfNecessary() + v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray()) + self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer()) + self.assertTrue(v.isEqual(DataArrayDouble([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3]),1e-14)) + pass + pass + + def test39(self): + """Idem test37, test38, test39, test40 except that here it is an unstructured mesh.""" + fname="ForMEDReader39.med" + meshName="mesh" + description="Spherical grid" + comps=["X [cm]","Y [cm]","Z [cm]"] + arrX=DataArrayDouble(3) ; arrX.iota() ; arrX*=0.8 ; arrX.setInfoOnComponent(0,comps[0]) + arrY=DataArrayDouble(4) ; arrY.iota() ; arrY*=pi/(len(arrY)-1) ; arrY.setInfoOnComponent(0,comps[1]) + arrZ=DataArrayDouble(5) ; arrZ.iota() ; arrZ*=2*pi/(len(arrZ)-1) ; arrZ.setInfoOnComponent(0,comps[2]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY,arrZ) ; m.setName(meshName) ; m=m.buildUnstructured() + mm=MEDFileUMesh() ; mm[0]=m ; mm.setDescription(description) # the test is here : UMesh ! + mm.setAxType(AX_SPHER) # the test is here ! + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setName("Field") + arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota() ; arr*=0.1 ; f.setArray(arr) ; f.checkCoherency() + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(ff) + # + ms=MEDFileMeshes() ; ms.pushMesh(mm) + fields=MEDFileFields() ; fields.pushField(fmts) + ms.write(fname,2) ; fields.write(fname,0) + # + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() + fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() + fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] + allFMTSLeavesToDisplay=[] + for fields in fields_per_mesh: + allFMTSLeavesToDisplay2=[] + for fmts in fields: + tmp=fmts.splitDiscretizations() + for itmp in tmp: + self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType()) + pass + allFMTSLeavesToDisplay2+=tmp + pass + allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2) + pass + # + self.assertEqual(len(allFMTSLeavesToDisplay),1) + self.assertEqual(len(allFMTSLeavesToDisplay[0]),1) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) + allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + fcscp=allFMTSLeavesPerCommonSupport1[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) + ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays() + self.assertTrue(ncc) + ref_a=DataArrayDouble([0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.,0.6928203230275509,0.4,0.,1.3856406460551018,0.8,0.,0.,-0.,0.,0.692820323027551,-0.4,0.,1.385640646055102,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,0.,0.,-0.,0.,0.8,-0.,0.,1.6,-0.,0.,0.,-0.6928203230275509,0.,0.4,-1.3856406460551018,0.,0.8,-0.,0.,-0.,-0.692820323027551,0.,-0.4,-1.385640646055102,0.,-0.8,-0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,-0.,0.,-0.,-0.,0.8,-0.,-0.,1.6,-0.,-0.,0.,0.,-0.6928203230275509,0.4,0.,-1.3856406460551018,0.8,-0.,-0.,-0.,0.,-0.692820323027551,-0.4,0.,-1.385640646055102,-0.8,-0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,-0.,0.,0.,-0.,0.8,0.,-0.,1.6,0.,-0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,-0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6],60,3) + ref_a.setInfoOnComponents(comps) + self.assertTrue(a0.isEqual(ref_a,1e-14))#<- Test is here + for i in xrange(1): + ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i] + fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst) + ffCell.loadArraysIfNecessary() + v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray()) + self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer()) + self.assertTrue(v.isEqual(DataArrayDouble([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3]),1e-14)) + pass + + def test40(self): + """Idem test37, test38, test39, test40 except that here it is a CL mesh.""" + fname="ForMEDReader40.med" + meshName="mesh" + description="Spherical grid" + comps=["X [cm]","Y [cm]","Z [cm]"] + arrX=DataArrayDouble(3) ; arrX.iota() ; arrX*=0.8 ; arrX.setInfoOnComponent(0,comps[0]) + arrY=DataArrayDouble(4) ; arrY.iota() ; arrY*=pi/(len(arrY)-1) ; arrY.setInfoOnComponent(0,comps[1]) + arrZ=DataArrayDouble(5) ; arrZ.iota() ; arrZ*=2*pi/(len(arrZ)-1) ; arrZ.setInfoOnComponent(0,comps[2]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY,arrZ) ; m.setName(meshName) ; m=m.buildCurveLinear() + mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setDescription(description) # the test is here CLMesh! + mm.setAxType(AX_SPHER) # the test is here ! + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setName("Field") + arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota() ; arr*=0.1 ; f.setArray(arr) ; f.checkCoherency() + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(ff) + # + ms=MEDFileMeshes() ; ms.pushMesh(mm) + fields=MEDFileFields() ; fields.pushField(fmts) + ms.write(fname,2) ; fields.write(fname,0) + # + ms=MEDFileMeshes(fname) ; ms.cartesianizeMe() + fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() + fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] + allFMTSLeavesToDisplay=[] + for fields in fields_per_mesh: + allFMTSLeavesToDisplay2=[] + for fmts in fields: + tmp=fmts.splitDiscretizations() + for itmp in tmp: + self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType()) + pass + allFMTSLeavesToDisplay2+=tmp + pass + allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2) + pass + # + self.assertEqual(len(allFMTSLeavesToDisplay),1) + self.assertEqual(len(allFMTSLeavesToDisplay[0]),1) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) + allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + fcscp=allFMTSLeavesPerCommonSupport1[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev)) + a,b,c=mml2.buildVTUArrays() + self.assertTrue(c) + ref_a=DataArrayDouble([0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,0.,0.,0.,0.,0.8,0.,0.,1.6,0.,0.,0.,0.,0.6928203230275509,0.4,0.,1.3856406460551018,0.8,0.,0.,-0.,0.,0.692820323027551,-0.4,0.,1.385640646055102,-0.8,0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,0.,0.,-0.,0.,0.8,-0.,0.,1.6,-0.,0.,0.,-0.6928203230275509,0.,0.4,-1.3856406460551018,0.,0.8,-0.,0.,-0.,-0.692820323027551,0.,-0.4,-1.385640646055102,0.,-0.8,-0.,0.,-0.,0.,0.,-0.8,0.,0.,-1.6,-0.,-0.,0.,-0.,-0.,0.8,-0.,-0.,1.6,-0.,-0.,0.,0.,-0.6928203230275509,0.4,0.,-1.3856406460551018,0.8,-0.,-0.,-0.,0.,-0.692820323027551,-0.4,0.,-1.385640646055102,-0.8,-0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6,0.,-0.,0.,0.,-0.,0.8,0.,-0.,1.6,0.,-0.,0.,0.6928203230275509,0.,0.4,1.3856406460551018,0.,0.8,0.,-0.,-0.,0.692820323027551,0.,-0.4,1.385640646055102,0.,-0.8,0.,-0.,-0.,0.,0.,-0.8,0.,0.,-1.6],60,3) + ref_a.setInfoOnComponents(comps) + self.assertTrue(a.isEqual(ref_a,1e-14))#<- Test is here + self.assertEqual(b,[3,4,5]) + for i in xrange(1): + ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i] + fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst) + ffCell.loadArraysIfNecessary() + v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray()) + self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer()) + self.assertTrue(v.isEqual(DataArrayDouble([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3]),1e-14)) + pass + pass if __name__ == "__main__": -- 2.39.2