From d015afe3143042b1dadc9c406a1db89dcd751b87 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 8 Nov 2012 11:40:23 +0000 Subject: [PATCH] Gauss imp1 --- src/MEDCoupling/MEDCouplingField.hxx | 1 + .../MEDCouplingFieldDiscretization.cxx | 24 +++++- .../MEDCouplingFieldDiscretization.hxx | 6 +- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 6 +- src/MEDCoupling_Swig/MEDCouplingCommon.i | 15 ++++ src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 80 +++++++++++++++++++ 6 files changed, 125 insertions(+), 7 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 3593c8fac..69e6752ee 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM DataArrayInt *computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const; const MEDCouplingFieldDiscretization *getDiscretization() const { return _type; } MEDCouplingFieldDiscretization *getDiscretization() { return _type; } + void setDiscretization(MEDCouplingFieldDiscretization *newDisc) { _type=newDisc; } int getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception); // Gauss point specific methods diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 9f14e9c3f..8538521e6 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -113,6 +113,14 @@ bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCoupl return isEqual(other,eps); } +/*! + * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const int *startCellIds, const int *endCellIds) const +{ + return clone(); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -753,11 +761,16 @@ MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell() _discr_per_cell->decrRef(); } -MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other):_discr_per_cell(0) +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds):_discr_per_cell(0) { DataArrayInt *arr=other._discr_per_cell; if(arr) - _discr_per_cell=arr->deepCpy(); + { + if(startCellIds==0 && endCellIds==0) + _discr_per_cell=arr->deepCpy(); + else + _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds); + } } void MEDCouplingFieldDiscretizationPerCell::updateTime() const @@ -854,7 +867,7 @@ MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() { } -MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other):MEDCouplingFieldDiscretizationPerCell(other),_loc(other._loc) +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds, const int *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc) { } @@ -910,6 +923,11 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() con return new MEDCouplingFieldDiscretizationGauss(*this); } +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const int *startCellIds, const int *endCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds); +} + std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { std::ostringstream oss; oss << REPR << "." << std::endl; diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 0aad8b650..7133ff6ef 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -52,6 +52,7 @@ namespace ParaMEDMEM virtual bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const = 0; virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; virtual MEDCouplingFieldDiscretization *clone() const = 0; + virtual MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; virtual std::string getStringRepr() const = 0; virtual const char *getRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; @@ -187,7 +188,7 @@ namespace ParaMEDMEM const DataArrayInt *getArrayOfDiscIds() const; protected: MEDCouplingFieldDiscretizationPerCell(); - MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other); + MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds); ~MEDCouplingFieldDiscretizationPerCell(); void updateTime() const; void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); @@ -210,6 +211,7 @@ namespace ParaMEDMEM bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCouplingFieldDiscretization *clone() const; + MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; std::string getStringRepr() const; const char *getRepr() const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; @@ -252,7 +254,7 @@ namespace ParaMEDMEM std::vector splitIntoSingleGaussDicrPerCellType(std::vector< int >& locIds) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildNbOfGaussPointPerCellField() const throw(INTERP_KERNEL::Exception); protected: - MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other); + MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds=0, const int *endCellIds=0); void zipGaussLocalizations(); int getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception); void checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 170cf2ecb..ee15856f5 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -435,11 +435,13 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception) { DataArrayInt *arrSelect; - MEDCouplingMesh *m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); + MEDCouplingAutoRefCountObjectPtr m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); MEDCouplingAutoRefCountObjectPtr arrSelect2(arrSelect); MEDCouplingFieldDouble *ret=clone(false);//quick shallow copy. + const MEDCouplingFieldDiscretization *disc=getDiscretization(); + if(disc) + ret->setDiscretization(disc->clonePart(partBg,partEnd)); ret->setMesh(m); - m->decrRef(); std::vector arrays; _time_discr->getArrays(arrays); std::vector arrs; diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 21b921247..279d5424a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -78,6 +78,8 @@ using namespace INTERP_KERNEL; %feature("docstring"); %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr; +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clone; +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; %newobject ParaMEDMEM::MEDCouplingField::buildMeasureField; %newobject ParaMEDMEM::MEDCouplingField::getLocalizationOfDiscr; %newobject ParaMEDMEM::MEDCouplingField::computeTupleIdsToSelectFromCellIds; @@ -867,6 +869,17 @@ namespace ParaMEDMEM } } +%extend ParaMEDMEM::MEDCouplingFieldDiscretization +{ + MEDCouplingFieldDiscretization *clonePart(PyObject *li) + { + int sz=0,sw=-1,val1=-1; + std::vector val2; + const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2); + return self->clonePart(inp,inp+sz); + } +} + %extend ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell { PyObject *getArrayOfDiscIds() const @@ -882,6 +895,7 @@ namespace ParaMEDMEM %ignore ParaMEDMEM::DataArrayInt::getDifferentValues; %ignore ParaMEDMEM::DataArrayInt::partitionByDifferentValues; %ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds; +%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; %include "MEDCouplingMemArray.hxx" %include "NormalizedUnstructuredMesh.hxx" @@ -6196,6 +6210,7 @@ namespace ParaMEDMEM int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + void setDiscretization(MEDCouplingFieldDiscretization *newDisc); %extend { PyObject *getMesh() const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 98aad204d..b3350cc02 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -1409,3 +1409,83 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do } throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple"); } + +/*! + * if python int -> cpp int sw=1 + * if python list[int] -> cpp vector sw=2 + * if python tuple[int] -> cpp vector sw=2 + * if python DataArrayInt -> cpp DataArrayInt sw=3 + * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 + * + * switch between (int,vector,DataArrayInt) + */ +static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector& stdvecTyypp) throw(INTERP_KERNEL::Exception) +{ + sw=-1; + if(PyInt_Check(value)) + { + iTyypp=(int)PyInt_AS_LONG(value); + sw=1; sz=1; + return &iTyypp; + } + if(PyTuple_Check(value)) + { + int size=PyTuple_Size(value); + stdvecTyypp.resize(size); + for(int i=0;i(argp); + if(daIntTyypp) + { + sw=3; sz=daIntTyypp->getNbOfElems(); + return daIntTyypp->begin(); + } + else + { + sz=0; + return 0; + } + } + status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0); + if(SWIG_IsOK(status)) + { + ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); + sw=4; sz=daIntTuple->getNumberOfCompo(); + return daIntTuple->getConstPointer(); + } + throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); +} -- 2.39.2