1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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)
26 %include "MEDLoaderCommon.i"
29 #include "MEDCalculatorBrowserLiteStruct.hxx"
30 #include "MEDCalculatorBrowserField.hxx"
31 #include "MEDCalculatorDBField.hxx"
32 #include "MEDCalculatorTypemaps.i"
34 using namespace MEDCoupling;
35 using namespace INTERP_KERNEL;
38 %typemap(out) MEDCoupling::MEDCalculatorDBField*
40 $result=convertMEDCalculatorDBField($1,$owner);
43 %newobject MEDCoupling::MEDCalculatorDBField::operator+;
44 %newobject MEDCoupling::MEDCalculatorDBField::operator-;
45 %newobject MEDCoupling::MEDCalculatorDBField::operator*;
46 %newobject MEDCoupling::MEDCalculatorDBField::operator/;
47 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__radd__;
48 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__rsub__;
49 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__rmul__;
50 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__rdiv__;
51 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__getitem__;
52 %newobject MEDCoupling::MEDCalculatorDBFieldReal::__setitem__;
53 %newobject MEDCoupling::MEDCalculatorDBFieldReal::operator();
54 %newobject MEDCoupling::MEDCalculatorDBFieldReal::buildCstFieldFromThis;
55 %newobject MEDCoupling::MEDCalculatorDBFieldReal::dot;
56 %newobject MEDCoupling::MEDCalculatorDBFieldReal::operator^;
57 %newobject MEDCoupling::MEDCalculatorDBFieldReal::crossProduct;
58 %newobject MEDCoupling::MEDCalculatorDBFieldReal::doublyContractedProduct;
59 %newobject MEDCoupling::MEDCalculatorDBFieldReal::determinant;
60 %newobject MEDCoupling::MEDCalculatorDBFieldReal::eigenValues;
61 %newobject MEDCoupling::MEDCalculatorDBFieldReal::eigenVectors;
62 %newobject MEDCoupling::MEDCalculatorDBFieldReal::inverse;
63 %newobject MEDCoupling::MEDCalculatorDBFieldReal::trace;
64 %newobject MEDCoupling::MEDCalculatorDBFieldReal::deviator;
65 %newobject MEDCoupling::MEDCalculatorDBFieldReal::magnitude;
67 %feature("unref") MEDCalculatorDBField "$this->decrRef();"
71 class MEDCalculatorBrowserLiteStruct
74 MEDCalculatorBrowserLiteStruct(const char *);
75 const MEDCalculatorBrowserField& getField(int) const;
78 class MEDCalculatorDBField : public RefCountObject
81 virtual MEDCalculatorDBField *operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception);
82 MEDCalculatorDBField *operator+(double val) const throw(INTERP_KERNEL::Exception);
83 virtual MEDCalculatorDBField *operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception);
84 MEDCalculatorDBField *operator-(double val) const throw(INTERP_KERNEL::Exception);
85 virtual MEDCalculatorDBField *operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception);
86 MEDCalculatorDBField *operator*(double val) const throw(INTERP_KERNEL::Exception);
87 virtual MEDCalculatorDBField *operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception);
88 MEDCalculatorDBField *operator/(double val) const throw(INTERP_KERNEL::Exception);
89 virtual bool isEqual(const MEDCalculatorDBField& other, double precM, double precF) const;
92 class MEDCalculatorDBFieldReal : public MEDCalculatorDBField
95 MEDCalculatorDBFieldReal(const MEDCalculatorBrowserField& ls);
96 ~MEDCalculatorDBFieldReal();
97 MEDCalculatorDBFieldReal *buildCstFieldFromThis(double val) const;
98 MEDCoupling::TypeOfField getType() const;
99 void fetchData() const throw(INTERP_KERNEL::Exception);
100 int getNumberOfSteps() const;
101 int getNumberOfFetchedSteps() const;
102 int getNumberOfComponents() const;
103 void setName(const char *name);
104 void setDescription(const char *descr);
105 std::string getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception);
106 void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception);
107 void write(const char *fName, bool writeFromScratch) const throw(INTERP_KERNEL::Exception);
108 void display() const throw(INTERP_KERNEL::Exception);
109 void applyFunc(const char *func) throw(INTERP_KERNEL::Exception);
110 MEDCalculatorDBField *operator^(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception);
111 MEDCalculatorDBField *dot(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception);
112 MEDCalculatorDBField *crossProduct(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception);
113 MEDCalculatorDBField *doublyContractedProduct() const throw(INTERP_KERNEL::Exception);
114 MEDCalculatorDBField *determinant() const throw(INTERP_KERNEL::Exception);
115 MEDCalculatorDBField *eigenValues() const throw(INTERP_KERNEL::Exception);
116 MEDCalculatorDBField *eigenVectors() const throw(INTERP_KERNEL::Exception);
117 MEDCalculatorDBField *inverse() const throw(INTERP_KERNEL::Exception);
118 MEDCalculatorDBField *trace() const throw(INTERP_KERNEL::Exception);
119 MEDCalculatorDBField *deviator() const throw(INTERP_KERNEL::Exception);
120 MEDCalculatorDBField *magnitude() const throw(INTERP_KERNEL::Exception);
123 MEDCalculatorDBField *__radd__(double val)
125 MEDCalculatorDBFieldCst tmp(val);
129 MEDCalculatorDBField *__rsub__(double val)
131 MEDCalculatorDBFieldCst tmp(val);
135 MEDCalculatorDBField *__rmul__(double val)
137 MEDCalculatorDBFieldCst tmp(val);
141 MEDCalculatorDBField *__rdiv__(double val)
143 MEDCalculatorDBFieldCst tmp(val);
147 MEDCalculatorDBFieldReal *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
149 if(!PyTuple_Check(obj))
150 throw INTERP_KERNEL::Exception("Unexpected type found : Tuple expected ! Should never happen !");
151 int sz=PyTuple_Size(obj);
153 throw INTERP_KERNEL::Exception("Unexpected nb of element in slice : 3 expected !\n1st is for time, 2nd for geometrical entities and 3rd for components of field !");
154 MEDCalculatorDBRangeSelection tr,pr,cr;
155 PyObject *obj0=PyTuple_GetItem(obj,0);
156 convertPyObjToRS2(obj0,tr,"for 1st tuple element for time");
157 PyObject *obj1=PyTuple_GetItem(obj,1);
158 convertPyObjToRS2(obj1,pr,"for 2nd tuple element for geometrical entities");
159 PyObject *obj2=PyTuple_GetItem(obj,2);
160 convertPyObjToRS2(obj2,cr,"for 3rd tuple element for components of field");
161 return self->operator()(tr,pr,cr);
164 MEDCalculatorDBFieldReal *__setitem__(PyObject *obj, PyObject *val) throw(INTERP_KERNEL::Exception)
166 MEDCalculatorDBRangeSelection tr,pr,cr;
167 if(!PyTuple_Check(obj))
169 const char msg[]="Unexpected type found : Tuple expected or [:] !";
170 if(!PySlice_Check(obj))
171 throw INTERP_KERNEL::Exception(msg);
172 Py_ssize_t strt,stp,step;
173 PySlice_GetIndices(obj,std::numeric_limits<int>::max(),&strt,&stp,&step);
174 if(strt!=0 || stp!=std::numeric_limits<int>::max() || step!=1)
175 throw INTERP_KERNEL::Exception(msg);
176 tr.setAll(); pr.setAll(); cr.setAll();
180 int sz=PyTuple_Size(obj);
182 throw INTERP_KERNEL::Exception("Unexpected nb of element in slice : 3 expected !\n1st is for time, 2nd for geometrical entities and 3rd for components of field !");
183 PyObject *obj0=PyTuple_GetItem(obj,0);
184 convertPyObjToRS2(obj0,tr,"for 1st tuple element for time");
185 PyObject *obj1=PyTuple_GetItem(obj,1);
186 convertPyObjToRS2(obj1,pr,"for 2nd tuple element for geometrical entities");
187 PyObject *obj2=PyTuple_GetItem(obj,2);
188 convertPyObjToRS2(obj2,cr,"for 3rd tuple element for components of field");
190 MCAuto<MEDCalculatorDBFieldReal> ret=self->operator()(tr,pr,cr);
191 if(PyLong_Check(val))
193 (*ret)=double(PyLong_AS_LONG(val));
197 if(PyFloat_Check(val))
199 (*ret)=PyFloat_AS_DOUBLE(val);
204 int status=SWIG_ConvertPtr(val,&argp,SWIGTYPE_p_MEDCoupling__MEDCalculatorDBFieldReal,0|0);
205 if(!SWIG_IsOK(status))
207 throw INTERP_KERNEL::Exception("For setting only float, int or DBFieldReal supported !");
209 const MEDCoupling::MEDCalculatorDBFieldReal *arg=reinterpret_cast< const MEDCoupling::MEDCalculatorDBFieldReal * >(argp);
215 MEDCalculatorDBFieldReal *operator()(PyObject *t, PyObject *p, PyObject *c) throw(INTERP_KERNEL::Exception)
217 MEDCalculatorDBRangeSelection tr,pr,cr;
218 convertPyObjToRS(t,tr);
219 convertPyObjToRS(p,pr);
220 convertPyObjToRS(c,cr);
221 return self->operator()(tr,pr,cr);
224 const MEDCalculatorDBFieldReal& assign(const MEDCalculatorDBFieldReal& other) throw(INTERP_KERNEL::Exception)
230 const MEDCalculatorDBFieldReal& assign(const MEDCalculatorDBFieldReal& other, const char *name) throw(INTERP_KERNEL::Exception)
237 const MEDCalculatorDBFieldReal& assign(double val) throw(INTERP_KERNEL::Exception)
243 const MEDCalculatorDBFieldReal& assign(double val, const char *name) throw(INTERP_KERNEL::Exception)
250 const MEDCalculatorDBFieldReal& assign(int val) throw(INTERP_KERNEL::Exception)
252 (*self)=(double) val;
256 const MEDCalculatorDBFieldReal& assign(int val, const char *name) throw(INTERP_KERNEL::Exception)
258 (*self)=(double) val;
263 PyObject *getFields() const throw(INTERP_KERNEL::Exception)
265 std::vector<MEDCouplingFieldDouble *> r=self->getFields();
266 PyObject *ret = PyList_New(r.size());
267 for(unsigned int i=0;i<r.size();i++)
269 MEDCouplingFieldDouble *tmp=r[i];
270 PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ));
275 PyObject *getValues() const throw(INTERP_KERNEL::Exception)
277 std::vector<MEDCouplingFieldDouble *> r=self->getFields();
278 PyObject *ret = PyList_New(r.size());
279 for(unsigned int i=0;i<r.size();i++)
281 MEDCouplingFieldDouble *tmp=r[i];
282 const double *valtmp=tmp->getArray()->getConstPointer();
283 int nbvals=tmp->getNumberOfValues();
284 PyObject *ret2=PyList_New(nbvals);
285 for(int j=0;j<nbvals;j++)
286 PyList_SetItem(ret2,j,PyFloat_FromDouble(valtmp[j]));
287 PyList_SetItem(ret,i,ret2);
293 std::string __str__() const
295 return self->simpleRepr();
300 class MEDCalculatorDBFieldCst : public MEDCalculatorDBField
303 MEDCalculatorDBFieldCst(double val);
304 MEDCalculatorDBFieldCst(int val);
307 std::string __str__() const
309 std::ostringstream oss; oss << self->getValue();
317 def MEDCouplingDataArrayDoubleIadd(self,*args):
318 import _MEDCalculator
319 return _MEDCalculator.DataArrayDouble____iadd___(self, self, *args)
320 def MEDCouplingDataArrayDoubleIsub(self,*args):
321 import _MEDCalculator
322 return _MEDCalculator.DataArrayDouble____isub___(self, self, *args)
323 def MEDCouplingDataArrayDoubleImul(self,*args):
324 import _MEDCalculator
325 return _MEDCalculator.DataArrayDouble____imul___(self, self, *args)
326 def MEDCouplingDataArrayDoubleIdiv(self,*args):
327 import _MEDCalculator
328 return _MEDCalculator.DataArrayDouble____idiv___(self, self, *args)
329 def MEDCouplingDataArrayDoubleIpow(self,*args):
330 import _MEDCalculator
331 return _MEDCalculator.DataArrayDouble____ipow___(self, self, *args)
332 def MEDCouplingDataArrayDoubleTupleIadd(self,*args):
333 import _MEDCalculator
334 return _MEDCalculator.DataArrayDoubleTuple____iadd___(self, self, *args)
335 def MEDCouplingDataArrayDoubleTupleIsub(self,*args):
336 import _MEDCalculator
337 return _MEDCalculator.DataArrayDoubleTuple____isub___(self, self, *args)
338 def MEDCouplingDataArrayDoubleTupleImul(self,*args):
339 import _MEDCalculator
340 return _MEDCalculator.DataArrayDoubleTuple____imul___(self, self, *args)
341 def MEDCouplingDataArrayDoubleTupleIdiv(self,*args):
342 import _MEDCalculator
343 return _MEDCalculator.DataArrayDoubleTuple____idiv___(self, self, *args)
344 def MEDCouplingFieldDoubleIadd(self,*args):
345 import _MEDCalculator
346 return _MEDCalculator.MEDCouplingFieldDouble____iadd___(self, self, *args)
347 def MEDCouplingFieldDoubleIsub(self,*args):
348 import _MEDCalculator
349 return _MEDCalculator.MEDCouplingFieldDouble____isub___(self, self, *args)
350 def MEDCouplingFieldDoubleImul(self,*args):
351 import _MEDCalculator
352 return _MEDCalculator.MEDCouplingFieldDouble____imul___(self, self, *args)
353 def MEDCouplingFieldDoubleIdiv(self,*args):
354 import _MEDCalculator
355 return _MEDCalculator.MEDCouplingFieldDouble____idiv___(self, self, *args)
356 def MEDCouplingFieldDoubleIpow(self,*args):
357 import _MEDCalculator
358 return _MEDCalculator.MEDCouplingFieldDouble____ipow___(self, self, *args)
359 def MEDCouplingDataArrayIntIadd(self,*args):
360 import _MEDCalculator
361 return _MEDCalculator.DataArrayInt____iadd___(self, self, *args)
362 def MEDCouplingDataArrayIntIsub(self,*args):
363 import _MEDCalculator
364 return _MEDCalculator.DataArrayInt____isub___(self, self, *args)
365 def MEDCouplingDataArrayIntImul(self,*args):
366 import _MEDCalculator
367 return _MEDCalculator.DataArrayInt____imul___(self, self, *args)
368 def MEDCouplingDataArrayIntIdiv(self,*args):
369 import _MEDCalculator
370 return _MEDCalculator.DataArrayInt____idiv___(self, self, *args)
371 def MEDCouplingDataArrayIntImod(self,*args):
372 import _MEDCalculator
373 return _MEDCalculator.DataArrayInt____imod___(self, self, *args)
374 def MEDCouplingDataArrayIntIpow(self,*args):
375 import _MEDCalculator
376 return _MEDCalculator.DataArrayInt____ipow___(self, self, *args)
377 def MEDCouplingDataArrayIntTupleIadd(self,*args):
378 import _MEDCalculator
379 return _MEDCalculator.DataArrayIntTuple____iadd___(self, self, *args)
380 def MEDCouplingDataArrayIntTupleIsub(self,*args):
381 import _MEDCalculator
382 return _MEDCalculator.DataArrayIntTuple____isub___(self, self, *args)
383 def MEDCouplingDataArrayIntTupleImul(self,*args):
384 import _MEDCalculator
385 return _MEDCalculator.DataArrayIntTuple____imul___(self, self, *args)
386 def MEDCouplingDataArrayIntTupleIdiv(self,*args):
387 import _MEDCalculator
388 return _MEDCalculator.DataArrayIntTuple____idiv___(self, self, *args)
389 def MEDCouplingDataArrayIntTupleImod(self,*args):
390 import _MEDCalculator
391 return _MEDCalculator.DataArrayIntTuple____imod___(self, self, *args)
392 def MEDCouplingDenseMatrixIadd(self,*args):
393 import _MEDCalculator
394 return _MEDCalculator.DenseMatrix____iadd___(self, self, *args)
395 def MEDCouplingDenseMatrixIsub(self,*args):
396 import _MEDCalculator
397 return _MEDCalculator.DenseMatrix____isub___(self, self, *args)
400 %include "MEDCouplingFinalize.i"
403 MEDCalculatorDBFieldReal.__rtruediv__ = MEDCalculatorDBFieldReal.__rdiv__
404 def MEDCouplingMEDFileUMeshReduce(self):
405 return MEDCouplingStdReduceFunct,(MEDFileUMesh,((),(self.__getstate__()),))
406 MEDFileUMesh.__reduce__=MEDCouplingMEDFileUMeshReduce
407 del MEDCouplingMEDFileUMeshReduce