1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::New;
22 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::deepCpy;
23 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clone;
24 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePartRange;
25 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr;
26 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getLocalizationOfDiscValues;
27 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getMeasureField;
28 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart;
29 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getValueOnMulti;
30 %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::computeTupleIdsToSelectFromCellIds;
34 class MEDCouplingFieldDiscretization : public RefCountObject, public TimeLabel
37 static MEDCouplingFieldDiscretization *New(TypeOfField type) throw(INTERP_KERNEL::Exception);
38 double getPrecision() const throw(INTERP_KERNEL::Exception);
39 void setPrecision(double val) throw(INTERP_KERNEL::Exception);
40 static TypeOfField GetTypeOfFieldFromStringRepr(const char *repr) throw(INTERP_KERNEL::Exception);
41 virtual TypeOfField getEnum() const throw(INTERP_KERNEL::Exception);
42 virtual bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const throw(INTERP_KERNEL::Exception);
43 virtual bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const throw(INTERP_KERNEL::Exception);
44 virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const throw(INTERP_KERNEL::Exception);
45 virtual MEDCouplingFieldDiscretization *deepCpy() const throw(INTERP_KERNEL::Exception);
46 virtual MEDCouplingFieldDiscretization *clone() const throw(INTERP_KERNEL::Exception);
47 virtual MEDCouplingFieldDiscretization *clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception);
48 virtual std::string getStringRepr() const throw(INTERP_KERNEL::Exception);
49 virtual const char *getRepr() const throw(INTERP_KERNEL::Exception);
50 virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
51 virtual int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
52 virtual DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
53 virtual DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
54 virtual void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception);
55 virtual double getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception);
56 virtual void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const throw(INTERP_KERNEL::Exception);
57 virtual MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const throw(INTERP_KERNEL::Exception);
58 virtual void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
59 const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception);
60 virtual void clearGaussLocalizations() throw(INTERP_KERNEL::Exception);
61 virtual MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception);
62 virtual int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception);
63 virtual int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception);
64 virtual int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
67 virtual MEDCouplingFieldDiscretization *clonePart(PyObject *li)
69 int sz=0,sw=-1,val1=-1;
70 std::vector<int> val2;
71 const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2);
72 return self->clonePart(inp,inp+sz);
75 virtual PyObject *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const throw(INTERP_KERNEL::Exception)
79 MEDCouplingMesh *ret0=self->buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,bb,ee,ss,ret1);
80 PyObject *res=PyTuple_New(2);
81 PyTuple_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 ));
83 PyTuple_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0));
86 PyObject *res1=PySlice_New(PyInt_FromLong(bb),PyInt_FromLong(ee),PyInt_FromLong(ss));
87 PyTuple_SetItem(res,1,res1);
92 virtual int getNumberOfTuplesExpectedRegardingCode(PyObject *code, PyObject *idsPerType) const throw(INTERP_KERNEL::Exception)
94 std::vector<int> inp0;
95 convertPyToNewIntArr4(code,1,3,inp0);
96 std::vector<const DataArrayInt *> inp1;
97 convertFromPyObjVectorOfObj<const ParaMEDMEM::DataArrayInt *>(idsPerType,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",inp1);
98 return self->getNumberOfTuplesExpectedRegardingCode(inp0,inp1);
101 virtual PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception)
103 std::vector<int> vVal; int iVal=-1;
105 const int *tupleIdsBg=convertObjToPossibleCpp1_Safe(tupleIds,sw,sz,iVal,vVal);
107 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::computeMeshRestrictionFromTupleIds : none parameter in input !");
108 DataArrayInt *ret0=0,*ret1=0;
109 self->computeMeshRestrictionFromTupleIds(mesh,tupleIdsBg,tupleIdsBg+sz,ret0,ret1);
110 PyObject *pyRet=PyTuple_New(2);
111 PyTuple_SetItem(pyRet,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
112 PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
116 virtual PyObject *normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
119 throw INTERP_KERNEL::Exception("wrap of MEDCouplingFieldDiscretization::normL1 : input array is null !");
120 int sz(arr->getNumberOfComponents());
121 INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
122 self->normL1(mesh,arr,tmp);
123 return convertDblArrToPyList(tmp,sz);
126 virtual PyObject *normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
129 throw INTERP_KERNEL::Exception("wrap of MEDCouplingFieldDiscretization::normL2 : input array is null !");
130 int sz(arr->getNumberOfComponents());
131 INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
132 self->normL2(mesh,arr,tmp);
133 return convertDblArrToPyList(tmp,sz);
136 virtual PyObject *integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs) const throw(INTERP_KERNEL::Exception)
139 throw INTERP_KERNEL::Exception("wrap of MEDCouplingFieldDiscretization::integral : input array is null !");
140 int sz(arr->getNumberOfComponents());
141 INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
142 self->integral(mesh,arr,isWAbs,tmp);
143 return convertDblArrToPyList(tmp,sz);
146 virtual PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception)
148 std::vector<int> tmp;
149 self->getCellIdsHavingGaussLocalization(locId,tmp);
150 DataArrayInt *ret=DataArrayInt::New();
151 ret->alloc((int)tmp.size(),1);
152 std::copy(tmp.begin(),tmp.end(),ret->getPointer());
153 return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
156 virtual void setGaussLocalizationOnCells(const MEDCouplingMesh *m, PyObject *li, const std::vector<double>& refCoo,
157 const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
160 int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 );
161 if (!SWIG_IsOK(res1))
164 INTERP_KERNEL::AutoPtr<int> tmp=convertPyToNewIntArr2(li,&size);
165 self->setGaussLocalizationOnCells(m,tmp,((int *)tmp)+size,refCoo,gsCoo,wg);
169 DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da);
171 throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !");
172 da2->checkAllocated();
173 self->setGaussLocalizationOnCells(m,da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems(),refCoo,gsCoo,wg);
177 virtual PyObject *getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
179 std::set<int> ret=self->getGaussLocalizationIdsOfOneType(type);
180 return convertIntArrToPyList3(ret);
183 virtual PyObject *getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, PyObject *sl) const throw(INTERP_KERNEL::Exception)
187 DataArrayDoubleTuple *aa;
188 std::vector<double> bb;
191 throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingFieldDiscretization::getValueOn : no underlying mesh !");
192 int spaceDim=mesh->getSpaceDimension();
193 const char msg[]="Python wrap of MEDCouplingFieldDiscretization::getValueOn : ";
194 const double *spaceLoc=convertObjToPossibleCpp5_Safe(sl,sw,val,a,aa,bb,msg,1,spaceDim,true);
196 INTERP_KERNEL::AutoPtr<double> res(new double[spaceDim]);
197 self->getValueOn(arr,mesh,spaceLoc,res);
198 return convertDblArrToPyList(res,spaceDim);
201 virtual PyObject *getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k) const throw(INTERP_KERNEL::Exception)
204 throw INTERP_KERNEL::Exception("wrap of MEDCouplingFieldDiscretization::getValueOnPos : input array is null !");
205 int sz(arr->getNumberOfComponents());
206 INTERP_KERNEL::AutoPtr<double> res=new double[sz];
207 self->getValueOnPos(arr,mesh,i,j,k,res);
208 return convertDblArrToPyList(res,sz);
211 virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, PyObject *loc) const throw(INTERP_KERNEL::Exception)
214 throw INTERP_KERNEL::Exception("Python wrap MEDCouplingFieldDiscretization::getValueOnMulti : null input mesh !");
217 double v0; ParaMEDMEM::DataArrayDouble *v1(0); ParaMEDMEM::DataArrayDoubleTuple *v2(0); std::vector<double> v3;
218 const double *inp=convertObjToPossibleCpp5_Safe2(loc,sw,v0,v1,v2,v3,"wrap of MEDCouplingFieldDouble::getValueOnMulti",
219 mesh->getSpaceDimension(),true,nbPts);
220 return self->getValueOnMulti(arr,mesh,inp,nbPts);
223 virtual void renumberCells(PyObject *li, bool check=true) throw(INTERP_KERNEL::Exception)
226 int v0; std::vector<int> v1;
227 const int *ids(convertObjToPossibleCpp1_Safe(li,sw,sz,v0,v1));
228 self->renumberCells(ids,check);
231 virtual void renumberArraysForCell(const MEDCouplingMesh *mesh, PyObject *arrays,
232 PyObject *old2New, bool check) throw(INTERP_KERNEL::Exception)
234 std::vector<DataArray *> input1;
235 convertFromPyObjVectorOfObj<ParaMEDMEM::DataArray *>(arrays,SWIGTYPE_p_ParaMEDMEM__DataArray,"DataArray",input1);
238 int v0; std::vector<int> v1;
239 const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
241 self->renumberArraysForCell(mesh,input1,old2NewBg,check);
244 virtual DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, PyObject *cellIds) const throw(INTERP_KERNEL::Exception)
247 int v0; std::vector<int> v1;
248 const int *cellIdsBg(convertObjToPossibleCpp1_Safe(cellIds,sw,sz,v0,v1));
249 return self->computeTupleIdsToSelectFromCellIds(mesh,cellIdsBg,cellIdsBg+sz);
252 virtual PyObject *buildSubMeshData(const MEDCouplingMesh *mesh, PyObject *ids) const throw(INTERP_KERNEL::Exception)
255 int v0; std::vector<int> v1;
256 const int *idsBg(convertObjToPossibleCpp1_Safe(ids,sw,sz,v0,v1));
258 MEDCouplingMesh *ret0=self->buildSubMeshData(mesh,idsBg,idsBg+sz,di);
259 PyObject *ret=PyTuple_New(2);
260 PyTuple_SetItem(ret,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 ));
261 PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(di),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
265 virtual void renumberValuesOnNodes(double epsOnVals, PyObject *old2New, int newNbOfNodes, DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
268 int v0; std::vector<int> v1;
269 const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
270 self->renumberValuesOnNodes(epsOnVals,old2NewBg,newNbOfNodes,arr);
273 virtual void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, PyObject *old2New, int newSz, DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
276 int v0; std::vector<int> v1;
277 const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
278 self->renumberValuesOnCells(epsOnVals,mesh,old2NewBg,newSz,arr);
281 virtual void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, PyObject *new2old, int newSz, DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
284 int v0; std::vector<int> v1;
285 const int *new2oldBg(convertObjToPossibleCpp1_Safe(new2old,sw,sz,v0,v1));
286 self->renumberValuesOnCellsR(mesh,new2oldBg,newSz,arr);
291 class MEDCouplingFieldDiscretizationP0 : public MEDCouplingFieldDiscretization
295 class MEDCouplingFieldDiscretizationOnNodes : public MEDCouplingFieldDiscretization
299 class MEDCouplingFieldDiscretizationP1 : public MEDCouplingFieldDiscretizationOnNodes
303 class MEDCouplingFieldDiscretizationPerCell : public MEDCouplingFieldDiscretization
306 void setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception);
307 void checkNoOrphanCells() const throw(INTERP_KERNEL::Exception);
310 PyObject *getArrayOfDiscIds() const
312 DataArrayInt *ret=const_cast<DataArrayInt *>(self->getArrayOfDiscIds());
315 return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
318 PyObject *splitIntoSingleGaussDicrPerCellType() const throw(INTERP_KERNEL::Exception)
320 std::vector<int> ret1;
321 std::vector<DataArrayInt *> ret0=self->splitIntoSingleGaussDicrPerCellType(ret1);
322 std::size_t sz=ret0.size();
323 PyObject *pyRet=PyTuple_New(2);
324 PyObject *pyRet0=PyList_New((int)sz);
325 PyObject *pyRet1=PyList_New((int)sz);
326 for(std::size_t i=0;i<sz;i++)
328 PyList_SetItem(pyRet0,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret0[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
329 PyList_SetItem(pyRet1,i,PyInt_FromLong(ret1[i]));
331 PyTuple_SetItem(pyRet,0,pyRet0);
332 PyTuple_SetItem(pyRet,1,pyRet1);
337 ~MEDCouplingFieldDiscretizationPerCell();
340 class MEDCouplingFieldDiscretizationGauss : public MEDCouplingFieldDiscretizationPerCell
343 MEDCouplingFieldDiscretizationGauss();
346 class MEDCouplingFieldDiscretizationGaussNE : public MEDCouplingFieldDiscretization
350 class MEDCouplingFieldDiscretizationKriging : public MEDCouplingFieldDiscretizationOnNodes
355 PyObject *computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
358 DataArrayDouble *ret0=self->computeVectorOfCoefficients(mesh,arr,ret1);
359 PyObject *ret=PyTuple_New(2);
360 PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
361 PyTuple_SetItem(ret,1,PyInt_FromLong(ret1));
365 PyObject *computeInverseMatrix(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception)
367 int ret1(-1),ret2(-1);
368 DataArrayDouble *ret0=self->computeInverseMatrix(mesh,ret1,ret2);
369 PyObject *ret=PyTuple_New(3);
370 PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
371 PyTuple_SetItem(ret,1,PyInt_FromLong(ret1));
372 PyTuple_SetItem(ret,2,PyInt_FromLong(ret2));
376 PyObject *computeEvaluationMatrixOnGivenPts(const MEDCouplingMesh *mesh, PyObject *locs) const throw(INTERP_KERNEL::Exception)
379 throw INTERP_KERNEL::Exception("wrap of MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts : input mesh is empty !");
381 double v0; ParaMEDMEM::DataArrayDouble *v1(0); ParaMEDMEM::DataArrayDoubleTuple *v2(0); std::vector<double> v3;
382 const double *inp=convertObjToPossibleCpp5_Safe2(locs,sw,v0,v1,v2,v3,"wrap of MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts",
383 mesh->getSpaceDimension(),true,nbPts);
386 DataArrayDouble *ret0=self->computeEvaluationMatrixOnGivenPts(mesh,inp,nbPts,ret1);
387 PyObject *ret=PyTuple_New(2);
388 PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
389 PyTuple_SetItem(ret,1,PyInt_FromLong(ret1));