1 // Copyright (C) 2007-2016 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 (EDF R&D)
21 #include "MEDCouplingFieldDiscretization.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
27 #include "CellModel.hxx"
28 #include "InterpolationUtils.hxx"
29 #include "InterpKernelAutoPtr.hxx"
30 #include "InterpKernelGaussCoords.hxx"
31 #include "InterpKernelMatrixTools.hxx"
41 using namespace MEDCoupling;
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("Chosen 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 std::string MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(TypeOfField type)
164 if(type==MEDCouplingFieldDiscretizationP0::TYPE)
165 return MEDCouplingFieldDiscretizationP0::REPR;
166 if(type==MEDCouplingFieldDiscretizationP1::TYPE)
167 return MEDCouplingFieldDiscretizationP1::REPR;
168 if(type==MEDCouplingFieldDiscretizationGauss::TYPE)
169 return MEDCouplingFieldDiscretizationGauss::REPR;
170 if(type==MEDCouplingFieldDiscretizationGaussNE::TYPE)
171 return MEDCouplingFieldDiscretizationGaussNE::REPR;
172 if(type==MEDCouplingFieldDiscretizationKriging::TYPE)
173 return MEDCouplingFieldDiscretizationKriging::REPR;
174 throw INTERP_KERNEL::Exception("GetTypeOfFieldRepr : Representation does not match with any field discretization !");
177 bool MEDCouplingFieldDiscretization::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const
180 return isEqualIfNotWhy(other,eps,reason);
183 bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
185 return isEqual(other,eps);
189 * This method is an alias of MEDCouplingFieldDiscretization::clone. It is only here for coherency with all the remaining of MEDCoupling.
190 * \sa MEDCouplingFieldDiscretization::clone.
192 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::deepCopy() const
198 * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance.
200 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const int *startCellIds, const int *endCellIds) const
206 * For all field discretization excepted GaussPts the slice( \a beginCellId, \a endCellIds, \a stepCellId ) has no impact on the cloned instance.
208 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const
214 * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally.
216 void MEDCouplingFieldDiscretization::updateTime() const
220 std::size_t MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren() const
225 std::vector<const BigMemoryObject *> MEDCouplingFieldDiscretization::getDirectChildrenWithNull() const
227 return std::vector<const BigMemoryObject *>();
231 * Computes normL1 of DataArrayDouble instance arr.
232 * @param res output parameter expected to be of size arr->getNumberOfComponents();
233 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
235 void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const
237 MCAuto<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
238 int nbOfCompo=arr->getNumberOfComponents();
239 int nbOfElems=getNumberOfTuples(mesh);
240 std::fill(res,res+nbOfCompo,0.);
241 const double *arrPtr=arr->getConstPointer();
242 const double *volPtr=vol->getArray()->getConstPointer();
244 for(int i=0;i<nbOfElems;i++)
246 double v=fabs(volPtr[i]);
247 for(int j=0;j<nbOfCompo;j++)
248 res[j]+=fabs(arrPtr[i*nbOfCompo+j])*v;
251 std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
255 * Computes normL2 of DataArrayDouble instance arr.
256 * @param res output parameter expected to be of size arr->getNumberOfComponents();
257 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
259 void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const
261 MCAuto<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
262 int nbOfCompo=arr->getNumberOfComponents();
263 int nbOfElems=getNumberOfTuples(mesh);
264 std::fill(res,res+nbOfCompo,0.);
265 const double *arrPtr=arr->getConstPointer();
266 const double *volPtr=vol->getArray()->getConstPointer();
268 for(int i=0;i<nbOfElems;i++)
270 double v=fabs(volPtr[i]);
271 for(int j=0;j<nbOfCompo;j++)
272 res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*v;
275 std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
276 std::transform(res,res+nbOfCompo,res,std::ptr_fun<double,double>(std::sqrt));
280 * Computes integral of DataArrayDouble instance arr.
281 * @param res output parameter expected to be of size arr->getNumberOfComponents();
282 * @throw when the field discretization fails on getMeasure fields (gauss points for example)
284 void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const
287 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : mesh is NULL !");
289 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : input array is NULL !");
290 MCAuto<MEDCouplingFieldDouble> vol=getMeasureField(mesh,isWAbs);
291 std::size_t nbOfCompo(arr->getNumberOfComponents()),nbOfElems(getNumberOfTuples(mesh));
292 if(nbOfElems!=arr->getNumberOfTuples())
294 std::ostringstream oss; oss << "MEDCouplingFieldDiscretization::integral : field is not correct ! number of tuples in array is " << arr->getNumberOfTuples();
295 oss << " whereas number of tuples expected is " << nbOfElems << " !";
296 throw INTERP_KERNEL::Exception(oss.str().c_str());
298 std::fill(res,res+nbOfCompo,0.);
299 const double *arrPtr(arr->begin()),*volPtr(vol->getArray()->begin());
300 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfCompo];
301 for(std::size_t i=0;i<nbOfElems;i++)
303 std::transform(arrPtr+i*nbOfCompo,arrPtr+(i+1)*nbOfCompo,(double *)tmp,std::bind2nd(std::multiplies<double>(),volPtr[i]));
304 std::transform((double *)tmp,(double *)tmp+nbOfCompo,res,res,std::plus<double>());
309 * This method is strictly equivalent to MEDCouplingFieldDiscretization::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
311 * \param [out] beginOut Valid only if \a di is NULL
312 * \param [out] endOut Valid only if \a di is NULL
313 * \param [out] stepOut Valid only if \a di is NULL
314 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
316 * \sa MEDCouplingFieldDiscretization::buildSubMeshData
318 MEDCouplingMesh *MEDCouplingFieldDiscretization::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
320 MCAuto<DataArrayInt> da=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds);
321 return buildSubMeshData(mesh,da->begin(),da->end(),di);
324 void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const
332 void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
339 void MEDCouplingFieldDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
343 void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *& arr)
351 void MEDCouplingFieldDiscretization::checkForUnserialization(const std::vector<int>& tinyInfo, const DataArrayInt *arr)
358 void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector<double>& tinyInfo)
363 * This method is typically the first step of renumbering. The implementation is empty it is not a bug only gauss is impacted
364 * virtually by this method.
366 void MEDCouplingFieldDiscretization::renumberCells(const int *old2NewBg, bool check)
370 double MEDCouplingFieldDiscretization::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
372 throw INTERP_KERNEL::Exception("getIJK Invalid ! only for GaussPoint and GaussNE discretizations !");
375 void MEDCouplingFieldDiscretization::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
376 const std::vector<double>& gsCoo, const std::vector<double>& wg)
378 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
381 void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector<double>& refCoo,
382 const std::vector<double>& gsCoo, const std::vector<double>& wg)
384 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
387 void MEDCouplingFieldDiscretization::clearGaussLocalizations()
389 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
392 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId)
394 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
397 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) const
399 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
402 int MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const
404 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
407 int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(int cellId) const
409 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
412 int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
414 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
417 std::set<int> MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
419 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
422 void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
424 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
427 void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const std::string& msg)
430 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !");
431 int oldNbOfElems=arr->getNumberOfTuples();
432 int nbOfComp=arr->getNumberOfComponents();
433 int newNbOfTuples=newNbOfEntity;
434 MCAuto<DataArrayDouble> arrCpy=arr->deepCopy();
435 const double *ptSrc=arrCpy->getConstPointer();
436 arr->reAlloc(newNbOfTuples);
437 double *ptToFill=arr->getPointer();
438 std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits<double>::max());
439 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfComp];
440 for(int i=0;i<oldNbOfElems;i++)
442 int newNb=old2NewPtr[i];
443 if(newNb>=0)//if newNb<0 the node is considered as out.
445 if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to<double>(),std::numeric_limits<double>::max()))
446 ==ptToFill+(newNb+1)*nbOfComp)
447 std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp);
450 std::transform(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp,(double *)tmp,std::minus<double>());
451 std::transform((double *)tmp,((double *)tmp)+nbOfComp,(double *)tmp,std::ptr_fun<double,double>(fabs));
452 //if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
453 if(*std::max_element((double *)tmp,((double *)tmp)+nbOfComp)>eps)
455 std::ostringstream oss;
456 oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
457 << " have been merged and " << msg << " field on them are different !";
458 throw INTERP_KERNEL::Exception(oss.str().c_str());
465 void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const std::string& msg)
467 int nbOfComp=arr->getNumberOfComponents();
468 MCAuto<DataArrayDouble> arrCpy=arr->deepCopy();
469 const double *ptSrc=arrCpy->getConstPointer();
470 arr->reAlloc(new2OldSz);
471 double *ptToFill=arr->getPointer();
472 for(int i=0;i<new2OldSz;i++)
474 int oldNb=new2OldPtr[i];
475 std::copy(ptSrc+oldNb*nbOfComp,ptSrc+(oldNb+1)*nbOfComp,ptToFill+i*nbOfComp);
479 template<class FIELD_DISC>
480 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretization::EasyAggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds)
483 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : input array is empty");
484 for(const MEDCouplingFieldDiscretization * it : fds)
486 const FIELD_DISC *itc(dynamic_cast<const FIELD_DISC *>(it));
488 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : same field discretization expected for all input discretizations !");
490 return fds[0]->clone();
493 MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization()
497 TypeOfField MEDCouplingFieldDiscretizationP0::getEnum() const
503 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
505 * \sa MEDCouplingFieldDiscretization::deepCopy.
507 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP0::clone() const
509 return new MEDCouplingFieldDiscretizationP0;
512 std::string MEDCouplingFieldDiscretizationP0::getStringRepr() const
514 return std::string(REPR);
517 const char *MEDCouplingFieldDiscretizationP0::getRepr() const
522 bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
526 reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined.";
529 const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP0 *>(other);
532 reason="Spatial discrtization of this is ON_CELLS, which is not the case of other.";
536 int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const
539 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !");
540 return mesh->getNumberOfCells();
544 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
545 * The input code coherency is also checked regarding spatial discretization of \a this.
546 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
547 * 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).
549 int MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
552 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
553 int nbOfSplit=(int)idsPerType.size();
554 int nbOfTypes=(int)code.size()/3;
556 for(int i=0;i<nbOfTypes;i++)
558 int nbOfEltInChunk=code[3*i+1];
560 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
564 if(pos<0 || pos>=nbOfSplit)
566 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
567 throw INTERP_KERNEL::Exception(oss.str().c_str());
569 const DataArrayInt *ids(idsPerType[pos]);
570 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || (int)ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
572 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
573 throw INTERP_KERNEL::Exception(oss.str().c_str());
581 int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
584 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !");
585 return mesh->getNumberOfCells();
588 DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const
591 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !");
592 int nbOfTuples=mesh->getNumberOfCells();
593 DataArrayInt *ret=DataArrayInt::New();
594 ret->alloc(nbOfTuples+1,1);
599 void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
600 const int *old2NewBg, bool check)
603 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !");
604 const int *array=old2NewBg;
606 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
607 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
610 (*it)->renumberInPlace(array);
613 free(const_cast<int *>(array));
616 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
619 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !");
620 return mesh->computeCellCenterOfMass();
623 void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
624 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
627 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds : NULL input mesh !");
628 MCAuto<DataArrayInt> tmp=DataArrayInt::New();
629 tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
630 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
631 MCAuto<DataArrayInt> tmp2(tmp->deepCopy());
632 cellRestriction=tmp.retn();
633 trueTupleRestriction=tmp2.retn();
636 void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const
638 stream << "P0 spatial discretization.";
641 void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const
645 void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
648 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh or DataArray !");
649 if(mesh->getNumberOfCells()!=da->getNumberOfTuples())
651 std::ostringstream message;
652 message << "Field on cells invalid because there are " << mesh->getNumberOfCells();
653 message << " cells in mesh and " << da->getNumberOfTuples() << " tuples in field !";
654 throw INTERP_KERNEL::Exception(message.str().c_str());
658 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
661 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getMeasureField : mesh instance specified is NULL !");
662 return mesh->getMeasureField(isAbs);
665 void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
668 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !");
669 int id=mesh->getCellContainingPoint(loc,_precision);
671 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !");
672 arr->getTuple(id,res);
675 void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
677 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
679 throw INTERP_KERNEL::Exception("P0::getValueOnPos is only accessible for structured meshes !");
680 int id=meshC->getCellIdFromPos(i,j,k);
681 arr->getTuple(id,res);
684 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
687 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !");
688 MCAuto<DataArrayInt> eltsArr,eltsIndexArr;
689 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
690 const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
691 int spaceDim=mesh->getSpaceDimension();
692 int nbOfComponents=arr->getNumberOfComponents();
693 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
694 ret->alloc(nbOfPoints,nbOfComponents);
695 double *ptToFill=ret->getPointer();
696 for(int i=0;i<nbOfPoints;i++,ptToFill+=nbOfComponents)
697 if(eltsIndex[i+1]-eltsIndex[i]>=1)
698 arr->getTuple(elts[eltsIndex[i]],ptToFill);
701 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
702 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
703 oss << ") detected outside mesh : unable to apply P0::getValueOnMulti ! ";
704 throw INTERP_KERNEL::Exception(oss.str().c_str());
710 * Nothing to do. It's not a bug.
712 void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
716 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
718 RenumberEntitiesFromO2NArr(epsOnVals,old2New,newSz,arr,"Cell");
721 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
723 RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell");
727 * This method returns a tuple ids selection from cell ids selection [start;end).
728 * This method is called by MEDCouplingFieldDiscretizationP0::buildSubMeshData to return parameter \b di.
729 * Here for P0 it's very simple !
731 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
734 DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
736 MCAuto<DataArrayInt> ret=DataArrayInt::New();
737 ret->alloc((int)std::distance(startCellIds,endCellIds),1);
738 std::copy(startCellIds,endCellIds,ret->getPointer());
743 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
744 * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh.
745 * Example : The first cell id of returned mesh has the (*di)[0] id in 'mesh'
747 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange
749 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
752 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !");
753 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
754 MCAuto<DataArrayInt> diSafe=DataArrayInt::New();
755 diSafe->alloc((int)std::distance(start,end),1);
756 std::copy(start,end,diSafe->getPointer());
762 * This method is strictly equivalent to MEDCouplingFieldDiscretizationP0::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
764 * \param [out] beginOut Valid only if \a di is NULL
765 * \param [out] endOut Valid only if \a di is NULL
766 * \param [out] stepOut Valid only if \a di is NULL
767 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
769 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshData
771 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
774 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !");
775 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
776 di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds;
780 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationP0::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
782 return EasyAggregate<MEDCouplingFieldDiscretizationP0>(fds);
785 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const
788 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !");
789 return mesh->getNumberOfNodes();
793 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
794 * The input code coherency is also checked regarding spatial discretization of \a this.
795 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
796 * 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).
798 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
801 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
802 int nbOfSplit=(int)idsPerType.size();
803 int nbOfTypes=(int)code.size()/3;
805 for(int i=0;i<nbOfTypes;i++)
807 int nbOfEltInChunk=code[3*i+1];
809 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
813 if(pos<0 || pos>=nbOfSplit)
815 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
816 throw INTERP_KERNEL::Exception(oss.str().c_str());
818 const DataArrayInt *ids(idsPerType[pos]);
819 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || (int)ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
821 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
822 throw INTERP_KERNEL::Exception(oss.str().c_str());
830 int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
833 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !");
834 return mesh->getNumberOfNodes();
838 * Nothing to do here.
840 void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector<DataArray *>& arrays,
841 const int *old2NewBg, bool check)
845 DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const
848 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !");
849 int nbOfTuples=mesh->getNumberOfNodes();
850 DataArrayInt *ret=DataArrayInt::New();
851 ret->alloc(nbOfTuples+1,1);
856 DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
859 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !");
860 return mesh->getCoordinatesAndOwner();
863 void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
864 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
867 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : NULL input mesh !");
868 MCAuto<DataArrayInt> ret1=mesh->getCellIdsFullyIncludedInNodeIds(tupleIdsBg,tupleIdsEnd);
869 const MEDCouplingUMesh *meshc=dynamic_cast<const MEDCouplingUMesh *>(mesh);
871 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : trying to subpart field on nodes by node ids ! Your mesh has to be unstructured !");
872 MCAuto<MEDCouplingUMesh> meshPart=static_cast<MEDCouplingUMesh *>(meshc->buildPartOfMySelf(ret1->begin(),ret1->end(),true));
873 MCAuto<DataArrayInt> ret2=meshPart->computeFetchedNodeIds();
874 cellRestriction=ret1.retn();
875 trueTupleRestriction=ret2.retn();
878 void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
881 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh or DataArray !");
882 if(mesh->getNumberOfNodes()!=(int)da->getNumberOfTuples())
884 std::ostringstream message;
885 message << "Field on nodes invalid because there are " << mesh->getNumberOfNodes();
886 message << " nodes in mesh and " << da->getNumberOfTuples() << " tuples in field !";
887 throw INTERP_KERNEL::Exception(message.str().c_str());
892 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
893 * @param di is an array returned that specifies entity ids (here nodes ids) in mesh 'mesh' of entity in returned submesh.
894 * Example : The first node id of returned mesh has the (*di)[0] id in 'mesh'
896 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
899 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !");
900 DataArrayInt *diTmp=0;
901 MCAuto<MEDCouplingMesh> ret=mesh->buildPartAndReduceNodes(start,end,diTmp);
902 MCAuto<DataArrayInt> diTmpSafe(diTmp);
903 MCAuto<DataArrayInt> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
909 * This method is strictly equivalent to MEDCouplingFieldDiscretizationNodes::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
911 * \param [out] beginOut Valid only if \a di is NULL
912 * \param [out] endOut Valid only if \a di is NULL
913 * \param [out] stepOut Valid only if \a di is NULL
914 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
916 * \sa MEDCouplingFieldDiscretizationNodes::buildSubMeshData
918 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
921 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !");
922 DataArrayInt *diTmp=0;
923 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp);
926 MCAuto<DataArrayInt> diTmpSafe(diTmp);
927 MCAuto<DataArrayInt> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
934 * This method returns a tuple ids selection from cell ids selection [start;end).
935 * This method is called by MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData to return parameter \b di.
936 * Here for P1 only nodes fetched by submesh of mesh[startCellIds:endCellIds) is returned !
938 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
941 DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
944 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !");
945 const MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();
946 MCAuto<MEDCouplingUMesh> umesh2=static_cast<MEDCouplingUMesh *>(umesh->buildPartOfMySelf(startCellIds,endCellIds,true));
947 return umesh2->computeFetchedNodeIds();
950 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, int newNbOfNodes, DataArrayDouble *arr) const
952 RenumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,newNbOfNodes,arr,"Node");
956 * Nothing to do it's not a bug.
958 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
963 * Nothing to do it's not a bug.
965 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
969 void MEDCouplingFieldDiscretizationOnNodes::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
971 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
973 throw INTERP_KERNEL::Exception("OnNodes::getValueOnPos(i,j,k) is only accessible for structured meshes !");
974 int id=meshC->getNodeIdFromPos(i,j,k);
975 arr->getTuple(id,res);
978 TypeOfField MEDCouplingFieldDiscretizationP1::getEnum() const
984 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
986 * \sa MEDCouplingFieldDiscretization::deepCopy.
988 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP1::clone() const
990 return new MEDCouplingFieldDiscretizationP1;
993 std::string MEDCouplingFieldDiscretizationP1::getStringRepr() const
995 return std::string(REPR);
998 const char *MEDCouplingFieldDiscretizationP1::getRepr() const
1003 bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1007 reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined.";
1010 const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP1 *>(other);
1013 reason="Spatial discrtization of this is ON_NODES, which is not the case of other.";
1017 void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const
1019 if(nat!=IntensiveMaximum)
1020 throw INTERP_KERNEL::Exception("Invalid nature for P1 field : expected IntensiveMaximum !");
1023 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
1026 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getMeasureField : mesh instance specified is NULL !");
1027 return mesh->getMeasureFieldOnNode(isAbs);
1030 void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
1033 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !");
1034 int id=mesh->getCellContainingPoint(loc,_precision);
1036 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !");
1037 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(id);
1038 if(type!=INTERP_KERNEL::NORM_SEG2 && type!=INTERP_KERNEL::NORM_TRI3 && type!=INTERP_KERNEL::NORM_TETRA4)
1039 throw INTERP_KERNEL::Exception("P1 getValueOn is not specified for not simplex cells !");
1040 getValueInCell(mesh,id,arr,loc,res);
1044 * This method localizes a point defined by 'loc' in a cell with id 'cellId' into mesh 'mesh'.
1045 * The result is put into res expected to be of size at least arr->getNumberOfComponents()
1047 void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const
1050 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !");
1051 std::vector<int> conn;
1052 std::vector<double> coo;
1053 mesh->getNodeIdsOfCell(cellId,conn);
1054 for(std::vector<int>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
1055 mesh->getCoordinatesOfNode(*iter,coo);
1056 int spaceDim=mesh->getSpaceDimension();
1057 std::size_t nbOfNodes=conn.size();
1058 std::vector<const double *> vec(nbOfNodes);
1059 for(std::size_t i=0;i<nbOfNodes;i++)
1060 vec[i]=&coo[i*spaceDim];
1061 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfNodes];
1062 INTERP_KERNEL::NormalizedCellType ct(mesh->getTypeOfCell(cellId));
1063 INTERP_KERNEL::barycentric_coords(ct,vec,loc,tmp);
1064 int sz=arr->getNumberOfComponents();
1065 INTERP_KERNEL::AutoPtr<double> tmp2=new double[sz];
1066 std::fill(res,res+sz,0.);
1067 for(std::size_t i=0;i<nbOfNodes;i++)
1069 arr->getTuple(conn[i],(double *)tmp2);
1070 std::transform((double *)tmp2,((double *)tmp2)+sz,(double *)tmp2,std::bind2nd(std::multiplies<double>(),tmp[i]));
1071 std::transform(res,res+sz,(double *)tmp2,res,std::plus<double>());
1075 DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
1078 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !");
1079 MCAuto<DataArrayInt> eltsArr,eltsIndexArr;
1080 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
1081 const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
1082 int spaceDim=mesh->getSpaceDimension();
1083 int nbOfComponents=arr->getNumberOfComponents();
1084 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
1085 ret->alloc(nbOfPoints,nbOfComponents);
1086 double *ptToFill=ret->getPointer();
1087 for(int i=0;i<nbOfPoints;i++)
1088 if(eltsIndex[i+1]-eltsIndex[i]>=1)
1089 getValueInCell(mesh,elts[eltsIndex[i]],arr,loc+i*spaceDim,ptToFill+i*nbOfComponents);
1092 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
1093 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
1094 oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! ";
1095 throw INTERP_KERNEL::Exception(oss.str().c_str());
1100 void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const
1102 stream << "P1 spatial discretization.";
1105 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationP1::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
1107 return EasyAggregate<MEDCouplingFieldDiscretizationP1>(fds);
1110 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0)
1114 MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell()
1117 _discr_per_cell->decrRef();
1121 * This constructor deep copies MEDCoupling::DataArrayInt instance from other (if any).
1123 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds):_discr_per_cell(0)
1125 DataArrayInt *arr=other._discr_per_cell;
1128 if(startCellIds==0 && endCellIds==0)
1129 _discr_per_cell=arr->deepCopy();
1131 _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds);
1135 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, int beginCellIds, int endCellIds, int stepCellIds):_discr_per_cell(0)
1137 DataArrayInt *arr=other._discr_per_cell;
1140 _discr_per_cell=arr->selectByTupleIdSafeSlice(beginCellIds,endCellIds,stepCellIds);
1144 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(DataArrayInt *dpc):_discr_per_cell(dpc)
1147 _discr_per_cell->incrRef();
1150 void MEDCouplingFieldDiscretizationPerCell::updateTime() const
1153 updateTimeWith(*_discr_per_cell);
1156 std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren() const
1158 std::size_t ret(MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren());
1162 std::vector<const BigMemoryObject *> MEDCouplingFieldDiscretizationPerCell::getDirectChildrenWithNull() const
1164 std::vector<const BigMemoryObject *> ret(MEDCouplingFieldDiscretization::getDirectChildrenWithNull());
1165 ret.push_back(_discr_per_cell);
1169 void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1171 if(!_discr_per_cell)
1172 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !");
1174 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh or DataArray !");
1175 std::size_t nbOfTuples(_discr_per_cell->getNumberOfTuples());
1176 if(nbOfTuples!=mesh->getNumberOfCells())
1177 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !");
1180 bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1184 reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined.";
1187 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1190 reason="Spatial discretization of this is ON_GAUSS, which is not the case of other.";
1193 if(_discr_per_cell==0)
1194 return otherC->_discr_per_cell==0;
1195 if(otherC->_discr_per_cell==0)
1197 bool ret=_discr_per_cell->isEqualIfNotWhy(*otherC->_discr_per_cell,reason);
1199 reason.insert(0,"Field discretization per cell DataArrayInt given the discid per cell :");
1203 bool MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1205 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1208 if(_discr_per_cell==0)
1209 return otherC->_discr_per_cell==0;
1210 if(otherC->_discr_per_cell==0)
1212 return _discr_per_cell->isEqualWithoutConsideringStr(*otherC->_discr_per_cell);
1216 * This method is typically the first step of renumbering. The impact on _discr_per_cell is necessary here.
1217 * virtually by this method.
1219 void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, bool check)
1221 int nbCells=_discr_per_cell->getNumberOfTuples();
1222 const int *array=old2NewBg;
1224 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+nbCells);
1226 DataArrayInt *dpc=_discr_per_cell->renumber(array);
1227 _discr_per_cell->decrRef();
1228 _discr_per_cell=dpc;
1231 free(const_cast<int *>(array));
1234 void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh)
1237 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !");
1238 if(!_discr_per_cell)
1240 _discr_per_cell=DataArrayInt::New();
1241 int nbTuples=mesh->getNumberOfCells();
1242 _discr_per_cell->alloc(nbTuples,1);
1243 int *ptr=_discr_per_cell->getPointer();
1244 std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE);
1248 void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const
1250 if(!_discr_per_cell)
1251 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : no discretization defined !");
1252 MCAuto<DataArrayInt> test=_discr_per_cell->findIdsEqual(DFT_INVALID_LOCID_VALUE);
1253 if(test->getNumberOfTuples()!=0)
1254 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : presence of orphan cells !");
1258 * This method is useful when 'this' describes a field discretization with several gauss discretization on a \b same cell type.
1259 * For example same NORM_TRI3 cells having 6 gauss points and others with 12 gauss points.
1260 * This method returns 2 arrays with same size : the return value and 'locIds' output parameter.
1261 * 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.
1262 * The return vector contains a set of newly created instance to deal with.
1263 * The returned vector represents a \b partition of cells ids with a gauss discretization set.
1265 * If no descretization is set in 'this' and exception will be thrown.
1267 std::vector<DataArrayInt *> MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector<int>& locIds) const
1269 if(!_discr_per_cell)
1270 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType : no descretization set !");
1271 return _discr_per_cell->partitionByDifferentValues(locIds);
1274 const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const
1276 return _discr_per_cell;
1279 void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids)
1281 if(adids!=_discr_per_cell)
1284 _discr_per_cell->decrRef();
1285 _discr_per_cell=const_cast<DataArrayInt *>(adids);
1287 _discr_per_cell->incrRef();
1292 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss()
1296 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds, const int *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc)
1300 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, int beginCellIds, int endCellIds, int stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc)
1304 TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const
1309 bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1313 reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined.";
1316 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1319 reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other.";
1322 if(!MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(other,eps,reason))
1324 if(_loc.size()!=otherC->_loc.size())
1326 reason="Gauss spatial discretization : localization sizes differ";
1329 std::size_t sz=_loc.size();
1330 for(std::size_t i=0;i<sz;i++)
1331 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1333 std::ostringstream oss; oss << "Gauss spatial discretization : Localization #" << i << " differ from this to other.";
1340 bool MEDCouplingFieldDiscretizationGauss::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1342 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1345 if(!MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(other,eps))
1347 if(_loc.size()!=otherC->_loc.size())
1349 std::size_t sz=_loc.size();
1350 for(std::size_t i=0;i<sz;i++)
1351 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1357 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
1359 * \sa MEDCouplingFieldDiscretization::deepCopy.
1361 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() const
1363 return new MEDCouplingFieldDiscretizationGauss(*this);
1366 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const int *startCellIds, const int *endCellIds) const
1368 return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds);
1371 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const
1373 return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds);
1376 std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const
1378 std::ostringstream oss; oss << REPR << "." << std::endl;
1381 if(_discr_per_cell->isAllocated())
1383 oss << "Discretization per cell : ";
1384 std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator<int>(oss,", "));
1388 oss << "Presence of " << _loc.size() << " localizations." << std::endl;
1390 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++,i++)
1392 oss << "+++++ Localization #" << i << " +++++" << std::endl;
1393 oss << (*it).getStringRepr();
1394 oss << "++++++++++" << std::endl;
1399 std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySizeWithoutChildren() const
1401 std::size_t ret(MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren());
1402 ret+=_loc.capacity()*sizeof(MEDCouplingGaussLocalization);
1403 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++)
1404 ret+=(*it).getMemorySize();
1408 const char *MEDCouplingFieldDiscretizationGauss::getRepr() const
1414 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
1415 * The input code coherency is also checked regarding spatial discretization of \a this.
1416 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
1417 * 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).
1419 int MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
1421 if(!_discr_per_cell || !_discr_per_cell->isAllocated() || _discr_per_cell->getNumberOfComponents()!=1)
1422 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode");
1423 if(code.size()%3!=0)
1424 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
1425 int nbOfSplit=(int)idsPerType.size();
1426 int nbOfTypes=(int)code.size()/3;
1428 for(int i=0;i<nbOfTypes;i++)
1430 int nbOfEltInChunk=code[3*i+1];
1431 if(nbOfEltInChunk<0)
1432 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
1433 int pos=code[3*i+2];
1436 if(pos<0 || pos>=nbOfSplit)
1438 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
1439 throw INTERP_KERNEL::Exception(oss.str().c_str());
1441 const DataArrayInt *ids(idsPerType[pos]);
1442 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || (int)ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
1444 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
1445 throw INTERP_KERNEL::Exception(oss.str().c_str());
1448 ret+=nbOfEltInChunk;
1450 if(ret!=_discr_per_cell->getNumberOfTuples())
1452 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " cells whereas discretization percell array lgth is " << _discr_per_cell->getNumberOfTuples() << " !";
1453 throw INTERP_KERNEL::Exception(oss.str().c_str());
1455 return getNumberOfTuples(0);//0 is not an error ! It is to be sure that input mesh is not used
1458 int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const
1461 if (_discr_per_cell == 0)
1462 throw INTERP_KERNEL::Exception("Discretization is not initialized!");
1463 const int *dcPtr=_discr_per_cell->getConstPointer();
1464 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1465 int maxSz=(int)_loc.size();
1466 for(const int *w=dcPtr;w!=dcPtr+nbOfTuples;w++)
1468 if(*w>=0 && *w<maxSz)
1469 ret+=_loc[*w].getNumberOfGaussPt();
1472 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuples : At cell #" << std::distance(dcPtr,w) << " localization id is " << *w << " should be in [0," << maxSz << ") !";
1473 throw INTERP_KERNEL::Exception(oss.str().c_str());
1479 int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
1482 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces : NULL input mesh !");
1483 return mesh->getNumberOfCells();
1487 * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField
1488 * and a call to DataArrayDouble::computeOffsetsFull on the returned array.
1490 DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const
1493 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !");
1494 std::size_t nbOfTuples(mesh->getNumberOfCells());
1495 MCAuto<DataArrayInt> ret=DataArrayInt::New();
1496 ret->alloc(nbOfTuples+1,1);
1497 int *retPtr(ret->getPointer());
1498 const int *start(_discr_per_cell->begin());
1499 if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples)
1500 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !");
1501 int maxPossible=(int)_loc.size();
1503 for(std::size_t i=0;i<nbOfTuples;i++,start++)
1505 if(*start>=0 && *start<maxPossible)
1506 retPtr[i+1]=retPtr[i]+_loc[*start].getNumberOfGaussPt();
1509 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getOffsetArr : At position #" << i << " the locid = " << *start << " whereas it should be in [0," << maxPossible << ") !";
1510 throw INTERP_KERNEL::Exception(oss.str().c_str());
1516 void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
1517 const int *old2NewBg, bool check)
1520 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !");
1521 const int *array=old2NewBg;
1523 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
1524 int nbOfCells=_discr_per_cell->getNumberOfTuples();
1525 int nbOfTuples=getNumberOfTuples(0);
1526 const int *dcPtr=_discr_per_cell->getConstPointer();
1527 int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
1528 int *array3=new int[nbOfCells];//store for each cell in present dcp array (already renumbered) the offset needed by each cell in new numbering.
1530 for(int i=1;i<nbOfCells;i++)
1531 array3[i]=array3[i-1]+_loc[dcPtr[i-1]].getNumberOfGaussPt();
1533 for(int i=0;i<nbOfCells;i++)
1535 int nbOfGaussPt=_loc[dcPtr[array[i]]].getNumberOfGaussPt();
1536 for(int k=0;k<nbOfGaussPt;k++,j++)
1537 array2[j]=array3[array[i]]+k;
1540 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
1542 (*it)->renumberInPlace(array2);
1545 free(const_cast<int*>(array));
1548 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
1551 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !");
1552 checkNoOrphanCells();
1553 MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
1554 int nbOfTuples=getNumberOfTuples(mesh);
1555 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
1556 int spaceDim=mesh->getSpaceDimension();
1557 ret->alloc(nbOfTuples,spaceDim);
1558 std::vector< int > locIds;
1559 std::vector<DataArrayInt *> parts=splitIntoSingleGaussDicrPerCellType(locIds);
1560 std::vector< MCAuto<DataArrayInt> > parts2(parts.size());
1561 std::copy(parts.begin(),parts.end(),parts2.begin());
1562 MCAuto<DataArrayInt> offsets=buildNbOfGaussPointPerCellField();
1563 offsets->computeOffsets();
1564 const int *ptrOffsets=offsets->getConstPointer();
1565 const double *coords=umesh->getCoords()->getConstPointer();
1566 const int *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
1567 const int *conn=umesh->getNodalConnectivity()->getConstPointer();
1568 double *valsToFill=ret->getPointer();
1569 for(std::size_t i=0;i<parts2.size();i++)
1571 INTERP_KERNEL::GaussCoords calculator;
1573 const MEDCouplingGaussLocalization& cli(_loc[locIds[i]]);//curLocInfo
1574 INTERP_KERNEL::NormalizedCellType typ(cli.getType());
1575 const std::vector<double>& wg(cli.getWeights());
1576 calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(),
1577 &cli.getGaussCoords()[0],(int)wg.size(),&cli.getRefCoords()[0],
1578 INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes());
1580 for(const int *w=parts2[i]->begin();w!=parts2[i]->end();w++)
1581 calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w]));
1583 ret->copyStringInfoFrom(*umesh->getCoords());
1587 void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
1588 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
1591 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !");
1592 MCAuto<DataArrayInt> tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
1593 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
1595 tmp=tmp->buildUnique();
1596 MCAuto<DataArrayInt> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();
1597 nbOfNodesPerCell->computeOffsetsFull();
1598 nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
1604 void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const
1608 void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1612 val=_discr_per_cell->getNumberOfTuples();
1613 tinyInfo.push_back(val);
1614 tinyInfo.push_back((int)_loc.size());
1616 tinyInfo.push_back(-1);
1618 tinyInfo.push_back(_loc[0].getDimension());
1619 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1620 (*iter).pushTinySerializationIntInfo(tinyInfo);
1623 void MEDCouplingFieldDiscretizationGauss::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1625 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1626 (*iter).pushTinySerializationDblInfo(tinyInfo);
1629 void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayInt *& arr) const
1633 arr=_discr_per_cell;
1636 void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *& arr)
1638 int val=tinyInfo[0];
1641 _discr_per_cell=DataArrayInt::New();
1642 _discr_per_cell->alloc(val,1);
1646 arr=_discr_per_cell;
1647 commonUnserialization(tinyInfo);
1650 void MEDCouplingFieldDiscretizationGauss::checkForUnserialization(const std::vector<int>& tinyInfo, const DataArrayInt *arr)
1652 static const char MSG[]="MEDCouplingFieldDiscretizationGauss::checkForUnserialization : expect to have one not null DataArrayInt !";
1653 int val=tinyInfo[0];
1657 throw INTERP_KERNEL::Exception(MSG);
1658 arr->checkNbOfTuplesAndComp(val,1,MSG);
1659 _discr_per_cell=const_cast<DataArrayInt *>(arr);
1660 _discr_per_cell->incrRef();
1664 commonUnserialization(tinyInfo);
1667 void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vector<double>& tinyInfo)
1669 double *tmp=new double[tinyInfo.size()];
1670 std::copy(tinyInfo.begin(),tinyInfo.end(),tmp);
1671 const double *work=tmp;
1672 for(std::vector<MEDCouplingGaussLocalization>::iterator iter=_loc.begin();iter!=_loc.end();iter++)
1673 work=(*iter).fillWithValues(work);
1677 double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
1679 int offset=getOffsetOfCell(cellId);
1680 return da->getIJ(offset+nodeIdInCell,compoId);
1683 void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1686 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh or DataArray !");
1687 MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da);
1688 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1689 (*iter).checkConsistencyLight();
1690 int nbOfDesc=(int)_loc.size();
1691 int nbOfCells=mesh->getNumberOfCells();
1692 const int *dc=_discr_per_cell->getConstPointer();
1693 for(int i=0;i<nbOfCells;i++)
1697 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happened !";
1698 throw INTERP_KERNEL::Exception(oss.str().c_str());
1702 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has no gauss location !";
1703 throw INTERP_KERNEL::Exception(oss.str().c_str());
1705 if(mesh->getTypeOfCell(i)!=_loc[dc[i]].getType())
1707 std::ostringstream oss; oss << "Types of mesh and gauss location mismatch for cell # " << i;
1708 throw INTERP_KERNEL::Exception(oss.str().c_str());
1711 std::size_t nbOfTuples(getNumberOfTuples(mesh));
1712 if(nbOfTuples!=da->getNumberOfTuples())
1714 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " having " << da->getNumberOfTuples() << " !";
1715 throw INTERP_KERNEL::Exception(oss.str().c_str());
1719 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
1722 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : mesh instance specified is NULL !");
1723 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
1724 const double *volPtr=vol->getArray()->begin();
1725 MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_PT);
1727 ret->setDiscretization(const_cast<MEDCouplingFieldDiscretizationGauss *>(this));
1728 if(!_discr_per_cell)
1729 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array not defined ! spatial localization is incorrect !");
1730 _discr_per_cell->checkAllocated();
1731 if(_discr_per_cell->getNumberOfComponents()!=1)
1732 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but with nb of components different from 1 !");
1733 if(_discr_per_cell->getNumberOfTuples()!=vol->getNumberOfTuples())
1734 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 !");
1735 MCAuto<DataArrayInt> offset=getOffsetArr(mesh);
1736 MCAuto<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(getNumberOfTuples(mesh),1);
1738 double *arrPtr=arr->getPointer();
1739 const int *offsetPtr=offset->getConstPointer();
1740 int maxGaussLoc=(int)_loc.size();
1741 std::vector<int> locIds;
1742 std::vector<DataArrayInt *> ids=splitIntoSingleGaussDicrPerCellType(locIds);
1743 std::vector< MCAuto<DataArrayInt> > ids2(ids.size()); std::copy(ids.begin(),ids.end(),ids2.begin());
1744 for(std::size_t i=0;i<locIds.size();i++)
1746 const DataArrayInt *curIds=ids[i];
1747 int locId=locIds[i];
1748 if(locId>=0 && locId<maxGaussLoc)
1750 const MEDCouplingGaussLocalization& loc=_loc[locId];
1751 int nbOfGaussPt=loc.getNumberOfGaussPt();
1752 INTERP_KERNEL::AutoPtr<double> weights=new double[nbOfGaussPt];
1753 double sum=std::accumulate(loc.getWeights().begin(),loc.getWeights().end(),0.);
1754 std::transform(loc.getWeights().begin(),loc.getWeights().end(),(double *)weights,std::bind2nd(std::multiplies<double>(),1./sum));
1755 for(const int *cellId=curIds->begin();cellId!=curIds->end();cellId++)
1756 for(int j=0;j<nbOfGaussPt;j++)
1757 arrPtr[offsetPtr[*cellId]+j]=weights[j]*volPtr[*cellId];
1761 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getMeasureField : Presence of localization id " << locId << " in cell #" << curIds->getIJ(0,0) << " ! Must be in [0," << maxGaussLoc << ") !";
1762 throw INTERP_KERNEL::Exception(oss.str().c_str());
1765 ret->synchronizeTimeWithSupport();
1769 void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
1771 throw INTERP_KERNEL::Exception("Not implemented yet !");
1774 void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
1776 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !");
1779 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
1781 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented yet for gauss points !");
1784 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
1787 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !");
1788 MCAuto<DataArrayInt> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
1789 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
1795 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
1797 * \param [out] beginOut Valid only if \a di is NULL
1798 * \param [out] endOut Valid only if \a di is NULL
1799 * \param [out] stepOut Valid only if \a di is NULL
1800 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
1802 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
1804 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
1806 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
1807 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
1809 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : NULL input mesh !");
1810 if(!_discr_per_cell)
1811 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : no discretization array set !");
1812 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
1813 const char msg[]="MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : cell #";
1814 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
1815 const int *w=_discr_per_cell->begin();
1816 int nbMaxOfLocId=(int)_loc.size();
1817 for(int i=0;i<nbOfTuples;i++,w++)
1819 if(*w!=DFT_INVALID_LOCID_VALUE)
1821 if(*w>=0 && *w<nbMaxOfLocId)
1823 int delta=_loc[*w].getNumberOfGaussPt();
1831 { std::ostringstream oss; oss << msg << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1834 { std::ostringstream oss; oss << msg << i << " is detected as orphan !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1836 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
1841 * This method returns a tuple ids selection from cell ids selection [start;end).
1842 * This method is called by MEDCouplingFieldDiscretizationGauss::buildSubMeshData to return parameter \b di.
1844 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
1847 DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
1850 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !");
1851 MCAuto<DataArrayInt> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer
1852 std::size_t nbOfCells(mesh->getNumberOfCells());
1853 if(_discr_per_cell->getNumberOfTuples()!=nbOfCells)
1854 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : mismatch of nb of tuples of cell ids array and number of cells !");
1855 nbOfNodesPerCell->computeOffsetsFull();
1856 MCAuto<DataArrayInt> sel=DataArrayInt::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1);
1857 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
1861 * No implementation needed !
1863 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
1867 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
1869 throw INTERP_KERNEL::Exception("Not implemented yet !");
1872 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
1874 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 !");
1877 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationGauss::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
1880 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : input array is empty");
1881 std::vector<MEDCouplingGaussLocalization> loc;//store the localizations for the output GaussDiscretization object
1882 std::vector< MCAuto<DataArrayInt> > discPerCells(fds.size());
1884 for(auto it=fds.begin();it!=fds.end();++it,++i)
1886 const MEDCouplingFieldDiscretizationGauss *itc(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(*it));
1888 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : same field discretization expected for all input discretizations !");
1890 std::vector<MEDCouplingGaussLocalization> loc2(itc->_loc);
1891 std::vector<int> newLocId(loc2.size());
1892 for(std::size_t j=0;j<loc2.size();++j)
1895 for(;k<loc.size();++k)
1897 if(loc2[j].isEqual(loc[k],1e-10))
1903 if(k==loc.size())// current loc2[j]
1905 newLocId[j]=(int)loc.size();
1906 loc.push_back(loc2[j]);
1909 const DataArrayInt *dpc(itc->_discr_per_cell);
1911 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : Presence of nullptr array of disc per cell !");
1912 MCAuto<DataArrayInt> dpc2(dpc->deepCopy());
1913 dpc2->transformWithIndArr(newLocId.data(),newLocId.data()+newLocId.size());
1914 discPerCells[i]=dpc2;
1916 MCAuto<DataArrayInt> dpc3(DataArrayInt::Aggregate(ToConstVect(discPerCells)));
1917 MCAuto<MEDCouplingFieldDiscretizationGauss> ret(new MEDCouplingFieldDiscretizationGauss(dpc3,loc));
1918 return DynamicCast<MEDCouplingFieldDiscretizationGauss,MEDCouplingFieldDiscretization>(ret);
1921 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
1922 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1925 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !");
1926 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1927 if((int)cm.getDimension()!=mesh->getMeshDimension())
1929 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension();
1930 oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !";
1931 throw INTERP_KERNEL::Exception(oss.str().c_str());
1933 buildDiscrPerCellIfNecessary(mesh);
1934 int id=(int)_loc.size();
1935 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1936 _loc.push_back(elt);
1937 int *ptr=_discr_per_cell->getPointer();
1938 int nbCells=mesh->getNumberOfCells();
1939 for(int i=0;i<nbCells;i++)
1940 if(mesh->getTypeOfCell(i)==type)
1942 zipGaussLocalizations();
1945 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector<double>& refCoo,
1946 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1949 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !");
1950 buildDiscrPerCellIfNecessary(mesh);
1951 if(std::distance(begin,end)<1)
1952 throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !");
1953 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin);
1954 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1955 int id=(int)_loc.size();
1956 int *ptr=_discr_per_cell->getPointer();
1957 for(const int *w=begin+1;w!=end;w++)
1959 if(mesh->getTypeOfCell(*w)!=type)
1961 std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !";
1962 throw INTERP_KERNEL::Exception(oss.str().c_str());
1966 for(const int *w2=begin;w2!=end;w2++)
1969 _loc.push_back(elt);
1970 zipGaussLocalizations();
1973 void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations()
1977 _discr_per_cell->decrRef();
1983 void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc)
1986 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !");
1987 int sz=(int)_loc.size();
1988 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
1990 _loc.resize(locId+1,gLoc);
1994 void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz)
1997 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !");
1998 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
1999 _loc.resize(newSz,gLoc);
2002 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId)
2004 checkLocalizationId(locId);
2008 int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const
2010 return (int)_loc.size();
2013 int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const
2015 if(!_discr_per_cell)
2016 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
2017 int locId=_discr_per_cell->begin()[cellId];
2019 throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !");
2023 int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
2025 std::set<int> ret=getGaussLocalizationIdsOfOneType(type);
2027 throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
2029 throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
2030 return *ret.begin();
2033 std::set<int> MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
2035 if(!_discr_per_cell)
2036 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
2039 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++)
2040 if((*iter).getType()==type)
2045 void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
2047 if(locId<0 || locId>=(int)_loc.size())
2048 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
2049 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
2050 const int *ptr=_discr_per_cell->getConstPointer();
2051 for(int i=0;i<nbOfTuples;i++)
2053 cellIds.push_back(i);
2056 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) const
2058 checkLocalizationId(locId);
2062 void MEDCouplingFieldDiscretizationGauss::checkLocalizationId(int locId) const
2064 if(locId<0 || locId>=(int)_loc.size())
2065 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
2068 int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const
2071 const int *start=_discr_per_cell->getConstPointer();
2072 for(const int *w=start;w!=start+cellId;w++)
2073 ret+=_loc[*w].getNumberOfGaussPt();
2078 * This method do the assumption that there is no orphan cell. If there is an exception is thrown.
2079 * This method makes the assumption too that '_discr_per_cell' is defined. If not an exception is thrown.
2080 * This method returns a newly created array with number of tuples equals to '_discr_per_cell->getNumberOfTuples' and number of components equal to 1.
2081 * The i_th tuple in returned array is the number of gauss point if the corresponding cell.
2083 DataArrayInt *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField() const
2085 if(!_discr_per_cell)
2086 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : no discretization array set !");
2087 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
2088 MCAuto<DataArrayInt> ret=DataArrayInt::New();
2089 const int *w=_discr_per_cell->begin();
2090 ret->alloc(nbOfTuples,1);
2091 int *valsToFill=ret->getPointer();
2092 int nbMaxOfLocId=(int)_loc.size();
2093 for(int i=0;i<nbOfTuples;i++,w++)
2094 if(*w!=DFT_INVALID_LOCID_VALUE)
2096 if(*w>=0 && *w<nbMaxOfLocId)
2097 valsToFill[i]=_loc[*w].getNumberOfGaussPt();
2100 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !";
2101 throw INTERP_KERNEL::Exception(oss.str().c_str());
2106 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " is detected as orphan !";
2107 throw INTERP_KERNEL::Exception(oss.str().c_str());
2112 void MEDCouplingFieldDiscretizationGauss::reprQuickOverview(std::ostream& stream) const
2114 stream << "Gauss points spatial discretization.";
2118 * This method makes the assumption that _discr_per_cell is set.
2119 * This method reduces as much as possible number size of _loc.
2120 * This method is useful when several set on same cells has been done and that some Gauss Localization are no more used.
2122 void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations()
2124 const int *start=_discr_per_cell->begin();
2125 int nbOfTuples=_discr_per_cell->getNumberOfTuples();
2126 INTERP_KERNEL::AutoPtr<int> tmp=new int[_loc.size()];
2127 std::fill((int *)tmp,(int *)tmp+_loc.size(),-2);
2128 for(const int *w=start;w!=start+nbOfTuples;w++)
2132 for(int i=0;i<(int)_loc.size();i++)
2135 if(fid==(int)_loc.size())
2138 int *start2=_discr_per_cell->getPointer();
2139 for(int *w2=start2;w2!=start2+nbOfTuples;w2++)
2142 std::vector<MEDCouplingGaussLocalization> tmpLoc;
2143 for(int i=0;i<(int)_loc.size();i++)
2145 tmpLoc.push_back(_loc[i]);
2149 void MEDCouplingFieldDiscretizationGauss::commonUnserialization(const std::vector<int>& tinyInfo)
2151 int nbOfLoc=tinyInfo[1];
2153 int dim=tinyInfo[2];
2156 delta=((int)tinyInfo.size()-3)/nbOfLoc;
2157 for(int i=0;i<nbOfLoc;i++)
2159 std::vector<int> tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta);
2160 MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp);
2161 _loc.push_back(elt);
2165 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE()
2169 TypeOfField MEDCouplingFieldDiscretizationGaussNE::getEnum() const
2175 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
2177 * \sa MEDCouplingFieldDiscretization::deepCopy.
2179 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() const
2181 return new MEDCouplingFieldDiscretizationGaussNE(*this);
2184 std::string MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const
2186 return std::string(REPR);
2189 const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const
2194 bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2198 reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined.";
2201 const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGaussNE *>(other);
2204 reason="Spatial discrtization of this is ON_GAUSS_NE, which is not the case of other.";
2209 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
2210 * The input code coherency is also checked regarding spatial discretization of \a this.
2211 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
2212 * 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).
2214 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
2216 if(code.size()%3!=0)
2217 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
2218 int nbOfSplit=(int)idsPerType.size();
2219 int nbOfTypes=(int)code.size()/3;
2221 for(int i=0;i<nbOfTypes;i++)
2223 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)code[3*i]));
2226 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 !";
2227 throw INTERP_KERNEL::Exception(oss.str().c_str());
2229 int nbOfEltInChunk=code[3*i+1];
2230 if(nbOfEltInChunk<0)
2231 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
2232 int pos=code[3*i+2];
2235 if(pos<0 || pos>=nbOfSplit)
2237 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
2238 throw INTERP_KERNEL::Exception(oss.str().c_str());
2240 const DataArrayInt *ids(idsPerType[pos]);
2241 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || (int)ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
2243 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
2244 throw INTERP_KERNEL::Exception(oss.str().c_str());
2247 ret+=nbOfEltInChunk*(int)cm.getNumberOfNodes();
2252 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const
2255 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !");
2257 int nbOfCells=mesh->getNumberOfCells();
2258 for(int i=0;i<nbOfCells;i++)
2260 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2261 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2263 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2264 ret+=cm.getNumberOfNodes();
2269 int MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
2272 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces : NULL input mesh !");
2273 return mesh->getNumberOfCells();
2276 DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const
2279 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !");
2280 int nbOfTuples=mesh->getNumberOfCells();
2281 DataArrayInt *ret=DataArrayInt::New();
2282 ret->alloc(nbOfTuples+1,1);
2283 int *retPtr=ret->getPointer();
2285 for(int i=0;i<nbOfTuples;i++)
2287 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2288 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2290 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2291 retPtr[i+1]=retPtr[i]+cm.getNumberOfNodes();
2296 void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
2297 const int *old2NewBg, bool check)
2300 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !");
2301 const int *array=old2NewBg;
2303 array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
2304 int nbOfCells=mesh->getNumberOfCells();
2305 int nbOfTuples=getNumberOfTuples(mesh);
2306 int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
2307 int *array3=new int[nbOfCells];//store for each cell in after renumbering the offset needed by each cell in new numbering.
2309 for(int i=1;i<nbOfCells;i++)
2311 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell((int)std::distance(array,std::find(array,array+nbOfCells,i-1)));
2312 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2313 array3[i]=array3[i-1]+cm.getNumberOfNodes();
2316 for(int i=0;i<nbOfCells;i++)
2318 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2319 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2320 for(int k=0;k<(int)cm.getNumberOfNodes();k++,j++)
2321 array2[j]=array3[array[i]]+k;
2324 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
2326 (*it)->renumberInPlace(array2);
2329 free(const_cast<int *>(array));
2332 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
2335 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !");
2336 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
2337 MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
2338 int nbOfTuples=getNumberOfTuples(umesh);
2339 int spaceDim=mesh->getSpaceDimension();
2340 ret->alloc(nbOfTuples,spaceDim);
2341 const double *coords=umesh->getCoords()->begin();
2342 const int *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
2343 const int *conn=umesh->getNodalConnectivity()->getConstPointer();
2344 int nbCells=umesh->getNumberOfCells();
2345 double *retPtr=ret->getPointer();
2346 for(int i=0;i<nbCells;i++,connI++)
2347 for(const int *w=conn+connI[0]+1;w!=conn+connI[1];w++)
2349 retPtr=std::copy(coords+(*w)*spaceDim,coords+((*w)+1)*spaceDim,retPtr);
2354 * Reimplemented from MEDCouplingFieldDiscretization::integral for performance reason. The default implementation is valid too for GAUSS_NE spatial discretization.
2356 void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const
2359 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !");
2360 int nbOfCompo=arr->getNumberOfComponents();
2361 std::fill(res,res+nbOfCompo,0.);
2363 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isWAbs);
2364 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2365 MCAuto<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2366 nbOfNodesPerCell->computeOffsetsFull();
2367 const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin();
2368 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2370 std::size_t wArrSz=-1;
2371 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2372 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2373 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2374 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2375 MCAuto<DataArrayInt> ids=mesh->giveCellsWithType(*it);
2376 MCAuto<DataArrayInt> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2377 const int *ptIds2=ids2->begin(),*ptIds=ids->begin();
2378 int nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2379 for(int i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++,ptIds2+=wArrSz)
2381 for(int k=0;k<nbOfCompo;k++)
2384 for(std::size_t j=0;j<wArrSz;j++)
2385 tmp+=arrPtr[nbOfCompo*ptIds2[j]+k]*wArr2[j];
2386 res[k]+=tmp*volPtr[*ptIds];
2392 const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2396 case INTERP_KERNEL::NORM_POINT1:
2397 lgth=(int)sizeof(FGP_POINT1)/sizeof(double);
2399 case INTERP_KERNEL::NORM_SEG2:
2400 lgth=(int)sizeof(FGP_SEG2)/sizeof(double);
2402 case INTERP_KERNEL::NORM_SEG3:
2403 lgth=(int)sizeof(FGP_SEG3)/sizeof(double);
2405 case INTERP_KERNEL::NORM_SEG4:
2406 lgth=(int)sizeof(FGP_SEG4)/sizeof(double);
2408 case INTERP_KERNEL::NORM_TRI3:
2409 lgth=(int)sizeof(FGP_TRI3)/sizeof(double);
2411 case INTERP_KERNEL::NORM_TRI6:
2412 lgth=(int)sizeof(FGP_TRI6)/sizeof(double);
2414 case INTERP_KERNEL::NORM_TRI7:
2415 lgth=(int)sizeof(FGP_TRI7)/sizeof(double);
2417 case INTERP_KERNEL::NORM_QUAD4:
2418 lgth=(int)sizeof(FGP_QUAD4)/sizeof(double);
2420 case INTERP_KERNEL::NORM_QUAD8:
2421 lgth=(int)sizeof(FGP_QUAD8)/sizeof(double);
2423 case INTERP_KERNEL::NORM_QUAD9:
2424 lgth=(int)sizeof(FGP_QUAD9)/sizeof(double);
2426 case INTERP_KERNEL::NORM_TETRA4:
2427 lgth=(int)sizeof(FGP_TETRA4)/sizeof(double);
2429 case INTERP_KERNEL::NORM_TETRA10:
2430 lgth=(int)sizeof(FGP_TETRA10)/sizeof(double);
2432 case INTERP_KERNEL::NORM_PENTA6:
2433 lgth=(int)sizeof(FGP_PENTA6)/sizeof(double);
2435 case INTERP_KERNEL::NORM_PENTA15:
2436 lgth=(int)sizeof(FGP_PENTA15)/sizeof(double);
2438 case INTERP_KERNEL::NORM_HEXA8:
2439 lgth=(int)sizeof(FGP_HEXA8)/sizeof(double);
2441 case INTERP_KERNEL::NORM_HEXA20:
2442 lgth=(int)sizeof(FGP_HEXA20)/sizeof(double);
2444 case INTERP_KERNEL::NORM_HEXA27:
2445 lgth=(int)sizeof(FGP_HEXA27)/sizeof(double);
2447 case INTERP_KERNEL::NORM_PYRA5:
2448 lgth=(int)sizeof(FGP_PYRA5)/sizeof(double);
2450 case INTERP_KERNEL::NORM_PYRA13:
2451 lgth=(int)sizeof(FGP_PYRA13)/sizeof(double);
2454 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 !");
2458 const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2462 case INTERP_KERNEL::NORM_POINT1:
2465 case INTERP_KERNEL::NORM_SEG2:
2466 lgth=(int)sizeof(REF_SEG2)/sizeof(double);
2468 case INTERP_KERNEL::NORM_SEG3:
2469 lgth=(int)sizeof(REF_SEG3)/sizeof(double);
2471 case INTERP_KERNEL::NORM_SEG4:
2472 lgth=(int)sizeof(REF_SEG4)/sizeof(double);
2474 case INTERP_KERNEL::NORM_TRI3:
2475 lgth=(int)sizeof(REF_TRI3)/sizeof(double);
2477 case INTERP_KERNEL::NORM_TRI6:
2478 lgth=(int)sizeof(REF_TRI6)/sizeof(double);
2480 case INTERP_KERNEL::NORM_TRI7:
2481 lgth=(int)sizeof(REF_TRI7)/sizeof(double);
2483 case INTERP_KERNEL::NORM_QUAD4:
2484 lgth=(int)sizeof(REF_QUAD4)/sizeof(double);
2486 case INTERP_KERNEL::NORM_QUAD8:
2487 lgth=(int)sizeof(REF_QUAD8)/sizeof(double);
2489 case INTERP_KERNEL::NORM_QUAD9:
2490 lgth=(int)sizeof(REF_QUAD9)/sizeof(double);
2492 case INTERP_KERNEL::NORM_TETRA4:
2493 lgth=(int)sizeof(REF_TETRA4)/sizeof(double);
2495 case INTERP_KERNEL::NORM_TETRA10:
2496 lgth=(int)sizeof(REF_TETRA10)/sizeof(double);
2498 case INTERP_KERNEL::NORM_PENTA6:
2499 lgth=(int)sizeof(REF_PENTA6)/sizeof(double);
2501 case INTERP_KERNEL::NORM_PENTA15:
2502 lgth=(int)sizeof(REF_PENTA15)/sizeof(double);
2504 case INTERP_KERNEL::NORM_HEXA8:
2505 lgth=(int)sizeof(REF_HEXA8)/sizeof(double);
2507 case INTERP_KERNEL::NORM_HEXA20:
2508 lgth=(int)sizeof(REF_HEXA20)/sizeof(double);
2510 case INTERP_KERNEL::NORM_HEXA27:
2511 lgth=(int)sizeof(REF_HEXA27)/sizeof(double);
2513 case INTERP_KERNEL::NORM_PYRA5:
2514 lgth=(int)sizeof(REF_PYRA5)/sizeof(double);
2516 case INTERP_KERNEL::NORM_PYRA13:
2517 lgth=(int)sizeof(REF_PYRA13)/sizeof(double);
2520 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 !");
2524 const double *MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2528 case INTERP_KERNEL::NORM_POINT1:
2533 case INTERP_KERNEL::NORM_SEG2:
2535 lgth=(int)sizeof(LOC_SEG2)/sizeof(double);
2538 case INTERP_KERNEL::NORM_SEG3:
2540 lgth=(int)sizeof(LOC_SEG3)/sizeof(double);
2543 case INTERP_KERNEL::NORM_SEG4:
2545 lgth=(int)sizeof(LOC_SEG4)/sizeof(double);
2548 case INTERP_KERNEL::NORM_TRI3:
2550 lgth=(int)sizeof(LOC_TRI3)/sizeof(double);
2553 case INTERP_KERNEL::NORM_TRI6:
2555 lgth=(int)sizeof(LOC_TRI6)/sizeof(double);
2558 case INTERP_KERNEL::NORM_TRI7:
2560 lgth=(int)sizeof(LOC_TRI7)/sizeof(double);
2563 case INTERP_KERNEL::NORM_QUAD4:
2565 lgth=(int)sizeof(LOC_QUAD4)/sizeof(double);
2568 case INTERP_KERNEL::NORM_QUAD8:
2570 lgth=(int)sizeof(LOC_QUAD8)/sizeof(double);
2573 case INTERP_KERNEL::NORM_QUAD9:
2575 lgth=(int)sizeof(LOC_QUAD9)/sizeof(double);
2578 case INTERP_KERNEL::NORM_TETRA4:
2580 lgth=(int)sizeof(LOC_TETRA4)/sizeof(double);
2583 case INTERP_KERNEL::NORM_TETRA10:
2585 lgth=(int)sizeof(LOC_TETRA10)/sizeof(double);
2588 case INTERP_KERNEL::NORM_PENTA6:
2590 lgth=(int)sizeof(LOC_PENTA6)/sizeof(double);
2593 case INTERP_KERNEL::NORM_PENTA15:
2595 lgth=(int)sizeof(LOC_PENTA15)/sizeof(double);
2598 case INTERP_KERNEL::NORM_HEXA8:
2600 lgth=(int)sizeof(LOC_HEXA8)/sizeof(double);
2603 case INTERP_KERNEL::NORM_HEXA20:
2605 lgth=(int)sizeof(LOC_HEXA20)/sizeof(double);
2608 case INTERP_KERNEL::NORM_HEXA27:
2610 lgth=(int)sizeof(LOC_HEXA27)/sizeof(double);
2613 case INTERP_KERNEL::NORM_PYRA5:
2615 lgth=(int)sizeof(LOC_PYRA5)/sizeof(double);
2618 case INTERP_KERNEL::NORM_PYRA13:
2620 lgth=(int)sizeof(LOC_PYRA13)/sizeof(double);
2624 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 !");
2628 void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd,
2629 DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const
2632 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds : NULL input mesh !");
2633 MCAuto<DataArrayInt> tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
2634 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
2636 tmp=tmp->buildUnique();
2637 MCAuto<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2638 nbOfNodesPerCell->computeOffsetsFull();
2639 nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
2642 void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const
2646 double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const
2649 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !");
2651 for(int i=0;i<cellId;i++)
2653 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2654 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2655 offset+=cm.getNumberOfNodes();
2657 return da->getIJ(offset+nodeIdInCell,compoId);
2660 void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
2662 std::size_t nbOfTuples(getNumberOfTuples(mesh));
2663 if(nbOfTuples!=da->getNumberOfTuples())
2665 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !";
2666 throw INTERP_KERNEL::Exception(oss.str().c_str());
2670 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2673 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getMeasureField : mesh instance specified is NULL !");
2674 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
2675 const double *volPtr=vol->getArray()->begin();
2676 MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_NE);
2679 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2680 MCAuto<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2681 int nbTuples=nbOfNodesPerCell->accumulate(0);
2682 nbOfNodesPerCell->computeOffsetsFull();
2683 MCAuto<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(nbTuples,1);
2685 double *arrPtr=arr->getPointer();
2686 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2688 std::size_t wArrSz=-1;
2689 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2690 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2691 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2692 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2693 MCAuto<DataArrayInt> ids=mesh->giveCellsWithType(*it);
2694 MCAuto<DataArrayInt> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2695 const int *ptIds2=ids2->begin(),*ptIds=ids->begin();
2696 int nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2697 for(int i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++)
2698 for(std::size_t j=0;j<wArrSz;j++,ptIds2++)
2699 arrPtr[*ptIds2]=wArr2[j]*volPtr[*ptIds];
2701 ret->synchronizeTimeWithSupport();
2705 void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2707 throw INTERP_KERNEL::Exception("Not implemented yet !");
2710 void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const
2712 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !");
2715 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const
2717 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented for Gauss NE !");
2720 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
2723 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !");
2724 MCAuto<DataArrayInt> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
2725 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
2731 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
2733 * \param [out] beginOut Valid only if \a di is NULL
2734 * \param [out] endOut Valid only if \a di is NULL
2735 * \param [out] stepOut Valid only if \a di is NULL
2736 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
2738 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
2740 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
2742 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
2743 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
2745 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : NULL input mesh !");
2746 int nbOfCells=mesh->getNumberOfCells();
2747 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
2748 const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #";
2749 for(int i=0;i<nbOfCells;i++)
2751 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2752 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2754 { std::ostringstream oss; oss << msg << i << " presence of dynamic cell (polygons and polyedrons) ! Not implemented !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
2755 int delta=cm.getNumberOfNodes();
2762 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
2768 * This method returns a tuple ids selection from cell ids selection [start;end).
2769 * This method is called by MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData to return parameter \b di.
2771 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
2774 DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const
2777 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds : null mesh !");
2778 MCAuto<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2779 nbOfNodesPerCell->computeOffsetsFull();
2780 MCAuto<DataArrayInt> sel=DataArrayInt::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1);
2781 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
2785 * No implementation needed !
2787 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
2791 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
2793 throw INTERP_KERNEL::Exception("Not implemented yet !");
2796 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationGaussNE::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
2798 return EasyAggregate<MEDCouplingFieldDiscretizationGaussNE>(fds);
2801 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
2803 throw INTERP_KERNEL::Exception("Not implemented yet !");
2806 void MEDCouplingFieldDiscretizationGaussNE::reprQuickOverview(std::ostream& stream) const
2808 stream << "Gauss points on nodes per element spatial discretization.";
2811 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other)
2815 TypeOfField MEDCouplingFieldDiscretizationKriging::getEnum() const
2820 const char *MEDCouplingFieldDiscretizationKriging::getRepr() const
2826 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
2828 * \sa MEDCouplingFieldDiscretization::deepCopy.
2830 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationKriging::clone() const
2832 return new MEDCouplingFieldDiscretizationKriging;
2835 std::string MEDCouplingFieldDiscretizationKriging::getStringRepr() const
2837 return std::string(REPR);
2840 void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureOfField nat) const
2842 if(nat!=IntensiveMaximum)
2843 throw INTERP_KERNEL::Exception("Invalid nature for Kriging field : expected IntensiveMaximum !");
2846 bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2850 reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined.";
2853 const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationKriging *>(other);
2856 reason="Spatial discrtization of this is ON_NODES_KR, which is not the case of other.";
2860 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationKriging::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2863 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getMeasureField : mesh instance specified is NULL !");
2864 throw INTERP_KERNEL::Exception("getMeasureField on FieldDiscretizationKriging : not implemented yet !");
2867 void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2869 MCAuto<DataArrayDouble> res2=MEDCouplingFieldDiscretizationKriging::getValueOnMulti(arr,mesh,loc,1);
2870 std::copy(res2->begin(),res2->end(),res);
2873 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const
2875 if(!arr || !arr->isAllocated())
2876 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array is null or not allocated !");
2877 std::size_t nbOfRows(getNumberOfMeshPlaces(mesh));
2878 if(arr->getNumberOfTuples()!=nbOfRows)
2880 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array does not have correct number of tuples ! Excepted " << nbOfRows << " having " << arr->getNumberOfTuples() << " !";
2881 throw INTERP_KERNEL::Exception(oss.str().c_str());
2883 int nbCols(-1),nbCompo(arr->getNumberOfComponents());
2884 MCAuto<DataArrayDouble> m(computeEvaluationMatrixOnGivenPts(mesh,loc,nbOfTargetPoints,nbCols));
2885 MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
2886 ret->alloc(nbOfTargetPoints,nbCompo);
2887 INTERP_KERNEL::matrixProduct(m->begin(),nbOfTargetPoints,nbCols,arr->begin(),nbOfRows,nbCompo,ret->getPointer());
2891 void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const
2893 stream << "Kriging spatial discretization.";
2896 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationKriging::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
2898 return EasyAggregate<MEDCouplingFieldDiscretizationKriging>(fds);
2902 * Returns the matrix of size nbRows = \a nbOfTargetPoints and \a nbCols = \a nbCols. This matrix is useful if
2904 * \return the new result matrix to be deallocated by the caller.
2906 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts(const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints, int& nbCols) const
2908 int isDrift(-1),nbRows(-1);
2909 MCAuto<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2911 MCAuto<DataArrayDouble> coords=getLocalizationOfDiscValues(mesh);
2912 int nbOfPts(coords->getNumberOfTuples()),dimension(coords->getNumberOfComponents());
2913 MCAuto<DataArrayDouble> locArr=DataArrayDouble::New();
2914 locArr->useArray(loc,false,DeallocType::CPP_DEALLOC,nbOfTargetPoints,dimension);
2917 MCAuto<DataArrayDouble> matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr);
2918 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfTargetPoints*nbOfPts,matrix2->getPointer());
2920 MCAuto<DataArrayDouble> matrix3=DataArrayDouble::New();
2921 matrix3->alloc(nbOfTargetPoints*nbRows,1);
2922 double *work=matrix3->getPointer();
2923 const double *workCst(matrix2->begin()),*workCst2(loc);
2924 for(int i=0;i<nbOfTargetPoints;i++,workCst+=nbOfPts,workCst2+=isDrift-1)
2926 for(int j=0;j<nbOfPts;j++)
2927 work[i*nbRows+j]=workCst[j];
2928 work[i*nbRows+nbOfPts]=1.0;
2929 for(int j=0;j<isDrift-1;j++)
2930 work[i*nbRows+(nbOfPts+1+j)]=workCst2[j];
2932 MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
2933 ret->alloc(nbOfTargetPoints,nbRows);
2934 INTERP_KERNEL::matrixProduct(matrix3->begin(),nbOfTargetPoints,nbRows,matrixInv->begin(),nbRows,nbRows,ret->getPointer());
2935 MCAuto<DataArrayDouble> ret2(DataArrayDouble::New());
2936 ret2->alloc(nbOfTargetPoints*nbOfPts,1);
2937 workCst=ret->begin(); work=ret2->getPointer();
2938 for(int i=0;i<nbOfTargetPoints;i++,workCst+=nbRows)
2939 work=std::copy(workCst,workCst+nbOfPts,work);
2944 * 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
2945 * when multiplied by the vector of values attached to each point.
2947 * \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.
2948 * \param [out] matSz the size of returned square matrix
2949 * \return the new result matrix to be deallocated by the caller.
2952 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeInverseMatrix(const MEDCouplingMesh *mesh, int& isDrift, int& matSz) const
2954 MCAuto<DataArrayDouble> matrixWithDrift(computeMatrix(mesh,isDrift,matSz));
2955 MCAuto<DataArrayDouble> matrixInv(DataArrayDouble::New());
2956 matrixInv->alloc(matSz*matSz,1);
2957 INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),matSz,matrixInv->getPointer());
2958 return matrixInv.retn();
2962 * This method computes the kriging matrix.
2963 * \return the new result matrix to be deallocated by the caller.
2964 * \sa computeInverseMatrix
2966 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeMatrix(const MEDCouplingMesh *mesh, int& isDrift, int& matSz) const
2969 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeMatrix : NULL input mesh !");
2970 MCAuto<DataArrayDouble> coords(getLocalizationOfDiscValues(mesh));
2971 int nbOfPts(coords->getNumberOfTuples());
2972 MCAuto<DataArrayDouble> matrix(coords->buildEuclidianDistanceDenseMatrix());
2973 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer());
2975 MCAuto<DataArrayDouble> matrixWithDrift(performDrift(matrix,coords,isDrift));
2976 matSz=nbOfPts+isDrift;
2977 return matrixWithDrift.retn();
2981 * 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
2982 * number of tuples should be equal to the number of representing points in \a mesh.
2984 * \param [in] mesh is the sources of nodes on which kriging will be done regarding the parameters and the value of \c this->getSpaceDimension()
2985 * \param [in] arr input field DataArrayDouble whose number of tuples must be equal to the number of nodes in \a mesh
2986 * \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.
2987 * Whatever the value of \a isDrift the number of tuples of returned DataArrayDouble will be equal to \c arr->getNumberOfTuples() + \a isDrift.
2988 * \return a newly allocated array containing coefficients including or not drift coefficient at the end depending the value of \a isDrift parameter.
2990 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const
2993 MCAuto<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2994 MCAuto<DataArrayDouble> KnewiK(DataArrayDouble::New());
2995 KnewiK->alloc(nbRows*1,1);
2996 MCAuto<DataArrayDouble> arr2(PerformDriftOfVec(arr,isDrift));
2997 INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbRows,nbRows,arr2->getConstPointer(),arr2->getNumberOfTuples(),1,KnewiK->getPointer());
2998 return KnewiK.retn();
3002 * 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.
3004 * \param [in] spaceDimension space dimension of the input mesh on which the Kriging has to be performed
3005 * \param [in] nbOfElems is the result of the product of nb of rows and the nb of columns of matrix \a matrixPtr
3006 * \param [in,out] matrixPtr is the dense matrix whose on each values the operation will be applied
3008 void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimension, int nbOfElems, double *matrixPtr) const
3010 switch(spaceDimension)
3014 OperateOnDenseMatrixH3(nbOfElems,matrixPtr);
3019 OperateOnDenseMatrixH2Ln(nbOfElems,matrixPtr);
3024 //nothing here : it is not a bug g(h)=h with spaceDim 3.
3028 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix : only dimension 1, 2 and 3 implemented !");
3032 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH3(int nbOfElems, double *matrixPtr)
3034 for(int i=0;i<nbOfElems;i++)
3036 double val=matrixPtr[i];
3037 matrixPtr[i]=val*val*val;
3041 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH2Ln(int nbOfElems, double *matrixPtr)
3043 for(int i=0;i<nbOfElems;i++)
3045 double val=matrixPtr[i];
3047 matrixPtr[i]=val*val*log(val);
3052 * Performs a drift to the rectangular input matrix \a matr.
3053 * This method generate a dense matrix starting from an input dense matrix \a matr and input array \a arr.
3054 * \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
3055 * \param [in] arr The array of coords to be appended in the input dense matrix \a matr. Typically arr is an array of coordinates.
3056 * \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.
3059 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftRect(const DataArrayDouble *matr, const DataArrayDouble *arr, int& delta)
3061 if(!matr || !matr->isAllocated() || matr->getNumberOfComponents()!=1)
3062 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input dense matrix ! Must be allocated not NULL and with exactly one component !");
3063 if(!arr || !arr->isAllocated())
3064 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input array of coordiantes ! Must be allocated and not NULL !");
3065 int spaceDimension(arr->getNumberOfComponents()),nbOfPts(arr->getNumberOfTuples()),nbOfEltInMatrx(matr->getNumberOfTuples());
3066 delta=spaceDimension+1;
3067 int nbOfCols(nbOfEltInMatrx/nbOfPts);
3068 if(nbOfEltInMatrx%nbOfPts!=0)
3069 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 !");
3070 MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfPts*(nbOfCols+delta));
3071 double *retPtr(ret->getPointer());
3072 const double *mPtr(matr->begin()),*aPtr(arr->begin());
3073 for(int i=0;i<nbOfPts;i++,aPtr+=spaceDimension,mPtr+=nbOfCols)
3075 retPtr=std::copy(mPtr,mPtr+nbOfCols,retPtr);
3077 retPtr=std::copy(aPtr,aPtr+spaceDimension,retPtr);
3083 * \return a newly allocated array having \a isDrift more tuples than \a arr.
3084 * \sa computeVectorOfCoefficients
3086 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec(const DataArrayDouble *arr, int isDrift)
3088 if(!arr || !arr->isAllocated() || arr->getNumberOfComponents()!=1)
3089 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : input array must be not NULL allocated and with one component !");
3091 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : isDrift parameter must be >=0 !");
3092 MCAuto<DataArrayDouble> arr2(DataArrayDouble::New());
3093 arr2->alloc((arr->getNumberOfTuples()+isDrift)*1,1);
3094 double *work(std::copy(arr->begin(),arr->end(),arr2->getPointer()));
3095 std::fill(work,work+isDrift,0.);
3100 * Starting from a square matrix \a matr, this method returns a newly allocated dense square matrix whose \a matr is included in returned matrix
3101 * in the top left corner, and in the remaining returned matrix the parameters to take into account about the kriging drift.
3102 * For the moment only linear srift is implemented.
3104 * \param [in] arr the position of points were input mesh geometry is considered for Kriging
3105 * \param [in] matr input matrix whose drift part will be added
3106 * \param [out] delta the difference between the size of the output matrix and the input matrix \a matr.
3107 * \return a newly allocated matrix bigger than input matrix \a matr.
3108 * \sa MEDCouplingFieldDiscretizationKriging::PerformDriftRect
3110 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataArrayDouble *matr, const DataArrayDouble *arr, int& delta) const
3112 std::size_t spaceDimension(arr->getNumberOfComponents());
3113 delta=spaceDimension+1;
3114 std::size_t szOfMatrix(arr->getNumberOfTuples());
3115 if(szOfMatrix*szOfMatrix!=matr->getNumberOfTuples())
3116 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::performDrift : invalid size");
3117 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
3118 ret->alloc((szOfMatrix+delta)*(szOfMatrix+delta),1);
3119 const double *srcWork=matr->getConstPointer();
3120 const double *srcWork2=arr->getConstPointer();
3121 double *destWork=ret->getPointer();
3122 for(std::size_t i=0;i<szOfMatrix;i++)
3124 destWork=std::copy(srcWork,srcWork+szOfMatrix,destWork);
3125 srcWork+=szOfMatrix;
3127 destWork=std::copy(srcWork2,srcWork2+spaceDimension,destWork);
3128 srcWork2+=spaceDimension;
3130 std::fill(destWork,destWork+szOfMatrix,1.); destWork+=szOfMatrix;
3131 std::fill(destWork,destWork+spaceDimension+1,0.); destWork+=spaceDimension+1;
3132 MCAuto<DataArrayDouble> arrNoI=arr->toNoInterlace();
3133 srcWork2=arrNoI->getConstPointer();
3134 for(std::size_t i=0;i<spaceDimension;i++)
3136 destWork=std::copy(srcWork2,srcWork2+szOfMatrix,destWork);
3137 srcWork2+=szOfMatrix;
3138 std::fill(destWork,destWork+spaceDimension+1,0.);
3139 destWork+=spaceDimension+1;