SALOME_LOG_OPTIONAL_PACKAGE(PythonInterp MEDCOUPLING_ENABLE_PYTHON)
SALOME_LOG_OPTIONAL_PACKAGE(PythonLibs MEDCOUPLING_ENABLE_PYTHON)
SALOME_LOG_OPTIONAL_PACKAGE(SWIG MEDCOUPLING_ENABLE_PYTHON)
+ IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "2")
+ IF("${PYTHON_VERSION_MINOR}" LESS "7")
+ MESSAGE(FATAL_ERROR "MEDCoupling's Python requires at least Python 2.7 (you seem to have ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}). Upgrade your Python, or turn off MEDCOUPLING_ENABLE_PYTHON")
+ ENDIF()
+ ENDIF()
+ IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ MESSAGE(STATUS "Using Python 3")
+ ENDIF()
ENDIF(MEDCOUPLING_ENABLE_PYTHON)
IF(MEDCOUPLING_BUILD_DOC)
# Usage: BuildPyExamplesFromCPP.py <examples.in> <output directory>
-fCpp=file(sys.argv[1],"r")
-cppCont=fCpp.readlines() ; del fCpp
+with open(sys.argv[1], "r") as fCpp:
+ cppCont = fCpp.readlines()
pyCont=cppCont[:]
pyCont=[elt.replace("medcouplingcppexamples","medcouplingpyexamples") for elt in pyCont]
pyCont=Cpp2Python(pyCont)
# Save CPP and PY examples in two separate dox files
outFileName=os.path.join(sys.argv[2],os.path.basename(sys.argv[1]))
-f=file(os.path.splitext(outFileName)[0]+"CPP.dox","w")
-f.writelines(cppCont) ; del f
+with open(os.path.splitext(outFileName)[0] + "CPP.dox", "w") as f:
+ f.writelines(cppCont)
-f=file(os.path.splitext(outFileName)[0]+"PY.dox","w")
-f.writelines(pyCont) ; del f
+with open(os.path.splitext(outFileName)[0] + "PY.dox", "w") as f:
+ f.writelines(pyCont)
MEDCoupling_1_1MEDCouplingCMesh
MEDCoupling_1_1MEDCouplingRemapper
MEDCoupling_1_1DataArray
- MEDCoupling_1_1DataArrayInt
+ #MEDCoupling_1_1DataArrayInt
MEDCoupling_1_1DataArrayDouble
)
def add_text(self, value):
"""Adds text corresponding to `value` into `self.pieces`."""
- if type(value) in (types.ListType, types.TupleType):
+ if isinstance(value, (list, tuple)):
self.pieces.extend(value)
else:
self.pieces.append(value)
kind = node.attributes['kind'].value
if kind in ('class', 'struct'):
prot = node.attributes['prot'].value
- if prot <> 'public':
+ if prot != 'public':
return
names = ('compoundname', 'briefdescription',
'detaileddescription', 'includes')
first = self.get_specific_nodes(node, names)
for n in names:
- if first.has_key(n):
+ if n in first:
self.parse(first[n])
self.add_text(['";','\n'])
for n in node.childNodes:
if name[:8] == 'operator': # Don't handle operators yet.
return
- if not first.has_key('definition') or \
+ if 'definition' not in first or \
kind in ['variable', 'typedef']:
return
if not os.path.exists(fname):
fname = os.path.join(self.my_dir, fname)
if not self.quiet:
- print "parsing file: %s"%fname
+ print("parsing file: %s"%fname)
p = Doxy2SWIG(fname, self.include_function_definition, self.quiet)
p.generate()
self.pieces.extend(self.clean_pieces(p.pieces))
}
}
+ /** Get the minimal (square) distance between a point and all the available bounding boxes in the tree.
+ The (square) distance to a bbox is the true geometric distance between the point and a face
+ (or an edge, or a corner) of the bbox.
+ */
void getMinDistanceOfMax(const double *pt, double& minOfMaxDstsSq) const
{
if(_terminal)
TetraAffineTransform.cxx
CellModel.cxx
DiameterCalculator.cxx
+ OrientationInverter.cxx
UnitTetraIntersectionBary.cxx
InterpolationOptions.cxx
BoxSplittingOptions.cxx
#include "InterpKernelException.hxx"
#include "DiameterCalculator.hxx"
+#include "OrientationInverter.hxx"
#include <algorithm>
#include <sstream>
throw Exception("CellModel::buildInstanceOfDiameterCalulator : implemented only for TRI3, QUAD4, TETRA4, HEXA8, PENTA6, PYRA5 !");
}
}
+
+ OrientationInverter *CellModel::buildOrientationInverter() const
+ {
+ switch(_type)
+ {
+ case NORM_SEG2:
+ return new OrientationInverterSEG2;
+ case NORM_SEG3:
+ return new OrientationInverterSEG3;
+ case NORM_TRI3:
+ case NORM_QUAD4:
+ return new OrientationInverter2DLinear(getNumberOfNodes());
+ case NORM_TRI6:
+ case NORM_QUAD8:
+ return new OrientationInverter2DQuadratic(getNumberOfNodes());
+ case NORM_POLYGON:
+ return new OrientationInverterPolygon;
+ case NORM_QPOLYG:
+ return new OrientationInverterQPolygon;
+ case NORM_TETRA4:
+ return new OrientationInverterTetra4;
+ case NORM_PYRA5:
+ return new OrientationInverterPyra5;
+ case NORM_TETRA10:
+ return new OrientationInverterTetra10;
+ case NORM_PYRA13:
+ return new OrientationInverterPyra13;
+ case NORM_PENTA6:
+ case NORM_HEXA8:
+ return new OrientationInverter3DExtrusionLinear(getNumberOfNodes());
+ case NORM_PENTA15:
+ case NORM_HEXA20:
+ return new OrientationInverter3DExtrusionQuadratic(getNumberOfNodes());
+ default:
+ {
+ std::ostringstream oss; oss << "CellModel::buildOrientationInverter : not managed geometric type " << getRepr() << " yet !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ }
}
namespace INTERP_KERNEL
{
class DiameterCalculator;
+ class OrientationInverter;
/*!
* This class describes all static elements (different from polygons and polyhedron) 3D, 2D and 1D.
INTERPKERNEL_EXPORT void changeOrientationOf2D(int *nodalConn, unsigned int sz) const;
INTERPKERNEL_EXPORT void changeOrientationOf1D(int *nodalConn, unsigned int sz) const;
INTERPKERNEL_EXPORT DiameterCalculator *buildInstanceOfDiameterCalulator(int spaceDim) const;
+ INTERPKERNEL_EXPORT OrientationInverter *buildOrientationInverter() const;
private:
bool _dyn;
bool _quadratic;
# Author : Anthony Geay (EDF R&D)
import re
+import sys
s1=2709
s2=2848
#
nbLines=len(lines)-4
casePat=re.compile("[\s]+case[\s]+([\d]+)\:[\s]*$")
-entries=filter(lambda (i,x): casePat.match(x),enumerate(lines[offsetLines:-1]))
+entries=[i_x for i_x in enumerate(lines[offsetLines:-1]) if casePat.match(i_x[1])]
#
nbPts=len(entries)
if nbLines%nbPts!=0:
if dim<1 or dim>3:
raise Exception("Ooops invalid dim !")
entries=[(i,int(casePat.match(elt).group(1))) for i,elt in entries]
-assert(set([elt[1] for elt in entries])==set(range(nbPts)))
+assert({elt[1] for elt in entries} == set(range(nbPts)))
#
partEndEntries=re.compile("[\s]*break[\s]*\;[\s]*$")
zePat=re.compile("[\s]+coords\[([\d]+)\][\s]*=[\s]*([\-]?[\d]+[\.]?[\d]*)[\s]*\;[\s]*$")
for lineId,ptId in entries:
endLine=lines[offsetLines+lineId+1+dim]
assert(partEndEntries.match(endLine))
- for j in xrange(dim):
+ for j in range(dim):
curLine=lines[offsetLines+lineId+1+j]
m=zePat.match(curLine)
assert(m)
patInit="Init"
assert(m0.group(1)[-len(patInit):]==patInit)
varName="%s_REF"%((m0.group(1)[:-len(patInit)]).upper())
-print("const double %s[%d]={%s};"%(varName,len(zeTab),", ".join(zeTab)))
-for i in xrange(nbPts):
- print(" case %d:"%(i))
- for j in xrange(dim):
- print(" coords[%d] = %s[%d];"%(j,varName,i*dim+j))
+print(("const double %s[%d]={%s};"%(varName,len(zeTab),", ".join(zeTab))))
+for i in range(nbPts):
+ print((" case %d:"%(i)))
+ for j in range(dim):
+ print((" coords[%d] = %s[%d];"%(j,varName,i*dim+j)))
pass
print(" break;")
for(int k=0;k<n-1;k++)
{
// Find L=pivot index.
- l=idamax(n-k-1,a+k+k*lda,1)+k;
+ l=idamax(n-k,a+k+k*lda,1)+k;
ipvt[k]=l;
// Zero pivot implies this column already triangularized.
if(a[l+k*lda]==0.0)
{
- info=k+1;
+ info=k;
continue;
}
//Interchange if necessary.
for(int j=k+1;j<n;j++)
{
t=a[l+j*lda];
- if(l!=k-1)
+ if(l!=k)
{
a[l+j*lda]=a[k+j*lda];
a[k+j*lda]=t;
--- /dev/null
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "OrientationInverter.hxx"
+#include "InterpKernelException.hxx"
+#include "CellModel.hxx"
+
+#include <sstream>
+#include <algorithm>
+
+using namespace INTERP_KERNEL;
+
+OrientationInverter *OrientationInverter::BuildInstanceFrom(NormalizedCellType gt)
+{
+ switch(gt)
+ {
+ case NORM_SEG2:
+ return new OrientationInverterSEG2;
+ case NORM_SEG3:
+ return new OrientationInverterSEG3;
+ case NORM_TRI3:
+ return new OrientationInverter2DLinear(3u);
+ case NORM_QUAD4:
+ return new OrientationInverter2DLinear(4u);
+ case NORM_POLYGON:
+ return new OrientationInverterPolygon;
+ case NORM_TRI6:
+ return new OrientationInverter2DQuadratic(6u);
+ case NORM_QUAD8:
+ return new OrientationInverter2DQuadratic(8u);
+ case NORM_QPOLYG:
+ return new OrientationInverterQPolygon;
+ case NORM_TETRA4:
+ return new OrientationInverterTetra4;
+ case NORM_PYRA5:
+ return new OrientationInverterPyra5;
+ case NORM_PENTA6:
+ return new OrientationInverter3DExtrusionLinear(6u);
+ case NORM_HEXA8:
+ return new OrientationInverter3DExtrusionLinear(8u);
+ case NORM_TETRA10:
+ return new OrientationInverterTetra10;
+ case NORM_PYRA13:
+ return new OrientationInverterPyra13;
+ case NORM_PENTA15:
+ return new OrientationInverter3DExtrusionQuadratic(15u);
+ case NORM_HEXA20:
+ return new OrientationInverter3DExtrusionQuadratic(20u);
+ default:
+ {
+ const CellModel& cm(CellModel::GetCellModel(gt));
+ std::ostringstream oss; oss << "OrientationInverter::BuildInstanceFrom : Sorry no inverter for geo type " << cm.getRepr() << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+}
+
+void OrientationInverterChecker::check(int *beginPt, int *endPt) const
+{
+ if(std::distance(beginPt,endPt)!=getNbNodes())
+ {
+ std::ostringstream oss; oss << "OrientationInverterChecker::check : length of nodal connectivity mismatches ! Expecting " << getNbNodes() << " having " << std::distance(beginPt,endPt) << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+}
+
+void OrientationInverterSEG2::operateAndShutUp(int *beginPt) const
+{
+ std::swap(beginPt[0],beginPt[1]);
+}
+
+void OrientationInverterSEG3::operateAndShutUp(int *beginPt) const
+{
+ std::swap(beginPt[0],beginPt[2]);
+}
+
+void OrientationInverter2DLinear::operateAndShutUp(int *beginPt) const
+{
+ std::reverse(beginPt+1,beginPt+getNbNodes());
+}
+
+void OrientationInverter2DQuadratic::operateAndShutUp(int *beginPt) const
+{
+ int nbNodes(getNbNodes());
+ std::reverse(beginPt+1,beginPt+nbNodes/2);
+ std::reverse(beginPt+nbNodes/2,beginPt+nbNodes);
+}
+
+void OrientationInverterPolygon::operate(int *beginPt, int *endPt) const
+{
+ std::reverse(beginPt+1,endPt);
+}
+
+void OrientationInverterQPolygon::operate(int *beginPt, int *endPt) const
+{
+ std::size_t sz(std::distance(beginPt,endPt));
+ std::reverse(beginPt+1,beginPt+sz/2);
+ std::reverse(beginPt+sz/2,endPt);
+}
+
+void OrientationInverterTetra4::operateAndShutUp(int *beginPt) const
+{
+ std::swap(beginPt[1],beginPt[2]);
+}
+
+void OrientationInverterTetra10::operateAndShutUp(int *beginPt) const
+{
+ std::swap(beginPt[1],beginPt[2]);
+ std::swap(beginPt[4],beginPt[6]);
+ std::swap(beginPt[8],beginPt[9]);
+}
+
+void OrientationInverterPyra5::operateAndShutUp(int *beginPt) const
+{
+ std::reverse(beginPt+1,beginPt+4);
+}
+
+void OrientationInverterPyra13::operateAndShutUp(int *beginPt) const
+{
+ std::reverse(beginPt+1,beginPt+4);
+ std::reverse(beginPt+5,beginPt+9);
+ std::swap(beginPt[10],beginPt[12]);
+}
+
+void OrientationInverter3DExtrusionLinear::operateAndShutUp(int *beginPt) const
+{
+ int nbNodes(getNbNodes());
+ std::reverse(beginPt+1,beginPt+nbNodes/2);
+ std::reverse(beginPt+nbNodes/2+1,beginPt+nbNodes);
+}
+
+void OrientationInverter3DExtrusionQuadratic::operateAndShutUp(int *beginPt) const
+{
+ int nbNodes(getNbNodes()),nbNodesLinearBase(nbNodes/5);
+ std::reverse(beginPt+1,beginPt+nbNodesLinearBase);
+ std::reverse(beginPt+nbNodesLinearBase+1,beginPt+2*nbNodesLinearBase);
+ std::reverse(beginPt+2*nbNodesLinearBase,beginPt+3*nbNodesLinearBase);
+ std::reverse(beginPt+3*nbNodesLinearBase,beginPt+4*nbNodesLinearBase);
+ std::reverse(beginPt+4*nbNodesLinearBase+1,beginPt+5*nbNodesLinearBase);
+}
--- /dev/null
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __ORIENTATIONINVERTER_HXX__
+#define __ORIENTATIONINVERTER_HXX__
+
+#include "INTERPKERNELDefines.hxx"
+#include "NormalizedGeometricTypes"
+
+namespace INTERP_KERNEL
+{
+ class OrientationInverter
+ {
+ public:
+ INTERPKERNEL_EXPORT static OrientationInverter *BuildInstanceFrom(NormalizedCellType gt);
+ INTERPKERNEL_EXPORT virtual ~OrientationInverter() { }
+ INTERPKERNEL_EXPORT virtual void operate(int *beginPt, int *endPt) const = 0;
+ };
+
+ class OrientationInverterChecker : public OrientationInverter
+ {
+ public:
+ OrientationInverterChecker(unsigned nbNodes):_nb_nodes(nbNodes) { }
+ void operate(int *beginPt, int *endPt) const { check(beginPt,endPt); operateAndShutUp(beginPt); }
+ virtual void operateAndShutUp(int *beginPt) const = 0;
+ protected:
+ unsigned getNbNodes() const { return _nb_nodes; }
+ private:
+ void check(int *beginPt, int *endPt) const;
+ private:
+ unsigned _nb_nodes;
+ };
+
+ class OrientationInverterSEG2 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterSEG2():OrientationInverterChecker(2u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverterSEG3 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterSEG3():OrientationInverterChecker(3u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverter2DLinear : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverter2DLinear(unsigned nbNodes):OrientationInverterChecker(nbNodes) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverter2DQuadratic : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverter2DQuadratic(unsigned nbNodes):OrientationInverterChecker(nbNodes) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverterPolygon : public OrientationInverter
+ {
+ public:
+ void operate(int *beginPt, int *endPt) const;
+ };
+
+ class OrientationInverterQPolygon : public OrientationInverter
+ {
+ public:
+ void operate(int *beginPt, int *endPt) const;
+ };
+
+ class OrientationInverterTetra4 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterTetra4():OrientationInverterChecker(4u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverterTetra10 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterTetra10():OrientationInverterChecker(10u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverterPyra5 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterPyra5():OrientationInverterChecker(5u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverterPyra13 : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverterPyra13():OrientationInverterChecker(13u) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverter3DExtrusionLinear : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverter3DExtrusionLinear(unsigned nbNodes):OrientationInverterChecker(nbNodes) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+
+ class OrientationInverter3DExtrusionQuadratic : public OrientationInverterChecker
+ {
+ public:
+ OrientationInverter3DExtrusionQuadratic(unsigned nbNodes):OrientationInverterChecker(nbNodes) { }
+ void operateAndShutUp(int *beginPt) const;
+ };
+}
+
+#endif
#include "VolSurfUser.hxx"
#include "InterpKernelAutoPtr.hxx"
+#include "InterpolationUtils.hxx"
#include <cmath>
#include <limits>
return (x-pt[0])*(x-pt[0])+(y-pt[1])*(y-pt[1]);
}
+ /**
+ * See http://geomalgorithms.com/a02-_lines.html#Distance-to-Ray-or-Segment
+ */
+ double DistanceFromPtToSegInSpaceDim3(const double *pt, const double *pt0Seg2, const double *pt1Seg2)
+ {
+ double v[3], w[3];
+ for(int i=0; i < 3; i++) {
+ v[i]=pt1Seg2[i]-pt0Seg2[i];
+ w[i] = pt[i] - pt0Seg2[i];
+ }
+
+ double c1 = dotprod<3>(w,v);
+ if ( c1 <= 0 )
+ return norm<3>(w);
+ double c2 = dotprod<3>(v,v);
+ if ( c2 <= c1 )
+ {
+ for(int i=0; i < 3; i++)
+ w[i] = pt[i] - pt1Seg2[i];
+ return norm<3>(w);
+ }
+ double b = c1 / c2;
+ for(int i=0; i < 3; i++)
+ w[i] = pt0Seg2[i] + b * v[i] - pt[i];
+ return norm<3>(w);
+ }
+
+ /**
+ Helper for DistanceFromPtToTriInSpaceDim3
+ */
+ inline double _HelperDistancePtToTri3D_1(const double aXX, const double bX, const double c)
+ {
+ if (bX >= 0)
+ return c;
+ if (-bX >= aXX)
+ return aXX + 2*bX + c;
+ return bX*(-bX / aXX) + c;
+ }
+
+ /**
+ Helper for DistanceFromPtToTriInSpaceDim3
+ */
+ inline double _HelperDistancePtToTri3D_2(const double a01, const double aXX, const double aYY,
+ const double bX, const double bY, const double c)
+ {
+ double tmp0 = a01 + bX, tmp1 = aXX + bY;
+ if (tmp1 > tmp0) {
+ double numer = tmp1 - tmp0, denom = aXX - 2*a01 + aYY;
+ if (numer >= denom)
+ return aXX + 2*bX + c;
+ else {
+ double s, t;
+ s = numer / denom; t = 1 - s;
+ return s*(aXX*s + a01*t + 2*bX) + t*(a01*s + aYY*t + 2*bY) + c;
+ }
+ }
+ else
+ {
+ if (tmp1 <= 0) return aYY + 2*bY + c;
+ else {
+ if (bY >= 0) return c;
+ else return bY*(-bY / aYY) + c;
+ }
+ }
+ }
+
+ /**
+ * From https://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf
+ */
double DistanceFromPtToTriInSpaceDim3(const double *pt, const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3)
{
- double matrix[12];
- if(!ComputeRotTranslationMatrixToPut3PointsOnOXY(pt0Tri3,pt1Tri3,pt2Tri3,matrix))
- return std::numeric_limits<double>::max();
- double xy0[2],xy1[2],xy2[2],xy[2]; xy0[0]=0.; xy0[1]=0.;
- xy1[0]=matrix[0]*pt1Tri3[0]+matrix[1]*pt1Tri3[1]+matrix[2]*pt1Tri3[2]+matrix[3]; xy1[1]=0.;
- xy2[0]=matrix[0]*pt2Tri3[0]+matrix[1]*pt2Tri3[1]+matrix[2]*pt2Tri3[2]+matrix[3];
- xy2[1]=matrix[4]*pt2Tri3[0]+matrix[5]*pt2Tri3[1]+matrix[6]*pt2Tri3[2]+matrix[7];
- xy[0]=matrix[0]*pt[0]+matrix[1]*pt[1]+matrix[2]*pt[2]+matrix[3];
- xy[1]=matrix[4]*pt[0]+matrix[5]*pt[1]+matrix[6]*pt[2]+matrix[7];
- double z=matrix[8]*pt[0]+matrix[9]*pt[1]+matrix[10]*pt[2]+matrix[11];
- double ret=std::numeric_limits<double>::max();
- std::size_t nbOfHint=0;
- if(xy[0]>0. && xy[0]<xy1[0])
- { ret=std::min(ret,z*z+xy[1]*xy[1]); nbOfHint++; } //distance pt to edge [pt0Tri3,pt1Tri3]
- double tmp=SquareDistanceFromPtToSegInSpaceDim2(xy,xy1,xy2,nbOfHint); //distance pt to edge [pt1Tri3,pt2Tri3]
- ret=std::min(ret,z*z+tmp);
- tmp=SquareDistanceFromPtToSegInSpaceDim2(xy,xy2,xy0,nbOfHint);//distance pt to edge [pt2Tri3,pt0Tri3]
- ret=std::min(ret,z*z+tmp);
- if(nbOfHint==3)
- ret=std::min(ret,z*z);
- return sqrt(ret);
+ double diff[3], edge0[3], edge1[3];
+ for(int i=0; i < 3; i++) diff[i]=pt0Tri3[i]-pt[i];
+ for(int i=0; i < 3; i++) edge0[i]=pt1Tri3[i]-pt0Tri3[i];
+ for(int i=0; i < 3; i++) edge1[i]=pt2Tri3[i]-pt0Tri3[i];
+
+ double a00=dotprod<3>(edge0, edge0), a01=dotprod<3>(edge0,edge1), a11=dotprod<3>(edge1,edge1);
+ double b0=dotprod<3>(diff, edge0), b1=dotprod<3>(diff, edge1), c=dotprod<3>(diff, diff);
+ double det = fabs(a00*a11 - a01*a01);
+ double s = a01*b1 - a11*b0, t = a01*b0 - a00*b1;
+ double sDist;
+
+ if (s + t <= det)
+ {
+ if (s < 0) {
+ if (t < 0) { // region 4
+ if (b0 < 0) {
+ if (-b0 >= a00) sDist = a00 + 2*b0 + c;
+ else sDist = b0*(-b0 / a00) + c;
+ }
+ else
+ sDist = _HelperDistancePtToTri3D_1(a11, b1, c);
+ }
+ else // region 3
+ sDist = _HelperDistancePtToTri3D_1(a11, b1, c);
+ }
+ else {
+ if (t < 0) // region 5
+ sDist = _HelperDistancePtToTri3D_1(a00, b0, c);
+ else // region 0
+ {
+ // minimum at interior point
+ if (fabs(det) < 1.0e-12)
+ {
+ // points are colinear (degenerated triangle)
+ // => Compute distance between segments
+ double distance = std::min(DistanceFromPtToSegInSpaceDim3(pt, pt0Tri3, pt1Tri3),
+ DistanceFromPtToSegInSpaceDim3(pt, pt1Tri3, pt2Tri3));
+ return distance;
+ }
+
+ // else we can divide by non-zero
+ double invDet = 1 / det;
+ s *= invDet; t *= invDet;
+ sDist = s*(a00*s + a01*t + 2*b0) + t*(a01*s + a11*t + 2*b1) + c;
+ }
+ }
+ }
+ else // s+t > det
+ {
+ if (s < 0.0) // region 2
+ sDist = _HelperDistancePtToTri3D_2(a01, a00, a11, b0, b1, c);
+ else {
+ if (t < 0.0) // region 6
+ sDist = _HelperDistancePtToTri3D_2(a01, a11, a00, b1, b0, c);
+ else { // region 1
+ double numer = a11 + b1 - a01 - b0;
+ if (numer <= 0.0)
+ sDist = a11 + 2*b1 + c;
+ else {
+ double denom = a00 - 2*a01 + a11;
+ if (numer >= denom)
+ sDist = a00 + 2*b0 + c;
+ else {
+ s = numer / denom; t = 1 - s;
+ sDist = s*(a00*s + a01*t + 2*b0) + t*(a01*s + a11*t + 2*b1) + c;
+ }
+ }
+ }
+ }
+ }
+ // Account for numerical round-off error.
+ if (sDist < 0)
+ sDist = 0.0;
+
+ return sqrt(sDist);
}
double DistanceFromPtToPolygonInSpaceDim3(const double *pt, const int *connOfPolygonBg, const int *connOfPolygonEnd, const double *coords)
return resourceFile;
}
// else
- resourceFile = getcwd(NULL, 0);
+ char * tmp_c = getcwd(NULL, 0);
+ resourceFile = tmp_c;
+ free(tmp_c);
resourceFile += "/";
for(int i=0; i<levelUp; i++)
resourceFile += "../";
SET(medcoupling_SOURCES
MEDCouplingField.cxx
+ MEDCouplingFieldFloat.cxx
MEDCouplingFieldDouble.cxx
MEDCouplingFieldInt.cxx
MEDCouplingUMesh.cxx
MEDCouplingUMesh_intersection.cxx
MEDCoupling1GTUMesh.cxx
MEDCouplingMemArray.cxx
+ MEDCouplingMemArrayFloat.cxx
MEDCouplingMemArrayChar.cxx
+ MEDCouplingMap.cxx
MEDCouplingTraits.cxx
MEDCouplingTimeLabel.cxx
MEDCouplingCMesh.cxx
--- /dev/null
+// Copyright (C) 2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDCOUPLING_MCTYPE_HXX__
+#define __MEDCOUPLING_MCTYPE_HXX__
+
+namespace MEDCoupling
+{
+ typedef long Int64;
+ typedef int Int32;
+}
+
+#define DataArrayInt DataArrayInt32
+
+#define DataArrayIntIterator DataArrayInt32Iterator
+
+#endif
#include "SplitterTetra.hxx"
#include "DiameterCalculator.hxx"
+#include "OrientationInverter.hxx"
#include "InterpKernelAutoPtr.hxx"
using namespace MEDCoupling;
return ret.retn();
}
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCoupling1SGTUMesh::invertOrientationOfAllCells()
+{
+ checkConsistencyOfConnectivity();
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(getCellModelEnum()));
+ int nbOfNodesPerCell((int)_cm->getNumberOfNodes()),nbCells(getNumberOfCells());
+ int *conn(_conn->getPointer());
+ for(int i=0;i<nbCells;i++)
+ oi->operate(conn+i*nbOfNodesPerCell,conn+(i+1)*nbOfNodesPerCell);
+ updateTime();
+}
+
//==
MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New()
return ret;
}
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCoupling1DGTUMesh::invertOrientationOfAllCells()
+{
+ checkConsistencyOfConnectivity();
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(getCellModelEnum()));
+ int nbCells(getNumberOfCells());
+ const int *connI(_conn_indx->begin());
+ int *conn(_conn->getPointer());
+ for(int i=0;i<nbCells;i++)
+ oi->operate(conn+connI[i],conn+connI[i+1]);
+ updateTime();
+}
+
/*!
* This method performs an aggregation of \a nodalConns (as DataArrayInt::Aggregate does) but in addition of that a shift is applied on the
* values contained in \a nodalConns using corresponding offset specified in input \a offsetInNodeIdsPerElt.
#define __PARAMEDMEM_MEDCOUPLING1GTUMESH_HXX__
#include "MEDCoupling.hxx"
+#include "MCType.hxx"
#include "MEDCouplingPointSet.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MCAuto.hxx"
MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const;
MEDCOUPLING_EXPORT DataArrayDouble *getBoundingBoxForBBTree(double arcDetEps=1e-12) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *computeDiameterField() const;
+ MEDCOUPLING_EXPORT void invertOrientationOfAllCells();
// overload of MEDCoupling1GTUMesh
MEDCOUPLING_EXPORT void checkConsistencyOfConnectivity() const;
MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0);
MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const;
MEDCOUPLING_EXPORT DataArrayDouble *getBoundingBoxForBBTree(double arcDetEps=1e-12) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *computeDiameterField() const;
+ MEDCOUPLING_EXPORT void invertOrientationOfAllCells();
// overload of MEDCoupling1GTUMesh
MEDCOUPLING_EXPORT void checkConsistencyOfConnectivity() const;
MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0);
{
}
-MEDCouplingCMesh::MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy)
+MEDCouplingCMesh::MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCpy):MEDCouplingStructuredMesh(other,deepCpy)
{
- if(deepCopy)
+ if(deepCpy)
{
if(other._x_array)
_x_array=other._x_array->deepCopy();
MEDCOUPLING_EXPORT std::string getVTKFileExtension() const;
private:
MEDCouplingCMesh();
- MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCopy);
+ MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCpy);
~MEDCouplingCMesh();
void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const;
std::string getVTKDataSetType() const;
#include "MEDCouplingTimeLabel.hxx"
#include "MEDCouplingRefCountObject.hxx"
#include "MCAuto.hxx"
+#include "MCType.hxx"
#include "BoxSplittingOptions.hxx"
#include "InterpKernelException.hxx"
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include "MEDCouplingCurveLinearMesh.hxx"
#include "MEDCouplingPointSet.hxx"
{
}
-MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_structure(other._structure)
+MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCpy):MEDCouplingStructuredMesh(other,deepCpy),_structure(other._structure)
{
- if(deepCopy)
+ if(deepCpy)
{
if((const DataArrayDouble *)other._coords)
_coords=other._coords->deepCopy();
void getBarycenterAndOwnerMeshDim1(DataArrayDouble *bary) const;
private:
MEDCouplingCurveLinearMesh();
- MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCopy);
+ MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCpy);
~MEDCouplingCurveLinearMesh();
void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const;
std::string getVTKDataSetType() const;
_discr_per_cell->checkAllocated();
if(_discr_per_cell->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but with nb of components different from 1 !");
- if(_discr_per_cell->getNumberOfTuples()!=vol->getNumberOfTuples())
+ if(_discr_per_cell->getNumberOfTuples()!=(int)vol->getNumberOfTuples())
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but mismatch between nb of cells of mesh and size of spatial disr array !");
MCAuto<DataArrayInt> offset=getOffsetArr(mesh);
MCAuto<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(getNumberOfTuples(mesh),1);
* \endif
* \sa clone()
*/
-MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const
{
- MEDCouplingTimeDiscretization *tdo=timeDiscr()->buildNewTimeReprFromThis(td,deepCopy);
+ MEDCouplingTimeDiscretization *tdo=timeDiscr()->buildNewTimeReprFromThis(td,deepCpy);
MCAuto<MEDCouplingFieldDiscretization> disc;
if(_type)
disc=_type->clone();
return getArray()->findIdsInRange(vmin,vmax);
}
-/*!
- * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
- * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
- * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field.
- * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
- * \ref MEDCoupling::ON_CELLS "ON_CELLS",
- * \ref MEDCoupling::ON_NODES "ON_NODES",
- * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
- * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
- * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
- *
- * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a part contains following cell ids [3,7,6].
- * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
- * Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().<br>
- * Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().<br>
- * Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
- *
- * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a part contains following cellIds [3,7,6].
- * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
- * will contain 6 tuples and \a this field will lie on this restricted mesh.
- *
- * \param [in] part - an array of cell ids to include to the result field.
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
- * \ref py_mcfielddouble_subpart1 "Here is a Python example".
- * \endif
- * \sa MEDCouplingFieldDouble::buildSubPartRange
- */
-
-MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const
-{
- if(part==0)
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
- return buildSubPart(part->begin(),part->end());
-}
-
-/*!
- * Builds a newly created field, that the caller will have the responsability to deal with.
- * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkConsistencyLight() returns without any exception thrown), **no check of this will be done**.
- * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field.
- * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
- * \ref MEDCoupling::ON_CELLS "ON_CELLS",
- * \ref MEDCoupling::ON_NODES "ON_NODES",
- * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
- * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
- * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
- *
- * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a partBg contains the following cell ids [3,7,6].
- * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
- *- Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().
- *- Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().
- *- Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
- *
- * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a partBg contains following cellIds [3,7,6].
- * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
- * will contain 6 tuples and \a this field will lie on this restricted mesh.
- *
- * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
- * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
- * \return a newly allocated field the caller should deal with.
- *
- * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
- * \ref py_mcfielddouble_subpart1 "Here a Python example."
- * \endif
- * \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
- */
-MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
- DataArrayInt *arrSelect;
- MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
- MCAuto<DataArrayInt> arrSelect2(arrSelect);
- MCAuto<MEDCouplingFieldDouble> ret(clone(false));//quick shallow copy.
- const MEDCouplingFieldDiscretization *disc=getDiscretization();
- if(disc)
- ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
- ret->setMesh(m);
- std::vector<DataArrayDouble *> arrays;
- timeDiscr()->getArrays(arrays);
- std::vector<DataArrayDouble *> arrs;
- std::vector< MCAuto<DataArrayDouble> > arrsSafe;
- const int *arrSelBg=arrSelect->begin();
- const int *arrSelEnd=arrSelect->end();
- for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
- {
- DataArrayDouble *arr=0;
- if(*iter)
- arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
- arrs.push_back(arr); arrsSafe.push_back(arr);
- }
- ret->timeDiscr()->setArrays(arrs,0);
- return ret.retn();
-}
-
-/*!
- * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
- * given using a range given \a begin, \a end and \a step to optimize the part computation.
- *
- * \sa MEDCouplingFieldDouble::buildSubPart
- */
-MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
- DataArrayInt *arrSelect;
- int beginOut,endOut,stepOut;
- MCAuto<MEDCouplingMesh> m(_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect));
- MCAuto<DataArrayInt> arrSelect2(arrSelect);
- MCAuto<MEDCouplingFieldDouble> ret(clone(false));//quick shallow copy.
- const MEDCouplingFieldDiscretization *disc=getDiscretization();
- if(disc)
- ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
- ret->setMesh(m);
- std::vector<DataArrayDouble *> arrays;
- timeDiscr()->getArrays(arrays);
- std::vector<DataArrayDouble *> arrs;
- std::vector< MCAuto<DataArrayDouble> > arrsSafe;
- for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
- {
- DataArrayDouble *arr=0;
- if(*iter)
- {
- if(arrSelect)
- {
- const int *arrSelBg=arrSelect->begin();
- const int *arrSelEnd=arrSelect->end();
- arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
- }
- else
- arr=(*iter)->selectByTupleIdSafeSlice(beginOut,endOut,stepOut);
- }
- arrs.push_back(arr); arrsSafe.push_back(arr);
- }
- ret->timeDiscr()->setArrays(arrs,0);
- return ret.retn();
-}
-
MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const
{
MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*this));
{
}
-MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingFieldT<double>(other,deepCopy)
+MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingFieldT<double>(other,deepCpy)
{
}
*/
//void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs)
-void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
-{
- tinyInfo.clear();
- timeDiscr()->getTinySerializationStrInformation(tinyInfo);
- tinyInfo.push_back(_name);
- tinyInfo.push_back(_desc);
- tinyInfo.push_back(getTimeUnit());
-}
-
-/*!
- * This method retrieves some critical values to resize and prepare remote instance.
- * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
- * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
- */
-void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
- tinyInfo.clear();
- tinyInfo.push_back((int)_type->getEnum());
- tinyInfo.push_back((int)timeDiscr()->getEnum());
- tinyInfo.push_back((int)_nature);
- timeDiscr()->getTinySerializationIntInformation(tinyInfo);
- std::vector<int> tinyInfo2;
- _type->getTinySerializationIntInformation(tinyInfo2);
- tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
- tinyInfo.push_back((int)tinyInfo2.size());
-}
-
-/*!
- * This method retrieves some critical values to resize and prepare remote instance.
- * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
- */
-void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
- tinyInfo.clear();
- timeDiscr()->getTinySerializationDbleInformation(tinyInfo);
- std::vector<double> tinyInfo2;
- _type->getTinySerializationDbleInformation(tinyInfo2);
- tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
- tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
-}
-
-/*!
- * This method has to be called to the new instance filled by CORBA, MPI, File...
- * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
- * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied.
- * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method.
- * No decrRef must be applied to every instances in returned vector.
- * \sa checkForUnserialization
- */
-void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
- dataInt=0;
- std::vector<int> tinyInfoITmp(tinyInfoI);
- int sz=tinyInfoITmp.back();
- tinyInfoITmp.pop_back();
- std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
- std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
- timeDiscr()->resizeForUnserialization(tinyInfoI2,arrays);
- std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
- _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
-}
-
-/*!
- * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
- * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
- * \sa resizeForUnserialization
- */
-void MEDCouplingFieldDouble::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<DataArrayDouble *>& arrays)
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
- std::vector<int> tinyInfoITmp(tinyInfoI);
- int sz=tinyInfoITmp.back();
- tinyInfoITmp.pop_back();
- std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
- std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
- timeDiscr()->checkForUnserialization(tinyInfoI2,arrays);
- std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
- _type->checkForUnserialization(tinyInfoITmp3,dataInt);
-}
-
-void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
- std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
- //
- std::vector<double> tmp(tinyInfoD);
- int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
- tmp.pop_back();
- std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
- std::vector<double> tmp2(tmp.end()-sz,tmp.end());
- //
- timeDiscr()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
- _nature=(NatureOfField)tinyInfoI[2];
- _type->finishUnserialization(tmp2);
- int nbOfElemS=(int)tinyInfoS.size();
- _name=tinyInfoS[nbOfElemS-3];
- _desc=tinyInfoS[nbOfElemS-2];
- setTimeUnit(tinyInfoS[nbOfElemS-1]);
-}
-
-/*!
- * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
- * The values returned must be consulted only in readonly mode.
- */
-void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
-{
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
- timeDiscr()->getArrays(arrays);
- _type->getSerializationIntArray(dataInt);
-}
-
/*!
* Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
* a current and the \a other meshes are different with use of specified equality
if(!disc2)
throw INTERP_KERNEL::Exception("convertQuadraticCellsToLinear : Not a ON_GAUSS_PT field");
std::set<INTERP_KERNEL::NormalizedCellType> gt2(umesh->getAllGeoTypes());
- const DataArrayDouble *arr(getArray());
std::vector< MCAuto<DataArrayInt> > cellIdsV;
std::vector< MCAuto<MEDCouplingUMesh> > meshesV;
std::vector< MEDCouplingGaussLocalization > glV;
ptsInReal=gl.localizePtsInRefCooForEachCell(vorCellsForCurDisc->getCoords(),subMesh);
}
int nbPtsPerCell(vorCellsForCurDisc->getNumberOfNodes());
- for(std::size_t i=0;i<ids.size();i++)
+ for(std::size_t j=0;j<ids.size();j++)
{
MCAuto<MEDCouplingUMesh> elt(vorCellsForCurDisc->clone(false));
- MCAuto<DataArrayDouble> coo(ptsInReal->selectByTupleIdSafeSlice(i*nbPtsPerCell,(i+1)*nbPtsPerCell,1));
- elt->setCoords(coo);
- cells[ids[i]]=elt;
+ MCAuto<DataArrayDouble> coo4(ptsInReal->selectByTupleIdSafeSlice(j*nbPtsPerCell,(j+1)*nbPtsPerCell,1));
+ elt->setCoords(coo4);
+ cells[ids[j]]=elt;
}
}
std::vector< const MEDCouplingUMesh * > cellsPtr(VecAutoToVecOfCstPt(cells));
throw INTERP_KERNEL::Exception("Field Double Null invalid type of time discr !");
return retc;
}
-
MEDCOUPLING_EXPORT void renumberNodes(const int *old2NewBg, double eps=1e-15);
MEDCOUPLING_EXPORT void renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps=1e-15);
MEDCOUPLING_EXPORT DataArrayInt *findIdsInRange(double vmin, double vmax) const;
- MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const;
- MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPart(const int *partBg, const int *partEnd) const;
- MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *deepCopy() const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
- MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const;
+ MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const;
MEDCOUPLING_EXPORT MEDCouplingFieldInt *convertToIntField() const;
MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
//
- MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
- MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
- MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
- MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays);
- MEDCOUPLING_EXPORT void checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<DataArrayDouble *>& arrays);
- MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
- MEDCOUPLING_EXPORT void serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const;
- //
MEDCOUPLING_EXPORT void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps=1e-15);
MEDCOUPLING_EXPORT void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps=1e-15);
MEDCOUPLING_EXPORT bool mergeNodes(double eps, double epsOnVals=1e-15);
private:
MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td);
MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td);
- MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy);
+ MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy);
MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type);
MCAuto<MEDCouplingFieldDouble> voronoizeGen(const Voronizer *vor, double eps) const;
MEDCouplingTimeDiscretization *timeDiscr();
--- /dev/null
+// Copyright (C) 2007-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "MEDCouplingFieldFloat.hxx"
+#include "MEDCouplingFieldT.txx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldTemplate.hxx"
+#include "MEDCouplingMesh.hxx"
+
+using namespace MEDCoupling;
+
+template class MEDCoupling::MEDCouplingFieldT<float>;
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(TypeOfField type, TypeOfTimeDiscretization td)
+{
+ return new MEDCouplingFieldFloat(type,td);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
+{
+ return new MEDCouplingFieldFloat(ft,td);
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT<float>(type,MEDCouplingTimeDiscretizationFloat::New(td))
+{
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCpy):MEDCouplingFieldT<float>(other,deepCpy)
+{
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type):MEDCouplingFieldT<float>(type,n,td)
+{
+}
+
+/*!
+ * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
+ */
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingFieldT<float>(ft,MEDCouplingTimeDiscretizationFloat::New(td),false)
+{
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::deepCopy() const
+{
+ return cloneWithMesh(true);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::clone(bool recDeepCpy) const
+{
+ return new MEDCouplingFieldFloat(*this,recDeepCpy);
+}
+
+MEDCouplingFieldDouble *MEDCouplingFieldFloat::convertToDblField() const
+{
+ MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*this));
+ int t1,t2;
+ double t0(getTime(t1,t2));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*tmp,getTimeDiscretization()));
+ ret->setTime(t0,t1,t2);
+ if(getArray())
+ {
+ MCAuto<DataArrayDouble> arr(getArray()->convertToDblArr());
+ ret->setArray(arr);
+ }
+ return ret.retn();
+}
--- /dev/null
+// Copyright (C) 2007-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __MEDCOUPLINGFIELDFLOAT_HXX__
+#define __MEDCOUPLINGFIELDFLOAT_HXX__
+
+#include "MEDCoupling.hxx"
+#include "MEDCouplingFieldT.hxx"
+#include "MEDCouplingMemArray.hxx"
+
+#include <string>
+
+namespace MEDCoupling
+{
+ class MEDCouplingFieldDouble;
+ class MEDCouplingFieldTemplate;
+
+ class MEDCouplingFieldFloat : public MEDCouplingFieldT<float>
+ {
+ public:
+ MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
+ MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+ MEDCOUPLING_EXPORT MEDCouplingFieldFloat *deepCopy() const;
+ MEDCOUPLING_EXPORT MEDCouplingFieldFloat *clone(bool recDeepCpy) const;
+ MEDCOUPLING_EXPORT MEDCouplingFieldDouble *convertToDblField() const;
+ protected:
+ MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td);
+ MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCpy);
+ MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type);
+ MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td);
+ ~MEDCouplingFieldFloat() { }
+ };
+}
+
+#endif
{
}
-MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingFieldT<int>(other,deepCopy)
+MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCpy):MEDCouplingFieldT<int>(other,deepCpy)
{
}
MEDCOUPLING_EXPORT virtual typename Traits<T>::FieldType *clone(bool recDeepCpy) const = 0;
MEDCOUPLING_EXPORT void checkConsistencyLight() const;
MEDCOUPLING_EXPORT typename Traits<T>::FieldType *cloneWithMesh(bool recDeepCpy) const;
+ MEDCOUPLING_EXPORT typename Traits<T>::FieldType *buildSubPart(const DataArrayInt *part) const;
+ MEDCOUPLING_EXPORT typename Traits<T>::FieldType *buildSubPart(const int *partBg, const int *partEnd) const;
+ MEDCOUPLING_EXPORT typename Traits<T>::FieldType *buildSubPartRange(int begin, int end, int step) const;
MEDCOUPLING_EXPORT void setArray(typename Traits<T>::ArrayType *array) { _time_discr->setArray(array,this); }
MEDCOUPLING_EXPORT void setEndArray(typename Traits<T>::ArrayType *array) { _time_discr->setEndArray(array,this); }
MEDCOUPLING_EXPORT const typename Traits<T>::ArrayType *getArray() const { return _time_discr->getArray(); }
MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const;
MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingFieldT<T> *other);
MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldT<T> *other);
+ //
+ MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays);
+ MEDCOUPLING_EXPORT void checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays);
+ MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
+ MEDCOUPLING_EXPORT void serialize(DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const;
+ MEDCOUPLING_EXPORT const MEDCouplingTimeDiscretizationTemplate<T> *timeDiscrSafe() const;
+ protected:
+ MEDCouplingTimeDiscretizationTemplate<T> *timeDiscrSafe();
protected:
MEDCouplingTimeDiscretizationTemplate<T> *_time_discr;
};
{
return _time_discr->getEnum();
}
+
+ /*!
+ * Builds a newly created field, that the caller will have the responsability to deal with.
+ * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkConsistencyLight() returns without any exception thrown), **no check of this will be done**.
+ * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field.
+ * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
+ * \ref MEDCoupling::ON_CELLS "ON_CELLS",
+ * \ref MEDCoupling::ON_NODES "ON_NODES",
+ * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
+ * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
+ * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
+ *
+ * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a partBg contains the following cell ids [3,7,6].
+ * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
+ *- Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().
+ *- Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().
+ *- Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
+ *
+ * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a partBg contains following cellIds [3,7,6].
+ * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
+ * will contain 6 tuples and \a this field will lie on this restricted mesh.
+ *
+ * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
+ * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
+ * \return a newly allocated field the caller should deal with.
+ *
+ * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
+ * \ref py_mcfielddouble_subpart1 "Here a Python example."
+ * \endif
+ * \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const int *partBg, const int *partEnd) const
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : Expecting a not NULL spatial discretization !");
+ DataArrayInt *arrSelect;
+ MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
+ MCAuto<DataArrayInt> arrSelect2(arrSelect);
+ MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
+ const MEDCouplingFieldDiscretization *disc=getDiscretization();
+ if(disc)
+ ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
+ ret->setMesh(m);
+ std::vector<typename Traits<T>::ArrayType *> arrays;
+ timeDiscrSafe()->getArrays(arrays);
+ std::vector<typename Traits<T>::ArrayType *> arrs;
+ std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
+ const int *arrSelBg=arrSelect->begin();
+ const int *arrSelEnd=arrSelect->end();
+ for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ typename Traits<T>::ArrayType *arr(0);
+ if(*iter)
+ arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
+ arrs.push_back(arr); arrsSafe.push_back(arr);
+ }
+ ret->timeDiscrSafe()->setArrays(arrs,0);
+ return ret.retn();
+ }
+
+ /*!
+ * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
+ * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
+ * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field.
+ * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
+ * \ref MEDCoupling::ON_CELLS "ON_CELLS",
+ * \ref MEDCoupling::ON_NODES "ON_NODES",
+ * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
+ * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
+ * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
+ *
+ * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a part contains following cell ids [3,7,6].
+ * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
+ * Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().<br>
+ * Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().<br>
+ * Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
+ *
+ * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a part contains following cellIds [3,7,6].
+ * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
+ * will contain 6 tuples and \a this field will lie on this restricted mesh.
+ *
+ * \param [in] part - an array of cell ids to include to the result field.
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
+ * \ref py_mcfielddouble_subpart1 "Here is a Python example".
+ * \endif
+ * \sa MEDCouplingFieldDouble::buildSubPartRange
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const DataArrayInt *part) const
+ {
+ if(part==0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : not empty array must be passed to this method !");
+ return buildSubPart(part->begin(),part->end());
+ }
+
+ /*!
+ * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
+ * given using a range given \a begin, \a end and \a step to optimize the part computation.
+ *
+ * \sa MEDCouplingFieldDouble::buildSubPart
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPartRange(int begin, int end, int step) const
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
+ DataArrayInt *arrSelect;
+ int beginOut,endOut,stepOut;
+ MCAuto<MEDCouplingMesh> m(_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect));
+ MCAuto<DataArrayInt> arrSelect2(arrSelect);
+ MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
+ const MEDCouplingFieldDiscretization *disc=getDiscretization();
+ if(disc)
+ ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
+ ret->setMesh(m);
+ std::vector<typename Traits<T>::ArrayType *> arrays;
+ timeDiscrSafe()->getArrays(arrays);
+ std::vector<typename Traits<T>::ArrayType *> arrs;
+ std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
+ for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ typename Traits<T>::ArrayType *arr(0);
+ if(*iter)
+ {
+ if(arrSelect)
+ {
+ const int *arrSelBg=arrSelect->begin();
+ const int *arrSelEnd=arrSelect->end();
+ arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
+ }
+ else
+ arr=(*iter)->selectByTupleIdSafeSlice(beginOut,endOut,stepOut);
+ }
+ arrs.push_back(arr); arrsSafe.push_back(arr);
+ }
+ ret->timeDiscrSafe()->setArrays(arrs,0);
+ return ret.retn();
+ }
+
+ template<class T>
+ const MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe() const
+ {
+ const MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
+ if(!ret)
+ throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
+ return ret;
+ }
+
+ template<class T>
+ MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe()
+ {
+ MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
+ if(!ret)
+ throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
+ return ret;
+ }
+
+ template<class T>
+ void MEDCouplingFieldT<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
+ {
+ tinyInfo.clear();
+ timeDiscrSafe()->getTinySerializationStrInformation(tinyInfo);
+ tinyInfo.push_back(_name);
+ tinyInfo.push_back(_desc);
+ tinyInfo.push_back(getTimeUnit());
+ }
+
+ /*!
+ * This method retrieves some critical values to resize and prepare remote instance.
+ * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
+ * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
+ tinyInfo.clear();
+ tinyInfo.push_back((int)_type->getEnum());
+ tinyInfo.push_back((int)timeDiscrSafe()->getEnum());
+ tinyInfo.push_back((int)_nature);
+ timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo);
+ std::vector<int> tinyInfo2;
+ _type->getTinySerializationIntInformation(tinyInfo2);
+ tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
+ tinyInfo.push_back((int)tinyInfo2.size());
+ }
+
+ /*!
+ * This method retrieves some critical values to resize and prepare remote instance.
+ * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
+ tinyInfo.clear();
+ timeDiscrSafe()->getTinySerializationDbleInformation(tinyInfo);
+ std::vector<double> tinyInfo2;
+ _type->getTinySerializationDbleInformation(tinyInfo2);
+ tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
+ tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
+ }
+
+ /*!
+ * This method has to be called to the new instance filled by CORBA, MPI, File...
+ * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
+ * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied.
+ * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method.
+ * No decrRef must be applied to every instances in returned vector.
+ * \sa checkForUnserialization
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
+ dataInt=0;
+ std::vector<int> tinyInfoITmp(tinyInfoI);
+ int sz=tinyInfoITmp.back();
+ tinyInfoITmp.pop_back();
+ std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
+ std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
+ timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays);
+ std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
+ _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
+ }
+
+ /*!
+ * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
+ * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
+ * \sa resizeForUnserialization
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
+ std::vector<int> tinyInfoITmp(tinyInfoI);
+ int sz=tinyInfoITmp.back();
+ tinyInfoITmp.pop_back();
+ std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
+ std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
+ timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays);
+ std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
+ _type->checkForUnserialization(tinyInfoITmp3,dataInt);
+ }
+
+ template<class T>
+ void MEDCouplingFieldT<T>::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
+ std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
+ //
+ std::vector<double> tmp(tinyInfoD);
+ int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
+ tmp.pop_back();
+ std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
+ std::vector<double> tmp2(tmp.end()-sz,tmp.end());
+ //
+ timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
+ _nature=(NatureOfField)tinyInfoI[2];
+ _type->finishUnserialization(tmp2);
+ int nbOfElemS=(int)tinyInfoS.size();
+ _name=tinyInfoS[nbOfElemS-3];
+ _desc=tinyInfoS[nbOfElemS-2];
+ setTimeUnit(tinyInfoS[nbOfElemS-1]);
+ }
+
+ /*!
+ * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
+ * The values returned must be consulted only in readonly mode.
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::serialize(DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const
+ {
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
+ timeDiscrSafe()->getArrays(arrays);
+ _type->getSerializationIntArray(dataInt);
+ }
}
#endif
#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingMesh.hxx"
#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f)
{
- return new MEDCouplingFieldTemplate(f);
+ return new MEDCouplingFieldTemplate(f,true);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
+{
+ return new MEDCouplingFieldTemplate(f,true);
}
MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
{
- return new MEDCouplingFieldTemplate(f);
+ return new MEDCouplingFieldTemplate(f,true);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldDouble& f)
+{
+ return new MEDCouplingFieldTemplate(f,false);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldFloat& f)
+{
+ return new MEDCouplingFieldTemplate(f,false);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldInt& f)
+{
+ return new MEDCouplingFieldTemplate(f,false);
}
/*!
return new MEDCouplingFieldTemplate(type);
}
-MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f):MEDCouplingField(f,false)
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked):MEDCouplingField(f,false)
+{
+ forceTimeOfThis(f);
+ if(isChecked)
+ checkConsistencyLight();
+}
+
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked):MEDCouplingField(f,false)
{
forceTimeOfThis(f);
- checkConsistencyLight();
+ if(isChecked)
+ checkConsistencyLight();
}
-MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false)
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f, bool isChecked):MEDCouplingField(f,false)
{
forceTimeOfThis(f);
- checkConsistencyLight();
+ if(isChecked)
+ checkConsistencyLight();
}
MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
{
}
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy):MEDCouplingField(other,deepCopy)
+{
+}
+
void MEDCouplingFieldTemplate::checkConsistencyLight() const
{
if(_mesh==0)
stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
}
}
+
+MCAuto<MEDCouplingFieldTemplate> MEDCouplingFieldTemplate::clone(bool recDeepCpy) const
+{
+ MCAuto<MEDCouplingFieldTemplate> ret(new MEDCouplingFieldTemplate(*this,recDeepCpy));
+ return ret;
+}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#ifndef __PARAMEDMEM_MEDCOUPLINGFIELDTEMPLATE_HXX__
#define __PARAMEDMEM_MEDCOUPLINGFIELDTEMPLATE_HXX__
namespace MEDCoupling
{
class MEDCouplingFieldInt;
+ class MEDCouplingFieldFloat;
class MEDCouplingFieldDouble;
/*!
* \brief A field template can be seen as a field without the array of values.
{
public:
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f);
+ MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldFloat& f);
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f);
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(TypeOfField type);
+ MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldDouble& f);
+ MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldFloat& f);
+ MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldInt& f);
MEDCOUPLING_EXPORT std::string simpleRepr() const;
MEDCOUPLING_EXPORT std::string advancedRepr() const;
MEDCOUPLING_EXPORT void checkConsistencyLight() const;
+ MEDCOUPLING_EXPORT MCAuto<MEDCouplingFieldTemplate> clone(bool recDeepCpy) const;
//
MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
//
MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
private:
- MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f);
- MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f);
+ MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked=true);
+ MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked=true);
+ MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f, bool isChecked=true);
MEDCouplingFieldTemplate(TypeOfField type);
+ MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy);
};
}
MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
ret->alloc(nbPts*nbCells,outDim);
double *retPtr(ret->getPointer());
- if(dim!=ptsInRefCoo->getNumberOfComponents())
+ if(dim!=(int)ptsInRefCoo->getNumberOfComponents())
throw INTERP_KERNEL::Exception("MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell : number of components of input coo is not equal to dim of element !");
const std::vector<double>& wg(getWeights());
INTERP_KERNEL::GaussCoords calculator;
{
MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getType()));
- if(getDimension()!=cm.getDimension())
+ if(getDimension()!=(int)cm.getDimension())
throw INTERP_KERNEL::Exception("BuildRefCell : dimension mistmatch !");
coo->alloc(cm.getNumberOfNodes(),getDimension());
std::copy(_ref_coord.begin(),_ref_coord.end(),coo->getPointer());
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include "MEDCouplingIMesh.hxx"
#include "MEDCouplingCMesh.hxx"
_structure[0]=0; _structure[1]=0; _structure[2]=0;
}
-MEDCouplingIMesh::MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_space_dim(other._space_dim),_axis_unit(other._axis_unit)
+MEDCouplingIMesh::MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCpy):MEDCouplingStructuredMesh(other,deepCpy),_space_dim(other._space_dim),_axis_unit(other._axis_unit)
{
_origin[0]=other._origin[0]; _origin[1]=other._origin[1]; _origin[2]=other._origin[2];
_dxyz[0]=other._dxyz[0]; _dxyz[1]=other._dxyz[1]; _dxyz[2]=other._dxyz[2];
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the parameters 1 or 3 are NULL or not allocated !");
int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseSt)),nbOfTuplesInFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(fineLocInCoarse));
int nbCompo(fineDA->getNumberOfComponents());
- if(coarseDA->getNumberOfComponents()!=nbCompo)
+ if((int)coarseDA->getNumberOfComponents()!=nbCompo)
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the number of components of fine DA and coarse one mismatches !");
if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size())
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !");
std::vector<int> coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus<int>(),2*ghostSize));
int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG));
int nbCompo(fineDA->getNumberOfComponents());
- if(coarseDA->getNumberOfComponents()!=nbCompo)
+ if((int)coarseDA->getNumberOfComponents()!=nbCompo)
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : the number of components of fine DA and coarse one mismatches !");
if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size())
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !");
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the parameters 1 or 3 are NULL or not allocated !");
int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseSt)),nbOfTuplesInFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(fineLocInCoarse));
int nbCompo(fineDA->getNumberOfComponents());
- if(coarseDA->getNumberOfComponents()!=nbCompo)
+ if((int)coarseDA->getNumberOfComponents()!=nbCompo)
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the number of components of fine DA and coarse one mismatches !");
if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size())
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !");
std::vector<int> coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus<int>(),2*ghostSize));
int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG));
int nbCompo(fineDA->getNumberOfComponents());
- if(coarseDA->getNumberOfComponents()!=nbCompo)
+ if((int)coarseDA->getNumberOfComponents()!=nbCompo)
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : the number of components of fine DA and coarse one mismatches !");
if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size())
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !");
std::vector<int> coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus<int>(),2*ghostSize));
int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG));
int nbCompo(fineDA->getNumberOfComponents());
- if(coarseDA->getNumberOfComponents()!=nbCompo)
+ if((int)coarseDA->getNumberOfComponents()!=nbCompo)
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : the number of components of fine DA and coarse one mismatches !");
if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size())
throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !");
--- /dev/null
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "MEDCouplingMap.txx"
+
+using namespace MEDCoupling;
+
+template class MEDCoupling::MapKeyVal<int>;
--- /dev/null
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDCOUPLING_MEDCOUPLINGMAP_HXX__
+#define __MEDCOUPLING_MEDCOUPLINGMAP_HXX__
+
+#include "MEDCoupling.hxx"
+#include "MCAuto.hxx"
+#include "MEDCouplingTimeLabel.hxx"
+#include "MEDCouplingRefCountObject.hxx"
+#include "InterpKernelException.hxx"
+
+#include <map>
+
+namespace MEDCoupling
+{
+ template<class T>
+ class MapKeyVal : public RefCountObject, public TimeLabel
+ {
+ public:
+ static MCAuto< MapKeyVal<T> > New();
+ std::map<T,T>& data() { return _m; }
+ const std::map<T,T>& data() const { return _m; }
+ std::size_t getHeapMemorySizeWithoutChildren() const;
+ std::vector<const BigMemoryObject*> getDirectChildrenWithNull() const;
+ void updateTime() const { }
+ private:
+ MapKeyVal() { }
+ ~MapKeyVal() { }
+ private:
+ std::map<T,T> _m;
+ };
+
+ typedef MapKeyVal<int> MapII;
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDCOUPLING_MEDCOUPLINGMAP_TXX__
+#define __MEDCOUPLING_MEDCOUPLINGMAP_TXX__
+
+#include "MEDCouplingMap.hxx"
+
+namespace MEDCoupling
+{
+ template<class T>
+ MCAuto< MapKeyVal<T> > MapKeyVal<T>::New()
+ {
+ MCAuto< MapKeyVal<T> > ret(new MapKeyVal<T>);
+ return ret;
+ }
+
+ template<class T>
+ std::size_t MapKeyVal<T>::getHeapMemorySizeWithoutChildren() const
+ {
+ return _m.size()*sizeof(std::pair<T,T>);
+ }
+
+ template<class T>
+ std::vector<const BigMemoryObject*> MapKeyVal<T>::getDirectChildrenWithNull() const
+ {
+ return std::vector<const BigMemoryObject*>();//not a bug no child. Leaf object !
+ }
+}
+
+#endif
{
}
-MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh(const MEDCouplingMappedExtrudedMesh& other, bool deepCopy):MEDCouplingMesh(other),_cell_2D_id(other._cell_2D_id)
+MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh(const MEDCouplingMappedExtrudedMesh& other, bool deepCpy):MEDCouplingMesh(other),_cell_2D_id(other._cell_2D_id)
{
- if(deepCopy)
+ if(deepCpy)
{
_mesh2D=other._mesh2D->clone(true);
_mesh1D=other._mesh1D->clone(true);
private:
MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId);
MEDCouplingMappedExtrudedMesh(const MEDCouplingCMesh *mesh3D);
- MEDCouplingMappedExtrudedMesh(const MEDCouplingMappedExtrudedMesh& other, bool deepCopy);
+ MEDCouplingMappedExtrudedMesh(const MEDCouplingMappedExtrudedMesh& other, bool deepCpy);
MEDCouplingMappedExtrudedMesh();
void computeExtrusion(const MEDCouplingUMesh *mesh3D);
void computeExtrusionAlg(const MEDCouplingUMesh *mesh3D);
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include "MEDCouplingMemArray.txx"
template class MEDCoupling::MemArray<double>;
template class MEDCoupling::DataArrayTemplate<int>;
template class MEDCoupling::DataArrayTemplate<double>;
+template class MEDCoupling::DataArrayTemplateClassic<int>;
+template class MEDCoupling::DataArrayTemplateClassic<double>;
+template class MEDCoupling::DataArrayTemplateFP<double>;
+template class MEDCoupling::DataArrayIterator<double>;
+template class MEDCoupling::DataArrayIterator<int>;
+template class MEDCoupling::DataArrayDiscrete<Int32>;
+template class MEDCoupling::DataArrayDiscreteSigned<Int32>;
template<int SPACEDIM>
void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other)
{
- int nbOfCompo=getNumberOfComponents();
+ std::size_t nbOfCompo(getNumberOfComponents());
std::size_t partOfCompoToSet=compoIds.size();
- if((int)partOfCompoToSet!=other.getNumberOfComponents())
+ if(partOfCompoToSet!=other.getNumberOfComponents())
throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !");
for(std::size_t i=0;i<partOfCompoToSet;i++)
- if(compoIds[i]>=nbOfCompo || compoIds[i]<0)
+ if(compoIds[i]>=(int)nbOfCompo || compoIds[i]<0)
{
std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
throw INTERP_KERNEL::Exception(oss.str().c_str());
*/
void DataArray::setInfoOnComponents(const std::vector<std::string>& info)
{
- if(getNumberOfComponents()!=(int)info.size())
+ if(getNumberOfComponents()!=info.size())
{
std::ostringstream oss; oss << "DataArray::setInfoOnComponents : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
*/
void DataArray::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info)
{
- if(getNumberOfComponents()!=(int)info.size())
+ if(getNumberOfComponents()!=info.size())
{
if(!isAllocated())
_info_on_compo=info;
void DataArray::checkNbOfComps(int nbOfCompo, const std::string& msg) const
{
- if(getNumberOfComponents()!=nbOfCompo)
+ if((int)getNumberOfComponents()!=nbOfCompo)
{
std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
return new DataArrayDouble(*this);
}
-/*!
- * Returns either a \a deep or \a shallow copy of this array. For more info see
- * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
- * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
- * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
- * == \a true) or \a this instance (if \a dCpy == \a false).
- */
-DataArrayDouble *DataArrayDouble::performCopyOrIncrRef(bool dCpy) const
-{
- if(dCpy)
- return deepCopy();
- else
- {
- incrRef();
- return const_cast<DataArrayDouble *>(this);
- }
-}
-
/*!
* Assign zero to all values in \a this array. To know more on filling arrays see
* \ref MEDCouplingArrayFill.
fillWithValue(0.);
}
-/*!
- * Set all values in \a this array so that the i-th element equals to \a init + i
- * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
- * \param [in] init - value to assign to the first element of array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::iota(double init)
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
- double *ptr=getPointer();
- int ntuples=getNumberOfTuples();
- for(int i=0;i<ntuples;i++)
- ptr[i]=init+double(i);
- declareAsNew();
-}
-
-/*!
- * Checks if all values in \a this array are equal to \a val at precision \a eps.
- * \param [in] val - value to check equality of array values to.
- * \param [in] eps - precision to check the equality.
- * \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
- * \a false else.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this is not allocated.
- */
-bool DataArrayDouble::isUniform(double val, double eps) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- const double *w=getConstPointer();
- const double *end2=w+nbOfTuples;
- const double vmin=val-eps;
- const double vmax=val+eps;
- for(;w!=end2;w++)
- if(*w<vmin || *w>vmax)
- return false;
- return true;
-}
-
/*!
* Checks that \a this array is consistently **increasing** or **decreasing** in value,
* with at least absolute difference value of |\a eps| at each step.
void DataArrayDouble::reprCppStream(const std::string& varName, std::ostream& stream) const
{
- int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
- const double *data=getConstPointer();
+ int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
+ const double *data(getConstPointer());
stream.precision(17);
stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl;
if(nbTuples*nbComp>=1)
return _mem.isEqual(other._mem,prec,tmp);
}
-/*!
- * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
- * array to the new one.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- */
-DataArrayInt *DataArrayDouble::convertToIntArr() const
-{
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(getNumberOfTuples(),getNumberOfComponents());
- int *dest=ret->getPointer();
- // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest);
- for(const double *src=begin();src!=end();src++,dest++)
- *dest=(int)*src;
- ret->copyStringInfoFrom(*this);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::fromNoInterlace() const
-{
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
- double *tab=_mem.fromNoInterlace(getNumberOfComponents());
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::toNoInterlace() const
-{
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
- double *tab=_mem.toNoInterlace(getNumberOfComponents());
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of
- * components increases.
- * \param [in] other - the DataArrayDouble to append to \a this one.
- * \throw If \a this is not allocated.
- * \throw If \a this and \a other arrays have different number of tuples.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
- *
- * \ref py_mcdataarraydouble_meldwith "Here is a Python example".
- * \endif
- */
-void DataArrayDouble::meldWith(const DataArrayDouble *other)
-{
- checkAllocated();
- other->checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples!=other->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
- int nbOfComp1=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- double *newArr=(double *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(double));
- double *w=newArr;
- const double *inp1=getConstPointer();
- const double *inp2=other->getConstPointer();
- for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
- {
- w=std::copy(inp1,inp1+nbOfComp1,w);
- w=std::copy(inp2,inp2+nbOfComp2,w);
- }
- useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
- std::vector<int> compIds(nbOfComp2);
- for(int i=0;i<nbOfComp2;i++)
- compIds[i]=nbOfComp1+i;
- copyPartOfStringInfoFrom2(compIds,*other);
-}
-
/*!
* This method checks that all tuples in \a other are in \a this.
* If true, the output param \a tupleIds contains the tuples ids of \a this that correspond to tupes in \a this.
commIndex=cI.retn();
}
-/*!
- *
- * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
- * \a nbTimes should be at least equal to 1.
- * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
- * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1.
- */
-DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
- if(nbTimes<1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
- int nbTuples=getNumberOfTuples();
- const double *inPtr=getConstPointer();
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
- double *retPtr=ret->getPointer();
- for(int i=0;i<nbTuples;i++,inPtr++)
- {
- double val=*inPtr;
- for(int j=0;j<nbTimes;j++,retPtr++)
- *retPtr=val;
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
/*!
* This methods returns the minimal distance between the two set of points \a this and \a other.
* So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
if(!other)
throw INTERP_KERNEL::Exception("DataArrayDouble::findClosestTupleId : other instance is NULL !");
checkAllocated(); other->checkAllocated();
- int nbOfCompo=getNumberOfComponents();
+ std::size_t nbOfCompo(getNumberOfComponents());
if(nbOfCompo!=other->getNumberOfComponents())
{
std::ostringstream oss; oss << "DataArrayDouble::findClosestTupleId : number of components in this is " << nbOfCompo;
throw INTERP_KERNEL::Exception("DataArrayDouble::computeNbOfInteractionsWith : input array is NULL !");
if(!isAllocated() || !otherBBoxFrmt->isAllocated())
throw INTERP_KERNEL::Exception("DataArrayDouble::computeNbOfInteractionsWith : this and input array must be allocated !");
- int nbOfComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
+ std::size_t nbOfComp(getNumberOfComponents());
+ int nbOfTuples(getNumberOfTuples());
if(nbOfComp!=otherBBoxFrmt->getNumberOfComponents())
{
std::ostringstream oss; oss << "DataArrayDouble::computeNbOfInteractionsWith : this number of components (" << nbOfComp << ") must be equal to the number of components of input array (" << otherBBoxFrmt->getNumberOfComponents() << ") !";
nc[nbOfCompo*i+compoIds[j]]=*ac;
}
-void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
-{
- if(newArray!=arrayToSet)
- {
- if(arrayToSet)
- arrayToSet->decrRef();
- arrayToSet=newArray;
- if(arrayToSet)
- arrayToSet->incrRef();
- }
-}
-
-void DataArrayDouble::aggregate(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
- if(getNumberOfComponents()!=other->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
- _mem.insertAtTheEnd(other->begin(),other->end());
-}
-
/*!
* Checks if 0.0 value is present in \a this array. If it is the case, an exception
* is thrown.
return ret.retn();
}
+/*!
+ * This method is close to numpy cumSum except that number of element is equal to \a this->getNumberOfTuples()+1. First element of DataArray returned is equal to 0.
+ * This method expects that \a this as only one component. The returned array will have \a this->getNumberOfTuples()+1 tuple with also one component.
+ * The ith element of returned array is equal to the sum of elements in \a this with rank strictly lower than i.
+ *
+ * \return DataArrayDouble - A newly built array containing cum sum of \a this.
+ */
+MCAuto<DataArrayDouble> DataArrayDouble::cumSum() const
+{
+ checkAllocated();
+ checkNbOfComps(1,"DataArrayDouble::cumSum : this is expected to be single component");
+ int nbOfTuple(getNumberOfTuples());
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfTuple+1,1);
+ double *ptr(ret->getPointer());
+ ptr[0]=0.;
+ const double *thisPtr(begin());
+ for(int i=0;i<nbOfTuple;i++)
+ ptr[i+1]=ptr[i]+thisPtr[i];
+ return ret;
+}
+
/*!
* Converts each 2D point defined by the tuple of \a this array from the Polar to the
* Cartesian coordinate system. The two components of the tuple of \a this array are
declareAsNew();
}
-/*!
- * Converts every value of \a this array to its absolute value.
- * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
- * should be called instead.
- *
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::computeAbs
- */
-void DataArrayDouble::abs()
-{
- checkAllocated();
- double *ptr(getPointer());
- std::size_t nbOfElems(getNbOfElems());
- std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
- declareAsNew();
-}
-
-/*!
- * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
- * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
- *
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::abs
- */
-DataArrayDouble *DataArrayDouble::computeAbs() const
-{
- checkAllocated();
- DataArrayDouble *newArr(DataArrayDouble::New());
- int nbOfTuples(getNumberOfTuples());
- int nbOfComp(getNumberOfComponents());
- newArr->alloc(nbOfTuples,nbOfComp);
- std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<double,double>(fabs));
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
-/*!
- * Apply a linear function to a given component of \a this array, so that
- * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
- */
-void DataArrayDouble::applyLin(double a, double b, int compoId)
-{
- checkAllocated();
- double *ptr(getPointer()+compoId);
- int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
- if(compoId<0 || compoId>=nbOfComp)
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Apply a linear function to all elements of \a this array, so that
- * an element _x_ becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::applyLin(double a, double b)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
declareAsNew();
}
-/*!
- * Returns a full copy of \a this array except that sign of all elements is reversed.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::negate() const
-{
- checkAllocated();
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *cptr=getConstPointer();
- std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes <em> val ^ x </em>. Contrary to DataArrayInt::applyPow
if(a.empty())
throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
- int nbOfComp=(*it)->getNumberOfComponents();
+ std::size_t nbOfComp((*it)->getNumberOfComponents());
int nbt=(*it++)->getNumberOfTuples();
for(int i=1;it!=a.end();it++,i++)
{
return ret.retn();
}
-/*!
- * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If both \a a1 and \a a2 are NULL.
- * \throw If any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- */
-DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- std::vector<const DataArrayDouble *> arr(2);
- arr[0]=a1; arr[1]=a2;
- return Meld(arr);
-}
-
-/*!
- * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] arr - a sequence of arrays to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If all arrays within \a arr are NULL.
- * \throw If any given array is not allocated.
- * \throw If getNumberOfTuples() of arrays within \a arr is different.
- */
-DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr)
-{
- std::vector<const DataArrayDouble *> a;
- for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
- std::vector<const DataArrayDouble *>::const_iterator it;
- for(it=a.begin();it!=a.end();it++)
- (*it)->checkAllocated();
- it=a.begin();
- int nbOfTuples=(*it)->getNumberOfTuples();
- std::vector<int> nbc(a.size());
- std::vector<const double *> pts(a.size());
- nbc[0]=(*it)->getNumberOfComponents();
- pts[0]=(*it++)->getConstPointer();
- for(int i=1;it!=a.end();it++,i++)
- {
- if(nbOfTuples!=(*it)->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
- nbc[i]=(*it)->getNumberOfComponents();
- pts[i]=(*it)->getConstPointer();
- }
- int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples,totalNbOfComp);
- double *retPtr=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<(int)a.size();j++)
- {
- retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
- pts[j]+=nbc[j];
- }
- int k=0;
- for(int i=0;i<(int)a.size();i++)
- for(int j=0;j<nbc[i];j++,k++)
- ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
- return ret;
-}
-
/*!
* Returns a new DataArrayDouble containing a dot product of two given arrays, so that
* the i-th tuple of the result array is a sum of products of j-th components of i-th
throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
a1->checkAllocated();
a2->checkAllocated();
- int nbOfComp=a1->getNumberOfComponents();
+ std::size_t nbOfComp(a1->getNumberOfComponents());
if(nbOfComp!=a2->getNumberOfComponents())
throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
int nbOfTuple=a1->getNumberOfTuples();
for(int i=0;i<nbOfTuple;i++)
{
double sum=0.;
- for(int j=0;j<nbOfComp;j++)
+ for(std::size_t j=0;j<nbOfComp;j++)
sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
retPtr[i]=sum;
}
{
if(!a1 || !a2)
throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
+ std::size_t nbOfComp(a1->getNumberOfComponents());
if(nbOfComp!=a2->getNumberOfComponents())
throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
if(nbOfComp!=3)
{
if(!a1 || !a2)
throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
+ std::size_t nbOfComp(a1->getNumberOfComponents());
if(nbOfComp!=a2->getNumberOfComponents())
throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
int nbOfTuple=a1->getNumberOfTuples();
{
if(!a1 || !a2)
throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
+ std::size_t nbOfComp(a1->getNumberOfComponents());
if(nbOfComp!=a2->getNumberOfComponents())
throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
int nbOfTuple=a1->getNumberOfTuples();
}
/*!
- * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
+ * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
* valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
- * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
*
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to sum up.
+ * \param [in] a1 - an array to pow up.
* \param [in] a2 - another array to sum up.
* \return DataArrayDouble * - the new instance of DataArrayDouble.
* The caller is to delete this result array using decrRef() as it is no more
* needed.
* \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
+ * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
+ * \throw If there is a negative value in \a a1.
*/
-DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2)
+DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !");
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
int nbOfTuple=a1->getNumberOfTuples();
int nbOfTuple2=a2->getNumberOfTuples();
int nbOfComp=a1->getNumberOfComponents();
int nbOfComp2=a2->getNumberOfComponents();
- MCAuto<DataArrayDouble> ret=0;
- if(nbOfTuple==nbOfTuple2)
+ if(nbOfTuple!=nbOfTuple2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
+ if(nbOfComp!=1 || nbOfComp2!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
+ MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
+ const double *ptr1(a1->begin()),*ptr2(a2->begin());
+ double *ptr=ret->getPointer();
+ for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
{
- if(nbOfComp==nbOfComp2)
+ if(*ptr1>=0)
{
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
- ret->copyStringInfoFrom(*a1);
+ *ptr=pow(*ptr1,*ptr2);
}
else
{
- int nbOfCompMin,nbOfCompMax;
- const DataArrayDouble *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
- else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const double *aMinPtr=aMin->getConstPointer();
- const double *aMaxPtr=aMax->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
- }
- }
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
- ret->copyStringInfoFrom(*aMax);
+ std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
}
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
return ret.retn();
}
/*!
- * Adds values of another DataArrayDouble to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is added to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] += _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] += _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] += _a2_ [ 0, j ].
+ * Apply pow on values of another DataArrayDouble to values of \a this one.
*
- * \param [in] other - an array to add to \a this one.
+ * \param [in] other - an array to pow to \a this one.
* \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
+ * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
+ * \throw If there is a negative value in \a this.
*/
-void DataArrayDouble::addEqual(const DataArrayDouble *other)
+void DataArrayDouble::powEqual(const DataArrayDouble *other)
{
if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !";
- checkAllocated();
- other->checkAllocated();
+ throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
int nbOfTuple=getNumberOfTuples();
int nbOfTuple2=other->getNumberOfTuples();
int nbOfComp=getNumberOfComponents();
int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
+ if(nbOfTuple!=nbOfTuple2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
+ if(nbOfComp!=1 || nbOfComp2!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
+ double *ptr=getPointer();
+ const double *ptrc=other->begin();
+ for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
{
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
- }
+ if(*ptr>=0)
+ *ptr=pow(*ptr,*ptrc);
else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
{
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
+ std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception(msg);
}
- else
- throw INTERP_KERNEL::Exception(msg);
declareAsNew();
}
/*!
- * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
+ * This method is \b NOT wrapped into python because it can be useful only for performance reasons in C++ context.
+ * All values in \a this must be 0. or 1. within eps error. 0 means false, 1 means true.
+ * If an another value than 0 or 1 appear (within eps precision) an INTERP_KERNEL::Exception will be thrown.
*
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to subtract from.
- * \param [in] a2 - an array to subtract.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * \throw if \a this is not allocated.
+ * \throw if \a this has not exactly one component.
*/
-DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2)
+std::vector<bool> DataArrayDouble::toVectorOfBool(double eps) const
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::toVectorOfBool : must be applied on single component array !");
+ int nbt(getNumberOfTuples());
+ std::vector<bool> ret(nbt);
+ const double *pt(begin());
+ for(int i=0;i<nbt;i++)
{
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
+ if(fabs(pt[i])<eps)
+ ret[i]=false;
+ else if(fabs(pt[i]-1.)<eps)
+ ret[i]=true;
else
{
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- return 0;
+ std::ostringstream oss; oss << "DataArrayDouble::toVectorOfBool : the tuple #" << i << " has value " << pt[i] << " is invalid ! must be 0. or 1. !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- else if(nbOfTuple2==1)
+ return ret;
+}
+
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * Server side.
+ */
+void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.resize(2);
+ if(isAllocated())
{
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
+ tinyInfo[0]=getNumberOfTuples();
+ tinyInfo[1]=getNumberOfComponents();
}
else
{
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
- return 0;
+ tinyInfo[0]=-1;
+ tinyInfo[1]=-1;
}
}
/*!
- * Subtract values of another DataArrayDouble from values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is subtracted from the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] -= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] -= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] -= _a2_ [ 0, j ].
- *
- * \param [in] other - an array to subtract from \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * Server side.
*/
-void DataArrayDouble::substractEqual(const DataArrayDouble *other)
+void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
+ if(isAllocated())
{
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ int nbOfCompo=getNumberOfComponents();
+ tinyInfo.resize(nbOfCompo+1);
+ tinyInfo[0]=getName();
+ for(int i=0;i<nbOfCompo;i++)
+ tinyInfo[i+1]=getInfoOnComponent(i);
}
- else if(nbOfTuple2==1)
+ else
{
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ tinyInfo.resize(1);
+ tinyInfo[0]=getName();
}
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
}
/*!
- * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a product of the corresponding values of \a a1 and
- * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - a factor array.
- * \param [in] a2 - another factor array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * This method returns if a feeding is needed.
*/
-DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2)
+bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- MCAuto<DataArrayDouble> ret=0;
- if(nbOfTuple==nbOfTuple2)
+ int nbOfTuple=tinyInfoI[0];
+ int nbOfComp=tinyInfoI[1];
+ if(nbOfTuple!=-1 || nbOfComp!=-1)
{
- if(nbOfComp==nbOfComp2)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
- ret->copyStringInfoFrom(*a1);
- }
- else
- {
- int nbOfCompMin,nbOfCompMax;
- const DataArrayDouble *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
- else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const double *aMinPtr=aMin->getConstPointer();
- const double *aMaxPtr=aMax->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
+ alloc(nbOfTuple,nbOfComp);
+ return true;
}
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
+ return false;
+}
+
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ */
+void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
+{
+ setName(tinyInfoS[0]);
+ if(isAllocated())
{
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<double>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
+ int nbOfCompo=getNumberOfComponents();
+ for(int i=0;i<nbOfCompo;i++)
+ setInfoOnComponent(i,tinyInfoS[i+1]);
}
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
- return ret.retn();
}
/*!
- * Multiply values of another DataArrayDouble to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is multiplied to the corresponding value of \a this array, i.e.
- * _this_ [ i, j ] *= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _this_ [ i, j ] *= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _this_ [ i, j ] *= _a2_ [ 0, j ].
- *
- * \param [in] other - an array to multiply to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * Low static method that operates 3D rotation of 'nbNodes' 3D nodes whose coordinates are arranged in \a coordsIn
+ * around an axe ( \a center, \a vect) and with angle \a angle.
*/
-void DataArrayDouble::multiplyEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a division of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \warning No check of division by zero is performed!
- * \param [in] a1 - a numerator array.
- * \param [in] a2 - a denominator array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
- */
-DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
- return 0;
- }
-}
-
-/*!
- * Divide values of \a this array by values of another DataArrayDouble. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a this array is divided by the corresponding value of \a other one, i.e.:
- * _a_ [ i, j ] /= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] /= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] /= _a2_ [ 0, j ].
- *
- * \warning No check of division by zero is performed!
- * \param [in] other - an array to divide \a this one by.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::divideEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
- * valid cases.
- *
- * \param [in] a1 - an array to pow up.
- * \param [in] a2 - another array to sum up.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
- * \throw If there is a negative value in \a a1.
- */
-DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
- const double *ptr1(a1->begin()),*ptr2(a2->begin());
- double *ptr=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
- {
- if(*ptr1>=0)
- {
- *ptr=pow(*ptr1,*ptr2);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
-}
-
-/*!
- * Apply pow on values of another DataArrayDouble to values of \a this one.
- *
- * \param [in] other - an array to pow to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
- * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
- * \throw If there is a negative value in \a this.
- */
-void DataArrayDouble::powEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
- double *ptr=getPointer();
- const double *ptrc=other->begin();
- for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
- {
- if(*ptr>=0)
- *ptr=pow(*ptr,*ptrc);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * This method is \b NOT wrapped into python because it can be useful only for performance reasons in C++ context.
- * All values in \a this must be 0. or 1. within eps error. 0 means false, 1 means true.
- * If an another value than 0 or 1 appear (within eps precision) an INTERP_KERNEL::Exception will be thrown.
- *
- * \throw if \a this is not allocated.
- * \throw if \a this has not exactly one component.
- */
-std::vector<bool> DataArrayDouble::toVectorOfBool(double eps) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::toVectorOfBool : must be applied on single component array !");
- int nbt(getNumberOfTuples());
- std::vector<bool> ret(nbt);
- const double *pt(begin());
- for(int i=0;i<nbt;i++)
- {
- if(fabs(pt[i])<eps)
- ret[i]=false;
- else if(fabs(pt[i]-1.)<eps)
- ret[i]=true;
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::toVectorOfBool : the tuple #" << i << " has value " << pt[i] << " is invalid ! must be 0. or 1. !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret;
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
-{
- tinyInfo.resize(2);
- if(isAllocated())
- {
- tinyInfo[0]=getNumberOfTuples();
- tinyInfo[1]=getNumberOfComponents();
- }
- else
- {
- tinyInfo[0]=-1;
- tinyInfo[1]=-1;
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
-{
- if(isAllocated())
- {
- int nbOfCompo=getNumberOfComponents();
- tinyInfo.resize(nbOfCompo+1);
- tinyInfo[0]=getName();
- for(int i=0;i<nbOfCompo;i++)
- tinyInfo[i+1]=getInfoOnComponent(i);
- }
- else
- {
- tinyInfo.resize(1);
- tinyInfo[0]=getName();
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * This method returns if a feeding is needed.
- */
-bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
-{
- int nbOfTuple=tinyInfoI[0];
- int nbOfComp=tinyInfoI[1];
- if(nbOfTuple!=-1 || nbOfComp!=-1)
- {
- alloc(nbOfTuple,nbOfComp);
- return true;
- }
- return false;
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- */
-void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
-{
- setName(tinyInfoS[0]);
- if(isAllocated())
- {
- int nbOfCompo=getNumberOfComponents();
- for(int i=0;i<nbOfCompo;i++)
- setInfoOnComponent(i,tinyInfoS[i+1]);
- }
-}
-
-/*!
- * Low static method that operates 3D rotation of 'nbNodes' 3D nodes whose coordinates are arranged in \a coordsIn
- * around an axe ( \a center, \a vect) and with angle \a angle.
- */
-void DataArrayDouble::Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut)
+void DataArrayDouble::Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut)
{
if(!center || !vect)
throw INTERP_KERNEL::Exception("DataArrayDouble::Rotate3DAlg : null vector in input !");
}
}
-DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
-{
- if(_da)
- {
- _da->incrRef();
- if(_da->isAllocated())
- {
- _nb_comp=da->getNumberOfComponents();
- _nb_tuple=da->getNumberOfTuples();
- _pt=da->getPointer();
- }
- }
-}
-
-DataArrayDoubleIterator::~DataArrayDoubleIterator()
+DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):DataArrayIterator<double>(da)
{
- if(_da)
- _da->decrRef();
-}
-
-DataArrayDoubleTuple *DataArrayDoubleIterator::nextt()
-{
- if(_tuple_id<_nb_tuple)
- {
- _tuple_id++;
- DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
- _pt+=_nb_comp;
- return ret;
- }
- else
- return 0;
}
-DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
+DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):DataArrayTuple<double>(pt,nbOfComp)
{
}
double DataArrayDoubleTuple::doubleValue() const
{
- if(_nb_of_compo==1)
- return *_pt;
- throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
+ return this->zeValue();
}
/*!
*/
DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const
{
- if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
- {
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
- return ret;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
- oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ return this->buildDA(nbOfTuples,nbOfCompo);
}
/*!
* \ref MEDCouplingArrayBasicsCopyDeep.
* \return DataArrayInt * - a new instance of DataArrayInt.
*/
-DataArrayInt *DataArrayInt::deepCopy() const
-{
- return new DataArrayInt(*this);
-}
-
-/*!
- * Returns either a \a deep or \a shallow copy of this array. For more info see
- * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
- * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
- * \return DataArrayInt * - either a new instance of DataArrayInt (if \a dCpy
- * == \a true) or \a this instance (if \a dCpy == \a false).
- */
-DataArrayInt *DataArrayInt::performCopyOrIncrRef(bool dCpy) const
+DataArrayInt32 *DataArrayInt32::deepCopy() const
{
- if(dCpy)
- return deepCopy();
- else
- {
- incrRef();
- return const_cast<DataArrayInt *>(this);
- }
+ return new DataArrayInt32(*this);
}
/*!
stream << "]";
}
-/*!
- * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
- * i.e. a current value is used as in index to get a new value from \a indArrBg.
- * \param [in] indArrBg - pointer to the first element of array of new values to assign
- * to \a this array.
- * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
- * the last value of \a indArrBg is \a indArrEnd[ -1 ].
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If any value of \a this can't be used as a valid index for
- * [\a indArrBg, \a indArrEnd).
- *
- * \sa changeValue
- */
-void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd)
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbElemsIn((int)std::distance(indArrBg,indArrEnd)),nbOfTuples(getNumberOfTuples()),*pt(getPointer());
- for(int i=0;i<nbOfTuples;i++,pt++)
- {
- if(*pt>=0 && *pt<nbElemsIn)
- *pt=indArrBg[*pt];
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
/*!
* Computes distribution of values of \a this one-dimensional array between given value
* ranges (casts). This method is typically useful for entity number spliting by types,
}
}
+
+/*!
+ * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
+ * i.e. a current value is used as in index to get a new value from \a indArrBg.
+ * \param [in] indArrBg - pointer to the first element of array of new values to assign
+ * to \a this array.
+ * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
+ * the last value of \a indArrBg is \a indArrEnd[ -1 ].
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If any value of \a this can't be used as a valid index for
+ * [\a indArrBg, \a indArrEnd).
+ *
+ * \sa changeValue
+ */
+void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd)
+{
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ int nbElemsIn((int)std::distance(indArrBg,indArrEnd)),nbOfTuples(getNumberOfTuples()),*pt(getPointer());
+ for(int i=0;i<nbOfTuples;i++,pt++)
+ {
+ if(*pt>=0 && *pt<nbElemsIn)
+ *pt=indArrBg[*pt];
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ this->declareAsNew();
+}
+
+void DataArrayInt::transformWithIndArr(const MapKeyVal<int>& m)
+{
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ const std::map<int,int> dat(m.data());
+ int nbOfTuples(getNumberOfTuples()),*pt(getPointer());
+ for(int i=0;i<nbOfTuples;i++,pt++)
+ {
+ std::map<int,int>::const_iterator it(dat.find(*pt));
+ if(it!=dat.end())
+ *pt=(*it).second;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ this->declareAsNew();
+}
+
/*!
* Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from
* values of \a this (\a a) and the given (\a indArr) arrays as follows:
*/
DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
{
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
+ MCAuto<DataArrayInt> ret(DataArrayInt::New());
ret->alloc(newNbOfElem,1);
- int nbOfOldNodes=getNumberOfTuples();
- const int *old2New=getConstPointer();
- int *pt=ret->getPointer();
+ int nbOfOldNodes(this->getNumberOfTuples());
+ const int *old2New(begin());
+ int *pt(ret->getPointer());
for(int i=0;i!=nbOfOldNodes;i++)
{
int newp(old2New[i]);
{
std::ostringstream oss; oss << "DataArrayInt::invertArrayO2N2N2OBis : At place #" << i << " the newplace is " << newp << " must be in [0," << newNbOfElem << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- return ret.retn();
-}
-
-/*!
- * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
- * from values of \a this array, which is supposed to contain a renumbering map in
- * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
- * To know how to use the renumbering maps see \ref numbering.
- * \param [in] newNbOfElem - the number of tuples in the result array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(oldNbOfElem,1);
- const int *new2Old=getConstPointer();
- int *pt=ret->getPointer();
- std::fill(pt,pt+oldNbOfElem,-1);
- int nbOfNewElems=getNumberOfTuples();
- for(int i=0;i<nbOfNewElems;i++)
- {
- int v(new2Old[i]);
- if(v>=0 && v<oldNbOfElem)
- pt[v]=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::invertArrayN2O2O2N : in new id #" << i << " old value is " << v << " expected to be in [0," << oldNbOfElem << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
-}
-
-/*!
- * Equivalent to DataArrayInt::isEqual except that if false the reason of
- * mismatch is given.
- *
- * \param [in] other the instance to be compared with \a this
- * \param [out] reason In case of inequality returns the reason.
- * \sa DataArrayInt::isEqual
- */
-bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const
-{
- if(!areInfoEqualsIfNotWhy(other,reason))
- return false;
- return _mem.isEqual(other._mem,0,reason);
-}
-
-/*!
- * Checks if \a this and another DataArrayInt are fully equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqual(const DataArrayInt& other) const
-{
- std::string tmp;
- return isEqualIfNotWhy(other,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const
-{
- std::string tmp;
- return _mem.isEqual(other._mem,0,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. Comparison is
- * performed on sorted value sequences.
- * For more info see\ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const
-{
- MCAuto<DataArrayInt> a=deepCopy();
- MCAuto<DataArrayInt> b=other.deepCopy();
- a->sort();
- b->sort();
- return a->isEqualWithoutConsideringStr(*b);
-}
-
-/*!
- * This method compares content of input vector \a v and \a this.
- * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
- * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
- *
- * \param [in] v - the vector of 'flags' to be compared with \a this.
- *
- * \throw If \a this is not sorted ascendingly.
- * \throw If \a this has not exactly one component.
- * \throw If \a this is not allocated.
- */
-bool DataArrayInt::isFittingWith(const std::vector<bool>& v) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
- const int *w(begin()),*end2(end());
- int refVal=-std::numeric_limits<int>::max();
- int i=0;
- std::vector<bool>::const_iterator it(v.begin());
- for(;it!=v.end();it++,i++)
- {
- if(*it)
- {
- if(w!=end2)
- {
- if(*w++==i)
- {
- if(i>refVal)
- refVal=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(begin(),w-1) << " this is not sorted ascendingly !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- return false;
- }
- else
- return false;
+ }
}
}
- return w==end2;
+ return ret.retn();
}
/*!
- * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
- * put True to the corresponding entry in \a vec.
- * \a vec is expected to be with the same size than the number of tuples of \a this.
+ * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
+ * from values of \a this array, which is supposed to contain a renumbering map in
+ * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
+ * To know how to use the renumbering maps see \ref numbering.
+ * \param [in] newNbOfElem - the number of tuples in the result array.
+ * \return DataArrayInt * - the new instance of DataArrayInt.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
*
- * \sa DataArrayInt::switchOnTupleNotEqualTo.
+ * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
+ * \sa invertArrayN2O2O2NOptimized
+ * \endif
*/
-void DataArrayInt::switchOnTupleEqualTo(int val, std::vector<bool>& vec) const
+DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
{
checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=(int)vec.size())
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
- const int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(pt[i]==val)
- vec[i]=true;
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(oldNbOfElem,1);
+ const int *new2Old=getConstPointer();
+ int *pt=ret->getPointer();
+ std::fill(pt,pt+oldNbOfElem,-1);
+ int nbOfNewElems=getNumberOfTuples();
+ for(int i=0;i<nbOfNewElems;i++)
+ {
+ int v(new2Old[i]);
+ if(v>=0 && v<oldNbOfElem)
+ pt[v]=i;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::invertArrayN2O2O2N : in new id #" << i << " old value is " << v << " expected to be in [0," << oldNbOfElem << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return ret.retn();
}
/*!
- * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
- * put True to the corresponding entry in \a vec.
- * \a vec is expected to be with the same size than the number of tuples of \a this.
+ * Creates a map, whose contents are computed
+ * from values of \a this array, which is supposed to contain a renumbering map in
+ * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
+ * To know how to use the renumbering maps see \ref numbering.
+ * \param [in] newNbOfElem - the number of tuples in the result array.
+ * \return MapII - the new instance of Map.
*
- * \sa DataArrayInt::switchOnTupleEqualTo.
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
+ *
+ * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
+ * \sa invertArrayN2O2O2N
+ * \endif
*/
-void DataArrayInt::switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const
+MCAuto< MapKeyVal<int> > DataArrayInt::invertArrayN2O2O2NOptimized() const
{
checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=(int)vec.size())
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !");
- const int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(pt[i]!=val)
- vec[i]=true;
+ MCAuto< MapKeyVal<int> > ret(MapKeyVal<int>::New());
+ std::map<int,int>& m(ret->data());
+ const int *new2Old(begin());
+ int nbOfNewElems(this->getNumberOfTuples());
+ for(int i=0;i<nbOfNewElems;i++)
+ {
+ int v(new2Old[i]);
+ m[v]=i;
+ }
+ return ret;
}
/*!
std::map<int,int> m;
for(int i=0;i<thisNbTuples;i++,thisPt++)
m[*thisPt]=i;
- if(m.size()!=thisNbTuples)
+ if((int)m.size()!=thisNbTuples)
throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
for(int i=0;i<nbTuples;i++,retPt++,pt++)
{
return ret.retn();
}
-void DataArrayInt::aggregate(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : null pointer !");
- if(getNumberOfComponents()!=other->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : mismatch number of components !");
- _mem.insertAtTheEnd(other->begin(),other->end());
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::fromNoInterlace() const
-{
- checkAllocated();
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
- int *tab=_mem.fromNoInterlace(getNumberOfComponents());
- DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::toNoInterlace() const
-{
- checkAllocated();
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
- int *tab=_mem.toNoInterlace(getNumberOfComponents());
- DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
/*!
* Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
* This map, if applied to \a this array, would make it sorted. For example, if
* \return bool - \a true if all values are \a val.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1
+ * \sa DataArrayInt::checkUniformAndGuess
*/
bool DataArrayInt::isUniform(int val) const
{
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- const int *w=getConstPointer();
- const int *end2=w+nbOfTuples;
+ const int *w(begin()),*end2(end());
for(;w!=end2;w++)
if(*w!=val)
return false;
return true;
}
+/*!
+ * This method checks that \a this is uniform. If not and exception will be thrown.
+ * In case of uniformity the corresponding value is returned.
+ *
+ * \return int - the unique value contained in this
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If \a this is not uniform.
+ * \sa DataArrayInt::isUniform
+ */
+int DataArrayInt::checkUniformAndGuess() const
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ if(empty())
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : this is empty !");
+ const int *w(begin()),*end2(end());
+ int ret(*w);
+ for(;w!=end2;w++)
+ if(*w!=ret)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : this is not uniform !");
+ return ret;
+}
+
/*!
* Checks if all values in \a this array are unique.
* \return bool - \a true if condition above is true
throw INTERP_KERNEL::Exception("DataArrayInt::hasOnlyUniqueValues: must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
int nbOfTuples(getNumberOfTuples());
std::set<int> s(begin(),end()); // in C++11, should use unordered_set (O(1) complexity)
- if (s.size() != nbOfTuples)
+ if ((int)s.size() != nbOfTuples)
return false;
return true;
}
-/*!
- * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
- * array to the new one.
- * \return DataArrayDouble * - the new instance of DataArrayInt.
- */
-DataArrayDouble *DataArrayInt::convertToDblArr() const
-{
- checkAllocated();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),getNumberOfComponents());
- std::size_t nbOfVals=getNbOfElems();
- const int *src=getConstPointer();
- double *dest=ret->getPointer();
- std::copy(src,src+nbOfVals,dest);
- ret->copyStringInfoFrom(*this);
- return ret;
-}
-
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of
- * components increases.
- * \param [in] other - the DataArrayInt to append to \a this one.
- * \throw If \a this is not allocated.
- * \throw If \a this and \a other arrays have different number of tuples.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_meldwith "Here is a Python example".
- * \endif
- */
-void DataArrayInt::meldWith(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- other->checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples!=other->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
- int nbOfComp1=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
- int *w=newArr;
- const int *inp1=getConstPointer();
- const int *inp2=other->getConstPointer();
- for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
- {
- w=std::copy(inp1,inp1+nbOfComp1,w);
- w=std::copy(inp2,inp2+nbOfComp2,w);
- }
- useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
- std::vector<int> compIds(nbOfComp2);
- for(int i=0;i<nbOfComp2;i++)
- compIds[i]=nbOfComp1+i;
- copyPartOfStringInfoFrom2(compIds,*other);
-}
-
/*!
* Copy all components in a specified order from another DataArrayInt.
* The specified components become the first ones in \a this array.
nc[nbOfCompo*i+compoIds[j]]=*ac;
}
-/*!
- * Assign pointer to one array to a pointer to another appay. Reference counter of
- * \a arrayToSet is incremented / decremented.
- * \param [in] newArray - the pointer to array to assign to \a arrayToSet.
- * \param [in,out] arrayToSet - the pointer to array to assign to.
- */
-void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
-{
- if(newArray!=arrayToSet)
- {
- if(arrayToSet)
- arrayToSet->decrRef();
- arrayToSet=newArray;
- if(arrayToSet)
- arrayToSet->incrRef();
- }
-}
-
DataArrayIntIterator *DataArrayInt::iterator()
{
return new DataArrayIntIterator(this);
{
std::size_t nbOfCompoExp(std::distance(tupleBg,tupleEnd));
checkAllocated();
- if(getNumberOfComponents()!=(int)nbOfCompoExp)
+ if(getNumberOfComponents()!=nbOfCompoExp)
{
std::ostringstream oss; oss << "DataArrayInt::findIdsEqualTuple : mismatch of number of components. Input tuple has " << nbOfCompoExp << " whereas this array has " << getNumberOfComponents() << " components !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
{
if(!a1 || !a2)
throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
+ std::size_t nbOfComp(a1->getNumberOfComponents());
if(nbOfComp!=a2->getNumberOfComponents())
throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
int nbOfTuple1=a1->getNumberOfTuples();
if(a.empty())
throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
std::vector<const DataArrayInt *>::const_iterator it=a.begin();
- int nbOfComp=(*it)->getNumberOfComponents();
+ std::size_t nbOfComp((*it)->getNumberOfComponents());
int nbt=(*it++)->getNumberOfTuples();
for(int i=1;it!=a.end();it++,i++)
{
}
}
-/*!
- * Converts every value of \a this array to its absolute value.
- * \b WARNING this method is non const. If a new DataArrayInt instance should be built containing the result of abs DataArrayInt::computeAbs
- * should be called instead.
- *
- * \throw If \a this is not allocated.
- * \sa DataArrayInt::computeAbs
- */
-void DataArrayInt::abs()
-{
- checkAllocated();
- int *ptr(getPointer());
- std::size_t nbOfElems(getNbOfElems());
- std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
- declareAsNew();
-}
-
-/*!
- * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
- * This method is a const method (that do not change any values in \a this) contrary to DataArrayInt::abs method.
- *
- * \return DataArrayInt * - the new instance of DataArrayInt containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayInt::abs
- */
-DataArrayInt *DataArrayInt::computeAbs() const
-{
- checkAllocated();
- DataArrayInt *newArr(DataArrayInt::New());
- int nbOfTuples(getNumberOfTuples());
- int nbOfComp(getNumberOfComponents());
- newArr->alloc(nbOfTuples,nbOfComp);
- std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<int,int>(std::abs));
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
-/*!
- * Apply a liner function to a given component of \a this array, so that
- * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::applyLin(int a, int b, int compoId)
-{
- checkAllocated();
- int *ptr=getPointer()+compoId;
- int nbOfComp=getNumberOfComponents();
- int nbOfTuple=getNumberOfTuples();
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Apply a liner function to all elements of \a this array, so that
- * an element _x_ becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::applyLin(int a, int b)
-{
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Returns a full copy of \a this array except that sign of all elements is reversed.
- * \return DataArrayInt * - the new instance of DataArrayInt containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::negate() const
-{
- checkAllocated();
- DataArrayInt *newArr=DataArrayInt::New();
- int nbOfTuples=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const int *cptr=getConstPointer();
- std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
*/
DataArrayInt *DataArrayInt::findIdsInRange(int vmin, int vmax) const
{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsInRange : this must have exactly one component !");
- const int *cptr(begin());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr>=vmin && *cptr<vmax)
- ret->pushBackSilent(i);
+ InRange<int> ir(vmin,vmax);
+ MCAuto<DataArrayInt> ret(findIdsAdv(ir));
return ret.retn();
}
*/
DataArrayInt *DataArrayInt::findIdsNotInRange(int vmin, int vmax) const
{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsNotInRange : this must have exactly one component !");
- const int *cptr(getConstPointer());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr<vmin || *cptr>=vmax)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * This method works only on data array with one component. This method returns a newly allocated array storing stored ascendantly of tuple ids in \a this so that this[id]<0.
- *
- * \return a newly allocated data array that the caller should deal with.
- * \sa DataArrayInt::findIdsInRange
- */
-DataArrayInt *DataArrayInt::findIdsStricltyNegative() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsStricltyNegative : this must have exactly one component !");
- const int *cptr(getConstPointer());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr<0)
- ret->pushBackSilent(i);
+ NotInRange<int> nir(vmin,vmax);
+ MCAuto<DataArrayInt> ret(findIdsAdv(nir));
return ret.retn();
}
}
else
{
- std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayInt by aggregating two given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If both \a a1 and \a a2 are NULL.
- * \throw If any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- */
-DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2)
-{
- std::vector<const DataArrayInt *> arr(2);
- arr[0]=a1; arr[1]=a2;
- return Meld(arr);
-}
-
-/*!
- * Returns a new DataArrayInt by aggregating all given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] arr - a sequence of arrays to include in the result array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If all arrays within \a arr are NULL.
- * \throw If any given array is not allocated.
- * \throw If getNumberOfTuples() of arrays within \a arr is different.
- */
-DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr)
-{
- std::vector<const DataArrayInt *> a;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
- std::vector<const DataArrayInt *>::const_iterator it;
- for(it=a.begin();it!=a.end();it++)
- (*it)->checkAllocated();
- it=a.begin();
- int nbOfTuples=(*it)->getNumberOfTuples();
- std::vector<int> nbc(a.size());
- std::vector<const int *> pts(a.size());
- nbc[0]=(*it)->getNumberOfComponents();
- pts[0]=(*it++)->getConstPointer();
- for(int i=1;it!=a.end();it++,i++)
- {
- if(nbOfTuples!=(*it)->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !");
- nbc[i]=(*it)->getNumberOfComponents();
- pts[i]=(*it)->getConstPointer();
+ std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
+ oss << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
- int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(nbOfTuples,totalNbOfComp);
- int *retPtr=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<(int)a.size();j++)
- {
- retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
- pts[j]+=nbc[j];
- }
- int k=0;
- for(int i=0;i<(int)a.size();i++)
- for(int j=0;j<nbc[i];j++,k++)
- ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
- return ret;
+ declareAsNew();
}
/*!
if(!tmp[i])
retPtr[j++]=i;
return ret;
-}
-
-/*!
- * Returns a new DataArrayInt containing elements of \a this one-dimensional missing
- * from an \a other one-dimensional array.
- * \param [in] other - a DataArrayInt containing elements not to include in the result array.
- * \return DataArrayInt * - a new instance of DataArrayInt with one component. The
- * caller is to delete this array using decrRef() as it is no more needed.
- * \throw If \a other is NULL.
- * \throw If \a other is not allocated.
- * \throw If \a other->getNumberOfComponents() != 1.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \sa DataArrayInt::buildSubstractionOptimized()
- */
-DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- other->checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
- if(other->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
- const int *pt=getConstPointer();
- int nbOfTuples=getNumberOfTuples();
- std::set<int> s1(pt,pt+nbOfTuples);
- pt=other->getConstPointer();
- nbOfTuples=other->getNumberOfTuples();
- std::set<int> s2(pt,pt+nbOfTuples);
- std::vector<int> r;
- std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc((int)r.size(),1);
- std::copy(r.begin(),r.end(),ret->getPointer());
- return ret;
-}
-
-/*!
- * \a this is expected to have one component and to be sorted ascendingly (as for \a other).
- * \a other is expected to be a part of \a this. If not DataArrayInt::buildSubstraction should be called instead.
- *
- * \param [in] other an array with one component and expected to be sorted ascendingly.
- * \ret list of ids in \a this but not in \a other.
- * \sa DataArrayInt::buildSubstraction
- */
-DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const
-{
- static const char *MSG="DataArrayInt::buildSubstractionOptimized : only single component allowed !";
- if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstractionOptimized : NULL input array !");
- checkAllocated(); other->checkAllocated();
- if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
- if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
- const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end());
- const int *work1(pt1Bg),*work2(pt2Bg);
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- for(;work1!=pt1End;work1++)
- {
- if(work2!=pt2End && *work1==*work2)
- work2++;
- else
- ret->pushBackSilent(*work1);
- }
- return ret.retn();
-}
-
-
-/*!
- * Returns a new DataArrayInt which contains all elements of \a this and a given
- * one-dimensional arrays. The result array does not contain any duplicates
- * and its values are sorted in ascending order.
- * \param [in] other - an array to unite with \a this one.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this or \a other is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a other->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const
-{
- std::vector<const DataArrayInt *>arrs(2);
- arrs[0]=this; arrs[1]=other;
- return BuildUnion(arrs);
-}
-
-
-/*!
- * Returns a new DataArrayInt which contains elements present in both \a this and a given
- * one-dimensional arrays. The result array does not contain any duplicates
- * and its values are sorted in ascending order.
- * \param [in] other - an array to intersect with \a this one.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this or \a other is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a other->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const
-{
- std::vector<const DataArrayInt *>arrs(2);
- arrs[0]=this; arrs[1]=other;
- return BuildIntersection(arrs);
-}
-
-/*!
- * This method can be applied on allocated with one component DataArrayInt instance.
- * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance.
- * Example : if \a this contains [1,2,2,3,3,3,3,4,5,5,7,7,7,19] the returned array will contain [1,2,3,4,5,7,19]
- *
- * \return a newly allocated array that contain the result of the unique operation applied on \a this.
- * \throw if \a this is not allocated or if \a this has not exactly one component.
- * \sa DataArrayInt::buildUniqueNotSorted
- */
-DataArrayInt *DataArrayInt::buildUnique() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !");
- int nbOfTuples=getNumberOfTuples();
- MCAuto<DataArrayInt> tmp=deepCopy();
- int *data=tmp->getPointer();
- int *last=std::unique(data,data+nbOfTuples);
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(std::distance(data,last),1);
- std::copy(data,last,ret->getPointer());
- return ret.retn();
-}
-
-/*!
- * This method can be applied on allocated with one component DataArrayInt instance.
- * This method keep elements only once by keeping the same order in \a this that is not expected to be sorted.
- *
- * \return a newly allocated array that contain the result of the unique operation applied on \a this.
- *
- * \throw if \a this is not allocated or if \a this has not exactly one component.
- *
- * \sa DataArrayInt::buildUnique
- */
-DataArrayInt *DataArrayInt::buildUniqueNotSorted() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildUniqueNotSorted : only single component allowed !");
- int minVal,maxVal;
- getMinMaxValues(minVal,maxVal);
- std::vector<bool> b(maxVal-minVal+1,false);
- const int *ptBg(begin()),*endBg(end());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- for(const int *pt=ptBg;pt!=endBg;pt++)
- {
- if(!b[*pt-minVal])
- {
- ret->pushBackSilent(*pt);
- b[*pt-minVal]=true;
- }
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt which contains size of every of groups described by \a this
- * "index" array. Such "index" array is returned for example by
- * \ref MEDCoupling::MEDCouplingUMesh::buildDescendingConnectivity
- * "MEDCouplingUMesh::buildDescendingConnectivity" and
- * \ref MEDCoupling::MEDCouplingUMesh::getNodalConnectivityIndex
- * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
- * This method preforms the reverse operation of DataArrayInt::computeOffsetsFull.
- * \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
- * equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
- * The caller is to delete this array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() < 2.
- *
- * \b Example: <br>
- * - this contains [1,3,6,7,7,9,15]
- * - result array contains [2,3,1,0,2,6],
- * where 2 = 3 - 1, 3 = 6 - 3, 1 = 7 - 6 etc.
- *
- * \sa DataArrayInt::computeOffsetsFull
- */
-DataArrayInt *DataArrayInt::deltaShiftIndex() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<2)
- throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
- const int *ptr=getConstPointer();
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(nbOfTuples-1,1);
- int *out=ret->getPointer();
- std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
- return ret;
-}
-
-/*!
- * Modifies \a this one-dimensional array so that value of each element \a x
- * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
- * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number of tuples
- * and components remains the same.<br>
- * This method is useful for allToAllV in MPI with contiguous policy. This method
- * differs from computeOffsetsFull() in that the number of tuples is \b not changed by
- * this one.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- *
- * \b Example: <br>
- * - Before \a this contains [3,5,1,2,0,8]
- * - After \a this contains [0,3,8,9,11,11]<br>
- * Note that the last element 19 = 11 + 8 is missing because size of \a this
- * array is retained and thus there is no space to store the last element.
- */
-void DataArrayInt::computeOffsets()
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples==0)
- return ;
- int *work=getPointer();
- int tmp=work[0];
- work[0]=0;
- for(int i=1;i<nbOfTuples;i++)
- {
- int tmp2=work[i];
- work[i]=work[i-1]+tmp;
- tmp=tmp2;
- }
- declareAsNew();
-}
-
-
-/*!
- * Modifies \a this one-dimensional array so that value of each element \a x
- * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
- * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number
- * components remains the same and number of tuples is inceamented by one.<br>
- * This method is useful for allToAllV in MPI with contiguous policy. This method
- * differs from computeOffsets() in that the number of tuples is changed by this one.
- * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
+}
+
+/*!
+ * Returns a new DataArrayInt containing elements of \a this one-dimensional missing
+ * from an \a other one-dimensional array.
+ * \param [in] other - a DataArrayInt containing elements not to include in the result array.
+ * \return DataArrayInt * - a new instance of DataArrayInt with one component. The
+ * caller is to delete this array using decrRef() as it is no more needed.
+ * \throw If \a other is NULL.
+ * \throw If \a other is not allocated.
+ * \throw If \a other->getNumberOfComponents() != 1.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
- *
- * \b Example: <br>
- * - Before \a this contains [3,5,1,2,0,8]
- * - After \a this contains [0,3,8,9,11,11,19]<br>
- * \sa DataArrayInt::deltaShiftIndex
+ * \sa DataArrayInt::buildSubstractionOptimized()
*/
-void DataArrayInt::computeOffsetsFull()
+DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const
{
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
checkAllocated();
+ other->checkAllocated();
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsetsFull : only single component allowed !");
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
+ if(other->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
+ const int *pt=getConstPointer();
int nbOfTuples=getNumberOfTuples();
- int *ret=(int *)malloc((nbOfTuples+1)*sizeof(int));
- const int *work=getConstPointer();
- ret[0]=0;
- for(int i=0;i<nbOfTuples;i++)
- ret[i+1]=work[i]+ret[i];
- useArray(ret,true,C_DEALLOC,nbOfTuples+1,1);
- declareAsNew();
+ std::set<int> s1(pt,pt+nbOfTuples);
+ pt=other->getConstPointer();
+ nbOfTuples=other->getNumberOfTuples();
+ std::set<int> s2(pt,pt+nbOfTuples);
+ std::vector<int> r;
+ std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc((int)r.size(),1);
+ std::copy(r.begin(),r.end(),ret->getPointer());
+ return ret;
}
/*!
- * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows.
- * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsetsFull ) that is to say with one component
- * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds).
- * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds
- * filling completely one of the ranges in \a this.
- *
- * \param [in] listOfIds a list of ids that has to be sorted ascendingly.
- * \param [out] rangeIdsFetched the range ids fetched
- * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So
- * \a idsInInputListThatFetch is a part of input \a listOfIds.
- *
- * \sa DataArrayInt::computeOffsetsFull
- *
- * \b Example: <br>
- * - \a this : [0,3,7,9,15,18]
- * - \a listOfIds contains [0,1,2,3,7,8,15,16,17]
- * - \a rangeIdsFetched result array: [0,2,4]
- * - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17]
- * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch.
- * <br>
+ * \a this is expected to have one component and to be sorted ascendingly (as for \a other).
+ * \a other is expected to be a part of \a this. If not DataArrayInt::buildSubstraction should be called instead.
+ *
+ * \param [in] other an array with one component and expected to be sorted ascendingly.
+ * \ret list of ids in \a this but not in \a other.
+ * \sa DataArrayInt::buildSubstraction
*/
-void DataArrayInt::findIdsRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const
+DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const
{
- if(!listOfIds)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : input list of ids is null !");
- listOfIds->checkAllocated(); checkAllocated();
- if(listOfIds->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : input list of ids must have exactly one component !");
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : this must have exactly one component !");
- MCAuto<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
- MCAuto<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
- const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1);
- const int *tupPtr(listOfIds->begin()),*offPtr(offBg);
- while(tupPtr!=tupEnd && offPtr!=offEnd)
+ static const char *MSG="DataArrayInt::buildSubstractionOptimized : only single component allowed !";
+ if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstractionOptimized : NULL input array !");
+ checkAllocated(); other->checkAllocated();
+ if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
+ if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
+ const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end());
+ const int *work1(pt1Bg),*work2(pt2Bg);
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
+ for(;work1!=pt1End;work1++)
{
- if(*tupPtr==*offPtr)
- {
- int i=offPtr[0];
- while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
- if(i==offPtr[1])
- {
- ret0->pushBackSilent((int)std::distance(offBg,offPtr));
- ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
- offPtr++;
- }
- }
+ if(work2!=pt2End && *work1==*work2)
+ work2++;
else
- { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
+ ret->pushBackSilent(*work1);
}
- rangeIdsFetched=ret0.retn();
- idsInInputListThatFetch=ret1.retn();
+ return ret.retn();
}
+
/*!
- * Returns a new DataArrayInt whose contents is computed from that of \a this and \a
- * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
- * "index" array of a "iota" array, thus, whose each element gives an index of a group
- * beginning within the "iota" array. And \a this is a one-dimensional array
- * considered as a selector of groups described by \a offsets to include into the result array.
- * \throw If \a offsets is NULL.
- * \throw If \a offsets is not allocated.
- * \throw If \a offsets->getNumberOfComponents() != 1.
- * \throw If \a offsets is not monotonically increasing.
- * \throw If \a this is not allocated.
+ * Returns a new DataArrayInt which contains all elements of \a this and a given
+ * one-dimensional arrays. The result array does not contain any duplicates
+ * and its values are sorted in ascending order.
+ * \param [in] other - an array to unite with \a this one.
+ * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
+ * array using decrRef() as it is no more needed.
+ * \throw If \a this or \a other is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
- * \throw If any element of \a this is not a valid index for \a offsets array.
- *
- * \b Example: <br>
- * - \a this: [0,2,3]
- * - \a offsets: [0,3,6,10,14,20]
- * - result array: [0,1,2,6,7,8,9,10,11,12,13] == <br>
- * \c range(0,3) + \c range(6,10) + \c range(10,14) ==<br>
- * \c range( \a offsets[ \a this[0] ], offsets[ \a this[0]+1 ]) +
- * \c range( \a offsets[ \a this[1] ], offsets[ \a this[1]+1 ]) +
- * \c range( \a offsets[ \a this[2] ], offsets[ \a this[2]+1 ])
+ * \throw If \a other->getNumberOfComponents() != 1.
*/
-DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const
+DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const
{
- if(!offsets)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
- offsets->checkAllocated();
- if(offsets->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
- int othNbTuples=offsets->getNumberOfTuples()-1;
- int nbOfTuples=getNumberOfTuples();
- int retNbOftuples=0;
- const int *work=getConstPointer();
- const int *offPtr=offsets->getConstPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- int val=work[i];
- if(val>=0 && val<othNbTuples)
- {
- int delta=offPtr[val+1]-offPtr[val];
- if(delta>=0)
- retNbOftuples+=delta;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
- oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(retNbOftuples,1);
- int *retPtr=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- int val=work[i];
- int start=offPtr[val];
- int off=offPtr[val+1]-start;
- for(int j=0;j<off;j++,retPtr++)
- *retPtr=start+j;
- }
- return ret.retn();
+ std::vector<const DataArrayInt *>arrs(2);
+ arrs[0]=this; arrs[1]=other;
+ return BuildUnion(arrs);
}
+
/*!
- * Returns a new DataArrayInt whose contents is computed using \a this that must be a
- * scaled array (monotonically increasing).
-from that of \a this and \a
- * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
- * "index" array of a "iota" array, thus, whose each element gives an index of a group
- * beginning within the "iota" array. And \a this is a one-dimensional array
- * considered as a selector of groups described by \a offsets to include into the result array.
- * \throw If \a is NULL.
- * \throw If \a this is not allocated.
+ * Returns a new DataArrayInt which contains elements present in both \a this and a given
+ * one-dimensional arrays. The result array does not contain any duplicates
+ * and its values are sorted in ascending order.
+ * \param [in] other - an array to intersect with \a this one.
+ * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
+ * array using decrRef() as it is no more needed.
+ * \throw If \a this or \a other is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() == 0.
- * \throw If \a this is not monotonically increasing.
- * \throw If any element of ids in ( \a bg \a stop \a step ) points outside the scale in \a this.
- *
- * \b Example: <br>
- * - \a bg , \a stop and \a step : (0,5,2)
- * - \a this: [0,3,6,10,14,20]
- * - result array: [0,0,0, 2,2,2,2, 4,4,4,4,4,4] == <br>
- */
-DataArrayInt *DataArrayInt::buildExplicitArrOfSliceOnScaledArr(int bg, int stop, int step) const
-{
- if(!isAllocated())
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : not allocated array !");
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : number of components is expected to be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples==0)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : number of tuples must be != 0 !");
- const int *ids(begin());
- int nbOfEltsInSlc(GetNumberOfItemGivenBESRelative(bg,stop,step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr")),sz(0),pos(bg);
- for(int i=0;i<nbOfEltsInSlc;i++,pos+=step)
- {
- if(pos>=0 && pos<nbOfTuples-1)
- {
- int delta(ids[pos+1]-ids[pos]);
- sz+=delta;
- if(delta<0)
- {
- std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrOfSliceOnScaledArr : At pos #" << i << " of input slice, value is " << pos << " and at this pos this is not monotonically increasing !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrOfSliceOnScaledArr : At pos #" << i << " of input slice, value is " << pos << " should be in [0," << nbOfTuples-1 << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(sz,1);
- int *retPtr(ret->getPointer());
- pos=bg;
- for(int i=0;i<nbOfEltsInSlc;i++,pos+=step)
- {
- int delta(ids[pos+1]-ids[pos]);
- for(int j=0;j<delta;j++,retPtr++)
- *retPtr=pos;
- }
- return ret.retn();
+ * \throw If \a other->getNumberOfComponents() != 1.
+ */
+DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const
+{
+ std::vector<const DataArrayInt *>arrs(2);
+ arrs[0]=this; arrs[1]=other;
+ return BuildIntersection(arrs);
}
/*!
- * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
- * For each tuple at place **i** in \a this it tells which is the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
- * in tuple **i** of returned DataArrayInt.
- * If ranges overlapped (in theory it should not) this method do not detect it and always returns the first range.
- *
- * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
- * The return DataArrayInt will contain : **[0,4,1,2,2,3]**
- *
- * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
- * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
- * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
- * is thrown if no ranges in \a ranges contains value in \a this.
+ * This method can be applied on allocated with one component DataArrayInt instance.
+ * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance.
+ * Example : if \a this contains [1,2,2,3,3,3,3,4,5,5,7,7,7,19] the returned array will contain [1,2,3,4,5,7,19]
*
- * \sa DataArrayInt::findIdInRangeForEachTuple
+ * \return a newly allocated array that contain the result of the unique operation applied on \a this.
+ * \throw if \a this is not allocated or if \a this has not exactly one component.
+ * \sa DataArrayInt::buildUniqueNotSorted
*/
-DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const
+DataArrayInt *DataArrayInt::buildUnique() const
{
- if(!ranges)
- throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : null input pointer !");
- if(ranges->getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : input DataArrayInt instance should have 2 components !");
checkAllocated();
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : this should have only one component !");
- int nbTuples=getNumberOfTuples();
- MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
- int nbOfRanges=ranges->getNumberOfTuples();
- const int *rangesPtr=ranges->getConstPointer();
- int *retPtr=ret->getPointer();
- const int *inPtr=getConstPointer();
- for(int i=0;i<nbTuples;i++,retPtr++)
- {
- int val=inPtr[i];
- bool found=false;
- for(int j=0;j<nbOfRanges && !found;j++)
- if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
- { *retPtr=j; found=true; }
- if(found)
- continue;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ MCAuto<DataArrayInt> tmp=deepCopy();
+ int *data=tmp->getPointer();
+ int *last=std::unique(data,data+nbOfTuples);
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(std::distance(data,last),1);
+ std::copy(data,last,ret->getPointer());
return ret.retn();
}
/*!
- * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
- * For each tuple at place **i** in \a this it tells which is the sub position of the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
- * in tuple **i** of returned DataArrayInt.
- * If ranges overlapped (in theory it should not) this method do not detect it and always returns the sub position of the first range.
+ * This method can be applied on allocated with one component DataArrayInt instance.
+ * This method keep elements only once by keeping the same order in \a this that is not expected to be sorted.
*
- * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
- * The return DataArrayInt will contain : **[1,2,4,0,2,2]**
- * This method is often called in pair with DataArrayInt::findRangeIdForEachTuple method.
- *
- * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
- * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
- * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
- * is thrown if no ranges in \a ranges contains value in \a this.
- * \sa DataArrayInt::findRangeIdForEachTuple
+ * \return a newly allocated array that contain the result of the unique operation applied on \a this.
+ *
+ * \throw if \a this is not allocated or if \a this has not exactly one component.
+ *
+ * \sa DataArrayInt::buildUnique
*/
-DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const
+DataArrayInt *DataArrayInt::buildUniqueNotSorted() const
{
- if(!ranges)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : null input pointer !");
- if(ranges->getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : input DataArrayInt instance should have 2 components !");
checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : this should have only one component !");
- int nbTuples=getNumberOfTuples();
- MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
- int nbOfRanges=ranges->getNumberOfTuples();
- const int *rangesPtr=ranges->getConstPointer();
- int *retPtr=ret->getPointer();
- const int *inPtr=getConstPointer();
- for(int i=0;i<nbTuples;i++,retPtr++)
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildUniqueNotSorted : only single component allowed !");
+ int minVal,maxVal;
+ getMinMaxValues(minVal,maxVal);
+ std::vector<bool> b(maxVal-minVal+1,false);
+ const int *ptBg(begin()),*endBg(end());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
+ for(const int *pt=ptBg;pt!=endBg;pt++)
{
- int val=inPtr[i];
- bool found=false;
- for(int j=0;j<nbOfRanges && !found;j++)
- if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
- { *retPtr=val-rangesPtr[2*j]; found=true; }
- if(found)
- continue;
- else
+ if(!b[*pt-minVal])
{
- std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
+ ret->pushBackSilent(*pt);
+ b[*pt-minVal]=true;
}
}
+ ret->copyStringInfoFrom(*this);
return ret.retn();
}
/*!
- * \b WARNING this method is a \b non \a const \b method. This method works tuple by tuple. Each tuple is expected to be pairs (number of components must be equal to 2).
- * This method rearrange each pair in \a this so that, tuple with id \b tid will be after the call \c this->getIJ(tid,0)==this->getIJ(tid-1,1) and \c this->getIJ(tid,1)==this->getIJ(tid+1,0).
- * If it is impossible to reach such condition an exception will be thrown ! \b WARNING In case of throw \a this can be partially modified !
- * If this method has correctly worked, \a this will be able to be considered as a linked list.
- * This method does nothing if number of tuples is lower of equal to 1.
+ * Returns a new DataArrayInt which contains size of every of groups described by \a this
+ * "index" array. Such "index" array is returned for example by
+ * \ref MEDCoupling::MEDCouplingUMesh::buildDescendingConnectivity
+ * "MEDCouplingUMesh::buildDescendingConnectivity" and
+ * \ref MEDCoupling::MEDCouplingUMesh::getNodalConnectivityIndex
+ * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
+ * This method preforms the reverse operation of DataArrayInt::computeOffsetsFull.
+ * \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
+ * equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
+ * The caller is to delete this array using decrRef() as it is no more needed.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ * \throw If \a this->getNumberOfTuples() < 2.
*
- * This method is useful for users having an unstructured mesh having only SEG2 to rearrange internaly the connectibity without any coordinates consideration.
+ * \b Example: <br>
+ * - this contains [1,3,6,7,7,9,15]
+ * - result array contains [2,3,1,0,2,6],
+ * where 2 = 3 - 1, 3 = 6 - 3, 1 = 7 - 6 etc.
*
- * \sa MEDCouplingUMesh::orderConsecutiveCells1D
+ * \sa DataArrayInt::computeOffsetsFull
*/
-void DataArrayInt::sortEachPairToMakeALinkedList()
+DataArrayInt *DataArrayInt::deltaShiftIndex() const
{
checkAllocated();
- if(getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : Only works on DataArrayInt instance with nb of components equal to 2 !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples<=1)
- return ;
- int *conn(getPointer());
- for(int i=1;i<nbOfTuples;i++,conn+=2)
- {
- if(i>1)
- {
- if(conn[2]==conn[3])
- {
- std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " presence of a pair filled with same ids !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(conn[2]!=conn[1] && conn[3]==conn[1] && conn[2]!=conn[0])
- std::swap(conn[2],conn[3]);
- //not(conn[2]==conn[1] && conn[3]!=conn[1] && conn[3]!=conn[0])
- if(conn[2]!=conn[1] || conn[3]==conn[1] || conn[3]==conn[0])
- {
- std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " something is invalid !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- if(conn[0]==conn[1] || conn[2]==conn[3])
- throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : In the 2 first tuples presence of a pair filled with same ids !");
- int tmp[4];
- std::set<int> s;
- s.insert(conn,conn+4);
- if(s.size()!=3)
- throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : This can't be considered as a linked list regarding 2 first tuples !");
- if(std::count(conn,conn+4,conn[0])==2)
- {
- tmp[0]=conn[1];
- tmp[1]=conn[0];
- tmp[2]=conn[0];
- if(conn[2]==conn[0])
- { tmp[3]=conn[3]; }
- else
- { tmp[3]=conn[2];}
- std::copy(tmp,tmp+4,conn);
- }
- else
- {//here we are sure to have (std::count(conn,conn+4,conn[1])==2)
- if(conn[1]==conn[3])
- std::swap(conn[2],conn[3]);
- }
- }
- }
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ if(nbOfTuples<2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
+ const int *ptr=getConstPointer();
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(nbOfTuples-1,1);
+ int *out=ret->getPointer();
+ std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
+ return ret;
}
/*!
- *
- * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
- * \a nbTimes should be at least equal to 1.
- * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
- * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1.
+ * Modifies \a this one-dimensional array so that value of each element \a x
+ * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
+ * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number of tuples
+ * and components remains the same.<br>
+ * This method is useful for allToAllV in MPI with contiguous policy. This method
+ * differs from computeOffsetsFull() in that the number of tuples is \b not changed by
+ * this one.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ *
+ * \b Example: <br>
+ * - Before \a this contains [3,5,1,2,0,8]
+ * - After \a this contains [0,3,8,9,11,11]<br>
+ * Note that the last element 19 = 11 + 8 is missing because size of \a this
+ * array is retained and thus there is no space to store the last element.
*/
-DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const
+void DataArrayInt::computeOffsets()
{
checkAllocated();
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
- if(nbTimes<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !");
- int nbTuples=getNumberOfTuples();
- const int *inPtr=getConstPointer();
- MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1);
- int *retPtr=ret->getPointer();
- for(int i=0;i<nbTuples;i++,inPtr++)
+ throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ if(nbOfTuples==0)
+ return ;
+ int *work=getPointer();
+ int tmp=work[0];
+ work[0]=0;
+ for(int i=1;i<nbOfTuples;i++)
{
- int val=*inPtr;
- for(int j=0;j<nbTimes;j++,retPtr++)
- *retPtr=val;
+ int tmp2=work[i];
+ work[i]=work[i-1]+tmp;
+ tmp=tmp2;
}
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * This method returns all different values found in \a this. This method throws if \a this has not been allocated.
- * But the number of components can be different from one.
- * \return a newly allocated array (that should be dealt by the caller) containing different values in \a this.
- */
-DataArrayInt *DataArrayInt::getDifferentValues() const
-{
- checkAllocated();
- std::set<int> ret;
- ret.insert(begin(),end());
- MCAuto<DataArrayInt> ret2=DataArrayInt::New(); ret2->alloc((int)ret.size(),1);
- std::copy(ret.begin(),ret.end(),ret2->getPointer());
- return ret2.retn();
+ declareAsNew();
}
+
/*!
- * This method is a refinement of DataArrayInt::getDifferentValues because it returns not only different values in \a this but also, for each of
- * them it tells which tuple id have this id.
- * This method works only on arrays with one component (if it is not the case call DataArrayInt::rearrange(1) ).
- * This method returns two arrays having same size.
- * The instances of DataArrayInt in the returned vector have be specially allocated and computed by this method. Each of them should be dealt by the caller of this method.
- * Example : if this is equal to [1,0,1,2,0,2,2,-3,2] -> differentIds=[-3,0,1,2] and returned array will be equal to [[7],[1,4],[0,2],[3,5,6,8]]
+ * Modifies \a this one-dimensional array so that value of each element \a x
+ * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
+ * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number
+ * components remains the same and number of tuples is inceamented by one.<br>
+ * This method is useful for allToAllV in MPI with contiguous policy. This method
+ * differs from computeOffsets() in that the number of tuples is changed by this one.
+ * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ *
+ * \b Example: <br>
+ * - Before \a this contains [3,5,1,2,0,8]
+ * - After \a this contains [0,3,8,9,11,11,19]<br>
+ * \sa DataArrayInt::deltaShiftIndex
*/
-std::vector<DataArrayInt *> DataArrayInt::partitionByDifferentValues(std::vector<int>& differentIds) const
+void DataArrayInt::computeOffsetsFull()
{
checkAllocated();
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !");
- int id=0;
- std::map<int,int> m,m2,m3;
- for(const int *w=begin();w!=end();w++)
- m[*w]++;
- differentIds.resize(m.size());
- std::vector<DataArrayInt *> ret(m.size());
- std::vector<int *> retPtr(m.size());
- for(std::map<int,int>::const_iterator it=m.begin();it!=m.end();it++,id++)
- {
- m2[(*it).first]=id;
- ret[id]=DataArrayInt::New();
- ret[id]->alloc((*it).second,1);
- retPtr[id]=ret[id]->getPointer();
- differentIds[id]=(*it).first;
- }
- id=0;
- for(const int *w=begin();w!=end();w++,id++)
- {
- retPtr[m2[*w]][m3[*w]++]=id;
- }
- return ret;
+ throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsetsFull : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ int *ret=(int *)malloc((nbOfTuples+1)*sizeof(int));
+ const int *work=getConstPointer();
+ ret[0]=0;
+ for(int i=0;i<nbOfTuples;i++)
+ ret[i+1]=work[i]+ret[i];
+ useArray(ret,true,C_DEALLOC,nbOfTuples+1,1);
+ declareAsNew();
}
/*!
- * This method split ids in [0, \c this->getNumberOfTuples() ) using \a this array as a field of weight (>=0 each).
- * The aim of this method is to return a set of \a nbOfSlices chunk of contiguous ids as balanced as possible.
+ * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows.
+ * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsetsFull ) that is to say with one component
+ * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds).
+ * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds
+ * filling completely one of the ranges in \a this.
*
- * \param [in] nbOfSlices - number of slices expected.
- * \return - a vector having a size equal to \a nbOfSlices giving the start (included) and the stop (excluded) of each chunks.
- *
- * \sa DataArray::GetSlice
- * \throw If \a this is not allocated or not with exactly one component.
- * \throw If an element in \a this if < 0.
+ * \param [in] listOfIds a list of ids that has to be sorted ascendingly.
+ * \param [out] rangeIdsFetched the range ids fetched
+ * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So
+ * \a idsInInputListThatFetch is a part of input \a listOfIds.
+ *
+ * \sa DataArrayInt::computeOffsetsFull
+ *
+ * \b Example: <br>
+ * - \a this : [0,3,7,9,15,18]
+ * - \a listOfIds contains [0,1,2,3,7,8,15,16,17]
+ * - \a rangeIdsFetched result array: [0,2,4]
+ * - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17]
+ * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch.
+ * <br>
*/
-std::vector< std::pair<int,int> > DataArrayInt::splitInBalancedSlices(int nbOfSlices) const
+void DataArrayInt::findIdsRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const
{
- if(!isAllocated() || getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::splitInBalancedSlices : this array should have number of components equal to one and must be allocated !");
- if(nbOfSlices<=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::splitInBalancedSlices : number of slices must be >= 1 !");
- int sum(accumulate(0)),nbOfTuples(getNumberOfTuples());
- int sumPerSlc(sum/nbOfSlices),pos(0);
- const int *w(begin());
- std::vector< std::pair<int,int> > ret(nbOfSlices);
- for(int i=0;i<nbOfSlices;i++)
+ if(!listOfIds)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : input list of ids is null !");
+ listOfIds->checkAllocated(); checkAllocated();
+ if(listOfIds->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : input list of ids must have exactly one component !");
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdsRangesInListOfIds : this must have exactly one component !");
+ MCAuto<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
+ MCAuto<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
+ const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1);
+ const int *tupPtr(listOfIds->begin()),*offPtr(offBg);
+ while(tupPtr!=tupEnd && offPtr!=offEnd)
{
- std::pair<int,int> p(pos,-1);
- int locSum(0);
- while(locSum<sumPerSlc && pos<nbOfTuples) { pos++; locSum+=*w++; }
- if(i!=nbOfSlices-1)
- p.second=pos;
+ if(*tupPtr==*offPtr)
+ {
+ int i=offPtr[0];
+ while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
+ if(i==offPtr[1])
+ {
+ ret0->pushBackSilent((int)std::distance(offBg,offPtr));
+ ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
+ offPtr++;
+ }
+ }
else
- p.second=nbOfTuples;
- ret[i]=p;
+ { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
}
- return ret;
+ rangeIdsFetched=ret0.retn();
+ idsInInputListThatFetch=ret1.retn();
}
/*!
- * Returns a new DataArrayInt that is a sum of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
- * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
+ * Returns a new DataArrayInt whose contents is computed from that of \a this and \a
+ * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
+ * "index" array of a "iota" array, thus, whose each element gives an index of a group
+ * beginning within the "iota" array. And \a this is a one-dimensional array
+ * considered as a selector of groups described by \a offsets to include into the result array.
+ * \throw If \a offsets is NULL.
+ * \throw If \a offsets is not allocated.
+ * \throw If \a offsets->getNumberOfComponents() != 1.
+ * \throw If \a offsets is not monotonically increasing.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ * \throw If any element of \a this is not a valid index for \a offsets array.
*
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to sum up.
- * \param [in] a2 - another array to sum up.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * \b Example: <br>
+ * - \a this: [0,2,3]
+ * - \a offsets: [0,3,6,10,14,20]
+ * - result array: [0,1,2,6,7,8,9,10,11,12,13] == <br>
+ * \c range(0,3) + \c range(6,10) + \c range(10,14) ==<br>
+ * \c range( \a offsets[ \a this[0] ], offsets[ \a this[0]+1 ]) +
+ * \c range( \a offsets[ \a this[1] ], offsets[ \a this[1]+1 ]) +
+ * \c range( \a offsets[ \a this[2] ], offsets[ \a this[2]+1 ])
*/
-DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2)
+DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Add : input DataArrayInt instance is NULL !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- MCAuto<DataArrayInt> ret=0;
- if(nbOfTuple==nbOfTuple2)
+ if(!offsets)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
+ offsets->checkAllocated();
+ if(offsets->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
+ int othNbTuples=offsets->getNumberOfTuples()-1;
+ int nbOfTuples=getNumberOfTuples();
+ int retNbOftuples=0;
+ const int *work=getConstPointer();
+ const int *offPtr=offsets->getConstPointer();
+ for(int i=0;i<nbOfTuples;i++)
{
- if(nbOfComp==nbOfComp2)
- {
- ret=DataArrayInt::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<int>());
- ret->copyStringInfoFrom(*a1);
- }
- else
+ int val=work[i];
+ if(val>=0 && val<othNbTuples)
{
- int nbOfCompMin,nbOfCompMax;
- const DataArrayInt *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
+ int delta=offPtr[val+1]-offPtr[val];
+ if(delta>=0)
+ retNbOftuples+=delta;
else
{
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayInt::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const int *aMinPtr=aMin->getConstPointer();
- const int *aMaxPtr=aMax->getConstPointer();
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
}
- }
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
+ else
{
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayInt::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<int>());
- ret->copyStringInfoFrom(*aMax);
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
+ oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
}
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(retNbOftuples,1);
+ int *retPtr=ret->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ int val=work[i];
+ int start=offPtr[val];
+ int off=offPtr[val+1]-start;
+ for(int j=0;j<off;j++,retPtr++)
+ *retPtr=start+j;
+ }
return ret.retn();
}
/*!
- * Adds values of another DataArrayInt to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is added to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] += _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] += _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] += _a2_ [ 0, j ].
+ * Returns a new DataArrayInt whose contents is computed using \a this that must be a
+ * scaled array (monotonically increasing).
+from that of \a this and \a
+ * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
+ * "index" array of a "iota" array, thus, whose each element gives an index of a group
+ * beginning within the "iota" array. And \a this is a one-dimensional array
+ * considered as a selector of groups described by \a offsets to include into the result array.
+ * \throw If \a is NULL.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ * \throw If \a this->getNumberOfTuples() == 0.
+ * \throw If \a this is not monotonically increasing.
+ * \throw If any element of ids in ( \a bg \a stop \a step ) points outside the scale in \a this.
*
- * \param [in] other - an array to add to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * \b Example: <br>
+ * - \a bg , \a stop and \a step : (0,5,2)
+ * - \a this: [0,3,6,10,14,20]
+ * - result array: [0,0,0, 2,2,2,2, 4,4,4,4,4,4] == <br>
*/
-void DataArrayInt::addEqual(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual !";
- checkAllocated(); other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
+DataArrayInt *DataArrayInt::buildExplicitArrOfSliceOnScaledArr(int bg, int stop, int step) const
+{
+ if(!isAllocated())
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : not allocated array !");
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : number of components is expected to be equal to one !");
+ int nbOfTuples(getNumberOfTuples());
+ if(nbOfTuples==0)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : number of tuples must be != 0 !");
+ const int *ids(begin());
+ int nbOfEltsInSlc(GetNumberOfItemGivenBESRelative(bg,stop,step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr")),sz(0),pos(bg);
+ for(int i=0;i<nbOfEltsInSlc;i++,pos+=step)
{
- if(nbOfComp==nbOfComp2)
+ if(pos>=0 && pos<nbOfTuples-1)
{
- std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
+ int delta(ids[pos+1]-ids[pos]);
+ sz+=delta;
+ if(delta<0)
+ {
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrOfSliceOnScaledArr : At pos #" << i << " of input slice, value is " << pos << " and at this pos this is not monotonically increasing !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
- else if(nbOfComp2==1)
+ else
{
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*ptrc++));
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrOfSliceOnScaledArr : At pos #" << i << " of input slice, value is " << pos << " should be in [0," << nbOfTuples-1 << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception(msg);
}
- else if(nbOfTuple2==1)
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(sz,1);
+ int *retPtr(ret->getPointer());
+ pos=bg;
+ for(int i=0;i<nbOfEltsInSlc;i++,pos+=step)
{
- if(nbOfComp2==nbOfComp)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ int delta(ids[pos+1]-ids[pos]);
+ for(int j=0;j<delta;j++,retPtr++)
+ *retPtr=pos;
}
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
+ return ret.retn();
}
/*!
- * Returns a new DataArrayInt that is a subtraction of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
+ * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
+ * For each tuple at place **i** in \a this it tells which is the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
+ * in tuple **i** of returned DataArrayInt.
+ * If ranges overlapped (in theory it should not) this method do not detect it and always returns the first range.
*
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to subtract from.
- * \param [in] a2 - an array to subtract.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
+ * The return DataArrayInt will contain : **[0,4,1,2,2,3]**
+ *
+ * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
+ * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
+ * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
+ * is thrown if no ranges in \a ranges contains value in \a this.
+ *
+ * \sa DataArrayInt::findIdInRangeForEachTuple
*/
-DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2)
+DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Substract : input DataArrayInt instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
+ if(!ranges)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : null input pointer !");
+ if(ranges->getNumberOfComponents()!=2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : input DataArrayInt instance should have 2 components !");
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : this should have only one component !");
+ int nbTuples=getNumberOfTuples();
+ MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
+ int nbOfRanges=ranges->getNumberOfTuples();
+ const int *rangesPtr=ranges->getConstPointer();
+ int *retPtr=ret->getPointer();
+ const int *inPtr=getConstPointer();
+ for(int i=0;i<nbTuples;i++,retPtr++)
{
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a2Ptr=a2->getConstPointer();
- const int *a1Ptr=a1->getConstPointer();
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<int>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
+ int val=inPtr[i];
+ bool found=false;
+ for(int j=0;j<nbOfRanges && !found;j++)
+ if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
+ { *retPtr=j; found=true; }
+ if(found)
+ continue;
else
{
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- return 0;
+ std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- int *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
- return 0;
- }
+ return ret.retn();
}
/*!
- * Subtract values of another DataArrayInt from values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is subtracted from the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] -= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] -= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] -= _a2_ [ 0, j ].
+ * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
+ * For each tuple at place **i** in \a this it tells which is the sub position of the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
+ * in tuple **i** of returned DataArrayInt.
+ * If ranges overlapped (in theory it should not) this method do not detect it and always returns the sub position of the first range.
*
- * \param [in] other - an array to subtract from \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
+ * The return DataArrayInt will contain : **[1,2,4,0,2,2]**
+ * This method is often called in pair with DataArrayInt::findRangeIdForEachTuple method.
+ *
+ * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
+ * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
+ * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
+ * is thrown if no ranges in \a ranges contains value in \a this.
+ * \sa DataArrayInt::findRangeIdForEachTuple
*/
-void DataArrayInt::substractEqual(const DataArrayInt *other)
+DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const
{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual !";
- checkAllocated(); other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
+ if(!ranges)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : null input pointer !");
+ if(ranges->getNumberOfComponents()!=2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : input DataArrayInt instance should have 2 components !");
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : this should have only one component !");
+ int nbTuples=getNumberOfTuples();
+ MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
+ int nbOfRanges=ranges->getNumberOfTuples();
+ const int *rangesPtr=ranges->getConstPointer();
+ int *retPtr=ret->getPointer();
+ const int *inPtr=getConstPointer();
+ for(int i=0;i<nbTuples;i++,retPtr++)
{
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
- }
- else if(nbOfComp2==1)
+ int val=inPtr[i];
+ bool found=false;
+ for(int j=0;j<nbOfRanges && !found;j++)
+ if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
+ { *retPtr=val-rangesPtr[2*j]; found=true; }
+ if(found)
+ continue;
+ else
{
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
+ std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
}
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
+ return ret.retn();
}
/*!
- * Returns a new DataArrayInt that is a product of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a product of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
+ * \b WARNING this method is a \b non \a const \b method. This method works tuple by tuple. Each tuple is expected to be pairs (number of components must be equal to 2).
+ * This method rearrange each pair in \a this so that, tuple with id \b tid will be after the call \c this->getIJ(tid,0)==this->getIJ(tid-1,1) and \c this->getIJ(tid,1)==this->getIJ(tid+1,0).
+ * If it is impossible to reach such condition an exception will be thrown ! \b WARNING In case of throw \a this can be partially modified !
+ * If this method has correctly worked, \a this will be able to be considered as a linked list.
+ * This method does nothing if number of tuples is lower of equal to 1.
*
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - a factor array.
- * \param [in] a2 - another factor array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * This method is useful for users having an unstructured mesh having only SEG2 to rearrange internaly the connectibity without any coordinates consideration.
+ *
+ * \sa MEDCouplingUMesh::orderConsecutiveCells1D, DataArrayInt::fromLinkedListOfPairToList
*/
-DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2)
+void DataArrayInt::sortEachPairToMakeALinkedList()
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Multiply : input DataArrayInt instance is NULL !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- MCAuto<DataArrayInt> ret=0;
- if(nbOfTuple==nbOfTuple2)
+ checkAllocated();
+ if(getNumberOfComponents()!=2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : Only works on DataArrayInt instance with nb of components equal to 2 !");
+ int nbOfTuples(getNumberOfTuples());
+ if(nbOfTuples<=1)
+ return ;
+ int *conn(getPointer());
+ for(int i=1;i<nbOfTuples;i++,conn+=2)
{
- if(nbOfComp==nbOfComp2)
+ if(i>1)
{
- ret=DataArrayInt::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<int>());
- ret->copyStringInfoFrom(*a1);
+ if(conn[2]==conn[3])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " presence of a pair filled with same ids !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(conn[2]!=conn[1] && conn[3]==conn[1] && conn[2]!=conn[0])
+ std::swap(conn[2],conn[3]);
+ //not(conn[2]==conn[1] && conn[3]!=conn[1] && conn[3]!=conn[0])
+ if(conn[2]!=conn[1] || conn[3]==conn[1] || conn[3]==conn[0])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " something is invalid !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
else
{
- int nbOfCompMin,nbOfCompMax;
- const DataArrayInt *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
+ if(conn[0]==conn[1] || conn[2]==conn[3])
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : In the 2 first tuples presence of a pair filled with same ids !");
+ int tmp[4];
+ std::set<int> s;
+ s.insert(conn,conn+4);
+ if(s.size()!=3)
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : This can't be considered as a linked list regarding 2 first tuples !");
+ if(std::count(conn,conn+4,conn[0])==2)
{
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
+ tmp[0]=conn[1];
+ tmp[1]=conn[0];
+ tmp[2]=conn[0];
+ if(conn[2]==conn[0])
+ { tmp[3]=conn[3]; }
+ else
+ { tmp[3]=conn[2];}
+ std::copy(tmp,tmp+4,conn);
}
else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayInt::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const int *aMinPtr=aMin->getConstPointer();
- const int *aMaxPtr=aMax->getConstPointer();
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<int>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
+ {//here we are sure to have (std::count(conn,conn+4,conn[1])==2)
+ if(conn[1]==conn[3])
+ std::swap(conn[2],conn[3]);
}
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
}
}
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayInt::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<int>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
- return ret.retn();
}
-
/*!
- * Multiply values of another DataArrayInt to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is multiplied to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] *= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] *= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] *= _a2_ [ 0, j ].
- *
- * \param [in] other - an array to multiply to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * \a this is expected to be a correctly linked list of pairs.
+ *
+ * \sa DataArrayInt::sortEachPairToMakeALinkedList
*/
-void DataArrayInt::multiplyEqual(const DataArrayInt *other)
+MCAuto<DataArrayInt> DataArrayInt::fromLinkedListOfPairToList() const
{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
- checkAllocated(); other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
- }
- else if(nbOfComp2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<int>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
+ checkAllocated();
+ checkNbOfComps(2,"DataArrayInt::fromLinkedListOfPairToList : this is expected to have 2 components");
+ int nbTuples(getNumberOfTuples());
+ if(nbTuples<1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::fromLinkedListOfPairToList : no tuples in this ! Not a linked list !");
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbTuples+1,1);
+ const int *thisPtr(begin());
+ int *retPtr(ret->getPointer());
+ retPtr[0]=thisPtr[0];
+ for(int i=0;i<nbTuples;i++)
{
- if(nbOfComp2==nbOfComp)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<int>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ retPtr[i+1]=thisPtr[2*i+1];
+ if(i<nbTuples-1)
+ if(thisPtr[2*i+1]!=thisPtr[2*(i+1)+0])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::fromLinkedListOfPairToList : this is not a proper linked list of pair. The link is broken between tuple #" << i << " and tuple #" << i+1 << " ! Call sortEachPairToMakeALinkedList ?";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
}
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
+ return ret;
}
+/*!
+ * This method returns all different values found in \a this. This method throws if \a this has not been allocated.
+ * But the number of components can be different from one.
+ * \return a newly allocated array (that should be dealt by the caller) containing different values in \a this.
+ */
+DataArrayInt *DataArrayInt::getDifferentValues() const
+{
+ checkAllocated();
+ std::set<int> ret;
+ ret.insert(begin(),end());
+ MCAuto<DataArrayInt> ret2=DataArrayInt::New(); ret2->alloc((int)ret.size(),1);
+ std::copy(ret.begin(),ret.end(),ret2->getPointer());
+ return ret2.retn();
+}
/*!
- * Returns a new DataArrayInt that is a division of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a division of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \warning No check of division by zero is performed!
- * \param [in] a1 - a numerator array.
- * \param [in] a2 - a denominator array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
+ * This method is a refinement of DataArrayInt::getDifferentValues because it returns not only different values in \a this but also, for each of
+ * them it tells which tuple id have this id.
+ * This method works only on arrays with one component (if it is not the case call DataArrayInt::rearrange(1) ).
+ * This method returns two arrays having same size.
+ * The instances of DataArrayInt in the returned vector have be specially allocated and computed by this method. Each of them should be dealt by the caller of this method.
+ * Example : if this is equal to [1,0,1,2,0,2,2,-3,2] -> differentIds=[-3,0,1,2] and returned array will be equal to [[7],[1,4],[0,2],[3,5,6,8]]
*/
-DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2)
+std::vector<DataArrayInt *> DataArrayInt::partitionByDifferentValues(std::vector<int>& differentIds) const
{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Divide : input DataArrayInt instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a2Ptr=a2->getConstPointer();
- const int *a1Ptr=a1->getConstPointer();
- int *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<int>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !");
+ int id=0;
+ std::map<int,int> m,m2,m3;
+ for(const int *w=begin();w!=end();w++)
+ m[*w]++;
+ differentIds.resize(m.size());
+ std::vector<DataArrayInt *> ret(m.size());
+ std::vector<int *> retPtr(m.size());
+ for(std::map<int,int>::const_iterator it=m.begin();it!=m.end();it++,id++)
{
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- int *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
+ m2[(*it).first]=id;
+ ret[id]=DataArrayInt::New();
+ ret[id]->alloc((*it).second,1);
+ retPtr[id]=ret[id]->getPointer();
+ differentIds[id]=(*it).first;
}
- else
+ id=0;
+ for(const int *w=begin();w!=end();w++,id++)
{
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
- return 0;
+ retPtr[m2[*w]][m3[*w]++]=id;
}
+ return ret;
}
/*!
- * Divide values of \a this array by values of another DataArrayInt. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a this array is divided by the corresponding value of \a other one, i.e.:
- * _a_ [ i, j ] /= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] /= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] /= _a2_ [ 0, j ].
+ * This method split ids in [0, \c this->getNumberOfTuples() ) using \a this array as a field of weight (>=0 each).
+ * The aim of this method is to return a set of \a nbOfSlices chunk of contiguous ids as balanced as possible.
*
- * \warning No check of division by zero is performed!
- * \param [in] other - an array to divide \a this one by.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
+ * \param [in] nbOfSlices - number of slices expected.
+ * \return - a vector having a size equal to \a nbOfSlices giving the start (included) and the stop (excluded) of each chunks.
+ *
+ * \sa DataArray::GetSlice
+ * \throw If \a this is not allocated or not with exactly one component.
+ * \throw If an element in \a this if < 0.
*/
-void DataArrayInt::divideEqual(const DataArrayInt *other)
+std::vector< std::pair<int,int> > DataArrayInt::splitInBalancedSlices(int nbOfSlices) const
{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !";
- checkAllocated(); other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
- }
- else if(nbOfComp2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
+ if(!isAllocated() || getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::splitInBalancedSlices : this array should have number of components equal to one and must be allocated !");
+ if(nbOfSlices<=0)
+ throw INTERP_KERNEL::Exception("DataArrayInt::splitInBalancedSlices : number of slices must be >= 1 !");
+ int sum(accumulate(0)),nbOfTuples(getNumberOfTuples());
+ int sumPerSlc(sum/nbOfSlices),pos(0);
+ const int *w(begin());
+ std::vector< std::pair<int,int> > ret(nbOfSlices);
+ for(int i=0;i<nbOfSlices;i++)
{
- if(nbOfComp2==nbOfComp)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
- }
+ std::pair<int,int> p(pos,-1);
+ int locSum(0);
+ while(locSum<sumPerSlc && pos<nbOfTuples) { pos++; locSum+=*w++; }
+ if(i!=nbOfSlices-1)
+ p.second=pos;
else
- throw INTERP_KERNEL::Exception(msg);
+ p.second=nbOfTuples;
+ ret[i]=p;
}
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
+ return ret;
}
-
/*!
* Returns a new DataArrayInt that is a modulus of two given arrays. There are 3
* valid cases.
}
}
-DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
-{
- if(_da)
- {
- _da->incrRef();
- if(_da->isAllocated())
- {
- _nb_comp=da->getNumberOfComponents();
- _nb_tuple=da->getNumberOfTuples();
- _pt=da->getPointer();
- }
- }
-}
-
-DataArrayIntIterator::~DataArrayIntIterator()
-{
- if(_da)
- _da->decrRef();
-}
-
-DataArrayIntTuple *DataArrayIntIterator::nextt()
+DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):DataArrayIterator<int>(da)
{
- if(_tuple_id<_nb_tuple)
- {
- _tuple_id++;
- DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
- _pt+=_nb_comp;
- return ret;
- }
- else
- return 0;
}
-DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
+DataArrayInt32Tuple::DataArrayInt32Tuple(int *pt, int nbOfComp):DataArrayTuple<int>(pt,nbOfComp)
{
}
int DataArrayIntTuple::intValue() const
{
- if(_nb_of_compo==1)
- return *_pt;
- throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
+ return this->zeValue();
}
/*!
*/
DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const
{
- if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
- {
- DataArrayInt *ret=DataArrayInt::New();
- ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
- return ret;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
- oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ return this->buildDA(nbOfTuples,nbOfCompo);
}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
#include "MEDCoupling.hxx"
+#include "MCType.hxx"
#include "MCAuto.hxx"
#include "MEDCouplingTimeLabel.hxx"
#include "MEDCouplingRefCountObject.hxx"
#include "InterpKernelException.hxx"
#include "MEDCouplingTraits.hxx"
+#include "MEDCouplingMap.hxx"
#include "BBTreePts.txx"
#include <string>
std::size_t getNbOfElem() const { return _nb_of_elem; }
std::size_t getNbOfElemAllocated() const { return _nb_of_elem_alloc; }
T *getPointer() { return _pointer.getPointer(); }
- MemArray<T> &operator=(const MemArray<T>& other);
+ MemArray<T> &operator=(const MemArray<T>& other);
T operator[](std::size_t id) const { return _pointer.getConstPointer()[id]; }
T& operator[](std::size_t id) { return _pointer.getPointer()[id]; }
bool isEqual(const MemArray<T>& other, T prec, std::string& reason) const;
void *_param_for_deallocator;
};
- class DataArrayInt;
+ class DataArrayInt32;
class DataArrayByte;
- class MEDCOUPLING_EXPORT DataArray : public RefCountObject, public TimeLabel
+ class DataArray : public RefCountObject, public TimeLabel
{
public:
- std::size_t getHeapMemorySizeWithoutChildren() const;
- std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
- void setName(const std::string& name);
- void copyStringInfoFrom(const DataArray& other);
- void copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds);
- void copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other);
- bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const;
- bool areInfoEquals(const DataArray& other) const;
- std::string cppRepr(const std::string& varName) const;
- std::string getName() const { return _name; }
- const std::vector<std::string> &getInfoOnComponents() const { return _info_on_compo; }
- std::vector<std::string> &getInfoOnComponents() { return _info_on_compo; }
- void setInfoOnComponents(const std::vector<std::string>& info);
- void setInfoAndChangeNbOfCompo(const std::vector<std::string>& info);
- std::vector<std::string> getVarsOnComponent() const;
- std::vector<std::string> getUnitsOnComponent() const;
- std::string getInfoOnComponent(int i) const;
- std::string getVarOnComponent(int i) const;
- std::string getUnitOnComponent(int i) const;
- void setInfoOnComponent(int i, const std::string& info);
- std::size_t getNumberOfComponents() const { return _info_on_compo.size(); }
- void setPartOfValuesBase3(const DataArray *aBase, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
- virtual void *getVoidStarPointer() = 0;
- virtual DataArray *deepCopy() const = 0;
- virtual DataArray *buildNewEmptyInstance() const = 0;
- virtual bool isAllocated() const = 0;
- virtual void checkAllocated() const = 0;
- virtual void desallocate() = 0;
- virtual int getNumberOfTuples() const = 0;
- virtual std::size_t getNbOfElems() const = 0;
- virtual std::size_t getNbOfElemAllocated() const = 0;
- virtual void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1) = 0;
- virtual void reAlloc(std::size_t newNbOfTuple) = 0;
- virtual void renumberInPlace(const int *old2New) = 0;
- virtual void renumberInPlaceR(const int *new2Old) = 0;
- virtual void setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) = 0;
- virtual void setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) = 0;
- virtual DataArray *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const = 0;
- virtual DataArray *keepSelectedComponents(const std::vector<int>& compoIds) const = 0;
- virtual DataArray *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const = 0;
- virtual DataArray *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const = 0;
- virtual DataArray *selectByTupleIdSafeSlice(int bg, int end2, int step) const = 0;
- virtual void rearrange(int newNbOfCompo) = 0;
- virtual void circularPermutation(int nbOfShift=1) = 0;
- virtual void circularPermutationPerTuple(int nbOfShift=1) = 0;
- virtual void reversePerTuple() = 0;
- void checkNbOfTuples(int nbOfTuples, const std::string& msg) const;
- void checkNbOfComps(int nbOfCompo, const std::string& msg) const;
- void checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const;
- void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const std::string& msg) const;
- void checkNbOfElems(std::size_t nbOfElems, const std::string& msg) const;
- static void GetSlice(int start, int stop, int step, int sliceId, int nbOfSlices, int& startSlice, int& stopSlice);
- static int GetNumberOfItemGivenBES(int begin, int end, int step, const std::string& msg);
- static int GetNumberOfItemGivenBESRelative(int begin, int end, int step, const std::string& msg);
- static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step);
- static std::string GetVarNameFromInfo(const std::string& info);
- static std::string GetUnitFromInfo(const std::string& info);
- static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit);
- static std::string GetAxisTypeRepr(MEDCouplingAxisType at);
- static DataArray *Aggregate(const std::vector<const DataArray *>& arrs);
- virtual void reprStream(std::ostream& stream) const = 0;
- virtual void reprZipStream(std::ostream& stream) const = 0;
- virtual void reprWithoutNameStream(std::ostream& stream) const;
- virtual void reprZipWithoutNameStream(std::ostream& stream) const = 0;
- virtual void reprCppStream(const std::string& varName, std::ostream& stream) const = 0;
- virtual void reprQuickOverview(std::ostream& stream) const = 0;
- virtual void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const = 0;
+ MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+ MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+ MEDCOUPLING_EXPORT void setName(const std::string& name);
+ MEDCOUPLING_EXPORT void copyStringInfoFrom(const DataArray& other);
+ MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds);
+ MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other);
+ MEDCOUPLING_EXPORT bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const;
+ MEDCOUPLING_EXPORT std::string cppRepr(const std::string& varName) const;
+ MEDCOUPLING_EXPORT std::string getName() const { return _name; }
+ MEDCOUPLING_EXPORT const std::vector<std::string> &getInfoOnComponents() const { return _info_on_compo; }
+ MEDCOUPLING_EXPORT std::vector<std::string> &getInfoOnComponents() { return _info_on_compo; }
+ MEDCOUPLING_EXPORT void setInfoOnComponents(const std::vector<std::string>& info);
+ MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector<std::string>& info);
+ MEDCOUPLING_EXPORT std::vector<std::string> getVarsOnComponent() const;
+ MEDCOUPLING_EXPORT std::vector<std::string> getUnitsOnComponent() const;
+ MEDCOUPLING_EXPORT std::string getInfoOnComponent(int i) const;
+ MEDCOUPLING_EXPORT std::string getVarOnComponent(int i) const;
+ MEDCOUPLING_EXPORT std::string getUnitOnComponent(int i) const;
+ MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const std::string& info);
+ MEDCOUPLING_EXPORT std::size_t getNumberOfComponents() const { return _info_on_compo.size(); }
+ MEDCOUPLING_EXPORT void setPartOfValuesBase3(const DataArray *aBase, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
+ MEDCOUPLING_EXPORT virtual void *getVoidStarPointer() = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *deepCopy() const = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *buildNewEmptyInstance() const = 0;
+ MEDCOUPLING_EXPORT virtual bool isAllocated() const = 0;
+ MEDCOUPLING_EXPORT virtual void checkAllocated() const = 0;
+ MEDCOUPLING_EXPORT virtual void desallocate() = 0;
+ MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const = 0;
+ MEDCOUPLING_EXPORT virtual std::size_t getNbOfElems() const = 0;
+ MEDCOUPLING_EXPORT virtual std::size_t getNbOfElemAllocated() const = 0;
+ MEDCOUPLING_EXPORT virtual void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1) = 0;
+ MEDCOUPLING_EXPORT virtual void reAlloc(std::size_t newNbOfTuple) = 0;
+ MEDCOUPLING_EXPORT virtual void renumberInPlace(const int *old2New) = 0;
+ MEDCOUPLING_EXPORT virtual void renumberInPlaceR(const int *new2Old) = 0;
+ MEDCOUPLING_EXPORT virtual void setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt32 *tuplesSelec) = 0;
+ MEDCOUPLING_EXPORT virtual void setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *keepSelectedComponents(const std::vector<int>& compoIds) const = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const = 0;
+ MEDCOUPLING_EXPORT virtual DataArray *selectByTupleIdSafeSlice(int bg, int end2, int step) const = 0;
+ MEDCOUPLING_EXPORT virtual void rearrange(int newNbOfCompo) = 0;
+ MEDCOUPLING_EXPORT virtual void circularPermutation(int nbOfShift=1) = 0;
+ MEDCOUPLING_EXPORT virtual void circularPermutationPerTuple(int nbOfShift=1) = 0;
+ MEDCOUPLING_EXPORT virtual void reversePerTuple() = 0;
+ MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const std::string& msg) const;
+ MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const std::string& msg) const;
+ MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const;
+ MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const std::string& msg) const;
+ MEDCOUPLING_EXPORT void checkNbOfElems(std::size_t nbOfElems, const std::string& msg) const;
+ MEDCOUPLING_EXPORT static void GetSlice(int start, int stop, int step, int sliceId, int nbOfSlices, int& startSlice, int& stopSlice);
+ MEDCOUPLING_EXPORT static int GetNumberOfItemGivenBES(int begin, int end, int step, const std::string& msg);
+ MEDCOUPLING_EXPORT static int GetNumberOfItemGivenBESRelative(int begin, int end, int step, const std::string& msg);
+ MEDCOUPLING_EXPORT static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step);
+ MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info);
+ MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info);
+ MEDCOUPLING_EXPORT static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit);
+ MEDCOUPLING_EXPORT static std::string GetAxisTypeRepr(MEDCouplingAxisType at);
+ MEDCOUPLING_EXPORT static DataArray *Aggregate(const std::vector<const DataArray *>& arrs);
+ MEDCOUPLING_EXPORT virtual void reprStream(std::ostream& stream) const = 0;
+ MEDCOUPLING_EXPORT virtual void reprZipStream(std::ostream& stream) const = 0;
+ MEDCOUPLING_EXPORT virtual void reprWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT virtual void reprZipWithoutNameStream(std::ostream& stream) const = 0;
+ MEDCOUPLING_EXPORT virtual void reprCppStream(const std::string& varName, std::ostream& stream) const = 0;
+ MEDCOUPLING_EXPORT virtual void reprQuickOverview(std::ostream& stream) const = 0;
+ MEDCOUPLING_EXPORT virtual void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const = 0;
protected:
DataArray() { }
~DataArray() { }
protected:
- static void CheckValueInRange(int ref, int value, const std::string& msg);
- static void CheckValueInRangeEx(int value, int start, int end, const std::string& msg);
- static void CheckClosingParInRange(int ref, int value, const std::string& msg);
- static int EffectiveCircPerm(int nbOfShift, int nbOfTuples);
+ MEDCOUPLING_EXPORT static void CheckValueInRange(int ref, int value, const std::string& msg);
+ MEDCOUPLING_EXPORT static void CheckValueInRangeEx(int value, int start, int end, const std::string& msg);
+ MEDCOUPLING_EXPORT static void CheckClosingParInRange(int ref, int value, const std::string& msg);
+ MEDCOUPLING_EXPORT static int EffectiveCircPerm(int nbOfShift, int nbOfTuples);
protected:
std::string _name;
std::vector<std::string> _info_on_compo;
namespace MEDCoupling
{
- class DataArrayInt;
+ class DataArrayInt32;
template<class T>
class DataArrayTemplate : public DataArray
{
public:
- static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
- std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
+ MEDCOUPLING_EXPORT static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
+ MEDCOUPLING_EXPORT std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
//
- std::size_t getHeapMemorySizeWithoutChildren() const;
+ std::size_t getHeapMemorySizeWithoutChildren() const;
+ MEDCOUPLING_EXPORT void updateTime() const { }
//
- int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
- std::size_t getNbOfElems() const { return _mem.getNbOfElem(); }
- bool empty() const;
- void *getVoidStarPointer() { return getPointer(); }
- const T *getConstPointer() const { return _mem.getConstPointer(); }
- const T *begin() const { return getConstPointer(); }
- const T *end() const { return getConstPointer()+getNbOfElems(); }
- void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1);
- void useArray(const T *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
- void useExternalArrayWithRWAccess(const T *array, int nbOfTuple, int nbOfCompo);
- T getIJSafe(int tupleId, int compoId) const;
- T getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
- void setIJ(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
- void setIJSilent(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
- T *getPointer() { return _mem.getPointer(); declareAsNew(); }
- void pack() const;
- bool isAllocated() const;
- void checkAllocated() const;
- void desallocate();
- void reserve(std::size_t nbOfElems);
- void rearrange(int newNbOfCompo);
- void transpose();
- void pushBackSilent(T val);
- void pushBackValsSilent(const T *valsBg, const T *valsEnd);
- T popBackSilent();
- T front() const;
- T back() const;
- std::size_t getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); }
- void allocIfNecessary(int nbOfTuple, int nbOfCompo);
- void deepCopyFrom(const DataArrayTemplate<T>& other);
- void reverse();
- void fillWithValue(T val);
- void reAlloc(std::size_t newNbOfTuple);
- void renumberInPlace(const int *old2New);
- void renumberInPlaceR(const int *new2Old);
- void sort(bool asc=true);
- typename Traits<T>::ArrayType *renumber(const int *old2New) const;
- typename Traits<T>::ArrayType *renumberR(const int *new2Old) const;
- typename Traits<T>::ArrayType *renumberAndReduce(const int *old2New, int newNbOfTuple) const;
- typename Traits<T>::ArrayType *changeNbOfComponents(int newNbOfComp, T dftValue) const;
- typename Traits<T>::ArrayType *subArray(int tupleIdBg, int tupleIdEnd=-1) const;
- MCAuto<typename Traits<T>::ArrayTypeCh> selectPartDef(const PartDefinition* pd) const;
- void circularPermutation(int nbOfShift=1);
- void circularPermutationPerTuple(int nbOfShift=1);
- void reversePerTuple();
- void setPartOfValues1(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
- void setPartOfValuesSimple1(T a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp);
- void setPartOfValues2(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true);
- void setPartOfValuesSimple2(T a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp);
- void setPartOfValues3(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
- void setPartOfValuesSimple3(T a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp);
- void setPartOfValues4(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true);
- void setPartOfValuesSimple4(T a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp);
- void setPartOfValuesAdv(const typename Traits<T>::ArrayType *a, const DataArrayInt *tuplesSelec);
- void setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec);
- void setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step);
- T getMaxValue(int& tupleId) const;
- T getMaxValueInArray() const;
- T getMinValue(int& tupleId) const;
- T getMinValueInArray() const;
+ MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
+ MEDCOUPLING_EXPORT std::size_t getNbOfElems() const { return _mem.getNbOfElem(); }
+ bool empty() const;
+ MEDCOUPLING_EXPORT void *getVoidStarPointer() { return getPointer(); }
+ MEDCOUPLING_EXPORT const T *getConstPointer() const { return _mem.getConstPointer(); }
+ MEDCOUPLING_EXPORT const T *begin() const { return getConstPointer(); }
+ MEDCOUPLING_EXPORT const T *end() const { return getConstPointer()+getNbOfElems(); }
+ void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1);
+ void useArray(const T *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
+ void useExternalArrayWithRWAccess(const T *array, int nbOfTuple, int nbOfCompo);
+ T getIJSafe(int tupleId, int compoId) const;
+ MEDCOUPLING_EXPORT T getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
+ MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
+ MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
+ MEDCOUPLING_EXPORT T *getPointer() { return _mem.getPointer(); declareAsNew(); }
+ void pack() const;
+ bool isAllocated() const;
+ void checkAllocated() const;
+ void desallocate();
+ void reserve(std::size_t nbOfElems);
+ void rearrange(int newNbOfCompo);
+ void transpose();
+ void pushBackSilent(T val);
+ void pushBackValsSilent(const T *valsBg, const T *valsEnd);
+ T popBackSilent();
+ T front() const;
+ T back() const;
+ std::size_t getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); }
+ void allocIfNecessary(int nbOfTuple, int nbOfCompo);
+ void deepCopyFrom(const DataArrayTemplate<T>& other);
+ void reverse();
+ void fillWithValue(T val);
+ void reAlloc(std::size_t newNbOfTuple);
+ void renumberInPlace(const int *old2New);
+ void renumberInPlaceR(const int *new2Old);
+ void sort(bool asc=true);
+ typename Traits<T>::ArrayType *renumber(const int *old2New) const;
+ typename Traits<T>::ArrayType *renumberR(const int *new2Old) const;
+ typename Traits<T>::ArrayType *renumberAndReduce(const int *old2New, int newNbOfTuple) const;
+ typename Traits<T>::ArrayType *changeNbOfComponents(int newNbOfComp, T dftValue) const;
+ typename Traits<T>::ArrayType *subArray(int tupleIdBg, int tupleIdEnd=-1) const;
+ MCAuto<typename Traits<T>::ArrayTypeCh> selectPartDef(const PartDefinition* pd) const;
+ void circularPermutation(int nbOfShift=1);
+ void circularPermutationPerTuple(int nbOfShift=1);
+ void reversePerTuple();
+ void setPartOfValues1(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
+ void setPartOfValuesSimple1(T a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp);
+ void setPartOfValues2(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true);
+ void setPartOfValuesSimple2(T a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp);
+ void setPartOfValues3(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true);
+ void setPartOfValuesSimple3(T a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp);
+ void setPartOfValues4(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true);
+ void setPartOfValuesSimple4(T a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp);
+ void setPartOfValuesAdv(const typename Traits<T>::ArrayType *a, const DataArrayInt32 *tuplesSelec);
+ void setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt32 *tuplesSelec);
+ void setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step);
+ T getMaxValue(int& tupleId) const;
+ T getMaxValueInArray() const;
+ T getMinValue(int& tupleId) const;
+ T getMinValueInArray() const;
+ MEDCOUPLING_EXPORT void getTuple(int tupleId, T *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
+ template<class InputIterator>
+ void insertAtTheEnd(InputIterator first, InputIterator last);
+ MEDCOUPLING_EXPORT static void SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet);
+ MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, T element0, const T *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
+ public:
+ MEDCOUPLING_EXPORT MemArray<T>& accessToMemArray() { return _mem; }
+ MEDCOUPLING_EXPORT const MemArray<T>& accessToMemArray() const { return _mem; }
protected:
typename Traits<T>::ArrayType *mySelectByTupleId(const int *new2OldBg, const int *new2OldEnd) const;
- typename Traits<T>::ArrayType *mySelectByTupleId(const DataArrayInt& di) const;
+ typename Traits<T>::ArrayType *mySelectByTupleId(const DataArrayInt32& di) const;
typename Traits<T>::ArrayType *mySelectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const;
typename Traits<T>::ArrayType *myKeepSelectedComponents(const std::vector<int>& compoIds) const;
typename Traits<T>::ArrayType *mySelectByTupleIdSafeSlice(int bg, int end2, int step) const;
protected:
MemArray<T> _mem;
};
+
+ template<class T>
+ class DataArrayTemplateClassic : public DataArrayTemplate<T>
+ {
+ public:
+ MEDCOUPLING_EXPORT MCAuto<DataArrayDouble> convertToDblArr() const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> convertToIntArr() const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayFloat> convertToFloatArr() const;
+ MEDCOUPLING_EXPORT void applyLin(T a, T b, int compoId);
+ MEDCOUPLING_EXPORT void applyLin(T a, T b);
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *negate() const;
+ MEDCOUPLING_EXPORT void addEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void substractEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void multiplyEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void divideEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Meld(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Meld(const std::vector<const typename Traits<T>::ArrayType *>& arr);
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> findIdsGreaterOrEqualTo(T val) const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> findIdsGreaterThan(T val) const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> findIdsLowerOrEqualTo(T val) const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> findIdsLowerThan(T val) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsStrictlyNegative() const;
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *fromNoInterlace() const;
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *toNoInterlace() const;
+ MEDCOUPLING_EXPORT void meldWith(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *duplicateEachTupleNTimes(int nbTimes) const;
+ MEDCOUPLING_EXPORT void aggregate(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void abs();
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *computeAbs() const;
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *performCopyOrIncrRef(bool dCpy) const;
+ protected:
+ static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
+ template<class OP>
+ MCAuto<DataArrayInt32> findIdsAdv(const OP& op) const;
+ private:
+ template<class U>
+ MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
+ template<class FCT>
+ void somethingEqual(const typename Traits<T>::ArrayType *other);
+ };
+
+ template<class T>
+ class DataArrayTemplateFP : public DataArrayTemplateClassic<T>
+ {
+ public:
+ MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const;
+ MEDCOUPLING_EXPORT void iota(T init=0.);
+ };
+}
+
+namespace MEDCoupling
+{
+ class DataArrayFloatIterator;
+ class DataArrayFloat : public DataArrayTemplateFP<float>
+ {
+ public:
+ MEDCOUPLING_EXPORT static DataArrayFloat *New();
+ public:// abstract method overload
+ MEDCOUPLING_EXPORT DataArrayFloat *deepCopy() const;
+ MEDCOUPLING_EXPORT DataArrayFloat *buildNewEmptyInstance() const { return DataArrayFloat::New(); }
+ MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplateFP<float>::mySelectByTupleRanges(ranges); }
+ MEDCOUPLING_EXPORT DataArrayFloat *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplateFP<float>::myKeepSelectedComponents(compoIds); }
+ MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<float>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+ MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ public:// non abstract but essential
+ MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
+ MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT bool isEqual(const DataArrayFloat& other, float prec) const;
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const;
+ public:
+ MEDCOUPLING_EXPORT DataArrayFloatIterator *iterator();
+ private:
+ ~DataArrayFloat() { }
+ DataArrayFloat() { }
+ };
}
namespace MEDCoupling
{
class DataArrayDoubleIterator;
- class MEDCOUPLING_EXPORT DataArrayDouble : public DataArrayTemplate<double>
+ class DataArrayDouble : public DataArrayTemplateFP<double>
{
public:
- static DataArrayDouble *New();
- double doubleValue() const;
- DataArrayDouble *deepCopy() const;
- DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
- DataArrayDouble *performCopyOrIncrRef(bool deepCopy) const;
- void fillWithZero();
- void iota(double init=0.);
- bool isUniform(double val, double eps) const;
- void checkMonotonic(bool increasing, double eps) const;
- bool isMonotonic(bool increasing, double eps) const;
- std::string repr() const;
- std::string reprZip() const;
- std::string reprNotTooLong() const;
- void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const;
- void reprStream(std::ostream& stream) const;
- void reprZipStream(std::ostream& stream) const;
- void reprNotTooLongStream(std::ostream& stream) const;
- void reprWithoutNameStream(std::ostream& stream) const;
- void reprZipWithoutNameStream(std::ostream& stream) const;
- void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
- void reprCppStream(const std::string& varName, std::ostream& stream) const;
- void reprQuickOverview(std::ostream& stream) const;
- void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
- bool isEqual(const DataArrayDouble& other, double prec) const;
- bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const;
- bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const;
- DataArrayInt *convertToIntArr() const;
- DataArrayDouble *fromNoInterlace() const;
- DataArrayDouble *toNoInterlace() const;
- DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<double>::mySelectByTupleId(new2OldBg,new2OldEnd); }
- DataArrayDouble *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<double>::mySelectByTupleId(di); }
- DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<double>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
- DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<double>::myKeepSelectedComponents(compoIds); }
- DataArrayDouble *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<double>::mySelectByTupleIdSafeSlice(bg,end2,step); }
- DataArrayDouble *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<double>::mySelectByTupleRanges(ranges); }
- void meldWith(const DataArrayDouble *other);
- bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const;
- void findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const;
- double minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const;
- DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const;
- DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const;
- DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const;
- DataArrayInt *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const;
- void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds);
- void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
- static void SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet);
- DataArrayDoubleIterator *iterator();
- template<class InputIterator>
- void insertAtTheEnd(InputIterator first, InputIterator last);
- void aggregate(const DataArrayDouble *other);
- void writeOnPlace(std::size_t id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
- void checkNoNullValues() const;
- void getMinMaxPerComponent(double *bounds) const;
- DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const;
- void computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const;
- void recenterForMaxPrecision(double eps);
- double getMaxValue2(DataArrayInt*& tupleIds) const;
- double getMinValue2(DataArrayInt*& tupleIds) const;
- int count(double value, double eps) const;
- double getAverageValue() const;
- double norm2() const;
- double normMax() const;
- double normMin() const;
- void accumulate(double *res) const;
- double accumulate(int compId) const;
- DataArrayDouble *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
- double distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const;
- DataArrayDouble *fromPolarToCart() const;
- DataArrayDouble *fromCylToCart() const;
- DataArrayDouble *fromSpherToCart() const;
- DataArrayDouble *cartesianize(MEDCouplingAxisType atOfThis) const;
- DataArrayDouble *fromCartToPolar() const;
- DataArrayDouble *fromCartToCyl() const;
- DataArrayDouble *fromCartToSpher() const;
- DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, const double center[3], const double vect[3]) const;
- DataArrayDouble *doublyContractedProduct() const;
- DataArrayDouble *determinant() const;
- DataArrayDouble *eigenValues() const;
- DataArrayDouble *eigenVectors() const;
- DataArrayDouble *inverse() const;
- DataArrayDouble *trace() const;
- DataArrayDouble *deviator() const;
- DataArrayDouble *magnitude() const;
- DataArrayDouble *sumPerTuple() const;
- DataArrayDouble *maxPerTuple() const;
- DataArrayDouble *maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const;
- DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
- DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const;
- void sortPerTuple(bool asc);
- void abs();
- DataArrayDouble *computeAbs() const;
- void applyLin(double a, double b, int compoId);
- void applyLin(double a, double b);
- void applyInv(double numerator);
- void applyPow(double val);
- void applyRPow(double val);
- DataArrayDouble *negate() const;
- DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const;
- DataArrayDouble *applyFunc(int nbOfComp, const std::string& func, bool isSafe=true) const;
- DataArrayDouble *applyFunc(const std::string& func, bool isSafe=true) const;
- void applyFuncOnThis(const std::string& func, bool isSafe=true);
- DataArrayDouble *applyFuncCompo(int nbOfComp, const std::string& func, bool isSafe=true) const;
- DataArrayDouble *applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func, bool isSafe=true) const;
- void applyFuncFast32(const std::string& func);
- void applyFuncFast64(const std::string& func);
- MCAuto<DataArrayDouble> symmetry3DPlane(const double point[3], const double normalVector[3]) const;
- DataArrayInt *findIdsInRange(double vmin, double vmax) const;
- DataArrayInt *findIdsNotInRange(double vmin, double vmax) const;
- static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *Aggregate(const std::vector<const DataArrayDouble *>& arr);
- static DataArrayDouble *Meld(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *Meld(const std::vector<const DataArrayDouble *>& arr);
- static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *Min(const DataArrayDouble *a1, const DataArrayDouble *a2);
- static DataArrayDouble *Add(const DataArrayDouble *a1, const DataArrayDouble *a2);
- void addEqual(const DataArrayDouble *other);
- static DataArrayDouble *Substract(const DataArrayDouble *a1, const DataArrayDouble *a2);
- void substractEqual(const DataArrayDouble *other);
- static DataArrayDouble *Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2);
- void multiplyEqual(const DataArrayDouble *other);
- static DataArrayDouble *Divide(const DataArrayDouble *a1, const DataArrayDouble *a2);
- void divideEqual(const DataArrayDouble *other);
- static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2);
- void powEqual(const DataArrayDouble *other);
- void updateTime() const { }
- MemArray<double>& accessToMemArray() { return _mem; }
- const MemArray<double>& accessToMemArray() const { return _mem; }
- std::vector<bool> toVectorOfBool(double eps) const;
- static void Rotate2DAlg(const double *center, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
- static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
- static void Symmetry3DPlane(const double point[3], const double normalVector[3], int nbNodes, const double *coordsIn, double *coordsOut);
- static void GiveBaseForPlane(const double normalVector[3], double baseOfPlane[9]);
- public:
- void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
- void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
- bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
- void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
+ MEDCOUPLING_EXPORT static DataArrayDouble *New();
+ MEDCOUPLING_EXPORT double doubleValue() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *deepCopy() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
+ MEDCOUPLING_EXPORT void fillWithZero();
+ MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const;
+ MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT std::string reprZip() const;
+ MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
+ MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const;
+ MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const;
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplateFP<double>::mySelectByTupleId(di); }
+ MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplateFP<double>::myKeepSelectedComponents(compoIds); }
+ MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+ MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplateFP<double>::mySelectByTupleRanges(ranges); }
+ MEDCOUPLING_EXPORT bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt32 *&tupleIds) const;
+ MEDCOUPLING_EXPORT void findCommonTuples(double prec, int limitTupleId, DataArrayInt32 *&comm, DataArrayInt32 *&commIndex) const;
+ MEDCOUPLING_EXPORT double minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findClosestTupleId(const DataArrayDouble *other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const;
+ MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds);
+ MEDCOUPLING_EXPORT DataArrayDoubleIterator *iterator();
+ MEDCOUPLING_EXPORT void checkNoNullValues() const;
+ MEDCOUPLING_EXPORT void getMinMaxPerComponent(double *bounds) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const;
+ MEDCOUPLING_EXPORT void computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt32 *& c, DataArrayInt32 *& cI) const;
+ MEDCOUPLING_EXPORT void recenterForMaxPrecision(double eps);
+ MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt32*& tupleIds) const;
+ MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt32*& tupleIds) const;
+ MEDCOUPLING_EXPORT int count(double value, double eps) const;
+ MEDCOUPLING_EXPORT double getAverageValue() const;
+ MEDCOUPLING_EXPORT double norm2() const;
+ MEDCOUPLING_EXPORT double normMax() const;
+ MEDCOUPLING_EXPORT double normMin() const;
+ MEDCOUPLING_EXPORT void accumulate(double *res) const;
+ MEDCOUPLING_EXPORT double accumulate(int compId) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
+ MEDCOUPLING_EXPORT MCAuto<DataArrayDouble> cumSum() const;
+ MEDCOUPLING_EXPORT double distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const;
+ 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 *fromCartToPolar() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *fromCartToCyl() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *fromCartToSpher() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, const double center[3], const double vect[3]) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *doublyContractedProduct() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *determinant() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *eigenValues() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *eigenVectors() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *inverse() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *trace() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *deviator() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *magnitude() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *sumPerTuple() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *maxPerTuple() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *maxPerTupleWithCompoId(DataArrayInt32* &compoIdOfMaxPerTuple) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const;
+ MEDCOUPLING_EXPORT void sortPerTuple(bool asc);
+ MEDCOUPLING_EXPORT void applyInv(double numerator);
+ MEDCOUPLING_EXPORT void applyPow(double val);
+ MEDCOUPLING_EXPORT void applyRPow(double val);
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, const std::string& func, bool isSafe=true) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(const std::string& func, bool isSafe=true) const;
+ MEDCOUPLING_EXPORT void applyFuncOnThis(const std::string& func, bool isSafe=true);
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFuncCompo(int nbOfComp, const std::string& func, bool isSafe=true) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func, bool isSafe=true) const;
+ MEDCOUPLING_EXPORT void applyFuncFast32(const std::string& func);
+ MEDCOUPLING_EXPORT void applyFuncFast64(const std::string& func);
+ MEDCOUPLING_EXPORT MCAuto<DataArrayDouble> symmetry3DPlane(const double point[3], const double normalVector[3]) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsInRange(double vmin, double vmax) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsNotInRange(double vmin, double vmax) const;
+ MEDCOUPLING_EXPORT static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT static DataArrayDouble *Aggregate(const std::vector<const DataArrayDouble *>& arr);
+ MEDCOUPLING_EXPORT static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT static DataArrayDouble *Min(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT void powEqual(const DataArrayDouble *other);
+ MEDCOUPLING_EXPORT std::vector<bool> toVectorOfBool(double eps) const;
+ MEDCOUPLING_EXPORT static void Rotate2DAlg(const double *center, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
+ MEDCOUPLING_EXPORT static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
+ MEDCOUPLING_EXPORT static void Symmetry3DPlane(const double point[3], const double normalVector[3], int nbNodes, const double *coordsIn, double *coordsOut);
+ MEDCOUPLING_EXPORT static void GiveBaseForPlane(const double normalVector[3], double baseOfPlane[9]);
+ public:
+ MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ MEDCOUPLING_EXPORT bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
+ MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
public:
template<int SPACEDIM>
- void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const;
+ void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt32 *c, DataArrayInt32 *cI) const;
template<int SPACEDIM>
static void FindClosestTupleIdAlg(const BBTreePts<SPACEDIM,int>& myTree, double dist, const double *pos, int nbOfTuples, const double *thisPt, int thisNbOfTuples, int *res);
template<int SPACEDIM>
static void FindTupleIdsNearTuplesAlg(const BBTreePts<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
- DataArrayInt *c, DataArrayInt *cI);
+ DataArrayInt32 *c, DataArrayInt32 *cI);
private:
~DataArrayDouble() { }
DataArrayDouble() { }
};
- class DataArrayDoubleTuple;
+ template<class T>
+ class DataArrayDiscrete : public DataArrayTemplateClassic<T>
+ {
+ public:
+ MEDCOUPLING_EXPORT bool isEqual(const DataArrayDiscrete<T>& other) const;
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const;
+ MEDCOUPLING_EXPORT void switchOnTupleEqualTo(T val, std::vector<bool>& vec) const;
+ MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const;
+ protected:
+ template<class ALG>
+ void switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const;
+ protected:
+ ~DataArrayDiscrete() { }
+ };
+
+ template<class T>
+ class DataArrayDiscreteSigned : public DataArrayDiscrete<T>
+ {
+ public:
+ MEDCOUPLING_EXPORT bool isFittingWith(const std::vector<bool>& v) const;
+ protected:
+ ~DataArrayDiscreteSigned() { }
+ };
- class MEDCOUPLING_EXPORT DataArrayDoubleIterator
+ class DataArrayInt32Iterator;
+
+ class DataArrayInt32 : public DataArrayDiscreteSigned<Int32>
{
public:
- DataArrayDoubleIterator(DataArrayDouble *da);
- ~DataArrayDoubleIterator();
- DataArrayDoubleTuple *nextt();
+ MEDCOUPLING_EXPORT static DataArrayInt32 *New();
+ MEDCOUPLING_EXPORT int intValue() const;
+ MEDCOUPLING_EXPORT int getHashCode() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildPermutationArr(const DataArrayInt32& other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *indicesOfSubPart(const DataArrayInt32& partOfThis) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *sumPerTuple() const;
+ MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const;
+ MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const;
+ MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const;
+ MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const;
+ MEDCOUPLING_EXPORT void fillWithZero();
+ MEDCOUPLING_EXPORT void iota(int init=0);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT std::string reprZip() const;
+ MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
+ MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
+ MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd);
+ MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal<int>& m);
+ MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const;
+ MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd,
+ DataArrayInt32 *& castArr, DataArrayInt32 *& rankInsideCast, DataArrayInt32 *& castsPresent) const;
+ MEDCOUPLING_EXPORT bool isRange(int& strt, int& sttoopp, int& stteepp) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *invertArrayO2N2N2O(int newNbOfElem) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *invertArrayN2O2O2N(int oldNbOfElem) const;
+ MEDCOUPLING_EXPORT MCAuto< MapKeyVal<int> > invertArrayN2O2O2NOptimized() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *invertArrayO2N2N2OBis(int newNbOfElem) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplate<int>::mySelectByTupleId(di); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<int>::myKeepSelectedComponents(compoIds); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<int>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<int>::mySelectByTupleRanges(ranges); }
+ MEDCOUPLING_EXPORT DataArrayInt32 *checkAndPreparePermutation() const;
+ MEDCOUPLING_EXPORT static DataArrayInt32 *FindPermutationFromFirstToSecond(const DataArrayInt32 *ids1, const DataArrayInt32 *ids2);
+ MEDCOUPLING_EXPORT void changeSurjectiveFormat(int targetNb, DataArrayInt32 *&arr, DataArrayInt32 *&arrI) const;
+ MEDCOUPLING_EXPORT static DataArrayInt32 *ConvertIndexArrayToO2N(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples);
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildPermArrPerLevel() const;
+ MEDCOUPLING_EXPORT bool isIota(int sizeExpected) const;
+ MEDCOUPLING_EXPORT bool isUniform(int val) const;
+ MEDCOUPLING_EXPORT int checkUniformAndGuess() const;
+ MEDCOUPLING_EXPORT bool hasUniqueValues() const;
+ MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt32 *a, const std::vector<int>& compoIds);
+ MEDCOUPLING_EXPORT DataArrayInt32Iterator *iterator();
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsEqual(int val) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsNotEqual(int val) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsEqualList(const int *valsBg, const int *valsEnd) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsNotEqualList(const int *valsBg, const int *valsEnd) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsEqualTuple(const int *tupleBg, const int *tupleEnd) const;
+ MEDCOUPLING_EXPORT int changeValue(int oldValue, int newValue);
+ MEDCOUPLING_EXPORT int findIdFirstEqualTuple(const std::vector<int>& tupl) const;
+ MEDCOUPLING_EXPORT int findIdFirstEqual(int value) const;
+ MEDCOUPLING_EXPORT int findIdFirstEqual(const std::vector<int>& vals) const;
+ MEDCOUPLING_EXPORT int findIdSequence(const std::vector<int>& vals) const;
+ MEDCOUPLING_EXPORT bool presenceOfTuple(const std::vector<int>& tupl) const;
+ MEDCOUPLING_EXPORT bool presenceOfValue(int value) const;
+ MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector<int>& vals) const;
+ MEDCOUPLING_EXPORT int count(int value) const;
+ MEDCOUPLING_EXPORT void accumulate(int *res) const;
+ MEDCOUPLING_EXPORT int accumulate(int compId) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
+ MEDCOUPLING_EXPORT void getMinMaxValues(int& minValue, int& maxValue) const;
+ MEDCOUPLING_EXPORT void applyInv(int numerator);
+ MEDCOUPLING_EXPORT void applyDivideBy(int val);
+ MEDCOUPLING_EXPORT void applyModulus(int val);
+ MEDCOUPLING_EXPORT void applyRModulus(int val);
+ MEDCOUPLING_EXPORT void applyPow(int val);
+ MEDCOUPLING_EXPORT void applyRPow(int val);
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsInRange(int vmin, int vmax) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdsNotInRange(int vmin, int vmax) const;
+ MEDCOUPLING_EXPORT bool checkAllIdsInRange(int vmin, int vmax) const;
+ MEDCOUPLING_EXPORT static DataArrayInt32 *Aggregate(const DataArrayInt32 *a1, const DataArrayInt32 *a2, int offsetA2);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *Aggregate(const std::vector<const DataArrayInt32 *>& arr);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *AggregateIndexes(const std::vector<const DataArrayInt32 *>& arrs);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *MakePartition(const std::vector<const DataArrayInt32 *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *BuildUnion(const std::vector<const DataArrayInt32 *>& arr);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *BuildIntersection(const std::vector<const DataArrayInt32 *>& arr);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *BuildListOfSwitchedOn(const std::vector<bool>& v);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *BuildListOfSwitchedOff(const std::vector<bool>& v);
+ MEDCOUPLING_EXPORT static void PutIntoToSkylineFrmt(const std::vector< std::vector<int> >& v, DataArrayInt32 *& data, DataArrayInt32 *& dataIndex);
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildComplement(int nbOfElement) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildSubstraction(const DataArrayInt32 *other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildSubstractionOptimized(const DataArrayInt32 *other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildUnion(const DataArrayInt32 *other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildIntersection(const DataArrayInt32 *other) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildUnique() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildUniqueNotSorted() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *deltaShiftIndex() const;
+ MEDCOUPLING_EXPORT void computeOffsets();
+ MEDCOUPLING_EXPORT void computeOffsetsFull();
+ MEDCOUPLING_EXPORT void findIdsRangesInListOfIds(const DataArrayInt32 *listOfIds, DataArrayInt32 *& rangeIdsFetched, DataArrayInt32 *& idsInInputListThatFetch) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildExplicitArrByRanges(const DataArrayInt32 *offsets) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildExplicitArrOfSliceOnScaledArr(int begin, int stop, int step) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findRangeIdForEachTuple(const DataArrayInt32 *ranges) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *findIdInRangeForEachTuple(const DataArrayInt32 *ranges) const;
+ MEDCOUPLING_EXPORT void sortEachPairToMakeALinkedList();
+ MEDCOUPLING_EXPORT MCAuto<DataArrayInt32> fromLinkedListOfPairToList() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *getDifferentValues() const;
+ MEDCOUPLING_EXPORT std::vector<DataArrayInt32 *> partitionByDifferentValues(std::vector<int>& differentIds) const;
+ MEDCOUPLING_EXPORT std::vector< std::pair<int,int> > splitInBalancedSlices(int nbOfSlices) const;
+ MEDCOUPLING_EXPORT static DataArrayInt32 *Modulus(const DataArrayInt32 *a1, const DataArrayInt32 *a2);
+ MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt32 *other);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *Pow(const DataArrayInt32 *a1, const DataArrayInt32 *a2);
+ MEDCOUPLING_EXPORT void powEqual(const DataArrayInt32 *other);
+ MEDCOUPLING_EXPORT MemArray<int>& accessToMemArray() { return _mem; }
+ MEDCOUPLING_EXPORT const MemArray<int>& accessToMemArray() const { return _mem; }
+ public:
+ MEDCOUPLING_EXPORT static int *CheckAndPreparePermutation(const int *start, const int *end);
+ MEDCOUPLING_EXPORT static DataArrayInt32 *Range(int begin, int end, int step);
+ public:
+ MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ MEDCOUPLING_EXPORT bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
+ MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
private:
- DataArrayDouble *_da;
- double *_pt;
- int _tuple_id;
- int _nb_comp;
- int _nb_tuple;
+ ~DataArrayInt32() { }
+ DataArrayInt32() { }
};
- class MEDCOUPLING_EXPORT DataArrayDoubleTuple
+ class DataArrayInt64 : public DataArrayDiscrete<Int64>
+ {
+ };
+
+ template<class T>
+ template<class OP>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsAdv(const OP& op) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::findIdsAdv : this must have exactly one component !");
+ const T *cptr(this->begin());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
+ int nbOfTuples(this->getNumberOfTuples());
+ for(int i=0;i<nbOfTuples;i++,cptr++)
+ if(op(*cptr))
+ ret->pushBackSilent(i);
+ return ret;
+ }
+
+ class DataArrayChar : public DataArrayTemplate<char>
{
public:
- DataArrayDoubleTuple(double *pt, int nbOfComp);
- std::string repr() const;
- int getNumberOfCompo() const { return _nb_of_compo; }
- const double *getConstPointer() const { return _pt; }
- double *getPointer() { return _pt; }
- double doubleValue() const;
- DataArrayDouble *buildDADouble(int nbOfTuples, int nbOfCompo) const;
- private:
- double *_pt;
- int _nb_of_compo;
+ MEDCOUPLING_EXPORT virtual DataArrayChar *buildEmptySpecializedDAChar() const = 0;
+ MEDCOUPLING_EXPORT int getHashCode() const;
+ MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const;
+ MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayChar& other) const;
+ MEDCOUPLING_EXPORT void fillWithZero();
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT std::string reprZip() const;
+ MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const;
+ MEDCOUPLING_EXPORT DataArrayChar *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<char>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayChar *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<char>::mySelectByTupleId(di); }
+ MEDCOUPLING_EXPORT DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<char>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayChar *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<char>::myKeepSelectedComponents(compoIds); }
+ MEDCOUPLING_EXPORT DataArrayChar *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<char>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+ MEDCOUPLING_EXPORT bool isUniform(char val) const;
+ MEDCOUPLING_EXPORT void meldWith(const DataArrayChar *other);
+ MEDCOUPLING_EXPORT DataArray *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<char>::mySelectByTupleRanges(ranges); }
+ MEDCOUPLING_EXPORT DataArrayInt *findIdsEqual(char val) const;
+ MEDCOUPLING_EXPORT DataArrayInt *findIdsNotEqual(char val) const;
+ MEDCOUPLING_EXPORT int findIdSequence(const std::vector<char>& vals) const;
+ MEDCOUPLING_EXPORT int findIdFirstEqualTuple(const std::vector<char>& tupl) const;
+ MEDCOUPLING_EXPORT int findIdFirstEqual(char value) const;
+ MEDCOUPLING_EXPORT int findIdFirstEqual(const std::vector<char>& vals) const;
+ MEDCOUPLING_EXPORT bool presenceOfTuple(const std::vector<char>& tupl) const;
+ MEDCOUPLING_EXPORT bool presenceOfValue(char value) const;
+ MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector<char>& vals) const;
+ MEDCOUPLING_EXPORT DataArrayInt *findIdsInRange(char vmin, char vmax) const;
+ MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const DataArrayChar *a1, const DataArrayChar *a2);
+ MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const std::vector<const DataArrayChar *>& arr);
+ MEDCOUPLING_EXPORT static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2);
+ MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector<const DataArrayChar *>& arr);
+ MEDCOUPLING_EXPORT MemArray<char>& accessToMemArray() { return _mem; }
+ MEDCOUPLING_EXPORT const MemArray<char>& accessToMemArray() const { return _mem; }
+ public:
+ //MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ //MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ //MEDCOUPLING_EXPORT bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
+ //MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
+ protected:
+ DataArrayChar() { }
};
- class DataArrayIntIterator;
+ class DataArrayByteIterator;
- class MEDCOUPLING_EXPORT DataArrayInt : public DataArrayTemplate<int>
+ class DataArrayByte : public DataArrayChar
{
public:
- static DataArrayInt *New();
- int intValue() const;
- int getHashCode() const;
- DataArrayInt *deepCopy() const;
- DataArrayInt *performCopyOrIncrRef(bool deepCopy) const;
- DataArrayInt *buildNewEmptyInstance() const { return DataArrayInt::New(); }
- bool isEqual(const DataArrayInt& other) const;
- bool isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const;
- bool isEqualWithoutConsideringStr(const DataArrayInt& other) const;
- bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const;
- bool isFittingWith(const std::vector<bool>& v) const;
- void switchOnTupleEqualTo(int val, std::vector<bool>& vec) const;
- void switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const;
- DataArrayInt *buildPermutationArr(const DataArrayInt& other) const;
- DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const;
- DataArrayInt *sumPerTuple() const;
- void checkMonotonic(bool increasing) const;
- bool isMonotonic(bool increasing) const;
- void checkStrictlyMonotonic(bool increasing) const;
- bool isStrictlyMonotonic(bool increasing) const;
- void fillWithZero();
- void iota(int init=0);
- std::string repr() const;
- std::string reprZip() const;
- std::string reprNotTooLong() const;
- void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
- void reprStream(std::ostream& stream) const;
- void reprZipStream(std::ostream& stream) const;
- void reprNotTooLongStream(std::ostream& stream) const;
- void reprWithoutNameStream(std::ostream& stream) const;
- void reprZipWithoutNameStream(std::ostream& stream) const;
- void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
- void reprCppStream(const std::string& varName, std::ostream& stream) const;
- void reprQuickOverview(std::ostream& stream) const;
- void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
- void transformWithIndArr(const int *indArrBg, const int *indArrEnd);
- DataArrayInt *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const;
- void splitByValueRange(const int *arrBg, const int *arrEnd,
- DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const;
- bool isRange(int& strt, int& sttoopp, int& stteepp) const;
- DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const;
- DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const;
- DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const;
- DataArrayDouble *convertToDblArr() const;
- DataArrayInt *fromNoInterlace() const;
- DataArrayInt *toNoInterlace() const;
- DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleId(new2OldBg,new2OldEnd); }
- DataArrayInt *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<int>::mySelectByTupleId(di); }
- DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
- DataArrayInt *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<int>::myKeepSelectedComponents(compoIds); }
- DataArrayInt *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<int>::mySelectByTupleIdSafeSlice(bg,end2,step); }
- DataArrayInt *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<int>::mySelectByTupleRanges(ranges); }
- DataArrayInt *checkAndPreparePermutation() const;
- static DataArrayInt *FindPermutationFromFirstToSecond(const DataArrayInt *ids1, const DataArrayInt *ids2);
- void changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const;
- static DataArrayInt *ConvertIndexArrayToO2N(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples);
- DataArrayInt *buildPermArrPerLevel() const;
- bool isIota(int sizeExpected) const;
- bool isUniform(int val) const;
- bool hasUniqueValues() const;
- void meldWith(const DataArrayInt *other);
- void setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds);
- void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
- static void SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet);
- DataArrayIntIterator *iterator();
- DataArrayInt *findIdsEqual(int val) const;
- DataArrayInt *findIdsNotEqual(int val) const;
- DataArrayInt *findIdsEqualList(const int *valsBg, const int *valsEnd) const;
- DataArrayInt *findIdsNotEqualList(const int *valsBg, const int *valsEnd) const;
- DataArrayInt *findIdsEqualTuple(const int *tupleBg, const int *tupleEnd) const;
- int changeValue(int oldValue, int newValue);
- int findIdFirstEqualTuple(const std::vector<int>& tupl) const;
- int findIdFirstEqual(int value) const;
- int findIdFirstEqual(const std::vector<int>& vals) const;
- int findIdSequence(const std::vector<int>& vals) const;
- bool presenceOfTuple(const std::vector<int>& tupl) const;
- bool presenceOfValue(int value) const;
- bool presenceOfValue(const std::vector<int>& vals) const;
- int count(int value) const;
- void accumulate(int *res) const;
- int accumulate(int compId) const;
- DataArrayInt *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
- void getMinMaxValues(int& minValue, int& maxValue) const;
- void abs();
- DataArrayInt *computeAbs() const;
- void applyLin(int a, int b, int compoId);
- void applyLin(int a, int b);
- void applyInv(int numerator);
- DataArrayInt *negate() const;
- void applyDivideBy(int val);
- void applyModulus(int val);
- void applyRModulus(int val);
- void applyPow(int val);
- void applyRPow(int val);
- DataArrayInt *findIdsInRange(int vmin, int vmax) const;
- DataArrayInt *findIdsNotInRange(int vmin, int vmax) const;
- DataArrayInt *findIdsStricltyNegative() const;
- bool checkAllIdsInRange(int vmin, int vmax) const;
- static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2);
- static DataArrayInt *Aggregate(const std::vector<const DataArrayInt *>& arr);
- static DataArrayInt *AggregateIndexes(const std::vector<const DataArrayInt *>& arrs);
- static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2);
- static DataArrayInt *Meld(const std::vector<const DataArrayInt *>& arr);
- static DataArrayInt *MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups);
- static DataArrayInt *BuildUnion(const std::vector<const DataArrayInt *>& arr);
- static DataArrayInt *BuildIntersection(const std::vector<const DataArrayInt *>& arr);
- static DataArrayInt *BuildListOfSwitchedOn(const std::vector<bool>& v);
- static DataArrayInt *BuildListOfSwitchedOff(const std::vector<bool>& v);
- static void PutIntoToSkylineFrmt(const std::vector< std::vector<int> >& v, DataArrayInt *& data, DataArrayInt *& dataIndex);
- DataArrayInt *buildComplement(int nbOfElement) const;
- DataArrayInt *buildSubstraction(const DataArrayInt *other) const;
- DataArrayInt *buildSubstractionOptimized(const DataArrayInt *other) const;
- DataArrayInt *buildUnion(const DataArrayInt *other) const;
- DataArrayInt *buildIntersection(const DataArrayInt *other) const;
- DataArrayInt *buildUnique() const;
- DataArrayInt *buildUniqueNotSorted() const;
- DataArrayInt *deltaShiftIndex() const;
- void computeOffsets();
- void computeOffsetsFull();
- void findIdsRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const;
- DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const;
- DataArrayInt *buildExplicitArrOfSliceOnScaledArr(int begin, int stop, int step) const;
- DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const;
- DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const;
- void sortEachPairToMakeALinkedList();
- DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const;
- DataArrayInt *getDifferentValues() const;
- std::vector<DataArrayInt *> partitionByDifferentValues(std::vector<int>& differentIds) const;
- std::vector< std::pair<int,int> > splitInBalancedSlices(int nbOfSlices) const;
- template<class InputIterator>
- void insertAtTheEnd(InputIterator first, InputIterator last);
- void aggregate(const DataArrayInt *other);
- void writeOnPlace(std::size_t id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
- static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2);
- void addEqual(const DataArrayInt *other);
- static DataArrayInt *Substract(const DataArrayInt *a1, const DataArrayInt *a2);
- void substractEqual(const DataArrayInt *other);
- static DataArrayInt *Multiply(const DataArrayInt *a1, const DataArrayInt *a2);
- void multiplyEqual(const DataArrayInt *other);
- static DataArrayInt *Divide(const DataArrayInt *a1, const DataArrayInt *a2);
- void divideEqual(const DataArrayInt *other);
- static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2);
- void modulusEqual(const DataArrayInt *other);
- static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2);
- void powEqual(const DataArrayInt *other);
- void updateTime() const { }
- MemArray<int>& accessToMemArray() { return _mem; }
- const MemArray<int>& accessToMemArray() const { return _mem; }
- public:
- static int *CheckAndPreparePermutation(const int *start, const int *end);
- static DataArrayInt *Range(int begin, int end, int step);
- public:
- void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
- void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
- bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
- void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
+ MEDCOUPLING_EXPORT static DataArrayByte *New();
+ MEDCOUPLING_EXPORT DataArrayChar *buildEmptySpecializedDAChar() const;
+ MEDCOUPLING_EXPORT DataArrayByteIterator *iterator();
+ MEDCOUPLING_EXPORT DataArrayByte *deepCopy() const;
+ MEDCOUPLING_EXPORT DataArrayByte *performCopyOrIncrRef(bool deepCopy) const;
+ MEDCOUPLING_EXPORT DataArrayByte *buildNewEmptyInstance() const { return DataArrayByte::New(); }
+ MEDCOUPLING_EXPORT char byteValue() const;
+ MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
+ MEDCOUPLING_EXPORT std::vector<bool> toVectorOfBool() const;
private:
- ~DataArrayInt() { }
- DataArrayInt() { }
+ ~DataArrayByte() { }
+ DataArrayByte() { }
};
- class DataArrayIntTuple;
+ class DataArrayAsciiCharIterator;
- class MEDCOUPLING_EXPORT DataArrayIntIterator
+ class DataArrayAsciiChar : public DataArrayChar
+ {
+ public:
+ MEDCOUPLING_EXPORT static DataArrayAsciiChar *New();
+ MEDCOUPLING_EXPORT static DataArrayAsciiChar *New(const std::string& st);
+ MEDCOUPLING_EXPORT static DataArrayAsciiChar *New(const std::vector<std::string>& vst, char defaultChar);
+ MEDCOUPLING_EXPORT DataArrayChar *buildEmptySpecializedDAChar() const;
+ MEDCOUPLING_EXPORT DataArrayAsciiCharIterator *iterator();
+ MEDCOUPLING_EXPORT DataArrayAsciiChar *deepCopy() const;
+ MEDCOUPLING_EXPORT DataArrayAsciiChar *performCopyOrIncrRef(bool deepCopy) const;
+ MEDCOUPLING_EXPORT DataArrayAsciiChar *buildNewEmptyInstance() const { return DataArrayAsciiChar::New(); }
+ MEDCOUPLING_EXPORT char asciiCharValue() const;
+ MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
+ private:
+ ~DataArrayAsciiChar() { }
+ DataArrayAsciiChar() { }
+ DataArrayAsciiChar(const std::string& st);
+ DataArrayAsciiChar(const std::vector<std::string>& vst, char defaultChar);
+ };
+
+ template<class T>
+ class DataArrayIterator
{
public:
- DataArrayIntIterator(DataArrayInt *da);
- ~DataArrayIntIterator();
- DataArrayIntTuple *nextt();
+ DataArrayIterator(typename Traits<T>::ArrayType *da);
+ ~DataArrayIterator();
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayTuple *nextt();
private:
- DataArrayInt *_da;
- int *_pt;
+ typename Traits<T>::ArrayType *_da;
+ T *_pt;
int _tuple_id;
int _nb_comp;
int _nb_tuple;
};
- class MEDCOUPLING_EXPORT DataArrayIntTuple
+ template<class T>
+ class DataArrayTuple
{
public:
- DataArrayIntTuple(int *pt, int nbOfComp);
- std::string repr() const;
- int getNumberOfCompo() const { return _nb_of_compo; }
- const int *getConstPointer() const { return _pt; }
- int *getPointer() { return _pt; }
- int intValue() const;
- DataArrayInt *buildDAInt(int nbOfTuples, int nbOfCompo) const;
- private:
- int *_pt;
+ MEDCOUPLING_EXPORT DataArrayTuple(T *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT int getNumberOfCompo() const { return _nb_of_compo; }
+ MEDCOUPLING_EXPORT const T *getConstPointer() const { return _pt; }
+ MEDCOUPLING_EXPORT T *getPointer() { return _pt; }
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *buildDA(int nbOfTuples, int nbOfCompo) const;
+ protected:
+ T zeValue() const;
+ protected:
+ T *_pt;
int _nb_of_compo;
};
- class MEDCOUPLING_EXPORT DataArrayChar : public DataArrayTemplate<char>
+ class DataArrayDoubleTuple;
+
+ class DataArrayDoubleIterator : public DataArrayIterator<double>
{
public:
- virtual DataArrayChar *buildEmptySpecializedDAChar() const = 0;
- int getHashCode() const;
- bool isEqual(const DataArrayChar& other) const;
- virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
- bool isEqualWithoutConsideringStr(const DataArrayChar& other) const;
- void fillWithZero();
- std::string repr() const;
- std::string reprZip() const;
- DataArrayInt *convertToIntArr() const;
- DataArrayChar *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<char>::mySelectByTupleId(new2OldBg,new2OldEnd); }
- DataArrayChar *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<char>::mySelectByTupleId(di); }
- DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<char>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
- DataArrayChar *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<char>::myKeepSelectedComponents(compoIds); }
- DataArrayChar *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<char>::mySelectByTupleIdSafeSlice(bg,end2,step); }
- bool isUniform(char val) const;
- void meldWith(const DataArrayChar *other);
- DataArray *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<char>::mySelectByTupleRanges(ranges); }
- void getTuple(int tupleId, char *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
- DataArrayInt *findIdsEqual(char val) const;
- DataArrayInt *findIdsNotEqual(char val) const;
- int findIdSequence(const std::vector<char>& vals) const;
- int findIdFirstEqualTuple(const std::vector<char>& tupl) const;
- int findIdFirstEqual(char value) const;
- int findIdFirstEqual(const std::vector<char>& vals) const;
- bool presenceOfTuple(const std::vector<char>& tupl) const;
- bool presenceOfValue(char value) const;
- bool presenceOfValue(const std::vector<char>& vals) const;
- DataArrayInt *findIdsInRange(char vmin, char vmax) const;
- static DataArrayChar *Aggregate(const DataArrayChar *a1, const DataArrayChar *a2);
- static DataArrayChar *Aggregate(const std::vector<const DataArrayChar *>& arr);
- static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2);
- static DataArrayChar *Meld(const std::vector<const DataArrayChar *>& arr);
- template<class InputIterator>
- void insertAtTheEnd(InputIterator first, InputIterator last);
- void updateTime() const { }
- MemArray<char>& accessToMemArray() { return _mem; }
- const MemArray<char>& accessToMemArray() const { return _mem; }
- public:
- // void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
- // void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
- // bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
- // void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
- protected:
- DataArrayChar() { }
+ MEDCOUPLING_EXPORT DataArrayDoubleIterator(DataArrayDouble *da);
+ MEDCOUPLING_EXPORT ~DataArrayDoubleIterator() { }
};
- class DataArrayByteIterator;
+ class DataArrayDoubleTuple : public DataArrayTuple<double>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayDoubleTuple(double *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT double doubleValue() const;
+ MEDCOUPLING_EXPORT DataArrayDouble *buildDADouble(int nbOfTuples, int nbOfCompo) const;
+ };
- class MEDCOUPLING_EXPORT DataArrayByte : public DataArrayChar
+ class DataArrayFloatTuple;
+
+ class DataArrayFloatIterator : public DataArrayIterator<float>
{
public:
- static DataArrayByte *New();
- DataArrayChar *buildEmptySpecializedDAChar() const;
- DataArrayByteIterator *iterator();
- DataArrayByte *deepCopy() const;
- DataArrayByte *performCopyOrIncrRef(bool deepCopy) const;
- DataArrayByte *buildNewEmptyInstance() const { return DataArrayByte::New(); }
- char byteValue() const;
- void reprStream(std::ostream& stream) const;
- void reprZipStream(std::ostream& stream) const;
- void reprWithoutNameStream(std::ostream& stream) const;
- void reprZipWithoutNameStream(std::ostream& stream) const;
- void reprCppStream(const std::string& varName, std::ostream& stream) const;
- void reprQuickOverview(std::ostream& stream) const;
- void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
- bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
- std::vector<bool> toVectorOfBool() const;
- private:
- ~DataArrayByte() { }
- DataArrayByte() { }
+ MEDCOUPLING_EXPORT DataArrayFloatIterator(DataArrayFloat *da);
+ MEDCOUPLING_EXPORT ~DataArrayFloatIterator() { }
};
- class DataArrayByteTuple;
+ class DataArrayFloatTuple : public DataArrayTuple<float>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayFloatTuple(float *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT float floatValue() const;
+ MEDCOUPLING_EXPORT DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const;
+ };
+
+ class DataArrayIntIterator : public DataArrayIterator<int>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayIntIterator(DataArrayInt *da);
+ MEDCOUPLING_EXPORT ~DataArrayIntIterator() { }
+ };
+
+ class DataArrayInt32Tuple : public DataArrayTuple<Int32>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayInt32Tuple(int *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT int intValue() const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildDAInt(int nbOfTuples, int nbOfCompo) const;
+ };
+
+ typedef DataArrayInt32Tuple DataArrayIntTuple;
- class MEDCOUPLING_EXPORT DataArrayByteIterator
+ class DataArrayAsciiCharTuple;
+
+ class DataArrayAsciiCharIterator
{
public:
- DataArrayByteIterator(DataArrayByte *da);
- ~DataArrayByteIterator();
- DataArrayByteTuple *nextt();
+ MEDCOUPLING_EXPORT DataArrayAsciiCharIterator(DataArrayAsciiChar *da);
+ MEDCOUPLING_EXPORT ~DataArrayAsciiCharIterator();
+ MEDCOUPLING_EXPORT DataArrayAsciiCharTuple *nextt();
private:
- DataArrayByte *_da;
+ DataArrayAsciiChar *_da;
char *_pt;
int _tuple_id;
int _nb_comp;
int _nb_tuple;
};
- class MEDCOUPLING_EXPORT DataArrayByteTuple
+ class DataArrayAsciiCharTuple
{
public:
- DataArrayByteTuple(char *pt, int nbOfComp);
- std::string repr() const;
- int getNumberOfCompo() const { return _nb_of_compo; }
- const char *getConstPointer() const { return _pt; }
- char *getPointer() { return _pt; }
- char byteValue() const;
- DataArrayByte *buildDAByte(int nbOfTuples, int nbOfCompo) const;
+ MEDCOUPLING_EXPORT DataArrayAsciiCharTuple(char *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT int getNumberOfCompo() const { return _nb_of_compo; }
+ MEDCOUPLING_EXPORT const char *getConstPointer() const { return _pt; }
+ MEDCOUPLING_EXPORT char *getPointer() { return _pt; }
+ MEDCOUPLING_EXPORT char asciiCharValue() const;
+ MEDCOUPLING_EXPORT DataArrayAsciiChar *buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const;
private:
char *_pt;
int _nb_of_compo;
};
+
+ class DataArrayByteTuple;
- class DataArrayAsciiCharIterator;
-
- class MEDCOUPLING_EXPORT DataArrayAsciiChar : public DataArrayChar
- {
- public:
- static DataArrayAsciiChar *New();
- static DataArrayAsciiChar *New(const std::string& st);
- static DataArrayAsciiChar *New(const std::vector<std::string>& vst, char defaultChar);
- DataArrayChar *buildEmptySpecializedDAChar() const;
- DataArrayAsciiCharIterator *iterator();
- DataArrayAsciiChar *deepCopy() const;
- DataArrayAsciiChar *performCopyOrIncrRef(bool deepCopy) const;
- DataArrayAsciiChar *buildNewEmptyInstance() const { return DataArrayAsciiChar::New(); }
- char asciiCharValue() const;
- void reprStream(std::ostream& stream) const;
- void reprZipStream(std::ostream& stream) const;
- void reprWithoutNameStream(std::ostream& stream) const;
- void reprZipWithoutNameStream(std::ostream& stream) const;
- void reprCppStream(const std::string& varName, std::ostream& stream) const;
- void reprQuickOverview(std::ostream& stream) const;
- void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
- bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
- private:
- ~DataArrayAsciiChar() { }
- DataArrayAsciiChar() { }
- DataArrayAsciiChar(const std::string& st);
- DataArrayAsciiChar(const std::vector<std::string>& vst, char defaultChar);
- };
-
- class DataArrayAsciiCharTuple;
-
- class MEDCOUPLING_EXPORT DataArrayAsciiCharIterator
+ class DataArrayByteIterator
{
public:
- DataArrayAsciiCharIterator(DataArrayAsciiChar *da);
- ~DataArrayAsciiCharIterator();
- DataArrayAsciiCharTuple *nextt();
+ MEDCOUPLING_EXPORT DataArrayByteIterator(DataArrayByte *da);
+ MEDCOUPLING_EXPORT ~DataArrayByteIterator();
+ MEDCOUPLING_EXPORT DataArrayByteTuple *nextt();
private:
- DataArrayAsciiChar *_da;
+ DataArrayByte *_da;
char *_pt;
int _tuple_id;
int _nb_comp;
int _nb_tuple;
};
- class MEDCOUPLING_EXPORT DataArrayAsciiCharTuple
+ class DataArrayByteTuple
{
public:
- DataArrayAsciiCharTuple(char *pt, int nbOfComp);
- std::string repr() const;
- int getNumberOfCompo() const { return _nb_of_compo; }
- const char *getConstPointer() const { return _pt; }
- char *getPointer() { return _pt; }
- char asciiCharValue() const;
- DataArrayAsciiChar *buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const;
+ MEDCOUPLING_EXPORT DataArrayByteTuple(char *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT int getNumberOfCompo() const { return _nb_of_compo; }
+ MEDCOUPLING_EXPORT const char *getConstPointer() const { return _pt; }
+ MEDCOUPLING_EXPORT char *getPointer() { return _pt; }
+ MEDCOUPLING_EXPORT char byteValue() const;
+ MEDCOUPLING_EXPORT DataArrayByte *buildDAByte(int nbOfTuples, int nbOfCompo) const;
private:
char *_pt;
int _nb_of_compo;
pointer[_nb_of_elem++]=*first++;
}
}
-
- template<class InputIterator>
- void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last)
- {
- int nbCompo(getNumberOfComponents());
- if(nbCompo==1)
- _mem.insertAtTheEnd(first,last);
- else if(nbCompo==0)
- {
- _info_on_compo.resize(1);
- _mem.insertAtTheEnd(first,last);
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
- }
-
- template<class InputIterator>
- void DataArrayInt::insertAtTheEnd(InputIterator first, InputIterator last)
- {
- int nbCompo(getNumberOfComponents());
- if(nbCompo==1)
- _mem.insertAtTheEnd(first,last);
- else if(nbCompo==0)
- {
- _info_on_compo.resize(1);
- _mem.insertAtTheEnd(first,last);
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::insertAtTheEnd : not available for DataArrayInt with number of components different than 1 !");
- }
+ template<class T>
template<class InputIterator>
- void DataArrayChar::insertAtTheEnd(InputIterator first, InputIterator last)
+ void DataArrayTemplate<T>::insertAtTheEnd(InputIterator first, InputIterator last)
{
- int nbCompo(getNumberOfComponents());
+ int nbCompo(this->getNumberOfComponents());
if(nbCompo==1)
- _mem.insertAtTheEnd(first,last);
+ this->_mem.insertAtTheEnd(first,last);
else if(nbCompo==0)
{
- _info_on_compo.resize(1);
- _mem.insertAtTheEnd(first,last);
+ this->_info_on_compo.resize(1);
+ this->_mem.insertAtTheEnd(first,last);
}
else
- throw INTERP_KERNEL::Exception("DataArrayChar::insertAtTheEnd : not available for DataArrayChar with number of components different than 1 !");
+ throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
}
}
#include <sstream>
#include <cstdlib>
+#include <numeric>
#include <algorithm>
namespace MEDCoupling
//////////////////////////////////
+ template<class T>
+ DataArrayIterator<T>::DataArrayIterator(typename Traits<T>::ArrayType *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
+ {
+ if(_da)
+ {
+ _da->incrRef();
+ if(_da->isAllocated())
+ {
+ _nb_comp=da->getNumberOfComponents();
+ _nb_tuple=da->getNumberOfTuples();
+ _pt=da->getPointer();
+ }
+ }
+ }
+
+ template<class T>
+ DataArrayIterator<T>::~DataArrayIterator()
+ {
+ if(_da)
+ _da->decrRef();
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayTuple *DataArrayIterator<T>::nextt()
+ {
+ if(_tuple_id<_nb_tuple)
+ {
+ _tuple_id++;
+ typename Traits<T>::ArrayTuple *ret=new typename Traits<T>::ArrayTuple(_pt,_nb_comp);
+ _pt+=_nb_comp;
+ return ret;
+ }
+ else
+ return 0;
+ }
+
+ //////////////////////////////////
+
+ template<class T>
+ DataArrayTuple<T>::DataArrayTuple(T *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
+ {
+ }
+
+ template<class T>
+ T DataArrayTuple<T>::zeValue() const
+ {
+ if(_nb_of_compo==1)
+ return *_pt;
+ throw INTERP_KERNEL::Exception("DataArrayTuple<T>::zeValue : DataArrayTuple instance has not exactly 1 component -> Not possible to convert it into a single value !");
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTuple<T>::buildDA(int nbOfTuples, int nbOfCompo) const
+ {
+ if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
+ {
+ typename Traits<T>::ArrayType *ret=Traits<T>::ArrayType::New();
+ ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
+ return ret;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayTuple<T>::buildDA : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
+ oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+
+ //////////////////////////////////
+
template<class T>
MCAuto< typename Traits<T>::ArrayTypeCh > DataArrayTemplate<T>::NewFromStdVector(const typename std::vector<T>& v)
{
std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- if(compoId<0 || compoId>=getNumberOfComponents())
+ if(compoId<0 || compoId>=(int)getNumberOfComponents())
{
std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
{
if(isAllocated())
{
- if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
+ if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=(int)getNumberOfComponents())
alloc(nbOfTuple,nbOfCompo);
}
else
{
DataArrayTemplate<T> *directRet(const_cast<DataArrayTemplate<T> *>(this));
directRet->incrRef();
- MCAuto<DataArrayTemplate<T> > ret(directRet);
- return DynamicCastSafe<DataArrayTemplate<T>,typename Traits<T>::ArrayTypeCh>(ret);
+ MCAuto<DataArrayTemplate<T> > ret2(directRet);
+ return DynamicCastSafe<DataArrayTemplate<T>,typename Traits<T>::ArrayTypeCh>(ret2);
}
else
{
- MCAuto<DataArray> ret(selectByTupleIdSafeSlice(a,b,c));
- return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret);
+ MCAuto<DataArray> ret2(selectByTupleIdSafeSlice(a,b,c));
+ return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret2);
}
}
const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
if(dpd)
{
MCAuto<DataArrayInt> arr(dpd->toDAI());
- MCAuto<DataArray> ret(selectByTupleIdSafe(arr->begin(),arr->end()));
- return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret);
+ MCAuto<DataArray> ret2(selectByTupleIdSafe(arr->begin(),arr->end()));
+ return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret2);
}
throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::selectPartDef : unrecognized part def !");
checkAllocated();
a->checkAllocated();
tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
+ std::size_t nbOfComp(getNumberOfComponents());
if(nbOfComp!=a->getNumberOfComponents())
throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : This and a do not have the same number of components !");
if(tuplesSelec->getNumberOfComponents()!=2)
checkAllocated();
a->checkAllocated();
tuplesSelec->checkAllocated();
- int nbOfComp(getNumberOfComponents());
+ std::size_t nbOfComp(getNumberOfComponents());
if(nbOfComp!=a->getNumberOfComponents())
throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : This and a do not have the same number of components !");
if(tuplesSelec->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : input DataArray aBase is not a DataArrayDouble !");
checkAllocated();
a->checkAllocated();
- int nbOfComp(getNumberOfComponents());
+ std::size_t nbOfComp(getNumberOfComponents());
const char msg[]="DataArrayDouble::setContigPartOfSelectedValuesSlice";
int nbOfTupleToWrite(DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg));
if(nbOfComp!=a->getNumberOfComponents())
std::reverse(work,work+nbOfCompo);
std::reverse(_info_on_compo.begin(),_info_on_compo.end());
}
+
+ /*!
+ * Assign pointer to one array to a pointer to another appay. Reference counter of
+ * \a arrayToSet is incremented / decremented.
+ * \param [in] newArray - the pointer to array to assign to \a arrayToSet.
+ * \param [in,out] arrayToSet - the pointer to array to assign to.
+ */
+ template<class T>
+ void DataArrayTemplate<T>::SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet)
+ {
+ if(newArray!=arrayToSet)
+ {
+ if(arrayToSet)
+ arrayToSet->decrRef();
+ arrayToSet=newArray;
+ if(arrayToSet)
+ arrayToSet->incrRef();
+ }
+ }
+
+ template<class T>
+ template<class U>
+ MCAuto< typename Traits<U>::ArrayType > DataArrayTemplateClassic<T>::convertToOtherTypeOfArr() const
+ {
+ this->checkAllocated();
+ MCAuto<typename Traits<U>::ArrayType> ret(Traits<U>::ArrayType::New());
+ ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents());
+ std::size_t nbOfVals(this->getNbOfElems());
+ const T *src(this->begin());
+ U *dest(ret->getPointer());
+ // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest);
+ //for(const T *src=this->begin();src!=this->end();src++,dest++)
+ // *dest=(int)*src;
+ std::copy(src,src+nbOfVals,dest);
+ ret->copyStringInfoFrom(*this);
+ return ret;
+ }
+
+ /*!
+ * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
+ * array to the new one.
+ * \return DataArrayDouble * - the new instance of DataArrayInt.
+ */
+ template<class T>
+ MCAuto<DataArrayDouble> DataArrayTemplateClassic<T>::convertToDblArr() const
+ {
+ return convertToOtherTypeOfArr<double>();
+ }
+
+ /*!
+ * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
+ * array to the new one.
+ * \return DataArrayInt * - the new instance of DataArrayInt.
+ */
+ template<class T>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::convertToIntArr() const
+ {
+ return convertToOtherTypeOfArr<int>();
+ }
+
+ /*!
+ * Creates a new DataArrayFloat and assigns all (textual and numerical) data of \a this
+ * array to the new one.
+ * \return DataArrayFloat * - the new instance of DataArrayInt.
+ */
+ template<class T>
+ MCAuto<DataArrayFloat> DataArrayTemplateClassic<T>::convertToFloatArr() const
+ {
+ return convertToOtherTypeOfArr<float>();
+ }
+
+ /*!
+ * Apply a linear function to a given component of \a this array, so that
+ * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
+ * \param [in] a - the first coefficient of the function.
+ * \param [in] b - the second coefficient of the function.
+ * \param [in] compoId - the index of component to modify.
+ * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::applyLin(T a, T b, int compoId)
+ {
+ this->checkAllocated();
+ T *ptr(this->getPointer()+compoId);
+ int nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples());
+ if(compoId<0 || compoId>=nbOfComp)
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
+ *ptr=a*(*ptr)+b;
+ this->declareAsNew();
+ }
+
+ /*!
+ * Apply a linear function to all elements of \a this array, so that
+ * an element _x_ becomes \f$ a * x + b \f$.
+ * \param [in] a - the first coefficient of the function.
+ * \param [in] b - the second coefficient of the function.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::applyLin(T a, T b)
+ {
+ this->checkAllocated();
+ T *ptr(this->getPointer());
+ std::size_t nbOfElems(this->getNbOfElems());
+ for(std::size_t i=0;i<nbOfElems;i++,ptr++)
+ *ptr=a*(*ptr)+b;
+ this->declareAsNew();
+ }
+
+ /*!
+ * Returns a full copy of \a this array except that sign of all elements is reversed.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ * same number of tuples and component as \a this array.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::negate() const
+ {
+ this->checkAllocated();
+ MCAuto<typename Traits<T>::ArrayType> newArr(Traits<T>::ArrayType::New());
+ int nbOfTuples(this->getNumberOfTuples()),nbOfComp(this->getNumberOfComponents());
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const T *cptr(this->begin());
+ std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<T>());
+ newArr->copyStringInfoFrom(*this);
+ return newArr.retn();
+ }
+
+ template<class T>
+ template<class FCT>
+ void DataArrayTemplateClassic<T>::somethingEqual(const typename Traits<T>::ArrayType *other)
+ {
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArray<T>::SomethingEqual : input DataArray<T> instance is NULL !");
+ const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
+ this->checkAllocated();
+ other->checkAllocated();
+ int nbOfTuple(this->getNumberOfTuples()),nbOfTuple2(other->getNumberOfTuples());
+ int nbOfComp(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
+ if(nbOfTuple==nbOfTuple2)
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),FCT());
+ }
+ else if(nbOfComp2==1)
+ {
+ T *ptr(this->getPointer());
+ const T *ptrc(other->begin());
+ for(int i=0;i<nbOfTuple;i++)
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(FCT(),*ptrc++));
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ else if(nbOfTuple2==1)
+ {
+ if(nbOfComp2==nbOfComp)
+ {
+ T *ptr(this->getPointer());
+ const T *ptrc(other->begin());
+ for(int i=0;i<nbOfTuple;i++)
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,FCT());
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ this->declareAsNew();
+ }
+
+ /*!
+ * Adds values of another DataArrayDouble to values of \a this one. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * \a other array is added to the corresponding value of \a this array, i.e.:
+ * _a_ [ i, j ] += _other_ [ i, j ].
+ * 2. The arrays have same number of tuples and \a other array has one component. Then
+ * _a_ [ i, j ] += _other_ [ i, 0 ].
+ * 3. The arrays have same number of components and \a other array has one tuple. Then
+ * _a_ [ i, j ] += _a2_ [ 0, j ].
+ *
+ * \param [in] other - an array to add to \a this one.
+ * \throw If \a other is NULL.
+ * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
+ * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
+ * \a other has number of both tuples and components not equal to 1.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::addEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::plus<T> >(other);
+ }
+
+ /*!
+ * Subtract values of another DataArrayDouble from values of \a this one. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * \a other array is subtracted from the corresponding value of \a this array, i.e.:
+ * _a_ [ i, j ] -= _other_ [ i, j ].
+ * 2. The arrays have same number of tuples and \a other array has one component. Then
+ * _a_ [ i, j ] -= _other_ [ i, 0 ].
+ * 3. The arrays have same number of components and \a other array has one tuple. Then
+ * _a_ [ i, j ] -= _a2_ [ 0, j ].
+ *
+ * \param [in] other - an array to subtract from \a this one.
+ * \throw If \a other is NULL.
+ * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
+ * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
+ * \a other has number of both tuples and components not equal to 1.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::substractEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::minus<T> >(other);
+ }
+
+ /*!
+ * Multiply values of another DataArrayDouble to values of \a this one. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * \a other array is multiplied to the corresponding value of \a this array, i.e.
+ * _this_ [ i, j ] *= _other_ [ i, j ].
+ * 2. The arrays have same number of tuples and \a other array has one component. Then
+ * _this_ [ i, j ] *= _other_ [ i, 0 ].
+ * 3. The arrays have same number of components and \a other array has one tuple. Then
+ * _this_ [ i, j ] *= _a2_ [ 0, j ].
+ *
+ * \param [in] other - an array to multiply to \a this one.
+ * \throw If \a other is NULL.
+ * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
+ * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
+ * \a other has number of both tuples and components not equal to 1.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::multiplyEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::multiplies<T> >(other);
+ }
+
+ /*!
+ * Divide values of \a this array by values of another DataArrayDouble. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * \a this array is divided by the corresponding value of \a other one, i.e.:
+ * _a_ [ i, j ] /= _other_ [ i, j ].
+ * 2. The arrays have same number of tuples and \a other array has one component. Then
+ * _a_ [ i, j ] /= _other_ [ i, 0 ].
+ * 3. The arrays have same number of components and \a other array has one tuple. Then
+ * _a_ [ i, j ] /= _a2_ [ 0, j ].
+ *
+ * \warning No check of division by zero is performed!
+ * \param [in] other - an array to divide \a this one by.
+ * \throw If \a other is NULL.
+ * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
+ * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
+ * \a other has number of both tuples and components not equal to 1.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::divideEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::divides<T> >(other);
+ }
+
+ template<class T, class FCT>
+ typename Traits<T>::ArrayType *DivSub(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ if(!a1 || !a2)
+ throw INTERP_KERNEL::Exception("DivSub : input DataArrayDouble instance is NULL !");
+ int nbOfTuple1(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples());
+ int nbOfComp1(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents());
+ if(nbOfTuple2==nbOfTuple1)
+ {
+ if(nbOfComp1==nbOfComp2)
+ {
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuple2,nbOfComp1);
+ std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
+ ret->copyStringInfoFrom(*a1);
+ return ret.retn();
+ }
+ else if(nbOfComp2==1)
+ {
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuple1,nbOfComp1);
+ const T *a2Ptr(a2->begin()),*a1Ptr(a1->begin());
+ T *res(ret->getPointer());
+ for(int i=0;i<nbOfTuple1;i++)
+ res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(FCT(),a2Ptr[i]));
+ ret->copyStringInfoFrom(*a1);
+ return ret.retn();
+ }
+ else
+ {
+ a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
+ return 0;
+ }
+ }
+ else if(nbOfTuple2==1)
+ {
+ a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuple1,nbOfComp1);
+ const T *a1ptr=a1->begin(),*a2ptr(a2->begin());
+ T *pt(ret->getPointer());
+ for(int i=0;i<nbOfTuple1;i++)
+ pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,FCT());
+ ret->copyStringInfoFrom(*a1);
+ return ret.retn();
+ }
+ else
+ {
+ a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
+ return 0;
+ }
+ }
+
+ /*!
+ * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
+ * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
+ * 2. The arrays have same number of tuples and one array, say _a2_, has one
+ * component. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
+ * 3. The arrays have same number of components and one array, say _a2_, has one
+ * tuple. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
+ *
+ * Info on components is copied either from the first array (in the first case) or from
+ * the array with maximal number of elements (getNbOfElems()).
+ * \param [in] a1 - an array to subtract from.
+ * \param [in] a2 - an array to subtract.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If either \a a1 or \a a2 is NULL.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
+ * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
+ * none of them has number of tuples or components equal to 1.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return DivSub< T,std::minus<T> >(a1,a2);
+ }
+
+ /*!
+ * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * the result array (_a_) is a division of the corresponding values of \a a1 and
+ * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
+ * 2. The arrays have same number of tuples and one array, say _a2_, has one
+ * component. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
+ * 3. The arrays have same number of components and one array, say _a2_, has one
+ * tuple. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
+ *
+ * Info on components is copied either from the first array (in the first case) or from
+ * the array with maximal number of elements (getNbOfElems()).
+ * \warning No check of division by zero is performed!
+ * \param [in] a1 - a numerator array.
+ * \param [in] a2 - a denominator array.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If either \a a1 or \a a2 is NULL.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
+ * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
+ * none of them has number of tuples or components equal to 1.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return DivSub< T,std::divides<T> >(a1,a2);
+ }
+
+ template<class T, class FCT>
+ typename Traits<T>::ArrayType *MulAdd(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ if(!a1 || !a2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::MulAdd : input DataArrayDouble instance is NULL !");
+ int nbOfTuple(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples());
+ int nbOfComp(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents());
+ MCAuto<typename Traits<T>::ArrayType> ret=0;
+ if(nbOfTuple==nbOfTuple2)
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ ret=Traits<T>::ArrayType::New();
+ ret->alloc(nbOfTuple,nbOfComp);
+ std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
+ ret->copyStringInfoFrom(*a1);
+ }
+ else
+ {
+ int nbOfCompMin,nbOfCompMax;
+ const typename Traits<T>::ArrayType *aMin, *aMax;
+ if(nbOfComp>nbOfComp2)
+ {
+ nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
+ aMin=a2; aMax=a1;
+ }
+ else
+ {
+ nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
+ aMin=a1; aMax=a2;
+ }
+ if(nbOfCompMin==1)
+ {
+ ret=Traits<T>::ArrayType::New();
+ ret->alloc(nbOfTuple,nbOfCompMax);
+ const T *aMinPtr(aMin->begin());
+ const T *aMaxPtr(aMax->begin());
+ T *res=ret->getPointer();
+ for(int i=0;i<nbOfTuple;i++)
+ res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(FCT(),aMinPtr[i]));
+ ret->copyStringInfoFrom(*aMax);
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !");
+ }
+ }
+ else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
+ const typename Traits<T>::ArrayType *aMin(nbOfTuple>nbOfTuple2?a2:a1);
+ const typename Traits<T>::ArrayType *aMax(nbOfTuple>nbOfTuple2?a1:a2);
+ const T *aMinPtr(aMin->begin()),*aMaxPtr(aMax->begin());
+ ret=Traits<T>::ArrayType::New();
+ ret->alloc(nbOfTupleMax,nbOfComp);
+ T *res(ret->getPointer());
+ for(int i=0;i<nbOfTupleMax;i++)
+ res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,FCT());
+ ret->copyStringInfoFrom(*aMax);
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !");
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array MulAdd !");
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * the result array (_a_) is a product of the corresponding values of \a a1 and
+ * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
+ * 2. The arrays have same number of tuples and one array, say _a2_, has one
+ * component. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
+ * 3. The arrays have same number of components and one array, say _a2_, has one
+ * tuple. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
+ *
+ * Info on components is copied either from the first array (in the first case) or from
+ * the array with maximal number of elements (getNbOfElems()).
+ * \param [in] a1 - a factor array.
+ * \param [in] a2 - another factor array.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If either \a a1 or \a a2 is NULL.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
+ * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
+ * none of them has number of tuples or components equal to 1.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return MulAdd< T , std::multiplies<T> >(a1,a2);
+ }
+
+ /*!
+ * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
+ * valid cases.
+ * 1. The arrays have same number of tuples and components. Then each value of
+ * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
+ * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
+ * 2. The arrays have same number of tuples and one array, say _a2_, has one
+ * component. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
+ * 3. The arrays have same number of components and one array, say _a2_, has one
+ * tuple. Then
+ * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
+ *
+ * Info on components is copied either from the first array (in the first case) or from
+ * the array with maximal number of elements (getNbOfElems()).
+ * \param [in] a1 - an array to sum up.
+ * \param [in] a2 - another array to sum up.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If either \a a1 or \a a2 is NULL.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
+ * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
+ * none of them has number of tuples or components equal to 1.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return MulAdd< T , std::plus<T> >(a1,a2);
+ }
+
+ /*!
+ * Returns either a \a deep or \a shallow copy of this array. For more info see
+ * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
+ * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
+ * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
+ * == \a true) or \a this instance (if \a dCpy == \a false).
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self)
+ {
+ if(dCpy)
+ return self.deepCopy();
+ else
+ {
+ self.incrRef();
+ return const_cast<typename Traits<T>::ArrayType *>(&self);
+ }
+ }
+
+ template<class T>
+ struct GreatEqual
+ {
+ GreatEqual(T v):_v(v) { }
+ bool operator()(T v) const { return v>=_v; }
+ T _v;
+ };
+
+ template<class T>
+ struct GreaterThan
+ {
+ GreaterThan(T v):_v(v) { }
+ bool operator()(T v) const { return v>_v; }
+ T _v;
+ };
+
+ template<class T>
+ struct LowerEqual
+ {
+ LowerEqual(T v):_v(v) { }
+ bool operator()(T v) const { return v<=_v; }
+ T _v;
+ };
+
+ template<class T>
+ struct LowerThan
+ {
+ LowerThan(T v):_v(v) { }
+ bool operator()(T v) const { return v<_v; }
+ T _v;
+ };
+
+ template<class T>
+ struct InRange
+ {
+ InRange(T a, T b):_a(a),_b(b) { }
+ bool operator()(T v) const { return v>=_a && v<_b; }
+ T _a,_b;
+ };
+
+template<class T>
+struct NotInRange
+{
+ NotInRange(T a, T b):_a(a),_b(b) { }
+ bool operator()(T v) const { return v<_a || v>=_b; }
+ T _a,_b;
+};
+
+ /*!
+ * This method works only on data array with one component. This method returns a newly allocated array storing stored ascendantly of tuple ids in \a this so that this[id]<0.
+ *
+ * \return a newly allocated data array that the caller should deal with.
+ * \sa DataArrayInt::findIdsInRange
+ */
+ template<class T>
+ DataArrayInt *DataArrayTemplateClassic<T>::findIdsStrictlyNegative() const
+ {
+ LowerThan<T> lt((T)0);
+ MCAuto<DataArrayInt> ret(findIdsAdv(lt));
+ return ret.retn();
+ }
+
+ template<class T>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsGreaterOrEqualTo(T val) const
+ {
+ GreatEqual<T> ge(val);
+ return findIdsAdv(ge);
+ }
+
+ template<class T>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsGreaterThan(T val) const
+ {
+ GreaterThan<T> gt(val);
+ return findIdsAdv(gt);
+ }
+
+ template<class T>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsLowerOrEqualTo(T val) const
+ {
+ LowerEqual<T> le(val);
+ return findIdsAdv(le);
+ }
+
+ template<class T>
+ MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsLowerThan(T val) const
+ {
+ LowerThan<T> lt(val);
+ return findIdsAdv(lt);
+ }
+
+ /*!
+ * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
+ * of components in the result array is a sum of the number of components of given arrays
+ * and (2) the number of tuples in the result array is same as that of each of given
+ * arrays. In other words the i-th tuple of result array includes all components of
+ * i-th tuples of all given arrays.
+ * Number of tuples in the given arrays must be the same.
+ * \param [in] a1 - an array to include in the result array.
+ * \param [in] a2 - another array to include in the result array.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If both \a a1 and \a a2 are NULL.
+ * \throw If any given array is not allocated.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Meld(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ std::vector<const typename Traits<T>::ArrayType *> arr(2);
+ arr[0]=a1; arr[1]=a2;
+ return Meld(arr);
+ }
+
+ /*!
+ * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
+ * of components in the result array is a sum of the number of components of given arrays
+ * and (2) the number of tuples in the result array is same as that of each of given
+ * arrays. In other words the i-th tuple of result array includes all components of
+ * i-th tuples of all given arrays.
+ * Number of tuples in the given arrays must be the same.
+ * \param [in] arr - a sequence of arrays to include in the result array.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If all arrays within \a arr are NULL.
+ * \throw If any given array is not allocated.
+ * \throw If getNumberOfTuples() of arrays within \a arr is different.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Meld(const std::vector<const typename Traits<T>::ArrayType *>& arr)
+ {
+ std::vector<const typename Traits<T>::ArrayType *> a;
+ for(typename std::vector<const typename Traits<T>::ArrayType *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
+ if(*it4)
+ a.push_back(*it4);
+ if(a.empty())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
+ typename std::vector<const typename Traits<T>::ArrayType *>::const_iterator it;
+ for(it=a.begin();it!=a.end();it++)
+ (*it)->checkAllocated();
+ it=a.begin();
+ int nbOfTuples((*it)->getNumberOfTuples());
+ std::vector<int> nbc(a.size());
+ std::vector<const T *> pts(a.size());
+ nbc[0]=(*it)->getNumberOfComponents();
+ pts[0]=(*it++)->getConstPointer();
+ for(int i=1;it!=a.end();it++,i++)
+ {
+ if(nbOfTuples!=(*it)->getNumberOfTuples())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
+ nbc[i]=(*it)->getNumberOfComponents();
+ pts[i]=(*it)->getConstPointer();
+ }
+ int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
+ typename Traits<T>::ArrayType *ret(Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuples,totalNbOfComp);
+ T *retPtr(ret->getPointer());
+ for(int i=0;i<nbOfTuples;i++)
+ for(int j=0;j<(int)a.size();j++)
+ {
+ retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
+ pts[j]+=nbc[j];
+ }
+ int k=0;
+ for(int i=0;i<(int)a.size();i++)
+ for(int j=0;j<nbc[i];j++,k++)
+ ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
+ return ret;
+ }
+
+ /*!
+ * Returns a new DataArrayDouble holding the same values as \a this array but differently
+ * arranged in memory. If \a this array holds 2 components of 3 values:
+ * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
+ * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
+ * \warning Do not confuse this method with transpose()!
+ * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
+ * is to delete using decrRef() as it is no more needed.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::fromNoInterlace() const
+ {
+ if(this->_mem.isNull())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
+ T *tab(this->_mem.fromNoInterlace(this->getNumberOfComponents()));
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+ ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new DataArrayDouble holding the same values as \a this array but differently
+ * arranged in memory. If \a this array holds 2 components of 3 values:
+ * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
+ * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
+ * \warning Do not confuse this method with transpose()!
+ * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
+ * is to delete using decrRef() as it is no more needed.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::toNoInterlace() const
+ {
+ if(this->_mem.isNull())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
+ T *tab(this->_mem.toNoInterlace(this->getNumberOfComponents()));
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+ ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
+ return ret.retn();
+ }
+
+ /*!
+ * Appends components of another array to components of \a this one, tuple by tuple.
+ * So that the number of tuples of \a this array remains the same and the number of
+ * components increases.
+ * \param [in] other - the DataArrayDouble to append to \a this one.
+ * \throw If \a this is not allocated.
+ * \throw If \a this and \a other arrays have different number of tuples.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
+ *
+ * \ref py_mcdataarraydouble_meldwith "Here is a Python example".
+ * \endif
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::meldWith(const typename Traits<T>::ArrayType *other)
+ {
+ this->checkAllocated();
+ other->checkAllocated();
+ int nbOfTuples(this->getNumberOfTuples());
+ if(nbOfTuples!=other->getNumberOfTuples())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
+ int nbOfComp1(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
+ T *newArr=(T *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(T));
+ T *w=newArr;
+ const T *inp1(this->begin()),*inp2(other->begin());
+ for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
+ {
+ w=std::copy(inp1,inp1+nbOfComp1,w);
+ w=std::copy(inp2,inp2+nbOfComp2,w);
+ }
+ this->useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
+ std::vector<int> compIds(nbOfComp2);
+ for(int i=0;i<nbOfComp2;i++)
+ compIds[i]=nbOfComp1+i;
+ this->copyPartOfStringInfoFrom2(compIds,*other);
+ }
+
+ /*!
+ *
+ * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
+ * \a nbTimes should be at least equal to 1.
+ * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
+ * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::duplicateEachTupleNTimes(int nbTimes) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
+ if(nbTimes<1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
+ int nbTuples(this->getNumberOfTuples());
+ const T *inPtr(this->begin());
+ MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New()); ret->alloc(nbTimes*nbTuples,1);
+ T *retPtr(ret->getPointer());
+ for(int i=0;i<nbTuples;i++,inPtr++)
+ {
+ T val(*inPtr);
+ for(int j=0;j<nbTimes;j++,retPtr++)
+ *retPtr=val;
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret.retn();
+ }
+
+ template<class T>
+ void DataArrayTemplateClassic<T>::aggregate(const typename Traits<T>::ArrayType *other)
+ {
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
+ if(this->getNumberOfComponents()!=other->getNumberOfComponents())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
+ this->_mem.insertAtTheEnd(other->begin(),other->end());
+ }
+
+ /*!
+ * Converts every value of \a this array to its absolute value.
+ * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
+ * should be called instead.
+ *
+ * \throw If \a this is not allocated.
+ * \sa DataArrayDouble::computeAbs
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::abs()
+ {
+ this->checkAllocated();
+ T *ptr(this->getPointer());
+ std::size_t nbOfElems(this->getNbOfElems());
+ std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<T,T>(std::abs));
+ this->declareAsNew();
+ }
+
+ /*!
+ * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
+ * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
+ *
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ * same number of tuples and component as \a this array.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If \a this is not allocated.
+ * \sa DataArrayDouble::abs
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::computeAbs() const
+ {
+ this->checkAllocated();
+ MCAuto<typename Traits<T>::ArrayType> newArr(Traits<T>::ArrayType::New());
+ int nbOfTuples(this->getNumberOfTuples());
+ int nbOfComp(this->getNumberOfComponents());
+ newArr->alloc(nbOfTuples,nbOfComp);
+ std::transform(this->begin(),this->end(),newArr->getPointer(),std::ptr_fun<T,T>(std::abs));
+ newArr->copyStringInfoFrom(*this);
+ return newArr.retn();
+ }
+
+ /*!
+ * Returns either a \a deep or \a shallow copy of this array. For more info see
+ * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
+ * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
+ * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
+ * == \a true) or \a this instance (if \a dCpy == \a false).
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::performCopyOrIncrRef(bool dCpy) const
+ {
+ const typename Traits<T>::ArrayType *thisC(static_cast<const typename Traits<T>::ArrayType *>(this));
+ return DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(dCpy,*thisC);
+ }
+
+ /*!
+ * Checks if all values in \a this array are equal to \a val at precision \a eps.
+ * \param [in] val - value to check equality of array values to.
+ * \param [in] eps - precision to check the equality.
+ * \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
+ * \a false else.
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ bool DataArrayTemplateFP<T>::isUniform(T val, T eps) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
+ const T *w(this->begin()),*end2(this->end());
+ const T vmin(val-eps),vmax(val+eps);
+ for(;w!=end2;w++)
+ if(*w<vmin || *w>vmax)
+ return false;
+ return true;
+ }
+
+ /*!
+ * Set all values in \a this array so that the i-th element equals to \a init + i
+ * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
+ * \param [in] init - value to assign to the first element of array.
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ void DataArrayTemplateFP<T>::iota(T init)
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
+ T *ptr(this->getPointer());
+ int ntuples(this->getNumberOfTuples());
+ for(int i=0;i<ntuples;i++)
+ ptr[i]=init+T(i);
+ this->declareAsNew();
+ }
+
+ /*!
+ * Equivalent to DataArrayInt::isEqual except that if false the reason of
+ * mismatch is given.
+ *
+ * \param [in] other the instance to be compared with \a this
+ * \param [out] reason In case of inequality returns the reason.
+ * \sa DataArrayInt::isEqual
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const
+ {
+ if(!this->areInfoEqualsIfNotWhy(other,reason))
+ return false;
+ return this->_mem.isEqual(other._mem,0,reason);
+ }
+
+ /*!
+ * Checks if \a this and another DataArrayInt are fully equal. For more info see
+ * \ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the two arrays are equal, \a false else.
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqual(const DataArrayDiscrete<T>& other) const
+ {
+ std::string tmp;
+ return isEqualIfNotWhy(other,tmp);
+ }
+
+ /*!
+ * Checks if values of \a this and another DataArrayInt are equal. For more info see
+ * \ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the values of two arrays are equal, \a false else.
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const
+ {
+ std::string tmp;
+ return this->_mem.isEqual(other._mem,0,tmp);
+ }
+
+ /*!
+ * Checks if values of \a this and another DataArrayInt are equal. Comparison is
+ * performed on sorted value sequences.
+ * For more info see\ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const
+ {
+ MCAuto<DataArrayInt> a(static_cast<const typename Traits<T>::ArrayType *>(this)->deepCopy()),b(other.deepCopy());
+ a->sort();
+ b->sort();
+ return a->isEqualWithoutConsideringStr(*b);
+ }
+
+ template<class T>
+ template<class ALG>
+ void DataArrayDiscrete<T>::switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
+ int nbOfTuples(this->getNumberOfTuples());
+ if(nbOfTuples!=(int)vec.size())
+ throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
+ const T *pt(this->begin());
+ for(int i=0;i<nbOfTuples;i++)
+ if(algo(pt[i],val))
+ vec[i]=true;
+ }
+
+ /*!
+ * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
+ * put True to the corresponding entry in \a vec.
+ * \a vec is expected to be with the same size than the number of tuples of \a this.
+ *
+ * \sa DataArrayInt::switchOnTupleNotEqualTo.
+ */
+ template<class T>
+ void DataArrayDiscrete<T>::switchOnTupleEqualTo(T val, std::vector<bool>& vec) const
+ {
+ switchOnTupleAlg(val,vec,std::equal_to<T>());
+ }
+
+ /*!
+ * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
+ * put True to the corresponding entry in \a vec.
+ * \a vec is expected to be with the same size than the number of tuples of \a this.
+ *
+ * \sa DataArrayInt::switchOnTupleEqualTo.
+ */
+ template<class T>
+ void DataArrayDiscrete<T>::switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const
+ {
+ switchOnTupleAlg(val,vec,std::not_equal_to<T>());
+ }
+
+ /*!
+ * This method compares content of input vector \a v and \a this.
+ * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
+ * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
+ *
+ * \param [in] v - the vector of 'flags' to be compared with \a this.
+ *
+ * \throw If \a this is not sorted ascendingly.
+ * \throw If \a this has not exactly one component.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ bool DataArrayDiscreteSigned<T>::isFittingWith(const std::vector<bool>& v) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
+ const T *w(this->begin()),*end2(this->end());
+ T refVal=-std::numeric_limits<T>::max();
+ int i=0;
+ std::vector<bool>::const_iterator it(v.begin());
+ for(;it!=v.end();it++,i++)
+ {
+ if(*it)
+ {
+ if(w!=end2)
+ {
+ if(*w++==i)
+ {
+ if(i>refVal)
+ refVal=i;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(this->begin(),w-1) << " this is not sorted ascendingly !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ }
+ return w==end2;
+ }
}
#endif
if(a.empty())
throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : input list must be NON EMPTY !");
std::vector<const DataArrayChar *>::const_iterator it=a.begin();
- int nbOfComp=(*it)->getNumberOfComponents();
+ std::size_t nbOfComp((*it)->getNumberOfComponents());
int nbt=(*it++)->getNumberOfTuples();
for(int i=1;it!=a.end();it++,i++)
{
--- /dev/null
+// Copyright (C) 2007-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "MEDCouplingMemArray.txx"
+
+using namespace MEDCoupling;
+
+template class MEDCoupling::MemArray<float>;
+template class MEDCoupling::DataArrayTemplate<float>;
+template class MEDCoupling::DataArrayTemplateClassic<float>;
+template class MEDCoupling::DataArrayTemplateFP<float>;
+template class MEDCoupling::DataArrayIterator<float>;
+
+DataArrayFloat *DataArrayFloat::New()
+{
+ return new DataArrayFloat;
+}
+
+DataArrayFloat *DataArrayFloat::deepCopy() const
+{
+ return new DataArrayFloat(*this);
+}
+
+void DataArrayFloat::reprStream(std::ostream& stream) const
+{
+ stream << "Name of float array : \"" << _name << "\"\n";
+ reprWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprZipStream(std::ostream& stream) const
+{
+ stream << "Name of float array : \"" << _name << "\"\n";
+ reprZipWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const
+{
+ DataArray::reprWithoutNameStream(stream);
+ stream.precision(7);
+ _mem.repr(getNumberOfComponents(),stream);
+}
+
+void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
+{
+ int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
+ const float *data(begin());
+ stream.precision(7);
+ stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
+ if(nbTuples*nbComp>=1)
+ {
+ stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
+ std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
+ stream << data[nbTuples*nbComp-1] << "};" << std::endl;
+ stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
+ }
+ else
+ stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
+ stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
+}
+
+void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
+{
+ static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
+ stream << "DataArrayFloat C++ instance at " << this << ". ";
+ if(isAllocated())
+ {
+ int nbOfCompo=(int)_info_on_compo.size();
+ if(nbOfCompo>=1)
+ {
+ int nbOfTuples=getNumberOfTuples();
+ stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
+ reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
+ }
+ else
+ stream << "Number of components : 0.";
+ }
+ else
+ stream << "*** No data allocated ****";
+}
+
+void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
+{
+ const float *data(begin());
+ int nbOfTuples(getNumberOfTuples());
+ int nbOfCompo=(int)_info_on_compo.size();
+ std::ostringstream oss2; oss2 << "[";
+ oss2.precision(7);
+ std::string oss2Str(oss2.str());
+ bool isFinished=true;
+ for(int i=0;i<nbOfTuples && isFinished;i++)
+ {
+ if(nbOfCompo>1)
+ {
+ oss2 << "(";
+ for(int j=0;j<nbOfCompo;j++,data++)
+ {
+ oss2 << *data;
+ if(j!=nbOfCompo-1) oss2 << ", ";
+ }
+ oss2 << ")";
+ }
+ else
+ oss2 << *data++;
+ if(i!=nbOfTuples-1) oss2 << ", ";
+ std::string oss3Str(oss2.str());
+ if(oss3Str.length()<maxNbOfByteInRepr)
+ oss2Str=oss3Str;
+ else
+ isFinished=false;
+ }
+ stream << oss2Str;
+ if(!isFinished)
+ stream << "... ";
+ stream << "]";
+}
+
+std::string DataArrayFloat::reprNotTooLong() const
+{
+ std::ostringstream ret;
+ reprNotTooLongStream(ret);
+ return ret.str();
+}
+
+void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const
+{
+ stream << "Name of float array : \"" << _name << "\"\n";
+ reprNotTooLongWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const
+{
+ DataArray::reprWithoutNameStream(stream);
+ stream.precision(7);
+ _mem.reprNotTooLong(getNumberOfComponents(),stream);
+}
+
+bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
+{
+ if(!areInfoEqualsIfNotWhy(other,reason))
+ return false;
+ return _mem.isEqual(other._mem,prec,reason);
+}
+
+bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
+{
+ std::string tmp;
+ return isEqualIfNotWhy(other,prec,tmp);
+}
+
+bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
+{
+ std::string tmp;
+ return _mem.isEqual(other._mem,prec,tmp);
+}
+
+DataArrayFloatIterator *DataArrayFloat::iterator()
+{
+ return new DataArrayFloatIterator(this);
+}
+
+DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator<float>(da)
+{
+}
+
+DataArrayFloatTuple::DataArrayFloatTuple(float *pt, int nbOfComp):DataArrayTuple<float>(pt,nbOfComp)
+{
+}
+
+std::string DataArrayFloatTuple::repr() const
+{
+ std::ostringstream oss; oss.precision(7); oss << "(";
+ for(int i=0;i<_nb_of_compo-1;i++)
+ oss << _pt[i] << ", ";
+ oss << _pt[_nb_of_compo-1] << ")";
+ return oss.str();
+}
+
+float DataArrayFloatTuple::floatValue() const
+{
+ return this->zeValue();
+}
+
+/*!
+ * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef.
+ * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false.
+ * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
+ * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
+ */
+DataArrayFloat *DataArrayFloatTuple::buildDAFloat(int nbOfTuples, int nbOfCompo) const
+{
+ return this->buildDA(nbOfTuples,nbOfCompo);
+}
#define __PARAMEDMEM_MEDCOUPLINGMESH_HXX__
#include "MEDCoupling.hxx"
+#include "MCType.hxx"
#include "MEDCouplingTimeLabel.hxx"
#include "MEDCouplingRefCountObject.hxx"
#include "NormalizedUnstructuredMesh.hxx"
{
}
-MEDCouplingPointSet::MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCopy):MEDCouplingMesh(other),_coords(0)
+MEDCouplingPointSet::MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCpy):MEDCouplingMesh(other),_coords(0)
{
if(other._coords)
- _coords=other._coords->performCopyOrIncrRef(deepCopy);
+ _coords=other._coords->performCopyOrIncrRef(deepCpy);
}
MEDCouplingPointSet::~MEDCouplingPointSet()
{
protected:
MEDCOUPLING_EXPORT MEDCouplingPointSet();
- MEDCOUPLING_EXPORT MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCopy);
+ MEDCOUPLING_EXPORT MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCpy);
MEDCOUPLING_EXPORT ~MEDCouplingPointSet();
public:
MEDCOUPLING_EXPORT void updateTime() const;
MEDCOUPLING_EXPORT virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes);
MEDCOUPLING_EXPORT virtual void renumberNodesCenter(const int *newNodeNumbers, int newNbOfNodes);
MEDCOUPLING_EXPORT virtual bool isEmptyMesh(const std::vector<int>& tinyInfo) const = 0;
+ MEDCOUPLING_EXPORT virtual void invertOrientationOfAllCells() = 0;
MEDCOUPLING_EXPORT virtual void checkFullyDefined() const = 0;
MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
_my_map.clear();
}
-void GlobalDict::setKeyValue(const std::string& key, const std::string& value)
+void GlobalDict::setKeyValue(const std::string& key, const std::string& val)
{
std::map<std::string, std::string>::const_iterator it(_my_map.find(key));
if(it!=_my_map.end())
oss << "GlobalDict::setKeyValue : key \"" << key << "\" already exists !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- _my_map[key]=value;
+ _my_map[key]=val;
}
-void GlobalDict::setKeyValueForce(const std::string& key, const std::string& value)
+void GlobalDict::setKeyValueForce(const std::string& key, const std::string& val)
{
- _my_map[key]=value;
+ _my_map[key]=val;
}
std::string GlobalDict::printSelf() const
MEDCOUPLING_EXPORT std::vector<std::string> keys() const;
MEDCOUPLING_EXPORT void erase(const std::string& key);
MEDCOUPLING_EXPORT void clear();
- MEDCOUPLING_EXPORT void setKeyValue(const std::string& key, const std::string& value);
- MEDCOUPLING_EXPORT void setKeyValueForce(const std::string& key, const std::string& value);
+ MEDCOUPLING_EXPORT void setKeyValue(const std::string& key, const std::string& val);
+ MEDCOUPLING_EXPORT void setKeyValueForce(const std::string& key, const std::string& val);
MEDCOUPLING_EXPORT std::string printSelf() const;
private:
GlobalDict() { }
using namespace MEDCoupling;
MEDCouplingSkyLineArray::MEDCouplingSkyLineArray():
- _index( DataArrayInt::New() ), _values( DataArrayInt::New() ), _super_index( DataArrayInt::New() )
+ _super_index( DataArrayInt::New() ), _index( DataArrayInt::New() ), _values( DataArrayInt::New() )
{
}
const int * cP(c->begin()), * cIP(cI->begin());
int prev = -1;
- if (c->getNbOfElems() != *(cI->end()-1))
+ if ((int)c->getNbOfElems() != *(cI->end()-1))
throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::BuildFromDynamicConn: misformatted connectivity (wrong nb of tuples)!");
- for (int i=0; i < cI->getNbOfElems(); i++)
+ for (std::size_t i=0; i < cI->getNbOfElems(); i++)
{
int j = cIP[i];
if (cIP[i] < prev)
superIdx.push_back(0);
idx.push_back(0);
vals.resize(c->getNbOfElems()); // too much because of the type and the -1, but still better than push_back().
- for (int i=0; i < cI->getNbOfElems()-1; i++)
+ for (std::size_t i=0; i < cI->getNbOfElems()-1; i++)
{
int start = cIP[i]+1, end = cIP[i+1];
int * work = vals.data() + cnt;
c->alloc(sz, 1);
int * cVecP(c->getPointer());
- for (int i=0; i < _super_index->getNbOfElems()-1; i++)
+ for ( std::size_t i=0; i < _super_index->getNbOfElems()-1; i++)
{
cIVecP[i]= cnt;
int endId = siP[i+1];
DataArrayInt* MEDCouplingSkyLineArray::getSuperIndexArray() const
{
- return ((MEDCouplingSkyLineArray*)this)->_super_index;
+ return const_cast<MEDCouplingSkyLineArray*>(this)->_super_index;
}
DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const
{
- return ((MEDCouplingSkyLineArray*)this)->_index;
+ return const_cast<MEDCouplingSkyLineArray*>(this)->_index;
}
DataArrayInt* MEDCouplingSkyLineArray::getValuesArray() const
{
- return ((MEDCouplingSkyLineArray*)this)->_values;
+ return const_cast<MEDCouplingSkyLineArray*>(this)->_values;
}
void MEDCouplingSkyLineArray::checkSuperIndex(const std::string& func) const
void MEDCouplingSkyLineArray::validSuperIndex(const std::string& func, int superIndex) const
{
- if(superIndex < 0 || superIndex >= _super_index->getNbOfElems())
+ if(superIndex < 0 || superIndex >= (int)_super_index->getNbOfElems())
{
std::ostringstream oss;
oss << "MEDCouplingSkyLineArray::" << func << ": invalid super index!";
void MEDCouplingSkyLineArray::validIndex(const std::string& func, int idx) const
{
- if(idx < 0 || idx >= _index->getNbOfElems())
+ if(idx < 0 || idx >= (int)_index->getNbOfElems())
{
std::ostringstream oss;
oss << "MEDCouplingSkyLineArray::" << func << ": invalid index!";
{
validSuperIndex(func, superIndex);
int idx = _super_index->begin()[superIndex] + index;
- if(idx < 0 || idx >= _index->getNbOfElems())
+ if(idx < 0 || idx >= (int)_index->getNbOfElems())
{
std::ostringstream oss;
oss << "MEDCouplingSkyLineArray::" << func << ": invalid index!";
*/
void MEDCouplingSkyLineArray::getSimplePackSafe(const int absolutePackId, std::vector<int> & pack) const
{
- if(absolutePackId < 0 || absolutePackId >= _index->getNbOfElems())
+ if(absolutePackId < 0 || absolutePackId >= (int)_index->getNbOfElems())
throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::getPackSafe: invalid index!");
const int * iP(_index->begin()), *vP(_values->begin());
int sz = iP[absolutePackId+1]-iP[absolutePackId];
*/
const int * MEDCouplingSkyLineArray::getSimplePackSafePtr(const int absolutePackId, int & packSize) const
{
- if(absolutePackId < 0 || absolutePackId >= _index->getNbOfElems())
+ if(absolutePackId < 0 || absolutePackId >= (int)_index->getNbOfElems())
throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::getPackSafe: invalid index!");
const int * iP(_index->begin()), *vP(_values->begin());
packSize = iP[absolutePackId+1]-iP[absolutePackId];
iP[ii] -= (end-start);
// _super_index
- for(int ii = superIdx+1; ii < _super_index->getNbOfElems(); ii++)
+ for(int ii = superIdx+1; ii < (int)_super_index->getNbOfElems(); ii++)
(siP[ii])--;
}
iP[ii] += sz;
// _super_index
- for(int ii = superIdx+1; ii < _super_index->getNbOfElems(); ii++)
+ for(int ii = superIdx+1; ii < (int)_super_index->getNbOfElems(); ii++)
(siP[ii])++;
}
copy(packBg, packEnd, _values->getPointer()+start);
// _index
- for(int ii = idx+1; ii < _index->getNbOfElems(); ii++)
+ for(int ii = idx+1; ii < (int)_index->getNbOfElems(); ii++)
iP[ii] += deltaSz;
}
copy(packBg, packEnd, _values->getPointer()+start);
// _index
- for(int ii = siP[superIdx]+idx+1; ii < _index->getNbOfElems(); ii++)
+ for(int ii = siP[superIdx]+idx+1; ii < (int)_index->getNbOfElems(); ii++)
iP[ii] += deltaSz;
}
{
}
-MEDCouplingStructuredMesh::MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCopy):MEDCouplingMesh(other)
+MEDCouplingStructuredMesh::MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy):MEDCouplingMesh(other)
{
}
conn->alloc(4*n1*n2,1);
int *cp(conn->getPointer());
std::size_t pos(0);
- for(int j=0;j<n2;j++)
- for(int i=0;i<n1;i++,pos++)
+ for(std::size_t j=0;j<n2;j++)
+ for(std::size_t i=0;i<n1;i++,pos++)
{
cp[4*pos+0]=i+1+j*(n1+1);
cp[4*pos+1]=i+j*(n1+1);
conn->alloc(8*n1*n2*n3,1);
int *cp(conn->getPointer());
std::size_t pos(0);
- for(int k=0;k<n3;k++)
- for(int j=0;j<n2;j++)
- for(int i=0;i<n1;i++,pos++)
+ for(std::size_t k=0;k<n3;k++)
+ for(std::size_t j=0;j<n2;j++)
+ for(std::size_t i=0;i<n1;i++,pos++)
{
int tmp=(n1+1)*(n2+1);
cp[8*pos+0]=i+1+j*(n1+1)+k*tmp;
static int ZipNodeStructure(const int *nodeStBg, const int *nodeStEnd, int zipNodeSt[3]);
protected:
MEDCOUPLING_EXPORT MEDCouplingStructuredMesh();
- MEDCOUPLING_EXPORT MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCopy);
+ MEDCOUPLING_EXPORT MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy);
MEDCOUPLING_EXPORT ~MEDCouplingStructuredMesh();
};
}
using namespace MEDCoupling;
template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<double>;
+template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<float>;
+template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<float>;
template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<int>;
-
-const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label.";
+template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<int>;
const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
return ret;
}
-void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
-{
- if(_array)
- {
- tinyInfo.push_back(_array->getNumberOfTuples());
- tinyInfo.push_back(_array->getNumberOfComponents());
- }
- else
- {
- tinyInfo.push_back(-1);
- tinyInfo.push_back(-1);
- }
-}
-
-void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
-{
- arrays.resize(1);
- if(_array!=0)
- _array->decrRef();
- DataArrayDouble *arr=0;
- if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
- {
- arr=DataArrayDouble::New();
- arr->alloc(tinyInfoI[0],tinyInfoI[1]);
- }
- _array=arr;
- arrays[0]=arr;
-}
-
-void MEDCouplingTimeDiscretization::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
-{
- static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
- if(arrays.size()!=1)
- throw INTERP_KERNEL::Exception(MSG);
- if(_array!=0)
- _array->decrRef();
- _array=0;
- if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
- {
- if(!arrays[0])
- throw INTERP_KERNEL::Exception(MSG);
- arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
- _array=arrays[0];
- _array->incrRef();
- }
-}
-
-void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
-{
- _time_tolerance=tinyInfoD[0];
- int nbOfCompo=_array->getNumberOfComponents();
- for(int i=0;i<nbOfCompo;i++)
- _array->setInfoOnComponent(i,tinyInfoS[i]);
-}
-
-void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
-{
- tinyInfo.push_back(_time_tolerance);
-}
-
-void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
-{
- int nbOfCompo=_array->getNumberOfComponents();
- for(int i=0;i<nbOfCompo;i++)
- tinyInfo.push_back(_array->getInfoOnComponent(i));
-}
-
bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const
{
int iteration,order;
////////////////////////
-MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt()
-{
-}
-
-MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<int>(other,deepCopy),_tk(other._tk)
-{
-}
-
-std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const
+MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<int>(other,deepCopy)
{
- std::ostringstream stream;
- stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
- stream << "\nTime unit is : \"" << _time_unit << "\"";
- return stream.str();
}
MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
return _array->isEqualWithoutConsideringStr(*(other->getArray()));
}
-double MEDCouplingTimeDiscretizationInt::getEndTime(int& iteration, int& order) const
+////////////////////////
+
+MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<float>(other,deepCopy)
{
- throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
}
-void MEDCouplingTimeDiscretizationInt::setEndIteration(int it)
+MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const
{
- throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
+ return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy);
}
-void MEDCouplingTimeDiscretizationInt::setEndOrder(int order)
+MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type)
{
- throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
+ switch(type)
+ {
+ case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION:
+ return new MEDCouplingTimeDiscretizationFloat;
+ default:
+ throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !");
+ }
}
-void MEDCouplingTimeDiscretizationInt::setEndTimeValue(double time)
+bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const
{
- throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
+ if(prec!=0)
+ throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !");
+ if(!other)
+ {
+ reason="Time discretization is NULL.";
+ return false;
+ }
+ const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !");
+ if(!MEDCouplingTimeDiscretizationTemplate<float>::areStrictlyCompatible(other,reason))
+ return false;
+ if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
+ return false;
+ if(_array==other->getArray())
+ return true;
+ return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
}
-void MEDCouplingTimeDiscretizationInt::setEndTime(double time, int iteration, int order)
+bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const
{
- throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
+ if(prec!=0)
+ throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !");
+ const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !");
+ std::string tmp;
+ if(!areStrictlyCompatible(other,tmp))
+ return false;
+ std::string reason;
+ if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
+ return false;
+ if(_array==other->getArray())
+ return true;
+ return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec);
}
////////////////////////
{
std::ostringstream stream;
stream << REPR;
- stream << "\nTime unit is : \"" << _time_unit << "\"";
+ stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
return stream.str();
}
{
std::ostringstream stream;
stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
- stream << "\nTime unit is : \"" << _time_unit << "\"";
+ stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
return stream.str();
}
int it=-1,order=-1;
double val=mesh->getTime(it,order);
_tk.setAllInfo(val,it,order);
- std::string tUnit=mesh->getTimeUnit();
- _time_unit=tUnit;
+ std::string tUnit(mesh->getTimeUnit());
+ setTimeUnit(tUnit);
}
void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
std::ostringstream stream;
stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
- stream << "\nTime unit is : \"" << _time_unit << "\"";
+ stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
return stream.str();
}
_start.setAllInfo(val,it,order);
_end.setAllInfo(val,it,order);
std::string tUnit(mesh->getTimeUnit());
- _time_unit=tUnit;
+ setTimeUnit(tUnit);
}
MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
double val=mesh->getTime(it,order);
_start.setAllInfo(val,it,order);
_end.setAllInfo(val,it,order);
- std::string tUnit=mesh->getTimeUnit();
- _time_unit=tUnit;
+ std::string tUnit(mesh->getTimeUnit());
+ setTimeUnit(tUnit);
}
std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
std::ostringstream stream;
stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
- stream << "Time unit is : \"" << _time_unit << "\"";
+ stream << "Time unit is : \"" << getTimeUnit() << "\"";
return stream.str();
}
class DataArrayDouble;
class TimeLabel;
+ class TimeHolder
+ {
+ public:
+ MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_unit; }
+ MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_unit=unit; }
+ MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return getStartTime(iteration,order); }
+ MEDCOUPLING_EXPORT virtual double getStartTime(int& iteration, int& order) const = 0;
+ void copyTinyAttrFrom(const TimeHolder& other) { _time_unit=other._time_unit; }
+ protected:
+ TimeHolder() { }
+ TimeHolder(const TimeHolder& other):_time_unit(other._time_unit) { }
+ virtual ~TimeHolder() { }
+ private:
+ std::string _time_unit;
+ };
+
template<class T>
- class MEDCouplingTimeDiscretizationTemplate : public TimeLabel, public BigMemoryObject
+ class MEDCouplingTimeDiscretizationTemplate : public TimeLabel, public BigMemoryObject, public TimeHolder
{
public:
MEDCOUPLING_EXPORT void updateTime() const;
MEDCOUPLING_EXPORT virtual void setArray(typename Traits<T>::ArrayType *array, TimeLabel *owner);
MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *getArray() { return _array; }
MEDCOUPLING_EXPORT const typename Traits<T>::ArrayType *getArray() const { return _array; }
- MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_unit=unit; }
- MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_unit; }
MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_tolerance=val; }
MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_tolerance; }
- MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return getStartTime(iteration,order); }
MEDCOUPLING_EXPORT void setTime(double time, int iteration, int order) { setStartTime(time,iteration,order); }
MEDCOUPLING_EXPORT void setIteration(int it) { setStartIteration(it); }
MEDCOUPLING_EXPORT void setOrder(int order) { setStartOrder(order); }
MEDCOUPLING_EXPORT void setTimeValue(double val) { setStartTimeValue(val); }
- MEDCOUPLING_EXPORT virtual double getStartTime(int& iteration, int& order) const = 0;
MEDCOUPLING_EXPORT virtual void setStartIteration(int it) = 0;
MEDCOUPLING_EXPORT virtual void setStartOrder(int order) = 0;
MEDCOUPLING_EXPORT virtual void setStartTime(double time, int iteration, int order) = 0;
MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<T> *other) const;
MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<T> *other) const;
MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretizationTemplate();
+ MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ MEDCOUPLING_EXPORT virtual void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ MEDCOUPLING_EXPORT virtual void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<typename Traits<T>::ArrayType *>& arrays);
+ MEDCOUPLING_EXPORT virtual void checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<typename Traits<T>::ArrayType *>& arrays);
+ MEDCOUPLING_EXPORT virtual void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
protected:
MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate();
MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy);
protected:
- std::string _time_unit;
double _time_tolerance;
typename Traits<T>::ArrayType *_array;
protected:
MEDCOUPLING_EXPORT virtual void divideEqual(const MEDCouplingTimeDiscretization *other) = 0;
MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const = 0;
MEDCOUPLING_EXPORT virtual void powEqual(const MEDCouplingTimeDiscretization *other) = 0;
- MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
- MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
- MEDCOUPLING_EXPORT virtual void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
- MEDCOUPLING_EXPORT virtual void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
- MEDCOUPLING_EXPORT virtual void checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays);
- MEDCOUPLING_EXPORT virtual void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const = 0;
MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const = 0;
MEDCOUPLING_EXPORT virtual void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD) = 0;
MEDCOUPLING_EXPORT virtual void fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func);
MEDCOUPLING_EXPORT virtual void fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func);
};
-
- class MEDCouplingTimeDiscretizationInt : public MEDCouplingTimeDiscretizationTemplate<int>
+
+ template<class T>
+ class MEDCouplingTimeDiscretizationSimple : public MEDCouplingTimeDiscretizationTemplate<T>
{
public:
- MEDCouplingTimeDiscretizationInt();
- MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy);
- static MEDCouplingTimeDiscretizationInt *New(TypeOfTimeDiscretization type);
+ std::string getStringRepr() const;
double getStartTime(int& iteration, int& order) const { return _tk.getAllInfo(iteration,order); }
void setStartIteration(int it) { _tk.setIteration(it); }
void setStartOrder(int order) { _tk.setOrder(order); }
void setEndOrder(int order);
void setEndTimeValue(double time);
void setEndTime(double time, int iteration, int order);
- std::string getStringRepr() const;
TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; }
+ protected:
+ MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy);
+ MEDCouplingTimeDiscretizationSimple() { }
+ protected:
+ MEDCouplingTimeKeeper _tk;
+ private:
+ MEDCOUPLING_EXPORT static const char REPR[];
+ protected:
+ static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME;
+ };
+
+ class MEDCouplingTimeDiscretizationInt : public MEDCouplingTimeDiscretizationSimple<int>
+ {
+ public:
+ MEDCouplingTimeDiscretizationInt() { }
+ MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy);
+ static MEDCouplingTimeDiscretizationInt *New(TypeOfTimeDiscretization type);
MEDCouplingTimeDiscretizationInt *performCopyOrIncrRef(bool deepCopy) const;
bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec, std::string& reason) const;
bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec) const;
+ };
+
+ class MEDCouplingTimeDiscretizationFloat : public MEDCouplingTimeDiscretizationSimple<float>
+ {
+ public:
+ MEDCouplingTimeDiscretizationFloat() { }
+ MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy);
+ static MEDCouplingTimeDiscretizationFloat *New(TypeOfTimeDiscretization type);
+ MEDCouplingTimeDiscretizationFloat *performCopyOrIncrRef(bool deepCopy) const;
+ bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const;
+ bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const;
private:
static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME;
- MEDCOUPLING_EXPORT static const char REPR[];
- protected:
- MEDCouplingTimeKeeper _tk;
};
class MEDCouplingNoTimeLabel : public MEDCouplingTimeDiscretization
#define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
#include "MEDCouplingTimeDiscretization.hxx"
+#include "MEDCouplingMemArray.txx"
#include <cmath>
#include <sstream>
namespace MEDCoupling
{
+ template<class T>
+ const char MEDCouplingTimeDiscretizationSimple<T>::REPR[]="One time label.";
+
template<class T>
const double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
template<class T>
void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
{
+ TimeHolder::copyTinyAttrFrom(other);
_time_tolerance=other._time_tolerance;
- _time_unit=other._time_unit;
}
template<class T>
void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
{
- _time_unit=other._time_unit;
+ TimeHolder::copyTinyAttrFrom(other);
if(_array && other._array)
_array->copyStringInfoFrom(*other._array);
}
template<class T>
std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
{
- return _time_unit.capacity();
+ return getTimeUnit().capacity();
}
template<class T>
bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
{
std::ostringstream oss; oss.precision(15);
- if(_time_unit!=other->_time_unit)
+ if(getTimeUnit()!=other->getTimeUnit())
{
- oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
+ oss << "Field discretizations differ : this time unit = \"" << getTimeUnit() << "\" and other time unit = \"" << other->getTimeUnit() << "\" !";
reason=oss.str();
return false;
}
}
template<class T>
- MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
+ MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):TimeHolder(other),_time_tolerance(other._time_tolerance)
{
if(other._array)
_array=other._array->performCopyOrIncrRef(deepCopy);
arrays.resize(1);
arrays[0]=_array;
}
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+ {
+ if(_array)
+ {
+ tinyInfo.push_back(_array->getNumberOfTuples());
+ tinyInfo.push_back(_array->getNumberOfComponents());
+ }
+ else
+ {
+ tinyInfo.push_back(-1);
+ tinyInfo.push_back(-1);
+ }
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
+ {
+ tinyInfo.push_back(_time_tolerance);
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
+ {
+ int nbOfCompo(_array->getNumberOfComponents());
+ for(int i=0;i<nbOfCompo;i++)
+ tinyInfo.push_back(_array->getInfoOnComponent(i));
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ arrays.resize(1);
+ if(_array!=0)
+ _array->decrRef();
+ typename Traits<T>::ArrayType *arr=0;
+ if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
+ {
+ arr=Traits<T>::ArrayType::New();
+ arr->alloc(tinyInfoI[0],tinyInfoI[1]);
+ }
+ _array=arr;
+ arrays[0]=arr;
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
+ if(arrays.size()!=1)
+ throw INTERP_KERNEL::Exception(MSG);
+ if(_array!=0)
+ _array->decrRef();
+ _array=0;
+ if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
+ {
+ if(!arrays[0])
+ throw INTERP_KERNEL::Exception(MSG);
+ arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
+ _array=arrays[0];
+ _array->incrRef();
+ }
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+ {
+ _time_tolerance=tinyInfoD[0];
+ int nbOfCompo=_array->getNumberOfComponents();
+ for(int i=0;i<nbOfCompo;i++)
+ _array->setInfoOnComponent(i,tinyInfoS[i]);
+ }
+
+ /////////////////////////
+
+ template<class T>
+ std::string MEDCouplingTimeDiscretizationSimple<T>::getStringRepr() const
+ {
+ std::ostringstream stream;
+ stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
+ stream << "\nTime unit is : \"" << this->getTimeUnit() << "\"";
+ return stream.str();
+ }
+
+ template<class T>
+ double MEDCouplingTimeDiscretizationSimple<T>::getEndTime(int& iteration, int& order) const
+ {
+ throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndIteration(int it)
+ {
+ throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndOrder(int order)
+ {
+ throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndTimeValue(double time)
+ {
+ throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndTime(double time, int iteration, int order)
+ {
+ throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ MEDCouplingTimeDiscretizationSimple<T>::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<T>(other,deepCopy),_tk(other._tk)
+ {
+ }
}
#endif
const char Traits<double>::FieldTypeName[]="MEDCouplingFieldDouble";
+const char Traits<double>::NPYStr[]="FLOAT64";
+
+const char Traits<float>::ArrayTypeName[]="DataArrayFloat";
+
+const char Traits<float>::FieldTypeName[]="MEDCouplingFieldFloat";
+
+const char Traits<float>::NPYStr[]="FLOAT32";
+
const char Traits<int>::ArrayTypeName[]="DataArrayInt";
const char Traits<int>::FieldTypeName[]="MEDCouplingFieldInt";
const char Traits<char>::ArrayTypeName[]="DataArrayChar";
+
+const char Traits<Int64>::ArrayTypeName[]="DataArrayInt64";
+
+const char Traits<Int64>::FieldTypeName[]="MEDCouplingFieldInt64";
+
+const char Traits<Int64>::NPYStr[]="INT64";
#define __MEDCOUPLINGTRAITS_HXX__
#include "MEDCoupling.hxx"
+#include "MCType.hxx"
namespace MEDCoupling
{
typedef T EltType;
};
- class DataArrayInt;
+ class DataArrayInt32;
+ class DataArrayFloat;
class DataArrayDouble;
class DataArrayChar;
class DataArrayByte;
+ class DataArrayInt64;
class MEDCouplingFieldDouble;
+ class MEDCouplingFieldFloat;
class MEDCouplingFieldInt;
+ class DataArrayInt32Tuple;
+ class DataArrayFloatTuple;
+ class DataArrayDoubleTuple;
template<>
struct MEDCOUPLING_EXPORT Traits<double>
{
static const char ArrayTypeName[];
static const char FieldTypeName[];
+ static const char NPYStr[];
typedef DataArrayDouble ArrayType;
typedef DataArrayDouble ArrayTypeCh;
typedef MEDCouplingFieldDouble FieldType;
+ typedef DataArrayDoubleTuple ArrayTuple;
+ };
+
+ template<>
+ struct MEDCOUPLING_EXPORT Traits<float>
+ {
+ static const char ArrayTypeName[];
+ static const char FieldTypeName[];
+ static const char NPYStr[];
+ typedef DataArrayFloat ArrayType;
+ typedef DataArrayFloat ArrayTypeCh;
+ typedef MEDCouplingFieldFloat FieldType;
+ typedef DataArrayFloatTuple ArrayTuple;
};
template<>
- struct MEDCOUPLING_EXPORT Traits<int>
+ struct MEDCOUPLING_EXPORT Traits<Int32>
{
static const char ArrayTypeName[];
static const char FieldTypeName[];
- typedef DataArrayInt ArrayType;
- typedef DataArrayInt ArrayTypeCh;
+ typedef DataArrayInt32 ArrayType;
+ typedef DataArrayInt32 ArrayTypeCh;
typedef MEDCouplingFieldInt FieldType;
+ typedef DataArrayInt32Tuple ArrayTuple;
+ };
+
+ template<>
+ struct MEDCOUPLING_EXPORT Traits<Int64>
+ {
+ static const char ArrayTypeName[];
+ static const char FieldTypeName[];
+ static const char NPYStr[];
+ typedef DataArrayInt64 ArrayType;
+ typedef DataArrayInt64 ArrayTypeCh;
+ //typedef MEDCouplingFieldInt64 FieldType;
+ //typedef DataArrayInt64Tuple ArrayTuple;
};
template<>
#include "InterpKernelGeo2DEdgeLin.hxx"
#include "InterpKernelGeo2DEdgeArcCircle.hxx"
#include "InterpKernelGeo2DQuadraticPolygon.hxx"
+#include "OrientationInverter.hxx"
#include "MEDCouplingUMesh_internal.hxx"
#include <sstream>
void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
{
checkFullyDefined();
- int nbOfNodes=getNumberOfNodes();
+ int nbOfNodes(getNumberOfNodes());
int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
- const int *conn=_nodal_connec->getConstPointer();
- const int *connIndex=_nodal_connec_index->getConstPointer();
- int nbOfCells=getNumberOfCells();
- int nbOfEltsInRevNodal=0;
+ const int *conn(_nodal_connec->begin()),*connIndex(_nodal_connec_index->begin());
+ int nbOfCells(getNumberOfCells()),nbOfEltsInRevNodal(0);
for(int eltId=0;eltId<nbOfCells;eltId++)
{
- const int *strtNdlConnOfCurCell=conn+connIndex[eltId]+1;
- const int *endNdlConnOfCurCell=conn+connIndex[eltId+1];
+ const int *strtNdlConnOfCurCell(conn+connIndex[eltId]+1),*endNdlConnOfCurCell(conn+connIndex[eltId+1]);
for(const int *iter=strtNdlConnOfCurCell;iter!=endNdlConnOfCurCell;iter++)
if(*iter>=0)//for polyhedrons
{
{
if(!desc || !descIndx || !revDesc || !revDescIndx)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ComputeNeighborsOfCellsAdv some input array is empty !");
- const int *descPtr=desc->getConstPointer();
- const int *descIPtr=descIndx->getConstPointer();
- const int *revDescPtr=revDesc->getConstPointer();
- const int *revDescIPtr=revDescIndx->getConstPointer();
+ const int *descPtr=desc->begin();
+ const int *descIPtr=descIndx->begin();
+ const int *revDescPtr=revDesc->begin();
+ const int *revDescIPtr=revDescIndx->begin();
//
int nbCells=descIndx->getNumberOfTuples()-1;
MCAuto<DataArrayInt> out0=DataArrayInt::New();
neighborsIndx=out1.retn();
}
+/*!
+ * Explodes \a this into edges whatever its dimension.
+ */
+MCAuto<MEDCouplingUMesh> MEDCouplingUMesh::explodeIntoEdges(MCAuto<DataArrayInt>& desc, MCAuto<DataArrayInt>& descIndex, MCAuto<DataArrayInt>& revDesc, MCAuto<DataArrayInt>& revDescIndx) const
+{
+ checkFullyDefined();
+ int mdim(getMeshDimension());
+ desc=DataArrayInt::New(); descIndex=DataArrayInt::New(); revDesc=DataArrayInt::New(); revDescIndx=DataArrayInt::New();
+ MCAuto<MEDCouplingUMesh> mesh1D;
+ switch(mdim)
+ {
+ case 3:
+ {
+ mesh1D=explode3DMeshTo1D(desc,descIndex,revDesc,revDescIndx);
+ break;
+ }
+ case 2:
+ {
+ mesh1D=buildDescendingConnectivity(desc,descIndex,revDesc,revDescIndx);
+ break;
+ }
+ default:
+ {
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::computeNeighborsOfNodes : Mesh dimension supported are [3,2] !");
+ }
+ }
+ return mesh1D;
+}
+
/*!
* \b WARNING this method do the assumption that connectivity lies on the coordinates set.
* For speed reasons no check of this will be done. This method calls
* The number of tuples is equal to the last values in \b neighborsIndx.
* \param [out] neighborsIdx is an array of size this->getNumberOfCells()+1 newly allocated and should
* be dealt by the caller. This arrays allow to use the first output parameter \b neighbors.
+ *
+ * \sa MEDCouplingUMesh::computeEnlargedNeighborsOfNodes
*/
void MEDCouplingUMesh::computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const
{
checkFullyDefined();
int mdim(getMeshDimension()),nbNodes(getNumberOfNodes());
MCAuto<DataArrayInt> desc(DataArrayInt::New()),descIndx(DataArrayInt::New()),revDesc(DataArrayInt::New()),revDescIndx(DataArrayInt::New());
- MCAuto<MEDCouplingUMesh> mesh1D;
+ MCConstAuto<MEDCouplingUMesh> mesh1D;
switch(mdim)
{
case 3:
}
case 1:
{
- mesh1D=const_cast<MEDCouplingUMesh *>(this);
- mesh1D->incrRef();
+ mesh1D.takeRef(this);
break;
}
default:
neighborsIdx=descIndx.retn();
}
+/*!
+ * Computes enlarged neighbors for each nodes in \a this. The behavior of this method is close to MEDCouplingUMesh::computeNeighborsOfNodes except that the neighborhood of each node is wider here.
+ * A node j is considered to be in the neighborhood of i if and only if there is a cell in \a this containing in its nodal connectivity both i and j.
+ * This method is useful to find ghost cells of a part of a mesh with a code based on fields on nodes.
+ *
+ * \sa MEDCouplingUMesh::computeNeighborsOfNodes
+ */
+void MEDCouplingUMesh::computeEnlargedNeighborsOfNodes(MCAuto<DataArrayInt> &neighbors, MCAuto<DataArrayInt>& neighborsIdx) const
+{
+ checkFullyDefined();
+ int nbOfNodes(getNumberOfNodes());
+ const int *conn(_nodal_connec->begin()),*connIndex(_nodal_connec_index->begin());
+ int nbOfCells(getNumberOfCells());
+ std::vector< std::set<int> > st0(nbOfNodes);
+ for(int eltId=0;eltId<nbOfCells;eltId++)
+ {
+ const int *strtNdlConnOfCurCell(conn+connIndex[eltId]+1),*endNdlConnOfCurCell(conn+connIndex[eltId+1]);
+ std::set<int> s(strtNdlConnOfCurCell,endNdlConnOfCurCell); s.erase(-1); //for polyhedrons
+ for(std::set<int>::const_iterator iter2=s.begin();iter2!=s.end();iter2++)
+ st0[*iter2].insert(s.begin(),s.end());
+ }
+ neighborsIdx=DataArrayInt::New(); neighborsIdx->alloc(nbOfNodes+1,1); neighborsIdx->setIJ(0,0,0);
+ {
+ int *neighIdx(neighborsIdx->getPointer());
+ for(std::vector< std::set<int> >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++)
+ neighIdx[1]=neighIdx[0]+(*it).size()-1;
+ }
+ neighbors=DataArrayInt::New(); neighbors->alloc(neighborsIdx->back(),1);
+ {
+ const int *neighIdx(neighborsIdx->begin());
+ int *neigh(neighbors->getPointer()),nodeId(0);
+ for(std::vector< std::set<int> >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++,nodeId++)
+ {
+ std::set<int> s(*it); s.erase(nodeId);
+ std::copy(s.begin(),s.end(),neigh+*neighIdx);
+ }
+ }
+}
+
/*!
* Converts specified cells to either polygons (if \a this is a 2D mesh) or
* polyhedrons (if \a this is a 3D mesh). The cells to convert are specified by an
int nbOfCells(getNumberOfCells());
if(dim==2)
{
- const int *connIndex=_nodal_connec_index->getConstPointer();
+ const int *connIndex=_nodal_connec_index->begin();
int *conn=_nodal_connec->getPointer();
for(const int *iter=cellIdsToConvertBg;iter!=cellIdsToConvertEnd;iter++)
{
DAInt neighIInit00(tmp11);
// Neighbor information of the mesh WITH the crack (some neighbors are removed):
DataArrayInt *idsTmp=0;
- bool b=m01->areCellsIncludedIn(&otherDimM1OnSameCoords,2,idsTmp);
+ m01->areCellsIncludedIn(&otherDimM1OnSameCoords,2,idsTmp);
DAInt ids(idsTmp);
// In the neighbor information remove the connection between high dimension cells and its low level constituents which are part
// of the frontier given in parameter (i.e. the cells of low dimension from the group delimiting the crack):
* Copy constructor. If 'deepCopy' is false \a this is a shallow copy of other.
* If 'deeCpy' is true all arrays (coordinates and connectivities) are deeply copied.
*/
-MEDCouplingUMesh::MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCopy):MEDCouplingPointSet(other,deepCopy),_mesh_dim(other._mesh_dim),
+MEDCouplingUMesh::MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy):MEDCouplingPointSet(other,deepCpy),_mesh_dim(other._mesh_dim),
_nodal_connec(0),_nodal_connec_index(0),
_types(other._types)
{
if(other._nodal_connec)
- _nodal_connec=other._nodal_connec->performCopyOrIncrRef(deepCopy);
+ _nodal_connec=other._nodal_connec->performCopyOrIncrRef(deepCpy);
if(other._nodal_connec_index)
- _nodal_connec_index=other._nodal_connec_index->performCopyOrIncrRef(deepCopy);
+ _nodal_connec_index=other._nodal_connec_index->performCopyOrIncrRef(deepCpy);
}
MEDCouplingUMesh::~MEDCouplingUMesh()
std::vector<std::vector<int> > res;
buildSubCellsFromCut(cut3DSurf,desc2->begin(),descIndx2->begin(),mDesc1->getCoords()->begin(),eps,res);
std::size_t sz(res.size());
- if(res.size()==mDesc1->getNumberOfCells() && sameNbNodes)
+ if((int)res.size()==mDesc1->getNumberOfCells() && sameNbNodes)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::clipSingle3DCellByPlane : cell is not clipped !");
for(std::size_t i=0;i<sz;i++)
{
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoints works only for spaceDim=meshDim+1 !");
if(meshDim!=2 && meshDim!=1)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoints : only mesh dimension 2 and 1 are implemented !");
- if(pts->getNumberOfComponents()!=spaceDim)
+ if((int)pts->getNumberOfComponents()!=spaceDim)
{
std::ostringstream oss; oss << "MEDCouplingUMesh::distanceToPoints : input pts DataArrayDouble has " << pts->getNumberOfComponents() << " components whereas it should be equal to " << spaceDim << " (mesh spaceDimension) !";
throw INTERP_KERNEL::Exception(oss.str());
updateTime();
}
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCouplingUMesh::invertOrientationOfAllCells()
+{
+ checkConnectivityFullyDefined();
+ std::set<INTERP_KERNEL::NormalizedCellType> gts(getAllGeoTypes());
+ int *conn(_nodal_connec->getPointer());
+ const int *conni(_nodal_connec_index->begin());
+ for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator gt=gts.begin();gt!=gts.end();gt++)
+ {
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(*gt));
+ MCAuto<DataArrayInt> cwt(giveCellsWithType(*gt));
+ for(const int *it=cwt->begin();it!=cwt->end();it++)
+ oi->operate(conn+conni[*it]+1,conn+conni[*it+1]);
+ }
+ updateTime();
+}
+
/*!
* Finds and fixes incorrectly oriented linear extruded volumes (INTERP_KERNEL::NORM_HEXA8,
* INTERP_KERNEL::NORM_PENTA6, INTERP_KERNEL::NORM_HEXGP12 etc) to respect the MED convention
MEDCOUPLING_EXPORT bool areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const;
MEDCOUPLING_EXPORT bool areCellsIncludedInPolicy7(const MEDCouplingUMesh *other, DataArrayInt *& arr) const;
MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
+ MEDCOUPLING_EXPORT MCAuto<MEDCouplingUMesh> explodeIntoEdges(MCAuto<DataArrayInt>& desc, MCAuto<DataArrayInt>& descIndex, MCAuto<DataArrayInt>& revDesc, MCAuto<DataArrayInt>& revDescIndx) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *explode3DMeshTo1D(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
MEDCOUPLING_EXPORT static void ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI,
DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx);
MEDCOUPLING_EXPORT void computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const;
+ MEDCOUPLING_EXPORT void computeEnlargedNeighborsOfNodes(MCAuto<DataArrayInt> &neighbors, MCAuto<DataArrayInt>& neighborsIdx) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *buildPartOfMySelf(const int *begin, const int *end, bool keepCoords=true) const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *buildPartOfMySelfSlice(int start, int end, int step, bool keepCoords=true) const;
MEDCOUPLING_EXPORT void changeOrientationOfCells();
MEDCOUPLING_EXPORT void arePolyhedronsNotCorrectlyOriented(std::vector<int>& cells) const;
MEDCOUPLING_EXPORT void orientCorrectlyPolyhedrons();
+ MEDCOUPLING_EXPORT void invertOrientationOfAllCells();
MEDCOUPLING_EXPORT void getFastAveragePlaneOfThis(double *vec, double *pos) const;
//Mesh quality
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getEdgeRatioField() const;
private: // all private methods are impl in MEDCouplingUMesh_internal.cxx
MEDCouplingUMesh();
- MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCopy);
+ MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy);
~MEDCouplingUMesh();
void checkFullyDefined() const;
void checkConnectivityFullyDefined() const;
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSubCellsFromCut works only with single cell presently !");
for(int i=0;i<nbOfCells;i++)
{
- int offset(descIndx[i]),nbOfFaces(descIndx[i+1]-offset),start(-1),end(-1);
+ int offset(descIndx[i]),nbOfFaces(descIndx[i+1]-offset);
for(int j=0;j<nbOfFaces;j++)
{
const std::pair<int,int>& p=cut3DSurf[desc[offset+j]];
MCAuto<MEDCouplingUMesh> ret2D(MEDCouplingUMesh::MergeUMeshesOnSameCoords(tmp));
// To finish - filter ret3 - std::numeric_limits<int>::max() -> -1 - negate values must be resolved.
ret3->rearrange(1);
- MCAuto<DataArrayInt> edgesToDealWith(ret3->findIdsStricltyNegative());
+ MCAuto<DataArrayInt> edgesToDealWith(ret3->findIdsStrictlyNegative());
for(const int *it=edgesToDealWith->begin();it!=edgesToDealWith->end();it++)
{
int old2DCellId(-ret3->getIJ(*it,0)-1);
if(_types.size() != 1 || *(_types.begin()) != INTERP_KERNEL::NORM_POLYHED)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::conformize3D : This method only works for polyhedrons! Call convertAllToPoly first.");
- int *c(getNodalConnectivity()->getPointer()),*cI(getNodalConnectivityIndex()->getPointer());
MCAuto<MEDCouplingSkyLineArray> connSla(MEDCouplingSkyLineArray::BuildFromPolyhedronConn(getNodalConnectivity(), getNodalConnectivityIndex()));
const double * coo(_coords->begin());
MCAuto<DataArrayInt> ret(DataArrayInt::New());
// Build BBTree
MCAuto<DataArrayDouble> bboxArr(mDesc->getBoundingBoxForBBTree());
- const double *bbox(bboxArr->begin()),*coords(getCoords()->begin());
- int nCell=getNumberOfCells(), nDescCell=mDesc->getNumberOfCells();
+ const double *bbox(bboxArr->begin()); getCoords()->begin();
+ int nDescCell(mDesc->getNumberOfCells());
BBTree<SPACEDIM,int> myTree(bbox,0,0,nDescCell,-eps);
// Surfaces - handle biggest first
MCAuto<MEDCouplingFieldDouble> surfF = mDesc->getMeasureField(true);
vector<int> candidates, cands2;
myTree.getIntersectingElems(bbox+faceIdx*2*SPACEDIM,candidates);
// Keep only candidates whose normal matches the normal of current face
- for(vector<int>::const_iterator it=candidates.begin();it!=candidates.end();it++)
+ for(vector<int>::const_iterator it2=candidates.begin();it2!=candidates.end();it2++)
{
- bool col = INTERP_KERNEL::isColinear3D(normalsP + faceIdx*SPACEDIM, normalsP + *(it)*SPACEDIM, eps);
- if (*it != faceIdx && col)
- cands2.push_back(*it);
+ bool col = INTERP_KERNEL::isColinear3D(normalsP + faceIdx*SPACEDIM, normalsP + *(it2)*SPACEDIM, eps);
+ if (*it2 != faceIdx && col)
+ cands2.push_back(*it2);
}
if (!cands2.size())
continue;
const int * idsGoodPlaneP(idsGoodPlane->begin());
for (const int * ii = ids->begin(); ii != ids->end(); ii++)
{
- int faceIdx = cands2[idsGoodPlaneP[*ii]];
- hit[faceIdx] = true;
- checkSurf += surfs->begin()[faceIdx];
+ int faceIdx2 = cands2[idsGoodPlaneP[*ii]];
+ hit[faceIdx2] = true;
+ checkSurf += surfs->begin()[faceIdx2];
}
if (fabs(checkSurf - surfs->begin()[faceIdx]) > eps)
{
connSla->findPackIds(polyIndices, sIdxConn, sIdxConnE, packsIds);
// Deletion of old faces
int jj=0;
- for (vector<int>::const_iterator it=polyIndices.begin(); it!=polyIndices.end(); ++it, ++jj)
+ for (vector<int>::const_iterator it2=polyIndices.begin(); it2!=polyIndices.end(); ++it2, ++jj)
{
if (packsIds[jj] == -1)
// The below should never happen - if a face is used several times, with a different layout of the nodes
// faces which are actually used only once, by a single cell. This is different for edges below.
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::conformize3D: Could not find face in connectivity! Internal error.");
else
- connSla->deletePack(*it, packsIds[jj]);
+ connSla->deletePack(*it2, packsIds[jj]);
}
// Insertion of new faces:
for (const int * ii = ids->begin(); ii != ids->end(); ii++)
{
// Build pack from the face to insert:
- int faceIdx = cands2[idsGoodPlane->getIJ(*ii,0)];
+ int faceIdx2 = cands2[idsGoodPlane->getIJ(*ii,0)];
int facePack2Sz;
- const int * facePack2 = connSlaDesc->getSimplePackSafePtr(faceIdx, facePack2Sz); // contains the type!
+ const int * facePack2 = connSlaDesc->getSimplePackSafePtr(faceIdx2, facePack2Sz); // contains the type!
// Insert it in all hit polyhedrons:
- for (vector<int>::const_iterator it=polyIndices.begin(); it!=polyIndices.end(); ++it)
- connSla->pushBackPack(*it, facePack2+1, facePack2+facePack2Sz); // without the type
+ for (vector<int>::const_iterator it2=polyIndices.begin(); it2!=polyIndices.end(); ++it2)
+ connSla->pushBackPack(*it2, facePack2+1, facePack2+facePack2Sz); // without the type
}
}
} // end step1
{
/************************
* STEP 2 -- edges
- /************************/
+ ************************/
// Now we have a face-conform mesh.
// Recompute descending
unsigned start = cDesc2[cIDesc2[eIdx]+1], end = cDesc2[cIDesc2[eIdx]+2];
for (int i3=0; i3 < 3; i3++) // TODO: use fillSonCellNodalConnectivity2 or similar?
vCurr[i3] = coo[start*SPACEDIM+i3] - coo[end*SPACEDIM+i3];
- for(vector<int>::const_iterator it=candidates.begin();it!=candidates.end();it++)
+ for(vector<int>::const_iterator it2=candidates.begin();it2!=candidates.end();it2++)
{
double vOther[3];
- unsigned start2 = cDesc2[cIDesc2[*it]+1], end2 = cDesc2[cIDesc2[*it]+2];
+ unsigned start2 = cDesc2[cIDesc2[*it2]+1], end2 = cDesc2[cIDesc2[*it2]+2];
for (int i3=0; i3 < 3; i3++)
vOther[i3] = coo[start2*SPACEDIM+i3] - coo[end2*SPACEDIM+i3];
bool col = INTERP_KERNEL::isColinear3D(vCurr, vOther, eps);
// Warning: different from faces: we need to keep eIdx in the final list of candidates because we need
// to have its nodes inside the sub mesh mPartCand below (needed in OrderPointsAlongLine())
if (col)
- cands2.push_back(*it);
+ cands2.push_back(*it2);
}
if (cands2.size() == 1 && cands2[0] == eIdx) // see warning above
continue;
newCoords=a->getCoords()->selectByTupleId(tmp->begin(),tmp->end());
}
const double *cPtr(newCoords->begin());
- for(int i=0;i<newCoords->getNumberOfTuples();i++,cPtr+=2)
+ for(int j=0;j<newCoords->getNumberOfTuples();j++,cPtr+=2)
{
std::set<int> zeCandidates;
{
vorTess->getCellsContainingPoint(pt,eps,polygsToIterOn);
if(polygsToIterOn.size()<1)
throw INTERP_KERNEL::Exception("Voronoize3D : presence of a point outside the given cell !");
+ std::set<int> elemsToDo(polygsToIterOn.begin(),polygsToIterOn.end()),elemsDone;
+ std::size_t ii(0);
std::vector< MCAuto<MEDCouplingUMesh> > newVorCells;
- for(int poly=0;poly<vorTess->getNumberOfCells();poly++)
+ MCAuto<DataArrayInt> d(DataArrayInt::New()),dI(DataArrayInt::New()),rd(DataArrayInt::New()),rdI(DataArrayInt::New());
+ MCAuto<MEDCouplingUMesh> faces(vorTess->buildDescendingConnectivity(d,dI,rd,rdI));
+ //
+ while(!elemsToDo.empty())
{
+ int poly(*elemsToDo.begin()); elemsToDo.erase(elemsToDo.begin()); elemsDone.insert(poly);
const double *seed(pts+3*poly);
MCAuto<MEDCouplingUMesh> tile(l0[poly]);
tile->zipCoords();
newVorCell->zipCoords();
MCAuto<MEDCouplingUMesh> modifiedCell(cells->buildPartOfMySelfSlice(0,1,1,true));
modifiedCell->zipCoords();
+ l0[poly]=modifiedCell;
+ if(std::find(polygsToIterOn.begin(),polygsToIterOn.end(),poly)!=polygsToIterOn.end())// we iterate on a polyhedron containg the point to add pt -> add cells sharing faces with just computed newVorCell
+ {
+ MCAuto<MEDCouplingUMesh> faces2;
+ {
+ MCAuto<DataArrayInt> d2(DataArrayInt::New()),d2I(DataArrayInt::New()),rd2(DataArrayInt::New()),rd2I(DataArrayInt::New());
+ faces2=newVorCell->buildDescendingConnectivity(d2,d2I,rd2,rd2I);
+ }
+ MCAuto<MEDCouplingUMesh> faces3(faces2->buildPartOfMySelfSlice(1,faces2->getNumberOfCells(),1,true));// suppress internal face
+ MCAuto<MEDCouplingUMesh> facesOfCurSplitPol(faces->buildPartOfMySelf(d->begin()+dI->getIJ(poly,0),d->begin()+dI->getIJ(poly+1,0),true));
+ // intersection between the out faces of newVorCell and the neighbor faces of poly polyhedron -> candidates
+ MEDCouplingNormalizedUnstructuredMesh<3,2> source_mesh_wrapper(facesOfCurSplitPol);
+ MEDCouplingNormalizedUnstructuredMesh<3,2> target_mesh_wrapper(faces3);
+ INTERP_KERNEL::Interpolation3DSurf interpolation;
+ interpolation.setMinDotBtwPlane3DSurfIntersect(eps2);
+ interpolation.setMaxDistance3DSurfIntersect(eps);
+ interpolation.setPrecision(1e-12);
+ std::vector<std::map<int,double> > matrix;
+ interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,matrix,"P0P0");
+ std::set<int> zeCandidates;
+ for(std::vector<std::map<int,double> >::const_iterator it2=matrix.begin();it2!=matrix.end();it2++)
+ for(std::map<int,double>::const_iterator it3=(*it2).begin();it3!=(*it2).end();it3++)
+ {
+ int faceIdInVorTess(d->getIJ(dI->getIJ(poly,0)+(*it3).first,0));
+ for(const int *it4=rd->begin()+rdI->getIJ(faceIdInVorTess,0);it4!=rd->begin()+rdI->getIJ(faceIdInVorTess+1,0);it4++)
+ {
+ if(*it4!=poly)
+ zeCandidates.insert(*it4);
+ }
+ }
+ std::set<int> tmp2,newElementsToDo;
+ std::set_difference(zeCandidates.begin(),zeCandidates.end(),elemsDone.begin(),elemsDone.end(),std::inserter(tmp2,tmp2.begin()));
+ std::set_union(elemsToDo.begin(),elemsToDo.end(),tmp2.begin(),tmp2.end(),std::inserter(newElementsToDo,newElementsToDo.begin()));
+ elemsToDo=newElementsToDo;
+ }
+ //
newVorCells.push_back(newVorCell);
l0[poly]=modifiedCell;
}
arr->setInfoOnComponent(1,"hhhh");
arr->setInfoOnComponent(2,"jj");
arr->setInfoOnComponent(3,"kkkkkk");
- DataArrayInt *arr2=arr->convertToIntArr();
- DataArrayDouble *arr3=arr2->convertToDblArr();
- arr2->decrRef();
+ MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
+ MCAuto<DataArrayDouble> arr3(arr2->convertToDblArr());
CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
- arr3->decrRef();
arr->decrRef();
}
const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
for(int i=0;i<30;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
- DataArrayInt *a3=a1->convertToIntArr();
+ MCAuto<DataArrayInt> a3(a1->convertToIntArr());
DataArrayInt *a4=static_cast<DataArrayInt *>(a3->keepSelectedComponents(arr2V));
CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
for(int i=0;i<30;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
- DataArrayInt *a6=a5->convertToIntArr();
+ MCAuto<DataArrayInt> a6=a5->convertToIntArr();
a6->setInfoOnComponent(0,"eeee");
a6->setInfoOnComponent(1,"ffff");
a4->setSelectedComponents(a6,arr4V);
arr7V.resize(3);
CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
//
- a6->decrRef();
a5->decrRef();
a4->decrRef();
- a3->decrRef();
a2->decrRef();
a1->decrRef();
}
CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
- DataArrayDouble *da3=da->convertToDblArr();
+ MCAuto<DataArrayDouble> da3=da->convertToDblArr();
DataArrayDouble *da4=da3->fromNoInterlace();
CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
for(int i=0;i<15;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
da4->decrRef();
- da3->decrRef();
da2->decrRef();
da->decrRef();
}
CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
- DataArrayDouble *da3=da->convertToDblArr();
+ MCAuto<DataArrayDouble> da3=da->convertToDblArr();
DataArrayDouble *da4=da3->toNoInterlace();
CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
for(int i=0;i<15;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
da4->decrRef();
- da3->decrRef();
da2->decrRef();
da->decrRef();
}
CPPUNIT_ASSERT(!da->isUniform(1));
da->setIJ(2,0,1);
CPPUNIT_ASSERT(da->isUniform(1));
- DataArrayDouble *da2=da->convertToDblArr();
+ MCAuto<DataArrayDouble> da2=da->convertToDblArr();
CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
da2->setIJ(1,0,1.+1.e-13);
CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
da2->setIJ(1,0,1.+1.e-11);
CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
- da2->decrRef();
da->decrRef();
}
//
da1->fillWithValue(7.);
da2->iota(0.);
- DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
+ MCAuto<DataArrayDouble> da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
//
da1->setInfoOnComponent(0,"c0da1");
da1->setInfoOnComponent(1,"c1da1");
for(int i=0;i<35;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
//
- DataArrayInt *dai1=da1C->convertToIntArr();
- DataArrayInt *dai3=da3->convertToIntArr();
+ MCAuto<DataArrayInt> dai1=da1C->convertToIntArr();
+ MCAuto<DataArrayInt> dai3=da3->convertToIntArr();
dai1->meldWith(dai3);
CPPUNIT_ASSERT_EQUAL(5,(int)dai1->getNumberOfComponents());
CPPUNIT_ASSERT_EQUAL(7,(int)dai1->getNumberOfTuples());
for(int i=0;i<35;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
// test of static method DataArrayInt::meld
- dai1->decrRef();
dai1=da1C->convertToIntArr();
DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
CPPUNIT_ASSERT_EQUAL(5,(int)dai4->getNumberOfComponents());
//
dai4->decrRef();
da4->decrRef();
- dai3->decrRef();
- dai1->decrRef();
da1C->decrRef();
da1->decrRef();
da2->decrRef();
- da3->decrRef();
}
void MEDCouplingBasicsTest3::testFieldMeld1()
for(int i=0;i<12;i++)
CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
//double
- DataArrayDouble *da2=da1->convertToDblArr();
+ MCAuto<DataArrayDouble> da2=da1->convertToDblArr();
da1->decrRef();
const double *ptr2=da2->getConstPointer();
//
CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
for(int i=0;i<12;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
- da2->decrRef();
}
void MEDCouplingBasicsTest3::testGetDifferentValues1()
c=a->buildPermutationArr(*b);
const int expect2[5]={1,3,4,2,3};
CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
- DataArrayDouble *d=b->convertToDblArr();
+ MCAuto<DataArrayDouble> d=b->convertToDblArr();
b->sort();
const int expect3[5]={4,4,5,6,8};
CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
for(int i=0;i<5;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
//
- d->decrRef();
+ b->decrRef();
c->decrRef();
a->decrRef();
- b->decrRef();
}
void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
d1->deepCopyFrom(*d);
CPPUNIT_ASSERT(d->isEqual(*d1,1e-12));
//
- DataArrayInt *d2=d->convertToIntArr();
+ MCAuto<DataArrayInt> d2=d->convertToIntArr();
DataArrayInt *d4=DataArrayInt::New();
CPPUNIT_ASSERT(!d2->isEqual(*d4));
d4->deepCopyFrom(*d2);
//
d->decrRef();
d1->decrRef();
- d2->decrRef();
d4->decrRef();
}
const double expected1[12]={2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.};
d1->alloc(6,2);
std::copy(val1,val1+12,d1->getPointer());
- DataArrayInt *d2=d1->convertToIntArr();
+ MCAuto<DataArrayInt> d2=d1->convertToIntArr();
//
d1->abs();
for(int i=0;i<12;i++)
for(int i=0;i<12;i++)
CPPUNIT_ASSERT_EQUAL(expected2[i],d2->getIJ(0,i));
//
- d2->decrRef();
d1->decrRef();
}
ADD_DEFINITIONS(${PYTHON_DEFINITIONS} ${NUMPY_DEFINITIONS} ${SCIPY_DEFINITIONS})
SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_MEDCoupling_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
SET (MEDCoupling_SWIG_DPYS_FILES
MEDCouplingBasicsTest3.py
MEDCouplingBasicsTest4.py
MEDCouplingBasicsTest5.py
+ MEDCouplingBasicsTest6.py
MEDCouplingIntersectTest.py
MEDCouplingRemapperTest.py
MEDCouplingDataForTest.py
MEDCouplingRemapper.i
MEDCouplingTypemaps.i
MEDCouplingDataArrayTypemaps.i
+ MEDCouplingDataArrayTraits.hxx
)
INCLUDE_DIRECTORIES(
SWIG_LINK_LIBRARIES(MEDCoupling ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medcoupling)
SWIG_CHECK_GENERATION(MEDCoupling)
SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_MEDCouplingRemapper_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
# _ABR_ Ensure dependency mechanism on all SWIG files and headers
SET_TESTS_PROPERTIES(MEDCouplingBasicsTest4 PROPERTIES ENVIRONMENT "${tests_env}")
ADD_TEST(MEDCouplingBasicsTest5 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingBasicsTest5.py)
SET_TESTS_PROPERTIES(MEDCouplingBasicsTest5 PROPERTIES ENVIRONMENT "${tests_env}")
+ADD_TEST(MEDCouplingBasicsTest6 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingBasicsTest6.py)
+SET_TESTS_PROPERTIES(MEDCouplingBasicsTest6 PROPERTIES ENVIRONMENT "${tests_env}")
ADD_TEST(MEDCouplingIntersectTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingIntersectTest.py)
SET_TESTS_PROPERTIES(MEDCouplingIntersectTest PROPERTIES ENVIRONMENT "${tests_env}")
ADD_TEST(MEDCouplingExamplesTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingExamplesTest.py)
MEDCouplingBasicsTest3
MEDCouplingBasicsTest4
MEDCouplingBasicsTest5
+ MEDCouplingBasicsTest6
MEDCouplingIntersectTest
MEDCouplingExamplesTest
MEDCouplingRemapperTest
def MEDCouplingFieldDoubleIpow(self,*args):
import _MEDCoupling
return _MEDCoupling.MEDCouplingFieldDouble____ipow___(self, self, *args)
+def MEDCouplingFieldIntnew(cls,*args):
+ import _MEDCoupling
+ return _MEDCoupling.MEDCouplingFieldInt____new___(cls,args)
+def MEDCouplingFieldFloatnew(cls,*args):
+ import _MEDCoupling
+ return _MEDCoupling.MEDCouplingFieldFloat____new___(cls,args)
def MEDCouplingDataArrayIntnew(cls,*args):
import _MEDCoupling
return _MEDCoupling.DataArrayInt____new___(cls,args)
def MEDCouplingDataArrayBytenew(cls,*args):
import _MEDCoupling
return _MEDCoupling.DataArrayByte____new___(cls,args)
+def MEDCouplingDataArrayFloatnew(cls,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____new___(cls,args)
+def MEDCouplingDataArrayFloatIadd(self,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____iadd___(self, self, *args)
+def MEDCouplingDataArrayFloatIsub(self,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____isub___(self, self, *args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____imul___(self, self, *args)
+def MEDCouplingDataArrayFloatIdiv(self,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____idiv___(self, self, *args)
def MEDCouplingDataArrayDoubleTupleIadd(self,*args):
import _MEDCoupling
return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args)
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
class MEDCouplingBasicsTest1(unittest.TestCase):
def testArray2(self):
self.assertEqual(7,arr4.getNumberOfTuples());
self.assertEqual(2,arr4.getNumberOfComponents());
tmp=arr4.getValues()
- for i in xrange(14):
+ for i in range(14):
self.assertTrue(abs(arr4Ref[i]-tmp[i])<1e-14);
pass
arr5=arr4.subArray(3);
self.assertEqual(4,arr5.getNumberOfTuples());
self.assertEqual(2,arr5.getNumberOfComponents());
tmp=arr5.getValues()
- for i in xrange(8):
+ for i in range(8):
self.assertTrue(abs(arr4Ref[6+i]-tmp[i])<1e-14);
pass
arr6=arr4.subArray(2,5);
self.assertEqual(3,arr6.getNumberOfTuples());
self.assertEqual(2,arr6.getNumberOfComponents());
tmp=arr6.getValues()
- for i in xrange(6):
+ for i in range(6):
self.assertTrue(abs(arr4Ref[4+i]-tmp[i])<1e-14);
pass
pass
field.setNature(ExtensiveMaximum)
myCoords=DataArrayDouble.New()
sampleTab=[]
- for i in range(nbOfCells*9):
+ for i in range(nbOfCells * 9):
sampleTab.append(float(i))
myCoords.setValues(sampleTab,nbOfCells,9);
field.setArray(myCoords)
self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
m3DIds=m4.getMesh3DIds().getValues();
- self.assertEqual(range(15),list(m3DIds));
+ self.assertEqual(list(range(15)), list(m3DIds));
#some random in cells to check that extrusion alg find it correctly
expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4]
m3.renumberCells(expected1,False);
expected2=[0.075,0.0375,0.0375,0.075,0.075,
0.1125,0.05625,0.05625,0.1125,0.1125,
0.0625,0.03125,0.03125,0.0625,0.0625]
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],16);
pass
m5=m4.build3DUnstructuredMesh();
self.assertTrue(isinstance(f.getMesh(),MEDCouplingMappedExtrudedMesh))
arr=f.getArray();
arrPtr=arr.getValues();
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],15);
pass
pass
o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommonNodesFormat(comm,commI);
self.assertEqual(27,newNbOfNodes);
self.assertEqual(27,o2n.getNumberOfTuples());
- o2nExp1=range(27)
+ o2nExp1 = list(range(27))
self.assertEqual(o2nExp1,list(o2n.getValues()));
#
targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
def testMergeMeshOnSameCoords1(self):
m1=MEDCouplingDataForTest.build2DTargetMesh_1();
m2=MEDCouplingDataForTest.build2DTargetMesh_1();
- cells=range(5);
+ cells = list(range(5));
m2.convertToPolyTypes(cells);
m1.tryToShareSameCoords(m2,1e-12);
m3=MEDCouplingDataForTest.build2DTargetMesh_1();
values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5]
tmp=f3.getArray().getValues();
self.assertEqual(len(values),len(tmp))
- for i in xrange(7):
+ for i in range(7):
self.assertTrue(abs(values[i]-tmp[i])<1e-12)
pass
pass
values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
tmp=f1.getArray().getValues();
self.assertEqual(len(values1),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
pass
#
values2=[-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4]
tmp=f1.getArray().getValues();
self.assertEqual(len(values2),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
pass
#
values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
tmp=f1.getArray().getValues();
self.assertEqual(len(values3),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
pass
values4=f1.accumulate();
values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
tmp=f1.getArray().getValues();
self.assertEqual(len(values1),len(tmp))
- for i in xrange(len(values1)):
+ for i in range(len(values1)):
self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
pass
#
values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
tmp=f1.getArray().getValues();
self.assertEqual(len(values2),len(tmp))
- for i in xrange(len(values2)):
+ for i in range(len(values2)):
self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
pass
f1=m.fillFromAnalytic(ON_NODES,1,"2.*x+y");
tmp=f1.getArray().getValues();
values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
self.assertEqual(len(values2Bis),len(tmp))
- for i in xrange(len(values2Bis)):
+ for i in range(len(values2Bis)):
self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
pass
#
values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
tmp=f1.getArray().getValues();
self.assertEqual(len(values3),len(tmp))
- for i in xrange(len(values3)):
+ for i in range(len(values3)):
self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
pass
values4=f1.accumulate();
values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
tmp=f1.getArray().getValues();
self.assertEqual(len(values1),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
pass
pass
5.0423700574830965, 17.435300118916864]
tmp=f2.getArray().getValues();
self.assertEqual(len(tmp),len(values2))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
pass
#
values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
tmp=f1.getArray().getValues();
self.assertEqual(len(tmp),len(values1))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
pass
pass
values1=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
tmp=f3.getArray().getValues();
self.assertEqual(len(values1),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
pass
#
values2=[0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96]
tmp=f3.getArray().getValues();
self.assertEqual(len(values2),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
pass
#
values3=[0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4]
tmp=f4.getArray().getValues();
self.assertEqual(len(values3),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
pass
#
self.assertEqual(f4.getTypeOfField(),ON_NODES);
self.assertEqual(f4.getTimeDiscretization(),ONE_TIME);
tmp=f4.getArray().getValues();
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-2.)<1.e-12)
pass
#
tmp=f3.getArray().getValues();
values4=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
self.assertEqual(len(values3),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values4[i])<1.e-12)
pass
#
tmp=f3.getArray().getValues();
values5=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
self.assertEqual(len(values5),len(tmp))
- for i in xrange(len(tmp)):
+ for i in range(len(tmp)):
self.assertTrue(abs(tmp[i]-values5[i])<1.e-12)
pass
pass
self.assertEqual(1,f3.getNumberOfComponents());
self.assertEqual(9,f3.getNumberOfTuples());
val=f3.getArray().getValues();
- for i in xrange(9):
+ for i in range(9):
self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
#
f1=m.buildOrthogonalField();
f3=f1*f2;
expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
val=f3.getArray().getValues();
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
pass
#
f3=f2*f1;
val=f3.getArray().getValues();
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
pass
pass
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(9,f1.getNumberOfTuples());
val=f1.getArray().getValues();
- for i in xrange(9):
+ for i in range(9):
self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
pass
#
f1*=f2
expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
val=f1.getArray().getValues();
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
pass
#
self.assertEqual(3,len(corr));
expectedVals1=[3,3,2]
expectedVals2=[[0,1,2],[3,0,2],[3,0]]
- for i in xrange(3):
+ for i in range(3):
arr=corr[i];
self.assertEqual(1,arr.getNumberOfComponents());
nbOfVals=expectedVals1[i];
self.assertEqual(1,arr2.getNumberOfComponents());
self.assertEqual(4,arr2.getNumberOfTuples());
self.assertEqual(fidExp,list(arr2.getValues()));
- for i in xrange(3):
+ for i in range(3):
nbOfVals=expectedVals1[i];
self.assertEqual(list(fidsOfGroups[i]),fidsGrp[i]);
pass
self.assertEqual(5,field.getNumberOfTuples());
self.assertEqual(3,field.getNumberOfComponents());
vals=field.getArray().getValues();
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected[i%3]-vals[i])<1e-12);
# testing
targetCoords=[0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.]
fieldOnCells.setMesh(targetMesh);
array=DataArrayDouble.New();
tmp=2*nbOfCells*[None]
- for i in xrange(nbOfCells):
+ for i in range(nbOfCells):
tmp[2*i]=7.+float(i);
tmp[2*i+1]=17.+float(i)
pass
fieldOnNodes.setMesh(targetMesh);
array=DataArrayDouble.New();
tmp=2*nbOfNodes*[None]
- for i in xrange(nbOfNodes):
+ for i in range(nbOfNodes):
tmp[2*i]=17.+float(i);
tmp[2*i+1]=27.+float(i)
pass
7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.];
val=fieldOnNodes.getArray().getValues();
- for i in xrange(64):
+ for i in range(64):
self.assertAlmostEqual(expected1[i], val[i], 12)
res=fieldOnNodes.getValueOnPos(1, 3, 2);
self.assertAlmostEqual(7., res[0], 12);
val=fieldOnCells.getArray().getValues();
expected2=[0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6, 1.5, 3, 4.5, 3, 4.5,
6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9];
- for i in xrange(27):
+ for i in range(27):
self.assertAlmostEqual(expected2[i], val[i], 12);
#res=fieldOnCells.getValueOnPos(1,2,1);
#self.assertAlmostEqual(6.,res,12);
-0.05,0.45, 0.2,0.45, 0.45,0.45]
val=mesh.getCoords().getValues();
self.assertEqual(18,len(val))
- for i in xrange(18):
+ for i in range(18):
self.assertTrue(abs(expected1[i]-val[i])<1e-12);
pass
pass
self.assertEqual(3,m1.getSpaceDimension());
expected=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.]
val=m1.getCoords().getValues();
- for i in xrange(27):
+ for i in range(27):
self.assertTrue(abs(expected[i]-val[i])<1e-14);
pass
pass
self.assertEqual(2,f.getNbOfGaussLocalization());
array=DataArrayDouble.New();
ptr=18*2*[None]
- for i in xrange(18*2):
+ for i in range(18 * 2):
ptr[i]=float(i+1)
array.setValues(ptr,18,2);
ptr=array.getPointer();
f.setDescription("MyDescriptionNE");
array=DataArrayDouble.New();
tmp=18*2*[None]
- for i in xrange(18*2):
+ for i in range(18 * 2):
tmp[i]=float(i+7)
pass
array.setValues(tmp,18,2);
self.assertEqual(1,f3.getNumberOfComponents());
f3Ptr=f3.getArray().getValues();
expected1=[0.075,0.0375,0.0375,0.075,0.075, 0.1125,0.05625,0.05625,0.1125,0.1125, 0.0625,0.03125,0.03125,0.0625,0.0625];
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected1[i]-f3Ptr[i])<1e-12);
pass
f4=m5.computeCellCenterOfMass();
self.assertEqual(3,f4.getNumberOfComponents());
f4Ptr=f4.getValues();
expected2=[-0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,-0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,-0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875];
- for i in xrange(45):
+ for i in range(45):
self.assertTrue(abs(expected2[i]-f4Ptr[i])<1e-12);
pass
pass
def testCellOrientation3(self):
from cmath import rect
- c = [rect(1.0, i*pi/4.0) for i in range(8)]
+ c = [rect(1.0, i * pi / 4.0) for i in range(8)]
coords = [c[-1].real,c[-1].imag, c[3].real,c[3].imag,
c[5].real,c[5].imag, c[1].real,c[1].imag]
connec = [0,1,2,3]
self.assertEqual(3,da.getNumberOfComponents());
daPtr=da.getValues();
ref=meshN.getCoords().getValues()[24:];
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
pass
#
da=meshN.computeCellCenterOfMass();
daPtr=da.getValues();
ref=meshN.getCoords().getValues()[24:];
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
pass
#
da=meshN.computeCellCenterOfMass();
daPtr=da.getValues();
ref=meshN.getCoords().getValues()[24:];
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
pass
#
da=meshN.computeCellCenterOfMass();
daPtr=da.getValues();
ref=meshN.getCoords().getValues()[24:];
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(ref[i]-daPtr[i])<1e-10);
pass
pass
self.assertEqual(1,f3.getNumberOfComponents());
expected9=[0.75,5.105,0.8,5.155]
ptr=f3.getValues();
- for i in xrange(4):
+ for i in range(4):
self.assertTrue(abs(expected9[i]-ptr[i])<1e-12);
pass
#
self.assertEqual(1,f2.getNumberOfComponents());
expected1=[0.5,0.21,-0.6,-0.31]
ptr=f2.getArray().getValues();
- for i in xrange(4):
+ for i in range(4):
self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
pass
expected2=[0.5,0.21,0.6,0.31]
f2=m1.getMeasureField(True);
ptr=f2.getArray().getValues();
- for i in xrange(4):
+ for i in range(4):
self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
pass
#integral
res=f1.integral(False);
self.assertTrue(3,len(res))
expected3=[0.9866,-0.3615,0.4217]
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected3[i]-res[i])<1e-12);
pass
self.assertTrue(abs(expected3[0]-f1.integral(0,False))<1e-12);
self.assertTrue(abs(expected3[2]-f1.integral(2,False))<1e-12);
res=f1.integral(True);
expected4=[-3.4152,8.7639,-14.6879]
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected4[i]-res[i])<1e-12);
pass
#normL1
res=f1.normL1();
self.assertTrue(3,len(res))
expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected5[i]-res[i])<1e-12);
pass
self.assertTrue(abs(expected5[0]-f1.normL1(0))<1e-12);
res=f1.normL2();
self.assertTrue(3,len(res))
expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected7[i]-res[i])<1e-9);
pass
self.assertTrue(abs(expected7[0]-f1.normL2(0))<1e-9);
self.assertEqual(4,f2.getArray().getNumberOfTuples());
self.assertEqual(1,f2.getNumberOfComponents());
ptr=f2.getArray().getValues();
- for i in xrange(4):
+ for i in range(4):
self.assertTrue(abs(sqrt(2.)*expected2[i]-ptr[i])<1e-12);
pass
f2=m1.getMeasureField(True);
self.assertEqual(4,f2.getArray().getNumberOfTuples());
self.assertEqual(1,f2.getNumberOfComponents());
ptr=f2.getArray().getValues();
- for i in xrange(4):
+ for i in range(4):
self.assertTrue(abs(expected2[i]*sqrt(2.)-ptr[i])<1e-12);
pass
#bary
self.assertEqual(2,f3.getNumberOfComponents());
expected10=[0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155]
ptr=f3.getValues();
- for i in xrange(8):
+ for i in range(8):
self.assertTrue(abs(expected10[i]-ptr[i])<1e-12);
pass
#
array.setValues(arr,m1.getNumberOfCells(),3);
f1.setArray(array);
res=f1.integral(False);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
pass
res=f1.integral(True);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
pass
res=f1.normL1();
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected5[i]-res[i])<1e-12);
pass
res=f1.normL2();
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected7[i]-res[i])<1e-12);
pass
pass
self.assertEqual(1,f1.getNumberOfComponents());
expected1=[-0.5,-1,-1.5,-0.5,-1, 0.5,1,1.5,0.5,1]
ptr=f1.getArray().getValues();
- for i in xrange(10):
+ for i in range(10):
self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
pass
f1=m1.getMeasureField(True);
ptr=f1.getArray().getValues();
- for i in xrange(10):
+ for i in range(10):
self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
pass
f2=m1.computeCellCenterOfMass();
self.assertEqual(2,f2.getNumberOfComponents());
expected2=[0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5]
ptr=f2.getValues();
- for i in xrange(20):
+ for i in range(20):
self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
pass
m1.changeSpaceDimension(3);
self.assertEqual(10,f1.getArray().getNumberOfTuples());
self.assertEqual(1,f1.getNumberOfComponents());
ptr=f1.getArray().getValues();
- for i in xrange(10):
+ for i in range(10):
self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
pass
f2=m1.computeCellCenterOfMass();
self.assertEqual(3,f2.getNumberOfComponents());
ptr=f2.getValues();
expected3=[0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0., 0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.]
- for i in xrange(30):
+ for i in range(30):
self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
pass
pass
self.assertEqual(4,da.getNumberOfTuples());
self.assertEqual(3,da.getNumberOfComponents());
daPtr=da.getValues();
- for i in xrange(12):
+ for i in range(12):
self.assertTrue(abs(barys[i]-daPtr[i])<1e-12);
pass
pass
f.setArray(arr);
renumber1=[3,1,0,4,2]
loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
- for j in xrange(5):
+ for j in range(5):
res=f.getValueOn(loc[2*j:2*j+2]);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
pass
pass
f.renumberCells(renumber1,False);
ptr=f.getArray().getValues();
expected1=[9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.]
- for i in xrange(15):
+ for i in range(15):
self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
pass
#check that fields remains the same geometrically
- for j in xrange(5):
+ for j in range(5):
res=f.getValueOn(loc[2*j:2*(j+1)]);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
pass
pass
self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
expected2=[21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.]
ptr=f.getArray().getValues();
- for i in xrange(36):
+ for i in range(36):
self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
pass
renumber2=[2,1,4,0,3]
self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
expected3=[21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.]
ptr=f.getArray().getValues();
- for i in xrange(36):
+ for i in range(36):
self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
pass
f.renumberCells(renumber2,False);#perform reverse operation of renumbering to check that the resulting field is equal.
renumber1=[0,4,1,3,5,2,6,7,8]
loc=[0.5432,-0.2432, 0.5478,0.1528]
expected1=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124]
- for j in xrange(2):
+ for j in range(2):
res=f.getValueOn(loc[2*j:2*j+2]);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
pass
pass
self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
f.renumberNodes(renumber1);
self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
- for j in xrange(2):
+ for j in range(2):
res=f.getValueOn(loc[2*j:2*j+2]);
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
pass
pass
expected2=[7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
- for i in xrange(27):
+ for i in range(27):
self.assertTrue(abs(expected2[i]-f.getArray().getValues()[i])<1e-12);
pass
renumber2=[0,2,5,3,1,4,6,7,8]
types=mesh.getAllGeoTypes();
types.sort()
self.assertEqual(5,len(types));
- expected1=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8]
+ expected1 = [NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8]
expected1.sort()
self.assertEqual(expected1,types);
self.assertTrue(mesh.isPresenceOfQuadratic());
self.assertEqual(None,cellCor);
self.assertNotEqual(None,nodeCor);
expected1=[0, 1, 3, 4, 5, 6, 7, 8, 9]
- for i in xrange(9):
+ for i in range(9):
self.assertEqual(expected1[i],nodeCor.getIJ(i,0));
pass
pass
f2=m2.getMeasureField(False);
self.assertEqual(5,f1.getArray().getNumberOfTuples());
self.assertEqual(1,f2.getArray().getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
pass
self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
f2=m2.getMeasureField(False);
self.assertEqual(5,f1.getArray().getNumberOfTuples());
self.assertEqual(1,f2.getArray().getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
pass
self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
f1.changeUnderlyingMesh(mesh2,10,1e-12);
#self.assertTrue(f1.getMesh()==mesh2);
expected1=[7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.]
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
pass
#
f1.changeUnderlyingMesh(mesh2,10,1e-12);
#self.assertTrue(f1.getMesh()==mesh2);
expected2=[7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.]
- for i in xrange(22):
+ for i in range(22):
self.assertAlmostEqual(expected2[i],f1.getArray().getIJ(0,i),12);
pass
pass
#
f3=f1.dot(f2);
expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.]
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9);
pass
#
f4=f1.crossProduct(f2);
expected2=[-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
pass
pass
#
f3=f1.max(f2);
expected1=[7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9);
pass
#
f4=f1.min(f2);
expected2=[6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
pass
#
#
f1.applyLin(2.,3.,0);
expected1=[17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.]
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),9);
pass
#
f1.applyLin(4.,5.,1);
#
expected2=[17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.]
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),9);
pass
expected3=[2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.]
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected3[i],f1.getEndArray().getIJ(0,i),9);
pass
#
#
f1.checkConsistencyLight();
da=f1.findIdsInRange(2.9,7.1);
- self.failUnlessEqual(5,da.getNbOfElems());
+ self.assertEqual(5,da.getNbOfElems());
expected1=[2,3,5,7,9]
- self.failUnlessEqual(expected1,list(da.getValues()));
+ self.assertEqual(expected1,list(da.getValues()));
da=f1.findIdsInRange(8.,12.);
- self.failUnlessEqual(4,da.getNbOfElems());
+ self.assertEqual(4,da.getNbOfElems());
expected2=[1,4,6,8]
- self.failUnlessEqual(expected2,list(da.getValues()));
+ self.assertEqual(expected2,list(da.getValues()));
#
pass
part1=[2,1,4]
f2=f1[part1];
f2.zipCoords()
- self.failUnlessEqual(3,f2.getNumberOfTuples());
- self.failUnlessEqual(2,f2.getNumberOfComponents());
+ self.assertEqual(3,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
expected1=[5.,105.,4.,104.,7.,107.]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12);
pass
- self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
- self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
- self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
- self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+ self.assertEqual(3,f2.getMesh().getNumberOfCells());
+ self.assertEqual(6,f2.getMesh().getNumberOfNodes());
+ self.assertEqual(2,f2.getMesh().getSpaceDimension());
+ self.assertEqual(2,f2.getMesh().getMeshDimension());
m2C=f2.getMesh();
- self.failUnlessEqual(13,m2C.getNodalConnectivityArrayLen());
+ self.assertEqual(13,m2C.getNodalConnectivityArrayLen());
expected2=[0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
pass
expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
- self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
+ self.assertEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
expected4=[0,4,8,13]
- self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
+ self.assertEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
# Test with field on nodes.
f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
f1.setTime(2.3,5,6);
f1.setArray(array);
part2=[1,2]
f2=f1.buildSubPart(part2);
- self.failUnlessEqual(4,f2.getNumberOfTuples());
- self.failUnlessEqual(2,f2.getNumberOfComponents());
+ self.assertEqual(4,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
- for i in xrange(8):
+ for i in range(8):
self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
pass
- self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
- self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
- self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
- self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+ self.assertEqual(2,f2.getMesh().getNumberOfCells());
+ self.assertEqual(4,f2.getMesh().getNumberOfNodes());
+ self.assertEqual(2,f2.getMesh().getSpaceDimension());
+ self.assertEqual(2,f2.getMesh().getMeshDimension());
m2C=f2.getMesh();
- self.failUnlessEqual(8,m2C.getNodalConnectivityArrayLen());
- for i in xrange(8):#8 is not an error
+ self.assertEqual(8,m2C.getNodalConnectivityArrayLen());
+ for i in range(8): # 8 is not an error
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
pass
- self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
- self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
- self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
+ self.assertEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
+ self.assertEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
+ self.assertEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
#idem previous because nodes of cell#4 are not fully present in part3
part3=[1,2]
arrr=DataArrayInt.New();
arrr.setValues(part3,2,1);
f2=f1.buildSubPart(arrr);
- self.failUnlessEqual(4,f2.getNumberOfTuples());
- self.failUnlessEqual(2,f2.getNumberOfComponents());
- for i in xrange(8):
+ self.assertEqual(4,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
+ for i in range(8):
self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
pass
- self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
- self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
- self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
- self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+ self.assertEqual(2,f2.getMesh().getNumberOfCells());
+ self.assertEqual(4,f2.getMesh().getNumberOfNodes());
+ self.assertEqual(2,f2.getMesh().getSpaceDimension());
+ self.assertEqual(2,f2.getMesh().getMeshDimension());
m2C=f2.getMesh();
- self.failUnlessEqual(8,m2C.getNodalConnectivityArrayLen());
- for i in xrange(8):#8 is not an error
+ self.assertEqual(8,m2C.getNodalConnectivityArrayLen());
+ for i in range(8): # 8 is not an error
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
pass
- self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
- self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
- self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
+ self.assertEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
+ self.assertEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
+ self.assertEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
#
part4=[1,2,4]
f2=f1.buildSubPart(part4);
- self.failUnlessEqual(6,f2.getNumberOfTuples());
- self.failUnlessEqual(2,f2.getNumberOfComponents());
+ self.assertEqual(6,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12);
pass
- self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
- self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
- self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
- self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+ self.assertEqual(3,f2.getMesh().getNumberOfCells());
+ self.assertEqual(6,f2.getMesh().getNumberOfNodes());
+ self.assertEqual(2,f2.getMesh().getSpaceDimension());
+ self.assertEqual(2,f2.getMesh().getMeshDimension());
m2C=f2.getMesh();
- self.failUnlessEqual(13,m2C.getNodalConnectivityArrayLen());
- for i in xrange(12):
+ self.assertEqual(13,m2C.getNodalConnectivityArrayLen());
+ for i in range(12):
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
pass
- self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
- self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
- self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
- self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
+ self.assertEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
+ self.assertEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
+ self.assertEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
+ self.assertEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
pass
def testDoublyContractedProduct1(self):
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9);
pass
#
self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization());
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfValues());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13);
pass
#6 components multi arrays with end array not defined
self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
self.assertEqual(1,f2.getArray().getNumberOfComponents());
self.assertEqual(9,f2.getNumberOfTuples());
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
pass
#6 components multi arrays with end array defined
self.assertAlmostEqual(3.8,time2,12);
self.assertEqual(7,it);
self.assertEqual(3,order);
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9);
pass
self.assertAlmostEqual(7.8,time2,12);
self.assertEqual(10,it);
self.assertEqual(2,order);
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(3.267,f2.getIJ(i,0),13);
pass
pass
self.assertEqual(3,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1
-0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2
]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
self.assertEqual(9,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
self.assertEqual(6,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13);
self.assertEqual(4,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13);
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(15.9,f2.getIJ(i,0),13);
pass
#
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(25.8,f2.getIJ(i,0),13);
pass
#
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(5.7,f2.getIJ(i,0),13);
pass
#
self.assertEqual(6,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
expected1=[-1.1,0.,1.1,4.5,5.6,6.7]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13);
pass
#
f2.checkConsistencyLight();
self.assertEqual(1,f2.getNumberOfComponents());
self.assertEqual(5,f2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(5.6,f2.getIJ(i,0),13);
pass
#
d2,d2I=array.maxPerTupleWithCompoId()
self.assertEqual(1,d2.getNumberOfComponents());
self.assertEqual(5,d2.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(5.6,d2.getIJ(i,0),13);
pass
self.assertTrue(d2I.isEqual(DataArrayInt([4,3,2,0,1])))
self.assertEqual(3,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
expected1=[1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2]
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13);
pass
f1.changeNbOfComponents(4,7.77);
self.assertEqual(4,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
expected2=[1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77]
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13);
pass
#
f1.checkConsistencyLight();
self.assertEqual(5,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13);
self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13);
self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
f1.checkConsistencyLight();
self.assertEqual(5,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13);
self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13);
self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
self.assertEqual(5,f1.getNumberOfTuples());
self.assertEqual(1,f1.getNumberOfComponents());
expected1=[1.,1.4142135623730951, 1.4142135623730951,1.,1.]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),14);
pass
#
self.assertEqual(5,f1.getNumberOfTuples());
self.assertEqual(1,f1.getNumberOfComponents());
expected2=[1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected2[i],f1.getIJ(i,0),14);
pass
pass
values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
tmp=f1.getArray().getValues();
self.assertEqual(len(values1),len(tmp))
- for i in xrange(len(values1)):
+ for i in range(len(values1)):
self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
pass
#
values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
tmp=f1.getArray().getValues();
self.assertEqual(len(values2),len(tmp))
- for i in xrange(len(values2)):
+ for i in range(len(values2)):
self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
pass
f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
tmp=f1.getArray().getValues();
values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
self.assertEqual(len(values2Bis),len(tmp))
- for i in xrange(len(values2Bis)):
+ for i in range(len(values2Bis)):
self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
pass
tmp=f1.getEndArray().getValues();
self.assertEqual(len(values2Bis),len(tmp))
- for i in xrange(len(values2Bis)):
+ for i in range(len(values2Bis)):
self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
pass
#
values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
tmp=f1.getArray().getValues();
self.assertEqual(len(values3),len(tmp))
- for i in xrange(len(values3)):
+ for i in range(len(values3)):
self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
pass
values4=f1.accumulate();
f1.checkConsistencyLight();
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(0.07,f1.getIJ(i,0),16);
pass
f1.assign(0.09);
f1.checkConsistencyLight();
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(0.09,f1.getIJ(i,0),16);
pass
#
f1.checkConsistencyLight();
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(9,f1.getNumberOfTuples());
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(0.08,f1.getIJ(i,0),16);
pass
self.assertEqual(1,f1.getEndArray().getNumberOfComponents());
self.assertEqual(9,f1.getEndArray().getNumberOfTuples());
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(0.08,f1.getEndArray().getIJ(i,0),16);
pass
pass
self.assertEqual(3,f.getNumberOfTuples());
self.assertEqual(1,f.getNumberOfComponents());
expected1=[1.1,2.4,4.4]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected1[i],f.getIJ(i,0),12);
pass
coords=m.getCoordinatesAndOwner();
self.assertEqual(4,coords.getNumberOfTuples());
self.assertEqual(1,coords.getNumberOfComponents());
- for i in xrange(4):
+ for i in range(4):
self.assertAlmostEqual(discX[i],coords.getIJ(i,0),12);
pass
coords=m.computeCellCenterOfMass();
self.assertEqual(3,coords.getNumberOfTuples());
self.assertEqual(1,coords.getNumberOfComponents());
expected1_3=[2.85,4.6,8.]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected1_3[i],coords.getIJ(i,0),12);
pass
#
self.assertEqual(6,f.getNumberOfTuples());
self.assertEqual(1,f.getNumberOfComponents());
expected2=[12.21,26.64,48.84,24.64,53.76,98.56]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected2[i],f.getIJ(i,0),12);
pass
coords=m.getCoordinatesAndOwner();
self.assertEqual(12,coords.getNumberOfTuples());
self.assertEqual(2,coords.getNumberOfComponents());
expected2_2=[2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(expected2_2[i],coords.getIJ(0,i),12);
pass
coords=m.computeCellCenterOfMass();
self.assertEqual(6,coords.getNumberOfTuples());
self.assertEqual(2,coords.getNumberOfComponents());
expected2_3=[2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected2_3[i],coords.getIJ(0,i),12);
pass
#
self.assertEqual(24,f.getNumberOfTuples());
self.assertEqual(1,f.getNumberOfComponents());
expected3=[23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(expected3[i],f.getIJ(i,0),12);
pass
coords=m.getCoordinatesAndOwner();
2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67];
- for i in xrange(180):
+ for i in range(180):
self.assertAlmostEqual(expected3_2[i],coords.getIJ(0,i),12);
pass
coords=m.computeCellCenterOfMass();
2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4];
- for i in xrange(72):
+ for i in range(72):
self.assertAlmostEqual(expected3_3[i],coords.getIJ(0,i),12);
pass
pass
self.assertEqual(18,f.getNumberOfTuples());
self.assertEqual(2,f.getNumberOfComponents());
expected1=[-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
- for i in xrange(36):
+ for i in range(36):
self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
pass
self.assertTrue(f.zipCoords());
f.checkConsistencyLight();
expected2=[-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
pass
self.assertTrue(not f.zipCoords());
f.checkConsistencyLight();
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
pass
self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
expected1=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
-0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
- for i in xrange(20):
+ for i in range(20):
self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
pass
f.getArray().setInfoOnComponent(0,"titi");
-0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
self.assertEqual(7,f.getNumberOfTuples());
self.assertEqual(2,f.getNumberOfComponents());
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
pass
self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
-0.3, -0.3, 0.2, 0.2, 0.7, 0.7];
self.assertEqual(9,f2.getNumberOfTuples());
self.assertEqual(2,f2.getNumberOfComponents());
- for i in xrange(18):
+ for i in range(18):
self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
pass
self.assertTrue(f2.zipConnectivity(0));
self.assertEqual(9,f2.getNumberOfTuples());
self.assertEqual(2,f2.getNumberOfComponents());
- for i in xrange(18):
+ for i in range(18):
self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
pass
pass
self.assertTrue(b.getInfoOnComponent(0)=="toto");
self.assertTrue(b.getInfoOnComponent(1)=="tata");
expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
#
self.assertTrue(d.getInfoOnComponent(0)=="toto");
self.assertTrue(d.getInfoOnComponent(1)=="tata");
expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected2[i],d.getIJ(0,i));
pass
pass
self.assertTrue(b.getInfoOnComponent(0)=="toto");
self.assertTrue(b.getInfoOnComponent(1)=="tata");
expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
#
self.assertTrue(d.getInfoOnComponent(0)=="toto");
self.assertTrue(d.getInfoOnComponent(1)=="tata");
expected2=[5,15,3,13,1,11,7,17,6,16]
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(expected2[i],d.getIJ(0,i));
pass
pass
self.assertEqual(7,a.getNumberOfTuples());
self.assertEqual(2,a.getNumberOfComponents());
expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
pass
#
self.assertEqual(7,c.getNumberOfTuples());
self.assertEqual(2,c.getNumberOfComponents());
expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected2[i],c.getIJ(0,i));
pass
pass
self.assertTrue(b.getInfoOnComponent(0)=="toto");
self.assertTrue(b.getInfoOnComponent(1)=="tata");
expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
#
self.assertTrue(d.getInfoOnComponent(0)=="toto");
self.assertTrue(d.getInfoOnComponent(1)=="tata");
expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected2[i],d.getIJ(0,i));
pass
pass
self.assertEqual(7,a.getNumberOfTuples());
self.assertEqual(2,a.getNumberOfComponents());
expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
pass
#
self.assertEqual(7,c.getNumberOfTuples());
self.assertEqual(2,c.getNumberOfComponents());
expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected2[i],c.getIJ(0,i));
pass
pass
self.assertTrue(b.getInfoOnComponent(0)=="toto");
self.assertTrue(b.getInfoOnComponent(1)=="tata");
expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
#
self.assertTrue(d.getInfoOnComponent(0)=="toto");
self.assertTrue(d.getInfoOnComponent(1)=="tata");
expected2=[5,15,3,13,1,11,7,17,6,16]
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(expected2[i],d.getIJ(0,i));
pass
pass
self.assertEqual(3,ws.getNumberOfTuples());
self.assertEqual(1,ws.getNumberOfComponents());
expected1=[1,4,8]
- for i in xrange(3):
+ for i in range(3):
self.assertEqual(expected1[i],ws.getIJ(i,0));
pass
a=DataArrayDouble.New();
self.assertAlmostEqual(-4.56,m,12);
self.assertEqual(3,ws.getNumberOfTuples());
self.assertEqual(1,ws.getNumberOfComponents());
- for i in xrange(3):
+ for i in range(3):
self.assertEqual(expected1[i],ws.getIJ(i,0));
pass
pass
self.assertEqual(4,ws.getNumberOfTuples());
self.assertEqual(1,ws.getNumberOfComponents());
expected1=[0,3,7,17]
- for i in xrange(4):
+ for i in range(4):
self.assertEqual(expected1[i],ws.getIJ(i,0));
pass
#
self.assertAlmostEqual(-8.71,m,12);
self.assertEqual(4,ws.getNumberOfTuples());
self.assertEqual(1,ws.getNumberOfComponents());
- for i in xrange(4):
+ for i in range(4):
self.assertEqual(expected1[i],ws.getIJ(i,0));
pass
pass
self.assertEqual(f2.getNumberOfTuples(),3);
self.assertEqual(1,m2.getMeshDimension());
self.assertEqual(1,m2.getSpaceDimension());
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
pass
da=DataArrayDouble.New();
self.assertEqual(f2.getNumberOfTuples(),6);
self.assertEqual(2,m2.getMeshDimension());
self.assertEqual(2,m2.getSpaceDimension());
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
pass
#
self.assertEqual(f2.getNumberOfTuples(),24);
self.assertEqual(3,m2.getMeshDimension());
self.assertEqual(3,m2.getSpaceDimension());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
pass
#
self.assertEqual(6,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
expected1=[1,3,0,5,2,4]
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],da2.getIJ(i,0));
pass
da3=da2.invertArrayN2O2O2N(6);
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(arr1[i],da3.getIJ(i,0));
pass
#
self.assertEqual(6,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
expected2=[5,7,8,0,3,2]
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected2[i],da2.getIJ(i,0));
pass
da3=da2.invertArrayN2O2O2N(10);
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(arr2[i],da3.getIJ(i,0));
pass
pass
a1.setValues(arr1,5,4);
expp=[21.,22.,23.,24.]
self.assertEqual(4,len(a1.getTuple(2)));
- for i in xrange(4):
+ for i in range(4):
self.assertAlmostEqual(expp[i],a1.getTuple(2)[i],12)
pass
a1.setInfoOnComponent(0,"aaaa");
self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14);
pass
a3=a1.convertToIntArr();
self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
- for i in xrange(30):
+ for i in range(30):
self.assertEqual(int(expected1[i]),a4.getIJ(0,i));
pass
# setSelectedComponents
self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],a2.getIJ(0,i),14);
pass
a6=a5.convertToIntArr();
self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
- for i in xrange(30):
+ for i in range(30):
self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
pass
# test of throw
self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected1[i],f2.getIJ(0,i),14);
pass
#setSelectedComponents
self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),14);
pass
#
da4=da3.fromNoInterlace();
self.assertEqual(5,da4.getNumberOfTuples());
self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
pass
pass
da4=da3.toNoInterlace();
self.assertEqual(5,da4.getNumberOfTuples());
self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
pass
pass
da.setValues(tab1,2,2);
da2=da.fromPolarToCart();
expected1=[1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275]
- for i in xrange(4):
+ for i in range(4):
self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
pass
pass
da.setValues(tab1,2,3);
da2=da.fromCylToCart();
expected1=[1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
pass
pass
da.setValues(tab1,2,3);
da2=da.fromSpherToCart();
expected1=[0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
pass
pass
self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(1));
self.assertEqual(NORM_TETRA4,mesh.getTypeOfCell(2));
self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(3));
- for i in xrange(4):
+ for i in range(4):
self.assertAlmostEqual(f1.getArray().getIJ(0,i),f2.getArray().getIJ(0,i),5);
pass
pass
self.assertEqual(24,i.getNumberOfCellsWithType(NORM_QUAD4));
expected1=[0.25,0.75,2.0625]
j=i.getMeasureField(True);
- for ii in xrange(12):
- for k in xrange(3):
+ for ii in range(12):
+ for k in range(3):
self.assertAlmostEqual(expected1[k],j.getIJ(0,ii*3+k),10);
pass
pass
expected2=[0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853]
m=i.computeCellCenterOfMass();
- for i in xrange(72):
+ for i in range(72):
self.assertAlmostEqual(expected2[i],m.getIJ(0,i),10);
pass
#
g.checkConsistencyLight();
expected1=[ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 ]
f1=g.getMeasureField(True);
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),12);
pass
expected2=[0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414]
f2=g.computeCellCenterOfMass();
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),12);
pass
pass
self.assertTrue(tmp2);
self.assertEqual(444,tmp3);
expected1=[1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796]
- for ii in xrange(12):
- for jj in xrange(36):
+ for ii in range(12):
+ for jj in range(36):
self.assertAlmostEqual(expected1[jj],f2.getIJ(0,ii*36+jj),9);
pass
#
self.assertEqual(7,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
expected2=[0,0,1,2,3,4,4]
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected2[i],da.getIJ(i,0));
pass
m.checkConsistencyLight();
self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
expected1=[0.125,0.125,0.125,0.125,0.25,0.125,0.125]
f=m.getMeasureField(False);
- for i in xrange(7):
+ for i in range(7):
self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
pass
types=m.getAllGeoTypes();
da=m.simplexize(1);
self.assertEqual(7,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected2[i],da.getIJ(i,0));
pass
m.checkConsistencyLight();
self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
f=m.getMeasureField(False);
- for i in xrange(7):
+ for i in range(7):
self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
pass
pass
self.assertTrue(f1.simplexize(0));
f1.checkConsistencyLight();
expected1=[10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
pass
self.assertTrue(not f1.simplexize(0));
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
pass
#
self.assertTrue(da1.getInfoOnComponent(4)=="c2da3");
#
expected1=[7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.]
- for i in xrange(35):
+ for i in range(35):
self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),10);
pass
#
self.assertTrue(dai1.getInfoOnComponent(2)=="c0da3");
self.assertTrue(dai1.getInfoOnComponent(3)=="c1da3");
self.assertTrue(dai1.getInfoOnComponent(4)=="c2da3");
- for i in xrange(35):
+ for i in range(35):
self.assertEqual(int(expected1[i]),dai1.getIJ(0,i));
pass
# test of static method DataArrayDouble::meld
self.assertTrue(da4.getInfoOnComponent(2)=="c0da3");
self.assertTrue(da4.getInfoOnComponent(3)=="c1da3");
self.assertTrue(da4.getInfoOnComponent(4)=="c2da3");
- for i in xrange(35):
+ for i in range(35):
self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),10);
pass
# test of static method DataArrayInt::meld
self.assertTrue(dai4.getInfoOnComponent(2)=="c0da3");
self.assertTrue(dai4.getInfoOnComponent(3)=="c1da3");
self.assertTrue(dai4.getInfoOnComponent(4)=="c2da3");
- for i in xrange(35):
+ for i in range(35):
self.assertEqual(int(expected1[i]),dai4.getIJ(0,i));
pass
pass
self.assertTrue(f3.getArray().getInfoOnComponent(1)=="ccc");
self.assertTrue(f3.getArray().getInfoOnComponent(2)=="aaa");
expected1=[5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.]
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),12);
pass
time,dt,it=f3.getTime();
self.assertTrue(f6.getArray().getInfoOnComponent(0)=="bbb");
self.assertTrue(f6.getArray().getInfoOnComponent(1)=="ccc");
self.assertTrue(f6.getArray().getInfoOnComponent(2)=="aaa");
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],f6.getIJ(0,i),12);
pass
#
da,b,newNbOfNodes=m3.mergeNodesCenter(0.01);
self.assertEqual(9,m3.getNumberOfNodes());
expected1=[-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7]
- for i in xrange(18):
+ for i in range(18):
self.assertAlmostEqual(expected1[i],m3.getCoords().getIJ(0,i),13);
pass
#
f4=MEDCouplingFieldDouble.MergeFields([f1,f2,f3]);
self.assertEqual(15,f4.getMesh().getNumberOfCells());
expected1=[2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.]
- for i in xrange(30):
+ for i in range(30):
self.assertAlmostEqual(expected1[i],f4.getIJ(0,i),13);
pass
#
self.assertEqual(8,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[0,2,4,5,6,9,10,11]
- for i in xrange(8):
+ for i in range(8):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
pass
self.assertEqual(7,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[0,1,3,5,7,8,18]
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
b=DataArrayInt.BuildUnion([a,c]);
self.assertEqual(7,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[0,1,3,5,7,8,18]
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
pass
self.assertEqual(2,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[3,8]
- for i in xrange(2):
+ for i in range(2):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
b=DataArrayInt.BuildIntersection([a,c]);
self.assertEqual(2,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[3,8]
- for i in xrange(2):
+ for i in range(2):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
pass
self.assertEqual(6,b.getNumberOfTuples());
self.assertEqual(1,b.getNumberOfComponents());
expected1=[2,3,1,0,2,6]
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],b.getIJ(0,i));
pass
pass
self.assertTrue(b.getInfoOnComponent(0)=="toto");
self.assertTrue(b.getInfoOnComponent(1)=="tata");
expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
arr4=[4,-1,0,6,5]
self.assertTrue(d.getInfoOnComponent(0)=="toto");
self.assertTrue(d.getInfoOnComponent(1)=="tata");
expected2=[5,15,3,13,1,11,7,17,6,16]
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(expected2[i],d.getIJ(0,i));
pass
self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr4);
self.assertEqual(13,da1.getNumberOfTuples());
#
expected1=[-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.];
- for i in xrange(26):
+ for i in range(26):
self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),14);
pass
pass
#self.assertRaises(InterpKernelException,f2.__idiv__,f1) # mem leaks
self.assertTrue(f1.isEqual(f3,1e-10,1e-10));
expected1=[-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0]
- for i in xrange(26):
+ for i in range(26):
self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10);
pass
pass
self.assertEqual(12,da1.getNbOfElems());
self.assertEqual(4,da1.getNumberOfComponents());
self.assertEqual(3,da1.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(i,da1.getIJ(0,i));
#
da1.rearrange(6);
self.assertEqual(12,da1.getNbOfElems());
self.assertEqual(6,da1.getNumberOfComponents());
self.assertEqual(2,da1.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(i,da1.getIJ(0,i));
#
self.assertRaises(InterpKernelException,da1.rearrange,7);
self.assertEqual(12,da1.getNbOfElems());
self.assertEqual(12,da1.getNumberOfComponents());
self.assertEqual(1,da1.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(i,da1.getIJ(0,i));
#
da1.rearrange(3);
self.assertEqual(12,da1.getNbOfElems());
self.assertEqual(3,da1.getNumberOfComponents());
self.assertEqual(4,da1.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(i,da1.getIJ(0,i));
#double
da2=da1.convertToDblArr();
self.assertEqual(12,da2.getNbOfElems());
self.assertEqual(4,da2.getNumberOfComponents());
self.assertEqual(3,da2.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
#
da2.rearrange(6);
self.assertEqual(12,da2.getNbOfElems());
self.assertEqual(6,da2.getNumberOfComponents());
self.assertEqual(2,da2.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
#
self.assertRaises(InterpKernelException,da2.rearrange,7);
self.assertEqual(12,da2.getNbOfElems());
self.assertEqual(1,da2.getNumberOfComponents());
self.assertEqual(12,da2.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
#
da2.rearrange(3);
self.assertEqual(12,da2.getNbOfElems());
self.assertEqual(3,da2.getNumberOfComponents());
self.assertEqual(4,da2.getNumberOfTuples());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
pass
d.sort()
self.assertEqual(5,d.getNumberOfTuples());
self.assertEqual(1,d.getNumberOfComponents());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(float(expect3[i]),d.getIJ(i,0),14);
pass
pass
self.assertEqual(2,b.getNumberOfComponents());
self.assertEqual(3,b.getNumberOfTuples());
expected1=[0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45];
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
pass
self.assertEqual(1,b.getNumberOfComponents());
self.assertEqual(3,b.getNumberOfTuples());
expected1=[0.125,0.25,0.25];
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
pass
pass
self.assertEqual(3,b.getArray().getNumberOfComponents());
self.assertEqual(3,b.getArray().getNumberOfTuples());
expected1=[0.,0.,-1.,0.,0.,-1.,0.,0.,-1.];
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(expected1[i],b.getArray().getIJ(0,i),14);
pass
pass
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
class MEDCouplingBasicsTest3(unittest.TestCase):
def testSwigGetItem1(self):
da.iota(7)
da.rearrange(5)
da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
- da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ;
+ da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ;
da[:,2]=3
self.assertEqual([7, 8, 3, 10, 11, 12, 13, 3, 15, 16, 17, 18, 3, 20, 21, 22, 23, 3, 25, 26],da.getValues())
da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
da.iota(7)
da.rearrange(5)
da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
- da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ;
+ da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ;
da[:,2]=3.
self.assertEqual([7., 8., 3., 10., 11., 12., 13., 3., 15., 16., 17., 18., 3., 20., 21., 22., 23., 3., 25., 26.],da.getValues())
da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
da-=8
st2=da.getHiddenCppPointer()
self.assertEqual(st1,st2)
- self.assertEqual(range(12),da.getValues())
+ self.assertEqual(list(range(12)), da.getValues())
da+=da1
st2=da.getHiddenCppPointer()
self.assertEqual(st1,st2)
da-=8
st2=da.getHiddenCppPointer()
self.assertEqual(st1,st2)
- self.assertEqual(range(12),da.getValues())
+ self.assertEqual(list(range(12)), da.getValues())
da+=da1
st2=da.getHiddenCppPointer()
self.assertEqual(st1,st2)
it2=da2.__iter__()
i=0
for it in da:
- pt=it2.next()
+ pt = next(it2)
it[:]=pt
pass
self.assertTrue(da.isEqual(da2))
it2=da2.__iter__()
i=0
for it in da:
- pt=it2.next()
+ pt = next(it2)
it[:]=pt
pass
self.assertTrue(da.isEqual(da2,1e-12))
def testDAIAggregateMulti1(self):
a=DataArrayInt.New()
- a.setValues(range(4),2,2)
+ a.setValues(list(range(4)), 2, 2)
a.setName("aa")
b=DataArrayInt.New()
- b.setValues(range(6),3,2)
+ b.setValues(list(range(6)), 3, 2)
c=DataArrayInt.Aggregate([a,b])
- self.assertEqual(range(4)+range(6),c.getValues())
+ self.assertEqual(list(range(4)) + list(range(6)), c.getValues())
self.assertEqual("aa",c.getName())
self.assertEqual(5,c.getNumberOfTuples())
self.assertEqual(2,c.getNumberOfComponents())
self.assertEqual(0,m.getMeshDimension());
types1=m.getAllGeoTypes();
self.assertEqual([NORM_POINT1],types1);
- for i in xrange(4):
+ for i in range(4):
conn=m.getNodeIdsOfCell(i);
self.assertEqual([i],conn);
self.assertTrue(NORM_POINT1==m.getTypeOfCell(i));
hs=dt.getHotSpotsTime();
self.assertEqual(6,len(hs));
expected1=[0.2,0.7,1.2,1.35,1.7,2.7]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],hs[i],12);
pass
meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.2);
da2=da.checkAndPreparePermutation();
self.assertEqual(8,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
- for i in xrange(8):
+ for i in range(8):
self.assertEqual(expect1[i],da2.getIJ(i,0));
pass
#
self.assertEqual(1,da2.getNumberOfComponents());
self.assertEqual(5,da2.getNumberOfTuples());
expected1=[32.,34.,36.,38.,40.]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
pass
da2=da.applyFunc(1,"y+z");
expected2=[12.,14.,16.,18.,20.]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected2[i],da2.getIJ(0,i),12);
pass
#
f1.applyFuncCompo(1,"y+z");
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
pass
#
vs[1]="y";
da2=da.applyFuncNamedCompo(1,vs,"y+z");
expected1=[32.,34.,36.,38.,40.]
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
pass
self.assertRaises(InterpKernelException, da.applyFuncNamedCompo, 1, ["x","y","z","a"],"x+a")
f1.applyFuncNamedCompo(1,vs,"y+z");
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(5,f1.getNumberOfTuples());
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
pass
pass
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(9,f1.getNumberOfTuples());
expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
pass
pass
self.assertEqual(1,f1.getNumberOfComponents());
self.assertEqual(9,f1.getNumberOfTuples());
expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
- for i in xrange(9):
+ for i in range(9):
self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
pass
pass
self.assertEqual(3,resToTest.getNumberOfComponents());
self.assertEqual(2,resToTest.getNumberOfTuples());
expected1=[0.6,0.6,0.6, 0.6,0.6,0.6]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],resToTest.getIJ(0,i),14);
pass
#
2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,#TRI6
2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,#QUAD4
2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 ];#QUAD8
- for i in xrange(39):
+ for i in range(39):
self.assertAlmostEqual(expected2[i],resToTest.getIJ(0,i),14);
pass
#
self.assertEqual(3,resToTest.getNumberOfComponents());
self.assertEqual(8,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
expected3=[1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(expected3[i],resToTest.getIJ(0,i),14);
pass
#
loc=[2.27,1.3]
locs=f.getValueOnMulti(loc);
expected1=[6.0921164547752236, 7.1921164547752232, 8.2921164547752255]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
pass
pass
loc=[0.64637931739890486, -0.16185896817550552, 0.22678966365273748]
locs=f.getValueOnMulti(loc);
expected1=[10.0844021968047]
- for i in xrange(1):
+ for i in range(1):
self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
pass
pass
locs=f.getValueOnMulti(loc);
self.assertEqual(5,locs.getNumberOfTuples());
self.assertEqual(3,locs.getNumberOfComponents());
- for j in xrange(15):
+ for j in range(15):
self.assertAlmostEqual(values1[j],locs.getIJ(0,j),12);
pass
# Testing ON_NODES
locs=f.getValueOnMulti(loc3);
self.assertEqual(4,locs.getNumberOfTuples());
self.assertEqual(3,locs.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected2[i],locs.getIJ(0,i),12);
pass
#
self.assertEqual(7,d2.getNumberOfTuples());
self.assertEqual(1,d2.getNumberOfComponents());
expected1=[0,1,3,4,7,8,9]
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected1[i],d2.getIJ(0,i));
pass
d.rearrange(2);
self.assertEqual(5,d3.getNumberOfTuples());
self.assertEqual(1,d3.getNumberOfComponents());
expected2=[0,1,4,8,9]
- for i in xrange(5):
+ for i in range(5):
self.assertEqual(expected2[i],d3.getIJ(0,i));
pass
pass
d.computeOffsets();
self.assertEqual(6,d.getNumberOfTuples());
self.assertEqual(1,d.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],d.getIJ(0,i));
pass
pass
self.assertEqual(1,bary.getNumberOfTuples());
self.assertEqual(3,bary.getNumberOfComponents());
expected1=[0.,0.,1.]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected1[i],bary.getIJ(0,i),12);
pass
d1=DataArrayInt.New();
expected4=[[1,2,3,4,5,0],[7,6,11,10,9,8],[1,7,8,2],[2,8,9,3],[3,9,10,4],[4,10,11,5],[5,11,6,0],[0,6,7,1]];
expected2=[NORM_POLYGON, NORM_POLYGON, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4];
expected3=[6,6,4,4,4,4,4,4]
- for i in xrange(8):
+ for i in range(8):
self.assertTrue(m2.getTypeOfCell(i)==expected2[i]);
v=m2.getNodeIdsOfCell(i);
self.assertTrue(len(v)==expected3[i]);
d1.transformWithIndArr(d);
self.assertEqual(12,d1.getNumberOfTuples());
self.assertEqual(1,d1.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected[i],d1.getIJ(i,0));
pass
#
d1.transformWithIndArr(tab1)
self.assertEqual(12,d1.getNumberOfTuples());
self.assertEqual(1,d1.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected[i],d1.getIJ(i,0));
pass
pass
da2=da.buildPermArrPerLevel();
self.assertEqual(12,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected1[i],da2.getIJ(i,0));
pass
pass
self.assertEqual(4,da2.getNumberOfTuples());
self.assertEqual(3,da2.getNumberOfComponents());
expected1=[1,1,8,12,9,9,14,15,14,14,12,14]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected1[i],da2.getIJ(0,i));
pass
da1.substractEqual(da);
expected2=[3,5,0,-2,3,5,2,3,6,8,12,12]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected2[i],da1.getIJ(0,i));
pass
da1.rearrange(1); da1.iota(2); da1.rearrange(3);
da1.addEqual(da);
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected1[i],da1.getIJ(0,i));
pass
da1.rearrange(1); da1.iota(2); da1.rearrange(3);
self.assertEqual(4,da2.getNumberOfTuples());
self.assertEqual(3,da2.getNumberOfComponents());
expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected3[i],da2.getIJ(0,i));
pass
da.divideEqual(da1);
self.assertEqual(4,da.getNumberOfTuples());
self.assertEqual(3,da.getNumberOfComponents());
expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected4[i],da.getIJ(0,i));
pass
da.setValues(arr1,4,3);
da1.multiplyEqual(da);
self.assertEqual(4,da1.getNumberOfTuples());
self.assertEqual(3,da1.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected3[i],da1.getIJ(0,i));
pass
da1.rearrange(1); da1.iota(2); da1.rearrange(3);
da2=DataArrayInt.Divide(da,da1);
self.assertEqual(4,da2.getNumberOfTuples());
self.assertEqual(3,da2.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected4[i],da2.getIJ(0,i));
pass
da1.applyInv(321);
self.assertEqual(4,da1.getNumberOfTuples());
self.assertEqual(3,da1.getNumberOfComponents());
expected5=[160,107,80,64,53,45,40,35,32,29,26,24]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected5[i],da1.getIJ(0,i));
pass
da1.applyDivideBy(2);
self.assertEqual(4,da1.getNumberOfTuples());
self.assertEqual(3,da1.getNumberOfComponents());
expected6=[80,53,40,32,26,22,20,17,16,14,13,12]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected6[i],da1.getIJ(0,i));
pass
expected7=[3,4,5,4,5,1,6,3,2,0,6,5]
da1.applyModulus(7);
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected7[i],da1.getIJ(0,i));
pass
da1.applyLin(1,1);
expected8=[3,3,3,3,3,1,3,3,0,0,3,3]
da1.applyRModulus(3);
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected8[i],da1.getIJ(0,i));
pass
pass
expected1=[1,32,29,23,41,36]
self.assertEqual(47,da0.getNumberOfTuples());
self.assertEqual(1,da0.getNumberOfComponents());
- for i in xrange(47):
+ for i in range(47):
self.assertEqual(expected0[i],da0.getIJ(0,i));
pass
self.assertEqual(6,da5.getNumberOfTuples());
self.assertEqual(1,da5.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],da5.getIJ(0,i));
pass
expected2=[0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46]
self.assertEqual(70,da1.getNumberOfTuples());
self.assertEqual(1,da1.getNumberOfComponents());
- for i in xrange(70):
+ for i in range(70):
self.assertEqual(expected2[i],da1.getIJ(0,i));
pass
expected3=[0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70]
self.assertEqual(17,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
- for i in xrange(17):
+ for i in range(17):
self.assertEqual(expected3[i],da2.getIJ(0,i));
pass
expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70]
#expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70];
self.assertEqual(48,da4.getNumberOfTuples());
self.assertEqual(1,da4.getNumberOfComponents());
- for i in xrange(48):
+ for i in range(48):
self.assertEqual(expected4[i],da4.getIJ(0,i));
pass
expected5=[0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15]
self.assertEqual(70,da3.getNumberOfTuples());
self.assertEqual(1,da3.getNumberOfComponents());
- for i in xrange(70):
+ for i in range(70):
self.assertEqual(expected5[i],da3.getIJ(0,i));
pass
pass
expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46]
self.assertEqual(47,da0.getNumberOfTuples());
self.assertEqual(1,da0.getNumberOfComponents());
- for i in xrange(47):
+ for i in range(47):
self.assertEqual(expected0[i],da0.getIJ(0,i));
pass
self.assertEqual(2,da1.getNumberOfTuples());
#
self.assertEqual(47,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
- for i in xrange(47):
+ for i in range(47):
self.assertEqual(expected1[i],da2.getIJ(0,i));
pass
pass
d3=d.transformWithIndArrR(d1);
self.assertEqual(6,d3.getNumberOfTuples());
self.assertEqual(1,d3.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected[i],d3.getIJ(i,0));
pass
#
d3=d.transformWithIndArrR(tab2)
self.assertEqual(6,d3.getNumberOfTuples());
self.assertEqual(1,d3.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected[i],d3.getIJ(i,0));
pass
pass
#
expected1=[1,1,0,0,0,1,1,0,1]
expected2=[2,1,0,3,2,3,4,1,0]
- for i in xrange(9):
+ for i in range(9):
self.assertEqual(expected1[i],e.getIJ(i,0));
self.assertEqual(expected2[i],f.getIJ(i,0));
pass
self.assertEqual(11,f.getNumberOfTuples());
self.assertEqual(1,f.getNumberOfComponents());
expected1=[0,1,2,6,7,8,9,10,11,12,13]
- for i in xrange(11):
+ for i in range(11):
self.assertEqual(expected1[i],f.getIJ(i,0));
pass
pass
d.computeOffsetsFull();
self.assertEqual(7,d.getNumberOfTuples());
self.assertEqual(1,d.getNumberOfComponents());
- for i in xrange(7):
+ for i in range(7):
self.assertEqual(expected1[i],d.getIJ(0,i));
pass
pass
self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
#
pass
-
+
def testGetDistributionOfTypes1(self):
m=MEDCouplingDataForTest.build2DTargetMesh_1();
tab1=[2,0,1,3,4]
m3.setName(m.getName());
self.assertTrue(m.isEqual(m3,1e-12));
pass
-
+
def testChangeUnderlyingMeshWithCMesh1(self):
mesh=MEDCouplingCMesh.New();
coordsX=DataArrayDouble.New();
self.assertEqual(0,c.getNbOfElems());
self.assertEqual(1,cI.getNbOfElems());
self.assertEqual([0],cI.getValues())
-
+
array12=[0.]*(6*5)
da.setValues(array12,6,5) #bad NumberOfComponents
self.assertRaises(InterpKernelException, da.findCommonTuples, 1e-2);
expected1=[2.301,1.2,1.3,0.8]
dv=da.getDifferentValues(1e-2);
self.assertEqual(4,dv.getNbOfElems());
- for i in xrange(4):
+ for i in range(4):
self.assertAlmostEqual(expected1[i],dv.getIJ(i,0),14);
pass
#
dv=da.getDifferentValues(2e-1);
expected2=[2.301,1.3,0.8]
self.assertEqual(3,dv.getNbOfElems());
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14);
pass
pass
a.setValues(arr,6,1);
self.assertEqual(2,a.back());
a.reverse();
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(arr[5-i],a.getIJ(i,0));
pass
a.setValues(arr[:-1],5,1);
a.reverse();
- for i in xrange(5):
+ for i in range(5):
self.assertEqual(arr[4-i],a.getIJ(i,0));
pass
#
b=DataArrayDouble.New();
b.setValues(arr2,6,1);
b.reverse();
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(arr2[5-i],b.getIJ(i,0),14);
pass
b.setValues(arr2[:5],5,1);
self.assertAlmostEqual(9.,b.back(),14)
b.reverse();
- for i in xrange(5):
+ for i in range(5):
self.assertAlmostEqual(arr2[4-i],b.getIJ(i,0),14);
pass
pass
self.assertEqual(expected6,conn.getValues());
pass
+ def testIntersect2DMeshesTmp1(self):
+ m1c=MEDCouplingCMesh.New();
+ coordsX=DataArrayDouble.New();
+ arrX=[ -1., 1., 2., 4. ]
+ coordsX.setValues(arrX,4,1);
+ m1c.setCoordsAt(0,coordsX);
+ coordsY=DataArrayDouble.New();
+ arrY=[ -2., 2., 4., 8. ]
+ coordsY.setValues(arrY,4,1);
+ m1c.setCoordsAt(1,coordsY);
+ m1=m1c.buildUnstructured()
+ m1bis=m1.buildPartOfMySelf([3,4,5],False)
+ m2=m1.deepCopy()
+ m2=m2.buildPartOfMySelf([0,1,2],False)
+ m2.translate([0.5,0.5])
+ #
+ m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10)
+ expected1=[0,0,1,1,1,2,2,2]
+ expected2=[0,-1,0,1,-1,1,2,-1]
+ self.assertEqual(8,d1.getNumberOfTuples());
+ self.assertEqual(8,d2.getNumberOfTuples());
+ self.assertEqual(8,m3.getNumberOfCells());
+ self.assertEqual(22,m3.getNumberOfNodes());
+ self.assertEqual(2,m3.getSpaceDimension());
+ self.assertEqual(expected1,d1.getValues());
+ self.assertEqual(expected2,d2.getValues());
+ expected3=[5,17,1,16,12,5,16,0,4,5,17,12,5,18,1,17,13,5,19,2,18,13,5,17,5,6,19,13,5,20,2,19,14,5,21,3,20,14,5,19,6,7,21,14]
+ expected4=[0,5,12,17,22,28,33,38,44]
+ expected5=[-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5]
+ self.assertEqual(44,m3.getNodalConnectivity().getNumberOfTuples());
+ self.assertEqual(9,m3.getNodalConnectivityIndex().getNumberOfTuples());
+ self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
+ self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
+ for i in range(44):
+ self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
+ pass
+ pass
+
def testFindNodesOnLine1(self):
mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
pt=[-0.3,-0.3]
self.assertEqual(expected1,res.getValues());
pass
+ def testIntersect2DMeshesTmp2(self):
+ m1c=MEDCouplingCMesh.New();
+ coordsX1=DataArrayDouble.New();
+ arrX1=[ 0., 1., 1.5, 2. ]
+ coordsX1.setValues(arrX1,4,1);
+ m1c.setCoordsAt(0,coordsX1);
+ coordsY1=DataArrayDouble.New();
+ arrY1=[ 0., 1.5, 3.]
+ coordsY1.setValues(arrY1,3,1);
+ m1c.setCoordsAt(1,coordsY1);
+ m1=m1c.buildUnstructured();
+ m2c=MEDCouplingCMesh.New();
+ coordsX2=DataArrayDouble.New();
+ arrX2=[ 0., 1., 2. ]
+ coordsX2.setValues(arrX2,3,1);
+ m2c.setCoordsAt(0,coordsX2);
+ coordsY2=DataArrayDouble.New();
+ arrY2=[ 0., 1., 3.]
+ coordsY2.setValues(arrY2,3,1);
+ m2c.setCoordsAt(1,coordsY2);
+ m2=m2c.buildUnstructured();
+ #
+ m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
+ #
+ expected1=[0,0,1,1,2,2,3,4,5]
+ expected2=[0,2,1,3,1,3,2,3,3]
+ self.assertEqual(9,d1.getNumberOfTuples());
+ self.assertEqual(9,d2.getNumberOfTuples());
+ self.assertEqual(9,m3.getNumberOfCells());
+ self.assertEqual(22,m3.getNumberOfNodes());
+ self.assertEqual(2,m3.getSpaceDimension());
+ self.assertEqual(expected1,d1.getValues());
+ self.assertEqual(expected2,d2.getValues());
+ expected3=[5,16,13,12,15,5,15,4,5,16,5,21,2,13,16,5,16,5,6,21,5,17,14,2,21,5,21,6,7,17,5,4,18,19,5,5,5,19,10,6,5,6,10,20,7]
+ expected4=[0,5,10,15,20,25,30,35,40,45]
+ expected5=[0.0,0.0,1.0,0.0,1.5,0.0,2.0,0.0,0.0,1.5,1.0,1.5,1.5,1.5,2.0,1.5,0.0,3.0,1.0,3.0,1.5,3.0,2.0,3.0,0.0,0.0,1.0,0.0,2.0,0.0,0.0,1.0,1.0,1.0,2.0,1.0,0.0,3.0,1.0,3.0,2.0,3.0,1.5,1.0]
+ self.assertEqual(45,m3.getNodalConnectivity().getNumberOfTuples());
+ self.assertEqual(10,m3.getNodalConnectivityIndex().getNumberOfTuples());
+ self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
+ self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
+ for i in range(44):
+ self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
+ pass
+ pass
+
def testBuildPartOfMySelfSafe1(self):
mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,-1,4,2],True)
self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,4,5,4],True)
pass
+ def testIntersect2DMeshesTmp3(self):
+ m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
+ m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
+ m1=MEDCouplingUMesh.New();
+ m1.setMeshDimension(2);
+ m1.allocateCells(8);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
+ m1.finishInsertingCells();
+ myCoords1=DataArrayDouble.New();
+ myCoords1.setValues(m1Coords,25,2);
+ m1.setCoords(myCoords1);
+ #
+ m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
+ m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
+ m2=MEDCouplingUMesh.New();
+ m2.setMeshDimension(2);
+ m2.allocateCells(8);
+ for i in range(8):
+ m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
+ pass
+ m2.finishInsertingCells();
+ myCoords2=DataArrayDouble.New();
+ myCoords2.setValues(m2Coords,15,2);
+ m2.setCoords(myCoords2);
+ #
+ m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
+ m3.unPolyze()
+ #
+ expected1=[0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7]
+ expected2=[0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1]
+ self.assertEqual(16,d1.getNumberOfTuples());
+ self.assertEqual(16,d2.getNumberOfTuples());
+ self.assertEqual(16,m3.getNumberOfCells());
+ self.assertEqual(104,m3.getNumberOfNodes());
+ self.assertEqual(2,m3.getSpaceDimension());
+ self.assertEqual(expected1,d1.getValues());
+ self.assertEqual(expected2,d2.getValues());
+ expected3=[6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,8,28,4,40,27,55,56,57,58,6,28,25,5,59,60,61,8,28,5,32,31,62,63,64,65,8,32,6,41,31,66,67,68,69,8,41,4,28,31,70,71,72,73,6,25,37,5,74,75,76,8,32,5,37,36,77,78,79,80,8,42,6,32,36,81,82,83,84,8,37,8,42,36,85,86,87,88,6,1,37,25,89,90,91,8,37,1,26,38,92,93,94,95,8,26,2,43,38,96,97,98,99,8,43,8,37,38,100,101,102,103]
+ expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
+ expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,1.25,0.6123724356957946,1.369306393762915,1.1090169943749475,1.,0.55,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,-0.6123724356957941,1.3693063937629155,0.,1.25,-0.55,1.,-1.1090169943749475,1.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440734,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.,-1.25,-0.6123724356957945,-1.369306393762915,-1.1090169943749475,-1.,-0.55,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5,0.6123724356957946,-1.369306393762915,0.,-1.25,0.55,-1.,1.1090169943749475,-1.0]
+ self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
+ self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
+ self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
+ self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
+ for i in range(208):
+ self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
+ pass
+ pass
+
def testUMeshTessellate2D1(self):
m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
expected3=[5,0,3,25,26,1,5,3,4,27,28,2,1,26,25,5,5,29,30,3,0,5,6,31,32,4,3,30,29,5,5,5,0,7,33,34,5,6,5,34,33,7,8,35,36,5,0,1,37,38,7,5,1,2,39,40,8,7,38,37]
expected4=[0,6,15,21,30,36,45,51,60]
expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.479425538604203,0.8775825618903728,0.8414709848078964,0.54030230586814,0.7191383079063044,1.3163738428355591,1.2622064772118446,0.8104534588022099,-0.877582561890373,0.4794255386042027,-0.5403023058681399,0.8414709848078964,-1.3163738428355596,0.7191383079063038,-0.8104534588022098,1.2622064772118446,-0.4794255386042031,-0.8775825618903728,-0.8414709848078965,-0.5403023058681399,-0.7191383079063045,-1.3163738428355591,-1.2622064772118449,-0.8104534588022098,0.8775825618903729,-0.47942553860420295,0.54030230586814,-0.8414709848078964,1.3163738428355594,-0.7191383079063043,0.8104534588022099,-1.2622064772118446]
- for i in xrange(82):
+ for i in range(82):
self.assertAlmostEqual(expected5[i],m12.getCoords().getIJ(0,i),12);
pass
self.assertEqual(60,m12.getNodalConnectivity().getNumberOfTuples());
myCoords = DataArrayDouble.New(mcoords, 3, 2)
m1.setCoords(myCoords)
-
+
m2 = m1.deepCopy()
m2.tessellate2D(0.1)
# If the following raises, the test will fail automatically:
m2.checkConsistency(0.0) # eps param not used
+ def testIntersect2DMeshesTmp4(self):
+ m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
+ m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
+ m1=MEDCouplingUMesh.New();
+ m1.setMeshDimension(2);
+ m1.allocateCells(8);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
+ m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
+ m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
+ m1.finishInsertingCells();
+ myCoords1=DataArrayDouble.New();
+ myCoords1.setValues(m1Coords,25,2);
+ m1.setCoords(myCoords1);
+ #
+ m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
+ m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
+ m2=MEDCouplingUMesh.New();
+ m2.setMeshDimension(2);
+ m2.allocateCells(8);
+ for i in range(8):
+ m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
+ pass
+ m2.finishInsertingCells();
+ myCoords2=DataArrayDouble.New();
+ myCoords2.setValues(m2Coords,15,2);
+ m2.setCoords(myCoords2);
+ #
+ m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m2,m1,1e-10)
+ m3.unPolyze()
+ #
+ expected1=[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
+ expected2=[0,1,1,-1,2,3,3,-1,4,5,5,-1,6,7,7,-1]
+ self.assertEqual(16,d1.getNumberOfTuples());
+ self.assertEqual(16,d2.getNumberOfTuples());
+ self.assertEqual(16,m3.getNumberOfCells());
+ self.assertEqual(104,m3.getNumberOfNodes());
+ self.assertEqual(2,m3.getSpaceDimension());
+ self.assertEqual(expected1,d1.getValues());
+ self.assertEqual(expected2,d2.getValues());
+ expected3=[6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,8,40,5,4,17,55,56,57,58,6,18,15,20,59,60,61,8,20,7,6,18,62,63,64,65,8,41,6,7,21,66,67,68,69,8,21,8,9,41,70,71,72,73,6,20,15,22,74,75,76,8,22,11,7,20,77,78,79,80,8,21,7,11,42,81,82,83,84,8,42,10,8,21,85,86,87,88,6,22,15,16,89,90,91,8,16,1,13,22,92,93,94,95,8,43,13,1,17,96,97,98,99,8,17,4,14,43,100,101,102,103]
+ expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
+ expected5=[0.,0.,1.1, 0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865475,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,1.4090169943749475,1.,1.7,0.5,1.6,0.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865478,0.7071067811865475,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.6,0.,-1.7,0.5,-1.4090169943749475,1.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865475,-0.7071067811865477,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,-1.4090169943749475,-1.,-1.7,-0.5,-1.6,0.,-1.4012585384440732,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865475,-0.7071067811865477,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635,1.6,0.,1.7,-0.5,1.4090169943749475,-1.,1.4012585384440737,-0.535233134659635]
+ self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
+ self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
+ self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
+ self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
+ for i in range(208):
+ self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
+ pass
+ pass
+
def testGetCellIdsCrossingPlane1(self):
mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
vec=[-0.07,1.,0.07]
self.assertEqual(expected1,ids.getValues());
self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
- for i in xrange(171):
+ for i in range(171):
self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
pass
# 2nd slice based on already existing nodes of mesh3D.
self.assertEqual(expected1,ids.getValues());
self.assertEqual(expected5,slice1.getNodalConnectivity().getValues());
self.assertEqual(expected6,slice1.getNodalConnectivityIndex().getValues());
- for i in xrange(180):
+ for i in range(180):
self.assertAlmostEqual(expected7[i],slice1.getCoords().getIJ(0,i),12);
pass
# 3rd slice based on shared face of mesh3D.
self.assertEqual(expected8,ids.getValues());
self.assertEqual(expected9,slice1.getNodalConnectivity().getValues());
self.assertEqual(expected10,slice1.getNodalConnectivityIndex().getValues());
- for i in xrange(135):
+ for i in range(135):
self.assertAlmostEqual(expected11[i],slice1.getCoords().getIJ(0,i),12);
pass
pass
self.assertEqual(expected1,ids.getValues());
self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
- for i in xrange(171):
+ for i in range(171):
self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
pass
#
self.assertEqual(expected5,ids.getValues());
self.assertEqual(expected6,slice1.getNodalConnectivity().getValues());
self.assertEqual(expected7,slice1.getNodalConnectivityIndex().getValues());
- for i in xrange(135):
+ for i in range(135):
self.assertAlmostEqual(expected8[i],slice1.getCoords().getIJ(0,i),12);
pass
pass
expected1=[1.,11.,2.,12.,4.,14.,6.,16.,7.,17.]
self.assertEqual(5,tmp.getNumberOfTuples());
self.assertEqual(2,tmp.getNumberOfComponents());
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected1[i],tmp.getIJ(0,i),14);
pass
p=[(0,2),(0,2),(5,6)]
expected2=[1.,11.,2.,12.,1.,11.,2.,12.,6.,16.]
self.assertEqual(5,tmp.getNumberOfTuples());
self.assertEqual(2,tmp.getNumberOfComponents());
- for i in xrange(10):
+ for i in range(10):
self.assertAlmostEqual(expected2[i],tmp.getIJ(0,i),14);
pass
p=[(0,2),(-1,2),(5,6)]
dac=da.deepCopy();
dac.setContigPartOfSelectedValuesSlice(1,da2,2,4,1);
expected3=[1.,11.,0.,30.,11.,41.,4.,14.,5.,15.,6.,16.,7.,17.]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected3[i],dac.getIJ(0,i),14);
pass
#
self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValuesSlice,3,da2,5,0,1);
dac.setContigPartOfSelectedValuesSlice(3,da2,1,5,1);
expected4=[1.,11.,2.,12.,3.,13.,9.,39.,0.,30.,11.,41.,12.,42.]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected4[i],dac.getIJ(0,i),14);
pass
#
ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
dac.setContigPartOfSelectedValues(2,da2,ids);
expected5=[1.,11.,2.,12.,0.,30.,8.,38.,12.,42.,6.,16.,7.,17.]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected5[i],dac.getIJ(0,i),14);
pass
#
dac=da.deepCopy();
dac.setContigPartOfSelectedValues(4,da2,ids);
expected6=[1.,11.,2.,12.,3.,13.,4.,14.,0.,30.,0.,30.,9.,39.]
- for i in xrange(14):
+ for i in range(14):
self.assertAlmostEqual(expected6[i],dac.getIJ(0,i),14);
pass
pass
expected1=[1,11,2,12,4,14,6,16,7,17]
self.assertEqual(5,tmp.getNumberOfTuples());
self.assertEqual(2,tmp.getNumberOfComponents());
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(expected1[i],tmp.getIJ(0,i));
pass
p=[(0,2),(0,2),(5,6)]
expected2=[1,11,2,12,1,11,2,12,6,16]
self.assertEqual(5,tmp.getNumberOfTuples());
self.assertEqual(2,tmp.getNumberOfComponents());
- for i in xrange(10):
+ for i in range(10):
self.assertEqual(expected2[i],tmp.getIJ(0,i));
pass
p=[(0,2),(-1,2),(5,6)]
dac=da.deepCopy();
dac.setContigPartOfSelectedValuesSlice(1,da2,2,4,1);
expected3=[1,11,0,30,11,41,4,14,5,15,6,16,7,17]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected3[i],dac.getIJ(0,i));
pass
#
self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValuesSlice,3,da2,5,0,1);
dac.setContigPartOfSelectedValuesSlice(3,da2,1,5,1);
expected4=[1,11,2,12,3,13,9,39,0,30,11,41,12,42]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected4[i],dac.getIJ(0,i));
pass
#
ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
dac.setContigPartOfSelectedValues(2,da2,ids);
expected5=[1,11,2,12,0,30,8,38,12,42,6,16,7,17]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected5[i],dac.getIJ(0,i));
pass
#
dac=da.deepCopy();
dac.setContigPartOfSelectedValues(4,da2,ids);
expected6=[1,11,2,12,3,13,4,14,0,30,0,30,9,39]
- for i in xrange(14):
+ for i in range(14):
self.assertEqual(expected6[i],dac.getIJ(0,i));
pass
pass
m1.setCoords(myCoords1);
#
vec1=[0.,0.,1.]
- for i in xrange(18):
+ for i in range(18):
vec2=[3.*cos(pi/9.*i),3.*sin(pi/9.*i)];
m1Cpy=m1.deepCopy();
m1Cpy.translate(vec2);
d2=d1.convertToIntArr();
#
d1.abs();
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected1[i],d1.getIJ(0,i),14);
pass
#
expected2=[2,3,5,6,7,8,9,10,11,12,13,15]
d2.abs();
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(expected2[i],d2.getIJ(0,i));
pass
#
self.assertEqual(5,arr1.getNumberOfTuples());
self.assertEqual(3,arr1.getNumberOfComponents());
expected1=[5.7,57.,570.,6.5,65.,650.,5.,50.,500.,8.,80.,800.,7.,70.,700.]
- for i in xrange(15):
+ for i in range(15):
self.assertAlmostEqual(expected1[i],arr1.getIJ(0,i),14);
pass
pass
m1c.setCoordsAt(0,coordsX);
expected1=[[0,1],[1,2],[2,3],[3,4]]
self.assertEqual(4,m1c.getNumberOfCells())
- for i in xrange(m1c.getNumberOfCells()):
+ for i in range(m1c.getNumberOfCells()):
self.assertEqual(expected1[i],m1c.getNodeIdsOfCell(i))
pass
# test in 2D
self.assertEqual(12,m1c.getNumberOfCells())
self.assertEqual(20,m1c.getNumberOfNodes())
expected2=[[0,1,6,5],[1,2,7,6],[2,3,8,7],[3,4,9,8],[5,6,11,10],[6,7,12,11],[7,8,13,12],[8,9,14,13],[10,11,16,15],[11,12,17,16],[12,13,18,17],[13,14,19,18]]
- for i in xrange(m1c.getNumberOfCells()):
+ for i in range(m1c.getNumberOfCells()):
self.assertEqual(expected2[i],m1c.getNodeIdsOfCell(i))
pass
# test in 3D
self.assertEqual(60,m1c.getNumberOfNodes())
expected3=[[0,1,6,5,20,21,26,25],[1,2,7,6,21,22,27,26],[2,3,8,7,22,23,28,27],[3,4,9,8,23,24,29,28],[5,6,11,10,25,26,31,30],[6,7,12,11,26,27,32,31],[7,8,13,12,27,28,33,32],[8,9,14,13,28,29,34,33],[10,11,16,15,30,31,36,35],[11,12,17,16,31,32,37,36],[12,13,18,17,32,33,38,37],[13,14,19,18,33,34,39,38],[20,21,26,25,40,41,46,45],[21,22,27,26,41,42,47,46],[22,23,28,27,42,43,48,47],[23,24,29,28,43,44,49,48],[25,26,31,30,45,46,51,50],[26,27,32,31,46,47,52,51],[27,28,33,32,47,48,53,52],[28,29,34,33,48,49,54,53],[30,31,36,35,50,51,56,55],[31,32,37,36,51,52,57,56],[32,33,38,37,52,53,58,57],[33,34,39,38,53,54,59,58]]
self.assertEqual(24,m1c.getNumberOfCells())
- for i in xrange(m1c.getNumberOfCells()):
+ for i in range(m1c.getNumberOfCells()):
self.assertEqual(expected3[i],m1c.getNodeIdsOfCell(i))
pass
pass
-
+
pass
if __name__ == '__main__':
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
from sys import platform
def checkFreeMemory(size):
dic['free'] = tmp
dic['used'] = int(dic['total']) - int(dic['free'])
ret = dic['free'] > size
- #TODO: extend this method for Windows OS
+ #TODO: extend this method for Windows OS
return ret
class MEDCouplingBasicsTest4(unittest.TestCase):
def testSwigDADOp4(self):
- da=DataArrayDouble.New(range(6,30),12,2)
+ da = DataArrayDouble.New(list(range(6, 30)), 12, 2)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
pass
# operator transpose
da.transpose()
self.assertEqual(2,da.getNumberOfTuples());
self.assertEqual(12,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
pass
da.transpose()
da2=DataArrayDouble.New(12,1)
da2.iota(0.)
dabis=-da
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(dabis.getIJ(0,i),-float(i+6),13)
pass
# operator+=
da+=da2
expected1=[6.,7.,9.,10.,12.,13.,15.,16.,18.,19.,21.,22.,24.,25.,27.,28.,30.,31.,33.,34.,36.,37.,39.,40.]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
pass
da=-dabis
expected2=[106.,108.,108.,110.,110.,112.,112.,114.,114.,116.,116.,118.,118.,120.,120.,122.,122.,124.,124.,126.,126.,128.,128.,130.]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
pass
for pos,elt in enumerate(dabis):
self.assertAlmostEqual(li[0],100.,13) ; self.assertAlmostEqual(li[1],101.,13)
pass
# operator-=
- da=DataArrayDouble.New(range(6,30),12,2)
- da2=DataArrayDouble.New(range(12),12,1)
+ da = DataArrayDouble.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayDouble.New(list(range(12)), 12, 1)
dabis=-da
da-=da2
expected1=[6.,7.,7.,8.,8.,9.,9.,10.,10.,11.,11.,12.,12.,13.,13.,14.,14.,15.,15.,16.,16.,17.,17.,18.]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
pass
da=-dabis
expected2=[-94.,-94.,-92.,-92.,-90.,-90.,-88.,-88.,-86.,-86.,-84.,-84.,-82.,-82.,-80.,-80.,-78.,-78.,-76.,-76.,-74.,-74.,-72.,-72.]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
pass
for pos,elt in enumerate(dabis):
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected3=[-88.,-87.,-84.,-83.,-80.,-79.,-76.,-75.,-72.,-71.,-68.,-67.,-64.,-63.,-60.,-59.,-56.,-55.,-52.,-51.,-48.,-47.,-44.,-43.]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
pass
# operator*=
- da=DataArrayDouble.New(range(6,30),12,2)
- da2=DataArrayDouble.New(range(12),12,1)
+ da = DataArrayDouble.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayDouble.New(list(range(12)), 12, 1)
dabis=-da
da*=da2
expected1=[0.,0.,8.,9.,20.,22.,36.,39.,56.,60.,80.,85.,108.,114.,140.,147.,176.,184.,216.,225.,260.,270.,308.,319.]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
pass
da=-dabis
expected2=[600.,707.,800.,909.,1000.,1111.,1200.,1313.,1400.,1515.,1600.,1717.,1800.,1919.,2000.,2121.,2200.,2323.,2400.,2525.,2600.,2727.,2800.,2929.]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
pass
for pos,elt in enumerate(dabis):
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected3=[-3600.,-4949.,-6400.,-8181.,-10000.,-12221.,-14400.,-17069.,-19600.,-22725.,-25600.,-29189.,-32400.,-36461.,-40000.,-44541.,-48400.,-53429.,-57600.,-63125.,-67600.,-73629.,-78400.,-84941.0]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
pass
# operator/=
- da=DataArrayDouble.New(range(6,30),12,2)
- da2=DataArrayDouble.New(range(1,13),12,1)
+ da = DataArrayDouble.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayDouble.New(list(range(1, 13)), 12, 1)
dabis=-da
da/=da2
expected1=[6.0,7.0,4.0,4.5,3.3333333333333335,3.6666666666666665,3.0,3.25,2.8,3.0,2.6666666666666665,2.8333333333333335,2.5714285714285716,2.7142857142857144,2.5,2.625,2.4444444444444446,2.5555555555555554,2.4,2.5,2.3636363636363638,2.4545454545454546,2.3333333333333335,2.4166666666666665]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
pass
da=-dabis
expected2=[0.06,0.06930693069306931,0.08,0.0891089108910891,0.1,0.10891089108910891,0.12,0.12871287128712872,0.14,0.1485148514851485,0.16,0.16831683168316833,0.18,0.18811881188118812,0.2,0.2079207920792079,0.22,0.22772277227722773,0.24,0.24752475247524752,0.26,0.26732673267326734,0.28,0.2871287128712871]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
pass
for pos,elt in enumerate(dabis):
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected3=[-0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.0099009900990099]
- for i in xrange(24):
+ for i in range(24):
self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
pass
pass
def testSwigDAIOp4(self):
- da=DataArrayInt.New(range(6,30),12,2)
+ da = DataArrayInt.New(list(range(6, 30)), 12, 2)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),i+6)
pass
# operator transpose
da.transpose()
self.assertEqual(2,da.getNumberOfTuples());
self.assertEqual(12,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),i+6)
pass
da.transpose()
da2=DataArrayInt.New(12,1)
da2.iota(0)
dabis=-da
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(dabis.getIJ(0,i),-(i+6))
pass
# operator+=
da+=da2
expected1=[6,7,9,10,12,13,15,16,18,19,21,22,24,25,27,28,30,31,33,34,36,37,39,40]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected1[i])
pass
da=-dabis
expected2=[106,108,108,110,110,112,112,114,114,116,116,118,118,120,120,122,122,124,124,126,126,128,128,130]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected2[i])
pass
for pos,elt in enumerate(dabis):
self.assertEqual(li[0],100) ; self.assertEqual(li[1],101)
pass
# operator-=
- da=DataArrayInt.New(range(6,30),12,2)
- da2=DataArrayInt.New(range(12),12,1)
+ da = DataArrayInt.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayInt.New(list(range(12)), 12, 1)
dabis=-da
da-=da2
expected1=[6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected1[i])
pass
da=-dabis
expected2=[-94,-94,-92,-92,-90,-90,-88,-88,-86,-86,-84,-84,-82,-82,-80,-80,-78,-78,-76,-76,-74,-74,-72,-72]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected2[i])
pass
for pos,elt in enumerate(dabis):
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected3=[-88,-87,-84,-83,-80,-79,-76,-75,-72,-71,-68,-67,-64,-63,-60,-59,-56,-55,-52,-51,-48,-47,-44,-43]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected3[i])
pass
# operator*=
- da=DataArrayInt.New(range(6,30),12,2)
- da2=DataArrayInt.New(range(12),12,1)
+ da = DataArrayInt.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayInt.New(list(range(12)), 12, 1)
dabis=-da
da*=da2
expected1=[0,0,8,9,20,22,36,39,56,60,80,85,108,114,140,147,176,184,216,225,260,270,308,319]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected1[i])
pass
da=-dabis
expected2=[600,707,800,909,1000,1111,1200,1313,1400,1515,1600,1717,1800,1919,2000,2121,2200,2323,2400,2525,2600,2727,2800,2929]
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected2[i])
pass
for pos,elt in enumerate(dabis):
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected3=[-3600,-4949,-6400,-8181,-10000,-12221,-14400,-17069,-19600,-22725,-25600,-29189,-32400,-36461,-40000,-44541,-48400,-53429,-57600,-63125,-67600,-73629,-78400,-84941.0]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected3[i])
pass
# operator/=
- da=DataArrayInt.New(range(6,30),12,2)
- da2=DataArrayInt.New(range(1,13),12,1)
+ da = DataArrayInt.New(list(range(6, 30)), 12, 2)
+ da2 = DataArrayInt.New(list(range(1, 13)), 12, 1)
dabis=-da
da/=da2
expected1=[6,7,4,4,3,3,3,3,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected1[i])
pass
da=-dabis
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
expected2=[3,2,4,3,5,3,6,4,7,5,8,5,9,6,10,7,11,7,12,8,13,9,14,9]
- for i in xrange(24):
+ for i in range(24):
self.assertEqual(da.getIJ(0,i),expected2[i])
pass
pass
self.assertEqual(4,da3.getNumberOfTuples());
self.assertEqual(3,da3.getNumberOfComponents());
expected1=[10.,11.,12.,16.,17.,14.,17.,8.,13.,21.,20.,22.]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
pass
da3=da2+da
self.assertEqual(4,da3.getNumberOfTuples());
self.assertEqual(3,da3.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
pass
# Test new API of classmethod DataArrayDouble.New
da=DataArrayDouble.New(vals)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
pass
da=DataArrayDouble.New(vals,12)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
pass
da=DataArrayDouble.New(vals,1,12)
self.assertEqual(1,da.getNumberOfTuples());
self.assertEqual(12,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
pass
da=DataArrayDouble.New(vals,6,2)
self.assertEqual(6,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
pass
da=DataArrayDouble.New(vals,4,3)
self.assertEqual(4,da.getNumberOfTuples());
self.assertEqual(3,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
pass
self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
self.assertEqual(4,da3.getNumberOfTuples());
self.assertEqual(3,da3.getNumberOfComponents());
expected1=[10,11,12,16,17,14,17,8,13,21,20,22]
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da3.getIJ(0,i),expected1[i])
pass
da3=da2+da
self.assertEqual(4,da3.getNumberOfTuples());
self.assertEqual(3,da3.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da3.getIJ(0,i),expected1[i])
pass
da3=da+DataArrayInt.New(da2.getValues())
da=DataArrayDouble.New(vals)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da.getIJ(0,i),vals[i])
pass
da=DataArrayDouble.New(vals,12)
self.assertEqual(12,da.getNumberOfTuples());
self.assertEqual(1,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da.getIJ(0,i),vals[i])
pass
da=DataArrayDouble.New(vals,1,12)
self.assertEqual(1,da.getNumberOfTuples());
self.assertEqual(12,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da.getIJ(0,i),vals[i])
pass
da=DataArrayDouble.New(vals,6,2)
self.assertEqual(6,da.getNumberOfTuples());
self.assertEqual(2,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da.getIJ(0,i),vals[i])
pass
da=DataArrayDouble.New(vals,4,3)
self.assertEqual(4,da.getNumberOfTuples());
self.assertEqual(3,da.getNumberOfComponents());
- for i in xrange(12):
+ for i in range(12):
self.assertEqual(da.getIJ(0,i),vals[i])
pass
self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
self.assertEqual(8,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
expected1=[8,11,12,9,4,5,6,7]
- for i in xrange(8):
+ for i in range(8):
self.assertEqual(expected1[i],da2.getIJ(i,0));
pass
#
self.assertTrue(da1==None);
self.assertEqual(9,da2.getNumberOfTuples());
self.assertEqual(1,da2.getNumberOfComponents());
- for i in xrange(9):
+ for i in range(9):
self.assertEqual(8+i,da2.getIJ(i,0));
pass
#
self.assertEqual(expected2,mesh3D_4.getNodalConnectivity().getValues());
self.assertEqual(expected3,mesh2D_4.getNodalConnectivity().getValues());
self.assertEqual(expected4,mesh2D_5.getNodalConnectivity().getValues());
- for i in xrange(78):
+ for i in range(78):
self.assertAlmostEqual(expected5[i],mesh3D_4.getCoords().getIJ(0,i),12);
pass
#
self.assertEqual(expected6,mesh3D_4.getNodalConnectivity().getValues());
self.assertEqual(expected7,mesh2D_4.getNodalConnectivity().getValues());
self.assertEqual(expected8,mesh2D_5.getNodalConnectivity().getValues());
- for i in xrange(57):
+ for i in range(57):
self.assertAlmostEqual(expected9[i],mesh3D_4.getCoords().getIJ(0,i),12);
pass
#
pass
-
+
def testComputeNeighborsOfCells1(self):
m=MEDCouplingDataForTest.build2DTargetMesh_1();
d1,d2=m.computeNeighborsOfCells();
self.assertTrue(subMesh.isEqual(m5,1e-12))
self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[1,5],True);
pass
-
+
def testSwigGetItem3(self):
da=DataArrayInt.New([4,5,6])
self.assertEqual(5,da[1])
res=d1.getMinMaxPerComponent();
self.assertTrue(isinstance(res,list))
self.assertEqual(3,len(res))
- for i in xrange(3):
+ for i in range(3):
self.assertTrue(isinstance(res[i],tuple))
self.assertEqual(2,len(res[i]))
pass
expected1=[-0.9,1.3,1.7,2.1,3.,3.]
- for i in xrange(6):
- self.assertAlmostEqual(expected1[i],res[i/2][i%2],14)
+ for i in range(6):
+ self.assertAlmostEqual(expected1[i], res[i // 2][i % 2], 14)
pass
#
d1.rearrange(2);
res=d1.getMinMaxPerComponent();
self.assertTrue(isinstance(res,list))
self.assertEqual(2,len(res))
- for i in xrange(2):
+ for i in range(2):
self.assertTrue(isinstance(res[i],tuple))
self.assertEqual(2,len(res[i]))
pass
expected2=[1.,3.,-0.9,3.]
- for i in xrange(4):
- self.assertAlmostEqual(expected2[i],res[i/2][i%2],14)
+ for i in range(4):
+ self.assertAlmostEqual(expected2[i], res[i // 2][i % 2], 14)
pass
#
d1.rearrange(1);
res=d1.getMinMaxPerComponent();
self.assertTrue(isinstance(res,list))
self.assertEqual(1,len(res))
- for i in xrange(1):
+ for i in range(1):
self.assertTrue(isinstance(res[i],tuple))
self.assertEqual(2,len(res[i]))
pass
expected3=[-0.9,3.]
- for i in xrange(2):
- self.assertAlmostEqual(expected3[i],res[i/2][i%2],14)
+ for i in range(2):
+ self.assertAlmostEqual(expected3[i], res[i // 2][i % 2], 14)
pass
pass
def testDataArrayIntGetHashCode1(self):
- d1=DataArrayInt.New(range(3545))
- d2=DataArrayInt.New(range(3545))
+ d1 = DataArrayInt.New(list(range(3545)))
+ d2 = DataArrayInt.New(list(range(3545)))
self.assertEqual(d2.getHashCode(),d1.getHashCode())
self.assertEqual(232341068,d1.getHashCode())
d1[886]=6
d-=2
d%=7
pass
-
+
def testSwigDAIOp5(self):
d=DataArrayInt.New([4,5,6,10,3,-1],2,3)
self.toSeeIfDaIIopsAreOK(d)
dExp=DataArrayInt.New([2,4,6,0,0,6],2,3)
self.assertTrue(d.isEqual(dExp));
pass
-
+
def toSeeIfDaDIopsAreOK(self,d):
d+=5
d*=6
#
m=MEDCouplingUMesh.New("convexhull",2);
m.allocateCells(331);
- for i in xrange(331):
+ for i in range(331):
m.insertNextCell(NORM_POLYGON,conn[connI[i]:connI[i+1]]);
pass
m.finishInsertingCells();
expected3=[1.,2.,4.,5.,6.,7.]
self.assertEqual(6,ard1.getNumberOfTuples());
self.assertEqual(1,ard1.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected3[i],ard1.getIJ(i,0),12)
pass
ard2.sort(False);
expected4=[7.,6.,5.,4.,2.,1.]
self.assertEqual(6,ard2.getNumberOfTuples());
self.assertEqual(1,ard2.getNumberOfComponents());
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected4[i],ard2.getIJ(i,0),12)
pass
pass
-
+
def testPartitionBySpreadZone1(self):
m=MEDCouplingDataForTest.build2DTargetMesh_1();
m4=MEDCouplingUMesh.MergeUMeshes([m,m[-3:],m[0:2]]);
pass
def testSwigBugNonRegressionZipDA(self):
- angles=map(lambda x:pi/3*x,xrange(6))
+ angles = [pi / 3 * x for x in range(6)]
radius=3
#
dad=DataArrayDouble.New(6, 2)
valuesToTest=f.getValueOnMulti(targetPointCoordsX);
self.assertEqual(40,valuesToTest.getNumberOfTuples());
self.assertEqual(1,valuesToTest.getNumberOfComponents());
- for i in xrange(40):
+ for i in range(40):
self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
pass
fd=f.getDiscretization()
coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
mQ8.allocateCells(1)
- mQ8.insertNextCell(NORM_QUAD8,range(8))
+ mQ8.insertNextCell(NORM_QUAD8, list(range(8)))
mQ8.finishInsertingCells()
mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
mQ4.allocateCells(1)
- mQ4.insertNextCell(NORM_QUAD4,range(4))
+ mQ4.insertNextCell(NORM_QUAD4, list(range(4)))
mQ4.finishInsertingCells()
mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
mT3.allocateCells(1)
- mT3.insertNextCell(NORM_TRI3,range(3))
+ mT3.insertNextCell(NORM_TRI3, list(range(3)))
mT3.finishInsertingCells()
tr=[[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.],[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[22.,4.]]
self.assertRaises(InterpKernelException,arr.transformWithIndArr,d)
pass
+ def testIntersect2DMeshesTmp6(self):
+ # coordinates
+ coords=DataArrayDouble.New([2.7554552980815448e-15,45,-45,5.5109105961630896e-15,-31.819805153394636,31.81980515339464,2.8779199779962799e-15,47,2.8166876380389124e-15,46,-47,5.7558399559925599e-15,-33.234018715767732,33.234018715767739,-46,5.6333752760778247e-15],8,2);
+ # connectivity
+ conn=DataArrayInt.New([8,0,3,5,1,4,6,7,2])
+ connI=DataArrayInt.New([0,9]);
+ m1=MEDCouplingUMesh.New("Fixe",2);
+ m1.setCoords(coords);
+ m1.setConnectivity(conn,connI,True);
+ #
+ coords=DataArrayDouble.New([-7.3800475508445391,41.854329503018846,-3.7041190667754655,42.338274668899189,-3.7041190667754655,45.338274668899189,-7.3800475508445382,44.854329503018839,-5.5473631693521845,42.136406608386956,-3.7041190667754655,43.838274668899189,-5.5420833088100014,45.09630208595901,-7.3800475508445382,43.354329503018839,-3.7041190667754651,52.338274668899189,-7.3800475508445382,51.854329503018839,-3.7041190667754655,48.838274668899189,-5.5420833088100014,52.09630208595901,-7.3800475508445382,48.354329503018839],13,2);
+ # connectivity
+ conn=DataArrayInt.New([8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12]);
+ connI=DataArrayInt.New([0,9,18]);
+ #
+ m2=MEDCouplingUMesh.New("Mobile",2);
+ m2.setCoords(coords);
+ m2.setConnectivity(conn,connI,True);
+ #
+ m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10);
+ self.assertTrue(d1.isEqual(DataArrayInt([0,0,0,0])));
+ self.assertTrue(d2.isEqual(DataArrayInt([0,1,-1,-1])));
+ self.assertEqual(4,m3.getNumberOfCells());
+ self.assertEqual(4,d1.getNumberOfTuples());
+ self.assertEqual(4,d2.getNumberOfTuples());
+ self.assertEqual(43,m3.getNumberOfNodes());
+ dI,areMerged,newNbOfNodes=m3.mergeNodes(1e-12)
+ self.assertEqual(35,m3.getNumberOfNodes());
+ m3.zipCoords();
+ self.assertEqual(23,m3.getNumberOfNodes());
+ #
+ f=m3.getMeasureField(True);
+ valuesExpected=DataArrayDouble([1.6603638692585716,5.747555728471923,129.68907101754394,7.4162714498559694])
+ self.assertTrue(f.getArray().isEqual(valuesExpected,1e-12))
+ pass
+
def testDAPushBack(self):
d=DataArrayDouble(0,1)
- for i in xrange(8):
+ for i in range(8):
d.pushBackSilent(i)
pass
self.assertEqual(d.getNumberOfTuples(),8)
self.assertTrue(d.isEqual(DataArrayDouble([4.44,5.55,6.66]),1e-12))
#
d=DataArrayInt(0,1)
- for i in xrange(8):
+ for i in range(8):
d.pushBackSilent(i)
pass
self.assertEqual(d.getNumberOfTuples(),8)
#
m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented
- m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented
+ m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented
m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0)
self.assertRaises(InterpKernelException,m4.insertNextCell,NORM_HEXGP12,[0,1,2,3,4,5,6,7,8,9,10,11,12]);
m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
expected1=DataArrayDouble([0.16666666666666666,0.3333333333333333,0.5,1.,1.])
for v in vects:
- for i in xrange(nbOfDisc):
+ for i in range(nbOfDisc):
mm=m.deepCopy()
mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
mm2=mm.deepCopy()
#
mOK=m.deepCopy()
m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,2,1,3]); #Not well oriented
- m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented
- m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented
+ m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented
+ m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented
m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,3,2,1,4,7,6,5]); #Not well oriented
m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12,[0,5,4,3,2,1,6,11,10,9,8,7]); #Not well oriented
m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
expected2=DataArrayDouble([-0.16666666666666666,0.3333333333333333,0.5,-1.,-1.])
for v in vects:
- for i in xrange(nbOfDisc):
+ for i in range(nbOfDisc):
mm=m.deepCopy()
mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
mm2=mm.deepCopy() ; mm3=mm.deepCopy() ; mm3.convertAllToPoly()
pass
#
m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
- m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,3,2,1,4]); #Not well oriented
- m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,2,1,3,5,4]); #Not well oriented
+ m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,3,2,1,4]); #Not well oriented
+ m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,2,1,3,5,4]); #Not well oriented
m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
- m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12,range(12)); #Well oriented
+ m4 = MEDCouplingUMesh("m", 3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12, list(range(12))); # Well oriented
m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
expected3=DataArrayDouble([0.16666666666666666,-0.3333333333333333,-0.5,1.,1.])
for v in vects:
- for i in xrange(nbOfDisc):
+ for i in range(nbOfDisc):
mm=m.deepCopy()
mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
mm2=mm.deepCopy() ; mm3=mm.deepCopy() ; mm3.convertAllToPoly()
def testSwig2CellOrientation1(self):
coords=DataArrayDouble([-0.21606,-0.10803,0.29999999999999999,-0.21606,-0.10803,0.37700000000000006,0,-0.10803,0.29999999999999999,0,-0.10803,0.37700000000000006,0,0.10803,0.29999999999999999,0,0.10803,0.37700000000000006,-0.21606,0.10803,0.29999999999999999,-0.21606,0.10803,0.37700000000000006,0,0.03601,0.29999999999999999,0,0.03601,0.37700000000000006,0,-0.03601,0.29999999999999999,0,-0.03601,0.37700000000000006],12,3)
conn=[[0,2,10,8,4,6],[1,3,11,9,5,7],[0,1,3,2],[2,3,11,10],[10,11,9,8],[8,9,5,4],[4,5,7,6],[6,7,1,0]]
- for i in xrange(256):
+ for i in range(256):
mesh=MEDCouplingUMesh("FluidMesh_1",3);
mesh.allocateCells(0)
conn2=[elt[:] for elt in conn]
m.insertNextCell(NORM_TRI3,[0,1,2])
a,b=m.distanceToPoint([-0.335,2.27,1.21])
self.assertEqual(0,b)
- self.assertAlmostEqual(0.022360988100374124,a,14);
+ self.assertAlmostEqual(0.0223609881003,a,12);
a,b=m.distanceToPoint(DataArrayDouble([-0.335,2.27,1.21],1,3))
self.assertEqual(0,b)
- self.assertAlmostEqual(0.022360988100374124,a,14);
+ self.assertAlmostEqual(0.0223609881003,a,12);
a,b=coords.distanceToTuple([-0.335,2.27,1.21])
self.assertAlmostEqual(5.243302871282566,a,14)
self.assertEqual(0,b)
self.assertAlmostEqual(0.07071067811865482,a,14) ; self.assertEqual(1,b) # self.assertEqual(2,c)
pass
+ def testSwig2UMeshDistanceToMesh2(self):
+ mesh = MEDCouplingUMesh('Solid_3', 2)
+ coo = DataArrayDouble([(99.75,-1.42109e-14,102.75),(99.75,200,102.75),(2.5,0,200),(2.5,200,200),(197,0,200),(197,200,200)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([3, 4, 0, 1, 3, 4, 1, 5, 3, 1, 0, 3, 3, 3, 0, 2])
+ cI = DataArrayInt([0, 4, 8, 12, 16])
+ mesh.setConnectivity(c, cI)
+ mesh.checkConsistency()
+ pt = [125.0, 175.0, 175.0]
+ # Values computed from GEOM:
+ exp1, exp2, exp3, exp4 = 54.0633707597, 33.2340187158, 68.9429111657, 99.5221476482
+ d1, _ = mesh[0].distanceToPoint(pt)
+ d2, _ = mesh[1].distanceToPoint(pt)
+ d3, _ = mesh[2].distanceToPoint(pt)
+ d4, _ = mesh[3].distanceToPoint(pt)
+ self.assertAlmostEqual(exp1,d1,10)
+ self.assertAlmostEqual(exp2,d2,10)
+ self.assertAlmostEqual(exp3,d3,10)
+ self.assertAlmostEqual(exp4,d4,10)
+ pass
+
def testSwig2NonRegressionPartitionBySpreadZone1(self):
m=MEDCouplingCMesh()
arr=DataArrayDouble(6) ; arr.iota(0.)
coords=DataArrayDouble([0.,0.,1.,1.,1.,0.]) ; m.setCoords(coords)
da=DataArrayInt([0,1,2])
m.allocateCells(0)
- for i in xrange(5):
+ for i in range(5):
m.insertNextCell(NORM_TRI3,da)
pass
self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2])))
#
da=DataArrayInt([0,1,2,3])
m.allocateCells(0)
- for i in xrange(5):
+ for i in range(5):
m.insertNextCell(NORM_TRI3,3,da)
pass
self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2])))
pass
def testSwigSetItem3(self):
- # 1-2
+ # 1-2
d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
d[3]=[1,2]
self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,1,2,0,0,0,0],6,2),1e-14))
d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
d[1::2,:]=[3,9]
self.assertTrue(d.isEqual(DataArrayDouble([0,0,3,9,0,0,3,9,0,0,3,9],6,2),1e-14))
- # 1-2
+ # 1-2
d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
d[3]=[1,2]
self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,1,2,0,0,0,0],6,2)))
m3D.convertLinearCellsToQuadratic(0)
m3D.checkConsistency()
# check of new m3D content
- coordsExp2=[coordsExp.changeNbOfComponents(3,i) for i in xrange(4)]
- coordsExp3=[DataArrayDouble.Meld(cooTmp[:,[0,1]],cooTmp[:,2]+(0.5+float(i))) for i in xrange(3)]
+ coordsExp2 = [coordsExp.changeNbOfComponents(3, i) for i in range(4)]
+ coordsExp3 = [DataArrayDouble.Meld(cooTmp[:, [0, 1]], cooTmp[:, 2] + (0.5 + float(i))) for i in range(3)]
coordsExp4=DataArrayDouble.Aggregate([coordsExp2[0],coordsExp3[0],coordsExp2[1],coordsExp3[1],coordsExp2[2],coordsExp3[2],coordsExp2[3]])
c=DataArrayDouble.Aggregate(m3D.getCoords(),coordsExp4)
self.assertEqual(len(coordsExp4),115)
def testSwig2DataArrayAsciiChar1(self):
alpha=DataArrayInt(26) ; alpha.iota(ord("A"))
d=DataArrayAsciiChar(alpha.getValues(),2,13)
- d.setInfoOnComponents(["c%i"%(v) for v in xrange(13)])
+ d.setInfoOnComponents(["c%i" % (v) for v in range(13)])
self.assertEqual('ABCDEFGHIJKLM',d.getTuple(0))
self.assertEqual('NOPQRSTUVWXYZ',d.getTuple(1))
self.assertEqual(2,d.getNumberOfTuples())
self.assertTrue(mea.getArray().isEqual(DataArrayDouble([-0.08504076274779823,-0.06378057206084897,-0.08504076274779869,-0.10630095343474463,-0.12756114412169625,-0.10630095343474734,-0.0637805720608491,-0.0850407627477968,-0.1063009534347449,-0.0850407627477994,-0.10630095343474809,-0.1275611441216954,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.03879154890291829,-0.03879154890291829,-0.03879154890291829,-0.04120270848015563,-0.04120270848015563,-0.04120270848015563,-0.03393028948486933,-0.03393028948486933,-0.03393028948486933,-0.03151955746491709,-0.03151955746491709,-0.03151955746491709,-0.02424752187358276,-0.02424752187358276,-0.02424752187358276,-0.026657914642918758,-0.026657914642918758,-0.026657914642918758,-0.04120270848015456,-0.04120270848015456,-0.04120270848015456,-0.03879154890291757,-0.03879154890291757,-0.03879154890291757,-0.031519557464916595,-0.031519557464916595,-0.031519557464916595,-0.03393028948487046,-0.03393028948487046,-0.03393028948487046,-0.0266579146429191,-0.0266579146429191,-0.0266579146429191,-0.024247521873582645,-0.024247521873582645,-0.024247521873582645,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.04740400437515433,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.038785094488762675,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.030166184602371443,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.04740400437515492,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.03878509448876231,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.030166184602371266]),1e-14))
f=MEDCouplingFieldDouble(ft)
arr=DataArrayDouble(126,2)
- arr[:,0]=range(126)
- arr[:,1]=range(126)
+ arr[:, 0] = list(range(126))
+ arr[:, 1] = list(range(126))
arr[:,1]+=1000
f.setArray(arr)
f.checkConsistencyLight()
def testSwig2DAReverseMultiCompo1(self):
d=DataArrayDouble(6,2)
- d[:,0]=range(6)
- d[:,1]=range(10,16)
+ d[:, 0] = list(range(6))
+ d[:, 1] = list(range(10, 16))
d.reverse()
self.assertTrue(d.isEqual(DataArrayDouble([5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],6,2),1e-14))
d=DataArrayDouble(7,2)
- d[:,0]=range(7)
- d[:,1]=range(10,17)
+ d[:, 0] = list(range(7))
+ d[:, 1] = list(range(10, 17))
d.reverse()
self.assertTrue(d.isEqual(DataArrayDouble([6.,16.,5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],7,2),1e-14))
#
d=DataArrayInt(6,2)
- d[:,0]=range(6)
- d[:,1]=range(10,16)
+ d[:, 0] = list(range(6))
+ d[:, 1] = list(range(10, 16))
d.reverse()
self.assertTrue(d.isEqual(DataArrayInt([5,15,4,14,3,13,2,12,1,11,0,10],6,2)))
d=DataArrayInt(7,2)
- d[:,0]=range(7)
- d[:,1]=range(10,17)
+ d[:, 0] = list(range(7))
+ d[:, 1] = list(range(10, 17))
d.reverse()
self.assertTrue(d.isEqual(DataArrayInt([6,16,5,15,4,14,3,13,2,12,1,11,0,10],7,2)))
pass
d4**=d3
self.assertTrue(d4.isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
pass
-
+
def testSwig2Baryenter3DForCellsWithVolumeZero1(self):
coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
m2=MEDCouplingUMesh("mesh",2)
d=DataArrayDouble()
self.assertTrue(len(d.__repr__())<120)
d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
- for i in xrange(100):
+ for i in range(100):
d.alloc(i,1) ; d.iota(1.1234567890123456) ; d*=1e123
self.assertTrue(len(d.__repr__())<500)
pass
- for i in xrange(50):
+ for i in range(50):
d.alloc(i,2) ; d.rearrange(1) ; d.iota(1.1234567890123456) ; d.rearrange(2) ; d*=1e123
self.assertTrue(len(d.__repr__())<500)
pass
d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
- for i in xrange(2,4):
+ for i in range(2, 4):
d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
pass
d.alloc(0,9)
d=DataArrayInt()
self.assertTrue(len(d.__repr__())<100)
d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
- for i in xrange(100):
+ for i in range(100):
d.alloc(i,1) ; d.iota(123456789)
self.assertTrue(len(d.__repr__())<500)
pass
- for i in xrange(50):
+ for i in range(50):
d.alloc(i,2) ; d.rearrange(1) ; d.iota(123456789) ; d.rearrange(2)
self.assertTrue(len(d.__repr__())<500)
pass
d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
- for i in xrange(2,10):
+ for i in range(2, 10):
d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
pass
d.alloc(0,9)
d.alloc(1000,3) ; d.fillWithValue(127)
self.assertTrue(len(d.__repr__())<500)
pass
-
+
def testSwig2MeshComputeIsoBarycenterOfNodesPerCell1(self):
coo=DataArrayDouble([26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.,26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.],24,3)
m=MEDCouplingUMesh.New("toto",3)
m2.allocateCells(0)
m2.setCoords(coo)
conn2=[[0,3,5,1,7,4,6,2],[12,14,16,18,13,15,17,19],[0,12,18,3,8,19,11,7],[3,18,16,5,11,17,10,4],[5,16,14,1,10,15,9,6],[1,14,12,0,9,13,8,2]]
- for i in xrange(6):
+ for i in range(6):
m2.insertNextCell(NORM_QUAD8,conn2[i])
pass
self.assertTrue(m2.isEqual(a,1e-12))
conn4=[[0,2,3,1,8,9,10,11,20],[4,5,6,7,15,14,13,12,25],[0,4,7,2,16,12,17,8,21],[2,7,6,3,17,13,18,9,22],[3,6,5,1,18,14,19,10,23],[1,5,4,0,19,15,16,11,24]]
m4=MEDCouplingUMesh("mesh",2)
m4.allocateCells(0)
- for i in xrange(6):
+ for i in range(6):
m4.insertNextCell(NORM_QUAD9,conn4[i])
pass
m4.setCoords(coo2)
self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
pass
-
+
def testSwigAdvGauss(self):
f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
f.setDiscretization(None)
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__add__,2)
- self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException, f.__add__, list(range(5)))
self.assertRaises(InterpKernelException,f.__add__,arr)
self.assertRaises(InterpKernelException,f.__add__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__add__,2)
- self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException, f.__add__, list(range(5)))
self.assertRaises(InterpKernelException,f.__add__,arr)
self.assertRaises(InterpKernelException,f.__add__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=f+2
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__sub__,2)
- self.assertRaises(InterpKernelException,f.__sub__,range(5))
+ self.assertRaises(InterpKernelException, f.__sub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__sub__,arr)
self.assertRaises(InterpKernelException,f.__sub__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__sub__,2)
- self.assertRaises(InterpKernelException,f.__sub__,range(5))
+ self.assertRaises(InterpKernelException, f.__sub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__sub__,arr)
self.assertRaises(InterpKernelException,f.__sub__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=f-2
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__mul__,2)
- self.assertRaises(InterpKernelException,f.__mul__,range(5))
+ self.assertRaises(InterpKernelException, f.__mul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__mul__,arr)
self.assertRaises(InterpKernelException,f.__mul__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__mul__,2)
- self.assertRaises(InterpKernelException,f.__mul__,range(5))
+ self.assertRaises(InterpKernelException, f.__mul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__mul__,arr)
self.assertRaises(InterpKernelException,f.__mul__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=f*2
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(1, 6)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__div__,2)
- self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException, f.__div__, list(range(5)))
self.assertRaises(InterpKernelException,f.__div__,arr)
self.assertRaises(InterpKernelException,f.__div__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__div__,2)
- self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException, f.__div__, list(range(5)))
self.assertRaises(InterpKernelException,f.__div__,arr)
self.assertRaises(InterpKernelException,f.__div__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
self.assertRaises(InterpKernelException,f.__div__,0)
ff=f/2
ff.checkConsistencyLight()
arr[:]=[1,1,3,2,0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__div__,2)
- self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException, f.__div__, list(range(5)))
self.assertRaises(InterpKernelException,f.__div__,arr)
self.assertRaises(InterpKernelException,f.__div__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__div__,2)
- self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException, f.__div__, list(range(5)))
self.assertRaises(InterpKernelException,f.__div__,arr)
self.assertRaises(InterpKernelException,f.__div__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,1)
- f.getArray()[:]=range(2,7)
+ f.getArray()[:] = list(range(2, 7))
ff=f**2
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([4,9,16,25,36]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__iadd__,2)
- self.assertRaises(InterpKernelException,f.__iadd__,range(5))
+ self.assertRaises(InterpKernelException, f.__iadd__, list(range(5)))
self.assertRaises(InterpKernelException,f.__iadd__,arr)
self.assertRaises(InterpKernelException,f.__iadd__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__iadd__,2)
- self.assertRaises(InterpKernelException,f.__iadd__,range(5))
+ self.assertRaises(InterpKernelException, f.__iadd__, list(range(5)))
self.assertRaises(InterpKernelException,f.__iadd__,arr)
self.assertRaises(InterpKernelException,f.__iadd__,f2)
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
f.checkConsistencyLight()
f+=2
f.checkConsistencyLight()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__isub__,2)
- self.assertRaises(InterpKernelException,f.__isub__,range(5))
+ self.assertRaises(InterpKernelException, f.__isub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__isub__,arr)
self.assertRaises(InterpKernelException,f.__isub__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__isub__,2)
- self.assertRaises(InterpKernelException,f.__isub__,range(5))
+ self.assertRaises(InterpKernelException, f.__isub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__isub__,arr)
self.assertRaises(InterpKernelException,f.__isub__,f2)
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
f.checkConsistencyLight()
f-=2
f.checkConsistencyLight()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__imul__,2)
- self.assertRaises(InterpKernelException,f.__imul__,range(5))
+ self.assertRaises(InterpKernelException, f.__imul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__imul__,arr)
self.assertRaises(InterpKernelException,f.__imul__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__imul__,2)
- self.assertRaises(InterpKernelException,f.__imul__,range(5))
+ self.assertRaises(InterpKernelException, f.__imul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__imul__,arr)
self.assertRaises(InterpKernelException,f.__imul__,f2)
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
f.checkConsistencyLight()
f*=2
f.checkConsistencyLight()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(1, 6)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__idiv__,2)
- self.assertRaises(InterpKernelException,f.__idiv__,range(5))
+ self.assertRaises(InterpKernelException, f.__idiv__, list(range(5)))
self.assertRaises(InterpKernelException,f.__idiv__,arr)
self.assertRaises(InterpKernelException,f.__idiv__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__idiv__,2)
- self.assertRaises(InterpKernelException,f.__idiv__,range(5))
+ self.assertRaises(InterpKernelException, f.__idiv__, list(range(5)))
self.assertRaises(InterpKernelException,f.__idiv__,arr)
self.assertRaises(InterpKernelException,f.__idiv__,f2)
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
f.checkConsistencyLight()
f/=2
f.checkConsistencyLight()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(1, 6)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__ipow__,2)
- self.assertRaises(InterpKernelException,f.__ipow__,range(5))
+ self.assertRaises(InterpKernelException, f.__ipow__, list(range(5)))
self.assertRaises(InterpKernelException,f.__ipow__,arr)
self.assertRaises(InterpKernelException,f.__ipow__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__ipow__,2)
- self.assertRaises(InterpKernelException,f.__ipow__,range(5))
+ self.assertRaises(InterpKernelException, f.__ipow__, list(range(5)))
self.assertRaises(InterpKernelException,f.__ipow__,arr)
self.assertRaises(InterpKernelException,f.__ipow__,f2)
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
f.checkConsistencyLight()
f**=2
f.checkConsistencyLight()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__radd__,2)
- self.assertRaises(InterpKernelException,f.__radd__,range(5))
+ self.assertRaises(InterpKernelException, f.__radd__, list(range(5)))
self.assertRaises(InterpKernelException,f.__radd__,arr)
self.assertRaises(InterpKernelException,f.__radd__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__radd__,2)
- self.assertRaises(InterpKernelException,f.__radd__,range(5))
+ self.assertRaises(InterpKernelException, f.__radd__, list(range(5)))
self.assertRaises(InterpKernelException,f.__radd__,arr)
self.assertRaises(InterpKernelException,f.__radd__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=2+f
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__rsub__,2)
- self.assertRaises(InterpKernelException,f.__rsub__,range(5))
+ self.assertRaises(InterpKernelException, f.__rsub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rsub__,arr)
self.assertRaises(InterpKernelException,f.__rsub__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__rsub__,2)
- self.assertRaises(InterpKernelException,f.__rsub__,range(5))
+ self.assertRaises(InterpKernelException, f.__rsub__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rsub__,arr)
self.assertRaises(InterpKernelException,f.__rsub__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=2-f
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(5)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__rmul__,2)
- self.assertRaises(InterpKernelException,f.__rmul__,range(5))
+ self.assertRaises(InterpKernelException, f.__rmul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rmul__,arr)
self.assertRaises(InterpKernelException,f.__rmul__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__rmul__,2)
- self.assertRaises(InterpKernelException,f.__rmul__,range(5))
+ self.assertRaises(InterpKernelException, f.__rmul__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rmul__,arr)
self.assertRaises(InterpKernelException,f.__rmul__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(5)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=2*f
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
arr=DataArrayDouble(5,2)
- arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ arr[:, 0] = list(range(1, 6)) ; arr[:, 1] = 2 * arr[:, 0]
f2=f.clone(True)
self.assertRaises(InterpKernelException,f.__rdiv__,2)
- self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
+ self.assertRaises(InterpKernelException, f.__rdiv__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rdiv__,arr)
self.assertRaises(InterpKernelException,f.__rdiv__,f2)
f.setArray(DataArrayDouble())
self.assertRaises(InterpKernelException,f.__rdiv__,2)
- self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
+ self.assertRaises(InterpKernelException, f.__rdiv__, list(range(5)))
self.assertRaises(InterpKernelException,f.__rdiv__,arr)
self.assertRaises(InterpKernelException,f.__rdiv__,f2)
self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
f.getArray().alloc(5,2)
- f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.getArray()[:, 0] = list(range(1, 6)) ; f.getArray()[:, 1] = f.getArray()[:, 0] + 7
ff=2/f
ff.checkConsistencyLight()
self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,0.25),(1,0.22222222222222221),(0.66666666666666663,0.20000000000000001),(0.5,0.18181818181818182),(0.40000000000000002,0.16666666666666666)]),1e-12))
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
class MEDCouplingBasicsTest5(unittest.TestCase):
def testSwig2FieldDoubleBuildSubPartRange1(self):
m=MEDCouplingDataForTest.build2DTargetMesh_1()
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m)
- arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0]
+ arr = DataArrayDouble(5, 2) ; arr[:, 0] = list(range(7, 12)) ; arr[:, 1] = 100 + arr[:, 0]
f.setArray(arr)
f.checkConsistencyLight()
ff=f[1:-1:2]
#ON_NODES
f=MEDCouplingFieldDouble(ON_NODES)
f.setMesh(m)
- arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0]
+ arr = DataArrayDouble(9, 2) ; arr[:, 0] = list(range(7, 16)) ; arr[:, 1] = 100 + arr[:, 0]
f.setArray(arr)
f.checkConsistencyLight()
ff=f[1:-1:2]
#ON_GAUSS_NE
f=MEDCouplingFieldDouble(ON_GAUSS_NE)
f.setMesh(m)
- arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0]
+ arr = DataArrayDouble(18, 2) ; arr[:, 0] = list(range(7, 25)) ; arr[:, 1] = 100 + arr[:, 0]
f.setArray(arr)
f.checkConsistencyLight()
ff=f[1:-1:2]
f.setGaussLocalizationOnCells([3],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2,3.,3.],[0.2,0.4,0.4]);
f.setGaussLocalizationOnCells([1],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.],[0.1,0.1,0.4,0.4]);
f.setGaussLocalizationOnCells([2],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.,5.,5.],[0.1,0.1,0.4,0.3,0.1]);
- arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0]
+ arr = DataArrayDouble(16, 2) ; arr[:, 0] = list(range(7, 23)) ; arr[:, 1] = 100 + arr[:, 0]
f.setArray(arr)
f.checkConsistencyLight()
ff=f[1:-1:2]
time_deb = datetime.now()
a1=DataArrayDouble(len(d))
b1=DataArrayInt(len(d))
- m1s=[m1[i] for i in xrange(m1.getNumberOfCells())]
+ m1s = [m1[i] for i in range(m1.getNumberOfCells())]
for j,pt in enumerate(d):
eter=1e308
fter=-1
m=MEDCouplingUMesh("mesh",2)
m.setCoords(coo)
m.allocateCells()
- for i in xrange(24):
+ for i in range(24):
m.insertNextCell(NORM_QUAD4,conn[4*i:4*i+4])
pass
m.checkConsistency()
d[:,1]*=pi/180. # angle in radian
d=d.fromPolarToCart()
d+=zeBary
- m=MEDCouplingUMesh("quad8",2) ; m.allocateCells() ; m.insertNextCell(NORM_QUAD8,range(8)) ; m.setCoords(d)
+ m = MEDCouplingUMesh("quad8", 2) ; m.allocateCells() ; m.insertNextCell(NORM_QUAD8, list(range(8))) ; m.setCoords(d)
self.assertTrue(m.computeCellCenterOfMass().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
tri32D=m.buildDescendingConnectivity()[0][0] ; tri32D.zipCoords()
d[:,1]*=pi/180. # angle in radian
d=d.fromPolarToCart()
d+=zeBary
- m=MEDCouplingUMesh("tri6",2) ; m.allocateCells() ; m.insertNextCell(NORM_TRI6,range(6)) ; m.setCoords(d)
+ m = MEDCouplingUMesh("tri6", 2) ; m.allocateCells() ; m.insertNextCell(NORM_TRI6, list(range(6))) ; m.setCoords(d)
self.assertTrue(m.computeCellCenterOfMass().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
# spaceDim=3 TRI6 becomes TRI3 ... for the moment
d[:,1]*=pi/180. # angle in radian
d=d.fromPolarToCart()
d+=zeBary
- m=MEDCouplingUMesh("qpolyg",2) ; m.allocateCells() ; m.insertNextCell(NORM_QPOLYG,range(10)) ; m.setCoords(d)
+ m = MEDCouplingUMesh("qpolyg", 2) ; m.allocateCells() ; m.insertNextCell(NORM_QPOLYG, list(range(10))) ; m.setCoords(d)
self.assertTrue(m.computeCellCenterOfMass().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
# spaceDim=3 QPOLYG becomes POLYG ... for the moment
s=slice(18,1,-2)
self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
self.assertRaises(InterpKernelException,DataArray.GetNumberOfItemGivenBES,s)
- self.assertEqual(sum([DataArray.GetNumberOfItemGivenBESRelative(DataArray.GetSlice(s,i,4)) for i in xrange(4)]),DataArray.GetNumberOfItemGivenBESRelative(s))
+ self.assertEqual(sum([DataArray.GetNumberOfItemGivenBESRelative(DataArray.GetSlice(s, i, 4)) for i in range(4)]), DataArray.GetNumberOfItemGivenBESRelative(s))
self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
#
maxNbCSN=nbOfCellsSharingNodes.getMaxValue()[0]
arr3=DataArrayDouble(f.getMesh().getNumberOfNodes(),f.getArray().getNumberOfComponents()) ; arr3[:]=0.
- for i in xrange(1,maxNbCSN+1):
+ for i in range(1, maxNbCSN + 1):
ids=nbOfCellsSharingNodes.findIdsEqual(i)
if len(ids)==0:
continue
m=MEDCoupling1SGTUMesh("m",NORM_QUAD4)
mem_m=m.getHeapMemorySize()
m.allocateCells(5)
- self.assertIn(m.getHeapMemorySize()-mem_m,xrange(5*4*4,5*4*4+32))
+ self.assertIn(m.getHeapMemorySize() - mem_m, list(range(5 * 4 * 4, 5 * 4 * 4 + 32)))
self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
m.setCoords(um.getCoords())
m.insertNextCell([1,0,6,7])
self.assertRaises(InterpKernelException,m.buildUnstructured().splitProfilePerType,invalidPfl)
##
pfl1=DataArrayInt([1,2,3])
- a=m.checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
+ a=m.getCellsContainingPointcheckTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
self.assertTrue(a.isEqual(b) and pfl1.getHiddenCppPointer(),a.getHiddenCppPointer())
#
valuesToTest=f.getValueOnMulti(targetPointCoordsXY);
self.assertEqual(196,valuesToTest.getNumberOfTuples());
self.assertEqual(1,valuesToTest.getNumberOfComponents());
- for i in xrange(40):
+ for i in range(40):
self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
pass
fd=f.getDiscretization()
#
trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
for i,t in enumerate(trs):
- for j in xrange(64):
+ for j in range(64):
j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
m11=m1.deepCopy()
m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
m.allocateCells()
# the cell description is exactly those described in the description of TRI7 in MED file 3.0.7 documentation
- m.insertNextCell(NORM_TRI7,range(7))
+ m.insertNextCell(NORM_TRI7, list(range(7)))
refCoords=[0.,0.,1.,0.,0.,1.,0.5,0.,0.5,0.5,0.,0.5,0.3333333333333333,0.3333333333333333]
gaussCoords=[0.3333333333333333,0.3333333333333333,0.470142064105115,0.470142064105115,0.05971587178977,0.470142064105115,0.470142064105115,0.05971587178977,0.101286507323456,0.101286507323456,0.797426985353088,0.101286507323456,0.101286507323456,0.797426985353088]
weights=[0.062969590272413,0.062969590272413,0.062969590272413,0.066197076394253,0.066197076394253,0.066197076394253,0.1125]
def testSwigBugOnUnpackingTuplesInDataArray1(self):
inp=DataArrayDouble([(1,2,3),(4,5,6),(7,8,9),(10,11,12)])
it=inp.__iter__()
- r=it.next()
+ r = next(it)
self.assertRaises(StopIteration,r.__getitem__,4)
self.assertEqual(len(r),3)
a,b,c=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
d,e,f=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
g,h,i=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
j,k,l=r
self.assertTrue(inp.isEqual(DataArrayDouble([a,b,c,d,e,f,g,h,i,j,k,l],4,3),1e-12))
########
inp=DataArrayInt([(1,2,3),(4,5,6),(7,8,9),(10,11,12)])
it=inp.__iter__()
- r=it.next()
+ r = next(it)
self.assertRaises(StopIteration,r.__getitem__,4)
self.assertEqual(len(r),3)
a,b,c=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
d,e,f=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
g,h,i=r
- r=it.next()
+ r = next(it)
self.assertEqual(len(r),3)
j,k,l=r
self.assertTrue(inp.isEqual(DataArrayInt([a,b,c,d,e,f,g,h,i,j,k,l],4,3)))
self.assertTrue(isinstance(g0[0],MEDCouplingCartesianAMRPatchGF))
g1=amr.retrieveGridsAt(1)
self.assertEqual(5,len(g1))
- for i in xrange(5):
+ for i in range(5):
self.assertTrue(isinstance(g1[i],MEDCouplingCartesianAMRPatch))
pass
pass
NORM_SEG2,11,12,NORM_SEG2,12,13,
NORM_SEG2,14,15])
cI = DataArrayInt([0,3,7,10,14,18,21,24,27,30])
- coords2 = DataArrayDouble([float(i) for i in range(32)], 16,2)
+ coords2 = DataArrayDouble([float(i) for i in range(32)], 16, 2)
m2.setCoords(coords2);
m2.setConnectivity(c, cI);
m2.checkConsistency(1.0e-8);
def testSwig2DAIGetIdsStrictlyNegative1(self):
d=DataArrayInt([4,-5,-1,0,3,99,-7])
- self.assertTrue(d.findIdsStricltyNegative().isEqual(DataArrayInt([1,2,6])))
+ self.assertTrue(d.findIdsStrictlyNegative().isEqual(DataArrayInt([1,2,6])))
pass
def testSwig2DAIReplaceOneValByInThis1(self):
li=[]
liExp3D=[(0,0,0),(1,0,0),(2,0,0),(3,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(0,0,1),(1,0,1),(2,0,1),(3,0,1),(0,1,1),(1,1,1),(2,1,1),(3,1,1),(0,2,1),(1,2,1),(2,2,1),(3,2,1)]
self.assertEqual(24,m.getNumberOfCells())
- for i in xrange(m.getNumberOfCells()):
+ for i in range(m.getNumberOfCells()):
li.append(m.getLocationFromCellId(i))
pass
self.assertEqual(liExp3D,li)
li=[]
liExp2D=[(0,0),(1,0),(2,0),(3,0),(0,1),(1,1),(2,1),(3,1),(0,2),(1,2),(2,2),(3,2)]
self.assertEqual(12,m.getNumberOfCells())
- for i in xrange(m.getNumberOfCells()):
+ for i in range(m.getNumberOfCells()):
li.append(m.getLocationFromCellId(i))
pass
self.assertEqual(liExp2D,li)
arrX=DataArrayDouble(5) ; arrX.iota()
m=MEDCouplingCMesh() ; m.setCoords(arrX)
self.assertEqual(4,m.getNumberOfCells())
- for i in xrange(m.getNumberOfCells()):
+ for i in range(m.getNumberOfCells()):
self.assertEqual((i,),m.getLocationFromCellId(i))
pass
self.assertRaises(InterpKernelException,m.getLocationFromCellId,4)
li=[]
liExp3D=[(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(0,3,0),(1,3,0),(2,3,0),(3,3,0),(4,3,0),(0,0,1),(1,0,1),(2,0,1),(3,0,1),(4,0,1),(0,1,1),(1,1,1),(2,1,1),(3,1,1),(4,1,1),(0,2,1),(1,2,1),(2,2,1),(3,2,1),(4,2,1),(0,3,1),(1,3,1),(2,3,1),(3,3,1),(4,3,1),(0,0,2),(1,0,2),(2,0,2),(3,0,2),(4,0,2),(0,1,2),(1,1,2),(2,1,2),(3,1,2),(4,1,2),(0,2,2),(1,2,2),(2,2,2),(3,2,2),(4,2,2),(0,3,2),(1,3,2),(2,3,2),(3,3,2),(4,3,2)]
self.assertEqual(60,m.getNumberOfNodes())
- for i in xrange(m.getNumberOfNodes()):
+ for i in range(m.getNumberOfNodes()):
li.append(m.getLocationFromNodeId(i))
pass
self.assertEqual(liExp3D,li)
li=[]
liExp2D=[(0,0),(1,0),(2,0),(3,0),(4,0),(0,1),(1,1),(2,1),(3,1),(4,1),(0,2),(1,2),(2,2),(3,2),(4,2),(0,3),(1,3),(2,3),(3,3),(4,3)]
self.assertEqual(20,m.getNumberOfNodes())
- for i in xrange(m.getNumberOfNodes()):
+ for i in range(m.getNumberOfNodes()):
li.append(m.getLocationFromNodeId(i))
pass
self.assertEqual(liExp2D,li)
arrX=DataArrayDouble(5) ; arrX.iota()
m=MEDCouplingCMesh() ; m.setCoords(arrX)
self.assertEqual(5,m.getNumberOfNodes())
- for i in xrange(m.getNumberOfNodes()):
+ for i in range(m.getNumberOfNodes()):
self.assertEqual((i,),m.getLocationFromNodeId(i))
pass
self.assertRaises(InterpKernelException,m.getLocationFromCellId,5)
st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
self.assertNotEqual(st0,st1) # 1001 tuples ( > 1000) -> str(d)==d.reprNotTooLong()
self.assertEqual(st1,st2)
- self.assertIn(len(st2),xrange(0,1000)) # no more than 1000 characters
+ self.assertIn(len(st2), list(range(0, 1000))) # no more than 1000 characters
## Now for DataArrayInt
d=DataArrayInt(2000) ; d.iota() ; d.rearrange(2)
st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
self.assertNotEqual(st0,st1) # 1001 tuples ( > 1000) -> str(d)==d.reprNotTooLong()
self.assertEqual(st1,st2)
- self.assertIn(len(st2),xrange(0,1000)) # no more than 1000 characters
+ self.assertIn(len(st2), list(range(0, 1000))) # no more than 1000 characters
pass
def testExtrudedMeshWithoutZipCoords1(self):
coo=DataArrayDouble([(0,2),(2,0),(6,4),(4,9)])
m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.setCoords(coo)
exp3=sqrt(85.)
- for delta in xrange(4):
- c=[(elt+delta)%4 for elt in xrange(4)]
+ for delta in range(4):
+ c = [(elt + delta) % 4 for elt in range(4)]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp3,12)
m2=m.buildUnstructured() ; m2.convertLinearCellsToQuadratic(0)
# QUAD4 - spacedim = 3
coo=DataArrayDouble([(0.26570992384234871,2.0405889913271817,-0.079134238105786903),(2.3739976619218064,0.15779148692781009,0.021842842914139737),(6.1207841448393197,4.3755532938679655,0.43666375769970678),(3.8363255342943359,9.2521096041694229,0.41551170895942313)])
m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.setCoords(coo)
- for delta in xrange(4):
- c=[(elt+delta)%4 for elt in xrange(4)]
+ for delta in range(4):
+ c = [(elt + delta) % 4 for elt in range(4)]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp3,12)
m2=m.buildUnstructured() ; m2.convertLinearCellsToQuadratic(0)
m=MEDCoupling1SGTUMesh("mesh",NORM_PENTA6) ; m.setCoords(coo)
exp4=2.5041256256889888
self.assertAlmostEqual(exp4,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter
- for delta in xrange(3):
- c=[(elt+delta)%3 for elt in xrange(3)]
+ for delta in range(3):
+ c = [(elt + delta) % 3 for elt in range(3)]
c+=[elt+3 for elt in c]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp4,12)
m=MEDCoupling1SGTUMesh("mesh",NORM_HEXA8) ; m.setCoords(coo)
exp5=2.5366409441884215
self.assertAlmostEqual(exp5,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter
- for delta in xrange(4):
- c=[(elt+delta)%4 for elt in xrange(4)]
+ for delta in range(4):
+ c = [(elt + delta) % 4 for elt in range(4)]
c+=[elt+4 for elt in c]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp5,12)
m=MEDCoupling1SGTUMesh("mesh",NORM_PYRA5) ; m.setCoords(coo)
exp6=2.1558368027391386
self.assertAlmostEqual(exp6,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter
- for delta in xrange(4):
- c=[(elt+delta)%4 for elt in xrange(4)]
+ for delta in range(4):
+ c = [(elt + delta) % 4 for elt in range(4)]
c+=[4]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp6,12)
m=MEDCoupling1SGTUMesh("mesh",NORM_PYRA5) ; m.setCoords(coo)
exp7=1.4413563787228953
self.assertAlmostEqual(exp7,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter
- for delta in xrange(4):
- c=[(elt+delta)%4 for elt in xrange(4)]
+ for delta in range(4):
+ c = [(elt + delta) % 4 for elt in range(4)]
c+=[4]
m.setNodalConnectivity(DataArrayInt(c))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp7,12)
exp8=1.7131322579364157
self.assertAlmostEqual(exp8,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter
for c in [[0,1,2,3],[0,3,2,1],[0,1,3,2],[0,2,3,1],[0,3,1,2],[0,2,1,3]]:
- for i in xrange(4):
+ for i in range(4):
m.setNodalConnectivity(DataArrayInt([(elt+i)%4 for elt in c]))
self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp8,12)
m2=m.buildUnstructured() ; m2.convertLinearCellsToQuadratic(0)
self.assertEqual(f2.getTime(),[1.,2,3])
pass
- def testBugInComputationOfEqOfPlane1(self):
- coo=DataArrayDouble([-1.0, 1.0, -0.3872983455657959, -1.0, 1.0, 0.3872983455657959, -1.0, 1.0, 0.693649172782898, 1.0, 1.0, 0.693649172782898, 1.0, 1.0, 0.3872983455657959, 1.0, 1.0, -0.3872983455657959],6,3)
- m=MEDCouplingUMesh("",2)
- m.setCoords(coo)
- m.allocateCells()
- m.insertNextCell(NORM_POLYGON,[0,1,2,3,4,5])
- self.assertTrue(m.computePlaneEquationOf3DFaces().isEqual(DataArrayDouble([0,1,0,-1],1,4),1e-12))
+ def testDADCumSum1(self):
+ d=DataArrayDouble([3.,2.,4.,5.])
+ self.assertTrue(d.cumSum().isEqual(DataArrayDouble([0.,3.,5.,9.,14.]),1e-12))
+ d2=DataArrayDouble([])
+ self.assertTrue(d2.cumSum().isEqual(DataArrayDouble([0.]),1e-12))
+ d.rearrange(2)
+ self.assertRaises(InterpKernelException,d.cumSum)
+ pass
+
+ def testDAIFromLinkedListOfPairToList1(self):
+ d=DataArrayInt([(5,7),(7,3),(3,12),(12,17)])
+ zeRes=DataArrayInt([5,7,3,12,17])
+ self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
+ d.rearrange(1)
+ self.assertRaises(InterpKernelException,d.fromLinkedListOfPairToList)
+ d.rearrange(2)
+ self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
+ d2=DataArrayInt([(5,7)])
+ self.assertTrue(d2.fromLinkedListOfPairToList().isEqual(DataArrayInt([5,7])))
+ d3=DataArrayInt([(5,7),(7,3),(4,12),(12,17)])
+ self.assertRaises(InterpKernelException,d3.fromLinkedListOfPairToList) # not a linked list of pair
+ d4=DataArrayInt([(5,7),(7,3),(12,3),(12,17)])
+ self.assertRaises(InterpKernelException,d4.fromLinkedListOfPairToList) # not a linked list of pair, but can be repaired !
+ d4.sortEachPairToMakeALinkedList()
+ self.assertTrue(d4.fromLinkedListOfPairToList().isEqual(zeRes))
+ pass
+
+ def testUMeshExplodeIntoEdges1(self):
+ m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured()
+ self.assertEqual(m.getMeshDimension(),3)
+ a0,a1,a2,a3,a4=m.explodeIntoEdges()
+ b0,b1,b2,b3,b4=m.explode3DMeshTo1D()
+ self.assertTrue(a0.isEqual(b0,1e-12))
+ self.assertTrue(a1.isEqual(b1)) ; self.assertTrue(a2.isEqual(b2)) ; self.assertTrue(a3.isEqual(b3)) ; self.assertTrue(a4.isEqual(b4))
+ #
+ m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+ self.assertEqual(m.getMeshDimension(),2)
+ a0,a1,a2,a3,a4=m.explodeIntoEdges()
+ b0,b1,b2,b3,b4=m.buildDescendingConnectivity()
+ self.assertTrue(a0.isEqual(b0,1e-12))
+ self.assertTrue(a1.isEqual(b1)) ; self.assertTrue(a2.isEqual(b2)) ; self.assertTrue(a3.isEqual(b3)) ; self.assertTrue(a4.isEqual(b4))
+ pass
+
+ def testUMeshComputeEnlargedNeighborsOfNodes(self):
+ m=MEDCouplingCMesh() ; arr=DataArrayDouble(4) ; arr.iota() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+ a,b=m.computeEnlargedNeighborsOfNodes()
+ self.assertTrue(a.isEqual(DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84])))
+ pass
+
+ def testDAIfindIdsExt1(self):
+ d=DataArrayInt([4,6,-2,3,7,0,10])
+ self.assertTrue(d.findIdsGreaterOrEqualTo(3).isEqual(DataArrayInt([0,1,3,4,6])))
+ self.assertTrue(d.findIdsGreaterThan(3).isEqual(DataArrayInt([0,1,4,6])))
+ self.assertTrue(d.findIdsLowerThan(3).isEqual(DataArrayInt([2,5])))
+ self.assertTrue(d.findIdsLowerOrEqualTo(3).isEqual(DataArrayInt([2,3,5])))
+ pass
+
+ def testDAFacto1(self):
+ """Test focused of new wrapped methods for MEDCouplingFieldInt thanks to code factorization."""
+ d=DataArrayDouble(7) ; d.iota()
+ m=MEDCouplingUMesh.Build1DMeshFromCoords(d)
+ f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(m) ; arr=DataArrayInt(6) ; arr.iota() ; f.setArray(arr) ; f.checkConsistencyLight()
+ f_0=f[::2] # test is here
+ self.assertTrue(f_0.getArray().isEqual(DataArrayInt([0,2,4])))
+ self.assertTrue(f_0.getMesh().isEqual(m[[0,2,4]],1e-12))
+ #
+ f2=MEDCouplingFieldInt(ON_NODES) ; f2.setMesh(m) ; arr=DataArrayInt(7) ; arr.iota() ; f2.setArray(arr) ; f2.checkConsistencyLight()
+ f_1=f2[::2] # test is here
+ self.assertTrue(f_1.getArray().isEqual(DataArrayInt([0,1,2,3,4,5])))
+ m_1=m[[0,2,4]] ; m_1.zipCoords()
+ self.assertTrue(f_1.getMesh().isEqual(m_1,1e-12))
+ pass
+
+ def testFieldFloatIsOnStage1(self):
+ """ My first test with field int."""
+ m=MEDCouplingCMesh()
+ m.setName("mesh")
+ arrX=DataArrayDouble([0,1,2,3])
+ m.setCoords(arrX,arrX)
+ f=MEDCouplingFieldFloat(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayFloat(8) ; arr.iota() ;f.setArray(arr)
+ self.assertRaises(InterpKernelException,f.checkConsistencyLight)
+ arr=DataArrayFloat(9) ; arr.iota() ;f.setArray(arr)
+ f.checkConsistencyLight()
+ f.setTimeUnit("ms")
+ self.assertEqual(f.getTimeUnit(),"ms")
+ f.setTime(3.2,5,6)
+ a,b,c=f.getTime()
+ self.assertEqual(b,5)
+ self.assertEqual(c,6)
+ self.assertEqual(a,3.2,12)
+ pass
+
+ def testFieldFloatIsOnStage2(self):
+ """ Very important test to check that isEqual of MEDCouplingFieldFloat is OK !"""
+ m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4]))
+ m1=m1.buildUnstructured() ; m1.setName("mesh")
+ f1=MEDCouplingFieldFloat(ON_CELLS) ; f1.setMesh(m1)
+ arr1=DataArrayFloat([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr1.setInfoOnComponents(["aa","bbb"])
+ f1.setArray(arr1) ; f1.setName("f1") ; f1.setTime(2.,3,4)
+ #
+ m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4]))
+ m2=m2.buildUnstructured() ; m2.setName("mesh")
+ f2=MEDCouplingFieldFloat(ON_CELLS) ; f2.setMesh(m2)
+ arr2=DataArrayFloat([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr2.setInfoOnComponents(["aa","bbb"])
+ f2.setArray(arr2) ; f2.setName("f1") ; f2.setTime(2.,3,4)
+ #
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ f1.getArray()[:]*=2
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ f1.getArray()[:]/=2
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f1.setName("F1")
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ f1.setName("f1")
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f1.getArray().setInfoOnComponents(["aa","bbbb"])
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ f1.getArray().setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f3=f2.deepCopy()
+ self.assertTrue(f1.isEqual(f3,1e-12,0.))
+ #
+ for fd,expected in ((ON_NODES,False),(ON_CELLS,True)):
+ f4=MEDCouplingFieldFloat(fd) ; f4.setMesh(m2) ; f4.setTime(2.,3,4)
+ arr4=DataArrayFloat([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr4.setInfoOnComponents(["aa","bbb"])
+ f4.setArray(arr4) ; f4.setName("f1")
+ self.assertEqual(f1.isEqual(f4,1e-12,0.),expected)
+ pass
+ pass
+
+ def testLTGTDAD1(self):
+ d=DataArrayDouble(10) ; d.iota()
+ self.assertTrue(d.findIdsLowerThan(0).empty())
+ self.assertTrue(d.findIdsLowerThan(1).isEqual(DataArrayInt([0])))
+ d-=5.
+ self.assertTrue(d.findIdsStrictlyNegative().isEqual(DataArrayInt([0,1,2,3,4])))
+ self.assertTrue(d.findIdsGreaterThan(0.).isEqual(DataArrayInt([6,7,8,9])))
+ self.assertTrue(d.convertToFloatArr().isEqual(DataArrayFloat([-5,-4,-3,-2,-1,0,1,2,3,4]),1e-7))
+ self.assertTrue(d.convertToFloatArr().convertToDblArr().isEqual(d,1e-12))
+ pass
+
+ def testMapII1(self):
+ """ Test optimized maps for renumbering. Typical usage local to global in parallel mode"""
+ d=DataArrayInt([1003,1007])
+ m=d.invertArrayN2O2O2NOptimized()
+ d2=DataArrayInt([1003,1003,1007,1003,1007])
+ d2.transformWithIndArr(m)
+ self.assertTrue(d2.isEqual(DataArrayInt([0,0,1,0,1])))
+ pass
+
+ def testDAICheckUniformAndGuess1(self):
+ d=DataArrayInt([3,3],1,2)
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non single compo
+ d=DataArrayInt([])
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# empty
+ d=DataArrayInt()
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non allocated
+ d=DataArrayInt([3,3,3])
+ self.assertEqual(3,d.checkUniformAndGuess())
+ d=DataArrayInt([7])
+ self.assertEqual(7,d.checkUniformAndGuess())
+ d=DataArrayInt([3,4,3])
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non uniform
+ pass
+
+ def testUMComputePlaneEquationOf3DFaces1(self):
+ """ Consequence of an invalid traduction of matrix inversion transposition."""
+ m=MEDCoupling1SGTUMesh("msh",NORM_QUAD4)
+ m.setCoords(DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(0,2,0),(1,2,0),(2,2,0),(0,4,0),(1,4,0),(2,4,0),(0,0,3),(1,0,3),(2,0,3),(0,2,3),(1,2,3),(2,2,3),(0,4,3),(1,4,3),(2,4,3)]))
+ m.setNodalConnectivity(DataArrayInt([0,1,4,3,9,12,13,10,0,9,10,1,1,10,13,4,4,13,12,3,3,12,9,0,1,2,5,4,10,13,14,11,1,10,11,2,2,11,14,5,5,14,13,4,3,4,7,6,12,15,16,13,4,13,16,7,7,16,15,6,6,15,12,3,4,5,8,7,13,16,17,14,5,14,17,8,8,17,16,7]))
+ m=m.buildUnstructured()
+ ref=DataArrayDouble([(0,0,1,0),(0,0,1,-3),(0,1,0,0),(1,0,0,-1),(0,1,0,-2),(1,0,0,0),(0,0,1,0),(0,0,1,-3),(0,1,0,0),(1,0,0,-2),(0,1,0,-2),(0,0,1,0),(0,0,1,-3),(1,0,0,-1),(0,1,0,-4),(1,0,0,0),(0,0,1,0),(0,0,1,-3),(1,0,0,-2),(0,1,0,-4)])
+ res=m.computePlaneEquationOf3DFaces()
+ self.assertTrue(res.isEqual(ref,1e-12))
pass
pass
--- /dev/null
+# -*- coding: utf-8 -*-
+# Copyright (C) 2017 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from MEDCoupling import *
+import unittest
+from math import pi,e,sqrt,cos,sin
+from datetime import datetime
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
+
+class MEDCouplingBasicsTest6(unittest.TestCase):
+ def testPointSetInvertOrientationOfAllCells(self):
+ """ Test of inversion of orientation of cells on a different geo types"""
+ def level1(self):
+ m=MEDCouplingUMesh("",1)
+ m.allocateCells()
+ m.insertNextCell(NORM_SEG2,[3,4])
+ m.insertNextCell(NORM_SEG2,[13,14])
+ m.insertNextCell(NORM_SEG3,[5,6,7])
+ m.insertNextCell(NORM_SEG2,[23,24])
+ m.insertNextCell(NORM_SEG3,[8,9,10])
+ ref0=DataArrayInt([0,3,6,10,13,17])
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ m.invertOrientationOfAllCells()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([1,4,3, 1,14,13, 2,7,6,5, 1,24,23, 2,10,9,8])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ pass
+
+ def level2(self):
+ m=MEDCouplingUMesh("",2)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[1,2,3])
+ m.insertNextCell(NORM_QUAD4,[4,5,6,7])
+ m.insertNextCell(NORM_POLYGON,[8,9,10,11,12,13])
+ m.insertNextCell(NORM_TRI6,[14,15,16,17,18,19])
+ m.insertNextCell(NORM_QUAD8,[20,21,22,23,24,25,26,27])
+ m.insertNextCell(NORM_QPOLYG,[30,31,32,33,34,35, 36,37,38,39,40,41])
+ ref0=DataArrayInt([0,4,9,16,23,32,45])
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ m.invertOrientationOfAllCells()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,1,3,2, 4,4,7,6,5, 5,8,13,12,11,10,9, 6,14,16,15,19,18,17, 8,20,23,22,21,27,26,25,24, 32,30,35,34,33,32,31,41,40,39,38,37,36])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ pass
+
+ def level3(self):
+ m=MEDCouplingUMesh("",3)
+ m.allocateCells()
+ m.insertNextCell(NORM_TETRA4,[1,2,3,4])
+ m.insertNextCell(NORM_PYRA5,[5,6,7,8,9])
+ m.insertNextCell(NORM_PENTA6,[10,11,12,13,14,15])
+ m.insertNextCell(NORM_HEXA8,[20,21,22,23,24,25,26,27])
+ m.insertNextCell(NORM_TETRA10,[30,31,32,33,34,35,36,37,38,39])
+ m.insertNextCell(NORM_PYRA13,[40,41,42,43,44,45,46,47,48,49,50,51,52])
+ m.insertNextCell(NORM_HEXA20,[60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79])
+ m.insertNextCell(NORM_PENTA15,[80,81,82,83,84,85,86,87,88,89,90,91,92,93,94])
+ ref0=DataArrayInt([0,5,11,18,27,38,52,73,89])
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ m.invertOrientationOfAllCells()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([14,1,3,2,4, 15,5,8,7,6,9, 16,10,12,11,13,15,14, 18,20,23,22,21,24,27,26,25, 20,30,32,31,33,36,35,34,37,39,38, 23,40,43,42,41,44,48,47,46,45,49,52,51,50, 30,60,63,62,61,64,67,66,65,71,70,69,68,75,74,73,72,76,79,78,77, 25,80,82,81,83,85,84,88,87,86,91,90,89,92,94,93])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
+ pass
+
+ def gtumesh(self):
+ m=MEDCoupling1SGTUMesh("",NORM_SEG2)
+ m.setNodalConnectivity(DataArrayInt([1,2,3,4,5,6,7,8]))
+ self.assertEqual(m.getNumberOfCells(),4)
+ m2=m.deepCopy()
+ self.assertTrue(m2.isEqual(m,0.))
+ m.invertOrientationOfAllCells()
+ self.assertTrue(not m2.isEqual(m,0.))
+ m.getNodalConnectivity().isEqual(DataArrayInt([2,1,4,3,6,5,8,7]))
+ m.invertOrientationOfAllCells()
+ self.assertTrue(m2.isEqual(m,0.))
+ #
+ p=MEDCoupling1DGTUMesh("",NORM_POLYGON)
+ ref0=DataArrayInt([0,3,7,12])
+ p.setNodalConnectivity(DataArrayInt([1,2,3, 10,11,12,13, 20,21,22,23,24]),ref0)
+ p2=p.deepCopy()
+ self.assertTrue(p2.isEqual(p,0.))
+ self.assertEqual(p.getNumberOfCells(),3)
+ p.invertOrientationOfAllCells()
+ self.assertTrue(not p2.isEqual(p,0.))
+ self.assertTrue(p.getNodalConnectivityIndex().isEqual(ref0))
+ self.assertTrue(p.getNodalConnectivity().isEqual(DataArrayInt([1,3,2, 10,13,12,11, 20,24,23,22,21])))
+ p.invertOrientationOfAllCells()
+ self.assertTrue(p2.isEqual(p,0.))
+ pass
+ level1(self)
+ level2(self)
+ level3(self)
+ gtumesh(self)
+ pass
+ pass
+
+if __name__ == '__main__':
+ unittest.main()
#include "MEDCouplingField.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingGaussLocalization.hxx"
#include "MCAuto.hxx"
%init %{ import_array(); %}
#endif
+%init %{ initializeMe(); %}
+
%feature("autodoc", "1");
%feature("docstring");
%newobject MEDCoupling::MEDCouplingFieldInt::deepCopy;
%newobject MEDCoupling::MEDCouplingFieldInt::clone;
%newobject MEDCoupling::MEDCouplingFieldInt::cloneWithMesh;
+%newobject MEDCoupling::MEDCouplingFieldInt::buildSubPart;
+%newobject MEDCoupling::MEDCouplingFieldInt::buildSubPartRange;
+%newobject MEDCoupling::MEDCouplingFieldInt::__getitem__;
+%newobject MEDCoupling::MEDCouplingFieldFloat::New;
+%newobject MEDCoupling::MEDCouplingFieldFloat::convertToDblField;
+%newobject MEDCoupling::MEDCouplingFieldFloat::getArray;
+%newobject MEDCoupling::MEDCouplingFieldFloat::deepCopy;
+%newobject MEDCoupling::MEDCouplingFieldFloat::clone;
+%newobject MEDCoupling::MEDCouplingFieldFloat::cloneWithMesh;
+%newobject MEDCoupling::MEDCouplingFieldFloat::buildSubPart;
+%newobject MEDCoupling::MEDCouplingFieldFloat::buildSubPartRange;
+%newobject MEDCoupling::MEDCouplingFieldFloat::__getitem__;
%newobject MEDCoupling::MEDCouplingFieldTemplate::New;
%newobject MEDCoupling::MEDCouplingMesh::deepCopy;
%newobject MEDCoupling::MEDCouplingMesh::clone;
%newobject MEDCoupling::MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell;
%newobject MEDCoupling::MEDCouplingGaussLocalization::buildRefCell;
%newobject MEDCoupling::MEDCouplingSkyLineArray::BuildFromPolyhedronConn;
+%newobject MEDCoupling::MEDCouplingSkyLineArray::getSuperIndexArray;
+%newobject MEDCoupling::MEDCouplingSkyLineArray::getIndexArray;
+%newobject MEDCoupling::MEDCouplingSkyLineArray::getValuesArray;
%feature("unref") MEDCouplingPointSet "$this->decrRef();"
%feature("unref") MEDCouplingMesh "$this->decrRef();"
%include "MEDCouplingRefCountObject.i"
%include "MEDCouplingMemArray.i"
+%{
+ void initializeMe()
+ {// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions.
+ SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+ SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+ SWIGTITraits<int>::TI=SWIGTYPE_p_MEDCoupling__DataArrayInt;
+ SWIGTITraits<double>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple;
+ SWIGTITraits<float>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple;
+ SWIGTITraits<int>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayIntTuple;
+ }
+%}
+
namespace INTERP_KERNEL
{
/*!
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *ids(convertObjToPossibleCpp1_Safe(li,sw,sz,v0,v1));
+ const int *ids(convertIntStarLikePyObjToCppIntStar(li,sw,sz,v0,v1));
self->renumberCells(ids,check);
}
int spaceDim=self->getSpaceDimension();
INTERP_KERNEL::AutoPtr<double> tmp=new double[2*spaceDim];
self->getBoundingBox(tmp);
- PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,spaceDim);
+ PyObject *ret=convertDblArrToPyListOfTuple<double>(tmp,2,spaceDim);
return ret;
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingMesh *ret=self->buildPart(tmp,tmp+szArr);
if(sw==3)//DataArrayInt
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
DataArrayInt *arr=0;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingMesh *ret=self->buildPartAndReduceNodes(tmp,tmp+szArr,arr);
if(sw==3)//DataArrayInt
{
int getNumberOf() const;
int getLength() const;
- DataArrayInt* getSuperIndexArray() const;
- DataArrayInt* getIndexArray() const;
- DataArrayInt* getValuesArray() const;
-
void deletePack(const int i, const int j) throw(INTERP_KERNEL::Exception);
%extend
{
return self->simpleRepr();
}
+
+ DataArrayInt *getSuperIndexArray() const
+ {
+ DataArrayInt *ret(self->getSuperIndexArray());
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ DataArrayInt *getIndexArray() const
+ {
+ DataArrayInt *ret(self->getIndexArray());
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ DataArrayInt *getValuesArray() const
+ {
+ DataArrayInt *ret(self->getValuesArray());
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
PyObject *getSimplePackSafe(int absolutePackId) const throw(INTERP_KERNEL::Exception)
{
virtual void renumberNodesWithOffsetInConn(int offset) throw(INTERP_KERNEL::Exception);
virtual bool areAllNodesFetched() const throw(INTERP_KERNEL::Exception);
virtual MEDCouplingFieldDouble *computeDiameterField() const throw(INTERP_KERNEL::Exception);
+ virtual void invertOrientationOfAllCells() throw(INTERP_KERNEL::Exception);
%extend
{
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+szArr,keepCoords);
if(sw==3)//DataArrayInt
{
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+szArr,fullyIn);
if(sw==3)//DataArrayInt
{
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingPointSet *ret=self->buildPartOfMySelfKeepCoords(tmp,tmp+szArr);
if(sw==3)//DataArrayInt
{
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+szArr,fullyIn);
if(sw==3)//DataArrayInt
{
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberNodes(tmp,newNbOfNodes);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberNodesCenter(tmp,newNbOfNodes);
}
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
//
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->fillCellIdsToKeepFromNodeIds(tmp,tmp+szArr,fullyIn,ret);
return ret;
}
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
int nbc=self->getNumberOfCells();
- convertObjToPossibleCpp2(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
int nbc=self->getNumberOfCells();
- convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
int nbc=self->getNumberOfCells();
- convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
if(size>szArr)
{
std::ostringstream oss; oss << "Wrap of MEDCouplingUMesh::insertNextCell : request of connectivity with length " << size << " whereas the length of input is " << szArr << " !";
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->insertNextCell(type,szArr,tmp);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *seedPtr=convertObjToPossibleCpp1_Safe(seed,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *seedPtr=convertIntStarLikePyObjToCppIntStar(seed,sw,szArr,iTypppArr,stdvecTyyppArr);
int nbOfDepthPeelingPerformed=0;
DataArrayInt *ret0=MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(seedPtr,seedPtr+szArr,arrIn,arrIndxIn,nbOfDepthPeeling,nbOfDepthPeelingPerformed);
PyObject *res=PyTuple_New(2);
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
MEDCoupling::DataArrayInt *daIntTyypp=0;
if(!arrIndx)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : null pointer as arrIndex !");
- convertObjToPossibleCpp2(li,arrIndx->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,arrIndx->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
MEDCoupling::DataArrayInt *daIntTyypp=0;
if(!arrIndxIn)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : null pointer as arrIndxIn !");
- convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("ExtractFromIndexedArraysSlice (wrap) : the first param is not a pyslice !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sliC=reinterpret_cast<PySliceObject *>(slic);
if(!arrIndxIn)
throw INTERP_KERNEL::Exception("ExtractFromIndexedArraysSlice (wrap) : last array is null !");
arrIndxIn->checkAllocated();
if(arrIndxIn->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("ExtractFromIndexedArraysSlice (wrap) : number of components of last argument must be equal to one !");
- GetIndicesOfSlice(sliC,arrIndxIn->getNumberOfTuples(),&strt,&stp,&step,"ExtractFromIndexedArraysSlice (wrap) : Invalid slice regarding nb of elements !");
+ GetIndicesOfSlice(slic,arrIndxIn->getNumberOfTuples(),&strt,&stp,&step,"ExtractFromIndexedArraysSlice (wrap) : Invalid slice regarding nb of elements !");
DataArrayInt *arrOut=0,*arrIndexOut=0;
MEDCouplingUMesh::ExtractFromIndexedArraysSlice(strt,stp,step,arrIn,arrIndxIn,arrOut,arrIndexOut);
PyObject *ret=PyTuple_New(2);
MEDCoupling::DataArrayInt *daIntTyypp=0;
if(!arrIndxIn)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : null pointer as arrIndex !");
- convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
MEDCoupling::DataArrayInt *daIntTyypp=0;
if(!arrIndxIn)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : null pointer as arrIndex !");
- convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
double vals[6];
std::copy(vec,vec+3,vals);
std::copy(pos,pos+3,vals+3);
- return convertDblArrToPyListOfTuple(vals,3,2);
+ return convertDblArrToPyListOfTuple<double>(vals,3,2);
}
static MEDCouplingUMesh *MergeUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception)
return ret;
}
+ PyObject *explodeIntoEdges() const throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayInt> desc,descIndex,revDesc,revDescIndx;
+ MCAuto<MEDCouplingUMesh> m(self->explodeIntoEdges(desc,descIndex,revDesc,revDescIndx));
+ PyObject *ret=PyTuple_New(5);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m.retn()),SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(desc.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(descIndex.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(revDesc.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(revDescIndx.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
PyObject *explodeMeshIntoMicroEdges() const throw(INTERP_KERNEL::Exception)
{
MCAuto<DataArrayInt> d0=DataArrayInt::New();
PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
return ret;
}
+
+ PyObject *computeEnlargedNeighborsOfNodes() const throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayInt> neighbors,neighborsIdx;
+ self->computeEnlargedNeighborsOfNodes(neighbors,neighborsIdx);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
PyObject *computeCellNeighborhoodFromNodesOne(const DataArrayInt *nodeNeigh, const DataArrayInt *nodeNeighI) const throw(INTERP_KERNEL::Exception)
{
std::vector<int> pos2;
DataArrayInt *pos3=0;
DataArrayIntTuple *pos4=0;
- convertObjToPossibleCpp1(li,sw,pos1,pos2,pos3,pos4);
+ convertIntStarLikePyObjToCpp(li,sw,pos1,pos2,pos3,pos4);
switch(sw)
{
case 1:
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->insertNextCell(tmp,tmp+szArr);
}
//
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp4=convertObjToPossibleCpp1_Safe(st,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp4=convertIntStarLikePyObjToCppIntStar(st,sw,szArr,iTypppArr,stdvecTyyppArr);
std::vector<int> tmp5(tmp4,tmp4+szArr);
//
return MEDCouplingStructuredMesh::BuildExplicitIdsFrom(tmp5,inp);
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
return MEDCouplingStructuredMesh::Build1GTNodalConnectivity(tmp,tmp+szArr);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp(convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr));
+ const int *tmp(convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr));
return MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(tmp,tmp+szArr);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
int szArr2,sw2,iTypppArr2;
std::vector<int> stdvecTyyppArr2;
- const int *tmp2=convertObjToPossibleCpp1_Safe(st,sw2,szArr2,iTypppArr2,stdvecTyyppArr2);
+ const int *tmp2=convertIntStarLikePyObjToCppIntStar(st,sw2,szArr2,iTypppArr2,stdvecTyyppArr2);
std::vector<int> tmp3(tmp2,tmp2+szArr2);
std::vector< std::pair<int,int> > partCompactFormat;
bool ret0=MEDCouplingStructuredMesh::IsPartStructured(tmp,tmp+szArr,tmp3,partCompactFormat);
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(gridStruct,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(gridStruct,sw,szArr,iTypppArr,stdvecTyyppArr);
self->setNodeGridStructure(tmp,tmp+szArr);
}
}
const double *originPtr(0),*dxyzPtr(0);
int sw,sz,val0;
std::vector<int> bb0;
- nodeStrctPtr=convertObjToPossibleCpp1_Safe(nodeStrct,sw,sz,val0,bb0);
+ nodeStrctPtr=convertIntStarLikePyObjToCppIntStar(nodeStrct,sw,sz,val0,bb0);
//
double val,val2;
std::vector<double> bb,bb2;
{
int sw,sz,val0;
std::vector<int> bb0;
- const int *nodeStrctPtr(convertObjToPossibleCpp1_Safe(nodeStrct,sw,sz,val0,bb0));
+ const int *nodeStrctPtr(convertIntStarLikePyObjToCppIntStar(nodeStrct,sw,sz,val0,bb0));
self->setNodeStruct(nodeStrctPtr,nodeStrctPtr+sz);
}
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *cellIdsBg(convertObjToPossibleCpp1_Safe(cellIds,sw,sz,v0,v1));
+ const int *cellIdsBg(convertIntStarLikePyObjToCppIntStar(cellIds,sw,sz,v0,v1));
return self->computeTupleIdsToSelectFromCellIds(cellIdsBg,cellIdsBg+sz);
}
{
public:
static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception);
+ static MEDCouplingFieldTemplate *New(const MEDCouplingFieldFloat& f) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldTemplate *New(TypeOfField type);
std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
return MEDCouplingFieldTemplate::New(f);
}
+ MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDCouplingFieldTemplate::New(f);
+ }
+
MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f) throw(INTERP_KERNEL::Exception)
{
return MEDCouplingFieldTemplate::New(f);
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> res=new double[sz];
self->getValueOn(spaceLoc,res);
- return convertDblArrToPyList(res,sz);
+ return convertDblArrToPyList<double>(res,sz);
}
PyObject *getValueOnPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception)
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> res=new double[sz];
self->getValueOnPos(i,j,k,res);
- return convertDblArrToPyList(res,sz);
+ return convertDblArrToPyList<double>(res,sz);
}
DataArrayDouble *getValueOnMulti(PyObject *locs) const throw(INTERP_KERNEL::Exception)
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> res=new double[sz];
self->getValueOn(spaceLoc,time,res);
- return convertDblArrToPyList(res,sz);
+ return convertDblArrToPyList<double>(res,sz);
}
void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception)
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->accumulate(tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
PyObject *integral(bool isWAbs) const throw(INTERP_KERNEL::Exception)
{
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->integral(isWAbs,tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
PyObject *getWeightedAverageValue(bool isWAbs=true) const throw(INTERP_KERNEL::Exception)
{
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->getWeightedAverageValue(tmp,isWAbs);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
PyObject *normL1() const throw(INTERP_KERNEL::Exception)
{
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->normL1(tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
PyObject *normL2() const throw(INTERP_KERNEL::Exception)
{
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->normL2(tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
void renumberCells(PyObject *li, bool check=true) throw(INTERP_KERNEL::Exception)
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberCells(tmp,check);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberCellsWithoutMesh(tmp,check);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberNodes(tmp,eps);
}
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->renumberNodesWithoutMesh(tmp,newNbOfNodes,eps);
}
MEDCouplingFieldDouble *buildSubPart(PyObject *li) const throw(INTERP_KERNEL::Exception)
{
- int sw;
- int singleVal;
- std::vector<int> multiVal;
- std::pair<int, std::pair<int,int> > slic;
- MEDCoupling::DataArrayInt *daIntTyypp=0;
- const MEDCouplingMesh *mesh=self->getMesh();
- if(!mesh)
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !");
- int nbc=mesh->getNumberOfCells();
- convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
- switch(sw)
- {
- case 1:
- {
- if(singleVal>=nbc)
- {
- std::ostringstream oss;
- oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(singleVal>=0)
- return self->buildSubPart(&singleVal,&singleVal+1);
- else
- {
- if(nbc+singleVal>0)
- {
- int tmp=nbc+singleVal;
- return self->buildSubPart(&tmp,&tmp+1);
- }
- else
- {
- std::ostringstream oss;
- oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- case 2:
- {
- return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size());
- }
- case 3:
- {
- return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
- }
- case 4:
- {
- if(!daIntTyypp)
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !");
- daIntTyypp->checkAllocated();
- return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end());
- }
- default:
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !");
- }
+ return fieldT_buildSubPart(self,li);
}
MEDCouplingFieldDouble *__getitem__(PyObject *li) const throw(INTERP_KERNEL::Exception)
{
- const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n";
- if(PyTuple_Check(li))
- {
- Py_ssize_t sz=PyTuple_Size(li);
- if(sz!=2)
- throw INTERP_KERNEL::Exception(msg);
- PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
- int sw;
- int singleVal;
- std::vector<int> multiVal;
- std::pair<int, std::pair<int,int> > slic;
- MEDCoupling::DataArrayInt *daIntTyypp=0;
- if(!self->getArray())
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
- try
- { convertObjToPossibleCpp2(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); }
- catch(INTERP_KERNEL::Exception& e)
- { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
- MCAuto<MEDCouplingFieldDouble> ret0=MEDCoupling_MEDCouplingFieldDouble_buildSubPart(self,elt0);
- DataArrayDouble *ret0Arr=ret0->getArray();
- if(!ret0Arr)
- throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
- switch(sw)
- {
- case 1:
- {
- std::vector<int> v2(1,singleVal);
- MCAuto<DataArrayDouble> aarr(ret0Arr->keepSelectedComponents(v2));
- ret0->setArray(aarr);
- return ret0.retn();
- }
- case 2:
- {
- MCAuto<DataArrayDouble> aarr(ret0Arr->keepSelectedComponents(multiVal));
- ret0->setArray(aarr);
- return ret0.retn();
- }
- case 3:
- {
- int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !");
- std::vector<int> v2(nbOfComp);
- for(int i=0;i<nbOfComp;i++)
- v2[i]=slic.first+i*slic.second.second;
- MCAuto<DataArrayDouble> aarr(ret0Arr->keepSelectedComponents(v2));
- ret0->setArray(aarr);
- return ret0.retn();
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
-
- }
- else
- return MEDCoupling_MEDCouplingFieldDouble_buildSubPart(self,li);
+ return fieldT__getitem__(self,li);
}
PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception)
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception)
{
- std::vector<double> a0;
- std::vector<int> a1;
- std::vector<std::string> a2;
- self->getTinySerializationDbleInformation(a0);
- self->getTinySerializationIntInformation(a1);
- self->getTinySerializationStrInformation(a2);
- //
- PyObject *ret(PyTuple_New(3));
- PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
- PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
- int sz(a2.size());
- PyObject *ret2(PyList_New(sz));
- {
- for(int i=0;i<sz;i++)
- PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
- }
- PyTuple_SetItem(ret,2,ret2);
- return ret;
+ return field_getTinySerializationInformation<MEDCouplingFieldDouble>(self);
}
PyObject *serialize() const throw(INTERP_KERNEL::Exception)
{
- DataArrayInt *ret0(0);
- std::vector<DataArrayDouble *> ret1;
- self->serialize(ret0,ret1);
- if(ret0)
- ret0->incrRef();
- std::size_t sz(ret1.size());
- PyObject *ret(PyTuple_New(2));
- PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- PyObject *ret1Py(PyList_New(sz));
- for(std::size_t i=0;i<sz;i++)
- {
- if(ret1[i])
- ret1[i]->incrRef();
- PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
- }
- PyTuple_SetItem(ret,1,ret1Py);
- return ret;
+ return field_serialize<double>(self);
}
static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
{
- static const char MSG[]="MEDCouplingFieldDouble.__new__ : the args in input is expected to be a tuple !";
- if(!PyTuple_Check(args))
- throw INTERP_KERNEL::Exception(MSG);
- PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
- PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
- PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
- //
- PyObject *tmp0(PyTuple_New(1));
- PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
- PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
- Py_DECREF(tmp0);
- Py_DECREF(selfMeth);
- if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
- {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
- PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
- ////
- PyObject *a(PyInt_FromLong(0));
- PyObject *uniqueElt(PyDict_GetItem(PyTuple_GetItem(args,1),a));
- Py_DECREF(a);
- if(!uniqueElt)
- throw INTERP_KERNEL::Exception(MSG);
- if(!PyTuple_Check(uniqueElt) || PyTuple_Size(uniqueElt)!=2)
- throw INTERP_KERNEL::Exception(MSG);
- PyObject *tmp2(PyObject_CallObject(initMeth,uniqueElt));
- Py_XDECREF(tmp2);
- ////
- Py_DECREF(initMeth);
- }
- return instance;
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjExpectToBeAListOfSz2>(cls,args,"MEDCouplingFieldDouble");
}
PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
{// put an empty dict in input to say to __new__ to call __init__...
- self->checkConsistencyLight();
- PyObject *ret(PyTuple_New(1));
- PyObject *ret0(PyDict_New());
- {
- PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization()));
- PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c);
- PyDict_SetItem(ret0,a,d);
- Py_DECREF(a); Py_DECREF(d);
- }
- PyTuple_SetItem(ret,0,ret0);
- return ret;
+ return field__getnewargs__<MEDCouplingFieldDouble>(self);
}
PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
{
- self->checkConsistencyLight();
- PyObject *ret0(MEDCoupling_MEDCouplingFieldDouble_getTinySerializationInformation(self));
- PyObject *ret1(MEDCoupling_MEDCouplingFieldDouble_serialize(self));
- const MEDCouplingMesh *mesh(self->getMesh());
- if(mesh)
- mesh->incrRef();
- PyObject *ret(PyTuple_New(3));
- PyTuple_SetItem(ret,0,ret0);
- PyTuple_SetItem(ret,1,ret1);
- PyTuple_SetItem(ret,2,convertMesh(const_cast<MEDCouplingMesh *>(mesh),SWIG_POINTER_OWN | 0 ));
- return ret;
+ return field__getstate__<MEDCouplingFieldDouble>(self,MEDCoupling_MEDCouplingFieldDouble_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldDouble_serialize);
}
void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
{
- static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !";
- if(!PyTuple_Check(inp))
- throw INTERP_KERNEL::Exception(MSG);
- int sz(PyTuple_Size(inp));
- if(sz!=3)
- throw INTERP_KERNEL::Exception(MSG);
- // mesh
- PyObject *elt2(PyTuple_GetItem(inp,2));
- void *argp=0;
- int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0));
- if(!SWIG_IsOK(status))
- throw INTERP_KERNEL::Exception(MSG);
- self->setMesh(reinterpret_cast< const MEDCouplingUMesh * >(argp));
- //
- PyObject *elt0(PyTuple_GetItem(inp,0));
- PyObject *elt1(PyTuple_GetItem(inp,1));
- std::vector<double> a0;
- std::vector<int> a1;
- std::vector<std::string> a2;
- DataArrayInt *b0(0);
- std::vector<DataArrayDouble *>b1;
- {
- if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
- throw INTERP_KERNEL::Exception(MSG);
- PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
- int tmp(-1);
- fillArrayWithPyListDbl3(a0py,tmp,a0);
- convertPyToNewIntArr3(a1py,a1);
- fillStringVector(a2py,a2);
- }
- {
- if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
- throw INTERP_KERNEL::Exception(MSG);
- PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
- void *argp(0);
- int status(SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0));
- if(!SWIG_IsOK(status))
- throw INTERP_KERNEL::Exception(MSG);
- b0=reinterpret_cast<DataArrayInt *>(argp);
- convertFromPyObjVectorOfObj<MEDCoupling::DataArrayDouble *>(b1py,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",b1);
- }
- self->checkForUnserialization(a1,b0,b1);
- // useless here to call resizeForUnserialization because arrays are well resized.
- self->finishUnserialization(a1,a0,a2);
+ field__setstate__<double>(self,inp);
}
}
};
MEDCouplingFieldInt *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *convertToDblField() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldInt *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception);
%extend {
MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME)
{
return oss.str();
}
+ MEDCouplingFieldInt *buildSubPart(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ return fieldT_buildSubPart(self,li);
+ }
+
+ MEDCouplingFieldInt *__getitem__(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ return fieldT__getitem__(self,li);
+ }
+
DataArrayInt *getArray() throw(INTERP_KERNEL::Exception)
- {
- DataArrayInt *ret=self->getArray();
- if(ret)
- ret->incrRef();
- return ret;
- }
+ {
+ DataArrayInt *ret=self->getArray();
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
PyObject *getTime() throw(INTERP_KERNEL::Exception)
{
PyList_SetItem(res,2,SWIG_From_int(tmp2));
return res;
}
+
+ PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception)
+ {
+ return field_getTinySerializationInformation<MEDCouplingFieldInt>(self);
+ }
+
+ PyObject *serialize() const throw(INTERP_KERNEL::Exception)
+ {
+ return field_serialize<int>(self);
+ }
+
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjExpectToBeAListOfSz2>(cls,args,"MEDCouplingFieldInt");
+ }
+
+ PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+ {// put an empty dict in input to say to __new__ to call __init__...
+ return field__getnewargs__<MEDCouplingFieldInt>(self);
+ }
+
+ PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
+ {
+ return field__getstate__<MEDCouplingFieldInt>(self,MEDCoupling_MEDCouplingFieldInt_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldInt_serialize);
+ }
+
+ void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+ {
+ field__setstate__<int>(self,inp);
+ }
+ }
+ };
+
+ class MEDCouplingFieldFloat : public MEDCouplingField
+ {
+ public:
+ static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
+ static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+ void setTimeUnit(const std::string& unit) throw(INTERP_KERNEL::Exception);
+ std::string getTimeUnit() const throw(INTERP_KERNEL::Exception);
+ void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception);
+ void setArray(DataArrayFloat *array) throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *deepCopy() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *cloneWithMesh(bool recDeepCpy) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *convertToDblField() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception);
+ %extend {
+ MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME)
+ {
+ return MEDCouplingFieldFloat::New(type,td);
+ }
+
+ MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME)
+ {
+ return MEDCouplingFieldFloat::New(ft,td);
+ }
+
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->simpleRepr();
+ }
+
+ std::string __repr__() const throw(INTERP_KERNEL::Exception)
+ {
+ std::ostringstream oss;
+ self->reprQuickOverview(oss);
+ return oss.str();
+ }
+
+ MEDCouplingFieldFloat *buildSubPart(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ return fieldT_buildSubPart(self,li);
+ }
+
+ MEDCouplingFieldFloat *__getitem__(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ return fieldT__getitem__(self,li);
+ }
+
+ DataArrayFloat *getArray() throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayFloat *ret=self->getArray();
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ PyObject *getTime() throw(INTERP_KERNEL::Exception)
+ {
+ int tmp1,tmp2;
+ double tmp0=self->getTime(tmp1,tmp2);
+ PyObject *res = PyList_New(3);
+ PyList_SetItem(res,0,SWIG_From_double(tmp0));
+ PyList_SetItem(res,1,SWIG_From_int(tmp1));
+ PyList_SetItem(res,2,SWIG_From_int(tmp2));
+ return res;
+ }
+
+ PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception)
+ {
+ return field_getTinySerializationInformation<MEDCouplingFieldFloat>(self);
+ }
+
+ PyObject *serialize() const throw(INTERP_KERNEL::Exception)
+ {
+ return field_serialize<float>(self);
+ }
+
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjExpectToBeAListOfSz2>(cls,args,"MEDCouplingFieldFloat");
+ }
+
+ PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+ {// put an empty dict in input to say to __new__ to call __init__...
+ return field__getnewargs__<MEDCouplingFieldFloat>(self);
+ }
+
+ PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
+ {
+ return field__getstate__<MEDCouplingFieldFloat>(self,MEDCoupling_MEDCouplingFieldFloat_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldFloat_serialize);
+ }
+
+ void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+ {
+ field__setstate__<float>(self,inp);
+ }
}
};
const double *originPtr(0),*dxyzPtr(0);
int sw,sz,val0;
std::vector<int> bb0;
- nodeStrctPtr=convertObjToPossibleCpp1_Safe(nodeStrct,sw,sz,val0,bb0);
+ nodeStrctPtr=convertIntStarLikePyObjToCppIntStar(nodeStrct,sw,sz,val0,bb0);
//
double val,val2;
std::vector<double> bb,bb2;
import os
__filename=os.environ.get('PYTHONSTARTUP')
if __filename and os.path.isfile(__filename):
- execfile(__filename)
+ exec(open(__filename).read())
pass
%}
--- /dev/null
+// Copyright (C) 2007-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDCOUPLINGDATAARRAYTRAITS_HXX__
+#define __MEDCOUPLINGDATAARRAYTRAITS_HXX__
+
+#include "MEDCouplingMemArray.hxx"
+
+#include <Python.h>
+
+#ifdef WITH_NUMPY
+#include <numpy/arrayobject.h>
+#if NPY_API_VERSION <= 0x00000006
+# define MED_NUMPY_OWNDATA NPY_OWNDATA
+#else
+# define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
+#endif
+#endif
+
+// specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
+// method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
+// if no more alive the "standart" DataArray deallocator is called.
+void numarrdeal(void *pt, void *wron)
+{
+ void **wronc=(void **)wron;
+ PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
+ PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
+ if(obj!=Py_None)
+ {
+ Py_XINCREF(obj);
+ PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
+ objC->flags|=MED_NUMPY_OWNDATA;
+ Py_XDECREF(weakRefOnOwner);
+ Py_XDECREF(obj);
+ }
+ else
+ {
+ typedef void (*MyDeallocator)(void *,void *);
+ MyDeallocator deall=(MyDeallocator)wronc[1];
+ deall(pt,NULL);
+ Py_XDECREF(weakRefOnOwner);
+ }
+ delete [] wronc;
+}
+
+template<class MCData>
+struct PyCallBackDataArraySt {
+ PyObject_HEAD
+ MCData *_pt_mc;
+};
+
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayFloat> PyCallBackDataArrayFloat;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
+
+extern "C"
+{
+ static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
+
+ static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+ {
+ PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
+ return (PyObject *)self;
+ }
+
+ static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+ {
+ PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
+ return (PyObject *)self;
+ }
+
+ static PyObject *callbackmcdataarrayfloat___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+ {
+ PyCallBackDataArrayFloat *self = (PyCallBackDataArrayFloat *) ( type->tp_alloc(type, 0) );
+ return (PyObject *)self;
+ }
+
+ static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+ {
+ PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
+ return (PyObject *)self;
+ }
+
+ static void callbackmcdataarray_dealloc(PyObject *self)
+ {
+ Py_TYPE(self)->tp_free(self);
+ }
+
+
+ // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+ // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+ static PyObject *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
+ {
+ if(self->_pt_mc)
+ {
+ MEDCoupling::MemArray<char>& mma=self->_pt_mc->accessToMemArray();
+ mma.destroy();
+ }
+ Py_XINCREF(Py_None);
+ return Py_None;
+ }
+
+ // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+ // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+ static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
+ {
+ if(self->_pt_mc)
+ {
+ MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
+ mma.destroy();
+ }
+ Py_XINCREF(Py_None);
+ return Py_None;
+ }
+
+ // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+ // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+ static PyObject *callbackmcdataarrayfloat_call(PyCallBackDataArrayFloat *self, PyObject *args, PyObject *kw)
+ {
+ if(self->_pt_mc)
+ {
+ MEDCoupling::MemArray<float>& mma=self->_pt_mc->accessToMemArray();
+ mma.destroy();
+ }
+ Py_XINCREF(Py_None);
+ return Py_None;
+ }
+
+ // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+ // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+ static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
+ {
+ if(self->_pt_mc)
+ {
+ MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
+ mma.destroy();
+ }
+ Py_XINCREF(Py_None);
+ return Py_None;
+ }
+}
+
+PyTypeObject PyCallBackDataArrayChar_RefType = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "callbackmcdataarraychar",
+ sizeof(PyCallBackDataArrayChar),
+ 0,
+ callbackmcdataarray_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ (ternaryfunc)callbackmcdataarraychar_call, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ 0, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ callbackmcdataarray___init__, /*tp_init*/
+ PyType_GenericAlloc, /*tp_alloc*/
+ callbackmcdataarraychar___new__, /*tp_new*/
+ PyObject_GC_Del, /*tp_free*/
+};
+
+
+PyTypeObject PyCallBackDataArrayInt_RefType = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "callbackmcdataarrayint",
+ sizeof(PyCallBackDataArrayInt),
+ 0,
+ callbackmcdataarray_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ 0, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ callbackmcdataarray___init__, /*tp_init*/
+ PyType_GenericAlloc, /*tp_alloc*/
+ callbackmcdataarrayint___new__, /*tp_new*/
+ PyObject_GC_Del, /*tp_free*/
+};
+
+PyTypeObject PyCallBackDataArrayFloat_RefType = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "callbackmcdataarraydouble",
+ sizeof(PyCallBackDataArrayFloat),
+ 0,
+ callbackmcdataarray_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ 0, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ callbackmcdataarray___init__, /*tp_init*/
+ PyType_GenericAlloc, /*tp_alloc*/
+ callbackmcdataarrayfloat___new__, /*tp_new*/
+ PyObject_GC_Del, /*tp_free*/
+};
+
+PyTypeObject PyCallBackDataArrayDouble_RefType = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "callbackmcdataarraydouble",
+ sizeof(PyCallBackDataArrayDouble),
+ 0,
+ callbackmcdataarray_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ 0, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ callbackmcdataarray___init__, /*tp_init*/
+ PyType_GenericAlloc, /*tp_alloc*/
+ callbackmcdataarraydouble___new__, /*tp_new*/
+ PyObject_GC_Del, /*tp_free*/
+};
+
+template<class T>
+struct NPYTraits
+{
+};
+
+template<>
+struct NPYTraits<double>
+{
+ static const int NPYObjectType=NPY_DOUBLE;
+ static PyTypeObject *NPYFunc;
+ static PyObject *Array_SWIGTYPE;
+};
+
+template<>
+struct NPYTraits<float>
+{
+ static const int NPYObjectType=NPY_FLOAT;
+ static PyTypeObject *NPYFunc;
+ static PyObject *Array_SWIGTYPE;
+};
+
+#endif
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
#define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
+#if PY_VERSION_HEX >= 0x03000000
+#define PyInt_AS_LONG PyLong_AS_LONG
+#endif
+
#include "InterpKernelAutoPtr.hxx"
+#include "MEDCouplingDataArrayTraits.hxx"
#include <sstream>
+static PyObject *convertArray(MEDCoupling::DataArray *array, int owner)
+{
+ PyObject *ret(NULL);
+ if(!array)
+ {
+ Py_XINCREF(Py_None);
+ return Py_None;
+ }
+ if(dynamic_cast<MEDCoupling::DataArrayDouble *>(array))
+ ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
+ if(dynamic_cast<MEDCoupling::DataArrayInt *>(array))
+ ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
+ if(dynamic_cast<MEDCoupling::DataArrayFloat *>(array))
+ ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
+ if(!ret)
+ throw INTERP_KERNEL::Exception("Not recognized type of array on downcast !");
+ return ret;
+}
+
/*!
* This method is an extention of PySlice_GetIndices but less
* open than PySlice_GetIndicesEx that accepts too many situations.
*/
-void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
+void GetIndicesOfSlice(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
{
- int ret(PySlice_GetIndices(slice,length,start,stop,step));
+ int ret(PySlice_GetIndices(
+#if PY_VERSION_HEX >= 0x03000000
+ slice,
+#else
+ reinterpret_cast<PySliceObject *>(slice),
+#endif
+ length,start,stop,step));
if(ret==0)
return ;
if(*step>0 && *start==*stop && length==*start)
/*!
* This method allows to retrieve slice info from \a slice.
*/
-void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
+void GetIndicesOfSliceExplicitely(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
{
- int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
+ int ret(PySlice_GetIndices(
+#if PY_VERSION_HEX >= 0x03000000
+ slice,
+#else
+ reinterpret_cast<PySliceObject *>(slice),
+#endif
+ std::numeric_limits<int>::max(),start,stop,step));
if(ret==0)
{
if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
return val;
}
-#ifdef WITH_NUMPY
-#include <numpy/arrayobject.h>
-#if NPY_API_VERSION <= 0x00000006
-# define MED_NUMPY_OWNDATA NPY_OWNDATA
-#else
-# define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
-#endif
-
-// specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
-// method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
-// if no more alive the "standart" DataArray deallocator is called.
-void numarrdeal(void *pt, void *wron)
-{
- void **wronc=(void **)wron;
- PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
- PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
- if(obj!=Py_None)
- {
- Py_XINCREF(obj);
- PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
- objC->flags|=MED_NUMPY_OWNDATA;
- Py_XDECREF(weakRefOnOwner);
- Py_XDECREF(obj);
- }
- else
- {
- typedef void (*MyDeallocator)(void *,void *);
- MyDeallocator deall=(MyDeallocator)wronc[1];
- deall(pt,NULL);
- Py_XDECREF(weakRefOnOwner);
- }
- delete [] wronc;
-}
-
-template<class MCData>
-struct PyCallBackDataArraySt {
- PyObject_HEAD
- MCData *_pt_mc;
-};
-
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
-
-extern "C"
-{
- static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
-
- static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
- {
- PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
- return (PyObject *)self;
- }
-
- static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
- {
- PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
- return (PyObject *)self;
- }
-
- static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
- {
- PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
- return (PyObject *)self;
- }
-
- static void callbackmcdataarray_dealloc(PyObject *self)
- {
- Py_TYPE(self)->tp_free(self);
- }
-
-
- // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
- // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
- static PyObject *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
- {
- if(self->_pt_mc)
- {
- MEDCoupling::MemArray<char>& mma=self->_pt_mc->accessToMemArray();
- mma.destroy();
- }
- Py_XINCREF(Py_None);
- return Py_None;
- }
-
- // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
- // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
- static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
- {
- if(self->_pt_mc)
- {
- MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
- mma.destroy();
- }
- Py_XINCREF(Py_None);
- return Py_None;
- }
-
- // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
- // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
- static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
- {
- if(self->_pt_mc)
- {
- MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
- mma.destroy();
- }
- Py_XINCREF(Py_None);
- return Py_None;
- }
-}
-
-PyTypeObject PyCallBackDataArrayChar_RefType = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "callbackmcdataarraychar",
- sizeof(PyCallBackDataArrayChar),
- 0,
- callbackmcdataarray_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- (ternaryfunc)callbackmcdataarraychar_call, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- 0, /*tp_methods*/
- 0, /*tp_members*/
- 0, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- callbackmcdataarray___init__, /*tp_init*/
- PyType_GenericAlloc, /*tp_alloc*/
- callbackmcdataarraychar___new__, /*tp_new*/
- PyObject_GC_Del, /*tp_free*/
-};
-
-
-PyTypeObject PyCallBackDataArrayInt_RefType = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "callbackmcdataarrayint",
- sizeof(PyCallBackDataArrayInt),
- 0,
- callbackmcdataarray_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- 0, /*tp_methods*/
- 0, /*tp_members*/
- 0, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- callbackmcdataarray___init__, /*tp_init*/
- PyType_GenericAlloc, /*tp_alloc*/
- callbackmcdataarrayint___new__, /*tp_new*/
- PyObject_GC_Del, /*tp_free*/
-};
-
-PyTypeObject PyCallBackDataArrayDouble_RefType = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "callbackmcdataarraydouble",
- sizeof(PyCallBackDataArrayDouble),
- 0,
- callbackmcdataarray_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- 0, /*tp_methods*/
- 0, /*tp_members*/
- 0, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- callbackmcdataarray___init__, /*tp_init*/
- PyType_GenericAlloc, /*tp_alloc*/
- callbackmcdataarraydouble___new__, /*tp_new*/
- PyObject_GC_Del, /*tp_free*/
-};
-
// this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
// in input when an another DataArray is already client of this.
template<class MCData>
SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
-PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
+PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols)
{
int nbRows((int)m.size());
MEDCoupling::MCAuto<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
return ret;
}
-#endif
-
-static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
{
PyObject *ret=0;
if(!dac)
return ret;
}
-static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner)
{
PyObject *ret=0;
if(!dac)
ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
+ if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
+ ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
return ret;
}
-static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
+static PyObject *convertIntArrToPyList(const int *ptr, int size)
{
PyObject *ret=PyList_New(size);
for(int i=0;i<size;i++)
return ret;
}
-static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
+static PyObject *convertIntArrToPyList2(const std::vector<int>& v)
{
int size=v.size();
PyObject *ret=PyList_New(size);
return ret;
}
-static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
+static PyObject *convertIntArrToPyList3(const std::set<int>& v)
{
int size=v.size();
PyObject *ret=PyList_New(size);
return ret;
}
-static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
+static bool convertPyObjectToStrNT(PyObject *obj, std::string& ret)
+{
+ if(PyString_Check(obj))
+ {
+ ret=PyString_AsString(obj);
+ return true;
+ }
+#if PY_VERSION_HEX >= 0x03000000
+ else if(PyUnicode_Check(obj))
+ {
+ ret=PyUnicode_AsUTF8(obj);
+ return true;
+ }
+#endif
+ return false;
+}
+
+static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
+{
+ std::string ret;
+ if(PyString_Check(obj))
+ ret=PyString_AsString(obj);
+#if PY_VERSION_HEX >= 0x03000000
+ else if(PyUnicode_Check(obj))
+ ret=PyUnicode_AsUTF8(obj);
+#endif
+ else
+ {
+ std::ostringstream oss;
+ if(msg)
+ oss << msg;
+ else
+ oss << "PyWrap convertPyObjectToStr : expect a sting like py object !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret;
+}
+
+static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples)
{
PyObject *ret=PyList_New(nbOfTuples);
for(int i=0;i<nbOfTuples;i++)
return ret;
}
-static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
+static int *convertPyToNewIntArr2(PyObject *pyLi, int *size)
{
if(PyList_Check(pyLi))
{
}
}
-static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
+static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr)
{
PyObject *ret=PyList_New(arr.size());
for(std::size_t i=0;i<arr.size();i++)
return ret;
}
-static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr)
{
const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
if(PyList_Check(pyLi))
throw INTERP_KERNEL::Exception(msg);
}
-static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
{
const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
if(PyList_Check(pyLi))
if(sz2!=2)
throw INTERP_KERNEL::Exception(msg);
PyObject *o_0=PyTuple_GetItem(o,0);
- if(!PyString_Check(o_0))
- throw INTERP_KERNEL::Exception(msg);
PyObject *o_1=PyTuple_GetItem(o,1);
+ arr[i].first=convertPyObjectToStr(o_0,msg);
if(!PyInt_Check(o_1))
throw INTERP_KERNEL::Exception(msg);
- arr[i].first=PyString_AsString(o_0);
arr[i].second=(int)PyInt_AS_LONG(o_1);
}
else
if(sz2!=2)
throw INTERP_KERNEL::Exception(msg);
PyObject *o_0=PyTuple_GetItem(o,0);
- if(!PyString_Check(o_0))
- throw INTERP_KERNEL::Exception(msg);
PyObject *o_1=PyTuple_GetItem(o,1);
+ arr[i].first=convertPyObjectToStr(o_0,msg);
if(!PyInt_Check(o_1))
throw INTERP_KERNEL::Exception(msg);
- arr[i].first=PyString_AsString(o_0);
arr[i].second=(int)PyInt_AS_LONG(o_1);
}
else
throw INTERP_KERNEL::Exception(msg);
}
-static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr)
{
if(PyList_Check(pyLi))
{
}
}
-static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr)
{
if(recurseLev<0)
throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
}
-static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
+static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp)
{
if(nbOfTuples==-1)
{
throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
}
-static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
+static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
{
std::vector<int> ret;
int size1=-1,size2=-1;
return ret;
}
-static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
+static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
{
if(PyList_Check(pyLi))
{
for(int i=0;i<sz;i++)
{
PyObject *o=PyList_GetItem(pyLi,i);
- if(PyString_Check(o))
- vec[i]=PyString_AsString(o);
- else
+ if(!convertPyObjectToStrNT(o,vec[i]))
return false;
}
return true;
for(int i=0;i<sz;i++)
{
PyObject *o=PyTuple_GetItem(pyLi,i);
- if(PyString_Check(o))
- vec[i]=PyString_AsString(o);
- else
+ if(!convertPyObjectToStrNT(o,vec[i]))
return false;
}
return true;
else
return false;
}
-static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
{
const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
if(PyList_Check(pyLi))
throw INTERP_KERNEL::Exception(msg);
}
-static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
+static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec)
{
if(PyList_Check(pyLi))
{
return false;
}
-static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr)
{
const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
if(PyList_Check(pyLi))
throw INTERP_KERNEL::Exception(msg);
}
-static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
+static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
{
const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
if(PyList_Check(pyLi))
throw INTERP_KERNEL::Exception(msg);
std::pair<std::string, std::vector<std::string> > item;
PyObject *o_0=PyTuple_GetItem(o,0);
- if(!PyString_Check(o_0))
- throw INTERP_KERNEL::Exception(msg);
- item.first=PyString_AsString(o_0);
+ item.first=convertPyObjectToStr(o_0,msg);
PyObject *o_1=PyTuple_GetItem(o,1);
if(!fillStringVector(o_1,item.second))
throw INTERP_KERNEL::Exception(msg);
throw INTERP_KERNEL::Exception(msg);
std::pair<std::string, std::vector<std::string> > item;
PyObject *o_0=PyTuple_GetItem(o,0);
- if(!PyString_Check(o_0))
- throw INTERP_KERNEL::Exception(msg);
- item.first=PyString_AsString(o_0);
+ item.first=convertPyObjectToStr(o_0,msg);
PyObject *o_1=PyTuple_GetItem(o,1);
if(!fillStringVector(o_1,item.second))
throw INTERP_KERNEL::Exception(msg);
throw INTERP_KERNEL::Exception(msg);
}
-static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
+template<class T>
+PyObject *convertDblArrToPyList(const T *ptr, int size)
{
- PyObject *ret=PyList_New(size);
+ PyObject *ret(PyList_New(size));
for(int i=0;i<size;i++)
PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
return ret;
}
-static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
+static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
{
- int size=v.size();
- PyObject *ret=PyList_New(size);
+ int size(v.size());
+ PyObject *ret(PyList_New(size));
for(int i=0;i<size;i++)
PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
return ret;
}
-static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
+template<class T>
+PyObject *convertDblArrToPyListOfTuple(const T *vals, int nbOfComp, int nbOfTuples)
{
- PyObject *ret=PyList_New(nbOfTuples);
+ PyObject *ret(PyList_New(nbOfTuples));
for(int i=0;i<nbOfTuples;i++)
{
PyObject *t=PyTuple_New(nbOfComp);
return ret;
}
-static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
+static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples)
{
PyObject *ret=PyList_New(nbOfTuples);
INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
return ret;
}
-static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
+static double *convertPyToNewDblArr2(PyObject *pyLi, int *size)
{
if(PyList_Check(pyLi))
{
throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
}
-static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
+static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
{
std::vector<double> ret;
int size1=-1,size2=-1;
*
* switch between (int,vector<int>,DataArrayInt)
*/
-static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
+static void convertIntStarLikePyObjToCpp(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple)
{
sw=-1;
if(PyInt_Check(value))
throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
}
+/*!
+ * if python int -> cpp int sw=1
+ * if python list[int] -> cpp vector<int> sw=2
+ * if python tuple[int] -> cpp vector<int> sw=2
+ * if python DataArrayInt -> cpp DataArrayInt sw=3
+ * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static const int *convertIntStarLikePyObjToCppIntStar(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp)
+{
+ 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<size;i++)
+ {
+ PyObject *o=PyTuple_GetItem(value,i);
+ if(PyInt_Check(o))
+ stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ else
+ {
+ std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ sw=2; sz=size;
+ return &stdvecTyypp[0];
+ }
+ if(PyList_Check(value))
+ {
+ int size=PyList_Size(value);
+ stdvecTyypp.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyList_GetItem(value,i);
+ if(PyInt_Check(o))
+ stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ else
+ {
+ std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ sw=2; sz=size;
+ return &stdvecTyypp[0];
+ }
+ void *argp;
+ int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
+ if(SWIG_IsOK(status))
+ {
+ MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
+ if(daIntTyypp)
+ {
+ sw=3; sz=daIntTyypp->getNbOfElems();
+ return daIntTyypp->begin();
+ }
+ else
+ {
+ sz=0;
+ return 0;
+ }
+ }
+ status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
+ if(SWIG_IsOK(status))
+ {
+ MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::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");
+}
+
/*!
* if python double -> cpp double sw=1
* if python int -> cpp double sw=1
*
* switch between (int,vector<int>,DataArrayInt)
*/
-static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+template<class T>
+void considerPyObjAsATStarLikeObject(PyObject *value, int& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
{
sw=-1;
if(PyFloat_Check(value))
{
- iTyypp=PyFloat_AS_DOUBLE(value);
+ iTyypp=(T)PyFloat_AS_DOUBLE(value);
sw=1;
return;
}
if(PyInt_Check(value))
{
- iTyypp=(double)PyInt_AS_LONG(value);
+ iTyypp=(T)PyInt_AS_LONG(value);
sw=1;
return;
}
{
PyObject *o=PyTuple_GetItem(value,i);
if(PyFloat_Check(o))
- stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+ stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
else if(PyInt_Check(o))
- stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+ stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
else
{
std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
{
PyObject *o=PyList_GetItem(value,i);
if(PyFloat_Check(o))
- stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+ stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
else if(PyInt_Check(o))
- stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+ stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
else
{
std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
return;
}
void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
+ int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
if(!SWIG_IsOK(status))
throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
- daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
+ daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
sw=3;
}
*
* switch between (int,vector<int>,DataArrayInt)
*/
-static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+static void convertDoubleStarLikePyObjToCpp(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
{
sw=-1;
if(PyFloat_Check(value))
sw=3;
}
-/*!
- * if python int -> cpp int sw=1
- * if python list[int] -> cpp vector<int> sw=2
- * if python tuple[int] -> cpp vector<int> sw=2
- * if python slicp -> cpp pair sw=3 (begin,end,step)
- * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
- *
- * switch between (int,vector<int>,DataArrayInt)
- */
-static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+template<class T>
+void convertFPStarLikePyObjToCpp_2(PyObject *value, int& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
{
- const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
sw=-1;
+ if(PyFloat_Check(value))
+ {
+ val=PyFloat_AS_DOUBLE(value);
+ sw=1;
+ return;
+ }
if(PyInt_Check(value))
{
- iTyypp=(int)PyInt_AS_LONG(value);
+ val=(T)PyInt_AS_LONG(value);
sw=1;
return;
}
if(PyTuple_Check(value))
{
int size=PyTuple_Size(value);
- stdvecTyypp.resize(size);
+ f.resize(size);
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ if(PyFloat_Check(o))
+ f[i]=PyFloat_AS_DOUBLE(o);
+ else if(PyInt_Check(o))
+ f[i]=(T)PyInt_AS_LONG(o);
else
{
- std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
+ std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- sw=2;
+ sw=4;
return;
}
if(PyList_Check(value))
{
int size=PyList_Size(value);
- stdvecTyypp.resize(size);
+ f.resize(size);
for(int i=0;i<size;i++)
{
PyObject *o=PyList_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ if(PyFloat_Check(o))
+ f[i]=PyFloat_AS_DOUBLE(o);
+ else if(PyInt_Check(o))
+ f[i]=(T)PyInt_AS_LONG(o);
else
{
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
+ std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- sw=2;
+ sw=4;
return;
}
- if(PySlice_Check(value))
- {
- Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
- GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
- p.first=strt;
- p.second.first=stp;
- p.second.second=step;
- sw=3;
- return ;
- }
void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
+ int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
if(SWIG_IsOK(status))
- {
- daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
- if(!daIntTyypp)
- {
- std::ostringstream oss; oss << msg << " Instance in null !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- sw=4;
+ {
+ d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
+ sw=2;
return ;
}
- status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
+ status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
if(SWIG_IsOK(status))
- {
- MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
- if(!tmp)
- {
- std::ostringstream oss; oss << msg << " Instance in null !";
+ {
+ e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
+ sw=3;
+ return ;
+ }
+ throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
+}
+
+/*!
+ * if value int -> cpp val sw=1
+ * if value double -> cpp val sw=1
+ * if value DataArrayDouble -> cpp DataArrayDouble sw=2
+ * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
+ * if value list[int,double] -> cpp std::vector<double> sw=4
+ * if value tuple[int,double] -> cpp std::vector<double> sw=4
+ */
+static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
+{
+ convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
+}
+
+/*!
+ * if python int -> cpp int sw=1
+ * if python list[int] -> cpp vector<int> sw=2
+ * if python tuple[int] -> cpp vector<int> sw=2
+ * if python slicp -> cpp pair sw=3 (begin,end,step)
+ * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp)
+{
+ const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
+ sw=-1;
+ if(PyInt_Check(value))
+ {
+ iTyypp=(int)PyInt_AS_LONG(value);
+ sw=1;
+ return;
+ }
+ if(PyTuple_Check(value))
+ {
+ int size=PyTuple_Size(value);
+ stdvecTyypp.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyTuple_GetItem(value,i);
+ if(PyInt_Check(o))
+ stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ else
+ {
+ std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ sw=2;
+ return;
+ }
+ if(PyList_Check(value))
+ {
+ int size=PyList_Size(value);
+ stdvecTyypp.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyList_GetItem(value,i);
+ if(PyInt_Check(o))
+ stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+ else
+ {
+ std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ sw=2;
+ return;
+ }
+ if(PySlice_Check(value))
+ {
+ Py_ssize_t strt=2,stp=2,step=2;
+ GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
+ p.first=strt;
+ p.second.first=stp;
+ p.second.second=step;
+ sw=3;
+ return ;
+ }
+ void *argp;
+ int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
+ if(SWIG_IsOK(status))
+ {
+ daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
+ if(!daIntTyypp)
+ {
+ std::ostringstream oss; oss << msg << " Instance in null !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ sw=4;
+ return ;
+ }
+ status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
+ if(SWIG_IsOK(status))
+ {
+ MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
+ if(!tmp)
+ {
+ std::ostringstream oss; oss << msg << " Instance in null !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
stdvecTyypp.resize(tmp->getNumberOfCompo());
}
/*!
- * Idem than convertObjToPossibleCpp2
+ * Idem than convertIntStarOrSliceLikePyObjToCpp
*/
-static void convertObjToPossibleCpp2WithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp)
{
- convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
if(sw==1)
{
iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
* if python slice -> cpp pair sw=3
* if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
*/
-static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayIntTuple *& daIntTyypp)
{
sw=-1;
if(PyInt_Check(value))
if(PySlice_Check(value))
{
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
- GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
+ GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
p.first=strt;
p.second.first=stp;
p.second.second=step;
* if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
* switch between (int,string,vector<string>,DataArrayChar)
*/
-static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
+static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
{
const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
sw=-1;
return;
}
}
+#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(value))
+ {
+ Py_ssize_t sz;
+ const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
+ if(sz==1)
+ {
+ cTyp=pt[0];
+ sw=1;
+ return;
+ }
+ else
+ {
+ sType=pt;
+ sw=2;
+ return;
+ }
+ }
+#endif
if(PyTuple_Check(value))
{
int size=PyTuple_Size(value);
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(value,i);
- if(PyString_Check(o))
- vsType[i]=PyString_AsString(o);
- else
+ try
+ {
+ vsType[i]=convertPyObjectToStr(o);
+ }
+ catch(INTERP_KERNEL::Exception& e)
{
std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
for(int i=0;i<size;i++)
{
PyObject *o=PyList_GetItem(value,i);
- if(PyString_Check(o))
- vsType[i]=PyString_AsString(o);
- else
+ try
{
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
+ vsType[i]=convertPyObjectToStr(o);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
*/
static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
- MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
+ MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc)
{
if(!PyTuple_Check(value))
{
- convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
return ;
}
else
throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
PyObject *ob0=PyTuple_GetItem(value,0);
int sw1,sw2;
- convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
PyObject *ob1=PyTuple_GetItem(value,1);
- convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
sw=4*sw2+sw1;
}
}
-/*!
- * if value int -> cpp val sw=1
- * if value double -> cpp val sw=1
- * if value DataArrayDouble -> cpp DataArrayDouble sw=2
- * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
- * if value list[int,double] -> cpp std::vector<double> sw=4
- * if value tuple[int,double] -> cpp std::vector<double> sw=4
- */
-static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
-{
- sw=-1;
- if(PyFloat_Check(value))
- {
- val=PyFloat_AS_DOUBLE(value);
- sw=1;
- return;
- }
- if(PyInt_Check(value))
- {
- val=(double)PyInt_AS_LONG(value);
- sw=1;
- return;
- }
- if(PyTuple_Check(value))
- {
- int size=PyTuple_Size(value);
- f.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyTuple_GetItem(value,i);
- if(PyFloat_Check(o))
- f[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- f[i]=(double)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=4;
- return;
- }
- if(PyList_Check(value))
- {
- int size=PyList_Size(value);
- f.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(value,i);
- if(PyFloat_Check(o))
- f[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- f[i]=(double)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=4;
- return;
- }
- void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
- if(SWIG_IsOK(status))
- {
- d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
- sw=2;
- return ;
- }
- status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
- if(SWIG_IsOK(status))
- {
- e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
- sw=3;
- return ;
- }
- throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
-}
-
/*!
* if value int -> cpp val sw=1
* if value double -> cpp val sw=1
* if value tuple[int,double] -> cpp std::vector<double> sw=4
*/
static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
- const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
+ const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
{
sw=-1;
if(PyFloat_Check(value))
* if value tuple[int,double] -> cpp std::vector<double> sw=4
*/
static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
- const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
+ const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples)
{
sw=-1;
if(PyFloat_Check(value))
* if value tuple[int,double] -> cpp std::vector<double> sw=4
*/
static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
- const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
+ const char *msg, bool throwIfNullPt, int& nbTuples)
{
MEDCoupling::DataArrayDouble *d=0;
MEDCoupling::DataArrayDoubleTuple *e=0;
throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
}
-/*!
- * if python int -> cpp int sw=1
- * if python list[int] -> cpp vector<int> sw=2
- * if python tuple[int] -> cpp vector<int> sw=2
- * if python DataArrayInt -> cpp DataArrayInt sw=3
- * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
- *
- * switch between (int,vector<int>,DataArrayInt)
- */
-static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
+static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
{
- sw=-1;
- if(PyInt_Check(value))
- {
- iTyypp=(int)PyInt_AS_LONG(value);
- sw=1; sz=1;
- return &iTyypp;
- }
- if(PyTuple_Check(value))
+ void *aBasePtrVS=0;
+ int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
+ if(!SWIG_IsOK(status))
{
- int size=PyTuple_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
+ status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
+ if(!SWIG_IsOK(status))
{
- PyObject *o=PyTuple_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
- else
+ status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
+ if(!SWIG_IsOK(status))
{
- std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
+ status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
+ if(!SWIG_IsOK(status))
+ {
+ status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
+ std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
}
- sw=2; sz=size;
- return &stdvecTyypp[0];
}
- if(PyList_Check(value))
- {
- int size=PyList_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=2; sz=size;
- return &stdvecTyypp[0];
- }
- void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
- if(SWIG_IsOK(status))
- {
- MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
- if(daIntTyypp)
- {
- sw=3; sz=daIntTyypp->getNbOfElems();
- return daIntTyypp->begin();
- }
- else
- {
- sz=0;
- return 0;
- }
- }
- status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
- if(SWIG_IsOK(status))
- {
- MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::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");
-}
-
-static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
-{
- void *aBasePtrVS=0;
- int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
- if(!SWIG_IsOK(status))
- {
- status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
- if(!SWIG_IsOK(status))
- {
- status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
- if(!SWIG_IsOK(status))
- {
- status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
- if(!SWIG_IsOK(status))
- {
- status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
- std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- }
- return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
-}
-
-static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
-{
- if(!PyTuple_Check(args))
+ return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
+}
+
+static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
+{
+ if(!PyTuple_Check(args))
{
std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
return instance;
}
-static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
+template<class T>
+static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral(PyObject *cls, PyObject *args, const char *clsName)
{
if(!PyTuple_Check(args))
{
zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
Py_DECREF(tmp1);
}
+ if(!zeNumpyRepr)
+ {
+ std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ T tt;
{
- PyObject *tmp3(PyTuple_New(1));
- PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
- PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
- Py_XDECREF(tmp2);
+ PyObject *tmp3(0);
+ try
+ {
+ tmp3=tt(zeNumpyRepr);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ std::ostringstream oss; oss << clsName << ".__new__ : Invalid type in input " << " : " << e.what();
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ {
+ PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
+ Py_XDECREF(tmp2);
+ }
Py_DECREF(tmp3);
}
Py_DECREF(initMeth);
return instance;
}
-static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner) throw(INTERP_KERNEL::Exception)
+struct SinglePyObjToBePutInATuple
+{
+ PyObject *operator()(PyObject *zeNumpyRepr)
+ {
+ PyObject *tmp3(PyTuple_New(1));
+ PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
+ return tmp3;
+ }
+};
+
+struct SinglePyObjExpectToBeAListOfSz2
+{
+ PyObject *operator()(PyObject *uniqueElt)
+ {
+ if(!PyTuple_Check(uniqueElt) || PyTuple_Size(uniqueElt)!=2)
+ throw INTERP_KERNEL::Exception("Not a tuple of size 2 !");
+ Py_XINCREF(uniqueElt);
+ return uniqueElt;
+ }
+};
+
+static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
+{
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjToBePutInATuple>(cls,args,clsName);
+}
+
+static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
{
PyObject *ret=0;
if(!pd)
return ret;
}
+template<class T>
+static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
+{
+ const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
+ std::string msg(msgBase);
+#ifdef WITH_NUMPY
+ msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
+#endif
+ msg+=" !";
+ if(PyList_Check(elt0) || PyTuple_Check(elt0))
+ {
+ if(nbOfTuples)
+ {
+ if(PyInt_Check(nbOfTuples))
+ {
+ int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
+ if(nbOfTuples1<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
+ if(elt2)
+ {
+ if(PyInt_Check(elt2))
+ {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
+ int nbOfCompo=PyInt_AS_LONG(elt2);
+ if(nbOfCompo<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+ std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
+ ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+ return ret.retn();
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg.c_str());
+ }
+ else
+ {//DataArrayDouble.New([1.,3.,4.],3)
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+ int tmpp1(-1);
+ std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
+ ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+ return ret.retn();
+ }
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg.c_str());
+ }
+ else
+ {// DataArrayDouble.New([1.,3.,4.])
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+ int tmpp1(-1),tmpp2(-1);
+ std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
+ ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+ return ret.retn();
+ }
+ }
+ else if(PyInt_Check(elt0))
+ {
+ int nbOfTuples1(PyInt_AS_LONG(elt0));
+ if(nbOfTuples1<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
+ if(nbOfTuples)
+ {
+ if(!elt2)
+ {
+ if(PyInt_Check(nbOfTuples))
+ {//DataArrayDouble.New(5,2)
+ int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
+ if(nbOfCompo<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuples1,nbOfCompo);
+ return ret.retn();
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg.c_str());
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg.c_str());
+ }
+ else
+ {//DataArrayDouble.New(5)
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+ ret->alloc(nbOfTuples1,1);
+ return ret.retn();
+ }
+ }
+#ifdef WITH_NUMPY
+ else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
+ {//DataArrayDouble.New(numpyArray)
+ return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
+ }
#endif
+ else
+ throw INTERP_KERNEL::Exception(msg.c_str());
+ throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
+}
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
+{
+ self->checkAllocated();
+ const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
+ int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
+ int sw1,sw2;
+ T i1;
+ std::vector<T> v1;
+ typename MEDCoupling::Traits<T>::ArrayType *d1=0;
+ considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
+ int it1,ic1;
+ std::vector<int> vt1,vc1;
+ std::pair<int, std::pair<int,int> > pt1,pc1;
+ MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
+ convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
+ switch(sw2)
+ {
+ case 1:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 2:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 3:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 4:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 5:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 6:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 7:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 8:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 9:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
+ return self;
+ case 3:
+ self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 10:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+ return self;
+ case 3:
+ self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 11:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
+ return self;
+ case 3:
+ self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 12:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
+ return self;
+ case 3:
+ self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 13:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 14:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 15:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
+ return self;
+ case 3:
+ self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ case 16:
+ {
+ switch(sw1)
+ {
+ case 1:
+ self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ case 2:
+ tmp=MEDCoupling::Traits<T>::ArrayType::New();
+ tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+ self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
+ return self;
+ case 3:
+ self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+ return self;
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ break;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ return self;
+}
+
+template<class T>
+PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
+{
+ const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
+ const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
+ self->checkAllocated();
+ int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
+ int it1,ic1;
+ std::vector<int> vt1,vc1;
+ std::pair<int, std::pair<int,int> > pt1,pc1;
+ MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
+ int sw;
+ convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+ MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
+ switch(sw)
+ {
+ case 1:
+ if(nbOfComponents==1)
+ return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
+ return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
+ case 2:
+ return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
+ case 3:
+ return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
+ case 4:
+ return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
+ case 5:
+ return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
+ case 6:
+ {
+ ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+ std::vector<int> v2(1,ic1);
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 7:
+ {
+ ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+ std::vector<int> v2(1,ic1);
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 8:
+ {
+ ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+ std::vector<int> v2(1,ic1);
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 9:
+ {
+ ret=self->selectByTupleIdSafe(&it1,&it1+1);
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 10:
+ {
+ ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 11:
+ {
+ ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 12:
+ {
+ ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 13:
+ {
+ ret=self->selectByTupleIdSafe(&it1,&it1+1);
+ int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+ std::vector<int> v2(nbOfComp);
+ for(int i=0;i<nbOfComp;i++)
+ v2[i]=pc1.first+i*pc1.second.second;
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 14:
+ {
+ ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+ int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+ std::vector<int> v2(nbOfComp);
+ for(int i=0;i<nbOfComp;i++)
+ v2[i]=pc1.first+i*pc1.second.second;
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 15:
+ {
+ ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+ int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+ std::vector<int> v2(nbOfComp);
+ for(int i=0;i<nbOfComp;i++)
+ v2[i]=pc1.first+i*pc1.second.second;
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ case 16:
+ {
+ ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+ int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+ std::vector<int> v2(nbOfComp);
+ for(int i=0;i<nbOfComp;i++)
+ v2[i]=pc1.first+i*pc1.second.second;
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __imul__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
+ switch(sw)
+ {
+ case 1:
+ {
+ self->applyLin(val,0.);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 2:
+ {
+ self->multiplyEqual(a);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 3:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->multiplyEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ self->multiplyEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __idiv__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
+ switch(sw)
+ {
+ case 1:
+ {
+ if(val==0.)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
+ self->applyLin(1./val,0.);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 2:
+ {
+ self->divideEqual(a);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 3:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->divideEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ self->divideEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __iadd__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
+ switch(sw)
+ {
+ case 1:
+ {
+ self->applyLin(1.,val);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 2:
+ {
+ self->addEqual(a);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 3:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->addEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ self->addEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __isub__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
+ switch(sw)
+ {
+ case 1:
+ {
+ self->applyLin(1.,-val);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 2:
+ {
+ self->substractEqual(a);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 3:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->substractEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ self->substractEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+struct SWIGTITraits
+{ };
+
+template<>
+struct SWIGTITraits<double>
+{ static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
+
+template<>
+struct SWIGTITraits<float>
+{ static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
+
+template<>
+struct SWIGTITraits<int>
+{ static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
+
+swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<int>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<int>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
+
+PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
+
+PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
+
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
+{
+ return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
+}
+
+template<class T>
+PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
+{
+ return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
+}
+
+template<class T>
+PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+template<class T>
+PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+template<class T>
+PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+template<class T>
+PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+#endif
targetMesh=MEDCouplingUMesh.New();
targetMesh.setMeshDimension(3);
targetMesh.allocateCells(12);
- for i in xrange(8):
+ for i in range(8):
targetMesh.insertNextCell(NORM_HEXA8,8,targetConn[8*i:8*i+8]);
pass
targetMesh.finishInsertingCells();
targetMesh=MEDCouplingUMesh.New();
targetMesh.setMeshDimension(3);
targetMesh.allocateCells(12);
- for i in xrange(8):
+ for i in range(8):
targetMesh.insertNextCell(NORM_HEXA8,8,targetConn[8*i:8*(i+1)]);
pass
targetMesh.finishInsertingCells();
ret=MEDCouplingUMesh.New("1DSourceMesh",1);
ret.allocateCells(4);
conn=[0,1,2,3,1,2,3,4]
- for i in xrange(4):
+ for i in range(4):
ret.insertNextCell(NORM_SEG2,2,conn[2*i:2*i+2]);
pass
ret.finishInsertingCells();
15,24,25,16,12,21,22,13,
16,25,26,17,13,22,23,14];
mesh.allocateCells(8);
- for i in xrange(8):
+ for i in range(8):
mesh.insertNextCell(NORM_HEXA8,8,conn[8*i:8*(i+1)])
pass
mesh.finishInsertingCells();
mesh.setCoords(coo);
mesh2.setCoords(coo);
mesh.allocateCells(16);
- for i in xrange(12):
+ for i in range(12):
mesh.insertNextCell(NORM_TETRA4,4,conn[4*i:4*i+4])
pass
mesh.insertNextCell(NORM_PYRA5,5,conn[48:53])
#[1,34,29,23,41,32]
conn2=[0,5,1,14,18,17,8,7,4,9,5,2, 12,8,9,13,6,7,8,9]
mesh2.allocateCells(6);
- for i in xrange(4):
+ for i in range(4):
mesh2.insertNextCell(NORM_TRI3,3,conn2[3*i:3*i+3])
pass
mesh2.insertNextCell(NORM_QUAD4,4,conn2[12:16])
m.setCoords(coo)
m.allocateCells()
conn=[[11,8,13],[11,13,12],[8,9,13],[9,14,13],[9,10,15],[9,15,14],[12,13,19],[13,16,19],[13,14,17],[13,17,16],[14,15,17],[15,18,17],[0,1,4,3],[1,2,5,4],[2,6,7,5],[3,4,8,11],[4,5,9,8],[5,7,10,9],[20,22,21,28,41,51],[21,25,20,29,42,51],[22,23,21,30,43,41],[23,27,21,31,35,43],[23,38,24,32,44,52],[24,27,23,33,31,52],[25,21,50,29,45,53],[21,39,50,34,46,45],[21,27,26,35,47,54],[26,39,21,36,34,54],[27,24,26,33,48,47],[24,40,26,37,49,48],[50,39,56,55,46,62,58,71],[39,26,57,56,36,63,59,62],[26,40,61,57,49,64,60,63],[55,56,17,18,58,65,68,72],[56,57,16,17,59,66,69,65],[57,61,19,16,60,67,70,66]]
- for i in xrange(0,12):
+ for i in range(0, 12):
m.insertNextCell(NORM_TRI3,conn[i])
pass
- for i in xrange(12,18):
+ for i in range(12, 18):
m.insertNextCell(NORM_QUAD4,conn[i])
pass
- for i in xrange(18,30):
+ for i in range(18, 30):
m.insertNextCell(NORM_TRI6,conn[i])
pass
- for i in xrange(30,36):
+ for i in range(30, 36):
m.insertNextCell(NORM_QUAD8,conn[i])
pass
fff=MEDCouplingFieldDouble.New(ON_GAUSS_PT) ; fff.setName("CH1RB") ; fff.setNature(IntensiveMaximum)
fff.setMesh(m)
- fff.setGaussLocalizationOnCells(range(0,12),[0.,0.,1.,0.,0.,1.],[0.3333333333333333,0.3333333333333333],[0.5])
- fff.setGaussLocalizationOnCells(range(12,18),[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626],[1.,1.,1.,1.])
- fff.setGaussLocalizationOnCells(range(18,30),[0.,0.,1.,0.,0.,1.,0.5, 0.,0.5, 0.5, 0.,0.5],[0.16666666666666666,0.16666666666666666,0.6666666666666666,0.16666666666666666,0.16666666666666666,0.6666666666666666],[0.16666666666666666,0.16666666666666666,0.16666666666666666])
- fff.setGaussLocalizationOnCells(range(30,36),[-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.],[-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.0,-0.774596669241483,0.774596669241483,0.0,0.0,0.774596669241483,-0.774596669241483,0.0,0.0,0.0],[0.30864197530864196,0.30864197530864196,0.30864197530864196,0.30864197530864196,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.7901234567901234])
+ fff.setGaussLocalizationOnCells(list(range(0, 12)), [0., 0., 1., 0., 0., 1.], [0.3333333333333333, 0.3333333333333333], [0.5])
+ fff.setGaussLocalizationOnCells(list(range(12, 18)), [-1., -1., 1., -1., 1., 1., -1., 1.], [-0.577350269189626, -0.577350269189626, 0.577350269189626, -0.577350269189626, 0.577350269189626, 0.577350269189626, -0.577350269189626, 0.577350269189626], [1., 1., 1., 1.])
+ fff.setGaussLocalizationOnCells(list(range(18, 30)), [0., 0., 1., 0., 0., 1., 0.5, 0., 0.5, 0.5, 0., 0.5], [0.16666666666666666, 0.16666666666666666, 0.6666666666666666, 0.16666666666666666, 0.16666666666666666, 0.6666666666666666], [0.16666666666666666, 0.16666666666666666, 0.16666666666666666])
+ fff.setGaussLocalizationOnCells(list(range(30, 36)), [-1., -1., 1., -1., 1., 1., -1., 1., 0., -1., 1., 0., 0., 1., -1., 0.], [-0.774596669241483, -0.774596669241483, 0.774596669241483, -0.774596669241483, 0.774596669241483, 0.774596669241483, -0.774596669241483, 0.774596669241483, 0.0, -0.774596669241483, 0.774596669241483, 0.0, 0.0, 0.774596669241483, -0.774596669241483, 0.0, 0.0, 0.0], [0.30864197530864196, 0.30864197530864196, 0.30864197530864196, 0.30864197530864196, 0.49382716049382713, 0.49382716049382713, 0.49382716049382713, 0.49382716049382713, 0.7901234567901234])
return MEDCouplingFieldTemplate(fff)
# 2D usecase2 for interpolation Gauss Pt-> Gauss Pt. Coming from ASTER : Please, do not touch
m.setCoords(coo)
m.allocateCells(0)
conn=[[198,194,200],[198,200,199],[194,195,200],[195,201,200],[195,196,202],[195,202,201],[196,197,202],[197,203,202],[199,200,205],[199,205,204],[200,201,205],[201,206,205],[201,202,207],[201,207,206],[202,203,207],[203,208,207],[204,205,210],[204,210,209],[205,206,210],[206,211,210],[206,207,212],[206,212,211],[207,208,212],[208,213,212],[209,210,215],[209,215,214],[210,211,215],[211,216,215],[211,212,217],[211,217,216],[212,213,217],[213,218,217],[214,215,157],[214,157,158],[215,216,157],[216,156,157],[216,217,155],[216,155,156],[217,218,155],[218,163,155],[169,170,174,173],[170,171,175,174],[171,172,176,175],[172,189,190,176],[173,174,178,177],[174,175,179,178],[175,176,180,179],[176,190,191,180],[177,178,182,181],[178,179,183,182],[179,180,184,183],[180,191,192,184],[181,182,186,185],[182,183,187,186],[183,184,188,187],[184,192,193,188],[185,186,194,198],[186,187,195,194],[187,188,196,195],[188,193,197,196],[0,2,1,27,62,89],[1,7,0,28,63,89],[2,3,1,29,64,62],[3,9,1,30,36,64],[3,5,4,31,65,90],[4,9,3,32,30,90],[5,6,4,33,66,65],[6,11,4,34,39,66],[7,1,8,28,67,91],[8,12,7,35,68,91],[1,9,8,36,69,67],[9,14,8,37,42,69],[9,4,10,32,70,92],[10,14,9,38,37,92],[4,11,10,39,71,70],[11,16,10,40,45,71],[12,8,13,35,72,93],[13,17,12,41,73,93],[8,14,13,42,74,72],[14,19,13,43,48,74],[14,10,15,38,75,94],[15,19,14,44,43,94],[10,16,15,45,76,75],[16,21,15,46,51,76],[17,13,18,41,77,95],[18,22,17,47,78,95],[13,19,18,48,79,77],[19,24,18,49,54,79],[19,15,20,44,80,96],[20,24,19,50,49,96],[15,21,20,51,81,80],[21,26,20,52,57,81],[22,18,23,47,82,97],[23,59,22,53,83,97],[18,24,23,54,84,82],[24,60,23,55,85,84],[24,20,25,50,86,98],[25,60,24,56,55,98],[20,26,25,57,87,86],[26,61,25,58,88,87],[59,23,100,99,53,135,115,164],[23,60,101,100,85,136,116,135],[60,25,102,101,56,137,117,136],[25,61,131,102,88,138,118,137],[99,100,104,103,115,139,119,165],[100,101,105,104,116,140,120,139],[101,102,106,105,117,141,121,140],[102,131,132,106,118,142,122,141],[103,104,108,107,119,143,123,166],[104,105,109,108,120,144,124,143],[105,106,110,109,121,145,125,144],[106,132,133,110,122,146,126,145],[107,108,112,111,123,147,127,167],[108,109,113,112,124,148,128,147],[109,110,114,113,125,149,129,148],[110,133,134,114,126,150,130,149],[111,112,155,163,127,151,159,168],[112,113,156,155,128,152,160,151],[113,114,157,156,129,153,161,152],[114,134,158,157,130,154,162,153]]
- for i in xrange(0,40):
+ for i in range(0, 40):
m.insertNextCell(NORM_TRI3,conn[i])
pass
- for i in xrange(40,60):
+ for i in range(40, 60):
m.insertNextCell(NORM_QUAD4,conn[i])
pass
- for i in xrange(60,100):
+ for i in range(60, 100):
m.insertNextCell(NORM_TRI6,conn[i])
pass
- for i in xrange(100,120):
+ for i in range(100, 120):
m.insertNextCell(NORM_QUAD8,conn[i])
pass
fff=MEDCouplingFieldDouble.New(ON_GAUSS_PT) ; fff.setName("CH2RB") ; fff.setNature(IntensiveMaximum)
fff.setMesh(m)
- fff.setGaussLocalizationOnCells(range(0,40),[0.,0.,1.,0.,0.,1.],[0.3333333333333333,0.3333333333333333],[0.5])
- fff.setGaussLocalizationOnCells(range(40,60),[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626],[1.,1.,1.,1.])
- fff.setGaussLocalizationOnCells(range(60,100),[0.,0.,1.,0.,0.,1.,0.5, 0.,0.5, 0.5, 0.,0.5],[0.16666666666666666,0.16666666666666666,0.6666666666666666,0.16666666666666666,0.16666666666666666,0.6666666666666666],[0.16666666666666666,0.16666666666666666,0.16666666666666666])
- fff.setGaussLocalizationOnCells(range(100,120),[-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.],[-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.0,-0.774596669241483,0.774596669241483,0.0,0.0,0.774596669241483,-0.774596669241483,0.0,0.0,0.0],[0.30864197530864196,0.30864197530864196,0.30864197530864196,0.30864197530864196,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.7901234567901234])
+ fff.setGaussLocalizationOnCells(list(range(0, 40)), [0., 0., 1., 0., 0., 1.], [0.3333333333333333, 0.3333333333333333], [0.5])
+ fff.setGaussLocalizationOnCells(list(range(40, 60)), [-1., -1., 1., -1., 1., 1., -1., 1.], [-0.577350269189626, -0.577350269189626, 0.577350269189626, -0.577350269189626, 0.577350269189626, 0.577350269189626, -0.577350269189626, 0.577350269189626], [1., 1., 1., 1.])
+ fff.setGaussLocalizationOnCells(list(range(60, 100)), [0., 0., 1., 0., 0., 1., 0.5, 0., 0.5, 0.5, 0., 0.5], [0.16666666666666666, 0.16666666666666666, 0.6666666666666666, 0.16666666666666666, 0.16666666666666666, 0.6666666666666666], [0.16666666666666666, 0.16666666666666666, 0.16666666666666666])
+ fff.setGaussLocalizationOnCells(list(range(100, 120)), [-1., -1., 1., -1., 1., 1., -1., 1., 0., -1., 1., 0., 0., 1., -1., 0.], [-0.774596669241483, -0.774596669241483, 0.774596669241483, -0.774596669241483, 0.774596669241483, 0.774596669241483, -0.774596669241483, 0.774596669241483, 0.0, -0.774596669241483, 0.774596669241483, 0.0, 0.0, 0.774596669241483, -0.774596669241483, 0.0, 0.0, 0.0], [0.30864197530864196, 0.30864197530864196, 0.30864197530864196, 0.30864197530864196, 0.49382716049382713, 0.49382716049382713, 0.49382716049382713, 0.49382716049382713, 0.7901234567901234])
return MEDCouplingFieldTemplate(fff)
# 3D usecase1 for interpolation Gauss Pt-> Gauss Pt. Coming from ASTER : Please, do not touch
conn=[[3,10,8,4],[19,22,23,20,14],[0,6,1,3,8,4],[4,8,10,5,9,11],[12,16,17,14,19,20],[14,20,23,15,21,24],[1,2,5,4,6,7,9,8],[12,13,15,14,17,18,21,20]]
m.insertNextCell(NORM_TETRA4,conn[0])
m.insertNextCell(NORM_PYRA5,conn[1])
- for i in xrange(2,6):
+ for i in range(2, 6):
m.insertNextCell(NORM_PENTA6,conn[i])
pass
m.insertNextCell(NORM_HEXA8,conn[6])
conn=[[3,10,8,4],[19,22,23,20,14],[0,6,1,3,8,4],[4,8,10,5,9,11],[12,16,17,14,19,20],[14,20,23,15,21,24],[1,2,5,4,6,7,9,8],[12,13,15,14,17,18,21,20]]
m.insertNextCell(NORM_TETRA4,conn[0])
m.insertNextCell(NORM_PYRA5,conn[1])
- for i in xrange(2,6):
+ for i in range(2, 6):
m.insertNextCell(NORM_PENTA6,conn[i])
pass
m.insertNextCell(NORM_HEXA8,conn[6])
fff.setGaussLocalizationOnCells([6,7],[-1.,-1.,-1.,-1.,1.,-1.,1.,1.,-1.,1.,-1.,-1.,-1.,-1.,1.,-1.,1.,1.,1.,1.,1.,1.,-1.,1.],[-0.577350269189626,-0.577350269189626,-0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626],[1.,1.,1.,1.,1.,1.,1.,1.])
return MEDCouplingFieldTemplate(fff)
- def buildCircle(self, center_X, center_Y, radius):
+ def buildCircle(self, center_X, center_Y, radius):
from cmath import rect
from math import pi
- c = [rect(radius, i*pi/4.0) for i in range(8)]
+ c = [rect(radius, i * pi / 4.0) for i in range(8)]
coords = [c[-1].real,c[-1].imag, c[3].real,c[3].imag,
c[5].real,c[5].imag, c[1].real,c[1].imag]
- connec = range(4)
+ connec = list(range(4))
baseMesh = MEDCouplingUMesh.New("circle", 2)
baseMesh.allocateCells(1)
- meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
+ meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2)
meshCoords += (center_X, center_Y)
baseMesh.setCoords(meshCoords)
from cmath import rect
from math import pi
- c = [rect(radius, i*pi/4.0) for i in range(8)]
+ c = [rect(radius, i * pi / 4.0) for i in range(8)]
coords = []
for i in range(8):
coords.extend([c[i].real,c[i].imag])
connec = [7,5,3,1, 6,4,2,0]
baseMesh = MEDCouplingUMesh.New("circle", 2)
baseMesh.allocateCells(1)
- meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
+ meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2)
meshCoords += (center_X, center_Y)
baseMesh.setCoords(meshCoords)
fileName = "testExample_MEDCouplingFieldDouble_WriteVTK"
fs = [ field1, field2, field3 ] # field series
writtenFileName=MEDCouplingFieldDouble.WriteVTK( fileName, fs )
- print "The file name with correct extension is : %s"%(writtenFileName)
+ print("The file name with correct extension is : %s"%(writtenFileName))
#! [PySnippet_MEDCouplingFieldDouble_WriteVTK_1]
import os
os.remove( writtenFileName )
#! [Snippet_DataArrayInt_getTuple_1]
#! [Snippet_DataArrayInt_getTuple_2]
for tpl in dv:
- print tpl
+ print(tpl)
#! [Snippet_DataArrayInt_getTuple_2]
return
da.setValues(arr1,6,1)
da2=da.invertArrayO2N2N2O(6)
expected1=[1,3,0,5,2,4]
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],da2.getIJ(i,0))
pass
#! [PySnippet_DataArrayInt_invertArrayO2N2N2O_1]
da.setValues(arr1,6,1)
da2=da.invertArrayN2O2O2N(7)
expected1=[1,3,0,5,2,4,-1]
- for i in xrange(6):
+ for i in range(6):
self.assertEqual(expected1[i],da2.getIJ(i,0))
pass
#! [PySnippet_DataArrayInt_invertArrayN2O2O2N_1]
#! [PySnippet_DataArrayDouble_getIdsInRange_1]
da=DataArrayDouble()
da.alloc( 10, 1 )
- da[ :, :] = range(10)
+ da[ :, :] = list(range(10))
da2 = da.findIdsInRange( 2.5, 6 )
#! [PySnippet_DataArrayDouble_getIdsInRange_1]
return
dv=da.getDifferentValues(2e-1)
expected2=[2.301,1.3,0.8]
self.assertEqual(3,dv.getNbOfElems())
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14)
pass
#! [Snippet_DataArrayDouble_getDifferentValues1]
self.assertEqual(3,f2.getNumberOfTuples())
self.assertEqual(2,f2.getNumberOfComponents())
expected1=[5.,105.,4.,104.,7.,107.]
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12)
pass
self.assertEqual(3,f2.getMesh().getNumberOfCells())
m2C=f2.getMesh()
self.assertEqual(13,m2C.getNodalConnectivityArrayLen())
expected2=[0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
pass
expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
self.assertEqual(4,f2.getNumberOfTuples())
self.assertEqual(2,f2.getNumberOfComponents())
expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
- for i in xrange(8):
+ for i in range(8):
self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12)
pass
self.assertEqual(2,f2.getMesh().getNumberOfCells())
self.assertEqual(2,f2.getMesh().getMeshDimension())
m2C=f2.getMesh()
self.assertEqual(8,m2C.getNodalConnectivityArrayLen())
- for i in xrange(8):#8 is not an error
+ for i in range(8): # 8 is not an error
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
pass
self.assertEqual(expected3[:4],[int(i) for i in m2C.getNodalConnectivity()][4:])
f2=f1.buildSubPart(arrr)
self.assertEqual(4,f2.getNumberOfTuples())
self.assertEqual(2,f2.getNumberOfComponents())
- for i in xrange(8):
+ for i in range(8):
self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12)
pass
self.assertEqual(2,f2.getMesh().getNumberOfCells())
self.assertEqual(2,f2.getMesh().getMeshDimension())
m2C=f2.getMesh()
self.assertEqual(8,m2C.getNodalConnectivityArrayLen())
- for i in xrange(8):#8 is not an error
+ for i in range(8): # 8 is not an error
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
pass
self.assertEqual(expected3[:4],[int(i) for i in m2C.getNodalConnectivity()][4:8])
self.assertEqual(6,f2.getNumberOfTuples())
self.assertEqual(2,f2.getNumberOfComponents())
expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12)
pass
self.assertEqual(3,f2.getMesh().getNumberOfCells())
self.assertEqual(2,f2.getMesh().getMeshDimension())
m2C=f2.getMesh()
self.assertEqual(13,m2C.getNodalConnectivityArrayLen())
- for i in xrange(12):
+ for i in range(12):
self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
pass
self.assertEqual(expected3[0:4],m2C.getNodalConnectivity().getValues()[4:8])
{
int sz=0,sw=-1,val1=-1;
std::vector<int> val2;
- const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2);
+ const int *inp=convertIntStarLikePyObjToCppIntStar(li,sw,sz,val1,val2);
return self->clonePart(inp,inp+sz);
}
{
std::vector<int> vVal; int iVal=-1;
int sz=-1,sw=0;
- const int *tupleIdsBg=convertObjToPossibleCpp1_Safe(tupleIds,sw,sz,iVal,vVal);
+ const int *tupleIdsBg=convertIntStarLikePyObjToCppIntStar(tupleIds,sw,sz,iVal,vVal);
if(sw==0)
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::computeMeshRestrictionFromTupleIds : none parameter in input !");
DataArrayInt *ret0=0,*ret1=0;
int sz(arr->getNumberOfComponents());
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->normL1(mesh,arr,tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
virtual PyObject *normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
int sz(arr->getNumberOfComponents());
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->normL2(mesh,arr,tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
virtual PyObject *integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs) const throw(INTERP_KERNEL::Exception)
int sz(arr->getNumberOfComponents());
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->integral(mesh,arr,isWAbs,tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
virtual PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception)
//
INTERP_KERNEL::AutoPtr<double> res(new double[spaceDim]);
self->getValueOn(arr,mesh,spaceLoc,res);
- return convertDblArrToPyList(res,spaceDim);
+ return convertDblArrToPyList<double>(res,spaceDim);
}
virtual PyObject *getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k) const throw(INTERP_KERNEL::Exception)
int sz(arr->getNumberOfComponents());
INTERP_KERNEL::AutoPtr<double> res=new double[sz];
self->getValueOnPos(arr,mesh,i,j,k,res);
- return convertDblArrToPyList(res,sz);
+ return convertDblArrToPyList<double>(res,sz);
}
virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, PyObject *loc) const throw(INTERP_KERNEL::Exception)
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *ids(convertObjToPossibleCpp1_Safe(li,sw,sz,v0,v1));
+ const int *ids(convertIntStarLikePyObjToCppIntStar(li,sw,sz,v0,v1));
self->renumberCells(ids,check);
}
//
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
+ const int *old2NewBg(convertIntStarLikePyObjToCppIntStar(old2New,sw,sz,v0,v1));
//
self->renumberArraysForCell(mesh,input1,old2NewBg,check);
}
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *cellIdsBg(convertObjToPossibleCpp1_Safe(cellIds,sw,sz,v0,v1));
+ const int *cellIdsBg(convertIntStarLikePyObjToCppIntStar(cellIds,sw,sz,v0,v1));
return self->computeTupleIdsToSelectFromCellIds(mesh,cellIdsBg,cellIdsBg+sz);
}
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *idsBg(convertObjToPossibleCpp1_Safe(ids,sw,sz,v0,v1));
+ const int *idsBg(convertIntStarLikePyObjToCppIntStar(ids,sw,sz,v0,v1));
DataArrayInt *di(0);
MEDCouplingMesh *ret0=self->buildSubMeshData(mesh,idsBg,idsBg+sz,di);
PyObject *ret=PyTuple_New(2);
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
+ const int *old2NewBg(convertIntStarLikePyObjToCppIntStar(old2New,sw,sz,v0,v1));
self->renumberValuesOnNodes(epsOnVals,old2NewBg,newNbOfNodes,arr);
}
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *old2NewBg(convertObjToPossibleCpp1_Safe(old2New,sw,sz,v0,v1));
+ const int *old2NewBg(convertIntStarLikePyObjToCppIntStar(old2New,sw,sz,v0,v1));
self->renumberValuesOnCells(epsOnVals,mesh,old2NewBg,newSz,arr);
}
{
int sw,sz(-1);
int v0; std::vector<int> v1;
- const int *new2oldBg(convertObjToPossibleCpp1_Safe(new2old,sw,sz,v0,v1));
+ const int *new2oldBg(convertIntStarLikePyObjToCppIntStar(new2old,sw,sz,v0,v1));
self->renumberValuesOnCellsR(mesh,new2oldBg,newSz,arr);
}
}
{
std::size_t sz(0);
const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(geoType,sz));
- return convertDblArrToPyList(ret,sz);
+ return convertDblArrToPyList<double>(ret,sz);
}
static PyObject *GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
{
std::size_t sz(0);
const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(geoType,sz));
- return convertDblArrToPyList(ret,sz);
+ return convertDblArrToPyList<double>(ret,sz);
}
static PyObject *GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
{
std::size_t sz(0);
const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(geoType,sz));
- return convertDblArrToPyList(ret,sz);
+ return convertDblArrToPyList<double>(ret,sz);
}
}
};
DataArrayDouble.__imul__=MEDCouplingDataArrayDoubleImul
DataArrayDouble.__idiv__=MEDCouplingDataArrayDoubleIdiv
DataArrayDouble.__ipow__=MEDCouplingDataArrayDoubleIpow
+DataArrayDouble.__truediv__=DataArrayDouble.__div__
+DataArrayDouble.__itruediv__=MEDCouplingDataArrayDoubleIdiv
+DataArrayDouble.__rtruediv__=DataArrayDouble.__rdiv__
+DataArrayDouble.__floordiv__=DataArrayDouble.__div__
+DataArrayDouble.__ifloordiv__=MEDCouplingDataArrayDoubleIdiv
+DataArrayDouble.__rfloordiv__=DataArrayDouble.__rdiv__
DataArrayInt.__new__=classmethod(MEDCouplingDataArrayIntnew)
DataArrayInt.__iadd__=MEDCouplingDataArrayIntIadd
DataArrayInt.__idiv__=MEDCouplingDataArrayIntIdiv
DataArrayInt.__imod__=MEDCouplingDataArrayIntImod
DataArrayInt.__ipow__=MEDCouplingDataArrayIntIpow
+DataArrayInt.__truediv__=DataArrayInt.__div__
+DataArrayInt.__itruediv__=MEDCouplingDataArrayIntIdiv
+DataArrayInt.__rtruediv__=DataArrayInt.__rdiv__
+DataArrayInt.__floordiv__=DataArrayInt.__div__
+DataArrayInt.__ifloordiv__=MEDCouplingDataArrayIntIdiv
+DataArrayInt.__rfloordiv__=DataArrayInt.__rdiv__
DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew)
+DataArrayFloat.__new__=classmethod(MEDCouplingDataArrayFloatnew)
+DataArrayFloat.__iadd__=MEDCouplingDataArrayFloatIadd
+DataArrayFloat.__isub__=MEDCouplingDataArrayFloatIsub
+DataArrayFloat.__imul__=MEDCouplingDataArrayFloatImul
+DataArrayFloat.__idiv__=MEDCouplingDataArrayFloatIdiv
+DataArrayFloat.__itruediv__=MEDCouplingDataArrayFloatIdiv
+DataArrayFloat.__ifloordiv__=MEDCouplingDataArrayFloatIdiv
+
+MEDCouplingFieldDouble.__new__=classmethod(MEDCouplingFieldDoublenew)
MEDCouplingFieldDouble.__iadd__=MEDCouplingFieldDoubleIadd
MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub
MEDCouplingFieldDouble.__imul__=MEDCouplingFieldDoubleImul
MEDCouplingFieldDouble.__idiv__=MEDCouplingFieldDoubleIdiv
MEDCouplingFieldDouble.__ipow__=MEDCouplingFieldDoubleIpow
+MEDCouplingFieldDouble.__truediv__=MEDCouplingFieldDouble.__div__
+MEDCouplingFieldDouble.__rtruediv__=MEDCouplingFieldDouble.__rdiv__
+MEDCouplingFieldDouble.__itruediv__=MEDCouplingFieldDoubleIdiv
+MEDCouplingFieldDouble.__floordiv__=MEDCouplingFieldDouble.__div__
+MEDCouplingFieldDouble.__rfloordiv__=MEDCouplingFieldDouble.__rdiv__
+MEDCouplingFieldDouble.__ifloordiv__=MEDCouplingFieldDoubleIdiv
+
+MEDCouplingFieldInt.__new__=classmethod(MEDCouplingFieldIntnew)
+
+MEDCouplingFieldFloat.__new__=classmethod(MEDCouplingFieldFloatnew)
DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd
DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub
DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul
DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv
+DataArrayDoubleTuple.__itruediv__=MEDCouplingDataArrayDoubleTupleIdiv
+DataArrayDoubleTuple.__ifloordiv__=MEDCouplingDataArrayDoubleTupleIdiv
DataArrayIntTuple.__iadd__=MEDCouplingDataArrayIntTupleIadd
DataArrayIntTuple.__isub__=MEDCouplingDataArrayIntTupleIsub
DataArrayIntTuple.__imul__=MEDCouplingDataArrayIntTupleImul
DataArrayIntTuple.__idiv__=MEDCouplingDataArrayIntTupleIdiv
+DataArrayIntTuple.__itruediv__=MEDCouplingDataArrayIntTupleIdiv
+DataArrayIntTuple.__ifloordiv__=MEDCouplingDataArrayIntTupleIdiv
DataArrayIntTuple.__imod__=MEDCouplingDataArrayIntTupleImod
DenseMatrix.__iadd__=ParaMEDMEMDenseMatrixIadd
MEDCouplingCMesh.__new__=classmethod(MEDCouplingCMeshnew)
MEDCouplingIMesh.__new__=classmethod(MEDCouplingIMeshnew)
MEDCouplingMappedExtrudedMesh.__new__=classmethod(MEDCouplingExtrudedMeshnew)
-MEDCouplingFieldDouble.__new__=classmethod(MEDCouplingFieldDoublenew)
+
+DataArrayAsciiCharIterator.__next__ = DataArrayAsciiCharIterator.next
+DataArrayIntIterator.__next__ = DataArrayIntIterator.next
+DataArrayDoubleIterator.__next__ = DataArrayDoubleIterator.next
+MEDCouplingUMeshCellIterator.__next__ = MEDCouplingUMeshCellIterator.next
+MEDCouplingUMeshCellByTypeIterator.__next__ = MEDCouplingUMeshCellByTypeIterator.next
del INTERPKERNELExceptionReduce
del MEDCouplingDataArrayDoublenew
del MEDCouplingDataArrayIntIdiv
del MEDCouplingDataArrayIntImod
del MEDCouplingDataArrayBytenew
+del MEDCouplingDataArrayFloatnew
+del MEDCouplingDataArrayFloatIadd
+del MEDCouplingDataArrayFloatIsub
+del MEDCouplingDataArrayFloatImul
+del MEDCouplingDataArrayFloatIdiv
del MEDCouplingDataArrayDoubleTupleIadd
del MEDCouplingDataArrayDoubleTupleIsub
del MEDCouplingDataArrayDoubleTupleImul
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
class MEDCouplingIntersectTest(unittest.TestCase):
def testSwig2NonRegressionBugIntersectMeshes1(self):
self.assertEqual(9,m3.getNodalConnectivityIndex().getNumberOfTuples());
self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
- for i in xrange(44):
+ for i in range(44):
self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
pass
pass
self.assertEqual(10,m3.getNodalConnectivityIndex().getNumberOfTuples());
self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
- for i in xrange(44):
+ for i in range(44):
self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
pass
pass
m2=MEDCouplingUMesh.New();
m2.setMeshDimension(2);
m2.allocateCells(8);
- for i in xrange(8):
+ for i in range(8):
m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
pass
m2.finishInsertingCells();
self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
- for i in xrange(208):
+ for i in range(208):
self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
pass
pass
m2=MEDCouplingUMesh.New();
m2.setMeshDimension(2);
m2.allocateCells(8);
- for i in xrange(8):
+ for i in range(8):
m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
pass
m2.finishInsertingCells();
self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
- for i in xrange(208):
+ for i in range(208):
self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
pass
pass
expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,16,16,17,18,19,19,20,20,20,20,20,21,21,22,23,23,24,24,24,24,24,25,25,26,27,27,28,28,28,28,28,29,29,30,31,31,32,32,32,32,32,32,32,32,32,33,33,33,34,35,35,35,36,36,36,36,36,37,37,38,39,39,40,40,40,40,40,41,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]
expected2=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,2,-1,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,1,2,3,4,5,6,7,-1,4,6,-1,-1,0,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
f3=m3.getMeasureField(False).getArray().getValues();
- for i in xrange(105):
+ for i in range(105):
self.assertAlmostEqual(areaExpected[i],f3[i],10)
pass
self.assertEqual(expected1,d1.getValues())
baseMesh = MEDCouplingUMesh.New("box_circle", 2)
baseMesh.allocateCells(2)
- meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
+ meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2)
meshCoords.setInfoOnComponents(["X [au]", "Y [au]"])
baseMesh.setCoords(meshCoords)
def testIntersect2DMeshesTmp7(self):
eps = 1.0e-8
coords = [-0.5,-0.5, -0.5, 0.5, 0.5, 0.5, 0.5,-0.5]
- connec = range(4)
+ connec = list(range(4))
m1 = MEDCouplingUMesh.New("box", 2)
m1.allocateCells(1)
- meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
+ meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2)
m1.setCoords(meshCoords)
m1.insertNextCell(NORM_POLYGON, connec)
m1.finishInsertingCells()
i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
m1=i.buildUnstructured()
m2=MEDCouplingUMesh("mesh",1) ; m2.setCoords(DataArrayDouble([0.5,2.,2.25,2.,2.5,2.,2.75,2.,3.,2.,4.,2.,5.,2.],7,2)) ; m2.allocateCells()
- for i in xrange(6):
+ for i in range(6):
m2.insertNextCell(NORM_SEG2,[i,i+1])
pass
a,b,c,d=MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1,m2,1e-12)
i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
m1=i.buildUnstructured()
m2=MEDCouplingUMesh("mesh",1) ; m2.setCoords(DataArrayDouble([(0.75,3.25),(0.5,3.5),(0.25,3.25)])) ; m2.allocateCells()
- for i in xrange(2):
+ for i in range(2):
m2.insertNextCell(NORM_SEG2,[i,i+1])
pass
a,b,c,d=MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1,m2,1e-12)
i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
m1=i.buildUnstructured()
m2=MEDCouplingUMesh("mesh",1) ; m2.setCoords(DataArrayDouble([(1.,0.),(3.,2.),(1.,4.)])) ; m2.allocateCells()
- for i in xrange(2):
+ for i in range(2):
m2.insertNextCell(NORM_SEG2,[i,i+1])
pass
a,b,c,d=MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1,m2,1e-12)
connec = [0,1]
m_line = MEDCouplingUMesh("seg", 1)
m_line.allocateCells(1)
- meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
+ meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2)
m_line.setCoords(meshCoords)
m_line.insertNextCell(NORM_SEG2, connec)
a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m_circ, m_line, eps)
coords2 = [0., 1.3, -1.3, 0., -0.6, 0.6, 0., -1.3, -0.5, -0.5]
connec2, cI2 = [NORM_SEG3, 0, 1, 2, NORM_SEG3, 1, 3, 4], [0,4,8]
m_line = MEDCouplingUMesh("seg", 1)
- m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+ m_line.setCoords(DataArrayDouble(coords2, len(coords2) // 2, 2))
m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
coords2 = [-1., 0.25, 1., 0.25]
connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
m_line = MEDCouplingUMesh.New("seg", 1)
- m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+ m_line.setCoords(DataArrayDouble(coords2, len(coords2) // 2, 2))
m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
m_line2 = m_line.deepCopy()
m2 = m.deepCopy()
coords2 = [-2., 1., 2., 1.0]
connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
m_line = MEDCouplingUMesh("seg", 1)
- m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+ m_line.setCoords(DataArrayDouble(coords2, len(coords2) // 2, 2))
m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
coords2 = [-2., 0., 2., 0.]
connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
m_line = MEDCouplingUMesh.New("seg", 1)
- m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+ m_line.setCoords(DataArrayDouble(coords2, len(coords2) // 2, 2))
m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
coords2 = [1., 2., 1., -2.]
connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
m_line = MEDCouplingUMesh("seg", 1)
- m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+ m_line.setCoords(DataArrayDouble(coords2, len(coords2) // 2, 2))
m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
conn = [5,5,2,6,4,5,6,3,0,1,5,4,5,10,8,11,9,5,11,2,1,7,10,9]
connI = [0,5,12,17,24]
m = MEDCouplingUMesh("box",2)
- cooArr = DataArrayDouble(coo,len(coo)/2,2)
+ cooArr = DataArrayDouble(coo, len(coo) // 2, 2)
m.setCoords(cooArr)
m.setConnectivity(DataArrayInt(conn),DataArrayInt(connI))
m.mergeNodes(eps)
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
////////////////////
%typemap(out) MEDCoupling::DataArray*
{
$result=convertDataArrayChar($1,$owner);
}
+
+%typemap(out) MCAuto<MEDCoupling::DataArrayInt>
+{
+ $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt,SWIG_POINTER_OWN|0);
+}
+
+%typemap(out) MCAuto<MEDCoupling::DataArrayDouble>
+{
+ $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIG_POINTER_OWN|0);
+}
+
+%typemap(out) MCAuto<MEDCoupling::DataArrayFloat>
+{
+ $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIG_POINTER_OWN|0);
+}
+
+%typemap(out) MCAuto<MEDCoupling::MapII>
+{
+ $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__MapII,SWIG_POINTER_OWN|0);
+}
//$$$$$$$$$$$$$$$$$$
%newobject MEDCoupling::DataArray::deepCopy;
%newobject MEDCoupling::DataArray::selectByTupleIdSafe;
%newobject MEDCoupling::DataArray::selectByTupleIdSafeSlice;
%newobject MEDCoupling::DataArray::Aggregate;
+%newobject MEDCoupling::DataArrayFloat::New;
+%newobject MEDCoupling::DataArrayFloat::iterator;
+%newobject MEDCoupling::DataArrayFloat::__iter__;
+%newobject MEDCoupling::DataArrayFloat::Meld;
%newobject MEDCoupling::DataArrayInt::New;
%newobject MEDCoupling::DataArrayInt::__iter__;
-%newobject MEDCoupling::DataArrayInt::selectPartDef;
-%newobject MEDCoupling::DataArrayInt::convertToDblArr;
%newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef;
%newobject MEDCoupling::DataArrayInt::subArray;
%newobject MEDCoupling::DataArrayInt::changeNbOfComponents;
%newobject MEDCoupling::DataArrayInt::computeAbs;
%newobject MEDCoupling::DataArrayInt::findIdsInRange;
%newobject MEDCoupling::DataArrayInt::findIdsNotInRange;
-%newobject MEDCoupling::DataArrayInt::findIdsStricltyNegative;
+%newobject MEDCoupling::DataArrayInt::findIdsStrictlyNegative;
%newobject MEDCoupling::DataArrayInt::Aggregate;
%newobject MEDCoupling::DataArrayInt::AggregateIndexes;
%newobject MEDCoupling::DataArrayInt::Meld;
%newobject MEDCoupling::DataArrayAsciiCharTuple::buildDAAsciiChar;
%newobject MEDCoupling::DataArrayDouble::New;
%newobject MEDCoupling::DataArrayDouble::__iter__;
-%newobject MEDCoupling::DataArrayDouble::selectPartDef;
-%newobject MEDCoupling::DataArrayDouble::convertToIntArr;
%newobject MEDCoupling::DataArrayDouble::performCopyOrIncrRef;
%newobject MEDCoupling::DataArrayDouble::Aggregate;
%newobject MEDCoupling::DataArrayDouble::Meld;
%newobject MEDCoupling::DataArrayDouble::accumulatePerChunck;
%newobject MEDCoupling::DataArrayDouble::findIdsInRange;
%newobject MEDCoupling::DataArrayDouble::findIdsNotInRange;
+%newobject MEDCoupling::DataArrayDouble::findIdsStrictlyNegative;
%newobject MEDCoupling::DataArrayDouble::negate;
%newobject MEDCoupling::DataArrayDouble::computeAbs;
%newobject MEDCoupling::DataArrayDouble::applyFunc;
%feature("unref") DataArrayAsciiChar "$this->decrRef();"
%feature("unref") DataArrayByte "$this->decrRef();"
+%feature("unref") MapII "$this->decrRef();"
%feature("unref") PartDefinition "$this->decrRef();"
%feature("unref") DataArrayPartDefinition "$this->decrRef();"
%feature("unref") SlicePartDefinition "$this->decrRef();"
} MEDCouplingAxisType;
class DataArrayInt;
+
+ class MapII : public RefCountObject, public TimeLabel
+ {
+ public:
+ static MCAuto< MapII > New();
+ };
class PartDefinition : public RefCountObject, public TimeLabel
{
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !");
+ GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !");
int a,b;
DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b);
return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step));
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::getSlice (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !");
+ GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !");
int a,b;
DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b);
return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step));
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !");
+ GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !");
return DataArray::GetNumberOfItemGivenBES(strt,stp,step,"");
}
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
+ GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,"");
}
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !");
+ GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !");
return DataArray::GetNumberOfItemGivenBES(strt,stp,step,"");
}
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
+ GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,"");
}
if(sz!=2)
throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid tuple in input ! Should be of size 2 ! Invalid overwrite of __getstate__ ?");
PyObject *a0(PyTuple_GetItem(inp,0));
- if(!PyString_Check(a0))
- throw INTERP_KERNEL::Exception(MSG);
+ self->setName(convertPyObjectToStr(a0,MSG));
PyObject *a1(PyTuple_GetItem(inp,1));
std::vector<std::string> a1cpp;
if(!fillStringVector(a1,a1cpp))
throw INTERP_KERNEL::Exception(MSG);
- self->setName(PyString_AsString(a0));
self->setInfoOnComponents(a1cpp);
}
}
};
+
+ class DataArrayDouble;
+
+ class DataArrayFloat : public DataArray
+ {
+ public:
+ static DataArrayFloat *New();
+ void fillWithValue(float val) throw(INTERP_KERNEL::Exception);
+ bool isEqual(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception);
+ bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception);
+ bool isUniform(float val, float eps) const throw(INTERP_KERNEL::Exception);
+ void pushBackSilent(float val) throw(INTERP_KERNEL::Exception);
+ void iota(float init=0.) throw(INTERP_KERNEL::Exception);
+ DataArrayFloatIterator *iterator() throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayDouble> convertToDblArr() const throw(INTERP_KERNEL::Exception);
+ static DataArrayFloat *Meld(const DataArrayFloat *a1, const DataArrayFloat *a2) throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ DataArrayFloat() throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayFloat::New();
+ }
+
+ static DataArrayFloat *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_New<float>(elt0,nbOfTuples,elt2);
+ }
+
+ DataArrayFloat(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDCoupling_DataArrayFloat_New__SWIG_1(elt0,nbOfTuples,elt2);
+ }
+
+ DataArrayFloatIterator *__iter__() throw(INTERP_KERNEL::Exception)
+ {
+ return self->iterator();
+ }
+
+ std::string __repr__() const throw(INTERP_KERNEL::Exception)
+ {
+ std::ostringstream oss;
+ self->reprQuickOverview(oss);
+ return oss.str();
+ }
+
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->reprNotTooLong();
+ }
+
+ int __len__() const throw(INTERP_KERNEL::Exception)
+ {
+ if(self->isAllocated())
+ {
+ return self->getNumberOfTuples();
+ }
+ else
+ {
+ throw INTERP_KERNEL::Exception("DataArrayFloat::__len__ : Instance is NOT allocated !");
+ }
+ }
+
+ PyObject *getValues() const throw(INTERP_KERNEL::Exception)
+ {
+ const float *vals(self->begin());
+ return convertDblArrToPyList<float>(vals,self->getNbOfElems());
+ }
+
+ PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception)
+ {
+ const float *vals(self->begin());
+ int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples());
+ return convertDblArrToPyListOfTuple<float>(vals,nbOfComp,nbOfTuples);
+ }
+
+ PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT__getitem<float>(self,obj);
+ }
+
+ DataArrayFloat *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT__setitem__<float>(self,obj,value);
+ }
+
+ PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_iadd<float>(trueSelf,obj,self);
+ }
+
+ PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_isub<float>(trueSelf,obj,self);
+ }
+
+ PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_imul<float>(trueSelf,obj,self);
+ }
+
+ PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_idiv<float>(trueSelf,obj,self);
+ }
+
+#ifdef WITH_NUMPY
+ PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug !
+ {
+ return ToNumPyArray<DataArrayFloat,float>(self,NPY_FLOAT,"DataArrayFloat");
+ }
+#endif
+
+ // serialization
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"DataArrayFloat");
+ }
+
+ PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+ {
+#ifdef WITH_NUMPY
+ if(!self->isAllocated())
+ throw INTERP_KERNEL::Exception("PyWrap of DataArrayFloat.__getnewargs__ : self is not allocated !");
+ PyObject *ret(PyTuple_New(1));
+ PyObject *ret0(PyDict_New());
+ PyObject *numpyArryObj(MEDCoupling_DataArrayFloat_toNumPyArray(self));
+ {// create a dict to discriminite in __new__ if __init__ should be called. Not beautiful but not idea ...
+ PyObject *tmp1(PyInt_FromLong(0));
+ PyDict_SetItem(ret0,tmp1,numpyArryObj); Py_DECREF(tmp1); Py_DECREF(numpyArryObj);
+ PyTuple_SetItem(ret,0,ret0);
+ }
+ return ret;
+#else
+ throw INTERP_KERNEL::Exception("PyWrap of DataArrayByte.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
+#endif
+ }
+ }
+ };
+
+ class DataArrayFloatTuple;
+
+ class DataArrayFloatIterator
+ {
+ public:
+ DataArrayFloatIterator(DataArrayFloat *da);
+ ~DataArrayFloatIterator();
+ %extend
+ {
+ PyObject *next()
+ {
+ DataArrayFloatTuple *ret=self->nextt();
+ if(ret)
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple,SWIG_POINTER_OWN|0);
+ else
+ {
+ PyErr_SetString(PyExc_StopIteration,"No more data.");
+ return 0;
+ }
+ }
+ }
+ };
+
+ class DataArrayFloatTuple
+ {
+ public:
+ int getNumberOfCompo() const throw(INTERP_KERNEL::Exception);
+ DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->repr();
+ }
+
+ float __float__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->floatValue();
+ }
+
+ DataArrayFloat *buildDAFloat() throw(INTERP_KERNEL::Exception)
+ {
+ return self->buildDAFloat(1,self->getNumberOfCompo());
+ }
+
+ /*PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayFloat> ret=self->buildDAFloat(1,self->getNumberOfCompo());
+ MEDCoupling_DataArrayFloat____imul___(ret,0,obj);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }*/
+
+ PyObject *__len__() throw(INTERP_KERNEL::Exception)
+ {
+ return PyInt_FromLong(self->getNumberOfCompo());
+ }
+ }
+ };
class DataArrayInt;
class DataArrayDoubleIterator;
std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception);
bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
void applyFuncFast64(const std::string& func) throw(INTERP_KERNEL::Exception);
DataArrayInt *findIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception);
DataArrayInt *findIdsNotInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *findIdsStrictlyNegative() const throw(INTERP_KERNEL::Exception);
static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
static DataArrayDouble *Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
void divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception);
static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
void powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsGreaterOrEqualTo(double val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsGreaterThan(double val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsLowerOrEqualTo(double val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsLowerThan(double val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> convertToIntArr() const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayDouble> selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayDouble> cumSum() const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayFloat> convertToFloatArr() const throw(INTERP_KERNEL::Exception);
%extend
{
DataArrayDouble() throw(INTERP_KERNEL::Exception)
- {
- return DataArrayDouble::New();
- }
+ {
+ return DataArrayDouble::New();
+ }
static DataArrayDouble *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
{
- const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
- std::string msg(msgBase);
-#ifdef WITH_NUMPY
- msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
-#endif
- msg+=" !";
- if(PyList_Check(elt0) || PyTuple_Check(elt0))
- {
- if(nbOfTuples)
- {
- if(PyInt_Check(nbOfTuples))
- {
- int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
- if(nbOfTuples1<0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
- if(elt2)
- {
- if(PyInt_Check(elt2))
- {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
- int nbOfCompo=PyInt_AS_LONG(elt2);
- if(nbOfCompo<0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo);
- ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
- return ret.retn();
- }
- else
- throw INTERP_KERNEL::Exception(msg.c_str());
- }
- else
- {//DataArrayDouble.New([1.,3.,4.],3)
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- int tmpp1=-1;
- std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1);
- ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
- return ret.retn();
- }
- }
- else
- throw INTERP_KERNEL::Exception(msg.c_str());
- }
- else
- {// DataArrayDouble.New([1.,3.,4.])
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- int tmpp1=-1,tmpp2=-1;
- std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
- ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
- return ret.retn();
- }
- }
- else if(PyInt_Check(elt0))
- {
- int nbOfTuples1=PyInt_AS_LONG(elt0);
- if(nbOfTuples1<0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
- if(nbOfTuples)
- {
- if(!elt2)
- {
- if(PyInt_Check(nbOfTuples))
- {//DataArrayDouble.New(5,2)
- int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
- if(nbOfCompo<0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples1,nbOfCompo);
- return ret.retn();
- }
- else
- throw INTERP_KERNEL::Exception(msg.c_str());
- }
- else
- throw INTERP_KERNEL::Exception(msg.c_str());
- }
- else
- {//DataArrayDouble.New(5)
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples1,1);
- return ret.retn();
- }
- }
-#ifdef WITH_NUMPY
- else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
- {//DataArrayDouble.New(numpyArray)
- return BuildNewInstance<DataArrayDouble,double>(elt0,NPY_DOUBLE,&PyCallBackDataArrayDouble_RefType,"FLOAT64");
- }
-#endif
- else
- throw INTERP_KERNEL::Exception(msg.c_str());
- throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
+ return DataArrayT_New<double>(elt0,nbOfTuples,elt2);
}
DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
- {
- return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2);
- }
-
- DataArrayDouble *selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception)
{
- MCAuto<DataArrayDouble> ret(self->selectPartDef(pd));
- return ret.retn();
+ return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2);
}
void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception)
PyObject *getValues() const throw(INTERP_KERNEL::Exception)
{
- const double *vals=self->getConstPointer();
- return convertDblArrToPyList(vals,self->getNbOfElems());
+ const double *vals(self->begin());
+ return convertDblArrToPyList<double>(vals,self->getNbOfElems());
}
#ifdef WITH_NUMPY
PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception)
{
- const double *vals=self->getConstPointer();
- int nbOfComp=self->getNumberOfComponents();
- int nbOfTuples=self->getNumberOfTuples();
- return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples);
+ const double *vals(self->begin());
+ int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples());
+ return convertDblArrToPyListOfTuple<double>(vals,nbOfComp,nbOfTuples);
}
DataArrayDouble *symmetry3DPlane(PyObject *point, PyObject *normalVector) throw(INTERP_KERNEL::Exception)
const double *vectorPtr(convertObjToPossibleCpp5_Safe(normalVector,sw,val,a,aa,bb,msg,1,3,true));
double res[9];
DataArrayDouble::GiveBaseForPlane(vectorPtr,res);
- return convertDblArrToPyListOfTuple(res,3,3);
+ return convertDblArrToPyListOfTuple<double>(res,3,3);
}
DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, PyObject *center, PyObject *vector) const
PyObject *getMinMaxPerComponent() const throw(INTERP_KERNEL::Exception)
{
- int nbOfCompo=self->getNumberOfComponents();
- INTERP_KERNEL::AutoPtr<double> tmp=new double[2*nbOfCompo];
+ int nbOfCompo(self->getNumberOfComponents());
+ INTERP_KERNEL::AutoPtr<double> tmp(new double[2*nbOfCompo]);
self->getMinMaxPerComponent(tmp);
- PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo);
+ PyObject *ret=convertDblArrToPyListOfTuple<double>(tmp,2,nbOfCompo);
return ret;
}
int sz=self->getNumberOfComponents();
INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
self->accumulate(tmp);
- return convertDblArrToPyList(tmp,sz);
+ return convertDblArrToPyList<double>(tmp,sz);
}
DataArrayDouble *accumulatePerChunck(PyObject *indexArr) const throw(INTERP_KERNEL::Exception)
{
int sw,sz,val;
std::vector<int> val2;
- const int *bg=convertObjToPossibleCpp1_Safe(indexArr,sw,sz,val,val2);
+ const int *bg=convertIntStarLikePyObjToCppIntStar(indexArr,sw,sz,val,val2);
return self->accumulatePerChunck(bg,bg+sz);
}
std::size_t sz(retCpp.size());
PyObject *res(PyList_New(sz));
for(std::size_t i=0;i<sz;i++)
- PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(retCpp[i].retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
- return res;
- }
-
- PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception)
- {
- int sz=self->getNumberOfComponents();
- INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
- self->getTuple(tupleId,tmp);
- return convertDblArrToPyList(tmp,sz);
- }
-
- static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception)
- {
- std::vector<const DataArrayDouble *> tmp;
- convertFromPyObjVectorOfObj<const DataArrayDouble *>(li,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",tmp);
- return DataArrayDouble::Aggregate(tmp);
- }
-
- static DataArrayDouble *Meld(PyObject *li) throw(INTERP_KERNEL::Exception)
- {
- std::vector<const DataArrayDouble *> tmp;
- convertFromPyObjVectorOfObj<const DataArrayDouble *>(li,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",tmp);
- return DataArrayDouble::Meld(tmp);
- }
-
- PyObject *computeTupleIdsNearTuples(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception)
- {
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- int nbComp=self->getNumberOfComponents(),nbTuples=-1;
- const char msg[]="Python wrap of DataArrayDouble::computeTupleIdsNearTuples : ";
- const double *pos=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,msg,nbComp,true,nbTuples);
- MCAuto<DataArrayDouble> inpu=DataArrayDouble::New(); inpu->useArray(pos,false,CPP_DEALLOC,nbTuples,nbComp);
- DataArrayInt *c=0,*cI=0;
- self->computeTupleIdsNearTuples(inpu,eps,c,cI);
- PyObject *ret=PyTuple_New(2);
- PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- return ret;
- }
-
- PyObject *areIncludedInMe(const DataArrayDouble *other, double prec) const throw(INTERP_KERNEL::Exception)
- {
- DataArrayInt *ret1=0;
- bool ret0=self->areIncludedInMe(other,prec,ret1);
- PyObject *ret=PyTuple_New(2);
- PyObject *ret0Py=ret0?Py_True:Py_False;
- Py_XINCREF(ret0Py);
- PyTuple_SetItem(ret,0,ret0Py);
- PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- return ret;
- }
-
- PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
- {
- const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
- const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
- self->checkAllocated();
- int nbOfTuples=self->getNumberOfTuples();
- int nbOfComponents=self->getNumberOfComponents();
- int it1,ic1;
- std::vector<int> vt1,vc1;
- std::pair<int, std::pair<int,int> > pt1,pc1;
- DataArrayInt *dt1=0,*dc1=0;
- int sw;
- convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
- MCAuto<DataArrayDouble> ret;
- switch(sw)
- {
- case 1:
- if(nbOfComponents==1)
- return PyFloat_FromDouble(self->getIJSafe(it1,0));
- return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- case 2:
- return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- case 3:
- return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- case 4:
- return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- case 5:
- return PyFloat_FromDouble(self->getIJSafe(it1,ic1));
- case 6:
- {
- ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
- std::vector<int> v2(1,ic1);
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 7:
- {
- ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
- std::vector<int> v2(1,ic1);
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 8:
- {
- ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
- std::vector<int> v2(1,ic1);
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 9:
- {
- ret=self->selectByTupleIdSafe(&it1,&it1+1);
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 10:
- {
- ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 11:
- {
- ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 12:
- {
- ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 13:
- {
- ret=self->selectByTupleIdSafe(&it1,&it1+1);
- int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
- std::vector<int> v2(nbOfComp);
- for(int i=0;i<nbOfComp;i++)
- v2[i]=pc1.first+i*pc1.second.second;
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 14:
- {
- ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
- int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
- std::vector<int> v2(nbOfComp);
- for(int i=0;i<nbOfComp;i++)
- v2[i]=pc1.first+i*pc1.second.second;
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 15:
- {
- ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
- int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
- std::vector<int> v2(nbOfComp);
- for(int i=0;i<nbOfComp;i++)
- v2[i]=pc1.first+i*pc1.second.second;
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- case 16:
- {
- ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
- int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
- std::vector<int> v2(nbOfComp);
- for(int i=0;i<nbOfComp;i++)
- v2[i]=pc1.first+i*pc1.second.second;
- return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- }
-
- DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
- {
- self->checkAllocated();
- const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
- int nbOfTuples=self->getNumberOfTuples();
- int nbOfComponents=self->getNumberOfComponents();
- int sw1,sw2;
- double i1;
- std::vector<double> v1;
- DataArrayDouble *d1=0;
- convertObjToPossibleCpp4(value,sw1,i1,v1,d1);
- int it1,ic1;
- std::vector<int> vt1,vc1;
- std::pair<int, std::pair<int,int> > pt1,pc1;
- DataArrayInt *dt1=0,*dc1=0;
- convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
- MCAuto<DataArrayDouble> tmp;
- switch(sw2)
- {
- case 1:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 2:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 3:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 4:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 5:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 6:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 7:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 8:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 9:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
- return self;
- case 3:
- self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 10:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
- return self;
- case 3:
- self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 11:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
- return self;
- case 3:
- self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 12:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
- return self;
- case 3:
- self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 13:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 14:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 15:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
- return self;
- case 3:
- self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- case 16:
- {
- switch(sw1)
- {
- case 1:
- self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
- return self;
- case 2:
- tmp=DataArrayDouble::New();
- tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
- self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
- return self;
- case 3:
- self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
- return self;
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- break;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
- return self;
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(retCpp[i].retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ return res;
+ }
+
+ PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception)
+ {
+ int sz=self->getNumberOfComponents();
+ INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
+ self->getTuple(tupleId,tmp);
+ return convertDblArrToPyList<double>(tmp,sz);
+ }
+
+ static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const DataArrayDouble *> tmp;
+ convertFromPyObjVectorOfObj<const DataArrayDouble *>(li,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",tmp);
+ return DataArrayDouble::Aggregate(tmp);
+ }
+
+ static DataArrayDouble *Meld(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const DataArrayDouble *> tmp;
+ convertFromPyObjVectorOfObj<const DataArrayDouble *>(li,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",tmp);
+ return DataArrayDouble::Meld(tmp);
+ }
+
+ PyObject *computeTupleIdsNearTuples(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception)
+ {
+ double val;
+ DataArrayDouble *a;
+ DataArrayDoubleTuple *aa;
+ std::vector<double> bb;
+ int sw;
+ int nbComp=self->getNumberOfComponents(),nbTuples=-1;
+ const char msg[]="Python wrap of DataArrayDouble::computeTupleIdsNearTuples : ";
+ const double *pos=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,msg,nbComp,true,nbTuples);
+ MCAuto<DataArrayDouble> inpu=DataArrayDouble::New(); inpu->useArray(pos,false,CPP_DEALLOC,nbTuples,nbComp);
+ DataArrayInt *c=0,*cI=0;
+ self->computeTupleIdsNearTuples(inpu,eps,c,cI);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ PyObject *areIncludedInMe(const DataArrayDouble *other, double prec) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret1=0;
+ bool ret0=self->areIncludedInMe(other,prec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT__getitem<double>(self,obj);
+ }
+
+ DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT__setitem__<double>(self,obj,value);
}
DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception)
}
#endif
//
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __iadd__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- self->applyLin(1.,val);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 2:
- {
- self->addEqual(a);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->addEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- self->addEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayT_iadd<double>(trueSelf,obj,self);
}
PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception)
}
#endif
//
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __isub__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- self->applyLin(1,-val);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 2:
- {
- self->substractEqual(a);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->substractEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- self->substractEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayT_isub<double>(trueSelf,obj,self);
}
PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception)
}
#endif
//
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __imul__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- self->applyLin(val,0.);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 2:
- {
- self->multiplyEqual(a);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->multiplyEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- self->multiplyEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayT_imul<double>(trueSelf,obj,self);
}
PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception)
}
#endif
//
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __idiv__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- if(val==0.)
- throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
- self->applyLin(1./val,0.);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 2:
- {
- self->divideEqual(a);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->divideEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- self->divideEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayT_idiv<double>(trueSelf,obj,self);
}
DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception)
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
MEDCoupling::DataArrayInt *daIntTyypp=0;
const double *pt=self->getConstPointer();
int nbc=self->getNumberOfCompo();
- convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::vector<double> multiValV;
MEDCoupling::DataArrayDoubleTuple *daIntTyyppV=0;
int nbc=self->getNumberOfCompo();
- convertObjToPossibleCpp44(value,sw1,singleValV,multiValV,daIntTyyppV);
+ convertDoubleStarLikePyObjToCpp(value,sw1,singleValV,multiValV,daIntTyyppV);
int singleVal;
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
double *pt=self->getPointer();
- convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
switch(sw2)
{
case 1:
DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
- DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception);
+ MCAuto< MapII > invertArrayN2O2O2NOptimized() const throw(INTERP_KERNEL::Exception);
DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception);
DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception);
bool isIota(int sizeExpected) const throw(INTERP_KERNEL::Exception);
bool isUniform(int val) const throw(INTERP_KERNEL::Exception);
+ int checkUniformAndGuess() const throw(INTERP_KERNEL::Exception);
bool hasUniqueValues() const throw(INTERP_KERNEL::Exception);
DataArrayInt *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
void transpose() throw(INTERP_KERNEL::Exception);
void applyRPow(int val) throw(INTERP_KERNEL::Exception);
DataArrayInt *findIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception);
DataArrayInt *findIdsNotInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *findIdsStricltyNegative() const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *findIdsStrictlyNegative() const throw(INTERP_KERNEL::Exception);
bool checkAllIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception);
static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2) throw(INTERP_KERNEL::Exception);
static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);
void modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);
void powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> fromLinkedListOfPairToList() const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsGreaterOrEqualTo(int val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsGreaterThan(int val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsLowerOrEqualTo(int val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> findIdsLowerThan(int val) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayInt> selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayDouble> convertToDblArr() const throw(INTERP_KERNEL::Exception);
+ MCAuto<DataArrayFloat> convertToFloatArr() const throw(INTERP_KERNEL::Exception);
public:
static DataArrayInt *Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception);
%extend
{
return MEDCoupling_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp);
}
-
+
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
return self->reprNotTooLong();
{
return self->iterator();
}
-
- DataArrayInt *selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception)
- {
- MCAuto<DataArrayInt> ret(self->selectPartDef(pd));
- return ret.retn();
- }
PyObject *accumulate() const throw(INTERP_KERNEL::Exception)
{
{
int sw,sz,val;
std::vector<int> val2;
- const int *bg=convertObjToPossibleCpp1_Safe(indexArr,sw,sz,val,val2);
+ const int *bg=convertIntStarLikePyObjToCppIntStar(indexArr,sw,sz,val,val2);
return self->accumulatePerChunck(bg,bg+sz);
}
{
int sw,sz,val;
std::vector<int> val2;
- const int *bg(convertObjToPossibleCpp1_Safe(inputTuple,sw,sz,val,val2));
+ const int *bg(convertIntStarLikePyObjToCppIntStar(inputTuple,sw,sz,val,val2));
return self->findIdsEqualTuple(bg,bg+sz);
}
if(!PySlice_Check(slic))
throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : expecting a pyslice as second (first) parameter !");
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
- GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !");
+ GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !");
if(strt==std::numeric_limits<int>::max() || stp==std::numeric_limits<int>::max())
throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !");
return self->buildExplicitArrOfSliceOnScaledArr(strt,stp,step);
int newNbOfTuples=-1;
int szArr,szArrI,sw,iTypppArr,iTypppArrI;
std::vector<int> stdvecTyyppArr,stdvecTyyppArrI;
- const int *arrPtr=convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr);
- const int *arrIPtr=convertObjToPossibleCpp1_Safe(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI);
+ const int *arrPtr=convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *arrIPtr=convertIntStarLikePyObjToCppIntStar(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI);
DataArrayInt *ret0=MEDCoupling::DataArrayInt::ConvertIndexArrayToO2N(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples);
PyObject *ret=PyTuple_New(2);
PyTuple_SetItem(ret,0,SWIG_NewPointerObj((void*)ret0,SWIGTYPE_p_MEDCoupling__DataArrayInt,SWIG_POINTER_OWN | 0));
MCAuto<DataArrayInt> ret(DataArrayInt::New());
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *arrPtr(convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr));
+ const int *arrPtr(convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr));
int *pt(MEDCoupling::DataArrayInt::CheckAndPreparePermutation(arrPtr,arrPtr+szArr));
ret->useArray(pt,true,MEDCoupling::C_DEALLOC,szArr,1);
return ret.retn();
void transformWithIndArr(PyObject *li) throw(INTERP_KERNEL::Exception)
{
void *da=0;
- int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 );
+ int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 ));
if (!SWIG_IsOK(res1))
{
- int size;
- INTERP_KERNEL::AutoPtr<int> tmp=convertPyToNewIntArr2(li,&size);
- self->transformWithIndArr(tmp,tmp+size);
+ int res2(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__MapII, 0 | 0 ));
+ if(SWIG_IsOK(res2))
+ {
+ MapII *m=reinterpret_cast<MapII *>(da);
+ self->transformWithIndArr(*m);
+ }
+ else
+ {
+ int size;
+ INTERP_KERNEL::AutoPtr<int> tmp=convertPyToNewIntArr2(li,&size);
+ self->transformWithIndArr(tmp,tmp+size);
+ }
}
else
{
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::vector<int> multiVal;
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCpp(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::vector<int> v1;
DataArrayInt *d1=0;
DataArrayIntTuple *dd1=0;
- convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1);
+ convertIntStarLikePyObjToCpp(value,sw1,i1,v1,d1,dd1);
int it1,ic1;
std::vector<int> vt1,vc1;
std::pair<int, std::pair<int,int> > pt1,pc1;
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
std::vector<int> aa;
DataArrayIntTuple *aaa;
int sw;
- convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa);
+ convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa);
switch(sw)
{
case 1:
{
int szArr,sw,iTypppArr;
std::vector<int> stdvecTyyppArr;
- const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr);
self->pushBackValsSilent(tmp,tmp+szArr);
}
Py_XINCREF(trueSelf);
return trueSelf;
}
-
PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
MCAuto<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
MEDCoupling::DataArrayInt *daIntTyypp=0;
const int *pt=self->getConstPointer();
int nbc=self->getNumberOfCompo();
- convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
switch(sw)
{
case 1:
std::pair<int, std::pair<int,int> > slic;
MEDCoupling::DataArrayInt *daIntTyypp=0;
int *pt=self->getPointer();
- convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
switch(sw2)
{
case 1:
{
int sz=-1,sw=-1;
int ival=-1; std::vector<int> ivval;
- const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval);
+ const int *pt=convertIntStarLikePyObjToCppIntStar(tupl,sw,sz,ival,ivval);
std::vector<char> vals(sz);
std::copy(pt,pt+sz,vals.begin());
return self->presenceOfTuple(vals);
{
int sz=-1,sw=-1;
int ival=-1; std::vector<int> ivval;
- const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval);
+ const int *pt=convertIntStarLikePyObjToCppIntStar(vals,sw,sz,ival,ivval);
std::vector<char> vals2(sz);
std::copy(pt,pt+sz,vals2.begin());
return self->presenceOfValue(vals2);
{
int sz=-1,sw=-1;
int ival=-1; std::vector<int> ivval;
- const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval);
+ const int *pt=convertIntStarLikePyObjToCppIntStar(vals,sw,sz,ival,ivval);
std::vector<char> vals2(sz);
std::copy(pt,pt+sz,vals2.begin());
return self->findIdFirstEqual(vals2);
{
int sz=-1,sw=-1;
int ival=-1; std::vector<int> ivval;
- const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval);
+ const int *pt=convertIntStarLikePyObjToCppIntStar(tupl,sw,sz,ival,ivval);
std::vector<char> vals(sz);
std::copy(pt,pt+sz,vals.begin());
return self->findIdFirstEqualTuple(vals);
{
int sz=-1,sw=-1;
int ival=-1; std::vector<int> ivval;
- const int *pt=convertObjToPossibleCpp1_Safe(strOrListOfInt,sw,sz,ival,ivval);
+ const int *pt=convertIntStarLikePyObjToCppIntStar(strOrListOfInt,sw,sz,ival,ivval);
std::vector<char> vals(sz);
std::copy(pt,pt+sz,vals.begin());
return self->findIdSequence(vals);
std::vector<int> v1;
DataArrayInt *d1=0;
DataArrayIntTuple *dd1=0;
- convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1);
+ convertIntStarLikePyObjToCpp(value,sw1,i1,v1,d1,dd1);
int it1,ic1;
std::vector<int> vt1,vc1;
std::pair<int, std::pair<int,int> > pt1,pc1;
else
throw INTERP_KERNEL::Exception(msg);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ else if(PyUnicode_Check(nbOfTuples))
+ {
+ if(PyUnicode_GET_LENGTH(nbOfTuples)!=1)
+ throw INTERP_KERNEL::Exception(msg);
+ //DataArrayAsciiChar.New(["abc","de","fghi"],"t")
+ std::vector<std::string> tmp;
+ if(fillStringVector(elt0,tmp))
+ return DataArrayAsciiChar::New(tmp,PyUnicode_AsUTF8(nbOfTuples)[0]);
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception(msg);
}
std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin());
return self->presenceOfTuple(vals);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ else if(PyUnicode_Check(tupl))
+ {
+ Py_ssize_t sz=PyUnicode_GET_LENGTH(tupl);
+ std::vector<char> vals(sz);
+ std::copy(PyUnicode_AsUTF8(tupl),PyUnicode_AsUTF8(tupl)+sz,vals.begin());
+ return self->presenceOfTuple(vals);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfTuple : only strings in input supported !");
}
std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin());
return self->presenceOfValue(vals2);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(vals))
+ {
+ Py_ssize_t sz=PyUnicode_GET_LENGTH(vals);
+ std::vector<char> vals2(sz);
+ std::copy(PyUnicode_AsUTF8(vals),PyUnicode_AsUTF8(vals)+sz,vals2.begin());
+ return self->presenceOfValue(vals2);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfValue : only strings in input supported !");
}
std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin());
return self->findIdFirstEqual(vals2);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(vals))
+ {
+ Py_ssize_t sz=PyUnicode_GET_LENGTH(vals);
+ std::vector<char> vals2(sz);
+ std::copy(PyUnicode_AsUTF8(vals),PyUnicode_AsUTF8(vals)+sz,vals2.begin());
+ return self->findIdFirstEqual(vals2);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::findIdFirstEqual : only strings in input supported !");
}
std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin());
return self->findIdFirstEqualTuple(vals);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(tupl))
+ {
+ Py_ssize_t sz=PyUnicode_GET_LENGTH(tupl);
+ std::vector<char> vals(sz);
+ std::copy(PyUnicode_AsUTF8(tupl),PyUnicode_AsUTF8(tupl)+sz,vals.begin());
+ return self->findIdFirstEqualTuple(vals);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::findIdFirstEqualTuple : only strings in input supported !");
}
std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin());
return self->findIdSequence(vals);
}
+%#if PY_VERSION_HEX >= 0x03000000
+ else if(PyUnicode_Check(strOrListOfInt))
+ {
+ Py_ssize_t sz=PyUnicode_GET_LENGTH(strOrListOfInt);
+ std::vector<char> vals(sz);
+ std::copy(PyUnicode_AsUTF8(strOrListOfInt),PyUnicode_AsUTF8(strOrListOfInt)+sz,vals.begin());
+ return self->findIdSequence(vals);
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !");
}
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !");
}
+%#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(obj))
+ {
+ Py_ssize_t sz;
+ char *pt=PyUnicode_AsUTF8AndSize(obj, &sz);
+ if(sz==1)
+ return self->findIdFirstEqual(pt[0]);
+ else
+ throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !");
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find an element which is not an integer !");
}
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !");
}
+%#if PY_VERSION_HEX >= 0x03000000
+ if(PyUnicode_Check(obj))
+ {
+ Py_ssize_t sz;
+ char *pt=PyUnicode_AsUTF8AndSize(obj, &sz);
+ if(sz==1)
+ return self->presenceOfValue(pt[0]);
+ else
+ throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !");
+ }
+%#endif
else
throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find an element which is not an integer !");
}
std::vector<int> stdvecTyyppArr;
std::pair<int, std::pair<int,int> > sTyyppArr;
MEDCoupling::DataArrayInt *daIntTyypp=0;
- convertObjToPossibleCpp2WithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
switch(sw)
{
case 1:
MEDCoupling::DataArrayInt *daIntTyypp=0;
int nbOfCompo=self->getNumberOfComponents();
int nbOfTuples=self->getNumberOfTuples();
- convertObjToPossibleCpp2WithNegIntInterp(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
+ convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
int sw2;
char vc; std::string sc; std::vector<std::string> vsc; DataArrayChar *dacc=0;
convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc);
"""Test on DataArrayBytes"""
# use case 1
d=DataArrayByte(256)
- for i in xrange(len(d)):
+ for i in range(len(d)):
d[i]=-128+i
pass
arr=d.toNumPyArray()
- for i in xrange(len(d)):
+ for i in range(len(d)):
self.assertEqual(int(arr[i]),-128+i)
pass
d[0]=7
gc.collect()
# use case 2
d=DataArrayByte(256)
- for i in xrange(len(d)):
+ for i in range(len(d)):
d[i]=-128+i
pass
arr=d.toNumPyArray()
- for i in xrange(len(d)):
+ for i in range(len(d)):
self.assertEqual(int(arr[i]),-128+i)
pass
del d
gc.collect()
# use case 3
d=DataArrayByte(256)
- for i in xrange(len(d)):
+ for i in range(len(d)):
d[i]=-128+i
pass
arr1=d.toNumPyArray()
self.assertEqual(int(arr1[0]),10) ; self.assertEqual(int(arr2[0]),10) ; self.assertEqual(int(arr3[0]),10)
arr2[0]=15 ; self.assertEqual(int(d.getIJ(0,0)),15) ; self.assertEqual(int(arr1[0]),15) ; self.assertEqual(int(arr3[0]),15)
arr1[0]=-128
- for i in xrange(len(d)):
+ for i in range(len(d)):
self.assertEqual(int(arr1[i]),-128+i)
self.assertEqual(int(arr2[i]),-128+i)
self.assertEqual(int(arr3[i]),-128+i)
pass
del arr2
gc.collect()
- for i in xrange(len(d)):
+ for i in range(len(d)):
self.assertEqual(int(arr1[i]),-128+i)
self.assertEqual(int(arr3[i]),-128+i)
pass
del arr1
gc.collect()
- for i in xrange(len(d)):
+ for i in range(len(d)):
self.assertEqual(int(arr3[i]),-128+i)
pass
del arr3
# use case 4
arr=array(0,dtype=int8)
arr.resize(256)
- for i in xrange(256):
+ for i in range(256):
arr[i]=-128+i
pass
d=DataArrayByte(arr)
- for i in xrange(256):
+ for i in range(256):
self.assertEqual(int(d.getIJ(i,0)),-128+i)
pass
del arr
# use case 5
arr=array(0,dtype=int8)
arr.resize(256)
- for i in xrange(256):
+ for i in range(256):
arr[i]=-128+i
pass
d=DataArrayByte(arr)
- for i in xrange(256):
+ for i in range(256):
self.assertEqual(int(d.getIJ(i,0)),-128+i)
pass
del d
gc.collect()
pass
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test29(self):
+ """Same as test9 with float32"""
+ sz=20
+ a=array(0,dtype=float32)
+ a.resize(sz)
+ a[:]=4
+ self.assertEqual(getrefcount(a),2)
+ a=a.cumsum(dtype=float32)
+ self.assertEqual(getrefcount(a),2)
+ d=DataArrayFloat(a)
+ d[:]=2
+ #
+ e=DataArrayFloat(sz) ; e.fillWithValue(2)
+ self.assertTrue(d.isEqual(e,1e-7))
+ #
+ a[:]=4 ; e.fillWithValue(4)
+ self.assertTrue(d.isEqual(e,1e-7))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test30(self):
+ """Same as test10 with float32"""
+ sz=20
+ a=array(0,dtype=float32)
+ a.resize(sz,2)
+ self.assertEqual(getrefcount(a),2)
+ b=a.reshape(2*sz)
+ self.assertEqual(getrefcount(a),3)
+ self.assertEqual(getrefcount(b),2)
+ b[:]=5
+ d=DataArrayFloat(b)
+ #
+ e=DataArrayFloat(sz*2) ; e.fillWithValue(5)
+ self.assertTrue(d.isEqual(e,1e-7))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test31(self):
+ """Same as test11 with float32"""
+ sz=10
+ a=array(0,dtype=float32)
+ a.resize(sz,2)
+ b=a.reshape(2*sz)
+ c=a.reshape(2,sz)
+ b[:]=6
+ b[7:17]=7
+ d=DataArrayFloat(b)
+ self.assertTrue(d.isEqual(DataArrayFloat([6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,6,6,6]),1e-7))
+ #
+ a=zeros((10,2),dtype=float32)
+ b=a.T
+ c=b.view()
+ a.shape=20
+ a[3:]=10.
+ d=DataArrayFloat(a)
+ self.assertTrue(d.isEqual(DataArrayFloat([0,0,0,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]),1e-7))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test32(self):
+ """Same as test12 with float32"""
+ a=zeros(20,dtype=float32)
+ b = a[::-1]
+ self.assertRaises(InterpKernelException,DataArrayFloat.New,b) # b is not contiguous in memory
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test33(self):
+ """Same as test13 with float32"""
+ a=arange(20,dtype=float32)
+ self.assertEqual(weakref.getweakrefcount(a),0)
+ d=DataArrayFloat(a)
+ self.assertEqual(weakref.getweakrefcount(a),1)
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ self.assertEqual(len(d),20)
+ a[:]=2 # modifying a and d because a and d share the same chunk of data
+ self.assertTrue(d.isUniform(2,1e-7))
+ del d # d is destroyed, a retrieves its ownership of its initial chunk of data
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ a[:]=4 # a can be used has usual
+ self.assertTrue(DataArrayFloat(a).isUniform(4,1e-7))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test34(self):
+ """Same as test14 with float32"""
+ a=arange(20,dtype=float32)
+ d=DataArrayFloat(a) # d owns data of a
+ e=DataArrayFloat(a) # a not owned -> e only an access to chunk of a
+ self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ a[:]=6
+ self.assertTrue(d.isUniform(6,1e-7))
+ self.assertTrue(e.isUniform(6,1e-7))
+ del a # a destroyed -> d no change because owned and e array is has no more data set
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(d.isUniform(6,1e-7))
+ self.assertTrue(not e.isAllocated())
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test35(self):
+ """Same as test15 with float32"""
+ a=array(0,dtype=float32) ; a.resize(10,2)
+ b=a.reshape(20)
+ c=a.reshape(2,10)
+ d=DataArrayFloat(b) # d owns data of a
+ e=DataArrayFloat(b) # a not owned -> e only an access to chunk of a
+ f=DataArrayFloat(b) # a not owned -> e only an access to chunk of a
+ del d # d removed -> a ownes again data
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(e.isUniform(0,1e-7))
+ e[:]=6
+ self.assertTrue(e.isUniform(6,1e-7))
+ self.assertTrue(f.isUniform(6,1e-7))
+ self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
+ self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
+ b[:]=arange(20)
+ del b # no impact on e and f because a is the base of a.
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(f.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(f.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+ del c # c killed -> a killed -> e and d are put into not allocated state
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(not e.isAllocated())
+ self.assertTrue(not f.isAllocated())
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test36(self):
+ """Same as test16 with float32"""
+ a=arange(20,dtype=float32)
+ self.assertTrue(a.flags["OWNDATA"])
+ d=DataArrayFloat(a) # d owns data of a
+ self.assertTrue(not a.flags["OWNDATA"])
+ d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),1e-7))
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test37(self):
+ """Same as test20 with float32"""
+ sz=20
+ a=array(0,dtype=float32)
+ a.resize(sz/2,2)
+ a[:]=4
+ self.assertEqual(getrefcount(a),2)
+ d=DataArrayFloat(a)
+ self.assertEqual(10,d.getNumberOfTuples())
+ self.assertEqual(2,d.getNumberOfComponents())
+ self.assertEqual(sz,d.getNbOfElems())
+ self.assertTrue(d.isEqual(DataArrayFloat([(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.)]),1e-7))
+ a[:]=7
+ self.assertTrue(d.isEqual(DataArrayFloat([(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.)]),1e-7))
+ #
+ b=a.reshape((2,5,2))
+ self.assertRaises(InterpKernelException,DataArrayFloat.New,b) # b has not dimension in [0,1] !
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test38(self):
+ """Same as test22 with float32"""
+ d=DataArrayFloat(10)
+ d.iota()
+ a=d.toNumPyArray()
+ self.assertTrue(not a.flags["OWNDATA"])
+ del d
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ #
+ d=DataArrayInt(10)
+ d.iota()
+ a=d.toNumPyArray()
+ self.assertTrue(not a.flags["OWNDATA"])
+ del d
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test39(self):
+ """Same as test23 with float32"""
+ d=DataArrayFloat(10)
+ d.iota()
+ a=d.toNumPyArray()
+ b=d.toNumPyArray()
+ c=d.toNumPyArray()
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(not c.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ del d
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(not c.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ #
+ d=DataArrayInt(10)
+ d.iota()
+ a=d.toNumPyArray()
+ b=d.toNumPyArray()
+ c=d.toNumPyArray()
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(not c.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ del d
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(not c.flags["OWNDATA"])
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test40(self):
+ """Same as test24 with float32"""
+ d=DataArrayFloat(10)
+ d.iota()
+ a=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(a.base is None)
+ del a
+ gc.collect()
+ a=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(a.base is None)
+ b=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(b.base is a)
+ del a
+ gc.collect()
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not b.flags["OWNDATA"])
+ del d
+ gc.collect()
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not b.flags["OWNDATA"])
+ #
+ d=DataArrayInt(10)
+ d.iota()
+ a=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(a.base is None)
+ del a
+ gc.collect()
+ a=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(a.base is None)
+ b=d.toNumPyArray()
+ self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(not b.flags["OWNDATA"])
+ self.assertTrue(b.base is a)
+ del a
+ gc.collect()
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not b.flags["OWNDATA"])
+ del d
+ gc.collect()
+ self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+ self.assertTrue(not b.flags["OWNDATA"])
+ pass
+
def setUp(self):
pass
pass
from platform import architecture
from sys import getrefcount
-import os,gc,weakref,cPickle,unittest
+import os, gc, weakref, unittest
+import sys
+if sys.version_info.major < 3:
+ import cPickle as pickle
+else:
+ import pickle
class MEDCouplingPickleTest(unittest.TestCase):
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
""" Test of a simple DataArrayDouble."""
x=DataArrayDouble(10,1) ; x.iota() ; x.rearrange(2) ; x.setInfoOnComponents(["aa","bbb"])
x.setName("toto")
- pickled=cPickle.dumps(x,cPickle.HIGHEST_PROTOCOL)
- xx=cPickle.loads(pickled)
+ pickled=pickle.dumps(x,pickle.HIGHEST_PROTOCOL)
+ xx=pickle.loads(pickled)
self.assertTrue(xx.isEqual(x,1e-16))
# Bigger to check that the behavior is OK for large strings.
x=DataArrayDouble(1200) ; x.iota() ; x.setInfoOnComponents(["aa"])
x.setName("titi")
- pickled=cPickle.dumps(x,cPickle.HIGHEST_PROTOCOL)
- xx=cPickle.loads(pickled)
+ pickled=pickle.dumps(x,pickle.HIGHEST_PROTOCOL)
+ xx=pickle.loads(pickled)
self.assertTrue(xx.isEqual(x,1e-16))
pass
""" Test of a simple DataArrayInt."""
x=DataArrayInt(10) ; x.iota() ; x.rearrange(2) ; x.setInfoOnComponents(["aa","bbb"])
x.setName("toto")
- pickled=cPickle.dumps(x,cPickle.HIGHEST_PROTOCOL)
- xx=cPickle.loads(pickled)
+ pickled=pickle.dumps(x,pickle.HIGHEST_PROTOCOL)
+ xx=pickle.loads(pickled)
self.assertTrue(xx.isEqual(x))
# Bigger to check that the behavior is OK for large strings.
x=DataArrayInt(1200) ; x.iota() ; x.setInfoOnComponents(["aa"])
x.setName("titi")
- pickled=cPickle.dumps(x,cPickle.HIGHEST_PROTOCOL)
- xx=cPickle.loads(pickled)
+ pickled=pickle.dumps(x,pickle.HIGHEST_PROTOCOL)
+ xx=pickle.loads(pickled)
self.assertTrue(xx.isEqual(x))
pass
m.setName("mesh")
m.getCoords().setInfoOnComponents(["aa","bbb","ddddd"])
m.checkConsistencyLight()
- st=cPickle.dumps(m,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(m,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(m,1e-16))
pass
m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY,arrZ)
m.setName("mesh")
m.checkConsistencyLight()
- st=cPickle.dumps(m,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(m,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(m,1e-16))
self.assertTrue(m2.getCoordsAt(0).isEqual(arrX,1e-16))
pass
m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
m=m.build1SGTUnstructured()
self.assertTrue(isinstance(m,MEDCoupling1SGTUMesh))
- st=cPickle.dumps(m,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(m,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(m,1e-16))
pass
m=m.buildUnstructured() ; m.convertAllToPoly()
m=MEDCoupling1DGTUMesh(m)
self.assertTrue(isinstance(m,MEDCoupling1DGTUMesh))
- st=cPickle.dumps(m,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(m,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(m,1e-16))
pass
mesh2D.setCoords(mesh3D.getCoords())
mesh=MEDCouplingMappedExtrudedMesh(mesh3D,mesh2D,0) ; del mesh3D,mesh2D
self.assertTrue(isinstance(mesh,MEDCouplingMappedExtrudedMesh))
- st=cPickle.dumps(mesh,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(mesh,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(mesh,1e-16))
pass
#
mesh=MEDCouplingCurveLinearMesh() ; mesh.setCoords(m.getCoords()) ; del m
mesh.setNodeGridStructure([10,5])
- st=cPickle.dumps(mesh,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(mesh,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(mesh,1e-16))
pass
""" Test of a MEDCouplingIMesh pickeling."""
m=MEDCouplingIMesh("mesh",3,DataArrayInt([3,1,4]),DataArrayDouble([1.5,2.5,3.5]),DataArrayDouble((0.5,1.,0.25))) ; m.setAxisUnit("km")
m.checkConsistencyLight()
- st=cPickle.dumps(m,cPickle.HIGHEST_PROTOCOL)
- m2=cPickle.loads(st)
+ st=pickle.dumps(m,pickle.HIGHEST_PROTOCOL)
+ m2=pickle.loads(st)
self.assertTrue(m2.isEqual(m,1e-16))
self.assertEqual(m2.getName(),m.getName())
pass
f.getArray().setInfoOnComponents(["u1","vv2"])
f.checkConsistencyLight();
#
- st=cPickle.dumps(f,cPickle.HIGHEST_PROTOCOL)
- f2=cPickle.loads(st)
+ st=pickle.dumps(f,pickle.HIGHEST_PROTOCOL)
+ f2=pickle.loads(st)
self.assertTrue(f2.isEqual(f,1e-16,1e-16))
self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16))
pass
self.assertEqual(2,f.getNbOfGaussLocalization());
array=DataArrayDouble.New();
ptr=18*2*[None]
- for i in xrange(18*2):
+ for i in range(18 * 2):
ptr[i]=float(i+1)
array.setValues(ptr,18,2);
ptr=array.getPointer();
f.setArray(array2);
f.checkConsistencyLight();
####
- st=cPickle.dumps(f,cPickle.HIGHEST_PROTOCOL)
- f2=cPickle.loads(st)
+ st=pickle.dumps(f,pickle.HIGHEST_PROTOCOL)
+ f2=pickle.loads(st)
self.assertTrue(f2.isEqual(f,1e-16,1e-16))
self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16))
pass
eStr="This is an exception."
e=InterpKernelException(eStr)
self.assertEqual(e.what(),eStr)
- st=cPickle.dumps(e,cPickle.HIGHEST_PROTOCOL)
- e2=cPickle.loads(st)
+ st=pickle.dumps(e,pickle.HIGHEST_PROTOCOL)
+ e2=pickle.loads(st)
self.assertTrue(e is not e2)
self.assertTrue(isinstance(e2,InterpKernelException))
self.assertEqual(e2.what(),eStr)
def test14(self):
"""Pickelization of DataArrayBytes"""
x=DataArrayByte(256,1)
- for i in xrange(256):
+ for i in range(256):
x[i]=-128+i
pass
x.rearrange(2) ; x.setInfoOnComponents(["aa","bbb"])
x.setName("toto")
- st=cPickle.dumps(x,cPickle.HIGHEST_PROTOCOL)
- x2=cPickle.loads(st)
+ st=pickle.dumps(x,pickle.HIGHEST_PROTOCOL)
+ x2=pickle.loads(st)
self.assertTrue(x2.isEqual(x))
pass
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test15(self):
+ """Pickelization of DataArrayFloat"""
+ x=DataArrayFloat(256) ; x.iota()
+ x.rearrange(2) ; x.setInfoOnComponents(["aa","bbb"])
+ x.setName("toto")
+ st = pickle.dumps(x, pickle.HIGHEST_PROTOCOL)
+ x2 = pickle.loads(st)
+ self.assertTrue(x2.isEqual(x,1e-7))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test16(self):
+ """ Test of MEDCouplingFieldInt lying on MEDCouplingCMesh pickeling. """
+ arrX=DataArrayDouble(10) ; arrX.iota() ; arrX.setInfoOnComponents(["aa"])
+ arrY=DataArrayDouble(5) ; arrY.iota() ; arrY.setInfoOnComponents(["bbb"])
+ m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY)
+ f=m.getMeasureField(True)
+ f=f.convertToIntField()
+ self.assertTrue(isinstance(f,MEDCouplingFieldInt))
+ f.setName("aname")
+ a=f.getArray()
+ b=a[:] ; b.iota(7000)
+ f.setArray(DataArrayInt.Meld(a,b))
+ f.getArray().setInfoOnComponents(["u1","vv2"])
+ f.checkConsistencyLight();
+ #
+ st = pickle.dumps(f, pickle.HIGHEST_PROTOCOL)
+ f2 = pickle.loads(st)
+ self.assertTrue(f2.isEqual(f,1e-16,0))
+ self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test17(self):
+ """ Test of MEDCouplingFieldInt lying on MEDCouplingCMesh pickeling. """
+ arrX=DataArrayDouble(10) ; arrX.iota() ; arrX.setInfoOnComponents(["aa"])
+ arrY=DataArrayDouble(5) ; arrY.iota() ; arrY.setInfoOnComponents(["bbb"])
+ m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY)
+ f2=m.getMeasureField(True)
+ f=MEDCouplingFieldFloat(ON_CELLS)
+ f.setMesh(m) ; f.setArray(f2.getArray().convertToFloatArr())
+ self.assertTrue(isinstance(f,MEDCouplingFieldFloat))
+ f.setName("aname")
+ a=f.getArray()
+ b=a[:] ; b.iota(7000.)
+ f.setArray(DataArrayFloat.Meld(a,b))
+ f.getArray().setInfoOnComponents(["u1","vv2"])
+ f.checkConsistencyLight();
+ #
+ st = pickle.dumps(f, pickle.HIGHEST_PROTOCOL)
+ f2 = pickle.loads(st)
+ self.assertTrue(f2.isEqual(f,1e-16,0))
+ self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16))
+ pass
+
def setUp(self):
pass
pass
def MEDCouplingFieldDoubleIpow(self,*args):
import _MEDCouplingRemapper
return _MEDCouplingRemapper.MEDCouplingFieldDouble____ipow___(self, self, *args)
+def MEDCouplingFieldIntnew(cls,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.MEDCouplingFieldInt____new___(cls,args)
+def MEDCouplingFieldFloatnew(cls,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.MEDCouplingFieldFloat____new___(cls,args)
def MEDCouplingDataArrayBytenew(cls,*args):
import _MEDCouplingRemapper
return _MEDCouplingRemapper.DataArrayByte____new___(cls,args)
+def MEDCouplingDataArrayFloatnew(cls,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.DataArrayFloat____new___(cls,args)
+def MEDCouplingDataArrayFloatIadd(self,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.DataArrayFloat____iadd___(self, self, *args)
+def MEDCouplingDataArrayFloatIsub(self,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.DataArrayFloat____isub___(self, self, *args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.DataArrayFloat____imul___(self, self, *args)
+def MEDCouplingDataArrayFloatIdiv(self,*args):
+ import _MEDCouplingRemapper
+ return _MEDCouplingRemapper.DataArrayFloat____idiv___(self, self, *args)
def MEDCouplingDataArrayIntnew(cls,*args):
import _MEDCouplingRemapper
return _MEDCouplingRemapper.DataArrayInt____new___(cls,args)
remapper=MEDCouplingRemapper()
remapper.setPrecision(1e-12);
remapper.setIntersectionType(Triangulation);
- self.failUnless(remapper.prepare(sourceMesh,targetMesh,"P0P0")==1);
+ self.assertTrue(remapper.prepare(sourceMesh,targetMesh,"P0P0")==1);
srcField=MEDCouplingFieldDouble.New(ON_CELLS);
srcField.setNature(IntensiveMaximum);
srcField.setMesh(sourceMesh);
array=DataArrayDouble.New();
ptr=sourceMesh.getNumberOfCells()*[None]
- for i in xrange(sourceMesh.getNumberOfCells()):
+ for i in range(sourceMesh.getNumberOfCells()):
ptr[i]=float(i+7)
pass
array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
self.assertEqual(c,10)
values=trgfield.getArray().getValues();
valuesExpected=[7.5 ,7. ,7.,8.,7.5];
- for i in xrange(targetMesh.getNumberOfCells()):
- self.failUnless(abs(values[i]-valuesExpected[i])<1e-12);
+ for i in range(targetMesh.getNumberOfCells()):
+ self.assertTrue(abs(values[i]-valuesExpected[i])<1e-12);
pass
- self.failUnless(1==trgfield.getArray().getNumberOfComponents());
+ self.assertTrue(1==trgfield.getArray().getNumberOfComponents());
pass
def testPrepareEx1(self):
srcField.setMesh(sourceMesh);
array=DataArrayDouble.New();
ptr=sourceMesh.getNumberOfCells()*[None]
- for i in xrange(sourceMesh.getNumberOfCells()):
+ for i in range(sourceMesh.getNumberOfCells()):
ptr[i]=float(i+7);
pass
array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
valuesExpected=[7.75, 7.0625, 4.220173,8.0]
self.assertEqual(4,trgfield.getArray().getNumberOfTuples());
self.assertEqual(1,trgfield.getArray().getNumberOfComponents());
- for i0 in xrange(4):
+ for i0 in range(4):
self.assertAlmostEqual(valuesExpected[i0],values[i0],12);
pass
pass
srcField.setMesh(sourceMesh);
array=DataArrayDouble.New();
ptr=sourceMesh.getNumberOfCells()*[None]
- for i in xrange(sourceMesh.getNumberOfCells()):
+ for i in range(sourceMesh.getNumberOfCells()):
ptr[i]=float(i+7);
pass
array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
trgfield.setMesh(targetMesh);
array=DataArrayDouble.New();
ptr=targetMesh.getNumberOfCells()*[None]
- for i in xrange(targetMesh.getNumberOfCells()):
+ for i in range(targetMesh.getNumberOfCells()):
ptr[i]=4.220173;
pass
array.setValues(ptr,targetMesh.getNumberOfCells(),1);
valuesExpected=[7.75, 7.0625, 4.220173,8.0]
self.assertEqual(4,trgfield.getArray().getNumberOfTuples());
self.assertEqual(1,trgfield.getArray().getNumberOfComponents());
- for i0 in xrange(4):
+ for i0 in range(4):
self.assertAlmostEqual(valuesExpected[i0],values[i0],12);
pass
pass
rem2=MEDCouplingRemapper() ; rem2.setSplittingPolicy(PLANAR_FACE_5) ; rem2.prepare(src1,trg,"P0P0")
mat1=rem1.getCrudeMatrix() ; mat2=rem2.getCrudeMatrix()
self.assertEqual(1,len(mat1)) ; self.assertEqual(1,len(mat2))
- self.assertEqual(mat1[0].keys(),mat2[0].keys()) ; self.assertEqual([0,1],mat1[0].keys())
+ self.assertEqual(list(mat1[0].keys()),list(mat2[0].keys())) ; self.assertEqual([0,1],list(mat1[0].keys()))
self.assertAlmostEqual(1.25884108122e-06,mat1[0][0],16) ; self.assertAlmostEqual(1.25884108122e-06,mat2[0][0],16)
self.assertAlmostEqual(1.25884086663e-06,mat1[0][1],16) ; self.assertAlmostEqual(1.25884086663e-06,mat2[0][1],16)
#
self.assertEqual(aRemapper.prepare(s,t,'P1P1'),1)
m=aRemapper.getCrudeMatrix()
self.assertEqual(len(m),28)
- for i in xrange(28):
+ for i in range(28):
if i not in [5,6]:
self.assertEqual(len(m[i]),0)
pass
rem=MEDCouplingRemapper()
rem.prepare(src,trg,"P0P0")
# Internal crude sparse matrix computed. Let's manipulate it using CSR matrix in scipy.
- for i in xrange(10):
+ for i in range(10):
m=rem.getCrudeCSRMatrix()
pass
m2=rem.getCrudeCSRMatrix()
a.allocateCells()
conna=[0,1,3,2,1,4,5,3,4,6,7,5,6,8,9,7,8,10,11,9,10,12,13,11,12,14,15,13,14,16,17,15,16,18,19,17,18,20,21,19,20,22,23,21,22,24,25,23,24,26,27,25]
a.setCoords(DataArrayDouble([1.54,0,-0.01,1.54,0.02,-0.01,1.54,0,0.01,1.54,0.02,0.01,1.54,0.04,-0.01,1.54,0.04,0.01,1.54,0.06,-0.01,1.54,0.06,0.01,1.54,0.08,-0.01,1.54,0.08,0.01,1.54,0.1,-0.01,1.54,0.1,0.01,1.54,0.12,-0.01,1.54,0.12,0.01,1.54,0.14,-0.01,1.54,0.14,0.01,1.54,0.16,-0.01,1.54,0.16,0.01,1.54,0.18,-0.01,1.54,0.18,0.01,1.54,0.2,-0.01,1.54,0.2,0.01,1.54,0.22,-0.01,1.54,0.22,0.01,1.54,0.24,-0.01,1.54,0.24,0.01,1.54,0.26,-0.01,1.54,0.26,0.01],28,3))
- for i in xrange(13):
+ for i in range(13):
a.insertNextCell(NORM_QUAD4,conna[4*i:4*(i+1)])
pass
a.finishInsertingCells() ; a.simplexize(0)
connb=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,0,2,39,3,5,40,6,8,41,9,11,42,12,14,43,15,17,44,18,20,45,21,23,46,24,26,47,27,29,48,30,32,49,33,35,50,36,38,51,52,2,39,53,5,40,54,8,41,55,11,42,56,14,43,57,17,44,58,20,45,59,23,46,60,26,47,61,29,48,62,32,49,63,35,50,64,38,51,52,2,65,53,5,66,54,8,67,55,11,68,56,14,69,57,17,70,58,20,71,59,23,72,60,26,73,61,29,74,62,32,75,63,35,76,64,38,77,53,2,65,54,5,66,55,8,67,56,11,68,57,14,69,58,17,70,59,20,71,60,23,72,61,26,73,62,29,74,63,32,75,64,35,76,78,38,77,53,2,40,54,5,41,55,8,42,56,11,43,57,14,44,58,17,45,59,20,46,60,23,47,61,26,48,62,29,49,63,32,50,64,35,51,78,38,79,3,2,40,6,5,41,9,8,42,12,11,43,15,14,44,18,17,45,21,20,46,24,23,47,27,26,48,30,29,49,33,32,50,36,35,51,80,38,79,3,2,1,6,5,4,9,8,7,12,11,10,15,14,13,18,17,16,21,20,19,24,23,22,27,26,25,30,29,28,33,32,31,36,35,34,80,38,37]
b=MEDCouplingUMesh("b",2)
b.allocateCells()
- for i in xrange(104):
+ for i in range(104):
b.insertNextCell(NORM_TRI3,connb[3*i:3*(i+1)])
pass
b.setCoords(DataArrayDouble([1.54,0,-0.01,1.54,0.01,-0.01,1.54,0.01,0,1.54,0.02,-0.01,1.54,0.03,-0.01,1.54,0.03,0,1.54,0.04,-0.01,1.54,0.05,-0.01,1.54,0.05,0,1.54,0.06,-0.01,1.54,0.07,-0.01,1.54,0.07,0,1.54,0.08,-0.01,1.54,0.09,-0.01,1.54,0.09,0,1.54,0.1,-0.01,1.54,0.11,-0.01,1.54,0.11,0,1.54,0.12,-0.01,1.54,0.13,-0.01,1.54,0.13,0,1.54,0.14,-0.01,1.54,0.15,-0.01,1.54,0.15,0,1.54,0.16,-0.01,1.54,0.17,-0.01,1.54,0.17,0,1.54,0.18,-0.01,1.54,0.19,-0.01,1.54,0.19,0,1.54,0.2,-0.01,1.54,0.21,-0.01,1.54,0.21,0,1.54,0.22,-0.01,1.54,0.23,-0.01,1.54,0.23,0,1.54,0.24,-0.01,1.54,0.25,-0.01,1.54,0.25,0,1.54,0,0,1.54,0.02,0,1.54,0.04,0,1.54,0.06,0,1.54,0.08,0,1.54,0.1,0,1.54,0.12,0,1.54,0.14,0,1.54,0.16,0,1.54,0.18,0,1.54,0.2,0,1.54,0.22,0,1.54,0.24,0,1.54,0,0.01,1.54,0.02,0.01,1.54,0.04,0.01,1.54,0.06,0.01,1.54,0.08,0.01,1.54,0.1,0.01,1.54,0.12,0.01,1.54,0.14,0.01,1.54,0.16,0.01,1.54,0.18,0.01,1.54,0.2,0.01,1.54,0.22,0.01,1.54,0.24,0.01,1.54,0.01,0.01,1.54,0.03,0.01,1.54,0.05,0.01,1.54,0.07,0.01,1.54,0.09,0.01,1.54,0.11,0.01,1.54,0.13,0.01,1.54,0.15,0.01,1.54,0.17,0.01,1.54,0.19,0.01,1.54,0.21,0.01,1.54,0.23,0.01,1.54,0.25,0.01,1.54,0.26,0.01,1.54,0.26,0,1.54,0.26,-0.01],81,3))
source=MEDCoupling1SGTUMesh("SourcePrimaire",NORM_SEG2)
source.setCoords(sourceCoo)
source.allocateCells()
- for i in xrange(len(sourceCoo)-1):
+ for i in range(len(sourceCoo) - 1):
source.insertNextCell([i,i+1])
pass
source=source.buildUnstructured()
cI2 = [0, 44]
mTgt = MEDCouplingUMesh("target", 3)
mSrc = MEDCouplingUMesh("src", 3)
- mTgt.setCoords(DataArrayDouble(coo1, len(coo1)/3, 3))
- mSrc.setCoords(DataArrayDouble(coo2, len(coo2)/3, 3))
+ mTgt.setCoords(DataArrayDouble(coo1, len(coo1) // 3, 3))
+ mSrc.setCoords(DataArrayDouble(coo2, len(coo2) // 3, 3))
mTgt.setConnectivity(DataArrayInt(conn1), DataArrayInt(cI1))
mSrc.setConnectivity(DataArrayInt(conn2), DataArrayInt(cI2))
def checkMatrix(self,mat1,mat2,nbCols,eps):
self.assertEqual(len(mat1),len(mat2))
- for i in xrange(len(mat1)):
+ for i in range(len(mat1)):
self.assertTrue(max(mat2[i].keys())<nbCols)
self.assertTrue(max(mat1[i].keys())<nbCols)
self.assertTrue(min(mat2[i].keys())>=0)
targetMesh=MEDCouplingUMesh.New();
targetMesh.setMeshDimension(2);
targetMesh.allocateCells(4);
- for i in xrange(4):
+ for i in range(4):
targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[4*i:4*(i+1)])
pass
targetMesh.finishInsertingCells();
#include "MEDCouplingPartDefinition.hxx"
#include "MEDCouplingCartesianAMRMesh.hxx"
-static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
{
PyObject *ret=0;
if(!mesh)
return ret;
}
-static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner)
{
PyObject *ret=0;
if(!fd)
return ret;
}
-static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner)
{
PyObject *ret=0;
if(!mfs)
return ret;
}
-static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner)
{
if(!mesh)
{
throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !");
}
-static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner) throw(INTERP_KERNEL::Exception)
+static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner)
{
if(!data)
{
MEDCoupling::DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
MEDCoupling::DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
MEDCoupling::DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
MEDCoupling::DataArrayDoubleTuple *aa;
std::vector<double> bb;
int sw;
- convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
switch(sw)
{
case 1:
}
}
+template<class T>
+typename MEDCoupling::Traits<T>::FieldType *fieldT_buildSubPart(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
+{
+ int sw;
+ int singleVal;
+ std::vector<int> multiVal;
+ std::pair<int, std::pair<int,int> > slic;
+ MEDCoupling::DataArrayInt *daIntTyypp=0;
+ const MEDCoupling::MEDCouplingMesh *mesh=self->getMesh();
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !");
+ int nbc=mesh->getNumberOfCells();
+ convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+ switch(sw)
+ {
+ case 1:
+ {
+ if(singleVal>=nbc)
+ {
+ std::ostringstream oss;
+ oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(singleVal>=0)
+ return self->buildSubPart(&singleVal,&singleVal+1);
+ else
+ {
+ if(nbc+singleVal>0)
+ {
+ int tmp=nbc+singleVal;
+ return self->buildSubPart(&tmp,&tmp+1);
+ }
+ else
+ {
+ std::ostringstream oss;
+ oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ case 2:
+ {
+ return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size());
+ }
+ case 3:
+ {
+ return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
+ }
+ case 4:
+ {
+ if(!daIntTyypp)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !");
+ daIntTyypp->checkAllocated();
+ return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end());
+ }
+ default:
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !");
+ }
+}
+
+template<class T>
+typename MEDCoupling::Traits<T>::FieldType *fieldT__getitem__(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
+{
+ const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n";
+ if(PyTuple_Check(li))
+ {
+ Py_ssize_t sz=PyTuple_Size(li);
+ if(sz!=2)
+ throw INTERP_KERNEL::Exception(msg);
+ PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
+ int sw;
+ int singleVal;
+ std::vector<int> multiVal;
+ std::pair<int, std::pair<int,int> > slic;
+ MEDCoupling::DataArrayInt *daIntTyypp=0;
+ if(!self->getArray())
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
+ try
+ { convertIntStarOrSliceLikePyObjToCpp(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); }
+ catch(INTERP_KERNEL::Exception& e)
+ { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
+ typename MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::FieldType > ret0(fieldT_buildSubPart<T>(self,elt0));
+ typename MEDCoupling::Traits<T>::ArrayType *ret0Arr=ret0->getArray();
+ if(!ret0Arr)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
+ switch(sw)
+ {
+ case 1:
+ {
+ std::vector<int> v2(1,singleVal);
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
+ ret0->setArray(aarr);
+ return ret0.retn();
+ }
+ case 2:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(multiVal));
+ ret0->setArray(aarr);
+ return ret0.retn();
+ }
+ case 3:
+ {
+ int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !"));
+ std::vector<int> v2(nbOfComp);
+ for(int i=0;i<nbOfComp;i++)
+ v2[i]=slic.first+i*slic.second.second;
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
+ ret0->setArray(aarr);
+ return ret0.retn();
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ }
+ else
+ return fieldT_buildSubPart<T>(self,li);
+}
+
+template<class FIELDT>
+PyObject *field_getTinySerializationInformation(const FIELDT *self)
+{
+ std::vector<double> a0;
+ std::vector<int> a1;
+ std::vector<std::string> a2;
+ self->getTinySerializationDbleInformation(a0);
+ self->getTinySerializationIntInformation(a1);
+ self->getTinySerializationStrInformation(a2);
+ //
+ PyObject *ret(PyTuple_New(3));
+ PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
+ PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
+ int sz(a2.size());
+ PyObject *ret2(PyList_New(sz));
+ {
+ for(int i=0;i<sz;i++)
+ PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
+ }
+ PyTuple_SetItem(ret,2,ret2);
+ return ret;
+}
+
+template<class T>
+PyObject *field_serialize(const typename MEDCoupling::Traits<T>::FieldType *self)
+{
+ MEDCoupling::DataArrayInt *ret0(0);
+ std::vector<typename MEDCoupling::Traits<T>::ArrayType *> ret1;
+ self->serialize(ret0,ret1);
+ if(ret0)
+ ret0->incrRef();
+ std::size_t sz(ret1.size());
+ PyObject *ret(PyTuple_New(2));
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyObject *ret1Py(PyList_New(sz));
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(ret1[i])
+ ret1[i]->incrRef();
+ PyList_SetItem(ret1Py,i,convertArray(ret1[i],SWIG_POINTER_OWN | 0));
+ }
+ PyTuple_SetItem(ret,1,ret1Py);
+ return ret;
+}
+
+template<class FIELDT>
+PyObject *field__getnewargs__(FIELDT *self)
+{
+ self->checkConsistencyLight();
+ PyObject *ret(PyTuple_New(1));
+ PyObject *ret0(PyDict_New());
+ {
+ PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization()));
+ PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c);
+ PyDict_SetItem(ret0,a,d);
+ Py_DECREF(a); Py_DECREF(d);
+ }
+ PyTuple_SetItem(ret,0,ret0);
+ return ret;
+}
+
+template<class FIELDT>
+PyObject *field__getstate__(const FIELDT *self, PyObject *(*tinyserial)(const FIELDT *), PyObject *(*bigserial)(const FIELDT *))
+{
+ self->checkConsistencyLight();
+ PyObject *ret0(tinyserial(self));
+ PyObject *ret1(bigserial(self));
+ const MEDCoupling::MEDCouplingMesh *mesh(self->getMesh());
+ if(mesh)
+ mesh->incrRef();
+ PyObject *ret(PyTuple_New(3));
+ PyTuple_SetItem(ret,0,ret0);
+ PyTuple_SetItem(ret,1,ret1);
+ PyTuple_SetItem(ret,2,convertMesh(const_cast<MEDCoupling::MEDCouplingMesh *>(mesh),SWIG_POINTER_OWN | 0 ));
+ return ret;
+}
+
+template<class T>
+void field__setstate__(typename MEDCoupling::Traits<T>::FieldType *self, PyObject *inp)
+{
+ static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !";
+ if(!PyTuple_Check(inp))
+ throw INTERP_KERNEL::Exception(MSG);
+ int sz(PyTuple_Size(inp));
+ if(sz!=3)
+ throw INTERP_KERNEL::Exception(MSG);
+ // mesh
+ PyObject *elt2(PyTuple_GetItem(inp,2));
+ void *argp=0;
+ int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0));
+ if(!SWIG_IsOK(status))
+ throw INTERP_KERNEL::Exception(MSG);
+ self->setMesh(reinterpret_cast< const MEDCoupling::MEDCouplingMesh * >(argp));
+ //
+ PyObject *elt0(PyTuple_GetItem(inp,0));
+ PyObject *elt1(PyTuple_GetItem(inp,1));
+ std::vector<double> a0;
+ std::vector<int> a1;
+ std::vector<std::string> a2;
+ MEDCoupling::DataArrayInt *b0(0);
+ std::vector<typename MEDCoupling::Traits<T>::ArrayType *>b1;
+ {
+ if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
+ throw INTERP_KERNEL::Exception(MSG);
+ PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
+ int tmp(-1);
+ fillArrayWithPyListDbl3(a0py,tmp,a0);
+ convertPyToNewIntArr3(a1py,a1);
+ fillStringVector(a2py,a2);
+ }
+ {
+ if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
+ throw INTERP_KERNEL::Exception(MSG);
+ PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
+ void *argp(0);
+ int status(SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0));
+ if(!SWIG_IsOK(status))
+ throw INTERP_KERNEL::Exception(MSG);
+ b0=reinterpret_cast<MEDCoupling::DataArrayInt *>(argp);
+ convertFromPyObjVectorOfObj<typename MEDCoupling::Traits<T>::ArrayType *>(b1py,SWIGTITraits<T>::TI,MEDCoupling::Traits<T>::ArrayTypeName,b1);
+ }
+ self->checkForUnserialization(a1,b0,b1);
+ // useless here to call resizeForUnserialization because arrays are well resized.
+ self->finishUnserialization(a1,a0,a2);
+}
+
#endif
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include "MEDFileField.txx"
#include "MEDFileMesh.hxx"
#include "MEDFileBlowStrEltUp.hxx"
#include "MEDFileFieldVisitor.hxx"
-#include "MEDCouplingFieldDouble.hxx"
-#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
#include "InterpKernelAutoPtr.hxx"
using namespace MEDCoupling;
template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<int>;
+template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<float>;
template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<double>;
+template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<int>;
+template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<float>;
+template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<int>;
+template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<float>;
+template class MEDCoupling::MEDFileTemplateField1TS<int>;
+template class MEDCoupling::MEDFileTemplateField1TS<float>;
+template class MEDCoupling::MEDFileTemplateField1TS<double>;
+template class MEDCoupling::MEDFileNDTemplateField1TS<int>;
+template class MEDCoupling::MEDFileNDTemplateField1TS<float>;
+template class MEDCoupling::MEDFileTemplateFieldMultiTS<int>;
+template class MEDCoupling::MEDFileTemplateFieldMultiTS<float>;
+template class MEDCoupling::MEDFileTemplateFieldMultiTS<double>;
+template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<int>;
+template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<float>;
const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
+const char MEDFileFloatField1TSWithoutSDA::TYPE_STR[]="FLOAT32";
MEDFileGTKeeper::~MEDFileGTKeeper()
{
return oss.str();
}
-void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
_type=field->getTypeOfField();
_start=start;
* \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
* \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
*/
-void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
_profile.clear();
_type=field->getTypeOfField();
start=_end;
}
-void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
+void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
{
_start=start;
_nval=arrr->getNumberOfTuples();
return ret;
}
-void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
* \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
* \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
*/
-void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
_field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
}
-void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
+void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
{
_field_pm_pt_pd.resize(1);
_field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
_field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
}
-void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
if(!arr || !arr->isAllocated())
_field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
}
-std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
+std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
{
TypeOfField type=field->getTypeOfField();
if(type!=ON_GAUSS_PT)
}
}
-std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
+std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
{
const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
return ret;
}
-std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
+std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
{
TypeOfField type=field->getTypeOfField();
if(type!=ON_GAUSS_PT)
}
}
-std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
+std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
{
const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
mesh->getTime(_mesh_iteration,_mesh_order);
}
-void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
int nbOfTypes=code.size()/3;
int offset=0;
* \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points.
* \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
*/
-void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
int nbOfTypes(code.size()/3);
for(int i=0;i<nbOfTypes;i++)
}
}
-void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
+void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
{
int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
_field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
}
-void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
_field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
* \throw If the underlying mesh of \a field has no name.
* \throw If elements in the mesh are not in the order suitable for writing to the MED file.
*/
-void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
- const MEDCouplingMesh *mesh=field->getMesh();
+ const MEDCouplingMesh *mesh(field->getMesh());
//
- TypeOfField type=field->getTypeOfField();
+ TypeOfField type(field->getTypeOfField());
std::vector<DataArrayInt *> dummy;
if(mesh)
setMeshName(mesh->getName());
- int start=copyTinyInfoFrom(field,arr);
- int pos=addNewEntryIfNecessary(mesh);
+ int start(copyTinyInfoFrom(th,field,arr));
+ int pos(addNewEntryIfNecessary(mesh));
if(type!=ON_NODES)
{
std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
* \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
* \sa setFieldNoProfileSBT()
*/
-void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
+void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
{
if(!field)
throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin());
std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
// start of check
- MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
+ MCAuto<MEDCouplingFieldTemplate> field2=field->clone(false);
int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
{
throw INTERP_KERNEL::Exception(oss.str());
}
// end of check
- int start=copyTinyInfoFrom(field,arrOfVals);
+ int start(copyTinyInfoFrom(th,field,arrOfVals));
code2=m->getDistributionOfTypes();
//
int pos=addNewEntryIfNecessary(m);
std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
throw INTERP_KERNEL::Exception(oss.str());
}
- int start=copyTinyInfoFrom(field,arrOfVals);
- int pos=addNewEntryIfNecessary(m);
+ int start(copyTinyInfoFrom(th,field,arrOfVals));
+ int pos(addNewEntryIfNecessary(m));
_field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
}
}
* \throw If \a this->_arr is already allocated but has different number of components
* than \a field.
*/
-int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
+int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
{
if(!field)
throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
setName(name.c_str());
if(field->getMesh())
setMeshName(field->getMesh()->getName());
- setDtUnit(field->getTimeUnit());
+ setDtUnit(th->getTimeUnit());
if(name.empty())
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
if(!arr)
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
if(!arr->isAllocated())
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
- _dt=field->getTime(_iteration,_order);
+ _dt=th->getTime(_iteration,_order);
getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
if(!getOrCreateAndGetArray()->isAllocated())
{
return ret.retn();
}
-/*!
- * Returns a pointer to the underground DataArrayDouble instance and a
- * sequence describing parameters of a support of each part of \a this field. The
- * caller should not decrRef() the returned DataArrayDouble. This method allows for a
- * direct access to the field values. This method is intended for the field lying on one
- * mesh only.
- * \param [in,out] entries - the sequence describing parameters of a support of each
- * part of \a this field. Each item of this sequence consists of two parts. The
- * first part describes a type of mesh entity and an id of discretization of a
- * current field part. The second part describes a range of values [begin,end)
- * within the returned array relating to the current field part.
- * \return DataArrayDouble * - the pointer to the field values array.
- * \throw If the number of underlying meshes is not equal to 1.
- * \throw If no field values are available.
- * \sa getUndergroundDataArray()
- */
-DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
-{
- if(_field_per_mesh.size()!=1)
- throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
- if(_field_per_mesh[0]==0)
- throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
- _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
- return getUndergroundDataArrayTemplate();
-}
-
/*!
* Returns a pointer to the underground DataArrayDouble instance and a
* sequence describing parameters of a support of each part of \a this field. The
*/
DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
{
- return getUndergroundDataArrayDoubleExt(entries);
+ return getUndergroundDataArrayTemplateExt(entries);
}
MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,meshName,csit,iteration,order)
return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
}
-MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
+MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA()
{
}
MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
- const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order)
+ const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order,infos)
{
DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
arr->setInfoAndChangeNbOfCompo(infos);
return TYPE_STR;
}
-MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
-{
- MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
- ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
- ret->deepCpyLeavesFrom(*this);
- const DataArrayInt *arr(_arr);
- if(arr)
- {
- MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
- ret->setArray(arr2);
- }
- return ret.retn();
-}
-
/*!
* Returns a pointer to the underground DataArrayInt instance and a
* sequence describing parameters of a support of each part of \a this field. The
return ret.retn();
}
-MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
+//= MEDFileFloatField1TSWithoutSDA
+
+MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
+{
+ return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
+}
+
+MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
+{
+}
+
+MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
+ const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order,infos)
+{
+ DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
+ arr->setInfoAndChangeNbOfCompo(infos);
+}
+
+const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
+{
+ return TYPE_STR;
+}
+
+/*!
+ * Returns a pointer to the underground DataArrayFloat instance and a
+ * sequence describing parameters of a support of each part of \a this field. The
+ * caller should not decrRef() the returned DataArrayFloat. This method allows for a
+ * direct access to the field values. This method is intended for the field lying on one
+ * mesh only.
+ * \param [in,out] entries - the sequence describing parameters of a support of each
+ * part of \a this field. Each item of this sequence consists of two parts. The
+ * first part describes a type of mesh entity and an id of discretization of a
+ * current field part. The second part describes a range of values [begin,end)
+ * within the returned array relating to the current field part.
+ * \return DataArrayFloat * - the pointer to the field values array.
+ * \throw If the number of underlying meshes is not equal to 1.
+ * \throw If no field values are available.
+ * \sa getUndergroundDataArray()
+ */
+DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+{
+ return getUndergroundDataArrayFloatExt(entries);
+}
+
+/*!
+ * Returns a pointer to the underground DataArrayFloat instance and a
+ * sequence describing parameters of a support of each part of \a this field. The
+ * caller should not decrRef() the returned DataArrayFloat. This method allows for a
+ * direct access to the field values. This method is intended for the field lying on one
+ * mesh only.
+ * \param [in,out] entries - the sequence describing parameters of a support of each
+ * part of \a this field. Each item of this sequence consists of two parts. The
+ * first part describes a type of mesh entity and an id of discretization of a
+ * current field part. The second part describes a range of values [begin,end)
+ * within the returned array relating to the current field part.
+ * \return DataArrayFloat * - the pointer to the field values array.
+ * \throw If the number of underlying meshes is not equal to 1.
+ * \throw If no field values are available.
+ * \sa getUndergroundDataArray()
+ */
+DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+{
+ if(_field_per_mesh.size()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
+ if(_field_per_mesh[0]==0)
+ throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
+ _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
+ return getUndergroundDataArrayTemplate();
+}
+
+MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
+{
+ MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
+ ret->deepCpyLeavesFrom(*this);
+ return ret.retn();
+}
+
+MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
{
+ MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
+ if(_arr.isNotNull())
+ ret->_arr=_arr->deepCopy();
+ return ret.retn();
}
//= MEDFileAnyTypeField1TS
+MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
+{
+}
+
MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
{
med_field_type typcha;
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
}
+ case MED_NODE://6432
+ {
+ ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
+ break;
+ }
default:
{
std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
med_field_type typcha;
std::vector<std::string> infos;
std::string dtunit,meshName;
- int iii=-1;
- int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
+ int nbSteps(0);
+ {
+ int iii=-1;
+ nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
+ }
MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
switch(typcha)
{
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
}
+ case MED_NODE://6432
+ {
+ ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
+ break;
+ }
default:
{
- std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
+ std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
throw INTERP_KERNEL::Exception(oss.str());
}
}
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
break;
}
+ case MED_NODE://6432
+ {
+ ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
+ break;
+ }
default:
{
- std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
+ std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
throw INTERP_KERNEL::Exception(oss.str());
}
}
int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
{
- return contentNotNullBase()->copyTinyInfoFrom(field,arr);
-}
-
-//= MEDFileField1TS
-
-/*!
- * Returns a new instance of MEDFileField1TS holding data of the first time step of
- * the first field that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- */
-MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,loadAll);
-}
-
-MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
-{
- MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
- ret->contentNotNull();
- return ret.retn();
-}
-
-/*!
- * Returns a new instance of MEDFileField1TS holding data of the first time step of
- * a given field that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \param [in] fieldName - the name of the field to read.
- * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- * \throw If there is no field named \a fieldName in the file.
- */
-MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,fieldName,loadAll);
-}
-
-MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
-{
- MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
- ret->contentNotNull();
- return ret.retn();
-}
-
-/*!
- * Returns a new instance of MEDFileField1TS holding data of a given time step of
- * a given field that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \param [in] fieldName - the name of the field to read.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- * \throw If there is no field named \a fieldName in the file.
- * \throw If the required time step is missing from the file.
- */
-MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,fieldName,iteration,order,loadAll);
-}
-
-MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
-{
- MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
- ret->contentNotNull();
- return ret.retn();
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
+ return copyTinyInfoFrom(field->timeDiscrSafe(),ft,arr);
}
-/*!
- * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
- * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
- *
- * Returns a new instance of MEDFileField1TS holding either a shallow copy
- * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
- * \warning this is a shallow copy constructor
- * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
- * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
- * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
+int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
{
- MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
- ret->contentNotNull();
- return ret.retn();
+ return contentNotNullBase()->copyTinyInfoFrom(th,field,arr);
}
-/*!
- * Returns a new empty instance of MEDFileField1TS.
- * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileField1TS *MEDFileField1TS::New()
-{
- MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
- ret->contentNotNull();
- return ret.retn();
-}
+//= MEDFileField1TS
/*!
* This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
return ret.retn();
}
-const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
-{
- const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
- const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
- return ret;
-}
-
-MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
-{
- MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
- MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
- return ret;
-}
-
-void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
-{
- if(!f)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
- if(arr.isNull())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
- DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
- if(!arrOutC)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
- f->setArray(arrOutC);
-}
-
-DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
-{
- if(arr.isNull())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
- DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
- if(!arrOutC)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
- arrOutC->incrRef();
- return arrOutC;
-}
-
-/*!
- * Return an extraction of \a this using \a extractDef map to specify the extraction.
- * The keys of \a extractDef is level relative to max ext of \a mm mesh.
- *
- * \return A new object that the caller is responsible to deallocate.
- * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
- */
-MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
-{
- if(!mm)
- throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
- MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
- std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
- for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
- {
- if((*it0)!=ON_NODES)
- {
- std::vector<int> levs;
- getNonEmptyLevels(mm->getName(),levs);
- for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
- {
- std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
- if(it2!=extractDef.end())
- {
- MCAuto<DataArrayInt> t((*it2).second);
- if(t.isNull())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
- MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
- MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
- ret->setFieldNoProfileSBT(fOut);
- }
- }
- }
- else
- {
- std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
- if(it2==extractDef.end())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
- MCAuto<DataArrayInt> t((*it2).second);
- if(t.isNull())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
- MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
- MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
- DataArrayDouble *arr(f->getArray());
- MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
- fOut->setArray(newArr);
- ret->setFieldNoProfileSBT(fOut);
- }
- }
- return ret.retn();
-}
-
MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
+try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
{
}
catch(INTERP_KERNEL::Exception& e)
{ throw e; }
MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
+try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
{
}
catch(INTERP_KERNEL::Exception& e)
{ throw e; }
MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
+try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
{
}
catch(INTERP_KERNEL::Exception& e)
* \warning this is a shallow copy constructor
*/
MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
-try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
+try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
{
}
catch(INTERP_KERNEL::Exception& e)
{ throw e; }
-MEDFileField1TS::MEDFileField1TS()
+MEDFileField1TS *MEDFileField1TS::shallowCpy() const
{
- _content=new MEDFileField1TSWithoutSDA;
+ return new MEDFileField1TS(*this);
}
-/*!
- * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
- * method should be called (getFieldOnMeshAtLevel for example).
- * But for normal usage of field in MED file world this method is the most efficient to fetch data.
- *
- * \param [in] mesh - the mesh the field is lying on
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- */
-MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
+std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
+ std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
+ return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
}
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type lying on
- * mesh entities of a given dimension of the first mesh in MED file. If \a this field
- * has not been constructed via file reading, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If \a this field has not been constructed via file reading.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- * \sa getFieldOnMeshAtLevel()
- */
-MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
+//= MEDFileIntField1TS
+
+MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
+ if(!f)
+ throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
+ int t1,t2;
+ double t0(f->getTime(t1,t2));
+ std::string tu(f->getTimeUnit());
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
+ ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
+ return ret;
}
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type lying on
- * the top level cells of the first mesh in MED file. If \a this field
- * has not been constructed via file reading, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If \a this field has not been constructed via file reading.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If no field values of the given \a type.
- * \throw If no field values lying on the top level support.
- * \sa getFieldAtLevel()
- */
-MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
-{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the new field.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If the mesh is empty.
- * \throw If no field values of the given \a type are available.
- * \sa getFieldAtLevel()
- * \sa getFieldOnMeshAtLevel()
- */
-MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
-{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
+//= MEDFileFloatField1TS
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- * \sa getFieldAtLevel()
- * \sa getFieldOnMeshAtLevel()
- */
-MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
-{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
+//= MEDFileFloatField1TS
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
- * This method is called "Old" because in MED3 norm a field has only one meshName
- * attached, so this method is for readers of MED2 files. If \a this field
- * has not been constructed via file reading, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] mName - a name of the supporting mesh.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh named \a mName in the MED file.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If \a this field has not been constructed via file reading.
- * \throw If no field of \a this is lying on the mesh named \a mName.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- * \sa getFieldAtLevel()
- */
-MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
-{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
+//= MEDFileAnyTypeFieldMultiTSWithoutSDA
-/*!
- * Returns values and a profile of the field of a given type lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the field.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
- * field of interest lies on. If the field lies on all entities of the given
- * dimension, all ids in \a pfl are zero. The caller is to delete this array
- * using decrRef() as it is no more needed.
- * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
- * field. The caller is to delete this array using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- */
-DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
+MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
{
- MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
- return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
}
-/*!
- * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
- * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
- * "Sort By Type"), if not, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this.
- * \throw If the name of \a field is empty.
- * \throw If the data array of \a field is not set.
- * \throw If the data array is already allocated but has different number of components
- * than \a field.
- * \throw If the underlying mesh of \a field has no name.
- * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
- */
-void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
+MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
{
- setFileName("");
- contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
}
/*!
- * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
- * can be an aggregation of several MEDCouplingFieldDouble instances.
- * The mesh support of input parameter \a field is ignored here, it can be NULL.
- * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
- * and \a profile.
- *
- * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
- * A new profile is added only if no equal profile is missing.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
- * \param [in] mesh - the supporting mesh of \a field.
- * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
- * \param [in] profile - ids of mesh entities on which corresponding field values lie.
- * \throw If either \a field or \a mesh or \a profile has an empty name.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If the data array of \a field is not set.
- * \throw If the data array of \a this is already allocated but has different number of
- * components than \a field.
- * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
- * \sa setFieldNoProfileSBT()
+ * \param [in] fieldId field id in C mode
*/
-void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
+MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
{
- setFileName("");
- contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
+ med_field_type typcha;
+ std::string dtunitOut,meshName;
+ int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
+ setMeshName(meshName);
+ setDtUnit(dtunitOut.c_str());
+ loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
}
-MEDFileField1TS *MEDFileField1TS::shallowCpy() const
+MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
{
- return new MEDFileField1TS(*this);
+ setDtUnit(dtunit.c_str());
+ loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
}
-
-DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
+catch(INTERP_KERNEL::Exception& e)
{
- return contentNotNull()->getUndergroundDataArrayTemplate();
+ throw e;
}
-DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
{
- return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
+ std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
+ for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
+ ret+=(*it).capacity();
+ return ret;
}
-std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
- std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
+std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
{
- return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
+ std::vector<const BigMemoryObject *> ret;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
+ return ret;
}
-//= MEDFileIntField1TS
-
-MEDFileIntField1TS *MEDFileIntField1TS::New()
+/*!
+ * If one of the id in [ \a startIds , \a endIds ) points to a null element, there is not throw. Simply, this empty element is added as if it were not
+ * NULL.
+ */
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
{
- MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
- ret->contentNotNull();
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
+ ret->setInfo(_infos);
+ int sz=(int)_time_steps.size();
+ for(const int *id=startIds;id!=endIds;id++)
+ {
+ if(*id>=0 && *id<sz)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
+ if(tse)
+ {
+ tse->incrRef();
+ tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
+ }
+ ret->pushBackTimeStep(tse2);
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
+ oss << " ! Should be in [0," << sz << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ if(ret->getNumberOfTS()>0)
+ ret->synchronizeNameScope();
+ ret->copyNameScope(*this);
return ret.retn();
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return MEDFileIntField1TS::New(fid,loadAll);
-}
-
-MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
+/*!
+ * If one of the id in the input range points to a null element, there is not throw. Simply, this empty element is added as if it were not
+ * NULL.
+ */
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
{
- MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
- ret->contentNotNull();
+ static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
+ int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
+ ret->setInfo(_infos);
+ int sz=(int)_time_steps.size();
+ int j=bg;
+ for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
+ {
+ if(j>=0 && j<sz)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
+ if(tse)
+ {
+ tse->incrRef();
+ tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
+ }
+ ret->pushBackTimeStep(tse2);
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
+ oss << " ! Should be in [0," << sz << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ if(ret->getNumberOfTS()>0)
+ ret->synchronizeNameScope();
+ ret->copyNameScope(*this);
return ret.retn();
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return MEDFileIntField1TS::New(fid,fieldName,loadAll);
+ int id=0;
+ MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
+ if(!cur)
+ continue;
+ std::pair<int,int> p(cur->getIteration(),cur->getOrder());
+ if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
+ ids->pushBackSilent(id);
+ }
+ return buildFromTimeStepIds(ids->begin(),ids->end());
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
{
- MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
- ret->contentNotNull();
- return ret.retn();
+ int id=0;
+ MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
+ if(!cur)
+ continue;
+ std::pair<int,int> p(cur->getIteration(),cur->getOrder());
+ if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
+ ids->pushBackSilent(id);
+ }
+ return buildFromTimeStepIds(ids->begin(),ids->end());
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
+bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ if((*it)->presenceOfStructureElements())
+ return true;
+ return false;
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
+bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
{
- MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
- ret->contentNotNull();
- return ret.retn();
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ if(!(*it)->onlyStructureElements())
+ return false;
+ return true;
}
-MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
{
- MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
- ret->contentNotNull();
- return ret.retn();
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ {
+ if((*it)->presenceOfStructureElements())
+ {
+ if(!(*it)->onlyStructureElements())
+ {
+ (*it)->killStructureElements();
+ ret.push_back(*it);
+ }
+ }
+ else
+ {
+ ret.push_back(*it);
+ }
+ }
+ _time_steps=ret;
}
-MEDFileIntField1TS::MEDFileIntField1TS()
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
{
- _content=new MEDFileIntField1TSWithoutSDA;
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ {
+ if((*it)->presenceOfStructureElements())
+ {
+ if(!(*it)->onlyStructureElements())
+ (*it)->keepOnlyStructureElements();
+ ret.push_back(*it);
+ }
+ }
+ _time_steps=ret;
}
-MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
{
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ (*it)->keepOnlyOnSE(seName);
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
{
+ std::vector< std::pair<std::string,std::string> > ps2;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ {
+ (*it)->getMeshSENames(ps2);
+ break;
+ }
+ if(ps2.empty())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ {
+ std::vector< std::pair<std::string,std::string> > ps3;
+ (*it)->getMeshSENames(ps3);
+ if(ps2!=ps3)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
+ }
+ for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
+ {
+ std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
+ if(it2==ps.end())
+ ps.push_back(*it);
+ }
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
+bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
{
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
+ if(!cur)
+ continue;
+ if(cur->presenceOfMultiDiscPerGeoType())
+ return true;
+ }
+ return false;
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-/*!
- * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
- * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
- *
- * \warning this is a shallow copy constructor
- */
-MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
+const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
{
+ return _infos;
}
-MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
{
- return new MEDFileIntField1TS(*this);
+ _infos=info;
}
-/*!
- * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
- * following the given input policy.
- *
- * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
- * By default (true) the globals are deeply copied.
- * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
- */
-MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
+int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
{
- MCAuto<MEDFileField1TS> ret;
- const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
- if(content)
+ int ret=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
{
- const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
- if(!contc)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
- MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
- ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
+ const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
+ if(pt->isDealingTS(iteration,order))
+ return ret;
}
- else
- ret=MEDFileField1TS::New();
- if(isDeepCpyGlobs)
- ret->deepCpyGlobs(*this);
- else
- ret->shallowCpyGlobs(*this);
- return ret.retn();
+ std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
+ std::vector< std::pair<int,int> > vp=getIterations();
+ for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
+ oss << "(" << (*it2).first << "," << (*it2).second << ") ";
+ throw INTERP_KERNEL::Exception(oss.str());
}
-/*!
- * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
- * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
- * "Sort By Type"), if not, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this.
- * \throw If the name of \a field is empty.
- * \throw If the data array of \a field is not set.
- * \throw If the data array is already allocated but has different number of components
- * than \a field.
- * \throw If the underlying mesh of \a field has no name.
- * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
- */
-void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
+const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
{
- MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
- setFileName("");
- contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
+ return *_time_steps[getTimeStepPos(iteration,order)];
}
-/*!
- * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
- * can be an aggregation of several MEDCouplingFieldDouble instances.
- * The mesh support of input parameter \a field is ignored here, it can be NULL.
- * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
- * and \a profile.
- *
- * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
- * A new profile is added only if no equal profile is missing.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this.
- * \param [in] mesh - the supporting mesh of \a field.
- * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
- * \param [in] profile - ids of mesh entities on which corresponding field values lie.
- * \throw If either \a field or \a mesh or \a profile has an empty name.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If the data array of \a field is not set.
- * \throw If the data array of \a this is already allocated but has different number of
- * components than \a field.
- * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
- * \sa setFieldNoProfileSBT()
- */
-void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
+MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
{
- MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
- setFileName("");
- contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
+ return *_time_steps[getTimeStepPos(iteration,order)];
}
-const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
+bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
{
- const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
- const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
+ bool ret(false);
+ for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
+ {
+ if((*it).first==getMeshName())
+ {
+ setMeshName((*it).second);
+ ret=true;
+ }
+ }
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
+ if(cur)
+ ret=cur->changeMeshNames(modifTab) || ret;
+ }
return ret;
}
-MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
-{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
-}
-
-DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
+/*!
+ * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
+ */
+DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
{
- if(arr.isNull())
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
- DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
- if(!arrC)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
- arrC->incrRef();
- return arrC;
+ return getTimeStepEntry(iteration,order).getUndergroundDataArray();
}
-MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
+/*!
+ * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
+ */
+DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
{
- int t1,t2;
- double t0(f->getTime(t1,t2));
- MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
- MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
- MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
- ret->setTime(t0,t1,t2); ret->setArray(arr2);
- return ret.retn();
+ return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
}
-MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
+bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
+ MEDFileFieldGlobsReal& glob)
{
- if(!f)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
- int t1,t2;
- double t0(f->getTime(t1,t2));
- MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
- MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
- ret->setTime(t0,t1,t2);
+ bool ret=false;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
+ if(f1ts)
+ ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
+ }
return ret;
}
-MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
{
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((*it).isNotNull())
+ {
+ visitor.newTimeStepEntry(*it);
+ (*it)->accept(visitor);
+ visitor.endTimeStepEntry(*it);
+ }
}
-/*!
- * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
- * method should be called (getFieldOnMeshAtLevel for example).
- * But for normal usage of field in MED file world this method is the most efficient to fetch data.
- *
- * \param [in] mesh - the mesh the field is lying on
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
- * caller is to delete this field using decrRef() as it is no more needed.
- */
-MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
+ std::string startLine(bkOffset,' ');
+ oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
+ if(fmtsId>=0)
+ oss << " (" << fmtsId << ")";
+ oss << " has the following name: \"" << _name << "\"." << std::endl;
+ oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
+ for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
+ {
+ oss << startLine << " - \"" << *it << "\"" << std::endl;
+ }
+ int i=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
+ {
+ std::string chapter(17,'0'+i);
+ oss << startLine << chapter << std::endl;
+ const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
+ if(cur)
+ cur->simpleRepr(bkOffset+2,oss,i);
+ else
+ oss << startLine << " Field on one time step #" << i << " is not defined !" << std::endl;
+ oss << startLine << chapter << std::endl;
+ }
}
-/*!
- * Returns a new MEDCouplingFieldInt of a given type lying on
- * the top level cells of the first mesh in MED file. If \a this field
- * has not been constructed via file reading, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If \a this field has not been constructed via file reading.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If no field values of the given \a type.
- * \throw If no field values lying on the top level support.
- * \sa getFieldAtLevel()
- */
-MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
+std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
+ std::size_t sz=_time_steps.size();
+ std::vector< std::pair<int,int> > ret(sz);
+ ret1.resize(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
+ if(f1ts)
+ {
+ ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ return ret;
}
-/*!
- * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the new field.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If the mesh is empty.
- * \throw If no field values of the given \a type are available.
- * \sa getFieldAtLevel()
- * \sa getFieldOnMeshAtLevel()
- */
-MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
-{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- * \sa getFieldAtLevel()
- * \sa getFieldOnMeshAtLevel()
- */
-MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
-{
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
- * This method is called "Old" because in MED3 norm a field has only one meshName
- * attached, so this method is for readers of MED2 files. If \a this field
- * has not been constructed via file reading, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] mName - a name of the supporting mesh.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh named \a mName in the MED file.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If \a this field has not been constructed via file reading.
- * \throw If no field of \a this is lying on the mesh named \a mName.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- * \sa getFieldAtLevel()
- */
-MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
-{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
- MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
-}
-
-/*!
- * Returns values and a profile of the field of a given type lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the field.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
- * field of interest lies on. If the field lies on all entities of the given
- * dimension, all ids in \a pfl are zero. The caller is to delete this array
- * using decrRef() as it is no more needed.
- * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
- * field. The caller is to delete this array using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
- */
-DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
{
- MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
- return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
+ MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
+ if(!tse2)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
+ checkCoherencyOfType(tse2);
+ if(_time_steps.empty())
+ {
+ setName(tse2->getName());
+ setMeshName(tse2->getMeshName());
+ setInfo(tse2->getInfo());
+ }
+ checkThatComponentsMatch(tse2->getInfo());
+ if(getDtUnit().empty() && !tse->getDtUnit().empty())
+ setDtUnit(tse->getDtUnit());
+ _time_steps.push_back(tse);
}
-MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
{
- MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
- MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
- return ret;
+ std::size_t nbOfCompo=_infos.size();
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
+ if(cur)
+ {
+ if((cur->getInfo()).size()!=nbOfCompo)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
+ oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ cur->copyNameScope(*this);
+ }
+ }
}
-DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
{
- return contentNotNull()->getUndergroundDataArrayTemplate();
+ _time_steps.resize(nbPdt);
+ for(int i=0;i<nbPdt;i++)
+ {
+ std::vector< std::pair<int,int> > ts;
+ med_int numdt=0,numo=0;
+ med_float dt=0.0;
+ MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
+ switch(fieldTyp)
+ {
+ case MED_FLOAT64:
+ {
+ _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
+ break;
+ }
+ case MED_INT32:
+ {
+ _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
+ break;
+ }
+ case MED_NODE://6432
+ {
+ _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
+ break;
+ }
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !");
+ }
+ if(loadAll)
+ _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
+ else
+ _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
+ synchronizeNameScope();
+ }
}
-//= MEDFileAnyTypeFieldMultiTSWithoutSDA
-
-MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
{
+ if(_time_steps.empty())
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
+ checkThatNbOfCompoOfTSMatchThis();
+ std::vector<std::string> infos(getInfo());
+ int nbComp=infos.size();
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
+ for(int i=0;i<nbComp;i++)
+ {
+ std::string info=infos[i];
+ std::string c,u;
+ MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
+ MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
+ }
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
+ MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
+ int nbOfTS=_time_steps.size();
+ for(int i=0;i<nbOfTS;i++)
+ _time_steps[i]->writeLL(fid,opts,*this);
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
{
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursively(fid,nasc);
+ }
}
-/*!
- * \param [in] fieldId field id in C mode
- */
-MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
{
- med_field_type typcha;
- std::string dtunitOut,meshName;
- int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
- setMeshName(meshName);
- setDtUnit(dtunitOut.c_str());
- loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
+ }
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
-{
- setDtUnit(dtunit.c_str());
- loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
-}
-catch(INTERP_KERNEL::Exception& e)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
{
- throw e;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->unloadArrays();
+ }
}
-std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
+int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
{
- std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
- for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
- ret+=(*it).capacity();
- return ret;
+ return _time_steps.size();
}
-std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
{
- std::vector<const BigMemoryObject *> ret;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
- return ret;
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
+ if(tmp)
+ newTS.push_back(*it);
+ }
+ _time_steps=newTS;
}
-/*!
- * If one of the id in [ \a startIds , \a endIds ) points to a null element, there is not throw. Simply, this empty element is added as if it were not
- * NULL.
- */
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
- ret->setInfo(_infos);
- int sz=(int)_time_steps.size();
- for(const int *id=startIds;id!=endIds;id++)
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
+ int maxId=(int)_time_steps.size();
+ int ii=0;
+ std::set<int> idsToDel;
+ for(const int *id=startIds;id!=endIds;id++,ii++)
{
- if(*id>=0 && *id<sz)
+ if(*id>=0 && *id<maxId)
{
- const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
- if(tse)
- {
- tse->incrRef();
- tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
- }
- ret->pushBackTimeStep(tse2);
+ idsToDel.insert(*id);
}
else
{
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
- oss << " ! Should be in [0," << sz << ") !";
+ std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
throw INTERP_KERNEL::Exception(oss.str());
}
}
- if(ret->getNumberOfTS()>0)
- ret->synchronizeNameScope();
- ret->copyNameScope(*this);
- return ret.retn();
+ for(int iii=0;iii<maxId;iii++)
+ if(idsToDel.find(iii)==idsToDel.end())
+ newTS.push_back(_time_steps[iii]);
+ _time_steps=newTS;
}
-/*!
- * If one of the id in the input range points to a null element, there is not throw. Simply, this empty element is added as if it were not
- * NULL.
- */
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
{
- static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
- int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
- ret->setInfo(_infos);
- int sz=(int)_time_steps.size();
+ static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
+ int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
+ if(nbOfEntriesToKill==0)
+ return ;
+ std::size_t sz=_time_steps.size();
+ std::vector<bool> b(sz,true);
int j=bg;
- for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
+ for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
+ b[j]=false;
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
+ for(std::size_t i=0;i<sz;i++)
+ if(b[i])
+ newTS.push_back(_time_steps[i]);
+ _time_steps=newTS;
+}
+
+int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
+{
+ int ret=0;
+ std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : ";
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
{
- if(j>=0 && j<sz)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
- if(tse)
- {
- tse->incrRef();
- tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
- }
- ret->pushBackTimeStep(tse2);
- }
- else
+ const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
+ if(tmp)
{
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
- oss << " ! Should be in [0," << sz << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
+ int it2,ord;
+ tmp->getTime(it2,ord);
+ if(it2==iteration && order==ord)
+ return ret;
+ else
+ oss << "(" << it2 << "," << ord << "), ";
}
}
- if(ret->getNumberOfTS()>0)
- ret->synchronizeNameScope();
- ret->copyNameScope(*this);
- return ret.retn();
+ throw INTERP_KERNEL::Exception(oss.str());
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
+int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
{
- int id=0;
- MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
+ int ret=0;
+ std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
+ oss.precision(15);
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
{
- const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
- if(!cur)
- continue;
- std::pair<int,int> p(cur->getIteration(),cur->getOrder());
- if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
- ids->pushBackSilent(id);
+ const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
+ if(tmp)
+ {
+ int it2,ord;
+ double ti=tmp->getTime(it2,ord);
+ if(fabs(time-ti)<eps)
+ return ret;
+ else
+ oss << ti << ", ";
+ }
}
- return buildFromTimeStepIds(ids->begin(),ids->end());
+ throw INTERP_KERNEL::Exception(oss.str());
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
+std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
{
- int id=0;
- MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
- if(!cur)
- continue;
- std::pair<int,int> p(cur->getIteration(),cur->getOrder());
- if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
- ids->pushBackSilent(id);
- }
- return buildFromTimeStepIds(ids->begin(),ids->end());
+ int lgth=_time_steps.size();
+ std::vector< std::pair<int,int> > ret(lgth);
+ for(int i=0;i<lgth;i++)
+ _time_steps[i]->fillIteration(ret[i]);
+ return ret;
}
-bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
+/*!
+ * This method has 3 inputs 'iteration' 'order' 'mname'. 'mname' can be null if the user is the general case where there is only one meshName lying on 'this'
+ * This method returns two things.
+ * - The absolute dimension of 'this' in first parameter.
+ * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
+ * to the first output parameter. The values in 'levs' will be returned in decreasing order.
+ *
+ * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
+ * Only these 3 discretizations will be taken into account here.
+ *
+ * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
+ * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
+ * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
+ *
+ * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
+ * It is possible (even if it is not common) that the highest level in 'this' were not equal to the meshDimension of the underlying mesh in 'this'.
+ *
+ * Let's consider the typical following case :
+ * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
+ * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
+ * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
+ * TETRA4 and SEG2
+ * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
+ *
+ * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
+ *
+ * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
+ * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
+ * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
+ * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
+ */
+int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- if((*it)->presenceOfStructureElements())
- return true;
- return false;
+ return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
}
-bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
+const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- if(!(*it)->onlyStructureElements())
- return false;
- return true;
+ if(pos<0 || pos>=(int)_time_steps.size())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
+ if(item==0)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
+ oss << "\nTry to use following method eraseEmptyTS !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return item;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
+MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
{
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- {
- if((*it)->presenceOfStructureElements())
- {
- if(!(*it)->onlyStructureElements())
- {
- (*it)->killStructureElements();
- ret.push_back(*it);
- }
- }
- else
+ if(pos<0 || pos>=(int)_time_steps.size())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
+ if(item==0)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
+ oss << "\nTry to use following method eraseEmptyTS !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return item;
+}
+
+std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
{
- ret.push_back(*it);
+ ret.push_back(*it2);
+ ret2.insert(*it2);
}
- }
- _time_steps=ret;
+ }
+ return ret;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
+std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
{
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- {
- if((*it)->presenceOfStructureElements())
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
{
- if(!(*it)->onlyStructureElements())
- (*it)->keepOnlyStructureElements();
- ret.push_back(*it);
+ ret.push_back(*it2);
+ ret2.insert(*it2);
}
- }
- _time_steps=ret;
+ }
+ return ret;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
+std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
{
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- (*it)->keepOnlyOnSE(seName);
+ std::vector<std::string> ret;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
+ ret.insert(ret.end(),tmp.begin(),tmp.end());
+ }
+ return ret;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
+std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
{
- std::vector< std::pair<std::string,std::string> > ps2;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- {
- (*it)->getMeshSENames(ps2);
- break;
- }
- if(ps2.empty())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- {
- std::vector< std::pair<std::string,std::string> > ps3;
- (*it)->getMeshSENames(ps3);
- if(ps2!=ps3)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
- }
- for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
+ std::vector<std::string> ret;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
{
- std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
- if(it2==ps.end())
- ps.push_back(*it);
+ std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
+ ret.insert(ret.end(),tmp.begin(),tmp.end());
}
+ return ret;
}
-bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
- if(!cur)
- continue;
- if(cur->presenceOfMultiDiscPerGeoType())
- return true;
- }
- return false;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ (*it)->changePflsRefsNamesGen2(mapOfModif);
}
-const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
{
- return _infos;
+ for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ (*it)->changeLocsRefsNamesGen2(mapOfModif);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
+std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
{
- _infos=info;
+ int lgth=_time_steps.size();
+ std::vector< std::vector<TypeOfField> > ret(lgth);
+ for(int i=0;i<lgth;i++)
+ _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
+ return ret;
}
-int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
+/*!
+ * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
+ */
+std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
{
- int ret=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
- if(pt->isDealingTS(iteration,order))
- return ret;
- }
- std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
- std::vector< std::pair<int,int> > vp=getIterations();
- for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
- oss << "(" << (*it2).first << "," << (*it2).second << ") ";
- throw INTERP_KERNEL::Exception(oss.str());
+ return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
}
-const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
{
- return *_time_steps[getTimeStepPos(iteration,order)];
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
+ std::size_t i=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
+ {
+ if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
+ ret->_time_steps[i]=(*it)->deepCopy();
+ }
+ return ret.retn();
}
-MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
+std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
{
- return *_time_steps[getTimeStepPos(iteration,order)];
+ std::size_t sz(_infos.size()),sz2(_time_steps.size());
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
+ std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ ret[i]=shallowCpy();
+ ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
+ }
+ for(std::size_t i=0;i<sz2;i++)
+ {
+ std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
+ if(ret1.size()!=sz)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ ts[i]=ret1;
+ }
+ for(std::size_t i=0;i<sz;i++)
+ for(std::size_t j=0;j<sz2;j++)
+ ret[i]->_time_steps[j]=ts[j][i];
+ return ret;
}
-bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
+/*!
+ * This method splits into discretization each time steps in \a this.
+ * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
+ */
+std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
{
- bool ret(false);
- for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
+ std::size_t sz(_time_steps.size());
+ std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
+ for(std::size_t i=0;i<sz;i++)
{
- if((*it).first==getMeshName())
+ const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
+ if(!timeStep)
{
- setMeshName((*it).second);
- ret=true;
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
+ items[i]=timeStep->splitDiscretizations();
}
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ //
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
+ std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
+ std::vector< TypeOfField > types;
+ for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+ {
+ std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
+ if(ts.size()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
+ std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
+ if(it2==types.end())
+ types.push_back(ts[0]);
+ }
+ ret.resize(types.size()); ret2.resize(types.size());
+ for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+ {
+ TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
+ std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
+ ret2[pos].push_back(*it1);
+ }
+ for(std::size_t i=0;i<types.size();i++)
{
- MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
- if(cur)
- ret=cur->changeMeshNames(modifTab) || ret;
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
+ elt->pushBackTimeStep(*it1);//also updates infos in elt
+ ret[i]=elt;
+ elt->MEDFileFieldNameScope::operator=(*this);
}
return ret;
}
/*!
- * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
+ * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
*/
-DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
+std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
{
- return getTimeStepEntry(iteration,order).getUndergroundDataArray();
+ std::size_t sz(_time_steps.size());
+ std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
+ std::size_t szOut(std::numeric_limits<std::size_t>::max());
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
+ if(!timeStep)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ items[i]=timeStep->splitMultiDiscrPerGeoTypes();
+ if(szOut==std::numeric_limits<std::size_t>::max())
+ szOut=items[i].size();
+ else
+ if(items[i].size()!=szOut)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
+ }
+ if(szOut==std::numeric_limits<std::size_t>::max())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
+ for(std::size_t i=0;i<szOut;i++)
+ {
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
+ for(std::size_t j=0;j<sz;j++)
+ elt->pushBackTimeStep(items[j][i]);
+ ret[i]=elt;
+ elt->MEDFileFieldNameScope::operator=(*this);
+ }
+ return ret;
}
-/*!
- * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
- */
-DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
{
- return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
+ setName(field->getName());
+ if(field->getMesh())
+ setMeshName(field->getMesh()->getName());
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
+ if(!arr)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
+ _infos=arr->getInfoOnComponents();
}
-bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
- MEDFileFieldGlobsReal& glob)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
{
- bool ret=false;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
+ if(_name!=field->getName())
{
- MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
- if(f1ts)
- ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
+ std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
+ oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
- return ret;
-}
-
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
-{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- if((*it).isNotNull())
- {
- visitor.newTimeStepEntry(*it);
- (*it)->accept(visitor);
- visitor.endTimeStepEntry(*it);
- }
+ if(!arr)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
+ checkThatComponentsMatch(arr->getInfoOnComponents());
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
{
- std::string startLine(bkOffset,' ');
- oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
- if(fmtsId>=0)
- oss << " (" << fmtsId << ")";
- oss << " has the following name: \"" << _name << "\"." << std::endl;
- oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
- for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
+ static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
+ if(getInfo().size()!=compos.size())
{
- oss << startLine << " - \"" << *it << "\"" << std::endl;
+ std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
+ oss << " number of components of element to append (" << compos.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
- int i=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
+ if(_infos!=compos)
{
- std::string chapter(17,'0'+i);
- oss << startLine << chapter << std::endl;
- const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
- if(cur)
- cur->simpleRepr(bkOffset+2,oss,i);
- else
- oss << startLine << " Field on one time step #" << i << " is not defined !" << std::endl;
- oss << startLine << chapter << std::endl;
+ std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
+ std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
+ oss << " But compo in input fields are : ";
+ std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
+ oss << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
}
-std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
{
- std::size_t sz=_time_steps.size();
- std::vector< std::pair<int,int> > ret(sz);
- ret1.resize(sz);
- for(std::size_t i=0;i<sz;i++)
+ std::size_t sz=_infos.size();
+ int j=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
{
- const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
- if(f1ts)
- {
- ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
- }
- else
- {
- std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
+ const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ if(elt->getInfo().size()!=sz)
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
+ oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
}
- return ret;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
{
- MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
- if(!tse2)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
- checkCoherencyOfType(tse2);
- if(_time_steps.empty())
- {
- setName(tse2->getName());
- setMeshName(tse2->getMeshName());
- setInfo(tse2->getInfo());
- }
- checkThatComponentsMatch(tse2->getInfo());
- if(getDtUnit().empty() && !tse->getDtUnit().empty())
- setDtUnit(tse->getDtUnit());
- _time_steps.push_back(tse);
+ if(!field)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
+ if(!_time_steps.empty())
+ checkCoherencyOfTinyInfo(field,arr);
+ MEDFileAnyTypeField1TSWithoutSDA *objC(createNew1TSWithoutSDAEmptyInstance());
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
+ {
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
+ objC->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,arr,glob,*this);
+ }
+ copyTinyInfoFrom(field,arr);
+ _time_steps.push_back(obj);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
{
- std::size_t nbOfCompo=_infos.size();
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
- if(cur)
- {
- if((cur->getInfo()).size()!=nbOfCompo)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
- oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- cur->copyNameScope(*this);
- }
- }
+ if(!field)
+ throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
+ if(!_time_steps.empty())
+ checkCoherencyOfTinyInfo(field,arr);
+ MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
+ {
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
+ objC->setFieldProfile(field->timeDiscrSafe(),ft,arr,mesh,meshDimRelToMax,profile,glob,*this);
+ }
+ copyTinyInfoFrom(field,arr);
+ setMeshName(objC->getMeshName());
+ _time_steps.push_back(obj);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
{
- _time_steps.resize(nbPdt);
- for(int i=0;i<nbPdt;i++)
+ int sz=(int)_time_steps.size();
+ if(i<0 || i>=sz)
{
- std::vector< std::pair<int,int> > ts;
- med_int numdt=0,numo=0;
- med_float dt=0.0;
- MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
- switch(fieldTyp)
- {
- case MED_FLOAT64:
- {
- _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
- break;
- }
- case MED_INT32:
- {
- _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
- break;
- }
- default:
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
- }
- if(loadAll)
- _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
- else
- _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
- synchronizeNameScope();
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
-}
-
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
-{
- if(_time_steps.empty())
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
- checkThatNbOfCompoOfTSMatchThis();
- std::vector<std::string> infos(getInfo());
- int nbComp=infos.size();
- INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
- for(int i=0;i<nbComp;i++)
+ const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
+ if(tsPtr)
{
- std::string info=infos[i];
- std::string c,u;
- MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
- MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
+ if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
}
- if(_name.empty())
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
- MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
- int nbOfTS=_time_steps.size();
- for(int i=0;i<nbOfTS;i++)
- _time_steps[i]->writeLL(fid,opts,*this);
+ _time_steps[i]=ts;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
-{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
- if(elt)
- elt->loadBigArraysRecursively(fid,nasc);
- }
-}
+//= MEDFileFieldMultiTSWithoutSDA
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
+/*!
+ * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
+ * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
+ */
+std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
- if(elt)
- elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
- }
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
+ const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
+ return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
+MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
{
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
+ ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
+ int i=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
{
- MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
- if(elt)
- elt->unloadArrays();
+ const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
+ if(eltToConv)
+ {
+ const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
+ if(!eltToConvC)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
+ ret->setIteration(i,elt);
+ }
}
+ return ret.retn();
}
-int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
-{
- return _time_steps.size();
-}
+//= MEDFileAnyTypeFieldMultiTS
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
+MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
{
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
- if(tmp)
- newTS.push_back(*it);
- }
- _time_steps=newTS;
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
+MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
+try:MEDFileFieldGlobsReal(fid)
{
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
- int maxId=(int)_time_steps.size();
- int ii=0;
- std::set<int> idsToDel;
- for(const int *id=startIds;id!=endIds;id++,ii++)
- {
- if(*id>=0 && *id<maxId)
- {
- idsToDel.insert(*id);
- }
- else
- {
- std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- for(int iii=0;iii<maxId;iii++)
- if(idsToDel.find(iii)==idsToDel.end())
- newTS.push_back(_time_steps[iii]);
- _time_steps=newTS;
+ _content=BuildContentFrom(fid,loadAll,ms);
+ loadGlobals(fid);
}
-
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
+catch(INTERP_KERNEL::Exception& e)
{
- static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
- int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
- if(nbOfEntriesToKill==0)
- return ;
- std::size_t sz=_time_steps.size();
- std::vector<bool> b(sz,true);
- int j=bg;
- for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
- b[j]=false;
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
- for(std::size_t i=0;i<sz;i++)
- if(b[i])
- newTS.push_back(_time_steps[i]);
- _time_steps=newTS;
+ throw e;
}
-int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
{
- int ret=0;
- std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : ";
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
- if(tmp)
- {
- int it2,ord;
- tmp->getTime(it2,ord);
- if(it2==iteration && order==ord)
- return ret;
- else
- oss << "(" << it2 << "," << ord << "), ";
- }
- }
- throw INTERP_KERNEL::Exception(oss.str());
+ med_field_type typcha;
+ std::vector<std::string> infos;
+ std::string dtunit;
+ std::string meshName;
+ int i(-1);
+ MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
+ switch(typcha)
+ {
+ case MED_FLOAT64:
+ {
+ ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
+ break;
+ }
+ case MED_INT32:
+ {
+ ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
+ break;
+ }
+ case MED_NODE://6432
+ {
+ ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
+ break;
+ }
+ default:
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ ret->setMeshName(meshName);
+ ret->setDtUnit(dtunit.c_str());
+ return ret.retn();
}
-int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
{
- int ret=0;
- std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
- oss.precision(15);
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
+ med_field_type typcha;
+ //
+ std::vector<std::string> infos;
+ std::string dtunit,fieldName,meshName;
+ MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
+ switch(typcha)
+ {
+ case MED_FLOAT64:
+ {
+ ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
+ break;
+ }
+ case MED_INT32:
+ {
+ ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
+ break;
+ }
+ case MED_NODE://6432
+ {
+ ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
+ break;
+ }
+ default:
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ ret->setMeshName(meshName);
+ ret->setDtUnit(dtunit.c_str());
+ return ret.retn();
+}
+
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
+{
+ if(!c)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
+ if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
{
- const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
- if(tmp)
- {
- int it2,ord;
- double ti=tmp->getTime(it2,ord);
- if(fabs(time-ti)<eps)
- return ret;
- else
- oss << ti << ", ";
- }
+ MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
+ ret->_content=c; c->incrRef();
+ return ret.retn();
}
- throw INTERP_KERNEL::Exception(oss.str());
+ if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
+ {
+ MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
+ ret->_content=c; c->incrRef();
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
}
-std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
{
- int lgth=_time_steps.size();
- std::vector< std::pair<int,int> > ret(lgth);
- for(int i=0;i<lgth;i++)
- _time_steps[i]->fillIteration(ret[i]);
+ MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
+ std::string fileName(FileNameFromFID(fid));
+ ret->setFileName(fileName);
return ret;
}
+MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+try:MEDFileFieldGlobsReal(fid)
+{
+ _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
+ loadGlobals(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+{
+ throw e;
+}
+
+//= MEDFileAnyTypeFieldMultiTS
+
/*!
- * This method has 3 inputs 'iteration' 'order' 'mname'. 'mname' can be null if the user is the general case where there is only one meshName lying on 'this'
- * This method returns two things.
- * - The absolute dimension of 'this' in first parameter.
- * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
- * to the first output parameter. The values in 'levs' will be returned in decreasing order.
- *
- * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
- * Only these 3 discretizations will be taken into account here.
- *
- * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
- * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
- * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
- *
- * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
- * It is possible (even if it is not common) that the highest level in 'this' were not equal to the meshDimension of the underlying mesh in 'this'.
- *
- * Let's consider the typical following case :
- * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
- * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
- * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
- * TETRA4 and SEG2
- * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
- *
- * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
- *
- * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
- * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
- * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
- * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
+ * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
+ * that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
*/
-int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
{
- return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,loadAll);
}
-const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
{
- if(pos<0 || pos>=(int)_time_steps.size())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
- if(item==0)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
- oss << "\nTry to use following method eraseEmptyTS !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- return item;
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
+ MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
+ ret->loadGlobals(fid);
+ return ret.retn();
}
-MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
+/*!
+ * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
+ * that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \param [in] fieldName - the name of the field to read.
+ * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ * \throw If there is no field named \a fieldName in the file.
+ */
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
{
- if(pos<0 || pos>=(int)_time_steps.size())
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,fieldName,loadAll);
+}
+
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
+{
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
+ MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
+ ret->loadGlobals(fid);
+ return ret.retn();
+}
+
+/*!
+ * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
+ * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ *
+ * \warning this is a shallow copy constructor
+ */
+MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
+{
+ if(!shallowCopyOfContent)
{
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
+ otherPtr->incrRef();
+ _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
}
- MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
- if(item==0)
+ else
{
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
- oss << "\nTry to use following method eraseEmptyTS !";
- throw INTERP_KERNEL::Exception(oss.str());
+ _content=other.shallowCpy();
}
- return item;
}
-std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
+MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
{
- std::vector<std::string> ret;
- std::set<std::string> ret2;
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
- for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
- if(ret2.find(*it2)==ret2.end())
- {
- ret.push_back(*it2);
- ret2.insert(*it2);
- }
- }
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
return ret;
}
-std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
+const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
{
- std::vector<std::string> ret;
- std::set<std::string> ret2;
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
- for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
- if(ret2.find(*it2)==ret2.end())
- {
- ret.push_back(*it2);
- ret2.insert(*it2);
- }
- }
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
return ret;
}
-std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
+std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
{
- std::vector<std::string> ret;
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
- ret.insert(ret.end(),tmp.begin(),tmp.end());
- }
- return ret;
+ return contentNotNullBase()->getPflsReallyUsed2();
}
-std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
+std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
{
- std::vector<std::string> ret;
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- {
- std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
- ret.insert(ret.end(),tmp.begin(),tmp.end());
- }
- return ret;
+ return contentNotNullBase()->getLocsReallyUsed2();
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
+std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
{
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- (*it)->changePflsRefsNamesGen2(mapOfModif);
+ return contentNotNullBase()->getPflsReallyUsedMulti2();
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
+std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
{
- for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
- (*it)->changeLocsRefsNamesGen2(mapOfModif);
+ return contentNotNullBase()->getLocsReallyUsedMulti2();
}
-std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
+void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
{
- int lgth=_time_steps.size();
- std::vector< std::vector<TypeOfField> > ret(lgth);
- for(int i=0;i<lgth;i++)
- _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
- return ret;
+ contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
}
-/*!
- * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
- */
-std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
+void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
{
- return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
+ contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
+int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
- std::size_t i=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
- {
- if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
- ret->_time_steps[i]=(*it)->deepCopy();
- }
- return ret.retn();
+ return contentNotNullBase()->getNumberOfTS();
}
-std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
+void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
{
- std::size_t sz(_infos.size()),sz2(_time_steps.size());
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
- std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
- for(std::size_t i=0;i<sz;i++)
- {
- ret[i]=shallowCpy();
- ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
- }
- for(std::size_t i=0;i<sz2;i++)
- {
- std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
- if(ret1.size()!=sz)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- ts[i]=ret1;
- }
- for(std::size_t i=0;i<sz;i++)
- for(std::size_t j=0;j<sz2;j++)
- ret[i]->_time_steps[j]=ts[j][i];
- return ret;
+ contentNotNullBase()->eraseEmptyTS();
}
-/*!
- * This method splits into discretization each time steps in \a this.
- * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
- */
-std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
+void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
{
- std::size_t sz(_time_steps.size());
- std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
- for(std::size_t i=0;i<sz;i++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
- if(!timeStep)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- items[i]=timeStep->splitDiscretizations();
- }
- //
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
- std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
- std::vector< TypeOfField > types;
- for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
- {
- std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
- if(ts.size()!=1)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
- std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
- if(it2==types.end())
- types.push_back(ts[0]);
- }
- ret.resize(types.size()); ret2.resize(types.size());
- for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
- {
- TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
- std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
- ret2[pos].push_back(*it1);
- }
- for(std::size_t i=0;i<types.size();i++)
- {
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
- elt->pushBackTimeStep(*it1);//also updates infos in elt
- ret[i]=elt;
- elt->MEDFileFieldNameScope::operator=(*this);
- }
- return ret;
+ contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
}
-/*!
- * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
- */
-std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
+void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
{
- std::size_t sz(_time_steps.size());
- std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
- std::size_t szOut(std::numeric_limits<std::size_t>::max());
- for(std::size_t i=0;i<sz;i++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
- if(!timeStep)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- items[i]=timeStep->splitMultiDiscrPerGeoTypes();
- if(szOut==std::numeric_limits<std::size_t>::max())
- szOut=items[i].size();
- else
- if(items[i].size()!=szOut)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
- }
- if(szOut==std::numeric_limits<std::size_t>::max())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
- for(std::size_t i=0;i<szOut;i++)
- {
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
- for(std::size_t j=0;j<sz;j++)
- elt->pushBackTimeStep(items[j][i]);
- ret[i]=elt;
- elt->MEDFileFieldNameScope::operator=(*this);
- }
- return ret;
+ contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
{
- setName(field->getName());
- if(field->getMesh())
- setMeshName(field->getMesh()->getName());
- if(_name.empty())
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
- if(!arr)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
- _infos=arr->getInfoOnComponents();
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
+ MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
+ ret->_content=c;
+ return ret.retn();
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
{
- static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
- if(_name!=field->getName())
- {
- std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
- oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- if(!arr)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
- checkThatComponentsMatch(arr->getInfoOnComponents());
+ MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
+ MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
+ ret->_content=c;
+ return ret.retn();
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
+std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
{
- static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
- if(getInfo().size()!=compos.size())
- {
- std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
- oss << " number of components of element to append (" << compos.size() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- if(_infos!=compos)
- {
- std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
- std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
- oss << " But compo in input fields are : ";
- std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
+ return contentNotNullBase()->getIterations();
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
+void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
{
- std::size_t sz=_infos.size();
- int j=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
+ for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
+ pushBackTimeStep(*it);
+}
+
+void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
+{
+ if(!fmts)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
+ int nbOfTS(fmts->getNumberOfTS());
+ for(int i=0;i<nbOfTS;i++)
{
- const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
- if(elt)
- if(elt->getInfo().size()!=sz)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
- oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
+ MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
+ pushBackTimeStep(elt);
}
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
+void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
{
- if(!field)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
- if(!_time_steps.empty())
- checkCoherencyOfTinyInfo(field,arr);
- MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
- objC->setFieldNoProfileSBT(field,arr,glob,*this);
- copyTinyInfoFrom(field,arr);
- _time_steps.push_back(obj);
-}
-
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
-{
- if(!field)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
- if(!_time_steps.empty())
- checkCoherencyOfTinyInfo(field,arr);
- MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
- objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
- copyTinyInfoFrom(field,arr);
- setMeshName(objC->getMeshName());
- _time_steps.push_back(obj);
+ if(!f1ts)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
+ checkCoherencyOfType(f1ts);
+ f1ts->incrRef();
+ MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
+ MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
+ c->incrRef();
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
+ if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
+ _content->pushBackTimeStep(cSafe);
+ appendGlobs(*f1ts,1e-12);
}
-void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
+void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
{
- int sz=(int)_time_steps.size();
- if(i<0 || i>=sz)
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
- if(tsPtr)
- {
- if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- _time_steps[i]=ts;
+ contentNotNullBase()->synchronizeNameScope();
}
-//= MEDFileFieldMultiTSWithoutSDA
-
-MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
{
- return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
+ return contentNotNullBase()->getPosOfTimeStep(iteration,order);
}
-MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
+int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
{
+ return contentNotNullBase()->getPosGivenTime(time,eps);
}
-MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
+int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
{
+ return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
}
-/*!
- * \param [in] fieldId field id in C mode
- */
-MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
+std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
{
+ return contentNotNullBase()->getTypesOfFieldAvailable();
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
+std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTS::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
{
+ return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
+std::string MEDFileAnyTypeFieldMultiTS::getName() const
{
- return new MEDFileField1TSWithoutSDA;
+ return contentNotNullBase()->getName();
}
-void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
+void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
{
- if(!f1ts)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
- const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
- if(!f1tsC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
+ contentNotNullBase()->setName(name);
}
-const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
+std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
{
- return MEDFileField1TSWithoutSDA::TYPE_STR;
+ return contentNotNullBase()->getDtUnit();
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
+void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
{
- return new MEDFileFieldMultiTSWithoutSDA(*this);
+ contentNotNullBase()->setDtUnit(dtUnit);
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
+void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
{
- return new MEDFileFieldMultiTSWithoutSDA;
+ contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
}
-/*!
- * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
- * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
- */
-std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
+std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
- return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
+ return contentNotNullBase()->getTimeSteps(ret1);
}
-MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
+std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
{
- MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
- ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
- int i=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
- {
- const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
- if(eltToConv)
- {
- const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
- if(!eltToConvC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
- ret->setIteration(i,elt);
- }
- }
- return ret.retn();
+ return contentNotNullBase()->getMeshName();
}
-//= MEDFileAnyTypeFieldMultiTS
-
-MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
+void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
{
+ contentNotNullBase()->setMeshName(newMeshName);
}
-MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileFieldGlobsReal(fid)
-{
- _content=BuildContentFrom(fid,loadAll,ms);
- loadGlobals(fid);
-}
-catch(INTERP_KERNEL::Exception& e)
+bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
{
- throw e;
+ return contentNotNullBase()->changeMeshNames(modifTab);
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
{
- med_field_type typcha;
- std::vector<std::string> infos;
- std::string dtunit;
- std::string meshName;
- int i(-1);
- MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
- switch(typcha)
- {
- case MED_FLOAT64:
- {
- ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
- break;
- }
- case MED_INT32:
- {
- ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
- break;
- }
- default:
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- ret->setMeshName(meshName);
- ret->setDtUnit(dtunit.c_str());
- return ret.retn();
+ return contentNotNullBase()->getInfo();
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
+bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
{
- med_field_type typcha;
- //
- std::vector<std::string> infos;
- std::string dtunit,fieldName,meshName;
- MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
- switch(typcha)
- {
- case MED_FLOAT64:
- {
- ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
- break;
- }
- case MED_INT32:
- {
- ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
- break;
- }
- default:
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- ret->setMeshName(meshName);
- ret->setDtUnit(dtunit.c_str());
- return ret.retn();
+ return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
}
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
+void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
{
- if(!c)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
- if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
- {
- MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
- ret->_content=c; c->incrRef();
- return ret.retn();
- }
- if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
- {
- MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
- ret->_content=c; c->incrRef();
- return ret.retn();
- }
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
+ return contentNotNullBase()->setInfo(info);
}
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
+int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
{
- MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
- std::string fileName(FileNameFromFID(fid));
- ret->setFileName(fileName);
- return ret;
+ const std::vector<std::string> ret=getInfo();
+ return (int)ret.size();
}
-MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileFieldGlobsReal(fid)
-{
- _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
- loadGlobals(fid);
-}
-catch(INTERP_KERNEL::Exception& e)
+void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
{
- throw e;
+ writeGlobals(fid,*this);
+ contentNotNullBase()->writeLL(fid,*this);
}
-//= MEDFileIntFieldMultiTSWithoutSDA
-
-MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+/*!
+ * This method alloc the arrays and load potentially huge arrays contained in this field.
+ * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
+ * This method can be also called to refresh or reinit values from a file.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ */
+void MEDFileAnyTypeFieldMultiTS::loadArrays()
{
- return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
+ if(getFileName().empty())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
+ contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
}
-MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
+/*!
+ * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
+ * But once data loaded once, this method does nothing.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
+ */
+void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
{
+ if(!getFileName().empty())
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
+ contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
+ }
}
-MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
+/*!
+ * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
+ * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
+ * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
+ *
+ * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
+ */
+void MEDFileAnyTypeFieldMultiTS::unloadArrays()
{
+ contentNotNullBase()->unloadArrays();
}
-MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
-{
-}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-
/*!
- * \param [in] fieldId field id in C mode
+ * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
+ * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
+ * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
+ *
+ * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
*/
-MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
-{
-}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-
-MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
+void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
{
- return new MEDFileIntField1TSWithoutSDA;
+ if(!getFileName().empty())
+ contentNotNullBase()->unloadArrays();
}
-void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
+std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
{
- if(!f1ts)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
- const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
- if(!f1tsC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
+ std::ostringstream oss;
+ contentNotNullBase()->simpleRepr(0,oss,-1);
+ simpleReprGlobs(oss);
+ return oss.str();
}
-const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
+std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
{
- return MEDFileIntField1TSWithoutSDA::TYPE_STR;
+ return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
+std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
{
- return new MEDFileIntFieldMultiTSWithoutSDA(*this);
+ std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
+ ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
+ return ret;
}
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
+/*!
+ * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
+ * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
+ * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
+ */
+std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
{
- return new MEDFileIntFieldMultiTSWithoutSDA;
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
+ if(!content)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
+ std::size_t sz(contentsSplit.size());
+ std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ ret[i]=shallowCpy();
+ ret[i]->_content=contentsSplit[i];
+ }
+ return ret;
}
-MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
+/*!
+ * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
+ * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
+ */
+std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
{
- MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
- ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
- int i=0;
- for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
+ if(!content)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
+ std::size_t sz(contentsSplit.size());
+ std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
{
- const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
- if(eltToConv)
- {
- const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
- if(!eltToConvC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
- ret->setIteration(i,elt);
- }
+ ret[i]=shallowCpy();
+ ret[i]->_content=contentsSplit[i];
}
- return ret.retn();
+ return ret;
}
-//= MEDFileAnyTypeFieldMultiTS
-
/*!
- * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
+ * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
+ * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
*/
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
+std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,loadAll);
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
+ if(!content)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
+ std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
+ std::size_t sz(contentsSplit.size());
+ std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ ret[i]=shallowCpy();
+ ret[i]->_content=contentsSplit[i];
+ }
+ return ret;
}
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
- MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
- ret->loadGlobals(fid);
+ MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
+ if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
+ ret->_content=_content->deepCopy();
+ ret->deepCpyGlobs(*this);
return ret.retn();
}
+MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
+{
+ return _content;
+}
+
/*!
- * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \param [in] fieldName - the name of the field to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- * \throw If there is no field named \a fieldName in the file.
+ * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
+ * delete this field using decrRef() as it is no more needed.
+ * \throw If there is no required time step in \a this field.
*/
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
+MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,fieldName,loadAll);
+ int pos=getPosOfTimeStep(iteration,order);
+ return getTimeStepAtPos(pos);
}
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
+/*!
+ * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
+ * \param [in] time - the time of the time step of interest.
+ * \param [in] eps - a precision used to compare time values.
+ * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
+ * delete this field using decrRef() as it is no more needed.
+ * \throw If there is no required time step in \a this field.
+ */
+MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
- MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
- ret->loadGlobals(fid);
- return ret.retn();
+ int pos=getPosGivenTime(time,eps);
+ return getTimeStepAtPos(pos);
}
/*!
- * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
- * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
+ * The float64 value of time attached to the pair of integers are not considered here.
+ * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
*
- * \warning this is a shallow copy constructor
+ * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
+ * \throw If there is a null pointer in \a vectFMTS.
*/
-MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
+std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
{
- if(!shallowCopyOfContent)
- {
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
- otherPtr->incrRef();
- _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
- }
- else
+ static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
+ std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
+ std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
+ while(!lstFMTS.empty())
{
- _content=other.shallowCpy();
+ std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
+ MEDFileAnyTypeFieldMultiTS *curIt(*it);
+ if(!curIt)
+ throw INTERP_KERNEL::Exception(msg);
+ std::vector< std::pair<int,int> > refIts=curIt->getIterations();
+ std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
+ elt.push_back(curIt); it=lstFMTS.erase(it);
+ while(it!=lstFMTS.end())
+ {
+ curIt=*it;
+ if(!curIt)
+ throw INTERP_KERNEL::Exception(msg);
+ std::vector< std::pair<int,int> > curIts=curIt->getIterations();
+ if(refIts==curIts)
+ { elt.push_back(curIt); it=lstFMTS.erase(it); }
+ else
+ it++;
+ }
+ ret.push_back(elt);
}
-}
-
-MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
-{
- MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
- return ret;
-}
-
-const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
return ret;
}
-std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
-{
- return contentNotNullBase()->getPflsReallyUsed2();
-}
-
-std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
-{
- return contentNotNullBase()->getLocsReallyUsed2();
-}
-
-std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
-{
- return contentNotNullBase()->getPflsReallyUsedMulti2();
-}
-
-std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
-{
- return contentNotNullBase()->getLocsReallyUsedMulti2();
-}
-
-void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
-{
- contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
-}
-
-void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
+/*!
+ * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
+ * All returned instances in a subvector can be safely loaded, rendered along time
+ * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
+ * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
+ * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items).
+ * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
+ * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector.
+ *
+ * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName().
+ * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
+ * \param [out] fsc - A vector having same size than returned vector. It specifies the support comporator of the corresponding vector of MEDFileAnyTypeFieldMultiTS in returned vector of vector.
+ * \return - A vector of vector of objects that contains the same pointers (objects) than thoose in \a vectFMTS except that there are organized differently. So pointers included in returned vector of vector should \b not been dealt by the caller.
+ *
+ * \throw If an element in \a vectFMTS has not only one spatial discretization set.
+ * \throw If an element in \a vectFMTS change of spatial discretization along time.
+ * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
+ * \thorw If some elements in \a vectFMTS do not have the same times steps.
+ * \throw If mesh is null.
+ * \throw If an element in \a vectFMTS is null.
+ * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
+ */
+std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
{
- contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
-}
-
-int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
-{
- return contentNotNullBase()->getNumberOfTS();
-}
-
-void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
-{
- contentNotNullBase()->eraseEmptyTS();
-}
-
-void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
-{
- contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
-}
-
-void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
-{
- contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
-}
-
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
-{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
- MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
- ret->_content=c;
- return ret.retn();
-}
-
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
-{
- MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
- MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
- ret->_content=c;
- return ret.retn();
-}
-
-std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
-{
- return contentNotNullBase()->getIterations();
-}
-
-void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
-{
- for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
- pushBackTimeStep(*it);
-}
-
-void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
-{
- if(!fmts)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
- int nbOfTS(fmts->getNumberOfTS());
- for(int i=0;i<nbOfTS;i++)
- {
- MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
- pushBackTimeStep(elt);
- }
-}
-
-void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
-{
- if(!f1ts)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
- checkCoherencyOfType(f1ts);
- f1ts->incrRef();
- MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
- MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
- c->incrRef();
- MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
- if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
- _content->pushBackTimeStep(cSafe);
- appendGlobs(*f1ts,1e-12);
-}
-
-void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
-{
- contentNotNullBase()->synchronizeNameScope();
-}
-
-int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
-{
- return contentNotNullBase()->getPosOfTimeStep(iteration,order);
-}
-
-int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
-{
- return contentNotNullBase()->getPosGivenTime(time,eps);
-}
-
-int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
-{
- return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
-}
-
-std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
-{
- return contentNotNullBase()->getTypesOfFieldAvailable();
-}
-
-std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTS::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
-{
- return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
-}
-
-std::string MEDFileAnyTypeFieldMultiTS::getName() const
-{
- return contentNotNullBase()->getName();
-}
-
-void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
-{
- contentNotNullBase()->setName(name);
-}
-
-std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
-{
- return contentNotNullBase()->getDtUnit();
-}
-
-void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
-{
- contentNotNullBase()->setDtUnit(dtUnit);
-}
-
-void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
-{
- contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
-}
-
-std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
-{
- return contentNotNullBase()->getTimeSteps(ret1);
-}
-
-std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
-{
- return contentNotNullBase()->getMeshName();
-}
-
-void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
-{
- contentNotNullBase()->setMeshName(newMeshName);
-}
-
-bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
-{
- return contentNotNullBase()->changeMeshNames(modifTab);
-}
-
-const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
-{
- return contentNotNullBase()->getInfo();
-}
-
-bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
-{
- return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
-}
-
-void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
-{
- return contentNotNullBase()->setInfo(info);
-}
-
-int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
-{
- const std::vector<std::string> ret=getInfo();
- return (int)ret.size();
-}
-
-void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
-{
- writeGlobals(fid,*this);
- contentNotNullBase()->writeLL(fid,*this);
-}
-
-/*!
- * This method alloc the arrays and load potentially huge arrays contained in this field.
- * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
- * This method can be also called to refresh or reinit values from a file.
- *
- * \throw If the fileName is not set or points to a non readable MED file.
- */
-void MEDFileAnyTypeFieldMultiTS::loadArrays()
-{
- if(getFileName().empty())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
- contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
-}
-
-/*!
- * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
- * But once data loaded once, this method does nothing.
- *
- * \throw If the fileName is not set or points to a non readable MED file.
- * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
- */
-void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
-{
- if(!getFileName().empty())
- {
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
- contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
- }
-}
-
-/*!
- * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
- * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
- * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
- *
- * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
- */
-void MEDFileAnyTypeFieldMultiTS::unloadArrays()
-{
- contentNotNullBase()->unloadArrays();
-}
-
-/*!
- * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
- * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
- * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
- *
- * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
- */
-void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
-{
- if(!getFileName().empty())
- contentNotNullBase()->unloadArrays();
-}
-
-std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
-{
- std::ostringstream oss;
- contentNotNullBase()->simpleRepr(0,oss,-1);
- simpleReprGlobs(oss);
- return oss.str();
-}
-
-std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
-{
- return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
-}
-
-std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
-{
- std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
- ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
- return ret;
-}
-
-/*!
- * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
- * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
- * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
- */
-std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
- if(!content)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
- std::size_t sz(contentsSplit.size());
- std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
- for(std::size_t i=0;i<sz;i++)
- {
- ret[i]=shallowCpy();
- ret[i]->_content=contentsSplit[i];
- }
- return ret;
-}
-
-/*!
- * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
- * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
- */
-std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
- if(!content)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
- std::size_t sz(contentsSplit.size());
- std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
- for(std::size_t i=0;i<sz;i++)
- {
- ret[i]=shallowCpy();
- ret[i]->_content=contentsSplit[i];
- }
- return ret;
-}
-
-/*!
- * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
- * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
- */
-std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
- if(!content)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
- std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
- std::size_t sz(contentsSplit.size());
- std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
- for(std::size_t i=0;i<sz;i++)
- {
- ret[i]=shallowCpy();
- ret[i]->_content=contentsSplit[i];
- }
- return ret;
-}
-
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
-{
- MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
- if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
- ret->_content=_content->deepCopy();
- ret->deepCpyGlobs(*this);
- return ret.retn();
-}
-
-MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
-{
- return _content;
-}
-
-/*!
- * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
- * delete this field using decrRef() as it is no more needed.
- * \throw If there is no required time step in \a this field.
- */
-MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
-{
- int pos=getPosOfTimeStep(iteration,order);
- return getTimeStepAtPos(pos);
-}
-
-/*!
- * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
- * \param [in] time - the time of the time step of interest.
- * \param [in] eps - a precision used to compare time values.
- * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
- * delete this field using decrRef() as it is no more needed.
- * \throw If there is no required time step in \a this field.
- */
-MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
-{
- int pos=getPosGivenTime(time,eps);
- return getTimeStepAtPos(pos);
-}
-
-/*!
- * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
- * The float64 value of time attached to the pair of integers are not considered here.
- * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
- *
- * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
- * \throw If there is a null pointer in \a vectFMTS.
- */
-std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
-{
- static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
- std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
- std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
- while(!lstFMTS.empty())
- {
- std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
- MEDFileAnyTypeFieldMultiTS *curIt(*it);
- if(!curIt)
- throw INTERP_KERNEL::Exception(msg);
- std::vector< std::pair<int,int> > refIts=curIt->getIterations();
- std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
- elt.push_back(curIt); it=lstFMTS.erase(it);
- while(it!=lstFMTS.end())
- {
- curIt=*it;
- if(!curIt)
- throw INTERP_KERNEL::Exception(msg);
- std::vector< std::pair<int,int> > curIts=curIt->getIterations();
- if(refIts==curIts)
- { elt.push_back(curIt); it=lstFMTS.erase(it); }
- else
- it++;
- }
- ret.push_back(elt);
- }
- return ret;
-}
-
-/*!
- * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
- * All returned instances in a subvector can be safely loaded, rendered along time
- * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
- * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
- * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items).
- * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
- * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector.
- *
- * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName().
- * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
- * \param [out] fsc - A vector having same size than returned vector. It specifies the support comporator of the corresponding vector of MEDFileAnyTypeFieldMultiTS in returned vector of vector.
- * \return - A vector of vector of objects that contains the same pointers (objects) than thoose in \a vectFMTS except that there are organized differently. So pointers included in returned vector of vector should \b not been dealt by the caller.
- *
- * \throw If an element in \a vectFMTS has not only one spatial discretization set.
- * \throw If an element in \a vectFMTS change of spatial discretization along time.
- * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
- * \thorw If some elements in \a vectFMTS do not have the same times steps.
- * \throw If mesh is null.
- * \throw If an element in \a vectFMTS is null.
- * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
- */
-std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
-{
- static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
- if(!mesh)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
- std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
- if(vectFMTS.empty())
- return ret;
- std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
- MEDFileAnyTypeFieldMultiTS *frstElt(*it);
- if(!frstElt)
- throw INTERP_KERNEL::Exception(msg);
- std::size_t i=0;
- std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
- std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
- for(;it!=vectFMTS.end();it++,i++)
- {
- if(!(*it))
- throw INTERP_KERNEL::Exception(msg);
- TypeOfField tof0,tof1;
- if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
- {
- if(tof1!=ON_NODES)
- vectFMTSNotNodes.push_back(*it);
- else
- vectFMTSNodes.push_back(*it);
- }
- else
- vectFMTSNotNodes.push_back(*it);
- }
- std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
- std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
- ret=retCell;
- for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
- {
- i=0;
- bool isFetched(false);
- for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
- {
- if((*it0).empty())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
- if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
- { ret[i].push_back(*it2); isFetched=true; }
- }
- if(!isFetched)
- {
- std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
- MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
- ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
- }
- }
- fsc=cmps;
- return ret;
-}
-
-/*!
- * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES.
- * \param [out] cmps - same size than the returned vector.
- */
-std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
-{
- std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
- std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
- while(!lstFMTS.empty())
- {
- std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
- MEDFileAnyTypeFieldMultiTS *ref(*it);
- std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
- elt.push_back(ref); it=lstFMTS.erase(it);
- MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
- MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
- while(it!=lstFMTS.end())
- {
- MEDFileAnyTypeFieldMultiTS *curIt(*it);
- if(cmp->isEqual(curIt))
- { elt.push_back(curIt); it=lstFMTS.erase(it); }
- else
- it++;
- }
- ret.push_back(elt); cmps.push_back(cmp);
- }
- return ret;
-}
-
-/*!
- * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh.
- * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
- *
- * \throw If \a f0 or \a f1 has not only one spatial discretization set.
- * \throw If \a f0 or \a f1 change of spatial discretization along time.
- * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
- * \thorw If \a f0 and \a f1 do not have the same times steps.
- * \throw If mesh is null.
- * \throw If \a f0 or \a f1 is null.
- * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
- */
-int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
-{
- if(!mesh)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
- if(!f0 || !f1)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
- if(f0->getMeshName()!=mesh->getName())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- if(f1->getMeshName()!=mesh->getName())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- int nts=f0->getNumberOfTS();
- if(nts!=f1->getNumberOfTS())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
- if(nts==0)
- return nts;
- for(int i=0;i<nts;i++)
- {
- MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
- MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
- std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
- if(tofs0.size()!=1 || tofs1.size()!=1)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
- if(i!=0)
- {
- if(tof0!=tofs0[0] || tof1!=tofs1[0])
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
- }
- else
- { tof0=tofs0[0]; tof1=tofs1[0]; }
- if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
- {
- std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- return nts;
-}
-
-/*!
- * Return an extraction of \a this using \a extractDef map to specify the extraction.
- * The keys of \a extractDef is level relative to max ext of \a mm mesh.
- *
- * \return A new object that the caller is responsible to deallocate.
- */
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
-{
- if(!mm)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
- MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
- int nbTS(getNumberOfTS());
- for(int i=0;i<nbTS;i++)
- {
- MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
- MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
- fmtsOut->pushBackTimeStep(f1tsOut);
- }
- return fmtsOut.retn();
-}
-
-template<class T>
-MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
-{
- MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
- if(f1tss.empty())
- throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
- std::size_t sz(f1tss.size()),i(0);
- std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
- for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
- {
- typename MLFieldTraits<T>::F1TSType const *elt(*it);
- if(!elt)
- throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
- f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
- }
- typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
- if(!retc)
- throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
- retc->aggregate(f1tsw,dts);
- ret->setDtUnit(f1tss[0]->getDtUnit());
- return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
-}
-
-template<class T>
-MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
-{
- MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
- if(fmtss.empty())
- throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
- std::size_t sz(fmtss.size());
- for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
- {
- typename MLFieldTraits<T>::FMTSType const *elt(*it);
- if(!elt)
- throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
- }
- int nbTS(fmtss[0]->getNumberOfTS());
- for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
- if((*it)->getNumberOfTS()!=nbTS)
- throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
- for(int iterTS=0;iterTS<nbTS;iterTS++)
- {
- std::size_t i(0);
- std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
- std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
- for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
- { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
- MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
- ret->pushBackTimeStep(f1ts);
- ret->setDtUnit(f1ts->getDtUnit());
- }
- return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
-}
-
-/*!
- * \a dts and \a ftmss are expected to have same size.
- */
-MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
-{
- if(fmtss.empty())
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
- std::size_t sz(fmtss.size());
- std::vector<const MEDFileFieldMultiTS *> fmtss1;
- std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
- for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
- {
- if(!(*it))
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
- const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
- if(elt1)
- {
- fmtss1.push_back(elt1);
- continue;
- }
- const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
- if(elt2)
- {
- fmtss2.push_back(elt2);
- continue;
- }
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
- }
- if(fmtss1.size()!=sz && fmtss2.size()!=sz)
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
- if(fmtss1.size()==sz)
- return AggregateHelperFMTS<double>(fmtss1,dts);
- if(fmtss2.size()!=sz)
- return AggregateHelperFMTS<int>(fmtss2,dts);
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
-}
-
-MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
-{
- return new MEDFileAnyTypeFieldMultiTSIterator(this);
-}
-
-//= MEDFileFieldMultiTS
-
-/*!
- * Returns a new empty instance of MEDFileFieldMultiTS.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
-{
- return new MEDFileFieldMultiTS;
-}
-
-/*!
- * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- */
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,loadAll);
-}
-
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
-{
- MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
-}
-
-/*!
- * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \param [in] fieldName - the name of the field to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- * \throw If there is no field named \a fieldName in the file.
- */
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,fieldName,loadAll);
-}
-
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
-{
- MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
-}
-
-/*!
- * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
- * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
- *
- * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
- * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
- * \warning this is a shallow copy constructor
- * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
- * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
-{
- return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
-}
-
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
-{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
- MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
-}
-
-MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
-{
- return new MEDFileFieldMultiTS(*this);
-}
-
-void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
-{
- if(!f1ts)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
- const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
- if(!f1tsC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
-}
-
-/*!
- * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
- * following the given input policy.
- *
- * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
- * By default (true) the globals are deeply copied.
- * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
- */
-MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
-{
- MCAuto<MEDFileIntFieldMultiTS> ret;
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
- if(content)
- {
- const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
- if(!contc)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
- MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
- ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
- }
- else
- ret=MEDFileIntFieldMultiTS::New();
- if(isDeepCpyGlobs)
- ret->deepCpyGlobs(*this);
- else
- ret->shallowCpyGlobs(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
- * \param [in] pos - a time step id.
- * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
- * delete this field using decrRef() as it is no more needed.
- * \throw If \a pos is not a valid time step id.
- */
-MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
- if(!item)
- {
- std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
- if(itemC)
- {
- MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
- ret->shallowCpyGlobs(*this);
- return ret.retn();
- }
- std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
- throw INTERP_KERNEL::Exception(oss.str());
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
- * mesh entities of a given dimension of the first mesh in MED file.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
- * the top level cells of the first mesh in MED file.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
- * method should be called (getFieldOnMeshAtLevel for example).
- * But for normal usage of field in MED file world this method is the most efficient to fetch data.
- *
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] mesh - the mesh the field is lying on
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
- * a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
- * given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the new field.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
- * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
- * This method is useful for MED2 file format when field on different mesh was autorized.
- */
-MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
- MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
- return ret.retn();
-}
-
-/*!
- * Returns values and a profile of the field of a given type, of a given time step,
- * lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the field.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
- * field of interest lies on. If the field lies on all entities of the given
- * dimension, all ids in \a pfl are zero. The caller is to delete this array
- * using decrRef() as it is no more needed.
- * \param [in] glob - the global data storing profiles and localization.
- * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
- * field. The caller is to delete this array using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
- MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
- return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
-}
-
-const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
- const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
- return ret;
-}
-
-MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
-{
- MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
- MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
+ static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
+ std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
+ if(vectFMTS.empty())
+ return ret;
+ std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
+ MEDFileAnyTypeFieldMultiTS *frstElt(*it);
+ if(!frstElt)
+ throw INTERP_KERNEL::Exception(msg);
+ std::size_t i=0;
+ std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
+ std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
+ for(;it!=vectFMTS.end();it++,i++)
+ {
+ if(!(*it))
+ throw INTERP_KERNEL::Exception(msg);
+ TypeOfField tof0,tof1;
+ if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
+ {
+ if(tof1!=ON_NODES)
+ vectFMTSNotNodes.push_back(*it);
+ else
+ vectFMTSNodes.push_back(*it);
+ }
+ else
+ vectFMTSNotNodes.push_back(*it);
+ }
+ std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
+ std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
+ ret=retCell;
+ for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
+ {
+ i=0;
+ bool isFetched(false);
+ for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
+ {
+ if((*it0).empty())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
+ if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
+ { ret[i].push_back(*it2); isFetched=true; }
+ }
+ if(!isFetched)
+ {
+ std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
+ MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
+ ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
+ }
+ }
+ fsc=cmps;
return ret;
}
/*!
- * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
- * the given field is checked if its elements are sorted suitable for writing to MED file
- * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this.
- * \throw If the name of \a field is empty.
- * \throw If the data array of \a field is not set.
- * \throw If existing time steps have different name or number of components than \a field.
- * \throw If the underlying mesh of \a field has no name.
- * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
+ * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES.
+ * \param [out] cmps - same size than the returned vector.
*/
-void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
+std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
{
- const DataArrayDouble *arr=0;
- if(field)
- arr=field->getArray();
- contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
+ std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
+ std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
+ while(!lstFMTS.empty())
+ {
+ std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
+ MEDFileAnyTypeFieldMultiTS *ref(*it);
+ std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
+ elt.push_back(ref); it=lstFMTS.erase(it);
+ MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
+ MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
+ while(it!=lstFMTS.end())
+ {
+ MEDFileAnyTypeFieldMultiTS *curIt(*it);
+ if(cmp->isEqual(curIt))
+ { elt.push_back(curIt); it=lstFMTS.erase(it); }
+ else
+ it++;
+ }
+ ret.push_back(elt); cmps.push_back(cmp);
+ }
+ return ret;
}
/*!
- * Adds a MEDCouplingFieldDouble to \a this as another time step.
- * The mesh support of input parameter \a field is ignored here, it can be NULL.
- * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
- * and \a profile.
+ * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh.
+ * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
*
- * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
- * A new profile is added only if no equal profile is missing.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
- * \param [in] mesh - the supporting mesh of \a field.
- * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
- * \param [in] profile - ids of mesh entities on which corresponding field values lie.
- * \throw If either \a field or \a mesh or \a profile has an empty name.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If the data array of \a field is not set.
- * \throw If the data array of \a this is already allocated but has different number of
- * components than \a field.
- * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
- * \sa setFieldNoProfileSBT()
+ * \throw If \a f0 or \a f1 has not only one spatial discretization set.
+ * \throw If \a f0 or \a f1 change of spatial discretization along time.
+ * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
+ * \thorw If \a f0 and \a f1 do not have the same times steps.
+ * \throw If mesh is null.
+ * \throw If \a f0 or \a f1 is null.
+ * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
*/
-void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
-{
- const DataArrayDouble *arr=0;
- if(field)
- arr=field->getArray();
- contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
-}
-
-MEDFileFieldMultiTS::MEDFileFieldMultiTS()
-{
- _content=new MEDFileFieldMultiTSWithoutSDA;
-}
-
-MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
-{
-}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-
-MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
-{
-}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-
-MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
-{
-}
-
-std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
-{
- return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
-}
-
-DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
-{
- return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
-}
-
-DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
-{
- return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
-}
-
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
-{
- return MEDFileFieldMultiTS::New();
-}
-
-//= MEDFileAnyTypeFieldMultiTSIterator
-
-MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
+int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
{
- if(fmts)
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
+ if(!f0 || !f1)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
+ if(f0->getMeshName()!=mesh->getName())
{
- fmts->incrRef();
- _nb_iter=fmts->getNumberOfTS();
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str());
}
-}
-
-MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator()
-{
-}
-
-MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
-{
- if(_iter_id<_nb_iter)
+ if(f1->getMeshName()!=mesh->getName())
{
- MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
- if(fmts)
- return fmts->getTimeStepAtPos(_iter_id++);
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ int nts=f0->getNumberOfTS();
+ if(nts!=f1->getNumberOfTS())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
+ if(nts==0)
+ return nts;
+ for(int i=0;i<nts;i++)
+ {
+ MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
+ MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
+ std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
+ if(tofs0.size()!=1 || tofs1.size()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
+ if(i!=0)
+ {
+ if(tof0!=tofs0[0] || tof1!=tofs1[0])
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
+ }
else
- return 0;
+ { tof0=tofs0[0]; tof1=tofs1[0]; }
+ if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
+ {
+ std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
}
- else
- return 0;
-}
-
-//= MEDFileIntFieldMultiTS
-
-/*!
- * Returns a new empty instance of MEDFileFieldMultiTS.
- * \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
-{
- return new MEDFileIntFieldMultiTS;
+ return nts;
}
-/*!
- * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- */
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
+template<class T>
+MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,loadAll);
+ MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
+ if(f1tss.empty())
+ throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
+ std::size_t sz(f1tss.size()),i(0);
+ std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
+ for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
+ {
+ typename MLFieldTraits<T>::F1TSType const *elt(*it);
+ if(!elt)
+ throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
+ f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
+ }
+ typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
+ if(!retc)
+ throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
+ retc->aggregate(f1tsw,dts);
+ ret->setDtUnit(f1tss[0]->getDtUnit());
+ return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
}
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
+template<class T>
+MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
{
- MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
+ MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
+ if(fmtss.empty())
+ throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
+ std::size_t sz(fmtss.size());
+ for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
+ {
+ typename MLFieldTraits<T>::FMTSType const *elt(*it);
+ if(!elt)
+ throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
+ }
+ int nbTS(fmtss[0]->getNumberOfTS());
+ for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
+ if((*it)->getNumberOfTS()!=nbTS)
+ throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
+ for(int iterTS=0;iterTS<nbTS;iterTS++)
+ {
+ std::size_t i(0);
+ std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
+ std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
+ for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
+ { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
+ MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
+ ret->pushBackTimeStep(f1ts);
+ ret->setDtUnit(f1ts->getDtUnit());
+ }
+ return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
}
/*!
- * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
- * that has been read from a specified MED file.
- * \param [in] fileName - the name of the MED file to read.
- * \param [in] fieldName - the name of the field to read.
- * \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- * \throw If reading the file fails.
- * \throw If there is no field named \a fieldName in the file.
+ * \a dts and \a ftmss are expected to have same size.
*/
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
+MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- return New(fid,fieldName,loadAll);
+ if(fmtss.empty())
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
+ std::size_t sz(fmtss.size());
+ std::vector<const MEDFileFieldMultiTS *> fmtss1;
+ std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
+ for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
+ {
+ if(!(*it))
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
+ const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
+ if(elt1)
+ {
+ fmtss1.push_back(elt1);
+ continue;
+ }
+ const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
+ if(elt2)
+ {
+ fmtss2.push_back(elt2);
+ continue;
+ }
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
+ }
+ if(fmtss1.size()!=sz && fmtss2.size()!=sz)
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
+ if(fmtss1.size()==sz)
+ return AggregateHelperFMTS<double>(fmtss1,dts);
+ if(fmtss2.size()!=sz)
+ return AggregateHelperFMTS<int>(fmtss2,dts);
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
}
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
+MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
{
- MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
+ return new MEDFileAnyTypeFieldMultiTSIterator(this);
}
-/*!
- * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
- * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
- *
- * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
- * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
- * \warning this is a shallow copy constructor
- * \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
- * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
- * \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
- * is to delete this field using decrRef() as it is no more needed.
- */
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
-{
- return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
-}
+//= MEDFileFieldMultiTS
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
+MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
{
- MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
- INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
- MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
- ret->contentNotNull();//to check that content type matches with \a this type.
- return ret.retn();
+ return new MEDFileFieldMultiTS(*this);
}
/*!
- * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
+ * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
* following the given input policy.
*
* \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
* By default (true) the globals are deeply copied.
- * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
+ * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
*/
-MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
+MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
{
- MCAuto<MEDFileFieldMultiTS> ret;
+ MCAuto<MEDFileIntFieldMultiTS> ret;
const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
if(content)
{
- const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
+ const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
if(!contc)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
- MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
- ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
+ MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
+ ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
}
else
- ret=MEDFileFieldMultiTS::New();
+ ret=MEDFileIntFieldMultiTS::New();
if(isDeepCpyGlobs)
ret->deepCpyGlobs(*this);
else
return ret.retn();
}
-MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
-{
- return new MEDFileIntFieldMultiTS(*this);
-}
-
-void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
-{
- if(!f1ts)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
- const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
- if(!f1tsC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
-}
-
-/*!
- * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
- * method should be called (getFieldOnMeshAtLevel for example).
- * But for normal usage of field in MED file world this method is the most efficient to fetch data.
- *
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] mesh - the mesh the field is lying on
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
- * caller is to delete this field using decrRef() as it is no more needed.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
- MCAuto<DataArray> arrOut;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
- return ret2.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
- * mesh entities of a given dimension of the first mesh in MED file.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
- MCAuto<DataArray> arr;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
- return ret2.retn();
-}
-
-/*!
- * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
- * the top level cells of the first mesh in MED file.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If the MED file is not readable.
- * \throw If there is no mesh in the MED file.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
+MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
+try:MEDFileTemplateFieldMultiTS<double>(fid,loadAll,ms)
{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
- MCAuto<DataArray> arr;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
- return ret2.retn();
}
+catch(INTERP_KERNEL::Exception& e)
+{ throw e; }
-/*!
- * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
- * a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of interest.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
+MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+try:MEDFileTemplateFieldMultiTS<double>(fid,fieldName,loadAll,ms,entities)
{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
- MCAuto<DataArray> arr;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
- return ret2.retn();
}
+catch(INTERP_KERNEL::Exception& e)
+{ throw e; }
-/*!
- * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
- * given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the new field.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] mesh - the supporting mesh.
- * \param [out] arrOut - the DataArrayInt containing values of field.
- * \param [in] renumPol - specifies how to permute values of the result field according to
- * the optional numbers of cells and nodes, if any. The valid values are
- * - 0 - do not permute.
- * - 1 - permute cells.
- * - 2 - permute nodes.
- * - 3 - permute cells and nodes.
- *
- * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
- * caller is to delete this field using decrRef() as it is no more needed.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
+MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<double>(other,shallowCopyOfContent)
{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
- MCAuto<DataArray> arr;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
- return ret2.retn();
}
-/*!
- * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
- * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
- * This method is useful for MED2 file format when field on different mesh was autorized.
- */
-MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
+std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
- const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
- MCAuto<DataArray> arr;
- MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
- MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
- return ret2.retn();
+ return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
}
-/*!
- * Returns values and a profile of the field of a given type, of a given time step,
- * lying on a given support.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] type - a spatial discretization of the field.
- * \param [in] iteration - the iteration number of a required time step.
- * \param [in] order - the iteration order number of required time step.
- * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
- * \param [in] mesh - the supporting mesh.
- * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
- * field of interest lies on. If the field lies on all entities of the given
- * dimension, all ids in \a pfl are zero. The caller is to delete this array
- * using decrRef() as it is no more needed.
- * \param [in] glob - the global data storing profiles and localization.
- * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
- * field. The caller is to delete this array using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If no field of \a this is lying on \a mesh.
- * \throw If no field values of the required parameters are available.
- */
-DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
-{
- const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
- const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
- if(!myF1TSC)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
- MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
- return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
-}
+//= MEDFileAnyTypeFieldMultiTSIterator
-/*!
- * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
- * \param [in] pos - a time step id.
- * \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
- * delete this field using decrRef() as it is no more needed.
- * \throw If \a pos is not a valid time step id.
- */
-MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
+MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
{
- const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
- if(!item)
- {
- std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
- if(itemC)
+ if(fmts)
{
- MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
- ret->shallowCpyGlobs(*this);
- return ret.retn();
+ fmts->incrRef();
+ _nb_iter=fmts->getNumberOfTS();
}
- std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
- throw INTERP_KERNEL::Exception(oss.str());
-}
-
-/*!
- * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
- * the given field is checked if its elements are sorted suitable for writing to MED file
- * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this.
- * \throw If the name of \a field is empty.
- * \throw If the data array of \a field is not set.
- * \throw If existing time steps have different name or number of components than \a field.
- * \throw If the underlying mesh of \a field has no name.
- * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
- */
-void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
-{
- MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
- contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
-}
-
-/*!
- * Adds a MEDCouplingFieldDouble to \a this as another time step.
- * The mesh support of input parameter \a field is ignored here, it can be NULL.
- * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
- * and \a profile.
- *
- * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
- * A new profile is added only if no equal profile is missing.
- * For more info, see \ref AdvMEDLoaderAPIFieldRW
- * \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
- * \param [in] arrOfVals - the values of the field \a field used.
- * \param [in] mesh - the supporting mesh of \a field.
- * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
- * \param [in] profile - ids of mesh entities on which corresponding field values lie.
- * \throw If either \a field or \a mesh or \a profile has an empty name.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
- * \throw If the data array of \a field is not set.
- * \throw If the data array of \a this is already allocated but has different number of
- * components than \a field.
- * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
- * \sa setFieldNoProfileSBT()
- */
-void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
-{
- MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
- contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
-}
-
-const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
-{
- const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
- const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
- return ret;
-}
-
-MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
-{
- MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
- if(!pt)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
- MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
- if(!ret)
- throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
- return ret;
-}
-
-MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
-{
- _content=new MEDFileIntFieldMultiTSWithoutSDA;
-}
-
-MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
-{
-}
-
-MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
-try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
-{
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
-try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
+MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator()
{
}
-catch(INTERP_KERNEL::Exception& e)
-{ throw e; }
-DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
+MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
{
- return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
+ if(_iter_id<_nb_iter)
+ {
+ MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
+ if(fmts)
+ return fmts->getTimeStepAtPos(_iter_id++);
+ else
+ return 0;
+ }
+ else
+ return 0;
}
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
-{
- return MEDFileIntFieldMultiTS::New();
-}
+//= MEDFileIntFieldMultiTS
//= MEDFileFields
_fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
break;
}
+ case MED_NODE://6432
+ {
+ _fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
+ break;
+ }
default:
{
- std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
+ std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
throw INTERP_KERNEL::Exception(oss.str());
}
}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#ifndef __MEDFILEFIELD_HXX__
#define __MEDFILEFIELD_HXX__
std::size_t getHeapMemorySizeWithoutChildren() const;
std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
MEDFileFieldPerMeshPerTypePerDisc *deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const;
- void assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob);
+ void assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob);
void getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const;
void writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const;
const MEDFileFieldPerMeshPerTypeCommon *getFather() const;
public:
std::size_t getHeapMemorySizeWithoutChildren() const;
std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
- void assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob);
- void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob);
+ void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
const MEDFileFieldPerMesh *getFather() const;
void loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc);
void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc);
virtual void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const = 0;
protected:
void deepCopyElements();
- std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells);
- std::vector<int> addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells);
- std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells);
- std::vector<int> addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells);
+ std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells);
+ std::vector<int> addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells);
+ std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells);
+ std::vector<int> addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells);
private:
MEDFileFieldPerMesh *_father;
protected:
MEDFileFieldPerMesh *deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const;
void simpleRepr(int bkOffset,std::ostream& oss, int id) const;
void copyTinyInfoFrom(const MEDCouplingMesh *mesh);
- void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob);
- void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob);
+ void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
void loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc);
void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc);
void writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const;
MEDLOADER_EXPORT void setInfo(const std::vector<std::string>& infos);
MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
- MEDLOADER_EXPORT int copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr);
- MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
- MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ MEDLOADER_EXPORT int copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr);
+ MEDLOADER_EXPORT void setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
+ MEDLOADER_EXPORT void setFieldProfile(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc);
MEDLOADER_EXPORT virtual void simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const;
MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TSWithoutSDA *deepCopy() const = 0;
MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TSWithoutSDA *shallowCpy() const = 0;
{
protected:
MEDFileField1TSTemplateWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order):MEDFileAnyTypeField1TSWithoutSDA(fieldName,meshName,csit,iteration,order) { }
- MEDFileField1TSTemplateWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA() { }
+ MEDFileField1TSTemplateWithoutSDA() { }
public:
MEDLOADER_EXPORT void setArray(DataArray *arr);
MEDLOADER_EXPORT DataArray *createNewEmptyDataArrayInstance() const;
MEDLOADER_EXPORT typename Traits<T>::ArrayType *getOrCreateAndGetArrayTemplate();
MEDLOADER_EXPORT typename Traits<T>::ArrayType const *getOrCreateAndGetArrayTemplate() const;
MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArrayTemplate() const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArrayTemplateExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
MEDLOADER_EXPORT DataArray *getOrCreateAndGetArray();
MEDLOADER_EXPORT const DataArray *getOrCreateAndGetArray() const;
MEDLOADER_EXPORT DataArray *getUndergroundDataArray() const;
public:
MEDLOADER_EXPORT const char *getTypeStr() const;
MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
- MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
MEDLOADER_EXPORT std::vector< std::vector<DataArrayDouble *> > getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
MEDLOADER_EXPORT static void CheckMeshDimRel(int meshDimRelToMax);
MEDLOADER_EXPORT static std::vector<int> CheckSBTMesh(const MEDCouplingMesh *mesh);
static const char TYPE_STR[];
};
+ template<class T>
+ class MEDFileField1TSNDTemplateWithoutSDA : public MEDFileField1TSTemplateWithoutSDA<T>
+ {
+ public:
+ MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *convertToDouble() const;
+ protected:
+ MEDFileField1TSNDTemplateWithoutSDA() { }
+ MEDFileField1TSNDTemplateWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<T>(fieldName,meshName,csit,iteration,order) { }
+ };
+
/*!
* SDA is for Shared Data Arrays such as profiles.
*/
- class MEDFileIntField1TSWithoutSDA : public MEDFileField1TSTemplateWithoutSDA<int>
+ class MEDFileIntField1TSWithoutSDA : public MEDFileField1TSNDTemplateWithoutSDA<int>
{
public:
MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA();
MEDLOADER_EXPORT const char *getTypeStr() const;
MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
- MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *convertToDouble() const;
protected:
MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos);
public:
MEDLOADER_EXPORT static const char TYPE_STR[];
};
+ /*!
+ * SDA is for Shared Data Arrays such as profiles.
+ */
+ class MEDFileFloatField1TSWithoutSDA : public MEDFileField1TSNDTemplateWithoutSDA<float>
+ {
+ public:
+ MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA();
+ MEDLOADER_EXPORT static MEDFileFloatField1TSWithoutSDA *New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos);
+ MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA *deepCopy() const;
+ MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA *shallowCpy() const;
+ MEDLOADER_EXPORT const char *getTypeStr() const;
+ MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ MEDLOADER_EXPORT DataArrayFloat *getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ protected:
+ MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos);
+ public:
+ MEDLOADER_EXPORT static const char TYPE_STR[];
+ };
+
/*!
* User class.
*/
MEDLOADER_EXPORT int getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const;
MEDLOADER_EXPORT void convertMedBallIntoClassic();
MEDLOADER_EXPORT void makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl);
+ MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const = 0;
+ MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TS *shallowCpy() const = 0;
public:
MEDLOADER_EXPORT void loadArrays();
MEDLOADER_EXPORT void loadArraysIfNecessary();
MEDLOADER_EXPORT std::vector< MCAuto< MEDFileAnyTypeField1TS > > splitMultiDiscrPerGeoTypes() const;
MEDLOADER_EXPORT MEDFileAnyTypeField1TS *deepCopy() const;
MEDLOADER_EXPORT int copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr);
- MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TS *shallowCpy() const = 0;
+ MEDLOADER_EXPORT int copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr);
public:
//! underground method see MEDFileField1TSWithoutSDA::setProfileNameOnLeaf
MEDLOADER_EXPORT void setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob=false);
public:
MEDLOADER_EXPORT static int LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName);
MEDLOADER_EXPORT static int LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName);
- public:
- MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const = 0;
public:
MEDLOADER_EXPORT virtual med_field_type getMEDFileFieldType() const = 0;
MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *contentNotNullBase();
class MEDFileIntField1TS;
+ template<class T>
+ class MEDFileTemplateField1TS : public MEDFileAnyTypeField1TS
+ {
+ public:
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New();
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(const std::string& fileName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(med_idt fid, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(DataArrayByte *db) { return BuildFromMemoryChunk<typename MLFieldTraits<T>::F1TSType>(db); }
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::F1TSType *New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent);
+ public:
+ MEDLOADER_EXPORT static typename Traits<T>::ArrayType *ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr);
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArray() const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ MEDLOADER_EXPORT static MCAuto<typename Traits<T>::FieldType> SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr);
+ MEDLOADER_EXPORT static MCAuto<MEDCouplingFieldDouble> ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f);
+ public:
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *field(const MEDFileMesh *mesh) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const;
+ MEDLOADER_EXPORT void setFieldNoProfileSBT(const typename Traits<T>::FieldType *field);
+ MEDLOADER_EXPORT void setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
+ MEDLOADER_EXPORT typename MLFieldTraits<T>::F1TSType *extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
+ MEDLOADER_EXPORT MEDFileAnyTypeField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const { return this->extractPartImpl(extractDef,mm); }
+ protected:
+ ~MEDFileTemplateField1TS() { }
+ MEDFileTemplateField1TS();
+ MEDFileTemplateField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,loadAll,ms) { }
+ MEDFileTemplateField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms) { }
+ MEDFileTemplateField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms) { }
+ MEDFileTemplateField1TS(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent) { }
+ const typename MLFieldTraits<T>::F1TSWSDAType *contentNotNull() const;
+ typename MLFieldTraits<T>::F1TSWSDAType *contentNotNull();
+ };
+
/*!
* User class.
*/
- class MEDFileField1TS : public MEDFileAnyTypeField1TS
+ class MEDFileField1TS : public MEDFileTemplateField1TS<double>
{
+ friend class MEDFileTemplateField1TS<double>;
public:
- MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileField1TS>(db); }
- MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileField1TS *New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent);
- MEDLOADER_EXPORT static MEDFileField1TS *New();
MEDLOADER_EXPORT MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const;
- //
- MEDLOADER_EXPORT MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT DataArrayDouble *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
- //
- MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field);
- MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
- // direct forwarding to MEDFileField1TSWithoutSDA instance _content
public:
MEDLOADER_EXPORT MEDFileField1TS *shallowCpy() const;
- MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArray() const;
- MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
-
MEDLOADER_EXPORT std::vector< std::vector<DataArrayDouble *> > getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
- std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
- public:
- MEDLOADER_EXPORT static void SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr);
- MEDLOADER_EXPORT static DataArrayDouble *ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr);
+ std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
public:
- MEDLOADER_EXPORT MEDFileField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
private:
med_field_type getMEDFileFieldType() const { return MED_FLOAT64; }
- const MEDFileField1TSWithoutSDA *contentNotNull() const;
- MEDFileField1TSWithoutSDA *contentNotNull();
private:
~MEDFileField1TS() { }
MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms);
MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms);
MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms);
MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent);
- MEDFileField1TS();
+ MEDFileField1TS() { }
};
- class MEDFileIntField1TS : public MEDFileAnyTypeField1TS
+ template<class T>
+ class MEDFileNDTemplateField1TS : public MEDFileTemplateField1TS<T>
{
public:
- MEDLOADER_EXPORT static MEDFileIntField1TS *New();
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileIntField1TS>(db); }
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntField1TS *New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent);
MEDLOADER_EXPORT MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const;
- MEDLOADER_EXPORT MEDFileIntField1TS *shallowCpy() const;
- //
- MEDLOADER_EXPORT MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
- //
- MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldInt *field);
- MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
- MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray() const;
+ protected:
+ ~MEDFileNDTemplateField1TS() { }
+ MEDFileNDTemplateField1TS() { }
+ MEDFileNDTemplateField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileTemplateField1TS<T>(fid,loadAll,ms) { }
+ MEDFileNDTemplateField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms):MEDFileTemplateField1TS<T>(fid,fieldName,loadAll,ms) { }
+ MEDFileNDTemplateField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms):MEDFileTemplateField1TS<T>(fid,fieldName,iteration,order,loadAll,ms) { }
+ MEDFileNDTemplateField1TS(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent):MEDFileTemplateField1TS<T>(other,shallowCopyOfContent) { }
+ };
+
+ class MEDFileIntField1TS : public MEDFileNDTemplateField1TS<int>
+ {
+ friend class MEDFileTemplateField1TS<int>;
public:
- MEDLOADER_EXPORT static DataArrayInt *ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr);
- MEDLOADER_EXPORT static MCAuto<MEDCouplingFieldInt> SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr);
- MEDLOADER_EXPORT static MCAuto<MEDCouplingFieldDouble> ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f);
+ MEDLOADER_EXPORT MEDFileIntField1TS *shallowCpy() const { return new MEDFileIntField1TS(*this); }
public:
- MEDLOADER_EXPORT MEDFileIntField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
+ MEDLOADER_EXPORT static MCAuto<MEDCouplingFieldDouble> ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f);
private:
med_field_type getMEDFileFieldType() const { return MED_INT32; }
- const MEDFileIntField1TSWithoutSDA *contentNotNull() const;
- MEDFileIntField1TSWithoutSDA *contentNotNull();
private:
~MEDFileIntField1TS() { }
- MEDFileIntField1TS();
- MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms);
- MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms);
- MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms);
- MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent);
+ MEDFileIntField1TS() { }
+ MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<int>(fid,loadAll,ms) { }
+ MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<int>(fid,fieldName,loadAll,ms) { }
+ MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<int>(fid,fieldName,iteration,order,loadAll,ms) { }
+ /*!
+ * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
+ * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ *
+ * \warning this is a shallow copy constructor
+ */
+ MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileNDTemplateField1TS<int>(other,shallowCopyOfContent) { }
+ };
+
+ class MEDFileFloatField1TS : public MEDFileNDTemplateField1TS<float>
+ {
+ friend class MEDFileTemplateField1TS<float>;
+ private:
+ med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432
+ MEDLOADER_EXPORT MEDFileFloatField1TS *shallowCpy() const { return new MEDFileFloatField1TS(*this); }
+ private:
+ ~MEDFileFloatField1TS() { }
+ MEDFileFloatField1TS() { }
+ MEDFileFloatField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<float>(fid,loadAll,ms) { }
+ MEDFileFloatField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<float>(fid,fieldName,loadAll,ms) { }
+ MEDFileFloatField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateField1TS<float>(fid,fieldName,iteration,order,loadAll,ms) { }
+ /*!
+ * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
+ * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ *
+ * \warning this is a shallow copy constructor
+ */
+ MEDFileFloatField1TS(const MEDFileFloatField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileNDTemplateField1TS<float>(other,shallowCopyOfContent) { }
};
class MEDFileAnyTypeFieldMultiTSWithoutSDA : public RefCountObject, public MEDFileFieldNameScope
class MEDFileIntFieldMultiTSWithoutSDA;
- class MEDFileFieldMultiTSWithoutSDA : public MEDFileAnyTypeFieldMultiTSWithoutSDA
+ template<class T>
+ class MEDFileTemplateFieldMultiTSWithoutSDA : public MEDFileAnyTypeFieldMultiTSWithoutSDA
{
public:
- MEDLOADER_EXPORT static MEDFileFieldMultiTSWithoutSDA *New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
- MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSWSDAType *New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
MEDLOADER_EXPORT const char *getTypeStr() const;
- MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const;
MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *createNew() const;
+ MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *createNew1TSWithoutSDAEmptyInstance() const;
+ protected:
+ MEDFileTemplateFieldMultiTSWithoutSDA() { }
+ MEDFileTemplateFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName) { }
+ /** \param [in] fieldId field id in C mode */
+ MEDFileTemplateFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities) { }
+ MEDFileTemplateFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
+ void checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const;
+ };
+
+ class MEDFileFieldMultiTSWithoutSDA : public MEDFileTemplateFieldMultiTSWithoutSDA<double>
+ {
+ friend class MEDFileTemplateFieldMultiTSWithoutSDA<double>;
+ public:
+ MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTSWithoutSDA<double>(fid,fieldId,loadAll,ms,entities) { }
MEDLOADER_EXPORT std::vector< std::vector<DataArrayDouble *> > getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
MEDLOADER_EXPORT MEDFileIntFieldMultiTSWithoutSDA *convertToInt() const;
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileFieldMultiTSWithoutSDA(*this); }
protected:
- MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName);
- MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
+ MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileTemplateFieldMultiTSWithoutSDA<double>(fieldName,meshName) { }
+ MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTSWithoutSDA<double>(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
med_field_type getMEDFileFieldType() const { return MED_FLOAT64; }
- MEDFileAnyTypeField1TSWithoutSDA *createNew1TSWithoutSDAEmptyInstance() const;
- void checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const;
public:
- MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA();
+ MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA() { }
};
- class MEDFileIntFieldMultiTSWithoutSDA : public MEDFileAnyTypeFieldMultiTSWithoutSDA
+ template<class T>
+ class MEDFileNDTemplateFieldMultiTSWithoutSDA : public MEDFileTemplateFieldMultiTSWithoutSDA<T>
{
public:
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTSWithoutSDA *New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
- MEDLOADER_EXPORT MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
- MEDLOADER_EXPORT const char *getTypeStr() const;
- MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const;
- MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *createNew() const;
MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA *convertToDouble() const;
protected:
- MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName);
- MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
+ MEDFileNDTemplateFieldMultiTSWithoutSDA() { }
+ MEDFileNDTemplateFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTSWithoutSDA<T>(fid,fieldId,loadAll,ms,entities) { }
+ MEDFileNDTemplateFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileTemplateFieldMultiTSWithoutSDA<T>(fieldName,meshName) { }
+ MEDFileNDTemplateFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTSWithoutSDA<T>(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
+ };
+
+ class MEDFileIntFieldMultiTSWithoutSDA : public MEDFileNDTemplateFieldMultiTSWithoutSDA<int>
+ {
+ friend class MEDFileTemplateFieldMultiTSWithoutSDA<int>;
+ public:
+ MEDLOADER_EXPORT MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA<int>(fid,fieldId,loadAll,ms,entities) { }
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileIntFieldMultiTSWithoutSDA(*this); }
+ protected:
+ MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA<int>(fieldName,meshName) { }
+ MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA<int>(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
med_field_type getMEDFileFieldType() const { return MED_INT32; }
- MEDFileAnyTypeField1TSWithoutSDA *createNew1TSWithoutSDAEmptyInstance() const;
- void checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const;
public:
- MEDLOADER_EXPORT MEDFileIntFieldMultiTSWithoutSDA();
+ MEDLOADER_EXPORT MEDFileIntFieldMultiTSWithoutSDA() { }
+ };
+
+ class MEDFileFloatFieldMultiTSWithoutSDA : public MEDFileNDTemplateFieldMultiTSWithoutSDA<float>
+ {
+ friend class MEDFileTemplateFieldMultiTSWithoutSDA<float>;
+ public:
+ MEDLOADER_EXPORT MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA<float>(fid,fieldId,loadAll,ms,entities) { }
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileFloatFieldMultiTSWithoutSDA(*this); }
+ protected:
+ MEDFileFloatFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA<float>(fieldName,meshName) { }
+ MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA<float>(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
+ med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432
+ public:
+ MEDLOADER_EXPORT MEDFileFloatFieldMultiTSWithoutSDA() { }
};
class MEDFileAnyTypeFieldMultiTSIterator;
MEDLOADER_EXPORT MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> getContent();
public:
MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTS *buildNewEmpty() const = 0;
- MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
+ MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const = 0;
MEDLOADER_EXPORT static MCAuto<MEDFileAnyTypeFieldMultiTS> Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts);
public:
MEDLOADER_EXPORT std::vector<std::string> getPflsReallyUsed() const;
MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> _content;
};
+ template<class T>
+ class MEDFileTemplateFieldMultiTS : public MEDFileAnyTypeFieldMultiTS
+ {
+ public:
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New();
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(const std::string& fileName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(med_idt fid, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(DataArrayByte *db) { return BuildFromMemoryChunk<typename MLFieldTraits<T>::FMTSType>(db); }
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent);
+ MEDLOADER_EXPORT static typename MLFieldTraits<T>::FMTSType *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll=true);
+ MEDLOADER_EXPORT typename MLFieldTraits<T>::FMTSType *extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const { return this->extractPartImpl(extractDef,mm); }
+ //
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *field(int iteration, int order, const MEDFileMesh *mesh) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::FieldType *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
+ //
+ MEDLOADER_EXPORT void appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field);
+ MEDLOADER_EXPORT void appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
+ //
+ MEDLOADER_EXPORT typename MLFieldTraits<T>::F1TSType *getTimeStepAtPos(int pos) const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArray(int iteration, int order) const;
+ MEDLOADER_EXPORT typename Traits<T>::ArrayType *getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ MEDLOADER_EXPORT typename MLFieldTraits<T>::FMTSType *buildNewEmptyImpl() const;
+ MEDLOADER_EXPORT void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const;
+ protected:
+ const typename MLFieldTraits<T>::FMTSWSDAType *contentNotNull() const;
+ typename MLFieldTraits<T>::FMTSWSDAType *contentNotNull();
+ protected:
+ ~MEDFileTemplateFieldMultiTS() { }
+ MEDFileTemplateFieldMultiTS();
+ MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent);
+ MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms);
+ MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities=0);
+ };
+
class MEDFileIntFieldMultiTS;
/*!
* User class.
*/
- class MEDFileFieldMultiTS : public MEDFileAnyTypeFieldMultiTS
+ class MEDFileFieldMultiTS : public MEDFileTemplateFieldMultiTS<double>
{
+ friend class MEDFileTemplateFieldMultiTS<double>;
public:
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New();
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(const std::string& fileName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(med_idt fid, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileFieldMultiTS>(db); }
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent);
- MEDLOADER_EXPORT static MEDFileFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll=true);
MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *shallowCpy() const;
- MEDLOADER_EXPORT void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const;
MEDLOADER_EXPORT MEDFileIntFieldMultiTS *convertToInt(bool isDeepCpyGlobs=true) const;
//
- MEDLOADER_EXPORT MEDFileField1TS *getTimeStepAtPos(int pos) const;
- MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const;
- MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const;
- //
- MEDLOADER_EXPORT MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT DataArrayDouble *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
- //
- MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field);
- MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
MEDLOADER_EXPORT std::vector< std::vector<DataArrayDouble *> > getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
- MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArray(int iteration, int order) const;
- MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ MEDLOADER_EXPORT MEDFileFieldMultiTS *buildNewEmpty() const { return buildNewEmptyImpl(); }
public:
- MEDLOADER_EXPORT MEDFileFieldMultiTS *buildNewEmpty() const;
- private:
- const MEDFileFieldMultiTSWithoutSDA *contentNotNull() const;
- MEDFileFieldMultiTSWithoutSDA *contentNotNull();
private:
~MEDFileFieldMultiTS() { }
- MEDFileFieldMultiTS();
+ MEDFileFieldMultiTS() { }
MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent);
MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms);
MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities=0);
};
+ template<class T>
+ class MEDFileNDTemplateFieldMultiTS : public MEDFileTemplateFieldMultiTS<T>
+ {
+ public:
+ MEDLOADER_EXPORT MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const;
+ protected:
+ ~MEDFileNDTemplateFieldMultiTS() { }
+ MEDFileNDTemplateFieldMultiTS() { }
+ MEDFileNDTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<T>(other,shallowCopyOfContent) { }
+ MEDFileNDTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileTemplateFieldMultiTS<T>(fid,loadAll,ms) { }
+ MEDFileNDTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTS<T>(fid,fieldName,loadAll,ms,entities) { }
+ };
+
/*!
* User class.
*/
- class MEDFileIntFieldMultiTS : public MEDFileAnyTypeFieldMultiTS
+ class MEDFileIntFieldMultiTS : public MEDFileNDTemplateFieldMultiTS<int>
{
+ friend class MEDFileTemplateFieldMultiTS<int>;
public:
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New();
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(const std::string& fileName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(med_idt fid, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileIntFieldMultiTS>(db); }
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(med_idt fid, const std::string& fieldName, bool loadAll=true);
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent);
- MEDLOADER_EXPORT static MEDFileIntFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll=true);
- MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *shallowCpy() const;
- MEDLOADER_EXPORT void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const;
- MEDLOADER_EXPORT MEDFileIntField1TS *getTimeStepAtPos(int pos) const;
- MEDLOADER_EXPORT MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const;
- //
- MEDLOADER_EXPORT MEDCouplingFieldInt *field(int iteration, int order, const MEDFileMesh *mesh) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const;
- MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const;
- MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const;
- //
- MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field);
- MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
- //
- MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray(int iteration, int order) const;
- public:
- MEDLOADER_EXPORT MEDFileIntFieldMultiTS *buildNewEmpty() const;
- private:
- const MEDFileIntFieldMultiTSWithoutSDA *contentNotNull() const;
- MEDFileIntFieldMultiTSWithoutSDA *contentNotNull();
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *shallowCpy() const { return new MEDFileIntFieldMultiTS(*this); }
+ MEDLOADER_EXPORT MEDFileIntFieldMultiTS *buildNewEmpty() const { return buildNewEmptyImpl(); }
private:
~MEDFileIntFieldMultiTS() { }
- MEDFileIntFieldMultiTS();
- MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent);
- MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms);
- MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities=0);
+ MEDFileIntFieldMultiTS() { }
+ MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileNDTemplateFieldMultiTS<int>(other,shallowCopyOfContent) { }
+ MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateFieldMultiTS<int>(fid,loadAll,ms) { }
+ MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities=0):MEDFileNDTemplateFieldMultiTS<int>(fid,fieldName,loadAll,ms,entities) { }
+ };
+
+ /*!
+ * User class.
+ */
+ class MEDFileFloatFieldMultiTS : public MEDFileNDTemplateFieldMultiTS<float>
+ {
+ friend class MEDFileTemplateFieldMultiTS<float>;
+ public:
+ MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *shallowCpy() const { return new MEDFileFloatFieldMultiTS(*this); }
+ MEDLOADER_EXPORT MEDFileFloatFieldMultiTS *buildNewEmpty() const { return buildNewEmptyImpl(); }
+ private:
+ ~MEDFileFloatFieldMultiTS() { }
+ MEDFileFloatFieldMultiTS() { }
+ MEDFileFloatFieldMultiTS(const MEDFileFloatFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileNDTemplateFieldMultiTS<float>(other,shallowCopyOfContent) { }
+ MEDFileFloatFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileNDTemplateFieldMultiTS<float>(fid,loadAll,ms) { }
+ MEDFileFloatFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities=0):MEDFileNDTemplateFieldMultiTS<float>(fid,fieldName,loadAll,ms,entities) { }
};
class MEDFileAnyTypeFieldMultiTSIterator
#include "MEDFileField.hxx"
#include "MEDCouplingTraits.hxx"
+#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldTemplate.hxx"
namespace MEDCoupling
{
return 0;
}
+ /*!
+ * Returns a pointer to the underground DataArrayDouble instance and a
+ * sequence describing parameters of a support of each part of \a this field. The
+ * caller should not decrRef() the returned DataArrayDouble. This method allows for a
+ * direct access to the field values. This method is intended for the field lying on one
+ * mesh only.
+ * \param [in,out] entries - the sequence describing parameters of a support of each
+ * part of \a this field. Each item of this sequence consists of two parts. The
+ * first part describes a type of mesh entity and an id of discretization of a
+ * current field part. The second part describes a range of values [begin,end)
+ * within the returned array relating to the current field part.
+ * \return DataArrayDouble * - the pointer to the field values array.
+ * \throw If the number of underlying meshes is not equal to 1.
+ * \throw If no field values are available.
+ * \sa getUndergroundDataArrayTemplate()
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplateExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+ {
+ if(this->_field_per_mesh.size()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
+ if(this->_field_per_mesh[0]==0)
+ throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
+ this->_field_per_mesh[0]->getUndergroundDataArrayExt(entries);
+ return getUndergroundDataArrayTemplate();
+ }
+
/*!
* Returns a pointer to the underground DataArrayDouble instance. So the
* caller should not decrRef() it. This method allows for a direct access to the field
start+=(*it).second.second-(*it).second.first;
}
}
+
+ ///////////////////////////////////////////////////////
+
+ template<class T>
+ MEDFileField1TSWithoutSDA *MEDFileField1TSNDTemplateWithoutSDA<T>::convertToDouble() const
+ {
+ MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
+ ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
+ ret->deepCpyLeavesFrom(*this);
+ if(this->_arr.isNotNull())
+ {
+ MCAuto<DataArrayDouble> arr2(this->_arr->convertToDblArr());
+ ret->setArray(arr2);
+ }
+ return ret.retn();
+ }
+
+ ///////////////////////////////////////////////////////
+
+ template<class T>
+ MEDFileTemplateField1TS<T>::MEDFileTemplateField1TS()
+ {
+ _content=new typename MLFieldTraits<T>::F1TSWSDAType;
+ }
+
+ /*!
+ * Returns a new empty instance of MEDFileField1TS.
+ * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New()
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType);
+ ret->contentNotNull();
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileField1TS holding data of the first time step of
+ * the first field that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,loadAll);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, bool loadAll)
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,loadAll,0));
+ ret->contentNotNull();
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileField1TS holding data of the first time step of
+ * a given field that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \param [in] fieldName - the name of the field to read.
+ * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ * \throw If there is no field named \a fieldName in the file.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,fieldName,loadAll);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,loadAll,0));
+ ret->contentNotNull();
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileField1TS holding data of a given time step of
+ * a given field that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \param [in] fieldName - the name of the field to read.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ * \throw If there is no field named \a fieldName in the file.
+ * \throw If the required time step is missing from the file.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,fieldName,iteration,order,loadAll);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,iteration,order,loadAll,0));
+ ret->contentNotNull();
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
+ * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ *
+ * Returns a new instance of MEDFileField1TS holding either a shallow copy
+ * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
+ * \warning this is a shallow copy constructor
+ * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
+ * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
+ * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent)
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(other,shallowCopyOfContent));
+ ret->contentNotNull();
+ return ret.retn();
+ }
+
+ template<class T>
+ const typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull() const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
+ if(!pt)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is null !");
+ const typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
+ if(!ret)
+ {
+ std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret;
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull()
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
+ if(!pt)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is null !");
+ typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
+ if(!ret)
+ {
+ std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret;
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr)
+ {
+ if(arr.isNull())
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : no array !");
+ typename Traits<T>::ArrayType *arrOutC(dynamic_cast<typename Traits<T>::ArrayType *>((DataArray*)arr));
+ if(!arrOutC)
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
+ arrOutC->incrRef();
+ return arrOutC;
+ }
+
+ /*!
+ * Returns values and a profile of the field of a given type lying on a given support.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of the field.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] mesh - the supporting mesh.
+ * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
+ * field of interest lies on. If the field lies on all entities of the given
+ * dimension, all ids in \a pfl are zero. The caller is to delete this array
+ * using decrRef() as it is no more needed.
+ * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
+ * field. The caller is to delete this array using decrRef() as it is no more needed.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
+ {
+ MCAuto<DataArray> arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull()));
+ return ReturnSafelyTypedDataArray(arr);
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArray() const
+ {
+ return contentNotNull()->getUndergroundDataArrayTemplate();
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+ {
+ return contentNotNull()->getUndergroundDataArrayTemplateExt(entries);
+ }
+
+ template<class T>
+ MCAuto<typename Traits<T>::FieldType> MEDFileTemplateField1TS<T>::SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
+ {
+ if(!f)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : input field is NULL !");
+ if(arr.isNull())
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : no array !");
+ int t1,t2;
+ double t0(f->getTime(t1,t2));
+ std::string tu(f->getTimeUnit());
+ MCAuto<typename Traits<T>::ArrayType> arr2(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(arr));
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
+ MCAuto<typename Traits<T>::FieldType> ret(Traits<T>::FieldType::New(*ft));
+ ret->setTime(t0,t1,t2); ret->setArray(arr2); ret->setTimeUnit(tu);
+ return ret.retn();
+ }
+
+ template<class T>
+ MCAuto<MEDCouplingFieldDouble> MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f)
+ {
+ int t1,t2;
+ double t0(f->getTime(t1,t2));
+ std::string tu(f->getTimeUnit());
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*f));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
+ ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
+ return ret.retn();
+ }
+
+ /*!
+ * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
+ * method should be called (getFieldOnMeshAtLevel for example).
+ * But for normal usage of field in MED file world this method is the most efficient to fetch data.
+ *
+ * \param [in] mesh - the mesh the field is lying on
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::field(const MEDFileMesh *mesh) const
+ {
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new typename Traits<T>::FieldType of a given type lying on
+ * mesh entities of a given dimension of the first mesh in MED file. If \a this field
+ * has not been constructed via file reading, an exception is thrown.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If \a this field has not been constructed via file reading.
+ * \throw If the MED file is not readable.
+ * \throw If there is no mesh in the MED file.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
+ * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
+ * \sa getFieldOnMeshAtLevel()
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
+ {
+ if(getFileName().empty())
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new typename Traits<T>::FieldType of a given type lying on
+ * the top level cells of the first mesh in MED file. If \a this field
+ * has not been constructed via file reading, an exception is thrown.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If \a this field has not been constructed via file reading.
+ * \throw If the MED file is not readable.
+ * \throw If there is no mesh in the MED file.
+ * \throw If no field values of the given \a type.
+ * \throw If no field values lying on the top level support.
+ * \sa getFieldAtLevel()
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtTopLevel(TypeOfField type, int renumPol) const
+ {
+ if(getFileName().empty())
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new typename Traits<T>::FieldType of given type lying on a given mesh.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of the new field.
+ * \param [in] mesh - the supporting mesh.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If the mesh is empty.
+ * \throw If no field values of the given \a type are available.
+ * \sa getFieldAtLevel()
+ * \sa getFieldOnMeshAtLevel()
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
+ {
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] mesh - the supporting mesh.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
+ * \sa getFieldAtLevel()
+ * \sa getFieldOnMeshAtLevel()
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
+ {
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
+ * This method is called "Old" because in MED3 norm a field has only one meshName
+ * attached, so this method is for readers of MED2 files. If \a this field
+ * has not been constructed via file reading, an exception is thrown.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] mName - a name of the supporting mesh.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If the MED file is not readable.
+ * \throw If there is no mesh named \a mName in the MED file.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
+ * \throw If \a this field has not been constructed via file reading.
+ * \throw If no field of \a this is lying on the mesh named \a mName.
+ * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
+ * \sa getFieldAtLevel()
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
+ {
+ if(getFileName().empty())
+ throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
+ * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
+ * "Sort By Type"), if not, an exception is thrown.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] field - the field to add to \a this.
+ * \throw If the name of \a field is empty.
+ * \throw If the data array of \a field is not set.
+ * \throw If the data array is already allocated but has different number of components
+ * than \a field.
+ * \throw If the underlying mesh of \a field has no name.
+ * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
+ */
+ template<class T>
+ void MEDFileTemplateField1TS<T>::setFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
+ {
+ setFileName("");
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
+ contentNotNull()->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,field->getArray(),*this,*contentNotNull());
+ }
+
+ /*!
+ * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
+ * can be an aggregation of several MEDCouplingFieldDouble instances.
+ * The mesh support of input parameter \a field is ignored here, it can be NULL.
+ * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
+ * and \a profile.
+ *
+ * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
+ * A new profile is added only if no equal profile is missing.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
+ * \param [in] mesh - the supporting mesh of \a field.
+ * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
+ * \param [in] profile - ids of mesh entities on which corresponding field values lie.
+ * \throw If either \a field or \a mesh or \a profile has an empty name.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
+ * \throw If the data array of \a field is not set.
+ * \throw If the data array of \a this is already allocated but has different number of
+ * components than \a field.
+ * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
+ * \sa setFieldNoProfileSBT()
+ */
+ template<class T>
+ void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
+ {
+ setFileName("");
+ MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
+ contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
+ }
+
+ /*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+ {
+ if(!mm)
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
+ std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
+ for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
+ {
+ if((*it0)!=ON_NODES)
+ {
+ std::vector<int> levs;
+ getNonEmptyLevels(mm->getName(),levs);
+ for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
+ {
+ std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
+ if(it2!=extractDef.end())
+ {
+ MCAuto<DataArrayInt> t((*it2).second);
+ if(t.isNull())
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
+ MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
+ MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
+ ret->setFieldNoProfileSBT(fOut);
+ }
+ }
+ }
+ else
+ {
+ std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
+ if(it2==extractDef.end())
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
+ MCAuto<DataArrayInt> t((*it2).second);
+ if(t.isNull())
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
+ MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
+ MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
+ typename Traits<T>::ArrayType *arr(f->getArray());
+ MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
+ fOut->setArray(newArr);
+ ret->setFieldNoProfileSBT(fOut);
+ }
+ }
+ return ret.retn();
+ }
+
+ //////////////////////////
+
+ /*!
+ * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
+ * following the given input policy.
+ *
+ * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
+ * By default (true) the globals are deeply copied.
+ * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
+ */
+ template<class T>
+ MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
+ {
+ MCAuto<MEDFileField1TS> ret;
+ const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
+ if(content)
+ {
+ const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
+ if(!contc)
+ {
+ std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
+ ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
+ }
+ else
+ ret=MEDFileField1TS::New();
+ if(isDeepCpyGlobs)
+ ret->deepCpyGlobs(*this);
+ else
+ ret->shallowCpyGlobs(*this);
+ return ret.retn();
+ }
+
+ //////////////////////////
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTSWithoutSDA<T>::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
+ {
+ return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
+ }
+
+ template<class T>
+ void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
+ {
+ if(!f1ts)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
+ const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
+ if(!f1tsC)
+ {
+ std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+
+ template<class T>
+ const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
+ {
+ return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
+ }
+
+ template<class T>
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
+ {
+ return new typename MLFieldTraits<T>::FMTSWSDAType;
+ }
+
+ template<class T>
+ MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
+ {
+ return new typename MLFieldTraits<T>::F1TSWSDAType;
+ }
+
+ //////////////////////////
+
+ template<class T>
+ MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
+ {
+ MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
+ ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
+ int i=0;
+ for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
+ if(eltToConv)
+ {
+ const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
+ if(!eltToConvC)
+ throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
+ MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
+ ret->setIteration(i,elt);
+ }
+ }
+ return ret.retn();
+ }
+
+ //////////////////////////
+
+ template<class T>
+ MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
+ {
+ _content=new typename MLFieldTraits<T>::FMTSWSDAType;
+ }
+
+ template<class T>
+ MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
+ {
+ }
+
+ template<class T>
+ MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
+ {
+ }
+
+ template<class T>
+ MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
+ {
+ }
+
+ /*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+ {
+ if(!mm)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
+ MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
+ int nbTS(getNumberOfTS());
+ for(int i=0;i<nbTS;i++)
+ {
+ MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
+ MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
+ MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
+ fmtsOut->pushBackTimeStep(f1tsOut);
+ }
+ return fmtsOut.retn();
+ }
+
+ /*!
+ * Returns a new empty instance of MEDFileFieldMultiTS.
+ * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
+ {
+ return new typename MLFieldTraits<T>::FMTSType;
+ }
+
+ /*!
+ * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
+ * that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,loadAll);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
+ {
+ MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
+ ret->contentNotNull();//to check that content type matches with \a this type.
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
+ * that has been read from a specified MED file.
+ * \param [in] fileName - the name of the MED file to read.
+ * \param [in] fieldName - the name of the field to read.
+ * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ * \throw If reading the file fails.
+ * \throw If there is no field named \a fieldName in the file.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,fieldName,loadAll);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
+ {
+ MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
+ ret->contentNotNull();//to check that content type matches with \a this type.
+ return ret.retn();
+ }
+
+ /*!
+ * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
+ * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
+ *
+ * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
+ * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
+ * \warning this is a shallow copy constructor
+ * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
+ * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
+ * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
+ * is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
+ {
+ return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
+ {
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
+ MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
+ ret->contentNotNull();//to check that content type matches with \a this type.
+ return ret.retn();
+ }
+
+ /*!
+ * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
+ * method should be called (getFieldOnMeshAtLevel for example).
+ * But for normal usage of field in MED file world this method is the most efficient to fetch data.
+ *
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] mesh - the mesh the field is lying on
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
+ * mesh entities of a given dimension of the first mesh in MED file.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If the MED file is not readable.
+ * \throw If there is no mesh in the MED file.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
+ * \throw If no field values of the required parameters are available.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
+ * the top level cells of the first mesh in MED file.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If the MED file is not readable.
+ * \throw If there is no mesh in the MED file.
+ * \throw If no field values of the required parameters are available.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
+ * a given support.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of interest.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] mesh - the supporting mesh.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If no field values of the required parameters are available.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
+ * given support.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of the new field.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] mesh - the supporting mesh.
+ * \param [in] renumPol - specifies how to permute values of the result field according to
+ * the optional numbers of cells and nodes, if any. The valid values are
+ * - 0 - do not permute.
+ * - 1 - permute cells.
+ * - 2 - permute nodes.
+ * - 3 - permute cells and nodes.
+ *
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If no field values of the required parameters are available.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
+ * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
+ * This method is useful for MED2 file format when field on different mesh was autorized.
+ */
+ template<class T>
+ typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
+ MCAuto<DataArray> arrOut;
+ MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
+ MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
+ return ret2.retn();
+ }
+
+ /*!
+ * Returns values and a profile of the field of a given type, of a given time step,
+ * lying on a given support.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] type - a spatial discretization of the field.
+ * \param [in] iteration - the iteration number of a required time step.
+ * \param [in] order - the iteration order number of required time step.
+ * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
+ * \param [in] mesh - the supporting mesh.
+ * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
+ * field of interest lies on. If the field lies on all entities of the given
+ * dimension, all ids in \a pfl are zero. The caller is to delete this array
+ * using decrRef() as it is no more needed.
+ * \param [in] glob - the global data storing profiles and localization.
+ * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
+ * field. The caller is to delete this array using decrRef() as it is no more needed.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
+ * \throw If no field of \a this is lying on \a mesh.
+ * \throw If no field values of the required parameters are available.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
+ const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
+ if(!myF1TSC)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
+ MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
+ return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
+ }
+
+ /*!
+ * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
+ * the given field is checked if its elements are sorted suitable for writing to MED file
+ * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] field - the field to add to \a this.
+ * \throw If the name of \a field is empty.
+ * \throw If the data array of \a field is not set.
+ * \throw If existing time steps have different name or number of components than \a field.
+ * \throw If the underlying mesh of \a field has no name.
+ * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
+ */
+ template<class T>
+ void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
+ {
+ const typename Traits<T>::ArrayType *arr(NULL);
+ if(field)
+ arr=field->getArray();
+ MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
+ contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
+ }
+
+ /*!
+ * Adds a MEDCouplingFieldDouble to \a this as another time step.
+ * The mesh support of input parameter \a field is ignored here, it can be NULL.
+ * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
+ * and \a profile.
+ *
+ * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
+ * A new profile is added only if no equal profile is missing.
+ * For more info, see \ref AdvMEDLoaderAPIFieldRW
+ * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
+ * \param [in] mesh - the supporting mesh of \a field.
+ * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
+ * \param [in] profile - ids of mesh entities on which corresponding field values lie.
+ * \throw If either \a field or \a mesh or \a profile has an empty name.
+ * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
+ * \throw If the data array of \a field is not set.
+ * \throw If the data array of \a this is already allocated but has different number of
+ * components than \a field.
+ * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
+ * \sa setFieldNoProfileSBT()
+ */
+ template<class T>
+ void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
+ {
+ const typename Traits<T>::ArrayType *arr(NULL);
+ if(field)
+ arr=field->getArray();
+ MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
+ contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this);
+ }
+
+ template<class T>
+ const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
+ {
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
+ if(!pt)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
+ const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
+ return ret;
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
+ {
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
+ if(!pt)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
+ typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
+ return ret;
+ }
+
+ /*!
+ * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
+ * \param [in] pos - a time step id.
+ * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
+ * delete this field using decrRef() as it is no more needed.
+ * \throw If \a pos is not a valid time step id.
+ */
+ template<class T>
+ typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
+ {
+ const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
+ if(!item)
+ {
+ std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
+ if(itemC)
+ {
+ MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
+ ret->shallowCpyGlobs(*this);
+ return ret.retn();
+ }
+ std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
+ {
+ DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
+ if(!ret)
+ return NULL;
+ typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
+ if(!ret2)
+ {
+ std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret2;
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
+ {
+ DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
+ if(!ret)
+ return NULL;
+ typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
+ if(!ret2)
+ {
+ std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret2;
+ }
+
+ template<class T>
+ typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
+ {
+ return MLFieldTraits<T>::FMTSType::New();
+ }
+
+ template<class T>
+ void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
+ {
+ if(!f1ts)
+ throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
+ const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
+ if(!f1tsC)
+ {
+ std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+
+ //////////////////////////
+
+ /*!
+ * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
+ * following the given input policy.
+ *
+ * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
+ * By default (true) the globals are deeply copied.
+ * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
+ */
+ template<class T>
+ MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
+ {
+ MCAuto<MEDFileFieldMultiTS> ret;
+ const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
+ if(content)
+ {
+ const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
+ if(!contc)
+ throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
+ MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
+ ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
+ }
+ else
+ ret=MEDFileFieldMultiTS::New();
+ if(isDeepCpyGlobs)
+ ret->deepCpyGlobs(*this);
+ else
+ ret->shallowCpyGlobs(*this);
+ return ret.retn();
+ }
}
#endif
ret.push_back((const DataArrayDouble*)_coords);
ret.push_back((const DataArrayInt *)_fam_coords);
ret.push_back((const DataArrayInt *)_num_coords);
+ ret.push_back((const DataArrayInt *)_global_num_coords);
ret.push_back((const DataArrayInt *)_rev_num_coords);
ret.push_back((const DataArrayAsciiChar *)_name_coords);
ret.push_back((const PartDefinition *)_part_coords);
{
MCAuto<MEDFileUMesh> ret(new MEDFileUMesh(*this));
ret->deepCpyEquivalences(*this);
- if((const DataArrayDouble*)_coords)
+ if(_coords.isNotNull())
ret->_coords=_coords->deepCopy();
- if((const DataArrayInt*)_fam_coords)
+ if(_fam_coords.isNotNull())
ret->_fam_coords=_fam_coords->deepCopy();
- if((const DataArrayInt*)_num_coords)
+ if(_num_coords.isNotNull())
ret->_num_coords=_num_coords->deepCopy();
- if((const DataArrayInt*)_rev_num_coords)
+ if(_global_num_coords.isNotNull())
+ ret->_global_num_coords=_global_num_coords->deepCopy();
+ if(_rev_num_coords.isNotNull())
ret->_rev_num_coords=_rev_num_coords->deepCopy();
- if((const DataArrayAsciiChar*)_name_coords)
+ if(_name_coords.isNotNull())
ret->_name_coords=_name_coords->deepCopy();
std::size_t i=0;
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
return false;
}
}
- const DataArrayInt *famc1=_fam_coords;
- const DataArrayInt *famc2=otherC->_fam_coords;
- if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
- {
- what="Mismatch of families arr on nodes ! One is defined and not other !";
- return false;
- }
- if(famc1)
- {
- bool ret=famc1->isEqual(*famc2);
- if(!ret)
- {
- what="Families arr on node differ !";
- return false;
- }
- }
- const DataArrayInt *numc1=_num_coords;
- const DataArrayInt *numc2=otherC->_num_coords;
- if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
- {
- what="Mismatch of numbering arr on nodes ! One is defined and not other !";
- return false;
- }
- if(numc1)
- {
- bool ret=numc1->isEqual(*numc2);
- if(!ret)
- {
- what="Numbering arr on node differ !";
- return false;
- }
- }
- const DataArrayAsciiChar *namec1=_name_coords;
- const DataArrayAsciiChar *namec2=otherC->_name_coords;
- if((namec1==0 && namec2!=0) || (namec1!=0 && namec2==0))
- {
- what="Mismatch of naming arr on nodes ! One is defined and not other !";
- return false;
- }
- if(namec1)
- {
- bool ret=namec1->isEqual(*namec2);
- if(!ret)
- {
- what="Names arr on node differ !";
- return false;
- }
- }
+ {
+ const DataArrayInt *famc1(_fam_coords),*famc2(otherC->_fam_coords);
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of families arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Families arr on node differ !";
+ return false;
+ }
+ }
+ }
+ {
+ const DataArrayInt *numc1(_num_coords),*numc2(otherC->_num_coords);
+ if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
+ {
+ what="Mismatch of numbering arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(numc1)
+ {
+ bool ret=numc1->isEqual(*numc2);
+ if(!ret)
+ {
+ what="Numbering arr on node differ !";
+ return false;
+ }
+ }
+ }
+ {
+ const DataArrayInt *gnumc1(_global_num_coords),*gnumc2(otherC->_global_num_coords);
+ if((gnumc1==0 && gnumc2!=0) || (gnumc1!=0 && gnumc2==0))
+ {
+ what="Mismatch of numbering arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(gnumc1)
+ {
+ bool ret=gnumc1->isEqual(*gnumc2);
+ if(!ret)
+ {
+ what="Global numbering arr on node differ !";
+ return false;
+ }
+ }
+ }
+ {
+ const DataArrayAsciiChar *namec1(_name_coords),*namec2(otherC->_name_coords);
+ if((namec1==0 && namec2!=0) || (namec1!=0 && namec2==0))
+ {
+ what="Mismatch of naming arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(namec1)
+ {
+ bool ret=namec1->isEqual(*namec2);
+ if(!ret)
+ {
+ what="Names arr on node differ !";
+ return false;
+ }
+ }
+ }
if(_ms.size()!=otherC->_ms.size())
{
what="Number of levels differs !";
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkConsistency(): coords are null but some mesh parts are present!");
if (!_fam_coords)
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkConsistency(): coords are null but not the internal node family array!");
- if (!_num_coords || !_rev_num_coords)
+ if (_num_coords.isNotNull() || _rev_num_coords.isNotNull() || _global_num_coords.isNotNull())
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkConsistency(): coords are null but not the internal node numbering array!");
}
else
{
int nbCoo = _coords->getNumberOfTuples();
- if (_fam_coords)
+ if (_fam_coords.isNotNull())
_fam_coords->checkNbOfTuplesAndComp(nbCoo,1,"MEDFileUMesh::checkConsistency(): inconsistent internal node family array!");
- if (_num_coords)
+ if (_num_coords.isNotNull())
{
_num_coords->checkNbOfTuplesAndComp(nbCoo,1,"MEDFileUMesh::checkConsistency(): inconsistent internal node numbering array!");
int pos;
if (!_rev_num_coords || _rev_num_coords->getNumberOfTuples() != (maxValue+1))
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkConsistency(): inconsistent internal revert node numbering array!");
}
+ if (_global_num_coords.isNotNull())
+ {
+ _global_num_coords->checkNbOfTuplesAndComp(nbCoo,1,"MEDFileUMesh::checkConsistency(): inconsistent global node numbering array!");
+ }
if ((_num_coords && !_rev_num_coords) || (!_num_coords && _rev_num_coords))
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
if (_num_coords && !_num_coords->hasUniqueValues())
*/
void MEDFileUMesh::clearNodeAndCellNumbers()
{
- _num_coords = 0;
- _rev_num_coords = 0;
- for (std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();
- it != _ms.end(); it++)
+ _num_coords.nullify();
+ _rev_num_coords.nullify();
+ _global_num_coords.nullify();
+ for (std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin(); it != _ms.end(); it++)
{
- (*it)->_num = 0;
- (*it)->_rev_num = 0;
+ (*it)->_num.nullify();
+ (*it)->_rev_num.nullify();
+ (*it)->_global_num.nullify();
}
}
void MEDFileUMesh::clearNonDiscrAttributes() const
{
MEDFileMesh::clearNonDiscrAttributes();
- const DataArrayDouble *coo1=_coords;
- if(coo1)
- (const_cast<DataArrayDouble *>(coo1))->setName("");//This parameter is not discriminant for comparison
- const DataArrayInt *famc1=_fam_coords;
- if(famc1)
- (const_cast<DataArrayInt *>(famc1))->setName("");//This parameter is not discriminant for comparison
- const DataArrayInt *numc1=_num_coords;
- if(numc1)
- (const_cast<DataArrayInt *>(numc1))->setName("");//This parameter is not discriminant for comparison
- const DataArrayAsciiChar *namc1=_name_coords;
- if(namc1)
- (const_cast<DataArrayAsciiChar *>(namc1))->setName("");//This parameter is not discriminant for comparison
+ if(_coords.isNotNull())
+ _coords.iAmATrollConstCast()->setName("");//This parameter is not discriminant for comparison
+ if(_fam_coords.isNotNull())
+ _fam_coords.iAmATrollConstCast()->setName("");//This parameter is not discriminant for comparison
+ if(_num_coords.isNotNull())
+ _num_coords.iAmATrollConstCast()->setName("");//This parameter is not discriminant for comparison
+ if(_name_coords.isNotNull())
+ _name_coords.iAmATrollConstCast()->setName("");//This parameter is not discriminant for comparison
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
{
- const MEDFileUMeshSplitL1 *tmp=(*it);
- if(tmp)
- tmp->clearNonDiscrAttributes();
+ if((*it).isNotNull())
+ (*it)->clearNonDiscrAttributes();
}
}
void MEDFileUMesh::setName(const std::string& name)
{
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
- if((MEDFileUMeshSplitL1 *)(*it)!=0)
+ if((*it).isNotNull())
(*it)->setName(name);
MEDFileMesh::setName(name);
}
_num_coords=loaderl2.getCoordsNum();
if(!mrs || mrs->isNodeNameFieldReading())
_name_coords=loaderl2.getCoordsName();
+ if(!mrs || mrs->isGlobalNodeNumFieldReading())
+ _global_num_coords=loaderl2.getCoordsGlobalNum();
_part_coords=loaderl2.getPartDefOfCoo();
computeRevNum();
}
if(_univ_wr_status)
MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
- MEDFileUMeshL2::WriteCoords(fid,meshName,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords);
+ MEDFileUMeshL2::WriteCoords(fid,meshName,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords,_global_num_coords);
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
if((const MEDFileUMeshSplitL1 *)(*it)!=0)
(*it)->write(fid,meshName,mdim);
std::vector<int> MEDFileUMesh::getNumArrNonEmptyLevelsExt() const
{
std::vector<int> ret;
- const DataArrayInt *numCoo(_num_coords);
- if(numCoo)
+ if(_num_coords.isNotNull())
ret.push_back(1);
int lev=0;
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
return l1->getNameField();
}
+MCAuto<DataArrayInt> MEDFileUMesh::getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const
+{
+ if(meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getGlobalNumFieldAtLevel : not implemented yet for structured mesh !");
+ return _global_num_coords;
+}
+
/*!
* This method returns for a specified relative level \a meshDimRelToMaxExt the part effectively read (if the instance is the result of the read of a file).
*
{
if(meshDimRelToMaxExt==1)
{
- if(!((const DataArrayInt *)_num_coords))
+ if(_num_coords.isNull())
throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
return _rev_num_coords;
}
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
return l1->getRevNumberField();
}
return ;
coords->checkAllocated();
int nbOfTuples(coords->getNumberOfTuples());
- _coords=coords;
- coords->incrRef();
+ _coords.takeRef(coords);
_fam_coords=DataArrayInt::New();
_fam_coords->alloc(nbOfTuples,1);
_fam_coords->fillWithZero();
- _num_coords=0; _rev_num_coords=0; _name_coords=0;
+ _num_coords.nullify(); _rev_num_coords.nullify(); _name_coords.nullify(); _global_num_coords.nullify();
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
if((MEDFileUMeshSplitL1 *)(*it))
(*it)->setCoords(coords);
_fam_coords=newFam;
}
- _num_coords = 0;
- _rev_num_coords = 0;
+ _num_coords.nullify(); _rev_num_coords.nullify(); _global_num_coords.nullify();
+
for (std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();
it != _ms.end(); it++)
{
MCAuto<DataArrayAsciiChar> newNameCoords;
if((const DataArrayInt *)_fam_coords)
newFamCoords=_fam_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
- MCAuto<DataArrayInt> newNumCoords;
- if((const DataArrayInt *)_num_coords)
+ MCAuto<DataArrayInt> newNumCoords,newGlobalNumCoords;
+ if(_num_coords.isNotNull())
newNumCoords=_num_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
- if((const DataArrayAsciiChar *)_name_coords)
+ if(_global_num_coords.isNotNull())
+ newGlobalNumCoords=_global_num_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
+ if(_name_coords.isNotNull())
newNameCoords=static_cast<DataArrayAsciiChar *>(_name_coords->selectByTupleIdSafe(ret2->begin(),ret2->end()));
- _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _name_coords=newNameCoords; _rev_num_coords=0;
+ _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _global_num_coords=newGlobalNumCoords; _name_coords=newNameCoords; _rev_num_coords.nullify();
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
{
if((MEDFileUMeshSplitL1*)*it)
if(!coo)
throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : the coordinates have not been set !");
famArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setFamilyFieldArr : Problem in size of node family arr ! ");
- famArr->incrRef();
- _fam_coords=famArr;
+ _fam_coords.takeRef(famArr);
return ;
}
if(meshDimRelToMaxExt>1)
{
if(!renumArr)
{
- _num_coords=0;
- _rev_num_coords=0;
+ _num_coords.nullify();
+ _rev_num_coords.nullify();
return ;
}
- DataArrayDouble *coo(_coords);
- if(!coo)
+ if(_coords.isNull())
throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
- renumArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
- renumArr->incrRef();
- _num_coords=renumArr;
+ renumArr->checkNbOfTuplesAndComp(_coords->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
+ _num_coords.takeRef(renumArr);
computeRevNum();
return ;
}
if(!coo)
throw INTERP_KERNEL::Exception("MEDFileUMesh::setNameFieldAtLevel : the coordinates have not been set !");
nameArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),MED_SNAME_SIZE,"MEDFileUMesh::setNameFieldAtLevel : Problem in size of node numbering arr ! ");
- nameArr->incrRef();
- _name_coords=nameArr;
+ _name_coords.takeRef(nameArr);
return ;
}
if(meshDimRelToMaxExt>1)
return _ms[traducedRk]->setNameArr(nameArr);
}
+void MEDFileUMesh::setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr)
+{
+ if(meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGlobalNumFieldAtLevel : Only implemented for meshDimRelToMaxExt==1 for the moment !");
+ if(globalNumArr)
+ globalNumArr->checkNbOfTuplesAndComp(_coords->getNumberOfTuples(),1,"MEDFileUMesh::setGlobalNumFieldAtLevel : Problem in size of node global numbering arr ! ");
+ _global_num_coords.takeRef(globalNumArr);
+}
+
void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
{
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
void MEDFileUMesh::computeRevNum() const
{
- if((const DataArrayInt *)_num_coords)
+ if(_num_coords.isNotNull())
{
int pos;
int maxValue=_num_coords->getMaxValue(pos);
nameArr->incrRef();
}
+void MEDFileStructuredMesh::setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr)
+{
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setGlobalNumFieldAtLevel : not implemented yet !");
+}
+
/*!
* Adds a group of nodes to \a this mesh.
* \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
}
}
+MCAuto<DataArrayInt> MEDFileStructuredMesh::getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const
+{
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGlobalNumFieldAtLevel : not implemented yet for structured mesh !");
+}
+
/*!
* Returns relative dimensions of mesh entities (excluding nodes) present in \a this mesh.
* \return std::vector<int> - a sequence of the relative dimensions: [0].
MEDLOADER_EXPORT virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) = 0;
MEDLOADER_EXPORT virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) = 0;
MEDLOADER_EXPORT virtual void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) = 0;
+ MEDLOADER_EXPORT virtual void setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr) = 0;
MEDLOADER_EXPORT virtual void addNodeGroup(const DataArrayInt *ids) = 0;
MEDLOADER_EXPORT virtual void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) = 0;
MEDLOADER_EXPORT virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const = 0;
MEDLOADER_EXPORT virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const = 0;
MEDLOADER_EXPORT virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const = 0;
MEDLOADER_EXPORT virtual const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const = 0;
+ MEDLOADER_EXPORT virtual MCAuto<DataArrayInt> getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const = 0;
MEDLOADER_EXPORT virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const = 0;
MEDLOADER_EXPORT virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const;
MEDLOADER_EXPORT virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const std::string& grp, bool renum=false) const;
MEDLOADER_EXPORT const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const;
+ MEDLOADER_EXPORT MCAuto<DataArrayInt> getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT const PartDefinition *getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt=INTERP_KERNEL::NORM_ERROR) const;
MEDLOADER_EXPORT int getNumberOfNodes() const;
MEDLOADER_EXPORT int getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr);
MEDLOADER_EXPORT void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr);
MEDLOADER_EXPORT void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr);
+ MEDLOADER_EXPORT void setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr);
MEDLOADER_EXPORT void addNodeGroup(const DataArrayInt *ids);
MEDLOADER_EXPORT void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids);
MEDLOADER_EXPORT void removeMeshAtLevel(int meshDimRelToMax);
MCAuto<DataArrayDouble> _coords;
MCAuto<DataArrayInt> _fam_coords;
MCAuto<DataArrayInt> _num_coords;
+ MCAuto<DataArrayInt> _global_num_coords;
MCAuto<DataArrayAsciiChar> _name_coords;
mutable MCAuto<DataArrayInt> _rev_num_coords;
MCAuto<PartDefinition> _part_coords;
MEDLOADER_EXPORT void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr);
MEDLOADER_EXPORT void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr);
MEDLOADER_EXPORT void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr);
+ MEDLOADER_EXPORT void setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr);
MEDLOADER_EXPORT void addNodeGroup(const DataArrayInt *ids);
MEDLOADER_EXPORT void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids);
MEDLOADER_EXPORT const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const;
+ MEDLOADER_EXPORT MCAuto<DataArrayInt> getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const;
MEDLOADER_EXPORT std::vector<int> getNonEmptyLevels() const;
MEDLOADER_EXPORT std::vector<int> getNonEmptyLevelsExt() const;
MEDLOADER_EXPORT std::vector<int> getFamArrNonEmptyLevelsExt() const;
}
else
_name_coords=0;
+ if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_GLOBAL_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ _global_num_coords=DataArrayInt::New();
+ _global_num_coords->alloc(nCoords,1);
+ MEDFILESAFECALLERRD0(MEDmeshGlobalNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_global_num_coords->getPointer()));
+ }
for(int i=0;i<spaceDim;i++)
_coords->setInfoOnComponent(i,infosOnComp[i]);
}
_per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
}
-void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords)
+void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayInt *globalNumCoords)
{
if(!coords)
return ;
- MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
+ MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->begin()));
if(famCoords)
- MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
+ MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->begin()));
if(numCoords)
- MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
+ MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->begin()));
if(nameCoords)
{
if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
+ MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->begin()));
}
+ if(globalNumCoords)
+ MEDFILESAFECALLERWR0(MEDmeshGlobalNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NONE,globalNumCoords->getNumberOfTuples(),globalNumCoords->begin()));
}
bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
{
updateTime();
_m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
- _m->renumberCells(_st->_num->getConstPointer(),true);
+ _m->renumberCells(_st->_num->begin(),true);
return _m.retn();
}
else
{
updateTime();
_m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
- _m->renumberCells(_st->_num->getConstPointer(),true);
+ _m->renumberCells(_st->_num->begin(),true);
return _m.retn();
}
}
_num=da->invertArrayO2N2N2O(m->getNumberOfCells());
_m.updateTime();
computeRevNum();
- _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
+ _m_by_types.getUmesh()->renumberCells(da->begin(),false);
}
}
else
MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
{
MCAuto<DataArrayInt> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
- MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
+ MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->begin(),eltsToKeep->end(),true);
if(renum)
- return renumIfNeeded(m,eltsToKeep->getConstPointer());
+ return renumIfNeeded(m,eltsToKeep->begin());
return m;
}
if(renum==0)
return m;
if(cellIds==0)
- m->renumberCells(renum->getConstPointer(),true);
+ m->renumberCells(renum->begin(),true);
else
{
MCAuto<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
- m->renumberCells(locnum->getConstPointer(),true);
+ m->renumberCells(locnum->begin(),true);
}
return m;
}
da->incrRef();
return const_cast<DataArrayInt *>(da);
}
- return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
+ return renum->selectByTupleId(da->begin(),da->end());
}
DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
MCAuto<DataArrayDouble> getCoords() const { return _coords; }
MCAuto<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
MCAuto<DataArrayInt> getCoordsNum() const { return _num_coords; }
+ MCAuto<DataArrayInt> getCoordsGlobalNum() const { return _global_num_coords; }
MCAuto<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
- static void WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
+ static void WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayInt *globalNumCoords);
private:
void sortTypes();
private:
MCAuto<DataArrayDouble> _coords;
MCAuto<DataArrayInt> _fam_coords;
MCAuto<DataArrayInt> _num_coords;
+ MCAuto<DataArrayInt> _global_num_coords;
MCAuto<DataArrayAsciiChar> _name_coords;
};
MEDFileUMeshAggregateCompute _m_by_types;
MCAuto<DataArrayInt> _fam;
MCAuto<DataArrayInt> _num;
+ MCAuto<DataArrayInt> _global_num;
MCAuto<DataArrayAsciiChar> _names;
mutable MCAuto<DataArrayInt> _rev_num;
MEDFileUMeshPermCompute _m;
return _code & 0x00000020;
}
+bool MEDFileMeshReadSelector::isGlobalNodeNumFieldReading() const
+{
+ return _code & 0x00000040;
+}
+
void MEDFileMeshReadSelector::setCellFamilyFieldReading(bool b)
{
unsigned int code(_code & 0xFFFFFFFE);
_code=code;
}
+void MEDFileMeshReadSelector::setGlobalNodeNumFieldReading(bool b)
+{
+ unsigned int code(_code & 0xFFFFFFBF);
+ unsigned int b2=b?1:0;
+ b2<<=6;
+ code+=b2;
+ _code=code;
+}
+
void MEDFileMeshReadSelector::reprAll(std::ostream& str) const
{
str << "MEDFileMeshReadSelector (code=" << _code << ") : \n";
str << "Read name field on cells : " << ReprStatus(isCellNameFieldReading()) << std::endl;
str << "Read name field on nodes : " << ReprStatus(isNodeNameFieldReading()) << std::endl;
str << "Read number field on cells : " << ReprStatus(isCellNumFieldReading()) << std::endl;
- str << "Read number field name on nodes : " << ReprStatus(isNodeNumFieldReading());
+ str << "Read number field name on nodes : " << ReprStatus(isNodeNumFieldReading()) << std::endl;
+ str << "Read global number field name on nodes : " << ReprStatus(isGlobalNodeNumFieldReading());
}
std::string MEDFileMeshReadSelector::ReprStatus(bool v)
bool isNodeNameFieldReading() const;
bool isCellNumFieldReading() const;
bool isNodeNumFieldReading() const;
+ bool isGlobalNodeNumFieldReading() const;
void setCellFamilyFieldReading(bool b);
void setNodeFamilyFieldReading(bool b);
void setCellNameFieldReading(bool b);
void setNodeNameFieldReading(bool b);
void setCellNumFieldReading(bool b);
void setNodeNumFieldReading(bool b);
+ void setGlobalNodeNumFieldReading(bool b);
void reprAll(std::ostream& str) const;
private:
static std::string ReprStatus(bool v);
class MEDFileField1TS;
class MEDFileIntFieldMultiTS;
class MEDFileIntField1TS;
+ class MEDFileFloatFieldMultiTS;
+ class MEDFileFloatField1TS;
class MEDFileField1TSWithoutSDA;
class MEDFileIntField1TSWithoutSDA;
+ class MEDFileFloatField1TSWithoutSDA;
+ class MEDFileFieldMultiTSWithoutSDA;
+ class MEDFileIntFieldMultiTSWithoutSDA;
+ class MEDFileFloatFieldMultiTSWithoutSDA;
template<>
struct MEDLOADER_EXPORT MLFieldTraits<double>
{
+ typedef MEDFileFieldMultiTSWithoutSDA FMTSWSDAType;
typedef MEDFileFieldMultiTS FMTSType;
typedef MEDFileField1TS F1TSType;
typedef MEDFileField1TSWithoutSDA F1TSWSDAType;
};
+
+ template<>
+ struct MEDLOADER_EXPORT MLFieldTraits<float>
+ {
+ typedef MEDFileFloatFieldMultiTSWithoutSDA FMTSWSDAType;
+ typedef MEDFileFloatFieldMultiTS FMTSType;
+ typedef MEDFileFloatField1TS F1TSType;
+ typedef MEDFileFloatField1TSWithoutSDA F1TSWSDAType;
+ };
template<>
struct MEDLOADER_EXPORT MLFieldTraits<int>
{
+ typedef MEDFileIntFieldMultiTSWithoutSDA FMTSWSDAType;
typedef MEDFileIntFieldMultiTS FMTSType;
typedef MEDFileIntField1TS F1TSType;
typedef MEDFileIntField1TSWithoutSDA F1TSWSDAType;
#include "NormalizedUnstructuredMesh.hxx"
#include "MEDCouplingRefCountObject.hxx"
#include "SauvUtilities.hxx"
+#include "MCType.hxx"
#include <vector>
#include <set>
#include "NormalizedUnstructuredMesh.hxx"
#include "SauvUtilities.hxx"
#include "MCAuto.hxx"
+#include "MCType.hxx"
#include <vector>
#include <string>
ADD_DEFINITIONS(${PYTHON_DEFINITIONS} ${NUMPY_DEFINITIONS} ${SCIPY_DEFINITIONS})
SET_SOURCE_FILES_PROPERTIES(MEDLoader.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(MEDLoader.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(MEDLoader.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(MEDLoader.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_MEDLoader_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
SET (MEDLoader_SWIG_DPYS_FILES
SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/MEDLoader.py ${MEDCOUPLING_INSTALL_PYTHON})
-INSTALL(FILES MEDLoaderDataForTest.py MEDLoaderTest1.py MEDLoaderTest2.py MEDLoaderTest3.py MEDLoaderTest123.py MEDLoaderTest4.py SauvLoaderTest.py MEDLoaderExamplesTest.py MEDLoaderCouplingTrainingSession.py CaseIO.py CaseReader.py CaseWriter.py VTKReader.py MEDLoaderSplitter.py medutilities.py DESTINATION ${MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS})
+INSTALL(FILES MEDLoaderSplitter.py DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
+
+INSTALL(FILES MEDLoaderDataForTest.py MEDLoaderTest1.py MEDLoaderTest2.py MEDLoaderTest3.py MEDLoaderTest123.py MEDLoaderTest4.py SauvLoaderTest.py MEDLoaderExamplesTest.py MEDLoaderCouplingTrainingSession.py CaseIO.py CaseReader.py CaseWriter.py VTKReader.py medutilities.py DESTINATION ${MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS})
+
INSTALL(FILES med2sauv PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
INSTALL(FILES sauv2med PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
INSTALL(FILES case2med PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
dictMCTyp={NORM_HEXA8:"hexa8",NORM_POLYHED:"nfaced",NORM_QUAD4:"quad4",NORM_POLYGON:"nsided",NORM_POINT1:"point",NORM_SEG2:"bar2",NORM_SEG3:"bar3",NORM_TRI3:"tria3",NORM_TRI6:"tria6",NORM_QUAD8:"quad8",NORM_TETRA4:"tetra4",NORM_TETRA10:"tetra10",NORM_PYRA5:"pyramid5",NORM_PYRA13:"pyramid13",NORM_PENTA6:"penta6",NORM_PENTA15:"penta15",NORM_HEXA20:"hexa20"}
discSpatial={ON_CELLS:"element",ON_NODES:"node"}
dictCompo={1:"scalar",3:"vector",6:"tensor",9:"tensor9"}
- dictMCTyp2=dict((v,k) for k,v in dictMCTyp.iteritems())
- discSpatial2=dict((v,k) for k,v in discSpatial.iteritems())
- dictCompo2=dict((v,k) for k,v in dictCompo.iteritems())
+ dictMCTyp2 = {v:k for k, v in dictMCTyp.items()}
+ discSpatial2 = {v:k for k, v in discSpatial.items()}
+ dictCompo2 = {v:k for k, v in dictCompo.items()}
pass
pos+=nbNodes*3*4 ; fd.seek(pos)#np.array(0,dtype='float%i'%(typeOfCoo)).nbytes
typ=fd.read(80).strip() ; pos=fd.tell()
zeK=""
- for k in self.dictMCTyp2.keys():
+ for k in self.dictMCTyp2:
if k in typ:
zeK=k
break
nbOfValsOfTyp=np.memmap(fd,dtype='>i4',mode='r',offset=pos,shape=(1)).tolist()[0]/4
pos+=4
vals=np.zeros(dtype=">f4",shape=(nbOfValsOfTyp*nbCompo))
- for iii in xrange(nbCompo):
+ for iii in range(nbCompo):
valsTmp=np.memmap(fd,dtype='>f4',mode='r',offset=int(pos),shape=(nbOfValsOfTyp))
vals[iii*nbOfValsOfTyp:(iii+1)*nbOfValsOfTyp]=valsTmp
pos+=nbOfValsOfTyp*4
if "TIME\n" in lines:
end=lines.index("TIME\n")
pass
- for i in xrange(ind+1,end):
+ for i in range(ind + 1, end):
m=re.match("^([\w]+)[\s]+\per[\s]+([\w]+)[\s]*\:[\s]*([\w]+)[\s]+([\S]+)$",lines[i])
if m:
if m.groups()[0]=="constant":
pass
expr=re.compile("number[\s]+of[\s]+steps[\s]*\:[\s]*([\d]+)")
- tmp=filter(expr.search,lines)
- if len(tmp)!=0:
- nbOfTimeSteps=int(expr.search(filter(expr.search,lines)[0]).group(1))
+ tmp = [line for line in lines if expr.search(line)]
+ if tmp:
+ nbOfTimeSteps = int(expr.search(tmp[0]).group(1))
expr=re.compile("filename[\s]+start[\s]+number[\s]*\:[\s]*([\d]+)")
- startIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
+ startIt = int(expr.search([line for line in lines if expr.search(line)][0]).group(1))
expr=re.compile("filename[\s]+increment[\s]*\:[\s]*([\d]+)")
- incrIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
+ incrIt = int(expr.search([line for line in lines if expr.search(line)][0]).group(1))
else:
nbOfTimeSteps=1
startIt=0
i+=1
pass
pass
- for ts in xrange(nbOfTimeSteps):
+ for ts in range(nbOfTimeSteps):
i=0
for field in fieldsInfo:
if typeOfFile:
pass
ret=MEDFileData()
ret.setMeshes(m2)
- del mlfields[filter(lambda x: len(mlfields[x])==0,range(len(mlfields)))]
+ del mlfields[[x for x in range(len(mlfields)) if len(mlfields[x]) == 0]]
ret.setFields(mlfields)
return ret
self._ze_top_dict={}
its,areForgottenTS=mdfs.getCommonIterations()
if areForgottenTS:
- print "WARNING : some iterations are NOT present in all fields ! Kept iterations are : %s !"%(str(its))
+ print("WARNING : some iterations are NOT present in all fields ! Kept iterations are : %s !"%(str(its)))
pass
TimeValues=""
for it in its:
for mdf in mdfs:
nbCompo=mdf.getNumberOfComponents()
if nbCompo not in self.dictCompo:
- l=filter(lambda x:x-nbCompo>0,self.dictCompo.keys())
+ l = [x for x in self.dictCompo if x - nbCompo > 0]
if len(l)==0:
- print "Field \"%s\" will be ignored because number of components (%i) is too big to be %s supported by case files !"%(mdf.getName(),nbCompo,str(self.dictCompo.keys()))
+ print("Field \"%s\" will be ignored because number of components (%i) is too big to be %s supported by case files !"%(mdf.getName(),nbCompo,str(list(self.dictCompo.keys()))))
continue
pass
- print "WARNING : Field \"%s\" will have its number of components (%i) set to %i, in order to be supported by case files (must be in %s) !"%(mdf.getName(),nbCompo,l[0],str(self.dictCompo.keys()))
+ print("WARNING : Field \"%s\" will have its number of components (%i) set to %i, in order to be supported by case files (must be in %s) !"%(mdf.getName(),nbCompo,l[0],str(list(self.dictCompo.keys()))))
nbCompo=l[0]
pass
if nbCompo in dictVars:
for mdf in mdfs:
nbCompo=mdf.getNumberOfComponents()
if nbCompo not in self.dictCompo:
- l=filter(lambda x:x-nbCompo>0,self.dictCompo.keys())
+ l = [x for x in self.dictCompo if x - nbCompo > 0]
if len(l)==0:
continue;
nbCompo=l[0]
mm.write(self.__str80("coordinates"))
pass
else:
- print "UnManaged type of field for field \"%s\" !"%(mdf.getName())
+ print("UnManaged type of field for field \"%s\" !"%(mdf.getName()))
pass
a=np.memmap(f,dtype='float32',mode='w+',offset=mm.tell(),shape=(nbCompo,end-bg))
b=arr.toNumPyArray() ; b=b.reshape(nbCompo,end-bg)
#
finalVersion=ml.MEDFileVersionOfFileStr(realFnOut)
#
- print("File \"%s\" has been converted to 3.0 successfuly ( %s -> %s ) !\nOutput file is here : \"%s\" !"%(fn,initalVersion,finalVersion,realFnOut))
+ print(("File \"%s\" has been converted to 3.0 successfuly ( %s -> %s ) !\nOutput file is here : \"%s\" !"%(fn,initalVersion,finalVersion,realFnOut)))
pass
if __name__=="__main__":
import argparse
- parser=argparse.ArgumentParser(description=u'Convert a MED file into a MED file with 3.0 version (3.0.8)')
+ parser=argparse.ArgumentParser(description='Convert a MED file into a MED file with 3.0 version (3.0.8)')
parser.add_argument('nameOfMEDFile', type=str, nargs=1,help='File name of the MED file to be converted into 3.0.')
args=parser.parse_args()
nameOfMEDFile=args.nameOfMEDFile[0]
def MEDCouplingFieldDoubleIpow(self,*args):
import _MEDLoader
return _MEDLoader.MEDCouplingFieldDouble____ipow___(self, self, *args)
+def MEDCouplingFieldIntnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.MEDCouplingFieldInt____new___(cls,args)
+def MEDCouplingFieldFloatnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.MEDCouplingFieldFloat____new___(cls,args)
def MEDCouplingDataArrayBytenew(cls,*args):
import _MEDLoader
return _MEDLoader.DataArrayByte____new___(cls,args)
+def MEDCouplingDataArrayFloatnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.DataArrayFloat____new___(cls,args)
+def MEDCouplingDataArrayFloatIadd(self,*args):
+ import _MEDLoader
+ return _MEDLoader.DataArrayFloat____iadd___(self, self, *args)
+def MEDCouplingDataArrayFloatIsub(self,*args):
+ import _MEDLoader
+ return _MEDLoader.DataArrayFloat____isub___(self, self, *args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+ import _MEDLoader
+ return _MEDLoader.DataArrayFloat____imul___(self, self, *args)
+def MEDCouplingDataArrayFloatIdiv(self,*args):
+ import _MEDLoader
+ return _MEDLoader.DataArrayFloat____idiv___(self, self, *args)
def MEDCouplingDataArrayIntnew(cls,*args):
import _MEDLoader
return _MEDLoader.DataArrayInt____new___(cls,args)
def MEDCouplingMEDFileIntFieldMultiTSnew(cls,*args):
import _MEDLoader
return _MEDLoader.MEDFileIntFieldMultiTS____new___(cls,args)
+def MEDCouplingMEDFileFloatField1TSnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.MEDFileFloatField1TS____new___(cls,args)
+def MEDCouplingMEDFileFloatFieldMultiTSnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.MEDFileFloatFieldMultiTS____new___(cls,args)
def MEDCouplingMEDFileParametersnew(cls,*args):
import _MEDLoader
return _MEDLoader.MEDFileParameters____new___(cls,args)
%include "MEDCouplingFinalize.i"
+%pythoncode %{
+MEDFileMeshesIterator.__next__ = MEDFileMeshesIterator.next
+MEDFileAnyTypeFieldMultiTSIterator.__next__ = MEDFileAnyTypeFieldMultiTSIterator.next
+MEDFileFieldsIterator.__next__ = MEDFileFieldsIterator.next
+%}
+
%pythoncode %{
MEDFileUMesh.__new__=classmethod(MEDCouplingMEDFileUMeshnew)
del MEDCouplingMEDFileUMeshnew
del MEDCouplingMEDFileIntField1TSnew
MEDFileIntFieldMultiTS.__new__=classmethod(MEDCouplingMEDFileIntFieldMultiTSnew)
del MEDCouplingMEDFileIntFieldMultiTSnew
+MEDFileFloatField1TS.__new__=classmethod(MEDCouplingMEDFileFloatField1TSnew)
+del MEDCouplingMEDFileFloatField1TSnew
+MEDFileFloatFieldMultiTS.__new__=classmethod(MEDCouplingMEDFileFloatFieldMultiTSnew)
+del MEDCouplingMEDFileFloatFieldMultiTSnew
MEDFileParameters.__new__=classmethod(MEDCouplingMEDFileParametersnew)
del MEDCouplingMEDFileParametersnew
%}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
%module MEDLoader
%newobject MEDCoupling::MEDFileMesh::getNodeGroupsArr;
%newobject MEDCoupling::MEDFileMesh::getNodeFamilyArr;
%newobject MEDCoupling::MEDFileMesh::getNodeFamiliesArr;
+%newobject MEDCoupling::MEDFileMesh::getGlobalNumFieldAtLevel;
%newobject MEDCoupling::MEDFileMesh::getAllFamiliesIdsReferenced;
%newobject MEDCoupling::MEDFileMesh::computeAllFamilyIdsInUse;
%newobject MEDCoupling::MEDFileMesh::getEquivalences;
%newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtLevelOld;
%newobject MEDCoupling::MEDFileFieldMultiTS::getUndergroundDataArray;
%newobject MEDCoupling::MEDFileFieldMultiTS::convertToInt;
+
%newobject MEDCoupling::MEDFileIntFieldMultiTS::New;
%newobject MEDCoupling::MEDFileIntFieldMultiTS::field;
%newobject MEDCoupling::MEDFileIntFieldMultiTS::LoadSpecificEntities;
%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel;
%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldAtLevelOld;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::New;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::field;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::LoadSpecificEntities;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::getUndergroundDataArray;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::convertToDouble;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::getFieldAtLevel;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::getFieldAtTopLevel;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::getFieldOnMeshAtLevel;
+%newobject MEDCoupling::MEDFileFloatFieldMultiTS::getFieldAtLevelOld;
+
%newobject MEDCoupling::MEDFileAnyTypeField1TS::New;
%newobject MEDCoupling::MEDFileAnyTypeField1TS::NewAdv;
%newobject MEDCoupling::MEDFileAnyTypeField1TS::shallowCpy;
%newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray;
%newobject MEDCoupling::MEDFileIntField1TS::convertToDouble;
+%newobject MEDCoupling::MEDFileFloatField1TS::New;
+%newobject MEDCoupling::MEDFileFloatField1TS::field;
+%newobject MEDCoupling::MEDFileFloatField1TS::getFieldAtLevel;
+%newobject MEDCoupling::MEDFileFloatField1TS::getFieldAtTopLevel;
+%newobject MEDCoupling::MEDFileFloatField1TS::getFieldOnMeshAtLevel;
+%newobject MEDCoupling::MEDFileFloatField1TS::getFieldAtLevelOld;
+%newobject MEDCoupling::MEDFileFloatField1TS::getUndergroundDataArray;
+%newobject MEDCoupling::MEDFileFloatField1TS::convertToDouble;
+
%newobject MEDCoupling::MEDFileData::New;
%newobject MEDCoupling::MEDFileData::deepCopy;
%newobject MEDCoupling::MEDFileData::getMeshes;
%newobject MEDCoupling::MEDFileJointCorrespondence::New;
%newobject MEDCoupling::MEDFileJointCorrespondence::deepCopy;
%newobject MEDCoupling::MEDFileJointCorrespondence::shallowCpy;
+%newobject MEDCoupling::MEDFileJointCorrespondence::getCorrespondence;
%newobject MEDCoupling::MEDFileJointOneStep::New;
%newobject MEDCoupling::MEDFileJointOneStep::deepCopy;
%newobject MEDCoupling::MEDFileJointOneStep::shallowCpy;
+%newobject MEDCoupling::MEDFileJointOneStep::getCorrespondenceAtPos;
+%newobject MEDCoupling::MEDFileJointOneStep::__getitem__;
%newobject MEDCoupling::MEDFileJoint::New;
%newobject MEDCoupling::MEDFileJoint::deepCopy;
%newobject MEDCoupling::MEDFileJoint::shallowCpy;
+%newobject MEDCoupling::MEDFileJoint::getStepAtPos;
+%newobject MEDCoupling::MEDFileJoint::__getitem__;
%newobject MEDCoupling::MEDFileJoints::New;
%newobject MEDCoupling::MEDFileJoints::deepCopy;
%newobject MEDCoupling::MEDFileJoints::getJointAtPos;
%feature("unref") MEDFileAnyTypeField1TS "$this->decrRef();"
%feature("unref") MEDFileField1TS "$this->decrRef();"
%feature("unref") MEDFileIntField1TS "$this->decrRef();"
+%feature("unref") MEDFileFloatField1TS "$this->decrRef();"
%feature("unref") MEDFileAnyTypeFieldMultiTS "$this->decrRef();"
%feature("unref") MEDFileFieldMultiTS "$this->decrRef();"
%feature("unref") MEDFileIntFieldMultiTS "$this->decrRef();"
+%feature("unref") MEDFileFloatFieldMultiTS "$this->decrRef();"
%feature("unref") MEDFileMeshSupports "$this->decrRef();"
%feature("unref") MEDFileStructureElements "$this->decrRef();"
%feature("unref") MEDFileFields "$this->decrRef();"
bool isNodeNameFieldReading() const;
bool isCellNumFieldReading() const;
bool isNodeNumFieldReading() const;
+ bool isGlobalNodeNumFieldReading() const;
void setCellFamilyFieldReading(bool b);
void setNodeFamilyFieldReading(bool b);
void setCellNameFieldReading(bool b);
void setNodeNameFieldReading(bool b);
void setCellNumFieldReading(bool b);
void setNodeNumFieldReading(bool b);
+ void setGlobalNodeNumFieldReading(bool b);
%extend
{
std::string __str__() const throw(INTERP_KERNEL::Exception)
void setRemoteGeometryType(INTERP_KERNEL::NormalizedCellType type);
INTERP_KERNEL::NormalizedCellType getRemoteGeometryType() const;
void setCorrespondence(DataArrayInt *corr) throw(INTERP_KERNEL::Exception);
- const DataArrayInt *getCorrespondence() const throw(INTERP_KERNEL::Exception);
void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const throw(INTERP_KERNEL::Exception);
std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
%extend
{
return self->simpleRepr();
}
+
+ DataArrayInt *getCorrespondence() const throw(INTERP_KERNEL::Exception)
+ {
+ const DataArrayInt *ret(self->getCorrespondence());
+ if(ret)
+ ret->incrRef();
+ return const_cast<DataArrayInt *>(ret);
+ }
}
};
int getIteration() const;
void pushCorrespondence(MEDFileJointCorrespondence* correspondence);
int getNumberOfCorrespondences() const;
- MEDFileJointCorrespondence *getCorrespondenceAtPos(int i) const;
void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const throw(INTERP_KERNEL::Exception);
std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
%extend
{
return self->simpleRepr();
}
+
+ MEDFileJointCorrespondence *getCorrespondenceAtPos(int i) const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileJointCorrespondence *ret(self->getCorrespondenceAtPos(i));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDFileJointCorrespondence *__getitem__(int i) const throw(INTERP_KERNEL::Exception)
+ {
+ return MEDCoupling_MEDFileJointOneStep_getCorrespondenceAtPos(self,i);
+ }
}
};
public:
static MEDFileJoint *New() throw(INTERP_KERNEL::Exception);
static MEDFileJoint *New(const std::string& fileName, const std::string& mName, int num) throw(INTERP_KERNEL::Exception);
- static MEDFileJoint *New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum ) throw(INTERP_KERNEL::Exception);
+ static MEDFileJoint *New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum) throw(INTERP_KERNEL::Exception);
MEDFileJoint *deepCopy() const;
MEDFileJoint *shallowCpy() const;
bool isEqual(const MEDFileJoint *other) const;
int getDomainNumber() const;
void pushStep(MEDFileJointOneStep* step);
int getNumberOfSteps() const;
- MEDFileJointOneStep *getStepAtPos(int i) const;
std::string simpleRepr() const;
%extend
{
return MEDFileJoint::New(fileName,mName,num);
}
+ MEDFileJoint(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileJoint::New(jointName,locMeshName,remoteMeshName,remoteMeshNum);
+ }
+
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
return self->simpleRepr();
}
+
+ MEDFileJointOneStep *getStepAtPos(int i) const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileJointOneStep *ret(self->getStepAtPos(i));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDFileJointOneStep *__getitem__(int i) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDCoupling_MEDFileJoint_getStepAtPos(self,i);
+ }
}
};
MEDFileJoint *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
+ static const char msg[]="MEDFileJoints::__getitem__ : only integer or string with meshname supported !";
if(PyInt_Check(obj))
{
MEDFileJoint *ret=self->getJointAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfJoints()));
ret->incrRef();
return ret;
}
- else if(PyString_Check(obj))
- {
- MEDFileJoint *ret=self->getJointWithName(PyString_AsString(obj));
- if(ret)
- ret->incrRef();
- return ret;
- }
- else
- throw INTERP_KERNEL::Exception("MEDFileJoints::__getitem__ : only integer or string with meshname supported !");
+ MEDFileJoint *ret(self->getJointWithName(convertPyObjectToStr(obj,msg)));
+ if(ret)
+ ret->incrRef();
+ return ret;
}
int __len__() const throw(INTERP_KERNEL::Exception)
virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
virtual void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception);
+ virtual void setGlobalNumFieldAtLevel(int meshDimRelToMaxExt, DataArrayInt *globalNumArr) throw(INTERP_KERNEL::Exception);
virtual void addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
virtual void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
if(ret) ret->incrRef();
return ret;
}
+
+ virtual DataArrayInt *getGlobalNumFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayInt> ret(self->getGlobalNumFieldAtLevel(meshDimRelToMaxExt));
+ return ret.retn();
+ }
}
};
MEDFileMesh *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- if(PyInt_Check(obj))
+ static const char msg[]="MEDFileMeshes::__getitem__ : only integer or string with meshname supported !";
+ if(PyInt_Check(obj))
{
MEDFileMesh *ret=self->getMeshAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfMeshes()));
if(ret)
ret->incrRef();
return ret;
}
- else if(PyString_Check(obj))
- {
- MEDFileMesh *ret=self->getMeshWithName(PyString_AsString(obj));
- if(ret)
- ret->incrRef();
- return ret;
- }
- else
- throw INTERP_KERNEL::Exception("MEDFileMeshes::__getitem__ : only integer or string with meshname supported !");
+ MEDFileMesh *ret(self->getMeshWithName(convertPyObjectToStr(obj,msg)));
+ if(ret)
+ ret->incrRef();
+ return ret;
}
MEDFileMeshes *__setitem__(int obj, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
}
};
+ class MEDFileFloatField1TS : public MEDFileAnyTypeField1TS
+ {
+ public:
+ static MEDFileFloatField1TS *New();
+ static MEDFileFloatField1TS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ static MEDFileFloatField1TS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
+ static MEDFileFloatField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ static MEDFileFloatField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ MEDCoupling::MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
+ //
+ void setFieldNoProfileSBT(const MEDCouplingFieldFloat *field) throw(INTERP_KERNEL::Exception);
+ void setFieldProfile(const MEDCouplingFieldFloat *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ MEDFileFloatField1TS() throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatField1TS::New();
+ }
+
+ MEDFileFloatField1TS(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatField1TS::New(fileName,loadAll);
+ }
+
+ MEDFileFloatField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatField1TS::New(fileName,fieldName,loadAll);
+ }
+
+ MEDFileFloatField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatField1TS::New(fileName,fieldName,iteration,order,loadAll);
+ }
+
+ MEDFileFloatField1TS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatField1TS::New(db);
+ }
+
+ // serialization
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileFloatField1TS");
+ }
+
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->simpleRepr();
+ }
+
+ PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret1=0;
+ DataArrayFloat *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayFloat, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ DataArrayFloat *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayFloat *ret=self->getUndergroundDataArray();
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ }
+ };
+
class MEDFileAnyTypeFieldMultiTSIterator
{
public:
if(PySlice_Check(elts))
{
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
- GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
+ GetIndicesOfSlice(elts,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
self->eraseTimeStepIds2(strt,stp,step);
}
else
std::vector<int> pos2;
DataArrayInt *pos3=0;
DataArrayIntTuple *pos4=0;
- convertObjToPossibleCpp1(li,sw,pos1,pos2,pos3,pos4);
+ convertIntStarLikePyObjToCpp(li,sw,pos1,pos2,pos3,pos4);
switch(sw)
{
case 1:
else if(elt0 && PySlice_Check(elt0))
{
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(elt0);
- GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
+ GetIndicesOfSlice(elt0,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
return convertMEDFileFieldMultiTS(self->buildSubPartSlice(strt,stp,step),SWIG_POINTER_OWN | 0);
}
else
}
};
+ class MEDFileIntFieldMultiTS;
+
class MEDFileFieldMultiTS : public MEDFileAnyTypeFieldMultiTS
{
public:
MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
- MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
//
void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception);
void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception);
- MEDCoupling::MEDFileIntFieldMultiTS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
+ MEDFileIntFieldMultiTS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
%extend
{
MEDFileFieldMultiTS()
static MEDFileIntFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, PyObject *entities, bool loadAll=true)
{
std::vector<std::pair<int,int> > tmp(convertTimePairIdsFromPy(entities));
- std::size_t sz(tmp.size());
- std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesCpp(sz);
- for(std::size_t i=0;i<sz;i++)
- {
- entitiesCpp[i].first=(TypeOfField)tmp[i].first;
- entitiesCpp[i].second=(INTERP_KERNEL::NormalizedCellType)tmp[i].second;
- }
+ std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesCpp(convertVecPairIntToVecPairTOFCT(tmp));
return MEDFileIntFieldMultiTS::LoadSpecificEntities(fileName,fieldName,entitiesCpp,loadAll);
}
}
}
};
+
+ class MEDFileFloatFieldMultiTS : public MEDFileAnyTypeFieldMultiTS
+ {
+ public:
+ static MEDFileFloatFieldMultiTS *New();
+ static MEDFileFloatFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ static MEDFileFloatFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ static MEDFileFloatFieldMultiTS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
+ //
+ void appendFieldNoProfileSBT(const MEDCouplingFieldFloat *field) throw(INTERP_KERNEL::Exception);
+ void appendFieldProfile(const MEDCouplingFieldFloat *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception);
+ MEDCoupling::MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ MEDFileFloatFieldMultiTS()
+ {
+ return MEDFileFloatFieldMultiTS::New();
+ }
+
+ MEDFileFloatFieldMultiTS(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatFieldMultiTS::New(fileName,loadAll);
+ }
+
+ MEDFileFloatFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatFieldMultiTS::New(fileName,fieldName,loadAll);
+ }
+
+ MEDFileFloatFieldMultiTS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+ {
+ return MEDFileFloatFieldMultiTS::New(db);
+ }
+
+ // serialization
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileFloatFieldMultiTS");
+ }
+
+ static MEDFileFloatFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, PyObject *entities, bool loadAll=true)
+ {
+ std::vector<std::pair<int,int> > tmp(convertTimePairIdsFromPy(entities));
+ std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesCpp(convertVecPairIntToVecPairTOFCT(tmp));
+ return MEDFileFloatFieldMultiTS::LoadSpecificEntities(fileName,fieldName,entitiesCpp,loadAll);
+ }
+
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->simpleRepr();
+ }
+
+ PyObject *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret1=0;
+ DataArrayFloat *ret0=self->getFieldWithProfile(type,iteration,order,meshDimRelToMax,mesh,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayFloat, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ DataArrayFloat *getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayFloat *ret=self->getUndergroundDataArray(iteration,order);
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ }
+ };
class MEDFileMeshSupports : public RefCountObject, public MEDFileWritableStandAlone
{
int getPosOfField(PyObject *elt0) const throw(INTERP_KERNEL::Exception)
{
- if(elt0 && PyInt_Check(elt0))
+ static const char msg[]="MEDFileFields::getPosOfField : invalid input params ! expected fields[int], fields[string_of_field_name] !";
+ if(!elt0)
+ throw INTERP_KERNEL::Exception(msg);
+ if(PyInt_Check(elt0))
{//fmts[3]
return PyInt_AS_LONG(elt0);
}
- else if(elt0 && PyString_Check(elt0))
- return self->getPosFromFieldName(PyString_AsString(elt0));
- else
- throw INTERP_KERNEL::Exception("MEDFileFields::getPosOfField : invalid input params ! expected fields[int], fields[string_of_field_name] !");
+ return self->getPosFromFieldName(convertPyObjectToStr(elt0,msg));
}
std::vector<int> getPosOfFields(PyObject *elts) const throw(INTERP_KERNEL::Exception)
if(elts && PySlice_Check(elts))
{
Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
- GetIndicesOfSlice(oC,self->getNumberOfFields(),&strt,&stp,&step,"MEDFileFields.__delitem__ : error in input slice !");
+ GetIndicesOfSlice(elts,self->getNumberOfFields(),&strt,&stp,&step,"MEDFileFields.__delitem__ : error in input slice !");
self->destroyFieldsAtPos2(strt,stp,step);
}
else
std::vector<int> pos2;
DataArrayInt *pos3=0;
DataArrayIntTuple *pos4=0;
- convertObjToPossibleCpp1(ids,sw,pos1,pos2,pos3,pos4);
+ convertIntStarLikePyObjToCpp(ids,sw,pos1,pos2,pos3,pos4);
switch(sw)
{
case 1:
MEDFileParameterMultiTS *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
+ static const char msg[]="MEDFileParameters::__getitem__ : only integer or string with meshname supported !";
if(PyInt_Check(obj))
{
MEDFileParameterMultiTS *ret=self->getParamAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfParams()));
ret->incrRef();
return ret;
}
- else if(PyString_Check(obj))
- {
- MEDFileParameterMultiTS *ret=self->getParamWithName(PyString_AsString(obj));
- if(ret)
- ret->incrRef();
- return ret;
- }
- else
- throw INTERP_KERNEL::Exception("MEDFileParameters::__getitem__ : only integer or string with meshname supported !");
+ MEDFileParameterMultiTS *ret(self->getParamWithName(convertPyObjectToStr(obj,msg)));
+ if(ret)
+ ret->incrRef();
+ return ret;
}
int __len__() const throw(INTERP_KERNEL::Exception)
d=DataArrayDouble.New(6,2)
d[:,0]=3.
-d[:,1]=range(6)
+d[:, 1] = list(range(6))
d[:,1]*=math.pi/3.
d=d.fromPolarToCart()
d.setInfoOnComponents(["X [m]","Y [m]"])
-print d.getValues()
-print d
-print d.magnitude().isUniform(3.,1e-12)
+print(d.getValues())
+print(d)
+print(d.magnitude().isUniform(3.,1e-12))
#
radius=3.
translationToPerform=[[0.,0.],[3./2.*radius,-radius*math.sqrt(3.)/2],[3./2.*radius,radius*math.sqrt(3.)/2],[0.,radius*math.sqrt(3.)],[-3./2.*radius,radius*math.sqrt(3.)/2],[-3./2.*radius,-radius*math.sqrt(3.)/2],[0.,-radius*math.sqrt(3.)]]
oldNbOfTuples=d2.getNumberOfTuples()
c,cI=d2.findCommonTuples(1e-12)
tmp=c[cI[0]:cI[0+1]]
-print tmp
+print(tmp)
a=cI.deltaShiftIndex()
b=a-1
myNewNbOfTuples=oldNbOfTuples-sum(b.getValues())
o2n,newNbOfTuples=DataArrayInt.ConvertIndexArrayToO2N(oldNbOfTuples,c,cI)
-print "Ai je trouve le bon resultat ? %s"%(str(myNewNbOfTuples==newNbOfTuples)) ; assert myNewNbOfTuples==newNbOfTuples
+print("Ai je trouve le bon resultat ? %s"%(str(myNewNbOfTuples==newNbOfTuples))) ; assert myNewNbOfTuples==newNbOfTuples
#
d3=d2.renumberAndReduce(o2n,newNbOfTuples)
n2o=o2n.invertArrayO2N2N2O(newNbOfTuples)
d3_bis=d2[n2o]
-print "Ai je trouve le bon resultat (2) ? %s"%(str(d3.isEqual(d3_bis,1e-12))) ; assert d3.isEqual(d3_bis,1e-12)
+print("Ai je trouve le bon resultat (2) ? %s"%(str(d3.isEqual(d3_bis,1e-12)))) ; assert d3.isEqual(d3_bis,1e-12)
#
d3+=[3.3,4.4]
# d3 contains coordinates
m=MEDCouplingUMesh.New("My7hexagons",2)
m.setCoords(d3)
m.allocateCells(7)
-for i in xrange(7):
+for i in range(7):
m.insertNextCell(NORM_POLYGON,o2n[6*i:6*(i+1)].getValues())
pass
m.finishInsertingCells()
mesh3D.orientCorrectlyPolyhedrons()
mesh3D.sortCellsInMEDFileFrmt()
mesh3D.checkConsistencyLight()
-renum=DataArrayInt.New(60) ; renum[:15]=range(15,30) ; renum[15:30]=range(15) ; renum[30:45]=range(45,60) ; renum[45:]=range(30,45)
+renum = DataArrayInt.New(60) ; renum[:15] = list(range(15, 30)) ; renum[15:30] = list(range(15)) ; renum[30:45] = list(range(45, 60)) ; renum[45:] = list(range(30, 45))
mesh3D.renumberNodes(renum,60)
#
mesh3D.getCoords()[:]*=100.
mesh3D.getCoords().setInfoOnComponents(["X [cm]","Y [cm]","Z [cm]"])
#
zLev=mesh3D.getCoords()[:,2]
-zLev=zLev.getDifferentValues(1e-12)
+zLev = zLev.getDifferentValues(1e-12)
zLev.sort()
#
tmp,cellIdsSol1=mesh3D.buildSlice3D([0.,0.,(zLev[1]+zLev[2])/2],[0.,0.,1.],1e-12)
mesh2D=mesh3D.buildFacePartOfMySelfNode(nodeIds,True)
extMesh=MEDCouplingMappedExtrudedMesh.New(mesh3D,mesh2D,0)
cellIdsSol3=extMesh.getMesh3DIds()[mesh2D.getNumberOfCells():2*mesh2D.getNumberOfCells()]
-for i in xrange(3):
- exec("print cellIdsSol%s.getValues()"%(i+1))
+for i in range(3):
+ exec("print( cellIdsSol%s.getValues())"%(i+1))
#
mesh3DPart=mesh3D[cellIdsSol2] # equivalent to mesh3DPart=mesh3D.buildPartOfMySelf(cellIdsSol2,True)
mesh3DPart.zipCoords()
-print mesh3DPart.checkConsecutiveCellTypesAndOrder([NORM_HEXA8,NORM_POLYHED]) ; assert mesh3DPart.checkConsecutiveCellTypesAndOrder([NORM_HEXA8,NORM_POLYHED])
-print mesh3DPart.checkConsecutiveCellTypes() ; assert mesh3DPart.checkConsecutiveCellTypes()
+print(mesh3DPart.checkConsecutiveCellTypesAndOrder([NORM_HEXA8,NORM_POLYHED])) ; assert mesh3DPart.checkConsecutiveCellTypesAndOrder([NORM_HEXA8,NORM_POLYHED])
+print(mesh3DPart.checkConsecutiveCellTypes()) ; assert mesh3DPart.checkConsecutiveCellTypes()
#print mesh3DPart.advancedRepr()
#
baryXY=bary[:,[0,1]]
magn=bary2.magnitude()
ids=magn.findIdsInRange(0.,1e-12)
idStart=int(ids) # ids is assumed to contain only one value, if not an exception is thrown
-cellIds2Sol2=extMesh.getMesh3DIds()[range(idStart,mesh3D.getNumberOfCells(),mesh2D.getNumberOfCells())]
+cellIds2Sol2 = extMesh.getMesh3DIds()[list(range(idStart, mesh3D.getNumberOfCells(), mesh2D.getNumberOfCells()))]
#
mesh3DSlice2=mesh3D[cellIds2Sol1]
mesh3DSlice2.zipCoords()
f2.setMesh(mesh)
f2.setName("MyField2")
f2.fillFromAnalytic(1,"(x-5.)*(x-5.)+(y-5.)*(y-5.)+(z-5.)*(z-5.)")
-print "f and f2 are equal : %s"%(f.isEqualWithoutConsideringStr(f2,1e-13,1e-12)) ; assert f.isEqualWithoutConsideringStr(f2,1e-13,1e-12)
+print("f and f2 are equal : %s"%(f.isEqualWithoutConsideringStr(f2,1e-13,1e-12))) ; assert f.isEqualWithoutConsideringStr(f2,1e-13,1e-12)
#
ids1=f.getArray().findIdsInRange(0.,5.)
fPart1=f.buildSubPart(ids1)
#Check that fPart1Cpy and fPart1 are the same
fPart1Cpy.substractInPlaceDM(fPart1,12,1e-12)
fPart1Cpy.getArray().abs()
-print "Fields are the same ? %s"%(fPart1Cpy.getArray().accumulate()[0]<1e-12) ; assert fPart1Cpy.getArray().accumulate()[0]<1e-12
+print("Fields are the same ? %s"%(fPart1Cpy.getArray().accumulate()[0]<1e-12)) ; assert fPart1Cpy.getArray().accumulate()[0]<1e-12
#
fPart12=MEDCouplingFieldDouble.MergeFields([fPart1,fPart2])
# evaluation on points
arr2=f.getValueOnMulti(bary)
delta=arr1-arr2
delta.abs()
-print "Check OK : %s"%(delta.accumulate()[0]<1e-12) ; assert delta.accumulate()[0]<1e-12
+print("Check OK : %s"%(delta.accumulate()[0]<1e-12)) ; assert delta.accumulate()[0]<1e-12
#
-print abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0])<1e-10 ; assert abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0])<1e-10
+print(abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0])<1e-10) ; assert abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0])<1e-10
fPart12.getMesh().scale([0.,0.,0.],1.2)
-print abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0]*1.2*1.2*1.2)<1e-8 ; assert abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0]*1.2*1.2*1.2)<1e-8
+print(abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0]*1.2*1.2*1.2)<1e-8) ; assert abs(fPart12.integral(0,True)-fPart12.getArray().accumulate()[0]*1.2*1.2*1.2)<1e-8
# Explosion of field
fVec=mesh.fillFromAnalytic(ON_CELLS,3,"(x-5.)*IVec+(y-5.)*JVec+(z-5.)*KVec")
fVecPart1=fVec.buildSubPart(ids1)
WriteUMesh("TargetMesh.med",targetMesh,True)
#
meshRead=ReadUMeshFromFile("TargetMesh.med",targetMesh.getName(),0)
-print "Is the mesh read in file equals targetMesh ? %s"%(meshRead.isEqual(targetMesh,1e-12)) ; assert meshRead.isEqual(targetMesh,1e-12)
+print("Is the mesh read in file equals targetMesh ? %s"%(meshRead.isEqual(targetMesh,1e-12))) ; assert meshRead.isEqual(targetMesh,1e-12)
#
f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
f.setTime(5.6,7,8)
WriteField("MyFirstField.med",f,True)
#
f2=ReadFieldCell("MyFirstField.med",f.getMesh().getName(),0,f.getName(),7,8)
-print "Is the field read in file equals f ? %s"%(f2.isEqual(f,1e-12,1e-12)) ; assert f2.isEqual(f,1e-12,1e-12)
+print("Is the field read in file equals f ? %s"%(f2.isEqual(f,1e-12,1e-12))) ; assert f2.isEqual(f,1e-12,1e-12)
#
WriteUMesh("MySecondField.med",f.getMesh(),True)
WriteFieldUsingAlreadyWrittenMesh("MySecondField.med",f)
WriteFieldUsingAlreadyWrittenMesh("MySecondField.med",f2)
#
f3=ReadFieldCell("MySecondField.med",f.getMesh().getName(),0,f.getName(),7,8)
-print "Is the field read in file equals f ? %s"%(f.isEqual(f3,1e-12,1e-12)) ; assert f.isEqual(f3,1e-12,1e-12)
+print("Is the field read in file equals f ? %s"%(f.isEqual(f3,1e-12,1e-12))) ; assert f.isEqual(f3,1e-12,1e-12)
f4=ReadFieldCell("MySecondField.med",f.getMesh().getName(),0,f.getName(),9,10)
-print "Is the field read in file equals f ? %s"%(f2.isEqual(f4,1e-12,1e-12)) ; assert f2.isEqual(f4,1e-12,1e-12)
+print("Is the field read in file equals f ? %s"%(f2.isEqual(f4,1e-12,1e-12))) ; assert f2.isEqual(f4,1e-12,1e-12)
#####
meshMEDFileRead=MEDFileMesh.New("TargetMesh2.med")
meshRead0=meshMEDFileRead.getMeshAtLevel(0)
meshRead1=meshMEDFileRead.getMeshAtLevel(-1)
-print "Is the mesh at level 0 read in file equals targetMesh ? %s"%(meshRead0.isEqual(targetMesh,1e-12)) ; assert meshRead0.isEqual(targetMesh,1e-12)
-print "Is the mesh at level -1 read in file equals targetMesh ? %s"%(meshRead1.isEqual(targetMesh1,1e-12)) ; assert meshRead1.isEqual(targetMesh1,1e-12)
+print("Is the mesh at level 0 read in file equals targetMesh ? %s"%(meshRead0.isEqual(targetMesh,1e-12))) ; assert meshRead0.isEqual(targetMesh,1e-12)
+print("Is the mesh at level -1 read in file equals targetMesh ? %s"%(meshRead1.isEqual(targetMesh1,1e-12))) ; assert meshRead1.isEqual(targetMesh1,1e-12)
#
-print meshMEDFileRead.getGrpNonEmptyLevels("grp0_Lev0")
+print(meshMEDFileRead.getGrpNonEmptyLevels("grp0_Lev0"))
grp0_0_read=meshMEDFileRead.getGroupArr(0,"grp0_Lev0")
-print "Is group \"grp0_Lev0\" are the same ? %s"%(grp0_0_read.isEqual(grp0_0)) ; assert grp0_0_read.isEqual(grp0_0)
+print("Is group \"grp0_Lev0\" are the same ? %s"%(grp0_0_read.isEqual(grp0_0))) ; assert grp0_0_read.isEqual(grp0_0)
#
# Fields
#
fMEDFileRead=MEDFileField1TS.New("TargetMesh2.med",f.getName(),7,8)
fRead1=fMEDFileRead.getFieldOnMeshAtLevel(ON_CELLS,0,meshMEDFileRead) # fastest method. No read in file.
fRead2=fMEDFileRead.getFieldAtLevel(ON_CELLS,0) # basic method like, mesh is reread in file...
-print "Does the field f remains the same using fast method ? %s"%(fRead1.isEqual(f,1e-12,1e-12)) ; assert fRead1.isEqual(f,1e-12,1e-12)
-print "Does the field f remains the same using slow method ? %s"%(fRead2.isEqual(f,1e-12,1e-12)) ; assert fRead2.isEqual(f,1e-12,1e-12)
+print("Does the field f remains the same using fast method ? %s"%(fRead1.isEqual(f,1e-12,1e-12))) ; assert fRead1.isEqual(f,1e-12,1e-12)
+print("Does the field f remains the same using slow method ? %s"%(fRead2.isEqual(f,1e-12,1e-12))) ; assert fRead2.isEqual(f,1e-12,1e-12)
#
# Writing and Reading fields on profile using MEDLoader advanced API
#
#
fMEDFileRead2=MEDFileField1TS.New("TargetMesh2.med",fPart.getName(),7,8)
fPartRead,pflRead=fMEDFileRead2.getFieldWithProfile(ON_CELLS,0,meshMEDFileRead)
-print fPartRead.isEqualWithoutConsideringStr(fPart.getArray(),1e-12) ; assert fPartRead.isEqualWithoutConsideringStr(fPart.getArray(),1e-12)
-print pflRead.isEqualWithoutConsideringStr(pfl) ; assert pflRead.isEqualWithoutConsideringStr(pfl)
+print(fPartRead.isEqualWithoutConsideringStr(fPart.getArray(),1e-12)) ; assert fPartRead.isEqualWithoutConsideringStr(fPart.getArray(),1e-12)
+print(pflRead.isEqualWithoutConsideringStr(pfl)) ; assert pflRead.isEqualWithoutConsideringStr(pfl)
#####
CellFieldCpy=CellField.deepCopy()
CellFieldCpy.substractInPlaceDM(CellField_read,10,1e-12)
CellFieldCpy.getArray().abs()
-print CellFieldCpy.getArray().isUniform(0.,1e-12)
+print(CellFieldCpy.getArray().isUniform(0.,1e-12))
#
NodeField0_read=ReadFieldNode("proc0.med","mesh",0,"NodeField",5,6)
NodeField1_read=ReadFieldNode("proc1.med","mesh",0,"NodeField",5,6)
NodeFieldCpy=NodeField.deepCopy()
NodeFieldCpy.mergeNodes(1e-10)
NodeFieldCpy.substractInPlaceDM(NodeField_read,10,1e-12)
-print NodeFieldCpy.getArray().isUniform(0.,1e-12) ; assert NodeFieldCpy.getArray().isUniform(0.,1e-12)
+print(NodeFieldCpy.getArray().isUniform(0.,1e-12)) ; assert NodeFieldCpy.getArray().isUniform(0.,1e-12)
#
fileNames=["proc0.med","proc1.med"]
msML=[MEDFileMesh.New(fname) for fname in fileNames]
for ft in fts:
for geoTyp,smth in ft.getFieldSplitedByType():
if geoTyp!=NORM_ERROR:
- smth1=filter(lambda x:x[0]==ON_CELLS,smth)
+ smth1=[x for x in smth if x[0]==ON_CELLS]
arr2s=[ft.getUndergroundDataArray()[elt[1][0]:elt[1][1]] for elt in smth1]
arr1s.append(DataArrayDouble.Aggregate(arr2s))
pass
pass
else:
for ft in fts:
- smth=filter(lambda x:x[0]==NORM_ERROR,ft.getFieldSplitedByType())
+ smth=[x for x in ft.getFieldSplitedByType() if x[0]==NORM_ERROR]
arr2=DataArrayDouble.Aggregate([ft.getUndergroundDataArray()[elt[1][0][1][0]:elt[1][0][1][1]] for elt in smth])
arr1s.append(arr2)
pass
remap.prepare(srcMesh,trgMesh,"P0P0")
#
myMatrix=remap.getCrudeMatrix()
-print myMatrix # pour voir a quoi elle ressemble
+print(myMatrix) # pour voir a quoi elle ressemble
sumByRows=DataArrayDouble(len(myMatrix))
for i,wIt in enumerate(sumByRows):
su=0.
for it in myMatrix[i]:
su+=myMatrix[i][it]
wIt[0]=su
-print "Does interpolation look OK ? %s"%(str(sumByRows.isUniform(1.,1e-12))) ; assert sumByRows.isUniform(1.,1e-12)
+print("Does interpolation look OK ? %s"%(str(sumByRows.isUniform(1.,1e-12)))) ; assert sumByRows.isUniform(1.,1e-12)
#
srcField=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; srcField.setMesh(srcMesh)
srcField.fillFromAnalytic(1,"7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.))") ; CellField.getArray().setInfoOnComponent(0,"powercell [W]")
srcField.setNature(IntensiveMaximum)
trgFieldCV=remap.transferField(srcField,1e300)
#
-print "IntensiveMaximum %lf == %lf"%(srcField.integral(True)[0],trgFieldCV.integral(True)[0]) ; assert abs(srcField.integral(True)[0]-trgFieldCV.integral(True)[0])<1e-6
-print "IntensiveMaximum %lf != %lf"%(srcField.getArray().accumulate()[0],trgFieldCV.getArray().accumulate()[0]) ; assert abs(srcField.getArray().accumulate()[0]-trgFieldCV.getArray().accumulate()[0])>1e-6
+print("IntensiveMaximum %lf == %lf"%(srcField.integral(True)[0],trgFieldCV.integral(True)[0])) ; assert abs(srcField.integral(True)[0]-trgFieldCV.integral(True)[0])<1e-6
+print("IntensiveMaximum %lf != %lf"%(srcField.getArray().accumulate()[0],trgFieldCV.getArray().accumulate()[0])) ; assert abs(srcField.getArray().accumulate()[0]-trgFieldCV.getArray().accumulate()[0])>1e-6
#
srcField.setNature(ExtensiveMaximum)
trgFieldI=remap.transferField(srcField,1e300)
#
-print "ExtensiveConservation %lf != %lf"%(srcField.integral(True)[0],trgFieldI.integral(True)[0]) ; assert abs(srcField.integral(True)[0]-trgFieldI.integral(True)[0])>1e-6
-print "ExtensiveConservation %lf == %lf"%(srcField.getArray().accumulate()[0],trgFieldI.getArray().accumulate()[0]) ; assert abs(srcField.getArray().accumulate()[0]-trgFieldI.getArray().accumulate()[0])<1e-6
+print("ExtensiveConservation %lf != %lf"%(srcField.integral(True)[0],trgFieldI.integral(True)[0])) ; assert abs(srcField.integral(True)[0]-trgFieldI.integral(True)[0])>1e-6
+print("ExtensiveConservation %lf == %lf"%(srcField.getArray().accumulate()[0],trgFieldI.getArray().accumulate()[0])) ; assert abs(srcField.getArray().accumulate()[0]-trgFieldI.getArray().accumulate()[0])<1e-6
######
pass
data=MEDFileData(agitateur_file)
ts=data.getFields()[0].getTimeSteps()
-print ts
+print(ts)
#
fMts=data.getFields()["DISTANCE_INTERFACE_ELEM_BODY_ELEM_DOM"]
f1ts=fMts[(2,-1)]
torquePerCellOnSkin=DataArrayDouble.CrossProduct(posSkin,forceVectSkin)
zeTorque=torquePerCellOnSkin.accumulate()
-print "couple = %r N.m"%(zeTorque[2]) ; assert abs(zeTorque[2]-0.37)<1e-2
+print("couple = %r N.m"%(zeTorque[2])) ; assert abs(zeTorque[2]-0.37)<1e-2
speedMts=data.getFields()["VITESSE_ELEM_DOM"]
speed1ts=speedMts[(2,-1)]
speedOnSkin=speedMc.getArray()[tupleIdsInField]
powerSkin=DataArrayDouble.Dot(forceVectSkin,speedOnSkin)
power=powerSkin.accumulate()[0]
-print "power = %r W"%(power) ; assert abs(power-4.22)<1e-2
+print("power = %r W"%(power)) ; assert abs(power-4.22)<1e-2
x2=posSkin[:,0]*posSkin[:,0] ; x2=x2.accumulate()[0]
y2=posSkin[:,1]*posSkin[:,1] ; y2=y2.accumulate()[0]
inertiaSkinValues,inertiaSkinVects=linalg.eig(inertiaSkin)
pos=max(enumerate(inertiaSkinValues),key=lambda x: x[1])[0]
vect0=inertiaSkinVects[pos].tolist()[0]
-print vect0
+print(vect0)
def computeAngle(locAgitateur1ts):
fMc=locAgitateur1ts.getFieldAtLevel(ON_CELLS,0)
pass
angle2=len(ts)*[0.]
-for pos in xrange(2,len(vects)):
+for pos in range(2, len(vects)):
norm1=sqrt(vects[pos-1][0]*vects[pos-1][0]+vects[pos-1][1]*vects[pos-1][1])
norm2=sqrt(vects[pos][0]*vects[pos][0]+vects[pos][1]*vects[pos][1])
crs=vects[pos-1][0]*vects[pos][0]+vects[pos-1][1]*vects[pos][1]
pass
omega=sum(angle2)/(ts[-1][2]-ts[0][2])
-print sum(angle2) ; assert abs(sum(angle2)-1.12)<1e-2
-print "Au pdt (%d,%d) a %r s le couple est de : %r N.m, power/omega=%r N.m"%(ts[2][0],ts[2][1],ts[2][2],zeTorque[2],power/omega)
+print(sum(angle2)) ; assert abs(sum(angle2)-1.12)<1e-2
+print("Au pdt (%d,%d) a %r s le couple est de : %r N.m, power/omega=%r N.m"%(ts[2][0],ts[2][1],ts[2][2],zeTorque[2],power/omega))
assert abs(power/omega-0.37)<1e-2
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author : Anthony Geay (CEA/DEN)
+# Author : Anthony Geay (EDF R&D)
from MEDLoader import *
from math import pi,e,sqrt
m2=MEDCouplingUMesh.New("ma",2)
m2.setCoords(coo2)
m2.allocateCells(128)
- nbTri=len(c2tri)/3
- for i in xrange(nbTri):
+ nbTri = len(c2tri) // 3
+ for i in range(nbTri):
m2.insertNextCell(NORM_TRI3,3,c2tri[3*i:3*i+3])
pass
- nbQua=len(c2quad4)/4
- for i in xrange(nbQua):
+ nbQua = len(c2quad4) // 4
+ for i in range(nbQua):
m2.insertNextCell(NORM_QUAD4,4,c2quad4[4*i:4*i+4])
pass
m2.finishInsertingCells()
m1.setCoords(coo2)
c1seg=[0,1,1,2,2,3,3,4,4,9,9,14,14,19,19,24,24,29,29,34,34,39,39,43,43,42,42,41,41,40,40,44,44,35,35,30,30,25,25,20,20,15,15,10,10,5,5,0,43,39,39,34,34,29,29,24,24,19,19,14,14,9,9,4,45,53,53,54,54,55,55,56,56,57,57,58,58,59,59,49,49,60,60,61,61,62,62,52,52,63,63,64,64,65,65,66,66,67,67,68,68,69,69,47,47,70,70,71,71,72,72,45,50,94,94,95,95,96,96,97,97,98,98,99,99,100,100,46,46,101,101,102,102,103,103,48,48,104,104,105,105,106,106,107,107,108,108,109,109,110,110,51,51,111,111,112,112,113,113,50]
m1.allocateCells(80)
- for i in xrange(80):
+ for i in range(80):
m1.insertNextCell(NORM_SEG2,2,c1seg[2*i:2*i+2])
pass
m1.finishInsertingCells()
m0.setCoords(coo2)
c0pt=[44,0,47,48]
m0.allocateCells(4)
- for i in xrange(4):
+ for i in range(4):
m0.insertNextCell(NORM_POINT1,1,[c0pt[i]])
pass
m0.finishInsertingCells()
array=DataArrayDouble.New();
array.alloc(19,2);
ptr=array.getPointer();
- for i in xrange(19*2):
+ for i in range(19 * 2):
array.setIJ(0,i,float(i+7));
pass
f.setArray(array);
array=DataArrayDouble.New();
array.alloc(53,2);
ptr=array.getPointer();
- for i in xrange(53*2):
+ for i in range(53 * 2):
array.setIJ(0,i,float(i+7));
pass
f.setArray(array);
array=DataArrayDouble.New();
array.alloc(53,2);
ptr=array.getPointer();
- for i in xrange(53*2):
+ for i in range(53 * 2):
array.setIJ(0,i,float(i+7));
pass
f.setArray(array);
f.setMesh(m);
array=DataArrayDouble.New();
array.alloc(20,2);
- for i in xrange(2*20):
+ for i in range(2 * 20):
array.setIJ(0,i,float(i+8));
f.setArray(array);
array.setInfoOnComponent(0,"power [W]");
#! [PySnippetMeshAdvAPI1_6]
m0D=ReadUMeshFromFile("file2.med","Example2",-3)
#! [PySnippetMeshAdvAPI1_6]
- for i in xrange(4):
+ for i in range(4):
mm.removeMeshAtLevel(-i)
pass
mm.setMeshAtLevel(0,myMesh1)
mfflds=mfflds.partOfThisLyingOnSpecifiedMeshName(mfmsh[0].getName())
retf=self.__splitFields(mfmsh[0],mfflds,idsLst)
retm=self.__splitMesh(mfmsh[0],idsLst)
- self._mfd_splitted=[MEDFileData() for i in xrange(len(idsLst))]
+ self._mfd_splitted=[MEDFileData() for i in range(len(idsLst))]
for a,b,c in zip(self._mfd_splitted,retf,retm):
a.setFields(b) ; a.setMeshes(c)
pass
pass
def __splitMEDFileField1TS(self,mm,f1ts,idsLst):
- ret=[MEDFileField1TS() for i in xrange(len(idsLst))]
+ ret=[f1ts.__class__() for i in range(len(idsLst))]
dico={ON_CELLS:self.__splitMEDFileField1TSCell,
ON_NODES:self.__splitMEDFileField1TSNode,
ON_GAUSS_PT:self.__splitMEDFileField1TSCell,
return ret
def __splitFields(self,mm,mfflds,idsLst):
- ret0=[MEDFileFields() for i in xrange(len(idsLst))]
+ ret0 = [MEDFileFields() for i in range(len(idsLst))]
for fmts in mfflds:
if len(fmts.getPflsReallyUsed())!=0:
- print "Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !"%(fmts.getName())
+ print("Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !" % (fmts.getName()))
continue
pass
- ret1=[MEDFileFieldMultiTS() for i in xrange(len(idsLst))]
+ ret1=[fmts.__class__() for i in range(len(idsLst))]
for f1ts in fmts:
for fmtsPart,f1tsPart in zip(ret1,self.__splitMEDFileField1TS(mm,f1ts,idsLst)):
fmtsPart.pushBackTimeStep(f1tsPart)
return ret0
def __splitMesh(self,mfm,idsLst):
- ret0=[MEDFileMeshes() for i in xrange(len(idsLst))]
+ ret0 = [MEDFileMeshes() for i in range(len(idsLst))]
m=mfm.getMeshAtLevel(0)
for ret,ids in zip(ret0,idsLst):
mlPart=mfm.createNewEmpty()
nbOfCompo=4100
arr=MEDLoader.DataArrayDouble(nbOfCompo*3) ; arr.iota()
arr.rearrange(nbOfCompo)
- arr.setInfoOnComponents(["c%i"%(i) for i in xrange(nbOfCompo)])
+ arr.setInfoOnComponents(["c%i" % (i) for i in range(nbOfCompo)])
f.setArray(arr)
f.setName("FieldBigCompo")
MEDLoader.WriteField(fileName,f,True)
m.insertNextCell([0,2,1,3])
m.setCoords(MEDLoader.DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
#
- ms=[m.deepCopy() for i in xrange(4)]
+ ms = [m.deepCopy() for i in range(4)]
for i,elt in enumerate(ms):
elt.translate([float(i)*1.5,0.])
pass
m.insertNextCell([0,2,1,3])
m.setCoords(MEDLoader.DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
#
- ms=[m.deepCopy() for i in xrange(4)]
+ ms = [m.deepCopy() for i in range(4)]
for i,elt in enumerate(ms):
elt.translate([float(i)*1.5,0.])
pass
mm[0]=m
mm.write(fname,2)
#
- pfl=MEDLoader.DataArrayInt(range(8))
+ pfl = MEDLoader.DataArrayInt(list(range(8)))
pfl.setName("PFL")
#
f=MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author : Anthony Geay (CEA/DEN)
+# Author : Anthony Geay (EDF R&D)
from MEDLoader import *
import unittest
from MEDLoaderDataForTest import MEDLoaderDataForTest
from distutils.version import LooseVersion
+import sys
+if sys.version_info.major < 3:
+ import cPickle as pickle
+else:
+ import pickle
+
class MEDLoaderTest3(unittest.TestCase):
def testMEDMesh1(self):
fileName="Pyfile18.med"
g1_2=DataArrayInt.New()
g1_2.setValues([1,3],2,1)
g1_2.setName("G1")
- g2_2=DataArrayInt.New()
+ g2_2=DataArrayInt.New()getCellsContainingPoint
g2_2.setValues([1,2,3],3,1)
g2_2.setName("G2")
mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
g2_1.setName("G2")
mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
g1_N=DataArrayInt.New()
- g1_N.setValues(range(8),8,1)
+ g1_N.setValues(list(range(8)),8,1)
g1_N.setName("G1")
g2_N=DataArrayInt.New()
- g2_N.setValues(range(9),9,1)
+ g2_N.setValues(list(range(9)),9,1)
g2_N.setName("G2")
mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
mm.createGroupOnAll(0,"GrpOnAllCell")
self.assertTrue(g2_N.isEqual(t));
self.assertTrue(mm.existsGroup("GrpOnAllCell"));
t=mm.getGroupArr(0,"GrpOnAllCell")
- self.assertTrue(t.getValues()==range(5))
+ self.assertTrue(t.getValues()==list(range(5)))
#
mmCpy=mm.deepCopy()
self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
self.assertTrue(not mm2.existsFamily("Family_-8"))
mm2.createGroupOnAll(-1,"GrpOnAllFace")
self.assertTrue(mm2.existsFamily("Family_-8"))
- self.assertEqual(range(3),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
+ self.assertEqual(list(range(3)),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
pass
#testing persistence of retrieved arrays
m.setRenumFieldArr(-1,n1)
m.setRenumFieldArr(-2,n0)
nbOfFams=len(fns)
- for i in xrange(nbOfFams):
+ for i in range(nbOfFams):
m.addFamily(fns[i],fids[i])
pass
nbOfGrps=len(grpns)
- for i in xrange(nbOfGrps):
+ for i in range(nbOfGrps):
m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
pass
m.setName(m2.getName())
m1=MEDLoaderDataForTest.build2DMesh_1()
m1.renumberCells([0,1,4,2,3,5],False)
tmp=m1.getName();
- m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
+ m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
mm1.write(fname,2)
ff1=MEDFileField1TS.New()
m1=MEDLoaderDataForTest.build2DMesh_1()
m1.renumberCells([0,1,4,2,3,5],False)
tmp=m1.getName();
- m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
+ m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
mm1.write(fname,2)
ff1=MEDFileFieldMultiTS.New()
da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
#
ff1.setFieldProfile(f1,mm1,0,da)
- m1=m0.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
+ m1=m0.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
mm1.write(fname,2)
ff1.write(fname,0)
f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
expected1=[1.,10.,100.,2.,20.,200.]
nodeCoordsWithValue1=[10.,2.5,0.]
nodeCoordsWithValue2=[10.,3.75,0.]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
pass
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
pass
del tes0
self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
self.assertEqual(2,tes1.getArray().getNumberOfTuples())
self.assertEqual(3,tes1.getArray().getNumberOfComponents())
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
pass
m.write(fname,2)
self.assertEqual(2,tes2.getArray().getNumberOfTuples())
self.assertEqual(3,tes2.getArray().getNumberOfComponents())
expected2=[2.,20.,200.,1.,10.,100.]
- for i in xrange(3):
+ for i in range(3):
self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
pass
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
pass
#
self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
self.assertEqual(2,tes3.getArray().getNumberOfTuples())
self.assertEqual(3,tes3.getArray().getNumberOfComponents())
- for i in xrange(6):
+ for i in range(6):
self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
pass
pass
coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
mQ8.allocateCells(1)
- mQ8.insertNextCell(NORM_QUAD8,range(8))
+ mQ8.insertNextCell(NORM_QUAD8,list(range(8)))
mQ8.finishInsertingCells()
mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
mQ4.allocateCells(1)
- mQ4.insertNextCell(NORM_QUAD4,range(4))
+ mQ4.insertNextCell(NORM_QUAD4,list(range(4)))
mQ4.finishInsertingCells()
mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
mT3.allocateCells(1)
- mT3.insertNextCell(NORM_TRI3,range(3))
+ mT3.insertNextCell(NORM_TRI3,list(range(3)))
mT3.finishInsertingCells()
tr=[[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.]]
mm.write(fname,2)
#
f1ts=MEDFileField1TS.New()
- pfl=DataArrayInt(range(13)) ; pfl.setName("pfl")
+ pfl=DataArrayInt(list(range(13))) ; pfl.setName("pfl")
self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
f1ts.setFieldProfile(f,mm,0,pfl)
m1=MEDCouplingUMesh(m0.getName(),1)
m1.allocateCells(9)
conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
- for i in xrange(9):
+ for i in range(9):
m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
pass
m1.finishInsertingCells()
m1=MEDCouplingUMesh(m0.getName(),1)
m1.allocateCells(9)
conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
- for i in xrange(9):
+ for i in range(9):
m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
pass
m1.finishInsertingCells()
m=MEDFileUMesh()
coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
- for i in xrange(7):
+ for i in range(7):
m0.insertNextCell(NORM_TRI3,[1,2,1])
pass
- for i in xrange(4):
+ for i in range(4):
m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
pass
- for i in xrange(2):
+ for i in range(2):
m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
pass
m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
m=m.buildUnstructured()
m.setName("mm")
f=m.getMeasureField(False)
- self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100+4*strMulFac))
- self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100+8*strMulFac))
+ self.assertIn(m.getHeapMemorySize(), list(range(3552 - 100, 3552 + 100 + 4 * strMulFac)))
+ self.assertIn(f.getHeapMemorySize(), list(range(4215 - 100, 4215 + 100 + 8 * strMulFac)))
#
mm=MEDFileUMesh()
mm.setMeshAtLevel(0,m)
- self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,4225+100+10*strMulFac))
+ self.assertIn(mm.getHeapMemorySize(), list(range(3889 - 100, 4225 + 100 + 10 * strMulFac)))
ff=MEDFileField1TS()
ff.setFieldNoProfileSBT(f)
- self.assertIn(ff.getHeapMemorySize(),xrange(771-40,871+21+(4+1)*strMulFac))
+ self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
#
fff=MEDFileFieldMultiTS()
fff.appendFieldNoProfileSBT(f)
- self.assertIn(fff.getHeapMemorySize(),xrange(815-50,915+30+(6+2)*strMulFac))
+ self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
f.setTime(1.,0,-1)
fff.appendFieldNoProfileSBT(f)
- self.assertIn(fff.getHeapMemorySize(),xrange(1594-90,1794+50+(10+1)*strMulFac))
- self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(771-40,871+20+(4+1)*strMulFac))
+ self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
+ self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
f2=f[:50]
f2.setTime(2.,1,-1)
pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
fff.appendFieldProfile(f2,mm,0,pfl)
- self.assertIn(fff.getHeapMemorySize(),xrange(2348-130,2608+100+(10+2)*strMulFac))
- self.assertIn(fff.getProfile("pfl").getHeapMemorySize(),xrange(204-10,204+10+2*strMulFac))
- self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(738-50,838+30+4*strMulFac))
+ self.assertIn(fff.getHeapMemorySize(), list(range(2348 - 130, 2608 + 100 + (10 + 2) * strMulFac)))
+ self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(204 - 10, 204 + 10 + 2 * strMulFac)))
+ self.assertIn(fff[1, -1].getHeapMemorySize(), list(range(738 - 50, 838 + 30 + 4 * strMulFac)))
pass
def testCurveLinearMesh1(self):
mm.setMeshAtLevel(0,m)
mm.setMeshAtLevel(-1,m1)
namesCellL0=DataArrayAsciiChar(6,16)
- namesCellL0[:]=["CellL0#%.3d "%(i) for i in xrange(6)]
+ namesCellL0[:] = ["CellL0#%.3d " % (i) for i in range(6)]
mm.setNameFieldAtLevel(0,namesCellL0)
namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
- namesCellL1[:]=["CellLM1#%.3d "%(i) for i in xrange(16)]
+ namesCellL1[:] = ["CellLM1#%.3d " % (i) for i in range(16)]
mm.setNameFieldAtLevel(-1,namesCellL1)
namesNodes=namesCellL1.subArray(4,16)
- namesNodes[:]=["Node#%.3d "%(i) for i in xrange(12)]
+ namesNodes[:] = ["Node#%.3d " % (i) for i in range(12)]
mm.setNameFieldAtLevel(1,namesNodes)
mm.write(fname,2)
#
mmr=MEDFileMesh.New(fname)
- self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d "%(i) for i in xrange(6)])))
- self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d "%(i) for i in xrange(16)])))
- self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(12)])))
+ self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
+ self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d " % (i) for i in range(16)])))
+ self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(12)])))
self.assertTrue(mm.isEqual(mmr,1e-12)[0])
mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
mm.write(fname,2)
mmr=MEDFileMesh.New(fname)
self.assertEqual(mmr.getNameFieldAtLevel(1),None)
- self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d "%(i) for i in xrange(6)])))
+ self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
#
c=MEDCouplingCMesh()
c.setName("cmesh")
cc=MEDFileCMesh()
cc.setMesh(c)
- cc.setNameFieldAtLevel(0,DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)]))
- cc.setNameFieldAtLevel(1,DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)]))
+ cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)]))
+ cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)]))
cc.write(fname2,2)
ccr=MEDFileMesh.New(fname2)
- self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)])))
- self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)])))
+ self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)])))
+ self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)])))
self.assertTrue(cc.isEqual(ccr,1e-12)[0])
ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
m.setFamilyFieldArr(-2,f0)
m.setFamilyFieldArr(1,p)
nbOfFams=len(fns)
- for i in xrange(nbOfFams):
+ for i in range(nbOfFams):
m.addFamily(fns[i],fids[i])
pass
nbOfGrps=len(grpns)
- for i in xrange(nbOfGrps):
+ for i in range(nbOfGrps):
m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
pass
m.setName(m2.getName())
nf1=MEDCouplingFieldInt(ON_NODES)
nf1.setTime(9.,10,-1)
nf1.setMesh(f1.getMesh())
- narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=range(12) ; narr[:,1]=2*narr[:,0]
+ narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
nff1=MEDFileIntField1TS.New()
nff1.setFieldNoProfileSBT(nf1)
nf2=MEDCouplingFieldInt(ON_NODES)
nf2.setTime(19.,20,-11)
nf2.setMesh(f1.getMesh())
- narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=range(8) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
+ narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
nff2=MEDFileIntField1TS.New()
npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
f1.setMesh(m)
- arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=range(12) ; arr[:,1]=2*arr[:,0]
+ arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
f1.setArray(arr)
f1.setName("Field1")
ff1=MEDFileField1TS.New()
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
fmts0_0=MEDFileFieldMultiTS()
fmts0_1=MEDFileFieldMultiTS()
# time steps
- for i in xrange(10):
+ for i in range(10):
infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
fmts0_0=MEDFileFieldMultiTS()
fmts0_1=MEDFileFieldMultiTS()
# time steps
- for i in xrange(10):
+ for i in range(10):
infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
#
fmts0_5=MEDFileFieldMultiTS()
- for i in xrange(7):
+ for i in range(7):
infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
fmts0_1=MEDFileFieldMultiTS()
# time steps
infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
- for i in xrange(10):
+ for i in range(10):
name1="1stField"
d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
self.assertEqual(4,len(fs1))
- for i in xrange(10):
+ for i in range(10):
for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
f1ts=fs1[fieldName][i]
f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(30)]
+ tris = [tri.deepCopy() for i in range(30)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(40)]
+ quads = [quad.deepCopy() for i in range(40)]
for i,elt in enumerate(quads): elt.translate([40+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
heap_memory_ref=ff0.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(182,465+3*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
ff0.loadArrays() ##
arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
heap_memory_ref=ff0.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(350,520+7*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(350, 600 + 6 * strMulFac)))
ff0.loadArrays() ##
arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
heap_memory_ref=ff0.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(1100,1384+3*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(1100, 1400 + 2 * strMulFac)))
ff0.unloadArrays()
hmd=ff0.getHeapMemorySize()-heap_memory_ref
self.assertEqual(hmd,-800) # -50*8*2
#
ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
heap_memory_ref=ff0.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(299,520+7*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(299, 620 + 6 * strMulFac)))
ff0.loadArrays() ##
self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
#
fieldName="FieldCellMultiTS"
ff0=MEDFileFieldMultiTS()
- for t in xrange(20):
+ for t in range(20):
f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota(float(t+1000)) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName(fieldName)
f0.setTime(float(t)+0.1,t,100+t)
f0.checkConsistencyLight()
#
ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
heap_memory_ref=ff0.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(5536,8212+(80+26+1+len(ff0))*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(5536, 9212 + (80 + 26 + 1) * strMulFac)))
ff0.loadArrays()
self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
del ff0
#
ffs=MEDFileFields(fname,False)
heap_memory_ref=ffs.getHeapMemorySize()
- self.assertIn(heap_memory_ref,xrange(5335,9031+(80+50+24+len(ffs))*strMulFac))
+ self.assertIn(heap_memory_ref, list(range(5335, 10031 + (80 + 50 + len(ffs)) * strMulFac)))
ffs.loadArrays()
self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
pass
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
m=MEDFileUMesh()
m.setMeshAtLevel(0,m00)
- m.setRenumFieldArr(1,DataArrayInt(range(10,26)))
+ m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
m.write(fname,2)
del m,a,c,m0,m00
m=MEDFileMesh.New(fname)
self.assertEqual((),m.getNonEmptyLevels())
self.assertTrue(m.getCoords().isEqual(DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(0,1),(1,1),(2,1),(3,1),(0,2),(1,2),(2,2),(3,2),(0,3),(1,3),(2,3),(3,3)]),1e-12))
- self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(range(10,26))))
+ self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
pass
m.insertNextCell([0,2,1,3])
m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
#
- ms=[m.deepCopy() for i in xrange(4)]
+ ms = [m.deepCopy() for i in range(4)]
for i,elt in enumerate(ms):
elt.translate([float(i)*1.5,0.])
pass
m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
m0.convertAllToPoly()
#
- ms=[m.deepCopy() for i in xrange(5)]
+ ms = [m.deepCopy() for i in range(5)]
for i,elt in enumerate(ms):
elt.translate([float(i)*1.5,1.5])
pass
#
fmts=MEDFileFieldMultiTS()
#
- for i in xrange(nbCells):
+ for i in range(nbCells):
t=(float(i)+0.1,i+1,-i-2)
f.setTime(*t)
arr2=DataArrayDouble(nbCells)
renum0=DataArrayInt([3,6,7,10,11,0,2,1,9,8,5,4,12,13,14,24,23,22,21,20,19,18,17,16,15])
famField0=DataArrayInt([-3,-6,-7,-10,-11,0,-2,-1,-9,-8,-5,-4,-12,-13,-14,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15])
namesCellL0=DataArrayAsciiChar(25,16)
- namesCellL0[:]=["Cell#%.3d "%(i) for i in xrange(25)]
+ namesCellL0[:] = ["Cell#%.3d " % (i) for i in range(25)]
renumM1=DataArrayInt([3,4,0,2,1])
famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
mm.setRenumFieldArr(0,renum0)
renum1=DataArrayInt([13,16,17,20,21,10,12,11,19,18,15,14,22,23,24,34,33,32,31,30,29,28,27,26,25,45,44,43,42,41,40,39,38,37,36,35])
famField1=DataArrayInt([-13,-16,-17,-20,-21,-10,-12,-11,-19,-18,-15,-14,-22,-23,-24,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35])
namesNodes=DataArrayAsciiChar(36,16)
- namesNodes[:]=["Node#%.3d "%(i) for i in xrange(36)]
+ namesNodes[:] = ["Node#%.3d " % (i) for i in range(36)]
mm.setRenumFieldArr(1,renum1)
mm.setFamilyFieldArr(1,famField1)
mm.setNameFieldAtLevel(1,namesNodes)
f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
f.setName("Field")
arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
- arr[:,0]=range(25)
- arr[:,1]=range(100,125)
+ arr[:,0]=list(range(25))
+ arr[:,1]=list(range(100,125))
f.setArray(arr)
WriteField(fileName,f,True)
f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
f.setName("FieldNode")
arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
- arr[:,0]=range(200,236)
- arr[:,1]=range(300,336)
+ arr[:,0]=list(range(200,236))
+ arr[:,1]=list(range(300,336))
f.setArray(arr)
f.checkConsistencyLight()
WriteFieldUsingAlreadyWrittenMesh(fileName,f)
fs=MEDFileFields.LoadPartOf(fileName,False,ms)
fs=fs.deepCopy()
fs[0][0].loadArrays()
- arr=DataArrayDouble(12,2) ; arr[:,0]=range(3,15) ; arr[:,1]=range(103,115)
+ arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
arr.setInfoOnComponents(compos)
self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
fs[1][0].loadArrays()
- arr=DataArrayDouble(21,2) ; arr[:,0]=range(203,224) ; arr[:,1]=range(303,324)
+ arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
arr.setInfoOnComponents(compos)
self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
pass
f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
f.setName("Field")
arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
- arr[:,0]=range(25)
- arr[:,1]=range(100,125)
+ arr[:,0]=list(range(25))
+ arr[:,1]=list(range(100,125))
f.setArray(arr)
WriteField(fileName,f,True)
f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
f.setName("FieldNode")
arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
- arr[:,0]=range(200,236)
- arr[:,1]=range(300,336)
+ arr[:,0]=list(range(200,236))
+ arr[:,1]=list(range(300,336))
f.setArray(arr)
f.checkConsistencyLight()
WriteFieldUsingAlreadyWrittenMesh(fileName,f)
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
def testMEDFileUMeshPickeling1(self):
- import cPickle
outFileName="Pyfile86.med"
c=DataArrayDouble([-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ],9,2)
c.setInfoOnComponents(["aa","bbb"])
g2_1.setName("G2")
mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
g1_N=DataArrayInt.New()
- g1_N.setValues(range(8),8,1)
+ g1_N.setValues(list(range(8)),8,1)
g1_N.setName("G1")
g2_N=DataArrayInt.New()
- g2_N.setValues(range(9),9,1)
+ g2_N.setValues(list(range(9)),9,1)
g2_N.setName("G2")
mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
mm.createGroupOnAll(0,"GrpOnAllCell")
self.assertTrue(mm.existsGroup("GrpOnAllCell"));
t=mm.getGroupArr(0,"GrpOnAllCell")
#
- st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
- mm2=cPickle.loads(st)
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm2=pickle.loads(st)
self.assertTrue(mm.isEqual(mm2,1e-12)[0])
self.assertEqual(mm.getAxisType(),AX_CART)
#
mm.setAxisType(AX_CYL)
- st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
- mm2=cPickle.loads(st)
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm2=pickle.loads(st)
self.assertTrue(mm.isEqual(mm2,1e-12)[0])
self.assertEqual(mm2.getAxisType(),AX_CYL)
pass
m.setName(meshName)
#
fmts=MEDFileFieldMultiTS()
- for i in xrange(nbPdt):
+ for i in range(nbPdt):
f=MEDCouplingFieldDouble(ON_NODES)
f.setMesh(m)
arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
fs.loadArraysIfNecessary()
fs2.loadArraysIfNecessary()
- for i in xrange(nbPdt):
+ for i in range(nbPdt):
self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
pass
m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
fmts=MEDFileFieldMultiTS()
- for i in xrange(nbPdt):
+ for i in range(nbPdt):
f=MEDCouplingFieldDouble(ON_CELLS)
f.setMesh(m3)
arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
fs2.loadArraysIfNecessary()
fs3.loadArraysIfNecessary()
fs4.loadArraysIfNecessary()
- for i in xrange(nbPdt):
+ for i in range(nbPdt):
self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
m=m.buildUnstructured()
m.setName(meshName)
#
- nbOfField=nbPdt/maxPdt
+ nbOfField=nbPdt//maxPdt
fs=MEDFileFields()
- for j in xrange(nbOfField):
+ for j in range(nbOfField):
fmts=MEDFileFieldMultiTS()
s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
- for i in xrange(s.start,s.stop,s.step):
+ for i in range(s.start, s.stop, s.step):
f=MEDCouplingFieldDouble(ON_NODES)
f.setMesh(m)
arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
fmts2.reverse()
zeResu=fmts2.pop()
nbIter=len(fmts2)
- for ii in xrange(nbIter):
+ for ii in range(nbIter):
zeResu.pushBackTimeSteps(fmts2.pop())
pass
zeResu.setName(k)
fs2.pushField(zeResu)
pass
- self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)])
+ self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
pass
def testMEDFileMeshRearrangeFamIds1(self):
def __del__(self):
import os,sys
sys.stderr=self.origPyVal
+ if sys.version_info.major >= 3:
+ self.fdOfSinkFile.close()
+ pass
#os.fsync(self.fdOfSinkFile)
os.fsync(2)
os.dup2(self.stdoutOld,2)
mm.setName("mesh")
mm.write(fname,2)
# third : change permissions to remove write access on created file
- os.chmod(fname,0444)
+ os.chmod(fname, 0o444)
# four : try to append data on file -> check that it raises Exception
f=MEDCouplingFieldDouble(ON_CELLS)
f.setName("field")
mm=MEDFileCMesh(fname)
self.assertTrue(mm.getUnivName()!="")
pass
-
+
def testEmptyMesh(self):
""" MEDLoader should be able to consistently write and read an empty mesh (coords array
with 0 tuples """
grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
mesh.setGroupsAtLevel(-1,[grp1,grp2])
- import cPickle
- st=cPickle.dumps(mesh,2)
- mm=cPickle.loads(st)
- st2=cPickle.dumps(mm,2)
- mm2=cPickle.loads(st2)
+ st=pickle.dumps(mesh,2)
+ mm=pickle.loads(st)
+ st2=pickle.dumps(mm,2)
+ mm2=pickle.loads(st2)
self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
pass
m1=MEDCouplingUMesh(m0.getName(),1)
m1.allocateCells(9)
conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
- for i in xrange(9):
+ for i in range(9):
m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
pass
m1.finishInsertingCells()
ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
# OK now end of joke -> serialization of MEDFileData
- import cPickle
- st=cPickle.dumps(mfd,cPickle.HIGHEST_PROTOCOL)
- mfd3=cPickle.loads(st)
+ st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
+ mfd3=pickle.loads(st)
# check of object
self.assertEqual(len(mfd3.getMeshes()),1)
self.assertEqual(len(mfd3.getFields()),1)
ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
# serialization of MEDFileFields
- st=cPickle.dumps(mfd.getFields(),cPickle.HIGHEST_PROTOCOL)
- fs4=cPickle.loads(st)
+ st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
+ fs4=pickle.loads(st)
ff4=fs4[0][0].field(mfd3.getMeshes()[0])
self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
# serialization of MEDFileFieldMulitTS
- st=cPickle.dumps(mfd.getFields()[0],cPickle.HIGHEST_PROTOCOL)
- fmts5=cPickle.loads(st)
+ st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
+ fmts5=pickle.loads(st)
ff5=fmts5[0].field(mfd3.getMeshes()[0])
self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
# serialization of MEDFileField1TS
- st=cPickle.dumps(mfd.getFields()[0][0],cPickle.HIGHEST_PROTOCOL)
- f1ts6=cPickle.loads(st)
+ st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
+ f1ts6=pickle.loads(st)
ff6=f1ts6.field(mfd3.getMeshes()[0])
self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
# serialization of MEDFileMeshes
- st=cPickle.dumps(mfd.getMeshes(),cPickle.HIGHEST_PROTOCOL)
- ms7=cPickle.loads(st)
+ st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
+ ms7=pickle.loads(st)
self.assertEqual(len(ms7),1)
self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
pass
self.testMEDMesh6() # generates MEDFileMesh5.med file
mm=MEDFileMesh.New("MEDFileMesh5.med")
self.assertTrue(isinstance(mm,MEDFileCMesh))
- import cPickle
- st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
- mm2=cPickle.loads(st)
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm2=pickle.loads(st)
self.assertTrue(isinstance(mm2,MEDFileCMesh))
self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
# CurveLinear
self.testCurveLinearMesh1() # generates Pyfile55.med
mm=MEDFileMesh.New("Pyfile55.med")
self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
- st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
- mm3=cPickle.loads(st)
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm3=pickle.loads(st)
self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
self.testInt32InMEDFileFieldStar1()# generates Pyfile63.med
fs4=MEDFileFields("Pyfile63.med")
ms4=MEDFileMeshes("Pyfile63.med")
self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
- st=cPickle.dumps(fs4[0],cPickle.HIGHEST_PROTOCOL)
- fmts5=cPickle.loads(st)
+ st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
+ fmts5=pickle.loads(st)
self.assertEqual(len(fs4[0]),len(fmts5))
self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,1e-12))
# MEDFileIntField1TS
- st=cPickle.dumps(fs4[0][0],cPickle.HIGHEST_PROTOCOL)
- f1ts6=cPickle.loads(st)
+ st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
+ f1ts6=pickle.loads(st)
self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,1e-12))
# MEDFileParameters
self.testParameters1()# generates Pyfile56.med
params=MEDFileParameters("Pyfile56.med")
- st=cPickle.dumps(params,cPickle.HIGHEST_PROTOCOL)
- params7=cPickle.loads(st)
+ st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
+ params7=pickle.loads(st)
self.assertEqual(len(params),len(params7))
- for i in xrange(len(params)):
+ for i in range(len(params)):
self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
pass
pass
+
+ def testGlobalNumOnNodes1(self):
+ """Test global number on nodes here. Used by partitionners."""
+ fname="Pyfile112.med"
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
+ m.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m
+ self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
+ d=DataArrayInt([7,8,9,2,0])
+ dRef=d.deepCopy()
+ mm.setGlobalNumFieldAtLevel(1,d)
+ mm.checkConsistency()
+ self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
+ mm.checkConsistency()
+ self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
+ self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
+ mm.write(fname,2)
+ mm2=MEDFileMesh.New(fname)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
+ mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
+ self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
+ mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ pass
+
+ def testPartialReadOfEntities1(self):
+ """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
+ fname="Pyfile113.med"
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
+ m.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m
+ #
+ fieldName="Field"
+ ts1=(5.,1,2)
+ f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
+ f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
+ f1.setTime(*ts1)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
+ f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
+ f2.setTime(*ts1)
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f1)
+ f1ts.setFieldNoProfileSBT(f2)
+ self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
+ f1ts_2=f1ts.deepCopy()
+ f1ts_2.getUndergroundDataArray()[:]+=2
+ f1ts_2.setTime(3,4,6.)
+ fmts=MEDFileFieldMultiTS()
+ fmts.pushBackTimeStep(f1ts)
+ fmts.pushBackTimeStep(f1ts_2)
+ #
+ mm.write(fname,2)
+ fmts.write(fname,0)
+ #
+ ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
+ mm=MEDFileMesh.New(fname)
+ fs=MEDFileFields(fname,False,ent) # the important line is here - We specify to MEDFileFields to read only nodes part to speed up read phase (by avoiding to scan all entities time geo types)
+ fs.loadArrays()
+ self.assertEqual(len(fs),1)
+ fmts=fs[0]
+ self.assertEqual(len(fmts),2)
+ ff0=fmts[0] ; ff1=fmts[1]
+ self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
+ self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
+ f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
+ self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
+ pass
pass
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a8.isEqual(DataArrayInt([120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,100,101,102,103,104,105,106,107,108])))
self.assertTrue(not a9)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
fsst=MEDFileField1TSStructItem.BuildItemFrom(fields[0][i],mst)
fields[0][i].loadArraysIfNecessary()
tmpMem=fields.getHeapMemorySize()
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
assert isinstance(mml2,MEDUMeshMultiLev)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
# for cells
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
f.loadArraysIfNecessary()
vExp=DataArrayDouble([200.,201.,202.,203.,204.,205.,206.,207.,208.,209.,210.,211.,212.,213.,214.,215.,216.,217.,218.,219.,220.,221.,222.,223.,224.,225.,226.,227.,228.,229.,230.,231.,232.,233.,234.,235.,236.,237.,238.,239.,240.,241.,242.,243.,244.,245.,246.,247.,248.,249.,250.,251.,252.,253.,254.,255.,256.,257.,258.,259.,260.,261.,262.,263.,100.,101.,102.,103.,104.,105.,106.,107.,108.,109.,110.,111.,112.,113.,114.,115.,116.,117.],41,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*1000
self.assertTrue(v.isEqual(vExp,1e-12))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][1][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
f.loadArraysIfNecessary()
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,3):
+ for i in range(1, 3):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
assert a5 is None
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
# for cells
- for i in xrange(3):
+ for i in range(3):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
f.loadArraysIfNecessary()
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
f.loadArraysIfNecessary()
tri=MEDCouplingUMesh("tri",2)
tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
- tris=[tri.deepCopy() for i in xrange(4)]
+ tris = [tri.deepCopy() for i in range(4)]
for i,elt in enumerate(tris): elt.translate([i,0])
tris=MEDCouplingUMesh.MergeUMeshes(tris)
quad=MEDCouplingUMesh("quad",2)
quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
- quads=[quad.deepCopy() for i in xrange(5)]
+ quads = [quad.deepCopy() for i in range(5)]
for i,elt in enumerate(quads): elt.translate([5+i,0])
quads=MEDCouplingUMesh.MergeUMeshes(quads)
m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
# test all the time steps of the 1/1 time step serie, on field 1
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(v.isEqual(vExp,1e-12))
pass
# test all the time steps of the 1/1 time step serie, on field 2
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][1][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(v.isEqual(vExp,1e-12))
pass
# test all the time steps of the 1/1 time step serie, on field 3
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][2][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName3="zeField3" ; pfl3=DataArrayInt([0,1,2,3,4,5,9,10]) ; pfl3.setName("pfl3") # on cells but different support
fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
#
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName1)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105])))
self.assertTrue(not a9)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
nbOfT=[6,8]
fieldNames=[fieldName1,fieldName2]
- for j in xrange(2):
+ for j in range(2):
m={"i":j}
f=allFMTSLeavesPerCommonSupport[0][0][j][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,109,110])))
self.assertTrue(not a9)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName4="zeField4" ;# on nodes
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS()
#
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a.isEqual(coordsX,1e-12))
self.assertTrue(b.isEqual(coordsY,1e-12))
self.assertTrue(isinstance(mml2,MEDCMeshMultiLev))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
a6,a7=mml2.retrieveFamilyIdsOnCells()
self.assertTrue(a10.isEqual(DataArrayInt([200,201,202,203,204,205,206,207,208,209,210,211,212,213,214])))
self.assertTrue(a11) # True because no copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a10.isEqual(DataArrayInt([202,203,204,207,208,209,212,213,214])))
self.assertTrue(not a11) # False because copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
self.assertTrue(not a9) # False because copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[2][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName4="zeField4" ;# on nodes
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS()
#
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
self.assertTrue(a9) # True because no copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([102,103,106,107])))
self.assertTrue(not a9) # False because copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
self.assertTrue(not a9) # False because copy
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[2][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName2="zeField2"
fieldName3="zeField3"
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_GAUSS_NE) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
pfl1=DataArrayInt([0,1,7,9,10]) ; pfl1.setName("pfl1") # on cells
pfl2=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl2.setName("pfl2") # on nodes
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_GAUSS_NE) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0)
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName2="zeField2"
pfl1=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl1.setName("pfl1") # on nodes
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0)
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
#
fieldName0="zeField0"
fs0=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName0="zeField0"
fieldName1="zeField1"
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fieldName1="zeField1"
fieldName2="zeField2" ; pfl1=DataArrayInt([2,3]) ; pfl1.setName("pfl1")
fieldName3="zefield3" ; pfl2=DataArrayInt([2,3,4]) ; pfl2.setName("pfl2")
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a4.isEqual(DataArrayInt([-1,-1,0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a4.isEqual(DataArrayInt([0,31])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4])))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[2][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
fieldName0="zeField0"
fieldName1="zeField1"
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
a6,a7=mml2.retrieveFamilyIdsOnCells()
a8,a9=mml2.retrieveNumberIdsOnCells()
self.assertTrue(a8 is None)
self.assertTrue(a9)
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
self.assertTrue(a9) # no copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
vExp1=[DataArrayDouble([3.,5.,7.,6.,2.,3.,11.,8.]),DataArrayDouble([7.,6.,3.,5.,11.,8.,2.,3.])]
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
self.assertTrue(a9) # no copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
self.assertTrue(a9) # no copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst) # no load needed here
v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
self.assertTrue(not a12)
self.assertTrue(a13) # no copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a12.isEqual(DataArrayInt([0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240])))
self.assertTrue(a13) # no copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,2):
+ for i in range(1, 2):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a12.isEqual(DataArrayInt([50,60,70,100,110,120,150,160,170,200,210,220])))
self.assertTrue(not a13) # copy here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport1[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(b.isEqual(arr1,1e-12))
self.assertTrue(c.isEqual(arr2,1e-12))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(2):
+ for i in range(2):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
self.assertEqual(v.getHiddenCppPointer(),ffGauss.getUndergroundDataArray().getHiddenCppPointer())
self.assertEqual(ffGauss.getName(),"fGauss")
- self.assertTrue(v.isEqual(arrGauss,1e-12)) ; self.assertTrue(v.isEqualWithoutConsideringStr(DataArrayDouble(range(27)),1e-12)) ; self.assertEqual(v.getInfoOnComponents(),["gaussc"])
+ self.assertTrue(v.isEqual(arrGauss, 1e-12)) ; self.assertTrue(v.isEqualWithoutConsideringStr(DataArrayDouble(list(range(27))), 1e-12)) ; self.assertEqual(v.getInfoOnComponents(), ["gaussc"])
ffGauss=allFMTSLeavesPerCommonSupport1[0][0][1][0]
pass
#
fmts0=MEDFileFieldMultiTS()
fmts1=MEDFileFieldMultiTS()
- for i in xrange(30):
+ for i in range(30):
f1ts=MEDFileField1TS()
fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnFaces")
arr=DataArrayDouble(98) ; arr.iota() ; arr[i]=100.
self.assertTrue(b.isEqual(arrY,1e-12))
self.assertTrue(c.isEqual(arrZ,1e-12))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(30):
+ for i in range(30):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
self.assertTrue(a3.isEqual(DataArrayInt([4,0,12,15,3,4,12,24,27,15,4,24,36,39,27,4,36,48,51,39,4,3,15,18,6,4,15,27,30,18,4,27,39,42,30,4,39,51,54,42,4,6,18,21,9,4,18,30,33,21,4,30,42,45,33,4,42,54,57,45,4,1,13,16,4,4,13,25,28,16,4,25,37,40,28,4,37,49,52,40,4,4,16,19,7,4,16,28,31,19,4,28,40,43,31,4,40,52,55,43,4,7,19,22,10,4,19,31,34,22,4,31,43,46,34,4,43,55,58,46,4,2,14,17,5,4,14,26,29,17,4,26,38,41,29,4,38,50,53,41,4,5,17,20,8,4,17,29,32,20,4,29,41,44,32,4,41,53,56,44,4,8,20,23,11,4,20,32,35,23,4,32,44,47,35,4,44,56,59,47,4,0,12,13,1,4,12,24,25,13,4,24,36,37,25,4,36,48,49,37,4,1,13,14,2,4,13,25,26,14,4,25,37,38,26,4,37,49,50,38,4,3,15,16,4,4,15,27,28,16,4,27,39,40,28,4,39,51,52,40,4,4,16,17,5,4,16,28,29,17,4,28,40,41,29,4,40,52,53,41,4,6,18,19,7,4,18,30,31,19,4,30,42,43,31,4,42,54,55,43,4,7,19,20,8,4,19,31,32,20,4,31,43,44,32,4,43,55,56,44,4,9,21,22,10,4,21,33,34,22,4,33,45,46,34,4,45,57,58,46,4,10,22,23,11,4,22,34,35,23,4,34,46,47,35,4,46,58,59,47,4,0,1,4,3,4,3,4,7,6,4,6,7,10,9,4,1,2,5,4,4,4,5,8,7,4,7,8,11,10,4,12,13,16,15,4,15,16,19,18,4,18,19,22,21,4,13,14,17,16,4,16,17,20,19,4,19,20,23,22,4,24,25,28,27,4,27,28,31,30,4,30,31,34,33,4,25,26,29,28,4,28,29,32,31,4,31,32,35,34,4,36,37,40,39,4,39,40,43,42,4,42,43,46,45,4,37,38,41,40,4,40,41,44,43,4,43,44,47,46,4,48,49,52,51,4,51,52,55,54,4,54,55,58,57,4,49,50,53,52,4,52,53,56,55,4,55,56,59,58])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
- for i in xrange(30):
+ for i in range(30):
ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
fmts0=MEDFileFieldMultiTS()
fmts1=MEDFileFieldMultiTS()
pfl=DataArrayInt(11) ; pfl.iota() ; pfl.setName("PflOnHECA8")
- for i in xrange(30):
+ for i in range(30):
f1ts=MEDFileField1TS()
fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnCells")
arr=DataArrayDouble(11) ; arr.iota() ; arr[i%11]=100.
self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,3,4,13,12,15,16,8,2,1,4,5,14,13,16,17,8,4,3,6,7,16,15,18,19,8,5,4,7,8,17,16,19,20,8,7,6,9,10,19,18,21,22,8,8,7,10,11,20,19,22,23,8,13,12,15,16,25,24,27,28,8,14,13,16,17,26,25,28,29,8,16,15,18,19,28,27,30,31,8,17,16,19,20,29,28,31,32,8,19,18,21,22,31,30,33,34])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
- for i in xrange(30):
+ for i in range(30):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
fmts0=MEDFileFieldMultiTS()
fmts1=MEDFileFieldMultiTS()
pfl=DataArrayInt(31) ; pfl.iota() ; pfl.setName("PflOnQUAD4")
- for i in xrange(30):
+ for i in range(30):
f1ts=MEDFileField1TS()
fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnFaces")
arr=DataArrayDouble(31) ; arr.iota() ; arr[i]=100.
self.assertTrue(b.isEqual(arrY,1e-12))
self.assertTrue(c.isEqual(arrZ,1e-12))
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(30):
+ for i in range(30):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
a6,a7=mml2.retrieveFamilyIdsOnCells()
self.assertTrue(a6 is None)
self.assertTrue(a7)
- for i in xrange(30):
+ for i in range(30):
ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
mm=MEDFileUMesh()
mm.setMeshAtLevel(0,m)
mm.write(fname,2)
- for i in xrange(15):
+ for i in range(15):
fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i)+0.1,i,0)
fCell0.setName(fieldName) ; fCell0.setMesh(m)
arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota(0) ; arr[i%10]=100.
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(15):
+ for i in range(15):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
fieldName0="zeField0"
fieldName1="zeField1"
fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
- for i in xrange(5):
+ for i in range(5):
f=MEDFileField1TS()
fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
fNode.setName(fieldName0) ; fNode.setMesh(m)
self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5)
allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
self.assertEqual(len(allFMTSLeavesPerCommonSupport),5)
- for i in xrange(5):
+ for i in range(5):
self.assertEqual(len(allFMTSLeavesPerCommonSupport[i][0]),1)
#
mst=MEDFileMeshStruct.New(ms[0])
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1,5):
+ for i in range(1, 5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- for i in xrange(5):
+ for i in range(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
f.loadArraysIfNecessary()
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
self.assertTrue(a.isEqual(ref_a,1e-14))
self.assertEqual(b,[3,4,5])
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
self.assertTrue(a.isEqual(ref_a,1e-14))
self.assertEqual(b,[3,4,5])
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
ref_a.setInfoOnComponents(comps)
self.assertTrue(a0.isEqual(ref_a,1e-14))#<- Test is here
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
self.assertTrue(a.isEqual(ref_a,1e-14))#<- Test is here
self.assertEqual(b,[3,4,5])
self.assertTrue(mml2.retrieveGlobalNodeIdsIfAny() is None)
- for i in xrange(1):
+ for i in range(1):
ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
ffCell.loadArraysIfNecessary()
ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileField1TS,owner);
if(dynamic_cast<MEDFileIntField1TS *>(p))
ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileIntField1TS,owner);
+ if(dynamic_cast<MEDFileFloatField1TS *>(p))
+ ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFloatField1TS,owner);
if(!ret)
throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeField1TS on downcast !");
return ret;
ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFieldMultiTS,owner);
if(dynamic_cast<MEDFileIntFieldMultiTS *>(p))
ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileIntFieldMultiTS,owner);
+ if(dynamic_cast<MEDFileFloatFieldMultiTS *>(p))
+ ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFloatFieldMultiTS,owner);
if(!ret)
throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeFieldMultiTS on downcast !");
return ret;
return ret;
}
+static std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > convertVecPairIntToVecPairTOFCT(const std::vector<std::pair<int,int> >& tmp)
+{
+ std::size_t sz(tmp.size());
+ std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesCpp(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ entitiesCpp[i].first=(TypeOfField)tmp[i].first;
+ entitiesCpp[i].second=(INTERP_KERNEL::NormalizedCellType)tmp[i].second;
+ }
+ return entitiesCpp;
+}
+
static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
{
+ static const char msg0[]="In list passed in argument some elements are NOT strings ! Expected a list containing only strings !";
+ static const char msg1[]="In tuple passed in argument some elements are NOT strings ! Expected a list containing only strings !";
+ static const char msg2[]="Unrecognized python argument : expected a list of string or tuple of string or string !";
if(PyList_Check(pyLi))
{
int size=PyList_Size(pyLi);
for(int i=0;i<size;i++)
{
PyObject *o=PyList_GetItem(pyLi,i);
- if(!PyString_Check(o))
- throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
- const char *st=PyString_AsString(o);
- v[i]=std::string(st);
+ v[i]=convertPyObjectToStr(o,msg0);
}
+ return ;
}
else if(PyTuple_Check(pyLi))
{
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(pyLi,i);
- if(!PyString_Check(o))
- throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
- const char *st=PyString_AsString(o);
- v[i]=std::string(st);
+ v[i]=convertPyObjectToStr(o,msg1);
}
+ return ;
}
- else if(PyString_Check(pyLi))
- {
- v.resize(1);
- v[0]=std::string((const char *)PyString_AsString(pyLi));
- }
- else
- {
- throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
- }
+ v.resize(1);
+ v[0]=convertPyObjectToStr(pyLi,msg2);
}
static PyObject *convertFieldDoubleVecToPy(const std::vector<MEDCoupling::MEDCouplingFieldDouble *>& li)
if(size2!=2)
throw INTERP_KERNEL::Exception(msg);
PyObject *o0=PyTuple_GetItem(o,0);
- if(PyString_Check(o0))
- p.first=std::string(PyString_AsString(o0));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.first=convertPyObjectToStr(o0,msg);
PyObject *o1=PyTuple_GetItem(o,1);
- if(PyString_Check(o1))
- p.second=std::string(PyString_AsString(o1));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.second=convertPyObjectToStr(o1,msg);
ret[i]=p;
}
else
for(int j=0;j<size3;j++)
{
PyObject *o0j=PyList_GetItem(o0,j);
- if(PyString_Check(o0j))
- {
- p.first[j]=std::string(PyString_AsString(o0j));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.first[j]=convertPyObjectToStr(o0j,msg);
}
}
else
throw INTERP_KERNEL::Exception(msg);
PyObject *o1=PyTuple_GetItem(o,1);
- if(PyString_Check(o1))
- p.second=std::string(PyString_AsString(o1));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.second=convertPyObjectToStr(o1,msg);
ret[i]=p;
}
else
*/
int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
+ static const char msg[]="MEDFileFields::__getitem__ : only integer or string with fieldname supported !";
if(PyInt_Check(obj))
{
return InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfFields());
}
- else if(PyString_Check(obj))
- {
- return self->getPosFromFieldName(PyString_AsString(obj));
- }
- else
- throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");
+ return self->getPosFromFieldName(convertPyObjectToStr(obj,msg));
}
void convertToMapIntDataArrayInt(PyObject *pyMap, std::map<int, MCAuto<DataArrayInt> >& cppMap)
#remove fieldnodeint
pointeFields = pointeMed.getFields()
- for i in range( pointeFields.getNumberOfFields() ):
+ for i in range(pointeFields.getNumberOfFields()):
if pointeFields.getFieldAtPos(i).getName() == "fieldnodeint":
pointeFields.destroyFieldAtPos( i )
break
self.assertEqual( fieldnodedoubleTS1.getNumberOfTS(), fieldnodedoubleTS2.getNumberOfTS())
io1 = fieldnodedoubleTS1.getIterations()
io2 = fieldnodedoubleTS2.getIterations()
- for i in range(fieldnodedoubleTS1.getNumberOfTS() ):
+ for i in range(fieldnodedoubleTS1.getNumberOfTS()):
fnd1 = fieldnodedoubleTS1.getFieldOnMeshAtLevel(ON_NODES, io1[i][0],io1[i][1],pointeUM0)
fnd2 = fieldnodedoubleTS2.getFieldOnMeshAtLevel(ON_NODES, io2[i][0],io2[i][1],um0)
self.assertTrue( fnd1.getArray().isEqual( fnd2.getArray(), 1e-12 ))
self.assertEqual( fieldnodedoubleTS1.getNumberOfTS(), fieldnodedoubleTS2.getNumberOfTS())
io1 = fieldnodedoubleTS1.getIterations()
io2 = fieldnodedoubleTS2.getIterations()
- for i in range(fieldnodedoubleTS1.getNumberOfTS() ):
+ for i in range(fieldnodedoubleTS1.getNumberOfTS()):
fnd1 = fieldnodedoubleTS1.getFieldOnMeshAtLevel(ON_CELLS, io1[i][0],io1[i][1],pointeUM0)
fnd2 = fieldnodedoubleTS2.getFieldOnMeshAtLevel(ON_CELLS, io2[i][0],io2[i][1],um0)
self.assertAlmostEqual( fnd1.accumulate(0), fnd2.accumulate(0) )
self._tmp=3
return
if name=="PDataArray":
- if self._tmp in self._data_array.keys():
+ if self._tmp in self._data_array:
self._data_array[self._tmp](attrs)
pass
return
except self.NormalException as e:
isOK=True
fd.seek(0)
- for i in xrange(e.getLineNb()): fd.readline()
+ for i in range(e.getLineNb()): fd.readline()
ref=fd.tell()+5
pass
if not isOK:
def __init__(self,fileName,tim=(0.,0)):
msg="The time specified in constructor as 2nd arg should be a tuple containing 2 values 1 float and 1 int !"
- if type(tim)!=tuple:
+ if not isinstance(tim, tuple):
raise Exception(msg)
if len(tim)!=2:
raise Exception(msg)
- if type(tim[0])!=float or type(tim[1])!=int:
+ if not isinstance(tim[0], float) or not isinstance(tim[1], int):
raise Exception(msg)
self._fileName=fileName
self._time=tim
def convert(file_in, driver_in, driver_out, format=1, file_out=None):
#
- print file_in
+ print(file_in)
#
if file_out is None:
file_out = file_in
msg = "Driver out %s is unknown"%(driver_out)
raise NotImplementedError(msg)
pass
- print file_out
+ print(file_out)
#
if driver_in == "GIBI":
sr = SauvReader.New(file_in)
ADD_DEFINITIONS(${PYTHON_DEFINITIONS} ${HDF5_DEFINITIONS} ${MEDFILE_DEFINITIONS} ${NUMPY_DEFINITIONS} ${SCIPY_DEFINITIONS})
SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_MEDPartitioner_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS};-DWITHOUT_AUTOFIELD")
SET (MEDPartitioner_SWIG_DPYS_FILES
INSTALL(TARGETS ${SWIG_MODULE_MEDPartitioner_REAL_NAME} DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDPartitioner.py)
-SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${MEDCOUPLING_INSTALL_SCRIPT_PYTHON})
+SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${MEDCOUPLING_INSTALL_PYTHON})
INSTALL(FILES MEDPartitioner.i MEDPartitionerCommon.i DESTINATION ${MEDCOUPLING_INSTALL_HEADERS})
INSTALL(FILES MEDPartitionerTest.py DESTINATION ${MEDCOUPLING_INSTALL_SCRIPT_PYTHON})
%newobject MEDPARTITIONER::MEDPartitioner::New;
%newobject MEDPARTITIONER::MEDPartitioner::Graph;
+%newobject MEDPARTITIONER::MEDPartitioner::Graph::getGraph;
+%newobject MEDPARTITIONER::MEDPartitioner::Graph::getPartition;
%newobject MEDPARTITIONER::MEDPartitioner::getMEDFileData;
%feature("unref") MEDCoupling::MEDFileData "$this->decrRef();"
{
class Graph
{
+ public:
+ typedef enum {METIS,SCOTCH} splitter_type;
public:
virtual void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector *sel=0) throw(INTERP_KERNEL::Exception);
- const MEDCoupling::MEDCouplingSkyLineArray *getGraph() const;
- const MEDCoupling::MEDCouplingSkyLineArray *getPartition() const;
+ MEDCoupling::MEDCouplingSkyLineArray *getGraph() const
+ {
+ const MEDCoupling::MEDCouplingSkyLineArray *ret(self->getGraph());
+ if(ret)
+ ret->incrRef();
+ return const_cast<MEDCoupling::MEDCouplingSkyLineArray *>(ret);
+ }
+ const MEDCoupling::MEDCouplingSkyLineArray *getPartition() const
+ {
+ const MEDCoupling::MEDCouplingSkyLineArray *ret(self->getPartition());
+ if(ret)
+ ret->incrRef();
+ return const_cast<MEDCoupling::MEDCouplingSkyLineArray *>(ret);
+ }
int nbVertices() const;
};
self.assertEqual( 2, joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences())
self.assertEqual( 1, joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences())
found=0
- for ii in xrange(joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()):
+ for ii in range(joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()):
correspond=joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(ii)
#VSR (10/05/2016): changed to work with metis 5.1... to be confirmed!
#if correspond.getCorrespondence().isEqual(DataArrayInt([1,3,2,4])):
INCLUDE(${SWIG_USE_FILE})
SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
SET (ParaMEDMEM_SWIG_DPYS_FILES
SWIG_LINK_LIBRARIES(ParaMEDMEM ${PYTHON_LIBRARIES} paramedmem medloader)
SWIG_CHECK_GENERATION(ParaMEDMEM)
-SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_DEFINITIONS "-shadow")
-
INSTALL(TARGETS _ParaMEDMEM DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
INSTALL(FILES ParaMEDMEM.i DESTINATION ${MEDCOUPLING_INSTALL_HEADERS})
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ParaMEDMEM.py test_InterpKernelDEC.py test_NonCoincidentDEC.py test_StructuredCoincidentDEC.py DESTINATION ${MEDCOUPLING_INSTALL_SCRIPT_PYTHON})
char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
for (i = 0; i < aSize; i++) {
PyObject *s = PyList_GetItem($input,i);
- if (!PyString_Check(s)) {
+ if (PyString_Check(s))
+ aStrs[i] = PyString_AsString(s);
+%#if PY_VERSION_HEX >= 0x03000000
+ else if (PyUnicode_Check(s))
+ aStrs[i] = PyUnicode_AsUTF8(s);
+%#endif
+ else {
free(aStrs);
PyErr_SetString(PyExc_ValueError, "List items must be strings");
return NULL;
}
- aStrs[i] = PyString_AsString(s);
}
aStrs[i] = 0;
$2 = &aStrs;
size = MPI_Comm_size(MPI_COMM_WORLD)
rank = MPI_Comm_rank(MPI_COMM_WORLD)
if size != 5:
- raise RuntimeError, "Expect MPI_COMM_WORLD size == 5"
- print rank
+ raise RuntimeError("Expect MPI_COMM_WORLD size == 5")
+ print(rank)
nproc_source = 3
- procs_source = range( nproc_source )
- procs_target = range( size - nproc_source + 1, size)
+ procs_source = list(range(nproc_source))
+ procs_target = list(range(size - nproc_source + 1, size))
interface = CommInterface()
target_group = MPIProcessorGroup(interface, procs_target)
dec.sendData()
dec.recvData()
field_after_int=parafield.getVolumeIntegral(0,True);
- self.failUnless(math.fabs(field_after_int-field_before_int)<1e-8)
+ self.assertTrue(math.fabs(field_after_int-field_before_int)<1e-8)
pass
else:
dec.synchronize()
size = MPI_Comm_size(MPI_COMM_WORLD)
rank = MPI_Comm_rank(MPI_COMM_WORLD)
if size != 5:
- raise RuntimeError, "Expect MPI_COMM_WORLD size == 5"
+ raise RuntimeError("Expect MPI_COMM_WORLD size == 5")
nproc_source = 3
-procs_source = range( nproc_source )
-procs_target = range( size - nproc_source + 1, size)
+procs_source = list(range(nproc_source))
+procs_target = list(range(size - nproc_source + 1, size))
interface = CommInterface()
field_before_int = [parafield.getVolumeIntegral(1)]
MPI_Bcast(field_before_int, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
dec.synchronize()
- print "DEC usage"
+ print("DEC usage")
dec.setForcedRenormalization(False)
dec.sendData()
epsilon = 1e-6
if abs(field_before_int[0] - field_after_int[0]) > epsilon:
- print "Field before is not equal field after: %s != %s"%\
- (field_before_int[0],field_after_int[0])
+ print("Field before is not equal field after: %s != %s"%\
+ (field_before_int[0],field_after_int[0]))
pass
MPI_Barrier(MPI_COMM_WORLD)
MPI_Finalize()
-print "# End of testNonCoincidentDEC"
+print("# End of testNonCoincidentDEC")
rank = MPI_Comm_rank(MPI_COMM_WORLD)
#
if size < 4:
- raise RuntimeError, "Expect MPI_COMM_WORLD size >= 4"
+ raise RuntimeError("Expect MPI_COMM_WORLD size >= 4")
#
interface = CommInterface()
#
for i in range(nb_local):
first=comptopo.firstLocalComponent()
for icomp in range(comptopo.nbLocalComponents()):
- self.failUnless(math.fabs(recv_value[i*comptopo.nbLocalComponents()+icomp]-
+ self.assertTrue(math.fabs(recv_value[i*comptopo.nbLocalComponents()+icomp]-
(float)(i*6+icomp+first))<1e-12)
pass
pass
source_group = 0
MPI_Barrier(MPI_COMM_WORLD)
MPI_Finalize()
- print "End of test StructuredCoincidentDEC"
+ print("End of test StructuredCoincidentDEC")
pass
#ifndef RENUMBERING_HXX_
#define RENUMBERING_HXX_
+
#include "RENUMBERDefines.hxx"
+#include "MCType.hxx"
+
#include <vector>
namespace MEDCoupling
ADD_DEFINITIONS(${PYTHON_DEFINITIONS} ${NUMPY_DEFINITIONS} ${SCIPY_DEFINITIONS})
SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+ SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES SWIG_FLAGS "-py3")
+ELSE()
+ SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+ENDIF()
SET(SWIG_MODULE_MEDRenumber_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS};-DWITHOUT_AUTOFIELD")
IF(Boost_FOUND)
def MEDCouplingDataArrayBytenew(cls,*args):
import _MEDRenumber
return _MEDRenumber.DataArrayByte____new___(cls,args)
+def MEDCouplingDataArrayFloatnew(cls,*args):
+ import _MEDRenumber
+ return _MEDRenumber.DataArrayFloat____new___(cls,args)
+def MEDCouplingDataArrayFloatIadd(self,*args):
+ import _MEDRenumber
+ return _MEDRenumber.DataArrayFloat____iadd___(self, self, *args)
+def MEDCouplingDataArrayFloatIsub(self,*args):
+ import _MEDRenumber
+ return _MEDRenumber.DataArrayFloat____isub___(self, self, *args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+ import _MEDRenumber
+ return _MEDRenumber.DataArrayFloat____imul___(self, self, *args)
+def MEDCouplingDataArrayFloatIdiv(self,*args):
+ import _MEDRenumber
+ return _MEDRenumber.DataArrayFloat____idiv___(self, self, *args)
def MEDCouplingDataArrayDoubleTupleIadd(self,*args):
import _MEDRenumber
return _MEDRenumber.DataArrayDoubleTuple____iadd___(self, self, *args)
%init %{ import_array(); %}
#endif
+%init %{ initializeMe(); %}
+
%feature("autodoc", "1");
%feature("docstring");
%include "MEDCouplingRefCountObject.i"
%include "MEDCouplingMemArray.i"
+%{
+ void initializeMe()
+ {// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions.
+ SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+ SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+ }
+%}
+
class Renumbering
{
public:
import os
__filename=os.environ.get('PYTHONSTARTUP')
if __filename and os.path.isfile(__filename):
- execfile(__filename)
+ exec(open(__filename).read())
pass
%}
dirs=["MEDCoupling","MEDCoupling/Test","MEDLoader","MEDLoader/Swig","MEDLoader/Test","MEDPartitioner","MEDPartitioner/Test","MEDPartitioner_Swig","RENUMBER","RENUMBER_Swig","INTERP_KERNELTest","ParaMEDMEM","ParaMEDLoader","ParaMEDMEMTest","ParaMEDMEM_Swig","doc/user/doxygen/fakesources","doc/user/doxygen/doxy2swig","doc/user/doxygen/doxfiles","/home/H87074/salome/DEV/modules/src/MED/src/MEDCouplingCorba","/home/H87074/salome/DEV/modules/src/MED/src/MEDCouplingCorba/Client","/home/H87074/salome/DEV/modules/src/MED/src/MEDCouplingCorba/Test","/home/H87074/salome/DEV/modules/src/MED/src/MEDCalc/cmp","/home/H87074/salome/DEV/modules/src/MED/src/MEDCalculator","/home/H87074/salome/DEV/modules/src/MED/src/MEDCalculator/Swig","/home/H87074/salome/DEV/modules/src/MED/src/MEDCalculator/Test","/home/H87074/salome/DEV/modules/src/PARAVIS/src/Plugins/MEDReader/IO"]
dirname=dirs[-1]
i=0
-print rep1(dirname,rep)
+print(rep1(dirname,rep))
"""for r,dirs,fis in os.walk(dirname):
for fi in fis:
if os.path.splitext(fi)[1] not in [".dox",".doxy"]:
# Skip this script!
if fileName == __myName:
if not quiet:
- print "!!! Skipping script %s !!!" % __myName
+ print("!!! Skipping script %s !!!" % __myName)
continue
ok = False
if fileName[-28:] != "MEDCouplingNatureOfFieldEnum":
else:
ok = True
if not ok: continue # skip file
- if not quiet: print "Handling %s ..." % fileName
+ if not quiet: print("Handling %s ..." % fileName)
for line in fileinput.input(fileName, inplace=1, backup='.bak'):
for before, after in REPLACEMENTS:
line = re.sub("(\W|^)(%s)(\W|$)" % before, r"\1%s\3" % after, line.rstrip('\r\n'))