1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingFieldDiscretization.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
27 #include "CellModel.hxx"
28 #include "InterpolationUtils.hxx"
29 #include "InterpKernelAutoPtr.hxx"
30 #include "InterpKernelGaussCoords.hxx"
31 #include "InterpKernelMatrixTools.hxx"
41 using namespace ParaMEDMEM;
43 const double MEDCouplingFieldDiscretization::DFLT_PRECISION=1.e-12;
45 const char MEDCouplingFieldDiscretizationP0::REPR[]="P0";
47 const TypeOfField MEDCouplingFieldDiscretizationP0::TYPE=ON_CELLS;
49 const char MEDCouplingFieldDiscretizationP1::REPR[]="P1";
51 const TypeOfField MEDCouplingFieldDiscretizationP1::TYPE=ON_NODES;
53 const int MEDCouplingFieldDiscretizationPerCell::DFT_INVALID_LOCID_VALUE=-1;
55 const char MEDCouplingFieldDiscretizationGauss::REPR[]="GAUSS";
57 const TypeOfField MEDCouplingFieldDiscretizationGauss::TYPE=ON_GAUSS_PT;
59 const char MEDCouplingFieldDiscretizationGaussNE::REPR[]="GSSNE";
61 const TypeOfField MEDCouplingFieldDiscretizationGaussNE::TYPE=ON_GAUSS_NE;
63 const char MEDCouplingFieldDiscretizationKriging::REPR[]="KRIGING";
65 const TypeOfField MEDCouplingFieldDiscretizationKriging::TYPE=ON_NODES_KR;
67 // doc is here http://www.code-aster.org/V2/doc/default/fr/man_r/r3/r3.01.01.pdf
68 const double MEDCouplingFieldDiscretizationGaussNE::FGP_POINT1[1]={0.};
69 const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG2[2]={1.,1.};
70 const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG3[3]={0.5555555555555556,0.8888888888888888,0.5555555555555556};
71 const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG4[4]={0.347854845137454,0.347854845137454,0.652145154862546,0.652145154862546};
72 const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI3[3]={0.16666666666666666,0.16666666666666666,0.16666666666666666};
73 const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI6[6]={0.0549758718227661,0.0549758718227661,0.0549758718227661,0.11169079483905,0.11169079483905,0.11169079483905};
74 const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI7[7]={0.062969590272413,0.062969590272413,0.062969590272413,0.066197076394253,0.066197076394253,0.066197076394253,0.1125};
75 const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD4[4]={1.,1.,1.,1.};
76 const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD8[8]={1.,1.,1.,1.,1.,1.,1.,1.};
77 const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD9[9]={0.30864197530864196,0.30864197530864196,0.30864197530864196,0.30864197530864196,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.7901234567901234};
78 const double MEDCouplingFieldDiscretizationGaussNE::FGP_TETRA4[4]={0.041666666666666664,0.041666666666666664,0.041666666666666664,0.041666666666666664};
79 const double MEDCouplingFieldDiscretizationGaussNE::FGP_TETRA10[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check
80 const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA6[6]={0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666};
81 const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA15[15]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check
82 const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA8[8]={1.,1.,1.,1.,1.,1.,1.,1.};
83 const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA20[20]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
84 const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA27[27]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
85 const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA5[5]={0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333};
86 const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA13[13]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check
87 const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG2[2]={-1.,1.};
88 const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG3[3]={-1.,1.,0.};
89 const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG4[4]={-1.,1.,-0.3333333333333333,0.3333333333333333};
90 const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI3[6]={0.,0.,1.,0.,0.,1.};
91 const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI6[12]={0.,0.,1.,0.,0.,1.,0.5,0.,0.5,0.5,0.,0.5};
92 const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI7[14]={0.,0.,1.,0.,0.,1.,0.5,0.,0.5,0.5,0.,0.5,0.3333333333333333,0.3333333333333333};
93 const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD4[8]={-1.,-1.,1.,-1.,1.,1.,-1.,1.};
94 const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD8[16]={-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.};
95 const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD9[18]={-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.,0.,0.};
96 const double MEDCouplingFieldDiscretizationGaussNE::REF_TETRA4[12]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.};
97 const double MEDCouplingFieldDiscretizationGaussNE::REF_TETRA10[30]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.5,0.,0.};
98 const double MEDCouplingFieldDiscretizationGaussNE::REF_PENTA6[18]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.};
99 const double MEDCouplingFieldDiscretizationGaussNE::REF_PENTA15[45]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.};
100 const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA8[24]={-1.,-1.,-1.,1.,-1.,-1.,1.,1.,-1.,-1.,1.,-1.,-1.,-1.,1.,1.,-1.,1.,1.,1.,1.,-1.,1.,1.};
101 const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA20[60]={-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.,-1.,-1.,1.,0.,-1.,0.,1.,-1.,-1.,0.,-1.,-1.,-1.,0.,1.,-1.,0.,1.,1.,0.,-1.,1.,0.,0.,-1.,1.,1.,0.,1.,0.,1.,1.,-1.,0.,1.};
102 const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA27[81]={-1.,-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.,-1.,0.,1.,-1.,1.,0.,-1.,0.,-1.,-1.,-1.,0.,1.,0.,1.,1.,1.,0.,1.,0.,-1.,1.,-1.,-1.,0.,-1.,1.,0.,1.,1.,0.,1.,-1.,0.,0.,0.,-1.,-1.,0.,0.,0.,1.,0.,1.,0.,0.,0.,-1.,0.,0.,0.,1.,0.,0.,0.};
103 const double MEDCouplingFieldDiscretizationGaussNE::REF_PYRA5[15]={1.,0.,0.,0.,1.,0.,-1.,0.,0.,0.,-1.,0.,0.,0.,1.};
104 const double MEDCouplingFieldDiscretizationGaussNE::REF_PYRA13[39]={1.,0.,0.,0.,-1.,0.,-1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,-0.5,0.,-0.5,-0.5,0.,-0.5,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.,-0.5,0.5,-0.5,0.,0.5,0.,0.5,0.5};
105 const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG2[2]={0.577350269189626,-0.577350269189626};
106 const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG3[3]={-0.774596669241,0.,0.774596669241};
107 const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG4[4]={0.339981043584856,-0.339981043584856,0.861136311594053,-0.861136311594053};
108 const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI3[6]={0.16666666666666667,0.16666666666666667,0.6666666666666667,0.16666666666666667,0.16666666666666667,0.6666666666666667};
109 const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI6[12]={0.091576213509771,0.091576213509771,0.816847572980458,0.091576213509771,0.091576213509771,0.816847572980458,0.445948490915965,0.10810301816807,0.445948490915965,0.445948490915965,0.10810301816807,0.445948490915965};
110 const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI7[14]={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};
111 const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD4[8]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483};
112 const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD8[16]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.,-0.774596669241483,0.774596669241483,0.,0.,0.774596669241483,-0.774596669241483,0.};
113 const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD9[18]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.,-0.774596669241483,0.774596669241483,0.,0.,0.774596669241483,-0.774596669241483,0.,0.,0.};
114 const double MEDCouplingFieldDiscretizationGaussNE::LOC_TETRA4[12]={0.1381966011250105,0.1381966011250105,0.1381966011250105,0.1381966011250105,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.1381966011250105};
115 const double MEDCouplingFieldDiscretizationGaussNE::LOC_TETRA10[30]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.5,0.,0.};//to check
116 const double MEDCouplingFieldDiscretizationGaussNE::LOC_PENTA6[18]={-0.5773502691896258,0.5,0.5,-0.5773502691896258,0.,0.5,-0.5773502691896258,0.5,0.,0.5773502691896258,0.5,0.5,0.5773502691896258,0.,0.5,0.5773502691896258,0.5,0.};
117 const double MEDCouplingFieldDiscretizationGaussNE::LOC_PENTA15[45]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.};//to check
118 const double MEDCouplingFieldDiscretizationGaussNE::LOC_HEXA8[24]={-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258};
119 const double MEDCouplingFieldDiscretizationGaussNE::LOC_HEXA20[60]={-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.,-1.,-1.,1.,0.,-1.,0.,1.,-1.,-1.,0.,-1.,-1.,-1.,0.,1.,-1.,0.,1.,1.,0.,-1.,1.,0.,0.,-1.,1.,1.,0.,1.,0.,1.,1.,-1.,0.,1.};//to check
120 const double MEDCouplingFieldDiscretizationGaussNE::LOC_HEXA27[81]={-1.,-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.,-1.,0.,1.,-1.,1.,0.,-1.,0.,-1.,-1.,-1.,0.,1.,0.,1.,1.,1.,0.,1.,0.,-1.,1.,-1.,-1.,0.,-1.,1.,0.,1.,1.,0.,1.,-1.,0.,0.,0.,-1.,-1.,0.,0.,0.,1.,0.,1.,0.,0.,0.,-1.,0.,0.,0.,1.,0.,0.,0.};
121 const double MEDCouplingFieldDiscretizationGaussNE::LOC_PYRA5[15]={0.5,0.,0.1531754163448146,0.,0.5,0.1531754163448146,-0.5,0.,0.1531754163448146,0.,-0.5,0.1531754163448146,0.,0.,0.6372983346207416};
122 const double MEDCouplingFieldDiscretizationGaussNE::LOC_PYRA13[39]={1.,0.,0.,0.,-1.,0.,-1.,0.,0.,0.,1.,0.,0.,0.,0.999999999999,0.5,-0.5,0.,-0.5,-0.5,0.,-0.5,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.,-0.5,0.5,-0.5,0.,0.5,0.,0.5,0.5};//to check 0.99999... to avoid nan ! on node #4 of PYRA13
124 MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION)
128 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::New(TypeOfField type)
132 case MEDCouplingFieldDiscretizationP0::TYPE:
133 return new MEDCouplingFieldDiscretizationP0;
134 case MEDCouplingFieldDiscretizationP1::TYPE:
135 return new MEDCouplingFieldDiscretizationP1;
136 case MEDCouplingFieldDiscretizationGauss::TYPE:
137 return new MEDCouplingFieldDiscretizationGauss;
138 case MEDCouplingFieldDiscretizationGaussNE::TYPE:
139 return new MEDCouplingFieldDiscretizationGaussNE;
140 case MEDCouplingFieldDiscretizationKriging::TYPE:
141 return new MEDCouplingFieldDiscretizationKriging;
143 throw INTERP_KERNEL::Exception("Choosen discretization is not implemented yet.");
147 TypeOfField MEDCouplingFieldDiscretization::GetTypeOfFieldFromStringRepr(const std::string& repr)
149 if(repr==MEDCouplingFieldDiscretizationP0::REPR)
150 return MEDCouplingFieldDiscretizationP0::TYPE;
151 if(repr==MEDCouplingFieldDiscretizationP1::REPR)
152 return MEDCouplingFieldDiscretizationP1::TYPE;
153 if(repr==MEDCouplingFieldDiscretizationGauss::REPR)
154 return MEDCouplingFieldDiscretizationGauss::TYPE;
155 if(repr==MEDCouplingFieldDiscretizationGaussNE::REPR)
156 return MEDCouplingFieldDiscretizationGaussNE::TYPE;
157 if(repr==MEDCouplingFieldDiscretizationKriging::REPR)
158 return MEDCouplingFieldDiscretizationKriging::TYPE;
159 throw INTERP_KERNEL::Exception("Representation does not match with any field discretization !");
162 bool MEDCouplingFieldDiscretization::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const
165 return isEqualIfNotWhy(other,eps,reason);
168 bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
170 return isEqual(other,eps);
174 * This method is an alias of MEDCouplingFieldDiscretization::clone. It is only here for coherency with all the remaining of MEDCoupling.
175 * \sa MEDCouplingFieldDiscretization::clone.
177 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::deepCpy() const
183 * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance.
185 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const int *startCellIds, const int *endCellIds) const
191 * For all field discretization excepted GaussPts the slice( \a beginCellId, \a endCellIds, \a stepCellId ) has no impact on the cloned instance.
193 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const
199 * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally.
201 void MEDCouplingFieldDiscretization::updateTime() const
205 std::size_t MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren() const
210 std::vector<const BigMemoryObject *> MEDCouplingFieldDiscretization::getDirectChildrenWithNull() const
212 return std::vector<const BigMemoryObject *>();
216 * Computes normL1 of DataArrayDouble instance arr.
217 * @param res output parameter expected to be of size arr->getNumberOfComponents();
218 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
220 void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const
222 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
223 int nbOfCompo=arr->getNumberOfComponents();
224 int nbOfElems=getNumberOfTuples(mesh);
225 std::fill(res,res+nbOfCompo,0.);
226 const double *arrPtr=arr->getConstPointer();
227 const double *volPtr=vol->getArray()->getConstPointer();
229 for(int i=0;i<nbOfElems;i++)
231 double v=fabs(volPtr[i]);
232 for(int j=0;j<nbOfCompo;j++)
233 res[j]+=fabs(arrPtr[i*nbOfCompo+j])*v;
236 std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
240 * Computes normL2 of DataArrayDouble instance arr.
241 * @param res output parameter expected to be of size arr->getNumberOfComponents();
242 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
244 void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const
246 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
247 int nbOfCompo=arr->getNumberOfComponents();
248 int nbOfElems=getNumberOfTuples(mesh);
249 std::fill(res,res+nbOfCompo,0.);
250 const double *arrPtr=arr->getConstPointer();
251 const double *volPtr=vol->getArray()->getConstPointer();
253 for(int i=0;i<nbOfElems;i++)
255 double v=fabs(volPtr[i]);
256 for(int j=0;j<nbOfCompo;j++)
257 res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*v;
260 std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
261 std::transform(res,res+nbOfCompo,res,std::ptr_fun<double,double>(std::sqrt));
265 * Computes integral of DataArrayDouble instance arr.
266 * @param res output parameter expected to be of size arr->getNumberOfComponents();
267 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
269 void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const
272 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : mesh is NULL !");
274 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : input array is NULL !");
275 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,isWAbs);
276 int nbOfCompo=arr->getNumberOfComponents();
277 int nbOfElems=getNumberOfTuples(mesh);
278 if(nbOfElems!=arr->getNumberOfTuples())
280 std::ostringstream oss; oss << "MEDCouplingFieldDiscretization::integral : field is not correct ! number of tuples in array is " << arr->getNumberOfTuples();
281 oss << " whereas number of tuples expected is " << nbOfElems << " !";
282 throw INTERP_KERNEL::Exception(oss.str().c_str());
284 std::fill(res,res+nbOfCompo,0.);
285 const double *arrPtr=arr->getConstPointer();
286 const double *volPtr=vol->getArray()->getConstPointer();
287 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfCompo];
288 for (int i=0;i<nbOfElems;i++)
290 std::transform(arrPtr+i*nbOfCompo,arrPtr+(i+1)*nbOfCompo,(double *)tmp,std::bind2nd(std::multiplies<double>(),volPtr[i]));
291 std::transform((double *)tmp,(double *)tmp+nbOfCompo,res,res,std::plus<double>());
296 * This method is strictly equivalent to MEDCouplingFieldDiscretization::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
298 * \param [out] beginOut Valid only if \a di is NULL
299 * \param [out] endOut Valid only if \a di is NULL
300 * \param [out] stepOut Valid only if \a di is NULL
301 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
303 * \sa MEDCouplingFieldDiscretization::buildSubMeshData
305 MEDCouplingMesh *MEDCouplingFieldDiscretization::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
307 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds);
308 return buildSubMeshData(mesh,da->begin(),da->end(),di);
311 void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const
319 void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
326 void MEDCouplingFieldDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
330 void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *& arr)
338 void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector<double>& tinyInfo)
343 * This method is typically the first step of renumbering. The implementation is empty it is not a bug only gauss is impacted
344 * virtualy by this method.
346 void MEDCouplingFieldDiscretization::renumberCells(const int *old2NewBg, bool check)
350 double MEDCouplingFieldDiscretization::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
352 throw INTERP_KERNEL::Exception("getIJK Invalid ! only for GaussPoint and GaussNE discretizations !");
355 void MEDCouplingFieldDiscretization::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
356 const std::vector<double>& gsCoo, const std::vector<double>& wg)
358 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
361 void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector<double>& refCoo,
362 const std::vector<double>& gsCoo, const std::vector<double>& wg)
364 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
367 void MEDCouplingFieldDiscretization::clearGaussLocalizations()
369 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
372 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId)
374 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
377 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) const
379 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
382 int MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const
384 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
387 int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(int cellId) const
389 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
392 int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
394 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
397 std::set<int> MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
399 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
402 void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
404 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
407 void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const std::string& msg)
410 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !");
411 int oldNbOfElems=arr->getNumberOfTuples();
412 int nbOfComp=arr->getNumberOfComponents();
413 int newNbOfTuples=newNbOfEntity;
414 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrCpy=arr->deepCpy();
415 const double *ptSrc=arrCpy->getConstPointer();
416 arr->reAlloc(newNbOfTuples);
417 double *ptToFill=arr->getPointer();
418 std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits<double>::max());
419 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfComp];
420 for(int i=0;i<oldNbOfElems;i++)
422 int newNb=old2NewPtr[i];
423 if(newNb>=0)//if newNb<0 the node is considered as out.
425 if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to<double>(),std::numeric_limits<double>::max()))
426 ==ptToFill+(newNb+1)*nbOfComp)
427 std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp);
430 std::transform(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp,(double *)tmp,std::minus<double>());
431 std::transform((double *)tmp,((double *)tmp)+nbOfComp,(double *)tmp,std::ptr_fun<double,double>(fabs));
432 //if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
433 if(*std::max_element((double *)tmp,((double *)tmp)+nbOfComp)>eps)
435 std::ostringstream oss;
436 oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
437 << " have been merged and " << msg << " field on them are different !";
438 throw INTERP_KERNEL::Exception(oss.str().c_str());
445 void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const std::string& msg)
447 int nbOfComp=arr->getNumberOfComponents();
448 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrCpy=arr->deepCpy();
449 const double *ptSrc=arrCpy->getConstPointer();
450 arr->reAlloc(new2OldSz);
451 double *ptToFill=arr->getPointer();
452 for(int i=0;i<new2OldSz;i++)
454 int oldNb=new2OldPtr[i];
455 std::copy(ptSrc+oldNb*nbOfComp,ptSrc+(oldNb+1)*nbOfComp,ptToFill+i*nbOfComp);
459 MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization()
463 TypeOfField MEDCouplingFieldDiscretizationP0::getEnum() const
469 * This method is simply called by MEDCouplingFieldDiscretization::deepCpy. It performs the deep copy of \a this.
471 * \sa MEDCouplingFieldDiscretization::deepCpy.
473 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP0::clone() const
475 return new MEDCouplingFieldDiscretizationP0;
478 std::string MEDCouplingFieldDiscretizationP0::getStringRepr() const
480 return std::string(REPR);
483 const char *MEDCouplingFieldDiscretizationP0::getRepr() const
488 bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
492 reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined.";
495 const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP0 *>(other);
498 reason="Spatial discrtization of this is ON_CELLS, which is not the case of other.";
502 int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const
505 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !");
506 return mesh->getNumberOfCells();
510 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
511 * The input code coherency is also checked regarding spatial discretization of \a this.
512 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
513 * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution).
515 int MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
518 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
519 int nbOfSplit=(int)idsPerType.size();
520 int nbOfTypes=(int)code.size()/3;
522 for(int i=0;i<nbOfTypes;i++)
524 int nbOfEltInChunk=code[3*i+1];
526 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
530 if(pos<0 || pos>=nbOfSplit)
532 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
533 throw INTERP_KERNEL::Exception(oss.str().c_str());
535 const DataArrayInt *ids(idsPerType[pos]);
536 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
538 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
539 throw INTERP_KERNEL::Exception(oss.str().c_str());
547 int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
550 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !");
551 return mesh->getNumberOfCells();
554 DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const
557 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !");
558 int nbOfTuples=mesh->getNumberOfCells();
559 DataArrayInt *ret=DataArrayInt::New();
560 ret->alloc(nbOfTuples+1,1);
565 void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
566 const int *old2NewBg, bool check)
569 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !");
570 const int *array=old2NewBg;
572 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
573 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
576 (*it)->renumberInPlace(array);
579 free(const_cast<int *>(array));
582 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
585 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !");
586 return mesh->getBarycenterAndOwner();
589 void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
590 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
593 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds : NULL input mesh !");
594 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
595 tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
596 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
597 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(tmp->deepCpy());
598 cellRestriction=tmp.retn();
599 trueTupleRestriction=tmp2.retn();
602 void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const
604 stream << "P0 spatial discretization.";
607 void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const
611 void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
614 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh or DataArray !");
615 if(mesh->getNumberOfCells()!=da->getNumberOfTuples())
617 std::ostringstream message;
618 message << "Field on cells invalid because there are " << mesh->getNumberOfCells();
619 message << " cells in mesh and " << da->getNumberOfTuples() << " tuples in field !";
620 throw INTERP_KERNEL::Exception(message.str().c_str());
624 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
627 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getMeasureField : mesh instance specified is NULL !");
628 return mesh->getMeasureField(isAbs);
631 void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
634 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !");
635 int id=mesh->getCellContainingPoint(loc,_precision);
637 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !");
638 arr->getTuple(id,res);
641 void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
643 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
645 throw INTERP_KERNEL::Exception("P0::getValueOnPos is only accessible for structured meshes !");
646 int id=meshC->getCellIdFromPos(i,j,k);
647 arr->getTuple(id,res);
650 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
653 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !");
654 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsArr,eltsIndexArr;
655 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
656 const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
657 int spaceDim=mesh->getSpaceDimension();
658 int nbOfComponents=arr->getNumberOfComponents();
659 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
660 ret->alloc(nbOfPoints,nbOfComponents);
661 double *ptToFill=ret->getPointer();
662 for(int i=0;i<nbOfPoints;i++,ptToFill+=nbOfComponents)
663 if(eltsIndex[i+1]-eltsIndex[i]>=1)
664 arr->getTuple(elts[eltsIndex[i]],ptToFill);
667 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
668 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
669 oss << ") detected outside mesh : unable to apply P0::getValueOnMulti ! ";
670 throw INTERP_KERNEL::Exception(oss.str().c_str());
676 * Nothing to do. It's not a bug.
678 void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
682 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
684 RenumberEntitiesFromO2NArr(epsOnVals,old2New,newSz,arr,"Cell");
687 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
689 RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell");
693 * This method returns a tuple ids selection from cell ids selection [start;end).
694 * This method is called by MEDCouplingFieldDiscretizationP0::buildSubMeshData to return parameter \b di.
695 * Here for P0 it's very simple !
697 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
700 DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
702 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
703 ret->alloc((int)std::distance(startCellIds,endCellIds),1);
704 std::copy(startCellIds,endCellIds,ret->getPointer());
709 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
710 * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh.
711 * Example : The first cell id of returned mesh has the (*di)[0] id in 'mesh'
713 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange
715 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
718 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !");
719 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPart(start,end);
720 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diSafe=DataArrayInt::New();
721 diSafe->alloc((int)std::distance(start,end),1);
722 std::copy(start,end,diSafe->getPointer());
728 * This method is strictly equivalent to MEDCouplingFieldDiscretizationP0::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
730 * \param [out] beginOut Valid only if \a di is NULL
731 * \param [out] endOut Valid only if \a di is NULL
732 * \param [out] stepOut Valid only if \a di is NULL
733 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
735 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshData
737 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
740 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !");
741 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
742 di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds;
746 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const
749 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !");
750 return mesh->getNumberOfNodes();
754 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
755 * The input code coherency is also checked regarding spatial discretization of \a this.
756 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
757 * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution).
759 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
762 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
763 int nbOfSplit=(int)idsPerType.size();
764 int nbOfTypes=(int)code.size()/3;
766 for(int i=0;i<nbOfTypes;i++)
768 int nbOfEltInChunk=code[3*i+1];
770 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
774 if(pos<0 || pos>=nbOfSplit)
776 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
777 throw INTERP_KERNEL::Exception(oss.str().c_str());
779 const DataArrayInt *ids(idsPerType[pos]);
780 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
782 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
783 throw INTERP_KERNEL::Exception(oss.str().c_str());
791 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
794 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !");
795 return mesh->getNumberOfNodes();
799 * Nothing to do here.
801 void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector<DataArray *>& arrays,
802 const int *old2NewBg, bool check)
806 DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const
809 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !");
810 int nbOfTuples=mesh->getNumberOfNodes();
811 DataArrayInt *ret=DataArrayInt::New();
812 ret->alloc(nbOfTuples+1,1);
817 DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
820 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !");
821 return mesh->getCoordinatesAndOwner();
824 void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
825 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
828 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : NULL input mesh !");
829 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=mesh->getCellIdsFullyIncludedInNodeIds(tupleIdsBg,tupleIdsEnd);
830 const MEDCouplingUMesh *meshc=dynamic_cast<const MEDCouplingUMesh *>(mesh);
832 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : trying to subpart field on nodes by node ids ! Your mesh has to be unstructured !");
833 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> meshPart=static_cast<MEDCouplingUMesh *>(meshc->buildPartOfMySelf(ret1->begin(),ret1->end(),true));
834 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=meshPart->computeFetchedNodeIds();
835 cellRestriction=ret1.retn();
836 trueTupleRestriction=ret2.retn();
839 void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
842 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh or DataArray !");
843 if(mesh->getNumberOfNodes()!=da->getNumberOfTuples())
845 std::ostringstream message;
846 message << "Field on nodes invalid because there are " << mesh->getNumberOfNodes();
847 message << " nodes in mesh and " << da->getNumberOfTuples() << " tuples in field !";
848 throw INTERP_KERNEL::Exception(message.str().c_str());
853 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
854 * @param di is an array returned that specifies entity ids (here nodes ids) in mesh 'mesh' of entity in returned submesh.
855 * Example : The first node id of returned mesh has the (*di)[0] id in 'mesh'
857 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
860 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !");
861 DataArrayInt *diTmp=0;
862 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPartAndReduceNodes(start,end,diTmp);
863 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diTmpSafe(diTmp);
864 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
870 * This method is strictly equivalent to MEDCouplingFieldDiscretizationNodes::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
872 * \param [out] beginOut Valid only if \a di is NULL
873 * \param [out] endOut Valid only if \a di is NULL
874 * \param [out] stepOut Valid only if \a di is NULL
875 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
877 * \sa MEDCouplingFieldDiscretizationNodes::buildSubMeshData
879 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
882 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !");
883 DataArrayInt *diTmp=0;
884 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp);
887 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diTmpSafe(diTmp);
888 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
895 * This method returns a tuple ids selection from cell ids selection [start;end).
896 * This method is called by MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData to return parameter \b di.
897 * Here for P1 only nodes fetched by submesh of mesh[startCellIds:endCellIds) is returned !
899 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
902 DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
905 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !");
906 const MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh=mesh->buildUnstructured();
907 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh2=static_cast<MEDCouplingUMesh *>(umesh->buildPartOfMySelf(startCellIds,endCellIds,true));
908 return umesh2->computeFetchedNodeIds();
911 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, int newNbOfNodes, DataArrayDouble *arr) const
913 RenumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,newNbOfNodes,arr,"Node");
917 * Nothing to do it's not a bug.
919 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
924 * Nothing to do it's not a bug.
926 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
930 void MEDCouplingFieldDiscretizationOnNodes::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
932 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
934 throw INTERP_KERNEL::Exception("OnNodes::getValueOnPos(i,j,k) is only accessible for structured meshes !");
935 int id=meshC->getNodeIdFromPos(i,j,k);
936 arr->getTuple(id,res);
939 TypeOfField MEDCouplingFieldDiscretizationP1::getEnum() const
945 * This method is simply called by MEDCouplingFieldDiscretization::deepCpy. It performs the deep copy of \a this.
947 * \sa MEDCouplingFieldDiscretization::deepCpy.
949 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP1::clone() const
951 return new MEDCouplingFieldDiscretizationP1;
954 std::string MEDCouplingFieldDiscretizationP1::getStringRepr() const
956 return std::string(REPR);
959 const char *MEDCouplingFieldDiscretizationP1::getRepr() const
964 bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
968 reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined.";
971 const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP1 *>(other);
974 reason="Spatial discrtization of this is ON_NODES, which is not the case of other.";
978 void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const
980 if(nat!=ConservativeVolumic)
981 throw INTERP_KERNEL::Exception("Invalid nature for P1 field : expected ConservativeVolumic !");
984 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
987 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getMeasureField : mesh instance specified is NULL !");
988 return mesh->getMeasureFieldOnNode(isAbs);
991 void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
994 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !");
995 int id=mesh->getCellContainingPoint(loc,_precision);
997 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !");
998 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(id);
999 if(type!=INTERP_KERNEL::NORM_SEG2 && type!=INTERP_KERNEL::NORM_TRI3 && type!=INTERP_KERNEL::NORM_TETRA4)
1000 throw INTERP_KERNEL::Exception("P1 getValueOn is not specified for not simplex cells !");
1001 getValueInCell(mesh,id,arr,loc,res);
1005 * This method localizes a point defined by 'loc' in a cell with id 'cellId' into mesh 'mesh'.
1006 * The result is put into res expected to be of size at least arr->getNumberOfComponents()
1008 void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const
1011 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !");
1012 std::vector<int> conn;
1013 std::vector<double> coo;
1014 mesh->getNodeIdsOfCell(cellId,conn);
1015 for(std::vector<int>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
1016 mesh->getCoordinatesOfNode(*iter,coo);
1017 int spaceDim=mesh->getSpaceDimension();
1018 std::size_t nbOfNodes=conn.size();
1019 std::vector<const double *> vec(nbOfNodes);
1020 for(std::size_t i=0;i<nbOfNodes;i++)
1021 vec[i]=&coo[i*spaceDim];
1022 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfNodes];
1023 INTERP_KERNEL::barycentric_coords(vec,loc,tmp);
1024 int sz=arr->getNumberOfComponents();
1025 INTERP_KERNEL::AutoPtr<double> tmp2=new double[sz];
1026 std::fill(res,res+sz,0.);
1027 for(std::size_t i=0;i<nbOfNodes;i++)
1029 arr->getTuple(conn[i],(double *)tmp2);
1030 std::transform((double *)tmp2,((double *)tmp2)+sz,(double *)tmp2,std::bind2nd(std::multiplies<double>(),tmp[i]));
1031 std::transform(res,res+sz,(double *)tmp2,res,std::plus<double>());
1035 DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
1038 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !");
1039 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsArr,eltsIndexArr;
1040 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
1041 const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
1042 int spaceDim=mesh->getSpaceDimension();
1043 int nbOfComponents=arr->getNumberOfComponents();
1044 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1045 ret->alloc(nbOfPoints,nbOfComponents);
1046 double *ptToFill=ret->getPointer();
1047 for(int i=0;i<nbOfPoints;i++)
1048 if(eltsIndex[i+1]-eltsIndex[i]>=1)
1049 getValueInCell(mesh,elts[eltsIndex[i]],arr,loc+i*spaceDim,ptToFill+i*nbOfComponents);
1052 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
1053 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
1054 oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! ";
1055 throw INTERP_KERNEL::Exception(oss.str().c_str());
1060 void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const
1062 stream << "P1 spatial discretization.";
1065 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0)
1069 MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell()
1072 _discr_per_cell->decrRef();
1076 * This constructor deep copies ParaMEDMEM::DataArrayInt instance from other (if any).
1078 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds):_discr_per_cell(0)
1080 DataArrayInt *arr=other._discr_per_cell;
1083 if(startCellIds==0 && endCellIds==0)
1084 _discr_per_cell=arr->deepCpy();
1086 _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds);
1090 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, int beginCellIds, int endCellIds, int stepCellIds):_discr_per_cell(0)
1092 DataArrayInt *arr=other._discr_per_cell;
1095 _discr_per_cell=arr->selectByTupleId2(beginCellIds,endCellIds,stepCellIds);
1099 void MEDCouplingFieldDiscretizationPerCell::updateTime() const
1102 updateTimeWith(*_discr_per_cell);
1105 std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren() const
1107 std::size_t ret(MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren());
1111 std::vector<const BigMemoryObject *> MEDCouplingFieldDiscretizationPerCell::getDirectChildrenWithNull() const
1113 std::vector<const BigMemoryObject *> ret(MEDCouplingFieldDiscretization::getDirectChildrenWithNull());
1114 ret.push_back(_discr_per_cell);
1118 void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1120 if(!_discr_per_cell)
1121 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !");
1123 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh or DataArray !");
1124 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1125 if(nbOfTuples!=mesh->getNumberOfCells())
1126 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !");
1129 bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1133 reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined.";
1136 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1139 reason="Spatial discretization of this is ON_GAUSS, which is not the case of other.";
1142 if(_discr_per_cell==0)
1143 return otherC->_discr_per_cell==0;
1144 if(otherC->_discr_per_cell==0)
1146 bool ret=_discr_per_cell->isEqualIfNotWhy(*otherC->_discr_per_cell,reason);
1148 reason.insert(0,"Field discretization per cell DataArrayInt given the discid per cell :");
1152 bool MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1154 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1157 if(_discr_per_cell==0)
1158 return otherC->_discr_per_cell==0;
1159 if(otherC->_discr_per_cell==0)
1161 return _discr_per_cell->isEqualWithoutConsideringStr(*otherC->_discr_per_cell);
1165 * This method is typically the first step of renumbering. The impact on _discr_per_cell is necessary here.
1166 * virtualy by this method.
1168 void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, bool check)
1170 int nbCells=_discr_per_cell->getNumberOfTuples();
1171 const int *array=old2NewBg;
1173 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+nbCells);
1175 DataArrayInt *dpc=_discr_per_cell->renumber(array);
1176 _discr_per_cell->decrRef();
1177 _discr_per_cell=dpc;
1180 free(const_cast<int *>(array));
1183 void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh)
1186 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !");
1187 if(!_discr_per_cell)
1189 _discr_per_cell=DataArrayInt::New();
1190 int nbTuples=mesh->getNumberOfCells();
1191 _discr_per_cell->alloc(nbTuples,1);
1192 int *ptr=_discr_per_cell->getPointer();
1193 std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE);
1197 void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const
1199 if(!_discr_per_cell)
1200 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : no discretization defined !");
1201 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> test=_discr_per_cell->getIdsEqual(DFT_INVALID_LOCID_VALUE);
1202 if(test->getNumberOfTuples()!=0)
1203 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : presence of orphan cells !");
1207 * This method is useful when 'this' describes a field discretization with several gauss discretization on a \b same cell type.
1208 * For example same NORM_TRI3 cells having 6 gauss points and others with 12 gauss points.
1209 * This method returns 2 arrays with same size : the return value and 'locIds' output parameter.
1210 * For a given i into [0,locIds.size) ret[i] represents the set of cell ids of i_th set an locIds[i] represents the set of discretisation of the set.
1211 * The return vector contains a set of newly created instance to deal with.
1212 * The returned vector represents a \b partition of cells ids with a gauss discretization set.
1214 * If no descretization is set in 'this' and exception will be thrown.
1216 std::vector<DataArrayInt *> MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector<int>& locIds) const
1218 if(!_discr_per_cell)
1219 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType : no descretization set !");
1220 return _discr_per_cell->partitionByDifferentValues(locIds);
1223 const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const
1225 return _discr_per_cell;
1228 void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids)
1230 if(adids!=_discr_per_cell)
1233 _discr_per_cell->decrRef();
1234 _discr_per_cell=const_cast<DataArrayInt *>(adids);
1236 _discr_per_cell->incrRef();
1241 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss()
1245 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds, const int *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc)
1249 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, int beginCellIds, int endCellIds, int stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc)
1253 TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const
1258 bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1262 reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined.";
1265 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1268 reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other.";
1271 if(!MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(other,eps,reason))
1273 if(_loc.size()!=otherC->_loc.size())
1275 reason="Gauss spatial discretization : localization sizes differ";
1278 std::size_t sz=_loc.size();
1279 for(std::size_t i=0;i<sz;i++)
1280 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1282 std::ostringstream oss; oss << "Gauss spatial discretization : Localization #" << i << " differ from this to other.";
1289 bool MEDCouplingFieldDiscretizationGauss::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1291 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1294 if(!MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(other,eps))
1296 if(_loc.size()!=otherC->_loc.size())
1298 std::size_t sz=_loc.size();
1299 for(std::size_t i=0;i<sz;i++)
1300 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1306 * This method is simply called by MEDCouplingFieldDiscretization::deepCpy. It performs the deep copy of \a this.
1308 * \sa MEDCouplingFieldDiscretization::deepCpy.
1310 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() const
1312 return new MEDCouplingFieldDiscretizationGauss(*this);
1315 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const int *startCellIds, const int *endCellIds) const
1317 return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds);
1320 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const
1322 return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds);
1325 std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const
1327 std::ostringstream oss; oss << REPR << "." << std::endl;
1330 if(_discr_per_cell->isAllocated())
1332 oss << "Discretization per cell : ";
1333 std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator<int>(oss,", "));
1337 oss << "Presence of " << _loc.size() << " localizations." << std::endl;
1339 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++,i++)
1341 oss << "+++++ Localization #" << i << " +++++" << std::endl;
1342 oss << (*it).getStringRepr();
1343 oss << "++++++++++" << std::endl;
1348 std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySizeWithoutChildren() const
1350 std::size_t ret(MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren());
1351 ret+=_loc.capacity()*sizeof(MEDCouplingGaussLocalization);
1352 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++)
1353 ret+=(*it).getMemorySize();
1357 const char *MEDCouplingFieldDiscretizationGauss::getRepr() const
1363 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
1364 * The input code coherency is also checked regarding spatial discretization of \a this.
1365 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
1366 * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution).
1368 int MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
1370 if(!_discr_per_cell || !_discr_per_cell->isAllocated() || _discr_per_cell->getNumberOfComponents()!=1)
1371 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode");
1372 if(code.size()%3!=0)
1373 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
1374 int nbOfSplit=(int)idsPerType.size();
1375 int nbOfTypes=(int)code.size()/3;
1377 for(int i=0;i<nbOfTypes;i++)
1379 int nbOfEltInChunk=code[3*i+1];
1380 if(nbOfEltInChunk<0)
1381 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
1382 int pos=code[3*i+2];
1385 if(pos<0 || pos>=nbOfSplit)
1387 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
1388 throw INTERP_KERNEL::Exception(oss.str().c_str());
1390 const DataArrayInt *ids(idsPerType[pos]);
1391 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
1393 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
1394 throw INTERP_KERNEL::Exception(oss.str().c_str());
1397 ret+=nbOfEltInChunk;
1399 if(ret!=_discr_per_cell->getNumberOfTuples())
1401 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " cells whereas discretization percell array lgth is " << _discr_per_cell->getNumberOfTuples() << " !";
1402 throw INTERP_KERNEL::Exception(oss.str().c_str());
1404 return getNumberOfTuples(0);//0 is not an error ! It is to be sure that input mesh is not used
1407 int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const
1410 if (_discr_per_cell == 0)
1411 throw INTERP_KERNEL::Exception("Discretization is not initialized!");
1412 const int *dcPtr=_discr_per_cell->getConstPointer();
1413 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1414 int maxSz=(int)_loc.size();
1415 for(const int *w=dcPtr;w!=dcPtr+nbOfTuples;w++)
1417 if(*w>=0 && *w<maxSz)
1418 ret+=_loc[*w].getNumberOfGaussPt();
1421 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuples : At cell #" << std::distance(dcPtr,w) << " localization id is " << *w << " should be in [0," << maxSz << ") !";
1422 throw INTERP_KERNEL::Exception(oss.str().c_str());
1428 int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
1431 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces : NULL input mesh !");
1432 return mesh->getNumberOfCells();
1436 * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField
1437 * and a call to DataArrayDouble::computeOffsets2 on the returned array.
1439 DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const
1442 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !");
1443 int nbOfTuples=mesh->getNumberOfCells();
1444 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1445 ret->alloc(nbOfTuples+1,1);
1446 int *retPtr=ret->getPointer();
1447 const int *start=_discr_per_cell->getConstPointer();
1448 if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples)
1449 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !");
1450 int maxPossible=(int)_loc.size();
1452 for(int i=0;i<nbOfTuples;i++,start++)
1454 if(*start>=0 && *start<maxPossible)
1455 retPtr[i+1]=retPtr[i]+_loc[*start].getNumberOfGaussPt();
1458 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getOffsetArr : At position #" << i << " the locid = " << *start << " whereas it should be in [0," << maxPossible << ") !";
1459 throw INTERP_KERNEL::Exception(oss.str().c_str());
1465 void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
1466 const int *old2NewBg, bool check)
1469 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !");
1470 const int *array=old2NewBg;
1472 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
1473 int nbOfCells=_discr_per_cell->getNumberOfTuples();
1474 int nbOfTuples=getNumberOfTuples(0);
1475 const int *dcPtr=_discr_per_cell->getConstPointer();
1476 int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
1477 int *array3=new int[nbOfCells];//store for each cell in present dcp array (already renumbered) the offset needed by each cell in new numbering.
1479 for(int i=1;i<nbOfCells;i++)
1480 array3[i]=array3[i-1]+_loc[dcPtr[i-1]].getNumberOfGaussPt();
1482 for(int i=0;i<nbOfCells;i++)
1484 int nbOfGaussPt=_loc[dcPtr[array[i]]].getNumberOfGaussPt();
1485 for(int k=0;k<nbOfGaussPt;k++,j++)
1486 array2[j]=array3[array[i]]+k;
1489 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
1491 (*it)->renumberInPlace(array2);
1494 free(const_cast<int*>(array));
1497 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
1500 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !");
1501 checkNoOrphanCells();
1502 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
1503 int nbOfTuples=getNumberOfTuples(mesh);
1504 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1505 int spaceDim=mesh->getSpaceDimension();
1506 ret->alloc(nbOfTuples,spaceDim);
1507 std::vector< int > locIds;
1508 std::vector<DataArrayInt *> parts=splitIntoSingleGaussDicrPerCellType(locIds);
1509 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > parts2(parts.size());
1510 std::copy(parts.begin(),parts.end(),parts2.begin());
1511 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> offsets=buildNbOfGaussPointPerCellField();
1512 offsets->computeOffsets();
1513 const int *ptrOffsets=offsets->getConstPointer();
1514 const double *coords=umesh->getCoords()->getConstPointer();
1515 const int *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
1516 const int *conn=umesh->getNodalConnectivity()->getConstPointer();
1517 double *valsToFill=ret->getPointer();
1518 for(std::size_t i=0;i<parts2.size();i++)
1520 INTERP_KERNEL::GaussCoords calculator;
1522 const MEDCouplingGaussLocalization& cli=_loc[locIds[i]];//curLocInfo
1523 INTERP_KERNEL::NormalizedCellType typ=cli.getType();
1524 const std::vector<double>& wg=cli.getWeights();
1525 calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(),
1526 &cli.getGaussCoords()[0],(int)wg.size(),&cli.getRefCoords()[0],
1527 INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes());
1529 int nbt=parts2[i]->getNumberOfTuples();
1530 for(const int *w=parts2[i]->getConstPointer();w!=parts2[i]->getConstPointer()+nbt;w++)
1531 calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w]));
1533 ret->copyStringInfoFrom(*umesh->getCoords());
1537 void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
1538 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
1541 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !");
1542 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
1543 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
1545 tmp=tmp->buildUnique();
1546 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();
1547 nbOfNodesPerCell->computeOffsets2();
1548 nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
1554 void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const
1558 void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1562 val=_discr_per_cell->getNumberOfTuples();
1563 tinyInfo.push_back(val);
1564 tinyInfo.push_back((int)_loc.size());
1566 tinyInfo.push_back(-1);
1568 tinyInfo.push_back(_loc[0].getDimension());
1569 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1570 (*iter).pushTinySerializationIntInfo(tinyInfo);
1573 void MEDCouplingFieldDiscretizationGauss::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1575 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1576 (*iter).pushTinySerializationDblInfo(tinyInfo);
1579 void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayInt *& arr) const
1583 arr=_discr_per_cell;
1586 void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *& arr)
1588 int val=tinyInfo[0];
1591 _discr_per_cell=DataArrayInt::New();
1592 _discr_per_cell->alloc(val,1);
1596 arr=_discr_per_cell;
1597 int nbOfLoc=tinyInfo[1];
1599 int dim=tinyInfo[2];
1602 delta=((int)tinyInfo.size()-3)/nbOfLoc;
1603 for(int i=0;i<nbOfLoc;i++)
1605 std::vector<int> tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta);
1606 MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp);
1607 _loc.push_back(elt);
1611 void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vector<double>& tinyInfo)
1613 double *tmp=new double[tinyInfo.size()];
1614 std::copy(tinyInfo.begin(),tinyInfo.end(),tmp);
1615 const double *work=tmp;
1616 for(std::vector<MEDCouplingGaussLocalization>::iterator iter=_loc.begin();iter!=_loc.end();iter++)
1617 work=(*iter).fillWithValues(work);
1621 double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
1623 int offset=getOffsetOfCell(cellId);
1624 return da->getIJ(offset+nodeIdInCell,compoId);
1627 void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1630 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh or DataArray !");
1631 MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da);
1632 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1633 (*iter).checkCoherency();
1634 int nbOfDesc=(int)_loc.size();
1635 int nbOfCells=mesh->getNumberOfCells();
1636 const int *dc=_discr_per_cell->getConstPointer();
1637 for(int i=0;i<nbOfCells;i++)
1641 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happend !";
1642 throw INTERP_KERNEL::Exception(oss.str().c_str());
1646 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has no gauss location !";
1647 throw INTERP_KERNEL::Exception(oss.str().c_str());
1649 if(mesh->getTypeOfCell(i)!=_loc[dc[i]].getType())
1651 std::ostringstream oss; oss << "Types of mesh and gauss location mismatch for cell # " << i;
1652 throw INTERP_KERNEL::Exception(oss.str().c_str());
1655 int nbOfTuples=getNumberOfTuples(mesh);
1656 if(nbOfTuples!=da->getNumberOfTuples())
1658 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !";
1659 throw INTERP_KERNEL::Exception(oss.str().c_str());
1663 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
1666 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : mesh instance specified is NULL !");
1667 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
1668 const double *volPtr=vol->getArray()->begin();
1669 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_PT);
1671 ret->setDiscretization(const_cast<MEDCouplingFieldDiscretizationGauss *>(this));
1672 if(!_discr_per_cell)
1673 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array not defined ! spatial localization is incorrect !");
1674 _discr_per_cell->checkAllocated();
1675 if(_discr_per_cell->getNumberOfComponents()!=1)
1676 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but with nb of components different from 1 !");
1677 if(_discr_per_cell->getNumberOfTuples()!=vol->getNumberOfTuples())
1678 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 !");
1679 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> offset=getOffsetArr(mesh);
1680 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(getNumberOfTuples(mesh),1);
1682 double *arrPtr=arr->getPointer();
1683 const int *offsetPtr=offset->getConstPointer();
1684 int maxGaussLoc=(int)_loc.size();
1685 std::vector<int> locIds;
1686 std::vector<DataArrayInt *> ids=splitIntoSingleGaussDicrPerCellType(locIds);
1687 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > ids2(ids.size()); std::copy(ids.begin(),ids.end(),ids2.begin());
1688 for(std::size_t i=0;i<locIds.size();i++)
1690 const DataArrayInt *curIds=ids[i];
1691 int locId=locIds[i];
1692 if(locId>=0 && locId<maxGaussLoc)
1694 const MEDCouplingGaussLocalization& loc=_loc[locId];
1695 int nbOfGaussPt=loc.getNumberOfGaussPt();
1696 INTERP_KERNEL::AutoPtr<double> weights=new double[nbOfGaussPt];
1697 double sum=std::accumulate(loc.getWeights().begin(),loc.getWeights().end(),0.);
1698 std::transform(loc.getWeights().begin(),loc.getWeights().end(),(double *)weights,std::bind2nd(std::multiplies<double>(),1./sum));
1699 for(const int *cellId=curIds->begin();cellId!=curIds->end();cellId++)
1700 for(int j=0;j<nbOfGaussPt;j++)
1701 arrPtr[offsetPtr[*cellId]+j]=weights[j]*volPtr[*cellId];
1705 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getMeasureField : Presence of localization id " << locId << " in cell #" << curIds->getIJ(0,0) << " ! Must be in [0," << maxGaussLoc << ") !";
1706 throw INTERP_KERNEL::Exception(oss.str().c_str());
1709 ret->synchronizeTimeWithSupport();
1713 void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
1715 throw INTERP_KERNEL::Exception("Not implemented yet !");
1718 void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
1720 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !");
1723 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
1725 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented yet for gauss points !");
1728 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
1731 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !");
1732 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
1733 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPart(start,end);
1739 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
1741 * \param [out] beginOut Valid only if \a di is NULL
1742 * \param [out] endOut Valid only if \a di is NULL
1743 * \param [out] stepOut Valid only if \a di is NULL
1744 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
1746 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
1748 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
1750 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
1751 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
1753 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : NULL input mesh !");
1754 if(!_discr_per_cell)
1755 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : no discretization array set !");
1756 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
1757 const char msg[]="MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : cell #";
1758 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1759 const int *w=_discr_per_cell->begin();
1760 int nbMaxOfLocId=(int)_loc.size();
1761 for(int i=0;i<nbOfTuples;i++,w++)
1763 if(*w!=DFT_INVALID_LOCID_VALUE)
1765 if(*w>=0 && *w<nbMaxOfLocId)
1767 int delta=_loc[*w].getNumberOfGaussPt();
1775 { std::ostringstream oss; oss << msg << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1778 { std::ostringstream oss; oss << msg << i << " is detected as orphan !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1780 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
1785 * This method returns a tuple ids selection from cell ids selection [start;end).
1786 * This method is called by MEDCouplingFieldDiscretizationGauss::buildSubMeshData to return parameter \b di.
1788 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
1791 DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
1794 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !");
1795 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer
1796 int nbOfCells=mesh->getNumberOfCells();
1797 if(_discr_per_cell->getNumberOfTuples()!=nbOfCells)
1798 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : mismatch of nb of tuples of cell ids array and number of cells !");
1799 nbOfNodesPerCell->computeOffsets2();
1800 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1);
1801 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
1805 * No implementation needed !
1807 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
1811 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
1813 throw INTERP_KERNEL::Exception("Not implemented yet !");
1816 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
1818 throw INTERP_KERNEL::Exception("Number of cells has changed and becomes higher with some cells that have been split ! Unable to conserve the Gauss field !");
1821 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
1822 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1825 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !");
1826 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1827 if((int)cm.getDimension()!=mesh->getMeshDimension())
1829 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension();
1830 oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !";
1831 throw INTERP_KERNEL::Exception(oss.str().c_str());
1833 buildDiscrPerCellIfNecessary(mesh);
1834 int id=(int)_loc.size();
1835 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1836 _loc.push_back(elt);
1837 int *ptr=_discr_per_cell->getPointer();
1838 int nbCells=mesh->getNumberOfCells();
1839 for(int i=0;i<nbCells;i++)
1840 if(mesh->getTypeOfCell(i)==type)
1842 zipGaussLocalizations();
1845 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector<double>& refCoo,
1846 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1849 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !");
1850 buildDiscrPerCellIfNecessary(mesh);
1851 if(std::distance(begin,end)<1)
1852 throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !");
1853 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin);
1854 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1855 int id=(int)_loc.size();
1856 int *ptr=_discr_per_cell->getPointer();
1857 for(const int *w=begin+1;w!=end;w++)
1859 if(mesh->getTypeOfCell(*w)!=type)
1861 std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !";
1862 throw INTERP_KERNEL::Exception(oss.str().c_str());
1866 for(const int *w2=begin;w2!=end;w2++)
1869 _loc.push_back(elt);
1870 zipGaussLocalizations();
1873 void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations()
1877 _discr_per_cell->decrRef();
1883 void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc)
1886 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !");
1887 int sz=(int)_loc.size();
1888 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
1890 _loc.resize(locId+1,gLoc);
1894 void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz)
1897 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !");
1898 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
1899 _loc.resize(newSz,gLoc);
1902 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId)
1904 checkLocalizationId(locId);
1908 int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const
1910 return (int)_loc.size();
1913 int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const
1915 if(!_discr_per_cell)
1916 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
1917 int locId=_discr_per_cell->begin()[cellId];
1919 throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !");
1923 int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
1925 std::set<int> ret=getGaussLocalizationIdsOfOneType(type);
1927 throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
1929 throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
1930 return *ret.begin();
1933 std::set<int> MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
1935 if(!_discr_per_cell)
1936 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
1939 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++)
1940 if((*iter).getType()==type)
1945 void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
1947 if(locId<0 || locId>=(int)_loc.size())
1948 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
1949 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1950 const int *ptr=_discr_per_cell->getConstPointer();
1951 for(int i=0;i<nbOfTuples;i++)
1953 cellIds.push_back(i);
1956 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) const
1958 checkLocalizationId(locId);
1962 void MEDCouplingFieldDiscretizationGauss::checkLocalizationId(int locId) const
1964 if(locId<0 || locId>=(int)_loc.size())
1965 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
1968 int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const
1971 const int *start=_discr_per_cell->getConstPointer();
1972 for(const int *w=start;w!=start+cellId;w++)
1973 ret+=_loc[*w].getNumberOfGaussPt();
1978 * This method do the assumption that there is no orphan cell. If there is an exception is thrown.
1979 * This method makes the assumption too that '_discr_per_cell' is defined. If not an exception is thrown.
1980 * This method returns a newly created array with number of tuples equals to '_discr_per_cell->getNumberOfTuples' and number of components equal to 1.
1981 * The i_th tuple in returned array is the number of gauss point if the corresponding cell.
1983 DataArrayInt *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField() const
1985 if(!_discr_per_cell)
1986 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : no discretization array set !");
1987 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1988 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1989 const int *w=_discr_per_cell->begin();
1990 ret->alloc(nbOfTuples,1);
1991 int *valsToFill=ret->getPointer();
1992 int nbMaxOfLocId=(int)_loc.size();
1993 for(int i=0;i<nbOfTuples;i++,w++)
1994 if(*w!=DFT_INVALID_LOCID_VALUE)
1996 if(*w>=0 && *w<nbMaxOfLocId)
1997 valsToFill[i]=_loc[*w].getNumberOfGaussPt();
2000 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !";
2001 throw INTERP_KERNEL::Exception(oss.str().c_str());
2006 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " is detected as orphan !";
2007 throw INTERP_KERNEL::Exception(oss.str().c_str());
2012 void MEDCouplingFieldDiscretizationGauss::reprQuickOverview(std::ostream& stream) const
2014 stream << "Gauss points spatial discretization.";
2018 * This method makes the assumption that _discr_per_cell is set.
2019 * This method reduces as much as possible number size of _loc.
2020 * This method is useful when several set on same cells has been done and that some Gauss Localization are no more used.
2022 void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations()
2024 const int *start=_discr_per_cell->begin();
2025 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
2026 INTERP_KERNEL::AutoPtr<int> tmp=new int[_loc.size()];
2027 std::fill((int *)tmp,(int *)tmp+_loc.size(),-2);
2028 for(const int *w=start;w!=start+nbOfTuples;w++)
2032 for(int i=0;i<(int)_loc.size();i++)
2035 if(fid==(int)_loc.size())
2038 int *start2=_discr_per_cell->getPointer();
2039 for(int *w2=start2;w2!=start2+nbOfTuples;w2++)
2042 std::vector<MEDCouplingGaussLocalization> tmpLoc;
2043 for(int i=0;i<(int)_loc.size();i++)
2045 tmpLoc.push_back(_loc[i]);
2049 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE()
2053 TypeOfField MEDCouplingFieldDiscretizationGaussNE::getEnum() const
2059 * This method is simply called by MEDCouplingFieldDiscretization::deepCpy. It performs the deep copy of \a this.
2061 * \sa MEDCouplingFieldDiscretization::deepCpy.
2063 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() const
2065 return new MEDCouplingFieldDiscretizationGaussNE(*this);
2068 std::string MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const
2070 return std::string(REPR);
2073 const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const
2078 bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2082 reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined.";
2085 const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGaussNE *>(other);
2088 reason="Spatial discrtization of this is ON_GAUSS_NE, which is not the case of other.";
2093 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
2094 * The input code coherency is also checked regarding spatial discretization of \a this.
2095 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
2096 * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution).
2098 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
2100 if(code.size()%3!=0)
2101 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
2102 int nbOfSplit=(int)idsPerType.size();
2103 int nbOfTypes=(int)code.size()/3;
2105 for(int i=0;i<nbOfTypes;i++)
2107 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)code[3*i]));
2110 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : At pos #" << i << " the geometric type " << cm.getRepr() << " is dynamic ! There are not managed by GAUSS_NE field discretization !";
2111 throw INTERP_KERNEL::Exception(oss.str().c_str());
2113 int nbOfEltInChunk=code[3*i+1];
2114 if(nbOfEltInChunk<0)
2115 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
2116 int pos=code[3*i+2];
2119 if(pos<0 || pos>=nbOfSplit)
2121 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2124 const DataArrayInt *ids(idsPerType[pos]);
2125 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
2127 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
2128 throw INTERP_KERNEL::Exception(oss.str().c_str());
2131 ret+=nbOfEltInChunk*(int)cm.getNumberOfNodes();
2136 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const
2139 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !");
2141 int nbOfCells=mesh->getNumberOfCells();
2142 for(int i=0;i<nbOfCells;i++)
2144 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2145 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2147 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2148 ret+=cm.getNumberOfNodes();
2153 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
2156 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces : NULL input mesh !");
2157 return mesh->getNumberOfCells();
2160 DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const
2163 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !");
2164 int nbOfTuples=mesh->getNumberOfCells();
2165 DataArrayInt *ret=DataArrayInt::New();
2166 ret->alloc(nbOfTuples+1,1);
2167 int *retPtr=ret->getPointer();
2169 for(int i=0;i<nbOfTuples;i++)
2171 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2172 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2174 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2175 retPtr[i+1]=retPtr[i]+cm.getNumberOfNodes();
2180 void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
2181 const int *old2NewBg, bool check)
2184 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !");
2185 const int *array=old2NewBg;
2187 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
2188 int nbOfCells=mesh->getNumberOfCells();
2189 int nbOfTuples=getNumberOfTuples(mesh);
2190 int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
2191 int *array3=new int[nbOfCells];//store for each cell in after renumbering the offset needed by each cell in new numbering.
2193 for(int i=1;i<nbOfCells;i++)
2195 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell((int)std::distance(array,std::find(array,array+nbOfCells,i-1)));
2196 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2197 array3[i]=array3[i-1]+cm.getNumberOfNodes();
2200 for(int i=0;i<nbOfCells;i++)
2202 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2203 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2204 for(int k=0;k<(int)cm.getNumberOfNodes();k++,j++)
2205 array2[j]=array3[array[i]]+k;
2208 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
2210 (*it)->renumberInPlace(array2);
2213 free(const_cast<int *>(array));
2216 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
2219 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !");
2220 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2221 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
2222 int nbOfTuples=getNumberOfTuples(umesh);
2223 int spaceDim=mesh->getSpaceDimension();
2224 ret->alloc(nbOfTuples,spaceDim);
2225 const double *coords=umesh->getCoords()->begin();
2226 const int *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
2227 const int *conn=umesh->getNodalConnectivity()->getConstPointer();
2228 int nbCells=umesh->getNumberOfCells();
2229 double *retPtr=ret->getPointer();
2230 for(int i=0;i<nbCells;i++,connI++)
2231 for(const int *w=conn+connI[0]+1;w!=conn+connI[1];w++)
2233 retPtr=std::copy(coords+(*w)*spaceDim,coords+((*w)+1)*spaceDim,retPtr);
2238 * Reimplemented from MEDCouplingFieldDiscretization::integral for performance reason. The default implementation is valid too for GAUSS_NE spatial discretization.
2240 void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const
2243 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !");
2244 int nbOfCompo=arr->getNumberOfComponents();
2245 std::fill(res,res+nbOfCompo,0.);
2247 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isWAbs);
2248 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2249 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2250 nbOfNodesPerCell->computeOffsets2();
2251 const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin();
2252 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2254 std::size_t wArrSz=-1;
2255 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2256 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2257 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2258 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2259 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=mesh->giveCellsWithType(*it);
2260 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2261 const int *ptIds2=ids2->begin(),*ptIds=ids->begin();
2262 int nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2263 for(int i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++,ptIds2+=wArrSz)
2265 for(int k=0;k<nbOfCompo;k++)
2268 for(std::size_t j=0;j<wArrSz;j++)
2269 tmp+=arrPtr[nbOfCompo*ptIds2[j]+k]*wArr2[j];
2270 res[k]+=tmp*volPtr[*ptIds];
2276 const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2280 case INTERP_KERNEL::NORM_POINT1:
2281 lgth=(int)sizeof(FGP_POINT1)/sizeof(double);
2283 case INTERP_KERNEL::NORM_SEG2:
2284 lgth=(int)sizeof(FGP_SEG2)/sizeof(double);
2286 case INTERP_KERNEL::NORM_SEG3:
2287 lgth=(int)sizeof(FGP_SEG3)/sizeof(double);
2289 case INTERP_KERNEL::NORM_SEG4:
2290 lgth=(int)sizeof(FGP_SEG4)/sizeof(double);
2292 case INTERP_KERNEL::NORM_TRI3:
2293 lgth=(int)sizeof(FGP_TRI3)/sizeof(double);
2295 case INTERP_KERNEL::NORM_TRI6:
2296 lgth=(int)sizeof(FGP_TRI6)/sizeof(double);
2298 case INTERP_KERNEL::NORM_TRI7:
2299 lgth=(int)sizeof(FGP_TRI7)/sizeof(double);
2301 case INTERP_KERNEL::NORM_QUAD4:
2302 lgth=(int)sizeof(FGP_QUAD4)/sizeof(double);
2304 case INTERP_KERNEL::NORM_QUAD8:
2305 lgth=(int)sizeof(FGP_QUAD8)/sizeof(double);
2307 case INTERP_KERNEL::NORM_QUAD9:
2308 lgth=(int)sizeof(FGP_QUAD9)/sizeof(double);
2310 case INTERP_KERNEL::NORM_TETRA4:
2311 lgth=(int)sizeof(FGP_TETRA4)/sizeof(double);
2313 case INTERP_KERNEL::NORM_TETRA10:
2314 lgth=(int)sizeof(FGP_TETRA10)/sizeof(double);
2316 case INTERP_KERNEL::NORM_PENTA6:
2317 lgth=(int)sizeof(FGP_PENTA6)/sizeof(double);
2319 case INTERP_KERNEL::NORM_PENTA15:
2320 lgth=(int)sizeof(FGP_PENTA15)/sizeof(double);
2322 case INTERP_KERNEL::NORM_HEXA8:
2323 lgth=(int)sizeof(FGP_HEXA8)/sizeof(double);
2325 case INTERP_KERNEL::NORM_HEXA20:
2326 lgth=(int)sizeof(FGP_HEXA20)/sizeof(double);
2328 case INTERP_KERNEL::NORM_HEXA27:
2329 lgth=(int)sizeof(FGP_HEXA27)/sizeof(double);
2331 case INTERP_KERNEL::NORM_PYRA5:
2332 lgth=(int)sizeof(FGP_PYRA5)/sizeof(double);
2334 case INTERP_KERNEL::NORM_PYRA13:
2335 lgth=(int)sizeof(FGP_PYRA13)/sizeof(double);
2338 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType : only SEG[2,3,4], TRI[3,6,7], QUAD[4,9], TETRA[4,10], PENTA[6,15], HEXA[8,20,27], PYRA[5,13] supported !");
2342 const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2346 case INTERP_KERNEL::NORM_POINT1:
2349 case INTERP_KERNEL::NORM_SEG2:
2350 lgth=(int)sizeof(REF_SEG2)/sizeof(double);
2352 case INTERP_KERNEL::NORM_SEG3:
2353 lgth=(int)sizeof(REF_SEG3)/sizeof(double);
2355 case INTERP_KERNEL::NORM_SEG4:
2356 lgth=(int)sizeof(REF_SEG4)/sizeof(double);
2358 case INTERP_KERNEL::NORM_TRI3:
2359 lgth=(int)sizeof(REF_TRI3)/sizeof(double);
2361 case INTERP_KERNEL::NORM_TRI6:
2362 lgth=(int)sizeof(REF_TRI6)/sizeof(double);
2364 case INTERP_KERNEL::NORM_TRI7:
2365 lgth=(int)sizeof(REF_TRI7)/sizeof(double);
2367 case INTERP_KERNEL::NORM_QUAD4:
2368 lgth=(int)sizeof(REF_QUAD4)/sizeof(double);
2370 case INTERP_KERNEL::NORM_QUAD8:
2371 lgth=(int)sizeof(REF_QUAD8)/sizeof(double);
2373 case INTERP_KERNEL::NORM_QUAD9:
2374 lgth=(int)sizeof(REF_QUAD9)/sizeof(double);
2376 case INTERP_KERNEL::NORM_TETRA4:
2377 lgth=(int)sizeof(REF_TETRA4)/sizeof(double);
2379 case INTERP_KERNEL::NORM_TETRA10:
2380 lgth=(int)sizeof(REF_TETRA10)/sizeof(double);
2382 case INTERP_KERNEL::NORM_PENTA6:
2383 lgth=(int)sizeof(REF_PENTA6)/sizeof(double);
2385 case INTERP_KERNEL::NORM_PENTA15:
2386 lgth=(int)sizeof(REF_PENTA15)/sizeof(double);
2388 case INTERP_KERNEL::NORM_HEXA8:
2389 lgth=(int)sizeof(REF_HEXA8)/sizeof(double);
2391 case INTERP_KERNEL::NORM_HEXA20:
2392 lgth=(int)sizeof(REF_HEXA20)/sizeof(double);
2394 case INTERP_KERNEL::NORM_HEXA27:
2395 lgth=(int)sizeof(REF_HEXA27)/sizeof(double);
2397 case INTERP_KERNEL::NORM_PYRA5:
2398 lgth=(int)sizeof(REF_PYRA5)/sizeof(double);
2400 case INTERP_KERNEL::NORM_PYRA13:
2401 lgth=(int)sizeof(REF_PYRA13)/sizeof(double);
2404 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType : only SEG[2,3,4], TRI[3,6,7], QUAD[4,8,9], TETRA[4,10], PENTA[6,15], HEXA[8,20,27], PYRA[5,13] supported !");
2408 const double *MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2412 case INTERP_KERNEL::NORM_POINT1:
2417 case INTERP_KERNEL::NORM_SEG2:
2419 lgth=(int)sizeof(LOC_SEG2)/sizeof(double);
2422 case INTERP_KERNEL::NORM_SEG3:
2424 lgth=(int)sizeof(LOC_SEG3)/sizeof(double);
2427 case INTERP_KERNEL::NORM_SEG4:
2429 lgth=(int)sizeof(LOC_SEG4)/sizeof(double);
2432 case INTERP_KERNEL::NORM_TRI3:
2434 lgth=(int)sizeof(LOC_TRI3)/sizeof(double);
2437 case INTERP_KERNEL::NORM_TRI6:
2439 lgth=(int)sizeof(LOC_TRI6)/sizeof(double);
2442 case INTERP_KERNEL::NORM_TRI7:
2444 lgth=(int)sizeof(LOC_TRI7)/sizeof(double);
2447 case INTERP_KERNEL::NORM_QUAD4:
2449 lgth=(int)sizeof(LOC_QUAD4)/sizeof(double);
2452 case INTERP_KERNEL::NORM_QUAD8:
2454 lgth=(int)sizeof(LOC_QUAD8)/sizeof(double);
2457 case INTERP_KERNEL::NORM_QUAD9:
2459 lgth=(int)sizeof(LOC_QUAD9)/sizeof(double);
2462 case INTERP_KERNEL::NORM_TETRA4:
2464 lgth=(int)sizeof(LOC_TETRA4)/sizeof(double);
2467 case INTERP_KERNEL::NORM_TETRA10:
2469 lgth=(int)sizeof(LOC_TETRA10)/sizeof(double);
2472 case INTERP_KERNEL::NORM_PENTA6:
2474 lgth=(int)sizeof(LOC_PENTA6)/sizeof(double);
2477 case INTERP_KERNEL::NORM_PENTA15:
2479 lgth=(int)sizeof(LOC_PENTA15)/sizeof(double);
2482 case INTERP_KERNEL::NORM_HEXA8:
2484 lgth=(int)sizeof(LOC_HEXA8)/sizeof(double);
2487 case INTERP_KERNEL::NORM_HEXA20:
2489 lgth=(int)sizeof(LOC_HEXA20)/sizeof(double);
2492 case INTERP_KERNEL::NORM_HEXA27:
2494 lgth=(int)sizeof(LOC_HEXA27)/sizeof(double);
2497 case INTERP_KERNEL::NORM_PYRA5:
2499 lgth=(int)sizeof(LOC_PYRA5)/sizeof(double);
2502 case INTERP_KERNEL::NORM_PYRA13:
2504 lgth=(int)sizeof(LOC_PYRA13)/sizeof(double);
2508 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType : only SEG[2,3,4], TRI[3,6,7], QUAD[4,8,9], TETRA[4,10], PENTA[6,15], HEXA[8,20,27], PYRA[5,13] supported !");
2512 void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
2513 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
2516 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds : NULL input mesh !");
2517 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
2518 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
2520 tmp=tmp->buildUnique();
2521 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2522 nbOfNodesPerCell->computeOffsets2();
2523 nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
2526 void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const
2530 double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
2533 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !");
2535 for(int i=0;i<cellId;i++)
2537 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2538 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2539 offset+=cm.getNumberOfNodes();
2541 return da->getIJ(offset+nodeIdInCell,compoId);
2544 void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
2546 int nbOfTuples=getNumberOfTuples(mesh);
2547 if(nbOfTuples!=da->getNumberOfTuples())
2549 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !";
2550 throw INTERP_KERNEL::Exception(oss.str().c_str());
2554 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2557 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getMeasureField : mesh instance specified is NULL !");
2558 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
2559 const double *volPtr=vol->getArray()->begin();
2560 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_NE);
2563 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2564 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2565 int nbTuples=nbOfNodesPerCell->accumulate(0);
2566 nbOfNodesPerCell->computeOffsets2();
2567 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(nbTuples,1);
2569 double *arrPtr=arr->getPointer();
2570 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2572 std::size_t wArrSz=-1;
2573 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2574 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2575 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2576 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2577 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=mesh->giveCellsWithType(*it);
2578 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2579 const int *ptIds2=ids2->begin(),*ptIds=ids->begin();
2580 int nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2581 for(int i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++)
2582 for(std::size_t j=0;j<wArrSz;j++,ptIds2++)
2583 arrPtr[*ptIds2]=wArr2[j]*volPtr[*ptIds];
2585 ret->synchronizeTimeWithSupport();
2589 void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2591 throw INTERP_KERNEL::Exception("Not implemented yet !");
2594 void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
2596 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !");
2599 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
2601 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented for Gauss NE !");
2604 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
2607 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !");
2608 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
2609 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPart(start,end);
2615 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
2617 * \param [out] beginOut Valid only if \a di is NULL
2618 * \param [out] endOut Valid only if \a di is NULL
2619 * \param [out] stepOut Valid only if \a di is NULL
2620 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
2622 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
2624 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
2626 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
2627 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
2629 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : NULL input mesh !");
2630 int nbOfCells=mesh->getNumberOfCells();
2631 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
2632 const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #";
2633 for(int i=0;i<nbOfCells;i++)
2635 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2636 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2638 { std::ostringstream oss; oss << msg << i << " presence of dynamic cell (polygons and polyedrons) ! Not implemented !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
2639 int delta=cm.getNumberOfNodes();
2646 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
2652 * This method returns a tuple ids selection from cell ids selection [start;end).
2653 * This method is called by MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData to return parameter \b di.
2655 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
2658 DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
2661 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds : null mesh !");
2662 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2663 nbOfNodesPerCell->computeOffsets2();
2664 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1);
2665 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
2669 * No implementation needed !
2671 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
2675 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
2677 throw INTERP_KERNEL::Exception("Not implemented yet !");
2680 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
2682 throw INTERP_KERNEL::Exception("Not implemented yet !");
2685 void MEDCouplingFieldDiscretizationGaussNE::reprQuickOverview(std::ostream& stream) const
2687 stream << "Gauss points on nodes per element spatial discretization.";
2690 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other)
2694 TypeOfField MEDCouplingFieldDiscretizationKriging::getEnum() const
2699 const char *MEDCouplingFieldDiscretizationKriging::getRepr() const
2705 * This method is simply called by MEDCouplingFieldDiscretization::deepCpy. It performs the deep copy of \a this.
2707 * \sa MEDCouplingFieldDiscretization::deepCpy.
2709 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationKriging::clone() const
2711 return new MEDCouplingFieldDiscretizationKriging;
2714 std::string MEDCouplingFieldDiscretizationKriging::getStringRepr() const
2716 return std::string(REPR);
2719 void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureOfField nat) const
2721 if(nat!=ConservativeVolumic)
2722 throw INTERP_KERNEL::Exception("Invalid nature for Kriging field : expected ConservativeVolumic !");
2725 bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2729 reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined.";
2732 const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationKriging *>(other);
2735 reason="Spatial discrtization of this is ON_NODES_KR, which is not the case of other.";
2739 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationKriging::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2742 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getMeasureField : mesh instance specified is NULL !");
2743 throw INTERP_KERNEL::Exception("getMeasureField on FieldDiscretizationKriging : not implemented yet !");
2746 void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2748 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> res2=MEDCouplingFieldDiscretizationKriging::getValueOnMulti(arr,mesh,loc,1);
2749 std::copy(res2->begin(),res2->end(),res);
2752 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const
2754 if(!arr || !arr->isAllocated())
2755 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array is null or not allocated !");
2756 int nbOfRows(getNumberOfMeshPlaces(mesh));
2757 if(arr->getNumberOfTuples()!=nbOfRows)
2759 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array does not have correct number of tuples ! Excepted " << nbOfRows << " having " << arr->getNumberOfTuples() << " !";
2760 throw INTERP_KERNEL::Exception(oss.str().c_str());
2762 int nbCols(-1),nbCompo(arr->getNumberOfComponents());
2763 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> m(computeEvaluationMatrixOnGivenPts(mesh,loc,nbOfTargetPoints,nbCols));
2764 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
2765 ret->alloc(nbOfTargetPoints,nbCompo);
2766 INTERP_KERNEL::matrixProduct(m->begin(),nbOfTargetPoints,nbCols,arr->begin(),nbOfRows,nbCompo,ret->getPointer());
2770 void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const
2772 stream << "Kriging spatial discretization.";
2776 * Returns the matrix of size nbRows = \a nbOfTargetPoints and \a nbCols = \a nbCols. This matrix is useful if
2778 * \return the new result matrix to be deallocated by the caller.
2780 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts(const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints, int& nbCols) const
2782 int isDrift(-1),nbRows(-1);
2783 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2785 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=getLocalizationOfDiscValues(mesh);
2786 int nbOfPts(coords->getNumberOfTuples()),dimension(coords->getNumberOfComponents());
2787 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> locArr=DataArrayDouble::New();
2788 locArr->useArray(loc,false,CPP_DEALLOC,nbOfTargetPoints,dimension);
2791 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr);
2792 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfTargetPoints*nbOfPts,matrix2->getPointer());
2794 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrix3=DataArrayDouble::New();
2795 matrix3->alloc(nbOfTargetPoints*nbRows,1);
2796 double *work=matrix3->getPointer();
2797 const double *workCst(matrix2->begin()),*workCst2(loc);
2798 for(int i=0;i<nbOfTargetPoints;i++,workCst+=nbOfPts,workCst2+=isDrift-1)
2800 for(int j=0;j<nbOfPts;j++)
2801 work[i*nbRows+j]=workCst[j];
2802 work[i*nbRows+nbOfPts]=1.0;
2803 for(int j=0;j<isDrift-1;j++)
2804 work[i*nbRows+(nbOfPts+1+j)]=workCst2[j];
2806 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
2807 ret->alloc(nbOfTargetPoints,nbRows);
2808 INTERP_KERNEL::matrixProduct(matrix3->begin(),nbOfTargetPoints,nbRows,matrixInv->begin(),nbRows,nbRows,ret->getPointer());
2809 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret2(DataArrayDouble::New());
2810 ret2->alloc(nbOfTargetPoints*nbOfPts,1);
2811 workCst=ret->begin(); work=ret2->getPointer();
2812 for(int i=0;i<nbOfTargetPoints;i++,workCst+=nbRows)
2813 work=std::copy(workCst,workCst+nbOfPts,work);
2818 * This method returns the square matrix of size \a matSz that is the inverse of the kriging matrix. The returned matrix can returned all the coeffs of kriging
2819 * when multiplied by the vector of values attached to each point.
2821 * \param [out] isDrift return if drift coefficients are present in the returned vector of coefficients. If different from 0 there is presence of drift coefficients.
2822 * \param [out] matSz the size of returned square matrix
2823 * \return the new result matrix to be deallocated by the caller.
2826 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeInverseMatrix(const MEDCouplingMesh *mesh, int& isDrift, int& matSz) const
2828 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrixWithDrift(computeMatrix(mesh,isDrift,matSz));
2829 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrixInv(DataArrayDouble::New());
2830 matrixInv->alloc(matSz*matSz,1);
2831 INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),matSz,matrixInv->getPointer());
2832 return matrixInv.retn();
2836 * This method computes the kriging matrix.
2837 * \return the new result matrix to be deallocated by the caller.
2838 * \sa computeInverseMatrix
2840 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeMatrix(const MEDCouplingMesh *mesh, int& isDrift, int& matSz) const
2843 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeMatrix : NULL input mesh !");
2844 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getLocalizationOfDiscValues(mesh));
2845 int nbOfPts(coords->getNumberOfTuples());
2846 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrix(coords->buildEuclidianDistanceDenseMatrix());
2847 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer());
2849 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrixWithDrift(performDrift(matrix,coords,isDrift));
2850 matSz=nbOfPts+isDrift;
2851 return matrixWithDrift.retn();
2855 * This method computes coefficients to apply to each representing points of \a mesh, that is to say the nodes of \a mesh given a field array \a arr whose
2856 * number of tuples should be equal to the number of representing points in \a mesh.
2858 * \param [in] mesh is the sources of nodes on which kriging will be done regarding the parameters and the value of \c this->getSpaceDimension()
2859 * \param [in] arr input field DataArrayDouble whose number of tuples must be equal to the number of nodes in \a mesh
2860 * \param [out] isDrift return if drift coefficients are present in the returned vector of coefficients. If different from 0 there is presence of drift coefficients.
2861 * Whatever the value of \a isDrift the number of tuples of returned DataArrayDouble will be equal to \c arr->getNumberOfTuples() + \a isDrift.
2862 * \return a newly allocated array containing coefficients including or not drift coefficient at the end depending the value of \a isDrift parameter.
2864 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const
2867 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2868 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> KnewiK(DataArrayDouble::New());
2869 KnewiK->alloc(nbRows*1,1);
2870 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(PerformDriftOfVec(arr,isDrift));
2871 INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbRows,nbRows,arr2->getConstPointer(),arr2->getNumberOfTuples(),1,KnewiK->getPointer());
2872 return KnewiK.retn();
2876 * Apply \f f(x) on each element x in \a matrixPtr. \a matrixPtr is expected to be a dense matrix represented by a chunck of memory of size at least equal to \a nbOfElems.
2878 * \param [in] spaceDimension space dimension of the input mesh on which the Kriging has to be performed
2879 * \param [in] nbOfElems is the result of the product of nb of rows and the nb of columns of matrix \a matrixPtr
2880 * \param [in,out] matrixPtr is the dense matrix whose on each values the operation will be applied
2882 void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimension, int nbOfElems, double *matrixPtr) const
2884 switch(spaceDimension)
2888 OperateOnDenseMatrixH3(nbOfElems,matrixPtr);
2893 OperateOnDenseMatrixH2Ln(nbOfElems,matrixPtr);
2898 //nothing here : it is not a bug g(h)=h with spaceDim 3.
2902 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix : only dimension 1, 2 and 3 implemented !");
2906 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH3(int nbOfElems, double *matrixPtr)
2908 for(int i=0;i<nbOfElems;i++)
2910 double val=matrixPtr[i];
2911 matrixPtr[i]=val*val*val;
2915 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH2Ln(int nbOfElems, double *matrixPtr)
2917 for(int i=0;i<nbOfElems;i++)
2919 double val=matrixPtr[i];
2921 matrixPtr[i]=val*val*log(val);
2926 * Performs a drift to the rectangular input matrix \a matr.
2927 * This method generate a dense matrix starting from an input dense matrix \a matr and input array \a arr.
2928 * \param [in] matr The rectangular dense matrix (with only one component). The number of rows of \a matr must be equal to the number of tuples of \a arr
2929 * \param [in] arr The array of coords to be appended in the input dense matrix \a matr. Typically arr is an array of coordinates.
2930 * \param [out] delta the delta of number of columns between returned dense matrix and input dense matrix \a matr. \a delta is equal to number of components of \a arr + 1.
2933 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftRect(const DataArrayDouble *matr, const DataArrayDouble *arr, int& delta)
2935 if(!matr || !matr->isAllocated() || matr->getNumberOfComponents()!=1)
2936 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input dense matrix ! Must be allocated not NULL and with exactly one component !");
2937 if(!arr || !arr->isAllocated())
2938 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input array of coordiantes ! Must be allocated and not NULL !");
2939 int spaceDimension(arr->getNumberOfComponents()),nbOfPts(arr->getNumberOfTuples()),nbOfEltInMatrx(matr->getNumberOfTuples());
2940 delta=spaceDimension+1;
2941 int nbOfCols(nbOfEltInMatrx/nbOfPts);
2942 if(nbOfEltInMatrx%nbOfPts!=0)
2943 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : size of input dense matrix and input arrays mismatch ! NbOfElems in matrix % nb of tuples in array must be equal to 0 !");
2944 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfPts*(nbOfCols+delta));
2945 double *retPtr(ret->getPointer());
2946 const double *mPtr(matr->begin()),*aPtr(arr->begin());
2947 for(int i=0;i<nbOfPts;i++,aPtr+=spaceDimension,mPtr+=nbOfCols)
2949 retPtr=std::copy(mPtr,mPtr+nbOfCols,retPtr);
2951 retPtr=std::copy(aPtr,aPtr+spaceDimension,retPtr);
2957 * \return a newly allocated array having \a isDrift more tuples than \a arr.
2958 * \sa computeVectorOfCoefficients
2960 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec(const DataArrayDouble *arr, int isDrift)
2962 if(!arr || !arr->isAllocated() || arr->getNumberOfComponents()!=1)
2963 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : input array must be not NULL allocated and with one component !");
2965 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : isDrift parameter must be >=0 !");
2966 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(DataArrayDouble::New());
2967 arr2->alloc((arr->getNumberOfTuples()+isDrift)*1,1);
2968 double *work(std::copy(arr->begin(),arr->end(),arr2->getPointer()));
2969 std::fill(work,work+isDrift,0.);
2974 * Starting from a square matrix \a matr, this method returns a newly allocated dense square matrix whose \a matr is included in returned matrix
2975 * in the top left corner, and in the remaining returned matrix the parameters to take into account about the kriging drift.
2976 * For the moment only linear srift is implemented.
2978 * \param [in] arr the position of points were input mesh geometry is considered for Kriging
2979 * \param [in] matr input matrix whose drift part will be added
2980 * \param [out] delta the difference between the size of the output matrix and the input matrix \a matr.
2981 * \return a newly allocated matrix bigger than input matrix \a matr.
2982 * \sa MEDCouplingFieldDiscretizationKriging::PerformDriftRect
2984 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataArrayDouble *matr, const DataArrayDouble *arr, int& delta) const
2986 int spaceDimension=arr->getNumberOfComponents();
2987 delta=spaceDimension+1;
2988 int szOfMatrix=arr->getNumberOfTuples();
2989 if(szOfMatrix*szOfMatrix!=matr->getNumberOfTuples())
2990 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::performDrift : invalid size");
2991 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2992 ret->alloc((szOfMatrix+delta)*(szOfMatrix+delta),1);
2993 const double *srcWork=matr->getConstPointer();
2994 const double *srcWork2=arr->getConstPointer();
2995 double *destWork=ret->getPointer();
2996 for(int i=0;i<szOfMatrix;i++)
2998 destWork=std::copy(srcWork,srcWork+szOfMatrix,destWork);
2999 srcWork+=szOfMatrix;
3001 destWork=std::copy(srcWork2,srcWork2+spaceDimension,destWork);
3002 srcWork2+=spaceDimension;
3004 std::fill(destWork,destWork+szOfMatrix,1.); destWork+=szOfMatrix;
3005 std::fill(destWork,destWork+spaceDimension+1,0.); destWork+=spaceDimension+1;
3006 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrNoI=arr->toNoInterlace();
3007 srcWork2=arrNoI->getConstPointer();
3008 for(int i=0;i<spaceDimension;i++)
3010 destWork=std::copy(srcWork2,srcWork2+szOfMatrix,destWork);
3011 srcWork2+=szOfMatrix;
3012 std::fill(destWork,destWork+spaceDimension+1,0.);
3013 destWork+=spaceDimension+1;