1 // Copyright (C) 2007-2019 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 mcIdType 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 mcIdType *startCellIds, const mcIdType *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(mcIdType beginCellIds, mcIdType endCellIds, mcIdType 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 std::size_t nbOfCompo=arr->getNumberOfComponents();
239 mcIdType 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(mcIdType i=0;i<nbOfElems;i++)
246 double v=fabs(volPtr[i]);
247 for(std::size_t 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 std::size_t nbOfCompo=arr->getNumberOfComponents();
263 mcIdType 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(mcIdType i=0;i<nbOfElems;i++)
270 double v=fabs(volPtr[i]);
271 for(std::size_t 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());
292 mcIdType nbOfElems(getNumberOfTuples(mesh));
293 if(nbOfElems!=arr->getNumberOfTuples())
295 std::ostringstream oss; oss << "MEDCouplingFieldDiscretization::integral : field is not correct ! number of tuples in array is " << arr->getNumberOfTuples();
296 oss << " whereas number of tuples expected is " << nbOfElems << " !";
297 throw INTERP_KERNEL::Exception(oss.str().c_str());
299 std::fill(res,res+nbOfCompo,0.);
300 const double *arrPtr(arr->begin()),*volPtr(vol->getArray()->begin());
301 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfCompo];
302 for(mcIdType i=0;i<nbOfElems;i++)
304 std::transform(arrPtr+i*nbOfCompo,arrPtr+(i+1)*nbOfCompo,(double *)tmp,std::bind2nd(std::multiplies<double>(),volPtr[i]));
305 std::transform((double *)tmp,(double *)tmp+nbOfCompo,res,res,std::plus<double>());
310 * This method is strictly equivalent to MEDCouplingFieldDiscretization::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
312 * \param [out] beginOut Valid only if \a di is NULL
313 * \param [out] endOut Valid only if \a di is NULL
314 * \param [out] stepOut Valid only if \a di is NULL
315 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
317 * \sa MEDCouplingFieldDiscretization::buildSubMeshData
319 MEDCouplingMesh *MEDCouplingFieldDiscretization::buildSubMeshDataRange(const MEDCouplingMesh *mesh, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
321 MCAuto<DataArrayIdType> da=DataArrayIdType::Range(beginCellIds,endCellIds,stepCellIds);
322 return buildSubMeshData(mesh,da->begin(),da->end(),di);
325 void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayIdType *& arr) const
333 void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
340 void MEDCouplingFieldDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
344 void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector<mcIdType>& tinyInfo, DataArrayIdType *& arr)
352 void MEDCouplingFieldDiscretization::checkForUnserialization(const std::vector<mcIdType>& tinyInfo, const DataArrayIdType *arr)
359 void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector<double>& tinyInfo)
364 * This method is typically the first step of renumbering. The implementation is empty it is not a bug only gauss is impacted
365 * virtually by this method.
367 void MEDCouplingFieldDiscretization::renumberCells(const mcIdType *old2NewBg, bool check)
371 double MEDCouplingFieldDiscretization::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, mcIdType cellId, mcIdType nodeIdInCell, int compoId) const
373 throw INTERP_KERNEL::Exception("getIJK Invalid ! only for GaussPoint and GaussNE discretizations !");
376 void MEDCouplingFieldDiscretization::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
377 const std::vector<double>& gsCoo, const std::vector<double>& wg)
379 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
382 void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const mcIdType *begin, const mcIdType *end, const std::vector<double>& refCoo,
383 const std::vector<double>& gsCoo, const std::vector<double>& wg)
385 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
388 void MEDCouplingFieldDiscretization::clearGaussLocalizations()
390 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
393 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(mcIdType locId)
395 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
398 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(mcIdType locId) const
400 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
403 mcIdType MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const
405 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
408 mcIdType MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(mcIdType cellId) const
410 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
413 mcIdType MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
415 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
418 std::set<mcIdType> MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
420 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
423 void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(mcIdType locId, std::vector<mcIdType>& cellIds) const
425 throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
428 void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const mcIdType *old2NewPtr, mcIdType newNbOfEntity, DataArrayDouble *arr, const std::string& msg)
431 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !");
432 mcIdType oldNbOfElems=arr->getNumberOfTuples();
433 std::size_t nbOfComp=arr->getNumberOfComponents();
434 mcIdType newNbOfTuples=newNbOfEntity;
435 MCAuto<DataArrayDouble> arrCpy=arr->deepCopy();
436 const double *ptSrc=arrCpy->getConstPointer();
437 arr->reAlloc(newNbOfTuples);
438 double *ptToFill=arr->getPointer();
439 std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits<double>::max());
440 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfComp];
441 for(mcIdType i=0;i<oldNbOfElems;i++)
443 mcIdType newNb=old2NewPtr[i];
444 if(newNb>=0)//if newNb<0 the node is considered as out.
446 if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to<double>(),std::numeric_limits<double>::max()))
447 ==ptToFill+(newNb+1)*nbOfComp)
448 std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp);
451 std::transform(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp,(double *)tmp,std::minus<double>());
452 std::transform((double *)tmp,((double *)tmp)+nbOfComp,(double *)tmp,std::ptr_fun<double,double>(fabs));
453 //if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
454 if(*std::max_element((double *)tmp,((double *)tmp)+nbOfComp)>eps)
456 std::ostringstream oss;
457 oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
458 << " have been merged and " << msg << " field on them are different !";
459 throw INTERP_KERNEL::Exception(oss.str().c_str());
466 void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const mcIdType *new2OldPtr, mcIdType new2OldSz, DataArrayDouble *arr, const std::string& msg)
468 std::size_t nbOfComp=arr->getNumberOfComponents();
469 MCAuto<DataArrayDouble> arrCpy=arr->deepCopy();
470 const double *ptSrc=arrCpy->getConstPointer();
471 arr->reAlloc(new2OldSz);
472 double *ptToFill=arr->getPointer();
473 for(mcIdType i=0;i<new2OldSz;i++)
475 mcIdType oldNb=new2OldPtr[i];
476 std::copy(ptSrc+oldNb*nbOfComp,ptSrc+(oldNb+1)*nbOfComp,ptToFill+i*nbOfComp);
480 template<class FIELD_DISC>
481 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretization::EasyAggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds)
484 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : input array is empty");
485 for(const MEDCouplingFieldDiscretization * it : fds)
487 const FIELD_DISC *itc(dynamic_cast<const FIELD_DISC *>(it));
489 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : same field discretization expected for all input discretizations !");
491 return fds[0]->clone();
494 MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization()
498 TypeOfField MEDCouplingFieldDiscretizationP0::getEnum() const
504 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
506 * \sa MEDCouplingFieldDiscretization::deepCopy.
508 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP0::clone() const
510 return new MEDCouplingFieldDiscretizationP0;
513 std::string MEDCouplingFieldDiscretizationP0::getStringRepr() const
515 return std::string(REPR);
518 const char *MEDCouplingFieldDiscretizationP0::getRepr() const
523 bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
527 reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined.";
530 const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP0 *>(other);
533 reason="Spatial discrtization of this is ON_CELLS, which is not the case of other.";
537 mcIdType MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const
540 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !");
541 return mesh->getNumberOfCells();
545 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
546 * The input code coherency is also checked regarding spatial discretization of \a this.
547 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
548 * 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).
550 mcIdType MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const
553 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
554 mcIdType nbOfSplit=ToIdType(idsPerType.size());
555 mcIdType nbOfTypes=ToIdType(code.size()/3);
557 for(mcIdType i=0;i<nbOfTypes;i++)
559 mcIdType nbOfEltInChunk=code[3*i+1];
561 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
562 mcIdType pos=code[3*i+2];
565 if(pos<0 || pos>=nbOfSplit)
567 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
568 throw INTERP_KERNEL::Exception(oss.str().c_str());
570 const DataArrayIdType *ids(idsPerType[pos]);
571 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
573 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
574 throw INTERP_KERNEL::Exception(oss.str().c_str());
582 mcIdType MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
585 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !");
586 return mesh->getNumberOfCells();
589 DataArrayIdType *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const
592 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !");
593 std::size_t nbOfTuples=mesh->getNumberOfCells();
594 DataArrayIdType *ret=DataArrayIdType::New();
595 ret->alloc(nbOfTuples+1,1);
600 void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
601 const mcIdType *old2NewBg, bool check)
604 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !");
605 const mcIdType *array=old2NewBg;
607 array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
608 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
611 (*it)->renumberInPlace(array);
614 free(const_cast<mcIdType *>(array));
617 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
620 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !");
621 return mesh->computeCellCenterOfMass();
624 void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd,
625 DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const
628 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds : NULL input mesh !");
629 MCAuto<DataArrayIdType> tmp=DataArrayIdType::New();
630 tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1);
631 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
632 MCAuto<DataArrayIdType> tmp2(tmp->deepCopy());
633 cellRestriction=tmp.retn();
634 trueTupleRestriction=tmp2.retn();
637 void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const
639 stream << "P0 spatial discretization.";
642 void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const
646 void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
649 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh or DataArray !");
650 if(mesh->getNumberOfCells()!=da->getNumberOfTuples())
652 std::ostringstream message;
653 message << "Field on cells invalid because there are " << mesh->getNumberOfCells();
654 message << " cells in mesh and " << da->getNumberOfTuples() << " tuples in field !";
655 throw INTERP_KERNEL::Exception(message.str().c_str());
659 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
662 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getMeasureField : mesh instance specified is NULL !");
663 return mesh->getMeasureField(isAbs);
666 void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
669 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !");
670 mcIdType id=mesh->getCellContainingPoint(loc,_precision);
672 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !");
673 arr->getTuple(id,res);
676 void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const
678 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
680 throw INTERP_KERNEL::Exception("P0::getValueOnPos is only accessible for structured meshes !");
681 mcIdType id=meshC->getCellIdFromPos(i,j,k);
682 arr->getTuple(id,res);
685 DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const
688 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !");
689 MCAuto<DataArrayIdType> eltsArr,eltsIndexArr;
690 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
691 const mcIdType *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
692 int spaceDim=mesh->getSpaceDimension();
693 std::size_t nbOfComponents=arr->getNumberOfComponents();
694 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
695 ret->alloc(nbOfPoints,nbOfComponents);
696 double *ptToFill=ret->getPointer();
697 for(mcIdType i=0;i<nbOfPoints;i++,ptToFill+=nbOfComponents)
698 if(eltsIndex[i+1]-eltsIndex[i]>=1)
699 arr->getTuple(elts[eltsIndex[i]],ptToFill);
702 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
703 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
704 oss << ") detected outside mesh : unable to apply P0::getValueOnMulti ! ";
705 throw INTERP_KERNEL::Exception(oss.str().c_str());
711 * Nothing to do. It's not a bug.
713 void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const mcIdType *, mcIdType newNbOfNodes, DataArrayDouble *) const
717 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const
719 RenumberEntitiesFromO2NArr(epsOnVals,old2New,newSz,arr,"Cell");
722 void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const
724 RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell");
728 * This method returns a tuple ids selection from cell ids selection [start;end).
729 * This method is called by MEDCouplingFieldDiscretizationP0::buildSubMeshData to return parameter \b di.
730 * Here for P0 it's very simple !
732 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
735 DataArrayIdType *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const
737 MCAuto<DataArrayIdType> ret=DataArrayIdType::New();
738 ret->alloc(std::distance(startCellIds,endCellIds),1);
739 std::copy(startCellIds,endCellIds,ret->getPointer());
744 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
745 * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh.
746 * Example : The first cell id of returned mesh has the (*di)[0] id in 'mesh'
748 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange
750 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const
753 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !");
754 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
755 MCAuto<DataArrayIdType> diSafe=DataArrayIdType::New();
756 diSafe->alloc(std::distance(start,end),1);
757 std::copy(start,end,diSafe->getPointer());
763 * This method is strictly equivalent to MEDCouplingFieldDiscretizationP0::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
765 * \param [out] beginOut Valid only if \a di is NULL
766 * \param [out] endOut Valid only if \a di is NULL
767 * \param [out] stepOut Valid only if \a di is NULL
768 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
770 * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshData
772 MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange(const MEDCouplingMesh *mesh, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
775 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !");
776 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
777 di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds;
781 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationP0::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
783 return EasyAggregate<MEDCouplingFieldDiscretizationP0>(fds);
786 mcIdType MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const
789 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !");
790 return mesh->getNumberOfNodes();
794 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
795 * The input code coherency is also checked regarding spatial discretization of \a this.
796 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
797 * 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).
799 mcIdType MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const
802 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
803 mcIdType nbOfSplit=ToIdType(idsPerType.size());
804 mcIdType nbOfTypes=ToIdType(code.size()/3);
806 for(mcIdType i=0;i<nbOfTypes;i++)
808 mcIdType nbOfEltInChunk=code[3*i+1];
810 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
811 mcIdType pos=code[3*i+2];
814 if(pos<0 || pos>=nbOfSplit)
816 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
817 throw INTERP_KERNEL::Exception(oss.str().c_str());
819 const DataArrayIdType *ids(idsPerType[pos]);
820 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
822 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
823 throw INTERP_KERNEL::Exception(oss.str().c_str());
831 mcIdType MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
834 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !");
835 return mesh->getNumberOfNodes();
839 * Nothing to do here.
841 void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector<DataArray *>& arrays,
842 const mcIdType *old2NewBg, bool check)
846 DataArrayIdType *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const
849 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !");
850 mcIdType nbOfTuples=mesh->getNumberOfNodes();
851 DataArrayIdType *ret=DataArrayIdType::New();
852 ret->alloc(nbOfTuples+1,1);
857 DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
860 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !");
861 return mesh->getCoordinatesAndOwner();
864 void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd,
865 DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const
868 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : NULL input mesh !");
869 MCAuto<DataArrayIdType> ret1=mesh->getCellIdsFullyIncludedInNodeIds(tupleIdsBg,tupleIdsEnd);
870 const MEDCouplingUMesh *meshc=dynamic_cast<const MEDCouplingUMesh *>(mesh);
872 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : trying to subpart field on nodes by node ids ! Your mesh has to be unstructured !");
873 MCAuto<MEDCouplingUMesh> meshPart=static_cast<MEDCouplingUMesh *>(meshc->buildPartOfMySelf(ret1->begin(),ret1->end(),true));
874 MCAuto<DataArrayIdType> ret2=meshPart->computeFetchedNodeIds();
875 cellRestriction=ret1.retn();
876 trueTupleRestriction=ret2.retn();
879 void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
882 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh or DataArray !");
883 if(mesh->getNumberOfNodes()!=da->getNumberOfTuples())
885 std::ostringstream message;
886 message << "Field on nodes invalid because there are " << mesh->getNumberOfNodes();
887 message << " nodes in mesh and " << da->getNumberOfTuples() << " tuples in field !";
888 throw INTERP_KERNEL::Exception(message.str().c_str());
893 * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
894 * @param di is an array returned that specifies entity ids (here nodes ids) in mesh 'mesh' of entity in returned submesh.
895 * Example : The first node id of returned mesh has the (*di)[0] id in 'mesh'
897 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const
900 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !");
901 DataArrayIdType *diTmp=0;
902 MCAuto<MEDCouplingMesh> ret=mesh->buildPartAndReduceNodes(start,end,diTmp);
903 MCAuto<DataArrayIdType> diTmpSafe(diTmp);
904 MCAuto<DataArrayIdType> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
910 * This method is strictly equivalent to MEDCouplingFieldDiscretizationNodes::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
912 * \param [out] beginOut Valid only if \a di is NULL
913 * \param [out] endOut Valid only if \a di is NULL
914 * \param [out] stepOut Valid only if \a di is NULL
915 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
917 * \sa MEDCouplingFieldDiscretizationNodes::buildSubMeshData
919 MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(const MEDCouplingMesh *mesh, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
922 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !");
923 DataArrayIdType *diTmp=0;
924 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp);
927 MCAuto<DataArrayIdType> diTmpSafe(diTmp);
928 MCAuto<DataArrayIdType> di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes());
935 * This method returns a tuple ids selection from cell ids selection [start;end).
936 * This method is called by MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData to return parameter \b di.
937 * Here for P1 only nodes fetched by submesh of mesh[startCellIds:endCellIds) is returned !
939 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
942 DataArrayIdType *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const
945 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !");
946 const MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();
947 MCAuto<MEDCouplingUMesh> umesh2=static_cast<MEDCouplingUMesh *>(umesh->buildPartOfMySelf(startCellIds,endCellIds,true));
948 return umesh2->computeFetchedNodeIds();
951 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const mcIdType *old2NewPtr, mcIdType newNbOfNodes, DataArrayDouble *arr) const
953 RenumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,newNbOfNodes,arr,"Node");
957 * Nothing to do it's not a bug.
959 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const
964 * Nothing to do it's not a bug.
966 void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const
970 void MEDCouplingFieldDiscretizationOnNodes::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const
972 const MEDCouplingCMesh *meshC=dynamic_cast<const MEDCouplingCMesh *>(mesh);
974 throw INTERP_KERNEL::Exception("OnNodes::getValueOnPos(i,j,k) is only accessible for structured meshes !");
975 mcIdType id=meshC->getNodeIdFromPos(i,j,k);
976 arr->getTuple(id,res);
979 TypeOfField MEDCouplingFieldDiscretizationP1::getEnum() const
985 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
987 * \sa MEDCouplingFieldDiscretization::deepCopy.
989 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP1::clone() const
991 return new MEDCouplingFieldDiscretizationP1;
994 std::string MEDCouplingFieldDiscretizationP1::getStringRepr() const
996 return std::string(REPR);
999 const char *MEDCouplingFieldDiscretizationP1::getRepr() const
1004 bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1008 reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined.";
1011 const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP1 *>(other);
1014 reason="Spatial discrtization of this is ON_NODES, which is not the case of other.";
1018 void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const
1020 if(nat!=IntensiveMaximum)
1021 throw INTERP_KERNEL::Exception("Invalid nature for P1 field : expected IntensiveMaximum !");
1024 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
1027 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getMeasureField : mesh instance specified is NULL !");
1028 return mesh->getMeasureFieldOnNode(isAbs);
1031 void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
1034 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !");
1035 mcIdType id=mesh->getCellContainingPoint(loc,_precision);
1037 throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !");
1038 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(id);
1039 if(type!=INTERP_KERNEL::NORM_SEG2 && type!=INTERP_KERNEL::NORM_TRI3 && type!=INTERP_KERNEL::NORM_TETRA4)
1040 throw INTERP_KERNEL::Exception("P1 getValueOn is not specified for not simplex cells !");
1041 getValueInCell(mesh,id,arr,loc,res);
1045 * This method localizes a point defined by 'loc' in a cell with id 'cellId' into mesh 'mesh'.
1046 * The result is put into res expected to be of size at least arr->getNumberOfComponents()
1048 void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, mcIdType cellId, const DataArrayDouble *arr, const double *loc, double *res) const
1051 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !");
1052 std::vector<mcIdType> conn;
1053 std::vector<double> coo;
1054 mesh->getNodeIdsOfCell(cellId,conn);
1055 for(std::vector<mcIdType>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
1056 mesh->getCoordinatesOfNode(*iter,coo);
1057 int spaceDim=mesh->getSpaceDimension();
1058 std::size_t nbOfNodes=conn.size();
1059 std::vector<const double *> vec(nbOfNodes);
1060 for(std::size_t i=0;i<nbOfNodes;i++)
1061 vec[i]=&coo[i*spaceDim];
1062 INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfNodes];
1063 INTERP_KERNEL::NormalizedCellType ct(mesh->getTypeOfCell(cellId));
1064 INTERP_KERNEL::barycentric_coords(ct,vec,loc,tmp);
1065 std::size_t sz=arr->getNumberOfComponents();
1066 INTERP_KERNEL::AutoPtr<double> tmp2=new double[sz];
1067 std::fill(res,res+sz,0.);
1068 for(std::size_t i=0;i<nbOfNodes;i++)
1070 arr->getTuple(conn[i],(double *)tmp2);
1071 std::transform((double *)tmp2,((double *)tmp2)+sz,(double *)tmp2,std::bind2nd(std::multiplies<double>(),tmp[i]));
1072 std::transform(res,res+sz,(double *)tmp2,res,std::plus<double>());
1076 DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const
1079 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !");
1080 MCAuto<DataArrayIdType> eltsArr,eltsIndexArr;
1081 mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr);
1082 const mcIdType *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin());
1083 int spaceDim=mesh->getSpaceDimension();
1084 std::size_t nbOfComponents=arr->getNumberOfComponents();
1085 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
1086 ret->alloc(nbOfPoints,nbOfComponents);
1087 double *ptToFill=ret->getPointer();
1088 for(mcIdType i=0;i<nbOfPoints;i++)
1089 if(eltsIndex[i+1]-eltsIndex[i]>=1)
1090 getValueInCell(mesh,elts[eltsIndex[i]],arr,loc+i*spaceDim,ptToFill+i*nbOfComponents);
1093 std::ostringstream oss; oss << "Point #" << i << " with coordinates : (";
1094 std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator<double>(oss,", "));
1095 oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! ";
1096 throw INTERP_KERNEL::Exception(oss.str().c_str());
1101 void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const
1103 stream << "P1 spatial discretization.";
1106 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationP1::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
1108 return EasyAggregate<MEDCouplingFieldDiscretizationP1>(fds);
1111 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0)
1115 MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell()
1118 _discr_per_cell->decrRef();
1122 * This constructor deep copies MEDCoupling::DataArrayIdType instance from other (if any).
1124 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const mcIdType *startCellIds, const mcIdType *endCellIds):_discr_per_cell(0)
1126 DataArrayIdType *arr=other._discr_per_cell;
1129 if(startCellIds==0 && endCellIds==0)
1130 _discr_per_cell=arr->deepCopy();
1132 _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds);
1136 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds):_discr_per_cell(0)
1138 DataArrayIdType *arr=other._discr_per_cell;
1141 _discr_per_cell=arr->selectByTupleIdSafeSlice(beginCellIds,endCellIds,stepCellIds);
1145 MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(DataArrayIdType *dpc):_discr_per_cell(dpc)
1148 _discr_per_cell->incrRef();
1151 void MEDCouplingFieldDiscretizationPerCell::updateTime() const
1154 updateTimeWith(*_discr_per_cell);
1157 std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren() const
1159 std::size_t ret(MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren());
1163 std::vector<const BigMemoryObject *> MEDCouplingFieldDiscretizationPerCell::getDirectChildrenWithNull() const
1165 std::vector<const BigMemoryObject *> ret(MEDCouplingFieldDiscretization::getDirectChildrenWithNull());
1166 ret.push_back(_discr_per_cell);
1170 void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1172 if(!_discr_per_cell)
1173 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !");
1175 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh or DataArray !");
1176 mcIdType nbOfTuples(_discr_per_cell->getNumberOfTuples());
1177 if(nbOfTuples!=mesh->getNumberOfCells())
1178 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !");
1181 bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1185 reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined.";
1188 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1191 reason="Spatial discretization of this is ON_GAUSS, which is not the case of other.";
1194 if(_discr_per_cell==0)
1195 return otherC->_discr_per_cell==0;
1196 if(otherC->_discr_per_cell==0)
1198 bool ret=_discr_per_cell->isEqualIfNotWhy(*otherC->_discr_per_cell,reason);
1200 reason.insert(0,"Field discretization per cell DataArrayIdType given the discid per cell :");
1204 bool MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1206 const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationPerCell *>(other);
1209 if(_discr_per_cell==0)
1210 return otherC->_discr_per_cell==0;
1211 if(otherC->_discr_per_cell==0)
1213 return _discr_per_cell->isEqualWithoutConsideringStr(*otherC->_discr_per_cell);
1217 * This method is typically the first step of renumbering. The impact on _discr_per_cell is necessary here.
1218 * virtually by this method.
1220 void MEDCouplingFieldDiscretizationPerCell::renumberCells(const mcIdType *old2NewBg, bool check)
1222 mcIdType nbCells=_discr_per_cell->getNumberOfTuples();
1223 const mcIdType *array=old2NewBg;
1225 array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+nbCells);
1227 DataArrayIdType *dpc=_discr_per_cell->renumber(array);
1228 _discr_per_cell->decrRef();
1229 _discr_per_cell=dpc;
1232 free(const_cast<mcIdType *>(array));
1235 void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh)
1238 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !");
1239 if(!_discr_per_cell)
1241 _discr_per_cell=DataArrayIdType::New();
1242 mcIdType nbTuples=mesh->getNumberOfCells();
1243 _discr_per_cell->alloc(nbTuples,1);
1244 mcIdType *ptr=_discr_per_cell->getPointer();
1245 std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE);
1249 void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const
1251 if(!_discr_per_cell)
1252 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : no discretization defined !");
1253 MCAuto<DataArrayIdType> test( _discr_per_cell->findIdsEqual(DFT_INVALID_LOCID_VALUE));
1254 if(test->getNumberOfTuples()!=0)
1255 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : presence of orphan cells !");
1259 * This method is useful when 'this' describes a field discretization with several gauss discretization on a \b same cell type.
1260 * For example same NORM_TRI3 cells having 6 gauss points and others with 12 gauss points.
1261 * This method returns 2 arrays with same size : the return value and 'locIds' output parameter.
1262 * 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.
1263 * The return vector contains a set of newly created instance to deal with.
1264 * The returned vector represents a \b partition of cells ids with a gauss discretization set.
1266 * If no descretization is set in 'this' and exception will be thrown.
1268 std::vector<DataArrayIdType *> MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector<mcIdType>& locIds) const
1270 if(!_discr_per_cell)
1271 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType : no descretization set !");
1272 return _discr_per_cell->partitionByDifferentValues(locIds);
1275 const DataArrayIdType *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const
1277 return _discr_per_cell;
1280 void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayIdType *adids)
1282 if(adids!=_discr_per_cell)
1285 _discr_per_cell->decrRef();
1286 _discr_per_cell=const_cast<DataArrayIdType *>(adids);
1288 _discr_per_cell->incrRef();
1293 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss()
1297 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const mcIdType *startCellIds, const mcIdType *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc)
1301 MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc)
1305 TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const
1310 bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
1314 reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined.";
1317 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1320 reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other.";
1323 if(!MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(other,eps,reason))
1325 if(_loc.size()!=otherC->_loc.size())
1327 reason="Gauss spatial discretization : localization sizes differ";
1330 std::size_t sz=_loc.size();
1331 for(std::size_t i=0;i<sz;i++)
1332 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1334 std::ostringstream oss; oss << "Gauss spatial discretization : Localization #" << i << " differ from this to other.";
1341 bool MEDCouplingFieldDiscretizationGauss::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const
1343 const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(other);
1346 if(!MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(other,eps))
1348 if(_loc.size()!=otherC->_loc.size())
1350 std::size_t sz=_loc.size();
1351 for(std::size_t i=0;i<sz;i++)
1352 if(!_loc[i].isEqual(otherC->_loc[i],eps))
1358 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
1360 * \sa MEDCouplingFieldDiscretization::deepCopy.
1362 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() const
1364 return new MEDCouplingFieldDiscretizationGauss(*this);
1367 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const mcIdType *startCellIds, const mcIdType *endCellIds) const
1369 return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds);
1372 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const
1374 return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds);
1377 std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const
1379 std::ostringstream oss; oss << REPR << "." << std::endl;
1382 if(_discr_per_cell->isAllocated())
1384 oss << "Discretization per cell : ";
1385 std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator<mcIdType>(oss,", "));
1389 oss << "Presence of " << _loc.size() << " localizations." << std::endl;
1391 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++,i++)
1393 oss << "+++++ Localization #" << i << " +++++" << std::endl;
1394 oss << (*it).getStringRepr();
1395 oss << "++++++++++" << std::endl;
1400 std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySizeWithoutChildren() const
1402 std::size_t ret(MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren());
1403 ret+=_loc.capacity()*sizeof(MEDCouplingGaussLocalization);
1404 for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++)
1405 ret+=(*it).getMemorySize();
1409 const char *MEDCouplingFieldDiscretizationGauss::getRepr() const
1415 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
1416 * The input code coherency is also checked regarding spatial discretization of \a this.
1417 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
1418 * 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).
1420 mcIdType MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const
1422 if(!_discr_per_cell || !_discr_per_cell->isAllocated() || _discr_per_cell->getNumberOfComponents()!=1)
1423 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode");
1424 if(code.size()%3!=0)
1425 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
1426 mcIdType nbOfSplit=ToIdType(idsPerType.size());
1427 mcIdType nbOfTypes=ToIdType(code.size()/3);
1429 for(mcIdType i=0;i<nbOfTypes;i++)
1431 mcIdType nbOfEltInChunk=code[3*i+1];
1432 if(nbOfEltInChunk<0)
1433 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
1434 mcIdType pos=code[3*i+2];
1437 if(pos<0 || pos>=nbOfSplit)
1439 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
1440 throw INTERP_KERNEL::Exception(oss.str().c_str());
1442 const DataArrayIdType *ids(idsPerType[pos]);
1443 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
1445 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
1446 throw INTERP_KERNEL::Exception(oss.str().c_str());
1449 ret+=nbOfEltInChunk;
1451 if(ret!=_discr_per_cell->getNumberOfTuples())
1453 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " cells whereas discretization percell array lgth is " << _discr_per_cell->getNumberOfTuples() << " !";
1454 throw INTERP_KERNEL::Exception(oss.str().c_str());
1456 return getNumberOfTuples(0);//0 is not an error ! It is to be sure that input mesh is not used
1459 mcIdType MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const
1462 if (_discr_per_cell == 0)
1463 throw INTERP_KERNEL::Exception("Discretization is not initialized!");
1464 const mcIdType *dcPtr=_discr_per_cell->getConstPointer();
1465 mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples();
1466 mcIdType maxSz=ToIdType(_loc.size());
1467 for(const mcIdType *w=dcPtr;w!=dcPtr+nbOfTuples;w++)
1469 if(*w>=0 && *w<maxSz)
1470 ret+=_loc[*w].getNumberOfGaussPt();
1473 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuples : At cell #" << std::distance(dcPtr,w) << " localization id is " << *w << " should be in [0," << maxSz << ") !";
1474 throw INTERP_KERNEL::Exception(oss.str().c_str());
1480 mcIdType MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
1483 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces : NULL input mesh !");
1484 return mesh->getNumberOfCells();
1488 * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField
1489 * and a call to DataArrayDouble::computeOffsetsFull on the returned array.
1491 DataArrayIdType *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const
1494 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !");
1495 mcIdType nbOfTuples=mesh->getNumberOfCells();
1496 MCAuto<DataArrayIdType> ret=DataArrayIdType::New();
1497 ret->alloc(nbOfTuples+1,1);
1498 mcIdType *retPtr(ret->getPointer());
1499 const mcIdType *start(_discr_per_cell->begin());
1500 if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples)
1501 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !");
1502 mcIdType maxPossible=ToIdType(_loc.size());
1504 for(mcIdType i=0;i<nbOfTuples;i++,start++)
1506 if(*start>=0 && *start<maxPossible)
1507 retPtr[i+1]=retPtr[i]+_loc[*start].getNumberOfGaussPt();
1510 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getOffsetArr : At position #" << i << " the locid = " << *start << " whereas it should be in [0," << maxPossible << ") !";
1511 throw INTERP_KERNEL::Exception(oss.str().c_str());
1517 void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
1518 const mcIdType *old2NewBg, bool check)
1521 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !");
1522 const mcIdType *array=old2NewBg;
1524 array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
1525 mcIdType nbOfCells=_discr_per_cell->getNumberOfTuples();
1526 mcIdType nbOfTuples=getNumberOfTuples(0);
1527 const mcIdType *dcPtr=_discr_per_cell->getConstPointer();
1528 mcIdType *array2=new mcIdType[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
1529 mcIdType *array3=new mcIdType[nbOfCells];//store for each cell in present dcp array (already renumbered) the offset needed by each cell in new numbering.
1531 for(mcIdType i=1;i<nbOfCells;i++)
1532 array3[i]=array3[i-1]+_loc[dcPtr[i-1]].getNumberOfGaussPt();
1534 for(mcIdType i=0;i<nbOfCells;i++)
1536 mcIdType nbOfGaussPt=_loc[dcPtr[array[i]]].getNumberOfGaussPt();
1537 for(mcIdType k=0;k<nbOfGaussPt;k++,j++)
1538 array2[j]=array3[array[i]]+k;
1541 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
1543 (*it)->renumberInPlace(array2);
1546 free(const_cast<mcIdType*>(array));
1549 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
1552 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !");
1553 checkNoOrphanCells();
1554 MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
1555 mcIdType nbOfTuples=getNumberOfTuples(mesh);
1556 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
1557 int spaceDim=mesh->getSpaceDimension();
1558 ret->alloc(nbOfTuples,spaceDim);
1559 std::vector< mcIdType > locIds;
1560 std::vector<DataArrayIdType *> parts=splitIntoSingleGaussDicrPerCellType(locIds);
1561 std::vector< MCAuto<DataArrayIdType> > parts2(parts.size());
1562 std::copy(parts.begin(),parts.end(),parts2.begin());
1563 MCAuto<DataArrayIdType> offsets=buildNbOfGaussPointPerCellField();
1564 offsets->computeOffsets();
1565 const mcIdType *ptrOffsets=offsets->getConstPointer();
1566 const double *coords=umesh->getCoords()->getConstPointer();
1567 const mcIdType *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
1568 const mcIdType *conn=umesh->getNodalConnectivity()->getConstPointer();
1569 double *valsToFill=ret->getPointer();
1570 for(std::size_t i=0;i<parts2.size();i++)
1572 INTERP_KERNEL::GaussCoords calculator;
1574 const MEDCouplingGaussLocalization& cli(_loc[locIds[i]]);//curLocInfo
1575 INTERP_KERNEL::NormalizedCellType typ(cli.getType());
1576 const std::vector<double>& wg(cli.getWeights());
1577 calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(),
1578 &cli.getGaussCoords()[0],ToIdType(wg.size()),&cli.getRefCoords()[0],
1579 INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes());
1581 for(const mcIdType *w=parts2[i]->begin();w!=parts2[i]->end();w++)
1582 calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w]));
1584 ret->copyStringInfoFrom(*umesh->getCoords());
1588 void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd,
1589 DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const
1592 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !");
1593 MCAuto<DataArrayIdType> tmp=DataArrayIdType::New(); tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1);
1594 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
1596 tmp=tmp->buildUnique();
1597 MCAuto<DataArrayIdType> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();
1598 nbOfNodesPerCell->computeOffsetsFull();
1599 nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
1605 void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const
1609 void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
1613 val=_discr_per_cell->getNumberOfTuples();
1614 tinyInfo.push_back(val);
1615 tinyInfo.push_back(ToIdType(_loc.size()));
1617 tinyInfo.push_back(-1);
1619 tinyInfo.push_back(_loc[0].getDimension());
1620 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1621 (*iter).pushTinySerializationIntInfo(tinyInfo);
1624 void MEDCouplingFieldDiscretizationGauss::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1626 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1627 (*iter).pushTinySerializationDblInfo(tinyInfo);
1630 void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayIdType *& arr) const
1634 arr=_discr_per_cell;
1637 void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector<mcIdType>& tinyInfo, DataArrayIdType *& arr)
1639 mcIdType val=tinyInfo[0];
1642 _discr_per_cell=DataArrayIdType::New();
1643 _discr_per_cell->alloc(val,1);
1647 arr=_discr_per_cell;
1648 commonUnserialization(tinyInfo);
1651 void MEDCouplingFieldDiscretizationGauss::checkForUnserialization(const std::vector<mcIdType>& tinyInfo, const DataArrayIdType *arr)
1653 static const char MSG[]="MEDCouplingFieldDiscretizationGauss::checkForUnserialization : expect to have one not null DataArrayIdType !";
1654 mcIdType val=tinyInfo[0];
1658 throw INTERP_KERNEL::Exception(MSG);
1659 arr->checkNbOfTuplesAndComp(val,1,MSG);
1660 _discr_per_cell=const_cast<DataArrayIdType *>(arr);
1661 _discr_per_cell->incrRef();
1665 commonUnserialization(tinyInfo);
1668 void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vector<double>& tinyInfo)
1670 double *tmp=new double[tinyInfo.size()];
1671 std::copy(tinyInfo.begin(),tinyInfo.end(),tmp);
1672 const double *work=tmp;
1673 for(std::vector<MEDCouplingGaussLocalization>::iterator iter=_loc.begin();iter!=_loc.end();iter++)
1674 work=(*iter).fillWithValues(work);
1678 double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, mcIdType cellId, mcIdType nodeIdInCell, int compoId) const
1680 mcIdType offset=getOffsetOfCell(cellId);
1681 return da->getIJ(offset+nodeIdInCell,compoId);
1684 void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
1687 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh or DataArray !");
1688 MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da);
1689 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++)
1690 (*iter).checkConsistencyLight();
1691 mcIdType nbOfDesc=ToIdType(_loc.size());
1692 mcIdType nbOfCells=mesh->getNumberOfCells();
1693 const mcIdType *dc=_discr_per_cell->getConstPointer();
1694 for(mcIdType i=0;i<nbOfCells;i++)
1698 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happened !";
1699 throw INTERP_KERNEL::Exception(oss.str().c_str());
1703 std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has no gauss location !";
1704 throw INTERP_KERNEL::Exception(oss.str().c_str());
1706 if(mesh->getTypeOfCell(i)!=_loc[dc[i]].getType())
1708 std::ostringstream oss; oss << "Types of mesh and gauss location mismatch for cell # " << i;
1709 throw INTERP_KERNEL::Exception(oss.str().c_str());
1712 mcIdType nbOfTuples(getNumberOfTuples(mesh));
1713 if(nbOfTuples!=da->getNumberOfTuples())
1715 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " having " << da->getNumberOfTuples() << " !";
1716 throw INTERP_KERNEL::Exception(oss.str().c_str());
1720 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
1723 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : mesh instance specified is NULL !");
1724 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
1725 const double *volPtr=vol->getArray()->begin();
1726 MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_PT);
1728 ret->setDiscretization(const_cast<MEDCouplingFieldDiscretizationGauss *>(this));
1729 if(!_discr_per_cell)
1730 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array not defined ! spatial localization is incorrect !");
1731 _discr_per_cell->checkAllocated();
1732 if(_discr_per_cell->getNumberOfComponents()!=1)
1733 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but with nb of components different from 1 !");
1734 if(_discr_per_cell->getNumberOfTuples()!=vol->getNumberOfTuples())
1735 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 !");
1736 MCAuto<DataArrayIdType> offset=getOffsetArr(mesh);
1737 MCAuto<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(getNumberOfTuples(mesh),1);
1739 double *arrPtr=arr->getPointer();
1740 const mcIdType *offsetPtr=offset->getConstPointer();
1741 mcIdType maxGaussLoc=ToIdType(_loc.size());
1742 std::vector<mcIdType> locIds;
1743 std::vector<DataArrayIdType *> ids=splitIntoSingleGaussDicrPerCellType(locIds);
1744 std::vector< MCAuto<DataArrayIdType> > ids2(ids.size()); std::copy(ids.begin(),ids.end(),ids2.begin());
1745 for(std::size_t i=0;i<locIds.size();i++)
1747 const DataArrayIdType *curIds=ids[i];
1748 mcIdType locId=locIds[i];
1749 if(locId>=0 && locId<maxGaussLoc)
1751 const MEDCouplingGaussLocalization& loc=_loc[locId];
1752 mcIdType nbOfGaussPt=loc.getNumberOfGaussPt();
1753 INTERP_KERNEL::AutoPtr<double> weights=new double[nbOfGaussPt];
1754 double sum=std::accumulate(loc.getWeights().begin(),loc.getWeights().end(),0.);
1755 std::transform(loc.getWeights().begin(),loc.getWeights().end(),(double *)weights,std::bind2nd(std::multiplies<double>(),1./sum));
1756 for(const mcIdType *cellId=curIds->begin();cellId!=curIds->end();cellId++)
1757 for(mcIdType j=0;j<nbOfGaussPt;j++)
1758 arrPtr[offsetPtr[*cellId]+j]=weights[j]*volPtr[*cellId];
1762 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getMeasureField : Presence of localization id " << locId << " in cell #" << curIds->getIJ(0,0) << " ! Must be in [0," << maxGaussLoc << ") !";
1763 throw INTERP_KERNEL::Exception(oss.str().c_str());
1766 ret->synchronizeTimeWithSupport();
1770 void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
1772 throw INTERP_KERNEL::Exception("Not implemented yet !");
1775 void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const
1777 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !");
1780 DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const
1782 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented yet for gauss points !");
1785 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const
1788 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !");
1789 MCAuto<DataArrayIdType> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
1790 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
1796 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
1798 * \param [out] beginOut Valid only if \a di is NULL
1799 * \param [out] endOut Valid only if \a di is NULL
1800 * \param [out] stepOut Valid only if \a di is NULL
1801 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
1803 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
1805 MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange(const MEDCouplingMesh *mesh, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
1807 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
1808 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
1810 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : NULL input mesh !");
1811 if(!_discr_per_cell)
1812 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : no discretization array set !");
1813 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
1814 const char msg[]="MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : cell #";
1815 mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples();
1816 const mcIdType *w=_discr_per_cell->begin();
1817 mcIdType nbMaxOfLocId=ToIdType(_loc.size());
1818 for(mcIdType i=0;i<nbOfTuples;i++,w++)
1820 if(*w!=DFT_INVALID_LOCID_VALUE)
1822 if(*w>=0 && *w<nbMaxOfLocId)
1824 mcIdType delta=_loc[*w].getNumberOfGaussPt();
1832 { std::ostringstream oss; oss << msg << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1835 { std::ostringstream oss; oss << msg << i << " is detected as orphan !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
1837 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
1842 * This method returns a tuple ids selection from cell ids selection [start;end).
1843 * This method is called by MEDCouplingFieldDiscretizationGauss::buildSubMeshData to return parameter \b di.
1845 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
1848 DataArrayIdType *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const
1851 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !");
1852 MCAuto<DataArrayIdType> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer
1853 mcIdType nbOfCells(mesh->getNumberOfCells());
1854 if(_discr_per_cell->getNumberOfTuples()!=nbOfCells)
1855 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : mismatch of nb of tuples of cell ids array and number of cells !");
1856 nbOfNodesPerCell->computeOffsetsFull();
1857 MCAuto<DataArrayIdType> sel=DataArrayIdType::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,ToIdType(std::distance(startCellIds,endCellIds)),1);
1858 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
1862 * No implementation needed !
1864 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const mcIdType *, mcIdType newNbOfNodes, DataArrayDouble *) const
1868 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const
1870 throw INTERP_KERNEL::Exception("Not implemented yet !");
1873 void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const
1875 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 !");
1878 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationGauss::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
1881 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : input array is empty");
1882 std::vector<MEDCouplingGaussLocalization> loc;//store the localizations for the output GaussDiscretization object
1883 std::vector< MCAuto<DataArrayIdType> > discPerCells(fds.size());
1885 for(auto it=fds.begin();it!=fds.end();++it,++i)
1887 const MEDCouplingFieldDiscretizationGauss *itc(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(*it));
1889 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : same field discretization expected for all input discretizations !");
1891 std::vector<MEDCouplingGaussLocalization> loc2(itc->_loc);
1892 std::vector<mcIdType> newLocId(loc2.size());
1893 for(std::size_t j=0;j<loc2.size();++j)
1896 for(;k<loc.size();++k)
1898 if(loc2[j].isEqual(loc[k],1e-10))
1900 newLocId[j]=ToIdType(k);
1904 if(k==loc.size())// current loc2[j]
1906 newLocId[j]=ToIdType(loc.size());
1907 loc.push_back(loc2[j]);
1910 const DataArrayIdType *dpc(itc->_discr_per_cell);
1912 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : Presence of nullptr array of disc per cell !");
1913 MCAuto<DataArrayIdType> dpc2(dpc->deepCopy());
1914 dpc2->transformWithIndArr(newLocId.data(),newLocId.data()+newLocId.size());
1915 discPerCells[i]=dpc2;
1917 MCAuto<DataArrayIdType> dpc3(DataArrayIdType::Aggregate(ToConstVect(discPerCells)));
1918 MCAuto<MEDCouplingFieldDiscretizationGauss> ret(new MEDCouplingFieldDiscretizationGauss(dpc3,loc));
1919 return DynamicCast<MEDCouplingFieldDiscretizationGauss,MEDCouplingFieldDiscretization>(ret);
1922 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
1923 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1926 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !");
1927 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1928 if(ToIdType(cm.getDimension())!=mesh->getMeshDimension())
1930 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension();
1931 oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !";
1932 throw INTERP_KERNEL::Exception(oss.str().c_str());
1934 buildDiscrPerCellIfNecessary(mesh);
1935 mcIdType id=ToIdType(_loc.size());
1936 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1937 _loc.push_back(elt);
1938 mcIdType *ptr=_discr_per_cell->getPointer();
1939 mcIdType nbCells=mesh->getNumberOfCells();
1940 for(mcIdType i=0;i<nbCells;i++)
1941 if(mesh->getTypeOfCell(i)==type)
1943 zipGaussLocalizations();
1946 void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const mcIdType *begin, const mcIdType *end, const std::vector<double>& refCoo,
1947 const std::vector<double>& gsCoo, const std::vector<double>& wg)
1950 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !");
1951 buildDiscrPerCellIfNecessary(mesh);
1952 if(std::distance(begin,end)<1)
1953 throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !");
1954 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin);
1955 MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg);
1956 mcIdType id=ToIdType(_loc.size());
1957 mcIdType *ptr=_discr_per_cell->getPointer();
1958 for(const mcIdType *w=begin+1;w!=end;w++)
1960 if(mesh->getTypeOfCell(*w)!=type)
1962 std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !";
1963 throw INTERP_KERNEL::Exception(oss.str().c_str());
1967 for(const mcIdType *w2=begin;w2!=end;w2++)
1970 _loc.push_back(elt);
1971 zipGaussLocalizations();
1974 void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations()
1978 _discr_per_cell->decrRef();
1984 void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(mcIdType locId, const MEDCouplingGaussLocalization& loc)
1987 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !");
1988 mcIdType sz=ToIdType(_loc.size());
1989 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
1991 _loc.resize(locId+1,gLoc);
1995 void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(mcIdType newSz)
1998 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !");
1999 MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
2000 _loc.resize(newSz,gLoc);
2003 MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(mcIdType locId)
2005 checkLocalizationId(locId);
2009 mcIdType MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const
2011 return ToIdType(_loc.size());
2014 mcIdType MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(mcIdType cellId) const
2016 if(!_discr_per_cell)
2017 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
2018 mcIdType locId=_discr_per_cell->begin()[cellId];
2020 throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !");
2024 mcIdType MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
2026 std::set<mcIdType> ret=getGaussLocalizationIdsOfOneType(type);
2028 throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
2030 throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
2031 return *ret.begin();
2034 std::set<mcIdType> MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
2036 if(!_discr_per_cell)
2037 throw INTERP_KERNEL::Exception("No Gauss localization still set !");
2038 std::set<mcIdType> ret;
2040 for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++)
2041 if((*iter).getType()==type)
2046 void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(mcIdType locId, std::vector<mcIdType>& cellIds) const
2048 if(locId<0 || locId>=ToIdType(_loc.size()))
2049 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
2050 mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples();
2051 const mcIdType *ptr=_discr_per_cell->getConstPointer();
2052 for(mcIdType i=0;i<nbOfTuples;i++)
2054 cellIds.push_back(i);
2057 const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(mcIdType locId) const
2059 checkLocalizationId(locId);
2063 void MEDCouplingFieldDiscretizationGauss::checkLocalizationId(mcIdType locId) const
2065 if(locId<0 || locId>=ToIdType(_loc.size()))
2066 throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !");
2069 mcIdType MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(mcIdType cellId) const
2072 const mcIdType *start=_discr_per_cell->getConstPointer();
2073 for(const mcIdType *w=start;w!=start+cellId;w++)
2074 ret+=_loc[*w].getNumberOfGaussPt();
2079 * This method do the assumption that there is no orphan cell. If there is an exception is thrown.
2080 * This method makes the assumption too that '_discr_per_cell' is defined. If not an exception is thrown.
2081 * This method returns a newly created array with number of tuples equals to '_discr_per_cell->getNumberOfTuples' and number of components equal to 1.
2082 * The i_th tuple in returned array is the number of gauss point if the corresponding cell.
2084 DataArrayIdType *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField() const
2086 if(!_discr_per_cell)
2087 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : no discretization array set !");
2088 mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples();
2089 MCAuto<DataArrayIdType> ret=DataArrayIdType::New();
2090 const mcIdType *w=_discr_per_cell->begin();
2091 ret->alloc(nbOfTuples,1);
2092 mcIdType *valsToFill=ret->getPointer();
2093 mcIdType nbMaxOfLocId=ToIdType(_loc.size());
2094 for(mcIdType i=0;i<nbOfTuples;i++,w++)
2095 if(*w!=DFT_INVALID_LOCID_VALUE)
2097 if(*w>=0 && *w<nbMaxOfLocId)
2098 valsToFill[i]=_loc[*w].getNumberOfGaussPt();
2101 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !";
2102 throw INTERP_KERNEL::Exception(oss.str().c_str());
2107 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " is detected as orphan !";
2108 throw INTERP_KERNEL::Exception(oss.str().c_str());
2113 void MEDCouplingFieldDiscretizationGauss::reprQuickOverview(std::ostream& stream) const
2115 stream << "Gauss points spatial discretization.";
2119 * This method makes the assumption that _discr_per_cell is set.
2120 * This method reduces as much as possible number size of _loc.
2121 * This method is useful when several set on same cells has been done and that some Gauss Localization are no more used.
2123 void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations()
2125 const mcIdType *start=_discr_per_cell->begin();
2126 mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples();
2127 INTERP_KERNEL::AutoPtr<mcIdType> tmp=new mcIdType[_loc.size()];
2128 std::fill((mcIdType *)tmp,(mcIdType *)tmp+_loc.size(),-2);
2129 for(const mcIdType *w=start;w!=start+nbOfTuples;w++)
2133 for(mcIdType i=0;i<ToIdType(_loc.size());i++)
2136 if(fid==ToIdType(_loc.size()))
2139 mcIdType *start2=_discr_per_cell->getPointer();
2140 for(mcIdType *w2=start2;w2!=start2+nbOfTuples;w2++)
2143 std::vector<MEDCouplingGaussLocalization> tmpLoc;
2144 for(mcIdType i=0;i<ToIdType(_loc.size());i++)
2146 tmpLoc.push_back(_loc[i]);
2150 void MEDCouplingFieldDiscretizationGauss::commonUnserialization(const std::vector<mcIdType>& tinyInfo)
2152 mcIdType nbOfLoc=tinyInfo[1];
2154 mcIdType dim=tinyInfo[2];
2157 delta=(ToIdType(tinyInfo.size())-3)/nbOfLoc;
2158 for(mcIdType i=0;i<nbOfLoc;i++)
2160 std::vector<mcIdType> tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta);
2161 MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp);
2162 _loc.push_back(elt);
2166 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE()
2170 TypeOfField MEDCouplingFieldDiscretizationGaussNE::getEnum() const
2176 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
2178 * \sa MEDCouplingFieldDiscretization::deepCopy.
2180 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() const
2182 return new MEDCouplingFieldDiscretizationGaussNE(*this);
2185 std::string MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const
2187 return std::string(REPR);
2190 const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const
2195 bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2199 reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined.";
2202 const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationGaussNE *>(other);
2205 reason="Spatial discrtization of this is ON_GAUSS_NE, which is not the case of other.";
2210 * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input.
2211 * The input code coherency is also checked regarding spatial discretization of \a this.
2212 * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned.
2213 * 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).
2215 mcIdType MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const
2217 if(code.size()%3!=0)
2218 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code !");
2219 mcIdType nbOfSplit=ToIdType(idsPerType.size());
2220 mcIdType nbOfTypes=ToIdType(code.size()/3);
2222 for(mcIdType i=0;i<nbOfTypes;i++)
2224 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)code[3*i]));
2227 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 !";
2228 throw INTERP_KERNEL::Exception(oss.str().c_str());
2230 mcIdType nbOfEltInChunk=code[3*i+1];
2231 if(nbOfEltInChunk<0)
2232 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code ! presence of negative value in a type !");
2233 mcIdType pos=code[3*i+2];
2236 if(pos<0 || pos>=nbOfSplit)
2238 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !";
2239 throw INTERP_KERNEL::Exception(oss.str().c_str());
2241 const DataArrayIdType *ids(idsPerType[pos]);
2242 if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0)
2244 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !";
2245 throw INTERP_KERNEL::Exception(oss.str().c_str());
2248 ret+=nbOfEltInChunk*ToIdType(cm.getNumberOfNodes());
2253 mcIdType MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const
2256 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !");
2258 mcIdType nbOfCells=mesh->getNumberOfCells();
2259 for(mcIdType i=0;i<nbOfCells;i++)
2261 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2262 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2264 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2265 ret+=cm.getNumberOfNodes();
2270 mcIdType MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const
2273 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces : NULL input mesh !");
2274 return mesh->getNumberOfCells();
2277 DataArrayIdType *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const
2280 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !");
2281 mcIdType nbOfTuples=mesh->getNumberOfCells();
2282 DataArrayIdType *ret=DataArrayIdType::New();
2283 ret->alloc(nbOfTuples+1,1);
2284 mcIdType *retPtr=ret->getPointer();
2286 for(mcIdType i=0;i<nbOfTuples;i++)
2288 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2289 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2291 throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !");
2292 retPtr[i+1]=retPtr[i]+cm.getNumberOfNodes();
2297 void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArray *>& arrays,
2298 const mcIdType *old2NewBg, bool check)
2301 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !");
2302 const mcIdType *array=old2NewBg;
2304 array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells());
2305 mcIdType nbOfCells=mesh->getNumberOfCells();
2306 mcIdType nbOfTuples=getNumberOfTuples(mesh);
2307 mcIdType *array2=new mcIdType[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace.
2308 mcIdType *array3=new mcIdType[nbOfCells];//store for each cell in after renumbering the offset needed by each cell in new numbering.
2310 for(mcIdType i=1;i<nbOfCells;i++)
2312 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(ToIdType(std::distance(array,std::find(array,array+nbOfCells,i-1))));
2313 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2314 array3[i]=array3[i-1]+cm.getNumberOfNodes();
2317 for(mcIdType i=0;i<nbOfCells;i++)
2319 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2320 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2321 for(mcIdType k=0;k<ToIdType(cm.getNumberOfNodes());k++,j++)
2322 array2[j]=array3[array[i]]+k;
2325 for(std::vector<DataArray *>::const_iterator it=arrays.begin();it!=arrays.end();it++)
2327 (*it)->renumberInPlace(array2);
2330 free(const_cast<mcIdType *>(array));
2333 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
2336 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !");
2337 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
2338 MCAuto<MEDCouplingUMesh> umesh=mesh->buildUnstructured();//in general do nothing
2339 mcIdType nbOfTuples=getNumberOfTuples(umesh);
2340 int spaceDim=mesh->getSpaceDimension();
2341 ret->alloc(nbOfTuples,spaceDim);
2342 const double *coords=umesh->getCoords()->begin();
2343 const mcIdType *connI=umesh->getNodalConnectivityIndex()->getConstPointer();
2344 const mcIdType *conn=umesh->getNodalConnectivity()->getConstPointer();
2345 mcIdType nbCells=umesh->getNumberOfCells();
2346 double *retPtr=ret->getPointer();
2347 for(mcIdType i=0;i<nbCells;i++,connI++)
2348 for(const mcIdType *w=conn+connI[0]+1;w!=conn+connI[1];w++)
2350 retPtr=std::copy(coords+(*w)*spaceDim,coords+((*w)+1)*spaceDim,retPtr);
2355 * Reimplemented from MEDCouplingFieldDiscretization::integral for performance reason. The default implementation is valid too for GAUSS_NE spatial discretization.
2357 void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const
2360 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !");
2361 std::size_t nbOfCompo=arr->getNumberOfComponents();
2362 std::fill(res,res+nbOfCompo,0.);
2364 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isWAbs);
2365 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2366 MCAuto<DataArrayIdType> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2367 nbOfNodesPerCell->computeOffsetsFull();
2368 const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin();
2369 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2371 std::size_t wArrSz=-1;
2372 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2373 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2374 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2375 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2376 MCAuto<DataArrayIdType> ids=mesh->giveCellsWithType(*it);
2377 MCAuto<DataArrayIdType> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2378 const mcIdType *ptIds2=ids2->begin(),*ptIds=ids->begin();
2379 mcIdType nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2380 for(mcIdType i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++,ptIds2+=wArrSz)
2382 for(std::size_t k=0;k<nbOfCompo;k++)
2385 for(std::size_t j=0;j<wArrSz;j++)
2386 tmp+=arrPtr[nbOfCompo*ptIds2[j]+k]*wArr2[j];
2387 res[k]+=tmp*volPtr[*ptIds];
2393 const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2397 case INTERP_KERNEL::NORM_POINT1:
2398 lgth=sizeof(FGP_POINT1)/sizeof(double);
2400 case INTERP_KERNEL::NORM_SEG2:
2401 lgth=sizeof(FGP_SEG2)/sizeof(double);
2403 case INTERP_KERNEL::NORM_SEG3:
2404 lgth=sizeof(FGP_SEG3)/sizeof(double);
2406 case INTERP_KERNEL::NORM_SEG4:
2407 lgth=sizeof(FGP_SEG4)/sizeof(double);
2409 case INTERP_KERNEL::NORM_TRI3:
2410 lgth=sizeof(FGP_TRI3)/sizeof(double);
2412 case INTERP_KERNEL::NORM_TRI6:
2413 lgth=sizeof(FGP_TRI6)/sizeof(double);
2415 case INTERP_KERNEL::NORM_TRI7:
2416 lgth=sizeof(FGP_TRI7)/sizeof(double);
2418 case INTERP_KERNEL::NORM_QUAD4:
2419 lgth=sizeof(FGP_QUAD4)/sizeof(double);
2421 case INTERP_KERNEL::NORM_QUAD8:
2422 lgth=sizeof(FGP_QUAD8)/sizeof(double);
2424 case INTERP_KERNEL::NORM_QUAD9:
2425 lgth=sizeof(FGP_QUAD9)/sizeof(double);
2427 case INTERP_KERNEL::NORM_TETRA4:
2428 lgth=sizeof(FGP_TETRA4)/sizeof(double);
2430 case INTERP_KERNEL::NORM_TETRA10:
2431 lgth=sizeof(FGP_TETRA10)/sizeof(double);
2433 case INTERP_KERNEL::NORM_PENTA6:
2434 lgth=sizeof(FGP_PENTA6)/sizeof(double);
2436 case INTERP_KERNEL::NORM_PENTA15:
2437 lgth=sizeof(FGP_PENTA15)/sizeof(double);
2439 case INTERP_KERNEL::NORM_HEXA8:
2440 lgth=sizeof(FGP_HEXA8)/sizeof(double);
2442 case INTERP_KERNEL::NORM_HEXA20:
2443 lgth=sizeof(FGP_HEXA20)/sizeof(double);
2445 case INTERP_KERNEL::NORM_HEXA27:
2446 lgth=sizeof(FGP_HEXA27)/sizeof(double);
2448 case INTERP_KERNEL::NORM_PYRA5:
2449 lgth=sizeof(FGP_PYRA5)/sizeof(double);
2451 case INTERP_KERNEL::NORM_PYRA13:
2452 lgth=sizeof(FGP_PYRA13)/sizeof(double);
2455 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 !");
2459 const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2463 case INTERP_KERNEL::NORM_POINT1:
2466 case INTERP_KERNEL::NORM_SEG2:
2467 lgth=sizeof(REF_SEG2)/sizeof(double);
2469 case INTERP_KERNEL::NORM_SEG3:
2470 lgth=sizeof(REF_SEG3)/sizeof(double);
2472 case INTERP_KERNEL::NORM_SEG4:
2473 lgth=sizeof(REF_SEG4)/sizeof(double);
2475 case INTERP_KERNEL::NORM_TRI3:
2476 lgth=sizeof(REF_TRI3)/sizeof(double);
2478 case INTERP_KERNEL::NORM_TRI6:
2479 lgth=sizeof(REF_TRI6)/sizeof(double);
2481 case INTERP_KERNEL::NORM_TRI7:
2482 lgth=sizeof(REF_TRI7)/sizeof(double);
2484 case INTERP_KERNEL::NORM_QUAD4:
2485 lgth=sizeof(REF_QUAD4)/sizeof(double);
2487 case INTERP_KERNEL::NORM_QUAD8:
2488 lgth=sizeof(REF_QUAD8)/sizeof(double);
2490 case INTERP_KERNEL::NORM_QUAD9:
2491 lgth=sizeof(REF_QUAD9)/sizeof(double);
2493 case INTERP_KERNEL::NORM_TETRA4:
2494 lgth=sizeof(REF_TETRA4)/sizeof(double);
2496 case INTERP_KERNEL::NORM_TETRA10:
2497 lgth=sizeof(REF_TETRA10)/sizeof(double);
2499 case INTERP_KERNEL::NORM_PENTA6:
2500 lgth=sizeof(REF_PENTA6)/sizeof(double);
2502 case INTERP_KERNEL::NORM_PENTA15:
2503 lgth=sizeof(REF_PENTA15)/sizeof(double);
2505 case INTERP_KERNEL::NORM_HEXA8:
2506 lgth=sizeof(REF_HEXA8)/sizeof(double);
2508 case INTERP_KERNEL::NORM_HEXA20:
2509 lgth=sizeof(REF_HEXA20)/sizeof(double);
2511 case INTERP_KERNEL::NORM_HEXA27:
2512 lgth=sizeof(REF_HEXA27)/sizeof(double);
2514 case INTERP_KERNEL::NORM_PYRA5:
2515 lgth=sizeof(REF_PYRA5)/sizeof(double);
2517 case INTERP_KERNEL::NORM_PYRA13:
2518 lgth=sizeof(REF_PYRA13)/sizeof(double);
2521 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 !");
2525 const double *MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth)
2529 case INTERP_KERNEL::NORM_POINT1:
2534 case INTERP_KERNEL::NORM_SEG2:
2536 lgth=sizeof(LOC_SEG2)/sizeof(double);
2539 case INTERP_KERNEL::NORM_SEG3:
2541 lgth=sizeof(LOC_SEG3)/sizeof(double);
2544 case INTERP_KERNEL::NORM_SEG4:
2546 lgth=sizeof(LOC_SEG4)/sizeof(double);
2549 case INTERP_KERNEL::NORM_TRI3:
2551 lgth=sizeof(LOC_TRI3)/sizeof(double);
2554 case INTERP_KERNEL::NORM_TRI6:
2556 lgth=sizeof(LOC_TRI6)/sizeof(double);
2559 case INTERP_KERNEL::NORM_TRI7:
2561 lgth=sizeof(LOC_TRI7)/sizeof(double);
2564 case INTERP_KERNEL::NORM_QUAD4:
2566 lgth=sizeof(LOC_QUAD4)/sizeof(double);
2569 case INTERP_KERNEL::NORM_QUAD8:
2571 lgth=sizeof(LOC_QUAD8)/sizeof(double);
2574 case INTERP_KERNEL::NORM_QUAD9:
2576 lgth=sizeof(LOC_QUAD9)/sizeof(double);
2579 case INTERP_KERNEL::NORM_TETRA4:
2581 lgth=sizeof(LOC_TETRA4)/sizeof(double);
2584 case INTERP_KERNEL::NORM_TETRA10:
2586 lgth=sizeof(LOC_TETRA10)/sizeof(double);
2589 case INTERP_KERNEL::NORM_PENTA6:
2591 lgth=sizeof(LOC_PENTA6)/sizeof(double);
2594 case INTERP_KERNEL::NORM_PENTA15:
2596 lgth=sizeof(LOC_PENTA15)/sizeof(double);
2599 case INTERP_KERNEL::NORM_HEXA8:
2601 lgth=sizeof(LOC_HEXA8)/sizeof(double);
2604 case INTERP_KERNEL::NORM_HEXA20:
2606 lgth=sizeof(LOC_HEXA20)/sizeof(double);
2609 case INTERP_KERNEL::NORM_HEXA27:
2611 lgth=sizeof(LOC_HEXA27)/sizeof(double);
2614 case INTERP_KERNEL::NORM_PYRA5:
2616 lgth=sizeof(LOC_PYRA5)/sizeof(double);
2619 case INTERP_KERNEL::NORM_PYRA13:
2621 lgth=sizeof(LOC_PYRA13)/sizeof(double);
2625 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 !");
2629 void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd,
2630 DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const
2633 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds : NULL input mesh !");
2634 MCAuto<DataArrayIdType> tmp=DataArrayIdType::New(); tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1);
2635 std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
2637 tmp=tmp->buildUnique();
2638 MCAuto<DataArrayIdType> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2639 nbOfNodesPerCell->computeOffsetsFull();
2640 nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
2643 void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const
2647 double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, mcIdType cellId, mcIdType nodeIdInCell, int compoId) const
2650 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !");
2652 for(mcIdType i=0;i<cellId;i++)
2654 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2655 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2656 offset+=cm.getNumberOfNodes();
2658 return da->getIJ(offset+nodeIdInCell,compoId);
2661 void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const
2663 mcIdType nbOfTuples(getNumberOfTuples(mesh));
2664 if(nbOfTuples!=da->getNumberOfTuples())
2666 std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !";
2667 throw INTERP_KERNEL::Exception(oss.str().c_str());
2671 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2674 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getMeasureField : mesh instance specified is NULL !");
2675 MCAuto<MEDCouplingFieldDouble> vol=mesh->getMeasureField(isAbs);
2676 const double *volPtr=vol->getArray()->begin();
2677 MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_GAUSS_NE);
2680 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
2681 MCAuto<DataArrayIdType> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2682 mcIdType nbTuples=nbOfNodesPerCell->accumulate((std::size_t)0);
2683 nbOfNodesPerCell->computeOffsetsFull();
2684 MCAuto<DataArrayDouble> arr=DataArrayDouble::New(); arr->alloc(nbTuples,1);
2686 double *arrPtr=arr->getPointer();
2687 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
2689 std::size_t wArrSz=-1;
2690 const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
2691 INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
2692 double sum=std::accumulate(wArr,wArr+wArrSz,0.);
2693 std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
2694 MCAuto<DataArrayIdType> ids=mesh->giveCellsWithType(*it);
2695 MCAuto<DataArrayIdType> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
2696 const mcIdType *ptIds2=ids2->begin(),*ptIds=ids->begin();
2697 mcIdType nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
2698 for(mcIdType i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++)
2699 for(std::size_t j=0;j<wArrSz;j++,ptIds2++)
2700 arrPtr[*ptIds2]=wArr2[j]*volPtr[*ptIds];
2702 ret->synchronizeTimeWithSupport();
2706 void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2708 throw INTERP_KERNEL::Exception("Not implemented yet !");
2711 void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const
2713 throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !");
2716 DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const
2718 throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented for Gauss NE !");
2721 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const
2724 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !");
2725 MCAuto<DataArrayIdType> diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end);
2726 MCAuto<MEDCouplingMesh> ret=mesh->buildPart(start,end);
2732 * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids.
2734 * \param [out] beginOut Valid only if \a di is NULL
2735 * \param [out] endOut Valid only if \a di is NULL
2736 * \param [out] stepOut Valid only if \a di is NULL
2737 * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
2739 * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData
2741 MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange(const MEDCouplingMesh *mesh, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
2743 if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range
2744 return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di);
2746 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : NULL input mesh !");
2747 mcIdType nbOfCells=mesh->getNumberOfCells();
2748 di=0; beginOut=0; endOut=0; stepOut=stepCellIds;
2749 const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #";
2750 for(mcIdType i=0;i<nbOfCells;i++)
2752 INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(i);
2753 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
2755 { std::ostringstream oss; oss << msg << i << " presence of dynamic cell (polygons and polyedrons) ! Not implemented !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
2756 mcIdType delta=cm.getNumberOfNodes();
2763 MCAuto<MEDCouplingMesh> ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds);
2769 * This method returns a tuple ids selection from cell ids selection [start;end).
2770 * This method is called by MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData to return parameter \b di.
2772 * \return a newly allocated array containing ids to select into the DataArrayDouble of the field.
2775 DataArrayIdType *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const
2778 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds : null mesh !");
2779 MCAuto<DataArrayIdType> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
2780 nbOfNodesPerCell->computeOffsetsFull();
2781 MCAuto<DataArrayIdType> sel=DataArrayIdType::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,std::distance(startCellIds,endCellIds),1);
2782 return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
2786 * No implementation needed !
2788 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const mcIdType *, mcIdType newNbOfNodes, DataArrayDouble *) const
2792 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const
2794 throw INTERP_KERNEL::Exception("Not implemented yet !");
2797 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationGaussNE::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
2799 return EasyAggregate<MEDCouplingFieldDiscretizationGaussNE>(fds);
2802 void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const
2804 throw INTERP_KERNEL::Exception("Not implemented yet !");
2807 void MEDCouplingFieldDiscretizationGaussNE::reprQuickOverview(std::ostream& stream) const
2809 stream << "Gauss points on nodes per element spatial discretization.";
2812 MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other)
2816 TypeOfField MEDCouplingFieldDiscretizationKriging::getEnum() const
2821 const char *MEDCouplingFieldDiscretizationKriging::getRepr() const
2827 * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this.
2829 * \sa MEDCouplingFieldDiscretization::deepCopy.
2831 MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationKriging::clone() const
2833 return new MEDCouplingFieldDiscretizationKriging;
2836 std::string MEDCouplingFieldDiscretizationKriging::getStringRepr() const
2838 return std::string(REPR);
2841 void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureOfField nat) const
2843 if(nat!=IntensiveMaximum)
2844 throw INTERP_KERNEL::Exception("Invalid nature for Kriging field : expected IntensiveMaximum !");
2847 bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const
2851 reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined.";
2854 const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationKriging *>(other);
2857 reason="Spatial discrtization of this is ON_NODES_KR, which is not the case of other.";
2861 MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationKriging::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
2864 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getMeasureField : mesh instance specified is NULL !");
2865 throw INTERP_KERNEL::Exception("getMeasureField on FieldDiscretizationKriging : not implemented yet !");
2868 void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const
2870 MCAuto<DataArrayDouble> res2=MEDCouplingFieldDiscretizationKriging::getValueOnMulti(arr,mesh,loc,1);
2871 std::copy(res2->begin(),res2->end(),res);
2874 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfTargetPoints) const
2876 if(!arr || !arr->isAllocated())
2877 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array is null or not allocated !");
2878 mcIdType nbOfRows=getNumberOfMeshPlaces(mesh);
2879 if(arr->getNumberOfTuples()!=nbOfRows)
2881 std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array does not have correct number of tuples ! Excepted " << nbOfRows << " having " << arr->getNumberOfTuples() << " !";
2882 throw INTERP_KERNEL::Exception(oss.str().c_str());
2884 mcIdType nbCols(-1);
2885 std::size_t nbCompo=arr->getNumberOfComponents();
2886 MCAuto<DataArrayDouble> m(computeEvaluationMatrixOnGivenPts(mesh,loc,nbOfTargetPoints,nbCols));
2887 MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
2888 ret->alloc(nbOfTargetPoints,nbCompo);
2889 INTERP_KERNEL::matrixProduct(m->begin(),nbOfTargetPoints,nbCols,arr->begin(),nbOfRows,ToIdType(nbCompo),ret->getPointer());
2893 void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const
2895 stream << "Kriging spatial discretization.";
2898 MCAuto<MEDCouplingFieldDiscretization> MEDCouplingFieldDiscretizationKriging::aggregate(std::vector<const MEDCouplingFieldDiscretization *>& fds) const
2900 return EasyAggregate<MEDCouplingFieldDiscretizationKriging>(fds);
2904 * Returns the matrix of size nbRows = \a nbOfTargetPoints and \a nbCols = \a nbCols. This matrix is useful if
2906 * \return the new result matrix to be deallocated by the caller.
2908 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts(const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfTargetPoints, mcIdType& nbCols) const
2910 mcIdType isDrift(-1),nbRows(-1);
2911 MCAuto<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2913 MCAuto<DataArrayDouble> coords=getLocalizationOfDiscValues(mesh);
2914 mcIdType nbOfPts(coords->getNumberOfTuples());
2915 std::size_t dimension(coords->getNumberOfComponents());
2916 MCAuto<DataArrayDouble> locArr=DataArrayDouble::New();
2917 locArr->useArray(loc,false,DeallocType::CPP_DEALLOC,nbOfTargetPoints,dimension);
2920 MCAuto<DataArrayDouble> matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr);
2921 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfTargetPoints*nbOfPts,matrix2->getPointer());
2923 MCAuto<DataArrayDouble> matrix3=DataArrayDouble::New();
2924 matrix3->alloc(nbOfTargetPoints*nbRows,1);
2925 double *work=matrix3->getPointer();
2926 const double *workCst(matrix2->begin()),*workCst2(loc);
2927 for(mcIdType i=0;i<nbOfTargetPoints;i++,workCst+=nbOfPts,workCst2+=isDrift-1)
2929 for(mcIdType j=0;j<nbOfPts;j++)
2930 work[i*nbRows+j]=workCst[j];
2931 work[i*nbRows+nbOfPts]=1.0;
2932 for(mcIdType j=0;j<isDrift-1;j++)
2933 work[i*nbRows+(nbOfPts+1+j)]=workCst2[j];
2935 MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
2936 ret->alloc(nbOfTargetPoints,nbRows);
2937 INTERP_KERNEL::matrixProduct(matrix3->begin(),nbOfTargetPoints,nbRows,matrixInv->begin(),nbRows,nbRows,ret->getPointer());
2938 MCAuto<DataArrayDouble> ret2(DataArrayDouble::New());
2939 ret2->alloc(nbOfTargetPoints*nbOfPts,1);
2940 workCst=ret->begin(); work=ret2->getPointer();
2941 for(mcIdType i=0;i<nbOfTargetPoints;i++,workCst+=nbRows)
2942 work=std::copy(workCst,workCst+nbOfPts,work);
2947 * 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
2948 * when multiplied by the vector of values attached to each point.
2950 * \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.
2951 * \param [out] matSz the size of returned square matrix
2952 * \return the new result matrix to be deallocated by the caller.
2955 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeInverseMatrix(const MEDCouplingMesh *mesh, mcIdType& isDrift, mcIdType& matSz) const
2957 MCAuto<DataArrayDouble> matrixWithDrift(computeMatrix(mesh,isDrift,matSz));
2958 MCAuto<DataArrayDouble> matrixInv(DataArrayDouble::New());
2959 matrixInv->alloc(matSz*matSz,1);
2960 INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),matSz,matrixInv->getPointer());
2961 return matrixInv.retn();
2965 * This method computes the kriging matrix.
2966 * \return the new result matrix to be deallocated by the caller.
2967 * \sa computeInverseMatrix
2969 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeMatrix(const MEDCouplingMesh *mesh, mcIdType& isDrift, mcIdType& matSz) const
2972 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeMatrix : NULL input mesh !");
2973 MCAuto<DataArrayDouble> coords(getLocalizationOfDiscValues(mesh));
2974 mcIdType nbOfPts(coords->getNumberOfTuples());
2975 MCAuto<DataArrayDouble> matrix(coords->buildEuclidianDistanceDenseMatrix());
2976 operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer());
2978 MCAuto<DataArrayDouble> matrixWithDrift(performDrift(matrix,coords,isDrift));
2979 matSz=nbOfPts+isDrift;
2980 return matrixWithDrift.retn();
2984 * 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
2985 * number of tuples should be equal to the number of representing points in \a mesh.
2987 * \param [in] mesh is the sources of nodes on which kriging will be done regarding the parameters and the value of \c this->getSpaceDimension()
2988 * \param [in] arr input field DataArrayDouble whose number of tuples must be equal to the number of nodes in \a mesh
2989 * \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.
2990 * Whatever the value of \a isDrift the number of tuples of returned DataArrayDouble will be equal to \c arr->getNumberOfTuples() + \a isDrift.
2991 * \return a newly allocated array containing coefficients including or not drift coefficient at the end depending the value of \a isDrift parameter.
2993 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, mcIdType& isDrift) const
2995 mcIdType nbRows(-1);
2996 MCAuto<DataArrayDouble> matrixInv(computeInverseMatrix(mesh,isDrift,nbRows));
2997 MCAuto<DataArrayDouble> KnewiK(DataArrayDouble::New());
2998 KnewiK->alloc(nbRows*1,1);
2999 MCAuto<DataArrayDouble> arr2(PerformDriftOfVec(arr,isDrift));
3000 INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbRows,nbRows,arr2->getConstPointer(),arr2->getNumberOfTuples(),1,KnewiK->getPointer());
3001 return KnewiK.retn();
3005 * 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.
3007 * \param [in] spaceDimension space dimension of the input mesh on which the Kriging has to be performed
3008 * \param [in] nbOfElems is the result of the product of nb of rows and the nb of columns of matrix \a matrixPtr
3009 * \param [in,out] matrixPtr is the dense matrix whose on each values the operation will be applied
3011 void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimension, mcIdType nbOfElems, double *matrixPtr) const
3013 switch(spaceDimension)
3017 OperateOnDenseMatrixH3(nbOfElems,matrixPtr);
3022 OperateOnDenseMatrixH2Ln(nbOfElems,matrixPtr);
3027 //nothing here : it is not a bug g(h)=h with spaceDim 3.
3031 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix : only dimension 1, 2 and 3 implemented !");
3035 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH3(mcIdType nbOfElems, double *matrixPtr)
3037 for(mcIdType i=0;i<nbOfElems;i++)
3039 double val=matrixPtr[i];
3040 matrixPtr[i]=val*val*val;
3044 void MEDCouplingFieldDiscretizationKriging::OperateOnDenseMatrixH2Ln(mcIdType nbOfElems, double *matrixPtr)
3046 for(mcIdType i=0;i<nbOfElems;i++)
3048 double val=matrixPtr[i];
3050 matrixPtr[i]=val*val*log(val);
3055 * Performs a drift to the rectangular input matrix \a matr.
3056 * This method generate a dense matrix starting from an input dense matrix \a matr and input array \a arr.
3057 * \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
3058 * \param [in] arr The array of coords to be appended in the input dense matrix \a matr. Typically arr is an array of coordinates.
3059 * \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.
3062 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftRect(const DataArrayDouble *matr, const DataArrayDouble *arr, mcIdType& delta)
3064 if(!matr || !matr->isAllocated() || matr->getNumberOfComponents()!=1)
3065 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input dense matrix ! Must be allocated not NULL and with exactly one component !");
3066 if(!arr || !arr->isAllocated())
3067 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input array of coordiantes ! Must be allocated and not NULL !");
3068 std::size_t spaceDimension(arr->getNumberOfComponents());
3069 mcIdType nbOfPts(arr->getNumberOfTuples()),nbOfEltInMatrx(matr->getNumberOfTuples());
3070 delta=ToIdType(spaceDimension)+1;
3071 mcIdType nbOfCols(nbOfEltInMatrx/nbOfPts);
3072 if(nbOfEltInMatrx%nbOfPts!=0)
3073 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 !");
3074 MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfPts*(nbOfCols+delta));
3075 double *retPtr(ret->getPointer());
3076 const double *mPtr(matr->begin()),*aPtr(arr->begin());
3077 for(mcIdType i=0;i<nbOfPts;i++,aPtr+=spaceDimension,mPtr+=nbOfCols)
3079 retPtr=std::copy(mPtr,mPtr+nbOfCols,retPtr);
3081 retPtr=std::copy(aPtr,aPtr+spaceDimension,retPtr);
3087 * \return a newly allocated array having \a isDrift more tuples than \a arr.
3088 * \sa computeVectorOfCoefficients
3090 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec(const DataArrayDouble *arr, mcIdType isDrift)
3092 if(!arr || !arr->isAllocated() || arr->getNumberOfComponents()!=1)
3093 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : input array must be not NULL allocated and with one component !");
3095 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : isDrift parameter must be >=0 !");
3096 MCAuto<DataArrayDouble> arr2(DataArrayDouble::New());
3097 arr2->alloc((arr->getNumberOfTuples()+isDrift)*1,1);
3098 double *work(std::copy(arr->begin(),arr->end(),arr2->getPointer()));
3099 std::fill(work,work+isDrift,0.);
3104 * Starting from a square matrix \a matr, this method returns a newly allocated dense square matrix whose \a matr is included in returned matrix
3105 * in the top left corner, and in the remaining returned matrix the parameters to take into account about the kriging drift.
3106 * For the moment only linear srift is implemented.
3108 * \param [in] arr the position of points were input mesh geometry is considered for Kriging
3109 * \param [in] matr input matrix whose drift part will be added
3110 * \param [out] delta the difference between the size of the output matrix and the input matrix \a matr.
3111 * \return a newly allocated matrix bigger than input matrix \a matr.
3112 * \sa MEDCouplingFieldDiscretizationKriging::PerformDriftRect
3114 DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataArrayDouble *matr, const DataArrayDouble *arr, mcIdType& delta) const
3116 std::size_t spaceDimension(arr->getNumberOfComponents());
3117 delta=ToIdType(spaceDimension)+1;
3118 mcIdType szOfMatrix(arr->getNumberOfTuples());
3119 if(szOfMatrix*szOfMatrix!=matr->getNumberOfTuples())
3120 throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::performDrift : invalid size");
3121 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
3122 ret->alloc((szOfMatrix+delta)*(szOfMatrix+delta),1);
3123 const double *srcWork=matr->getConstPointer();
3124 const double *srcWork2=arr->getConstPointer();
3125 double *destWork=ret->getPointer();
3126 for(mcIdType i=0;i<szOfMatrix;i++)
3128 destWork=std::copy(srcWork,srcWork+szOfMatrix,destWork);
3129 srcWork+=szOfMatrix;
3131 destWork=std::copy(srcWork2,srcWork2+spaceDimension,destWork);
3132 srcWork2+=spaceDimension;
3134 std::fill(destWork,destWork+szOfMatrix,1.); destWork+=szOfMatrix;
3135 std::fill(destWork,destWork+spaceDimension+1,0.); destWork+=spaceDimension+1;
3136 MCAuto<DataArrayDouble> arrNoI=arr->toNoInterlace();
3137 srcWork2=arrNoI->getConstPointer();
3138 for(std::size_t i=0;i<spaceDimension;i++)
3140 destWork=std::copy(srcWork2,srcWork2+szOfMatrix,destWork);
3141 srcWork2+=szOfMatrix;
3142 std::fill(destWork,destWork+spaceDimension+1,0.);
3143 destWork+=spaceDimension+1;