Salome HOME
Merge from V6_main 15/03/2013
[modules/med.git] / src / MEDCouplingCorba / Test / MEDCouplingMeshFieldFactoryComponent.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingMeshFieldFactoryComponent.hxx"
22 #include "MEDCouplingExtrudedMesh.hxx"
23 #include "MEDCouplingFieldDouble.hxx"
24 #include "MEDCouplingFieldTemplate.hxx"
25 #include "MEDCouplingMultiFields.hxx"
26 #include "MEDCouplingFieldOverTime.hxx"
27 #include "MEDCouplingMemArray.hxx"
28 #include "MEDCouplingUMesh.hxx"
29 #include "MEDCouplingCMesh.hxx"
30 #include "MEDCouplingCurveLinearMesh.hxx"
31
32 #include <cmath>
33 #include <algorithm>
34
35 namespace SALOME_TEST
36 {
37   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::build1DMesh()
38   {
39     double coords[4]={ 0.0, 0.3, 0.75, 1.0 };
40     int conn[2*3]={ 0,1, 1,2, 2,3 };
41     ParaMEDMEM::MEDCouplingUMesh *mesh=ParaMEDMEM::MEDCouplingUMesh::New("1DMeshForCorba",1);
42     mesh->setDescription("build1DMesh");
43     mesh->allocateCells(3);
44     mesh->setTime(5.6,7,8);
45     mesh->setTimeUnit("ms");
46     mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
47     mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
48     mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
49     mesh->finishInsertingCells();
50     ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
51     myCoords->alloc(4,1);
52     std::copy(coords,coords+4,myCoords->getPointer());
53     mesh->setCoords(myCoords);
54     myCoords->decrRef();
55     mesh->changeSpaceDimension(3);
56     myCoords=mesh->getCoords();
57     myCoords->setInfoOnComponent(0,"X1D [m]");
58     myCoords->setInfoOnComponent(1,"Y1D [dm]");
59     myCoords->setInfoOnComponent(2,"Z1D [pm]");
60     double center[3]={0.,0.,0.};
61     double vector[3]={0,1,0};
62     mesh->rotate(center,vector,-M_PI/2.);
63     return mesh;
64   }
65
66   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::build2DMesh()
67   {
68     double targetCoords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
69     int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
70     ParaMEDMEM::MEDCouplingUMesh *targetMesh=ParaMEDMEM::MEDCouplingUMesh::New();
71     targetMesh->setMeshDimension(2);
72     targetMesh->setName("MyMesh2D");
73     targetMesh->setDescription("build2DMesh");
74     targetMesh->allocateCells(5);
75     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
76     targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
77     targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
78     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
79     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
80     targetMesh->finishInsertingCells();
81     ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
82     myCoords->alloc(9,2);
83     std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
84     targetMesh->setCoords(myCoords);
85     myCoords->decrRef();
86     return targetMesh;
87   }
88
89   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::build3DMesh()
90   {
91     double targetCoords[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. , 200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
92                               0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50., 50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. , 200., 200., 50. ,
93                               0., 0., 200., 50., 0., 200. , 200., 0., 200.  , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,   0., 200., 200., 50., 200., 200. , 200., 200., 200. };
94     int targetConn[64]={0,1,4,3,9,10,13,12, 1,2,5,4,10,11,14,13, 3,4,7,6,12,13,16,15, 4,5,8,7,13,14,17,16,
95                         9,10,13,12,18,19,22,21, 10,11,14,13,19,20,23,22, 12,13,16,15,21,22,25,24, 13,14,17,16,22,23,26,25};
96     ParaMEDMEM::MEDCouplingUMesh *targetMesh=ParaMEDMEM::MEDCouplingUMesh::New();
97     targetMesh->setMeshDimension(3);
98     targetMesh->setName("MyMesh3D");
99     targetMesh->setDescription("build3DMesh");
100     targetMesh->allocateCells(12);
101     for(int i=0;i<8;i++)
102       targetMesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,targetConn+8*i);
103     targetMesh->finishInsertingCells();
104     ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
105     myCoords->alloc(27,3);
106     std::copy(targetCoords,targetCoords+81,myCoords->getPointer());
107     targetMesh->setCoords(myCoords);
108     myCoords->setName("check in case");
109     myCoords->decrRef();
110     return targetMesh;
111   }
112
113   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::build3DSurfMesh()
114   {
115     double targetCoords[27]={-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5};
116     int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
117     ParaMEDMEM::MEDCouplingUMesh *targetMesh=ParaMEDMEM::MEDCouplingUMesh::New();
118     targetMesh->setMeshDimension(2);
119     targetMesh->setName("MyMesh3DSurf");
120     targetMesh->setDescription("build3DSurfMesh");
121     targetMesh->allocateCells(5);
122     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
123     targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
124     targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
125     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
126     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
127     targetMesh->finishInsertingCells();
128     ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
129     myCoords->alloc(9,3);
130     std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
131     targetMesh->setCoords(myCoords);
132     myCoords->setInfoOnComponent(0,"X [m]");
133     myCoords->setInfoOnComponent(1,"X [dm]");
134     myCoords->setInfoOnComponent(2,"X [m]");
135     myCoords->decrRef();
136     return targetMesh;
137   }
138
139   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::build0DMesh()
140   {
141     double targetCoords[27]={-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5};
142     const int targetConn[]={0,1,2,3,4,5,7,6};
143     ParaMEDMEM::MEDCouplingUMesh *targetMesh=ParaMEDMEM::MEDCouplingUMesh::New();
144     targetMesh->setMeshDimension(0);
145     targetMesh->allocateCells(8);
146     targetMesh->setName("Wonderfull 0D mesh");
147     targetMesh->setDescription("build0DMesh");
148     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
149     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
150     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
151     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
152     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
153     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
154     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
155     targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
156     targetMesh->finishInsertingCells();
157     ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
158     myCoords->alloc(9,3);
159     std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
160     targetMesh->setCoords(myCoords);
161     myCoords->setInfoOnComponent(0,"X [m]");
162     myCoords->setInfoOnComponent(1,"YY [Pm]");
163     myCoords->setInfoOnComponent(2,"ZZZ [m]");
164     myCoords->decrRef();
165     //
166     targetMesh->checkCoherency();
167     return targetMesh;
168   }
169
170   ParaMEDMEM::MEDCouplingUMesh *MEDCouplingCorbaServBasicsTest::buildM1DMesh()
171   {
172     ParaMEDMEM::MEDCouplingUMesh *meshM1D=ParaMEDMEM::MEDCouplingUMesh::New("wonderfull -1 D mesh",-1);
173     meshM1D->setDescription("buildM1DMesh");
174     meshM1D->checkCoherency();
175     return meshM1D;
176   }
177
178   ParaMEDMEM::MEDCouplingExtrudedMesh *MEDCouplingCorbaServBasicsTest::buildExtrudedMesh(ParaMEDMEM::MEDCouplingUMesh *&m2D)
179   {
180     m2D=build2DMesh();
181     m2D->changeSpaceDimension(3);
182     ParaMEDMEM::MEDCouplingUMesh *m1D=build1DMesh();
183     ParaMEDMEM::MEDCouplingUMesh *retu=m2D->buildExtrudedMesh(m1D,0);
184     m1D->decrRef();
185     ParaMEDMEM::MEDCouplingExtrudedMesh *ret=ParaMEDMEM::MEDCouplingExtrudedMesh::New(retu,m2D,2);
186     ret->setName("ExtrudedTestForCorbaTest");
187     ret->setDescription("buildExtrudedMesh");
188     retu->decrRef();
189     return ret;
190   }
191
192   ParaMEDMEM::MEDCouplingCMesh *MEDCouplingCorbaServBasicsTest::buildCMesh()
193   {
194     ParaMEDMEM::MEDCouplingCMesh *targetMesh=ParaMEDMEM::MEDCouplingCMesh::New();
195     targetMesh->setTime(2.3,4,5);
196     targetMesh->setTimeUnit("us");
197     targetMesh->setName("Example of CMesh");
198     targetMesh->setDescription("buildCMesh");
199     ParaMEDMEM::DataArrayDouble *a1=ParaMEDMEM::DataArrayDouble::New();
200     a1->alloc(5,1);
201     a1->setInfoOnComponent(0,"SmthX");
202     const double a1Data[5]={3.,4.,5.,6.,7.};
203     std::copy(a1Data,a1Data+5,a1->getPointer());
204     ParaMEDMEM::DataArrayDouble *a2=ParaMEDMEM::DataArrayDouble::New();
205     a2->alloc(6,1);
206     a2->setInfoOnComponent(0,"SmthZ");
207     const double a2Data[6]={2.78,3.,4.,5.,6.,7.};
208     std::copy(a2Data,a2Data+6,a2->getPointer());
209     //
210     targetMesh->setCoordsAt(0,a1);
211     targetMesh->setCoordsAt(2,a2);
212     //
213     a1->decrRef();
214     a2->decrRef();
215     //
216     targetMesh->checkCoherency();
217     //
218     return targetMesh;
219   }
220
221   ParaMEDMEM::MEDCouplingCurveLinearMesh *MEDCouplingCorbaServBasicsTest::buildCLMesh()
222   {
223     ParaMEDMEM::MEDCouplingCurveLinearMesh *targetMesh=ParaMEDMEM::MEDCouplingCurveLinearMesh::New();
224     targetMesh->setTime(2.3,4,5);
225     targetMesh->setTimeUnit("us");
226     targetMesh->setName("Example of Cuve linear mesh");
227     targetMesh->setDescription("buildCLMesh");
228     ParaMEDMEM::DataArrayDouble *a1=ParaMEDMEM::DataArrayDouble::New();
229     a1->alloc(3*20,1);
230     a1->iota(7.);
231     a1->rearrange(3);
232     targetMesh->setCoords(a1);
233     a1->decrRef();
234     int structure[2]={4,5};
235     targetMesh->setNodeGridStructure(structure,structure+2);
236     //
237     targetMesh->checkCoherency();
238     //
239     return targetMesh;
240   }
241
242   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldScalarOn2DNT()
243   {
244     ParaMEDMEM::MEDCouplingUMesh *mesh=build2DMesh();
245     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
246     fieldOnCells->setTimeUnit("ms");
247     fieldOnCells->setName("toto");
248     fieldOnCells->setMesh(mesh);
249     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
250     array->alloc(mesh->getNumberOfCells(),6);
251     fieldOnCells->setArray(array);
252     double *tmp=array->getPointer();
253     array->decrRef();
254     std::fill(tmp,tmp+mesh->getNumberOfCells()*6,7.);
255     mesh->decrRef();
256     fieldOnCells->checkCoherency();
257     return fieldOnCells;
258   }
259
260   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldNodeScalarOn2DNT()
261   {
262     ParaMEDMEM::MEDCouplingUMesh *mesh=build2DMesh();
263     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnNodes=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::NO_TIME);
264     fieldOnNodes->setName("toto2");
265     fieldOnNodes->setTimeUnit("s");
266     fieldOnNodes->setDescription("my wonderful field toto2");
267     fieldOnNodes->setMesh(mesh);
268     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
269     array->alloc(mesh->getNumberOfNodes(),5);
270     fieldOnNodes->setArray(array);
271     double *tmp=array->getPointer();
272     array->decrRef();
273     std::fill(tmp,tmp+mesh->getNumberOfNodes()*5,7.1234);
274     mesh->decrRef();
275     fieldOnNodes->checkCoherency();
276     return fieldOnNodes;
277   }
278
279   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldScalarOn3DNT()
280   {
281     ParaMEDMEM::MEDCouplingUMesh *mesh=build3DMesh();
282     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
283     fieldOnCells->setNature(ParaMEDMEM::ConservativeVolumic);
284     fieldOnCells->setName("toto");
285     fieldOnCells->setDescription("my wonderful 3D field toto2");
286     fieldOnCells->setMesh(mesh);
287     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
288     array->alloc(mesh->getNumberOfCells(),6);
289     fieldOnCells->setArray(array);
290     double *tmp=array->getPointer();
291     array->decrRef();
292     std::fill(tmp,tmp+mesh->getNumberOfCells()*6,7.);
293     mesh->decrRef();
294     fieldOnCells->checkCoherency();
295     return fieldOnCells;
296   }
297
298   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldScalarOn3DSurfWT()
299   {
300     ParaMEDMEM::MEDCouplingUMesh *mesh=build3DSurfMesh();
301     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
302     fieldOnCells->setName("toto25");
303     fieldOnCells->setDescription("my wonderful 3D surf field toto25");
304     fieldOnCells->setTimeUnit("us");
305     fieldOnCells->setMesh(mesh);
306     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
307     array->alloc(mesh->getNumberOfCells(),3);
308     array->setInfoOnComponent(0,"aaa"); array->setInfoOnComponent(1,"bbbb"); array->setInfoOnComponent(2,"ccccc");
309     fieldOnCells->setArray(array);
310     double *tmp=array->getPointer();
311     array->decrRef();
312     std::fill(tmp,tmp+mesh->getNumberOfCells()*3,7.);
313     mesh->decrRef();
314     fieldOnCells->setTime(6.7,1,4);
315     fieldOnCells->checkCoherency();
316     return fieldOnCells;
317   }
318
319   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldScalarOn3DSurfCOTI()
320   {
321     ParaMEDMEM::MEDCouplingUMesh *mesh=build3DSurfMesh();
322     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
323     fieldOnCells->setName("toto26");
324     fieldOnCells->setDescription("my wonderful 3D surf field toto26");
325     fieldOnCells->setTimeUnit("us");
326     fieldOnCells->setMesh(mesh);
327     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
328     array->alloc(mesh->getNumberOfCells(),3);
329     fieldOnCells->setArray(array);
330     double *tmp=array->getPointer();
331     array->decrRef();
332     std::fill(tmp,tmp+mesh->getNumberOfCells()*3,7.);
333     mesh->decrRef();
334     fieldOnCells->setStartTime(6.7,1,4);
335     fieldOnCells->setEndTime(7.2,2,8);
336     fieldOnCells->checkCoherency();
337     return fieldOnCells;
338   }
339
340   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldScalarOn2DLT()
341   {
342     ParaMEDMEM::MEDCouplingUMesh *mesh=build2DMesh();
343     ParaMEDMEM::MEDCouplingFieldDouble *fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::LINEAR_TIME);
344     fieldOnCells->setName("toto27");
345     fieldOnCells->setDescription("my wonderful 2D field toto27");
346     fieldOnCells->setTimeUnit("ms");
347     fieldOnCells->setMesh(mesh);
348     ParaMEDMEM::DataArrayDouble *array1=ParaMEDMEM::DataArrayDouble::New();
349     array1->alloc(mesh->getNumberOfCells(),4);
350     fieldOnCells->setArray(array1);
351     double *tmp=array1->getPointer();
352     array1->decrRef();
353     const double arr1[20]={1.2,1.02,1.002,1.0002, 3.4,3.04,3.004,3.0004, 5.6,5.06,5.006,5.0006, 7.8,7.08,7.008,7.0008, 9.1,9.01,9.001,9.0001};
354     std::copy(arr1,arr1+20,tmp);
355     ParaMEDMEM::DataArrayDouble *array2=ParaMEDMEM::DataArrayDouble::New();
356     array2->alloc(mesh->getNumberOfCells(),4);
357     fieldOnCells->setEndArray(array2);
358     tmp=array2->getPointer();
359     array2->decrRef();
360     mesh->decrRef();
361     const double arr2[20]={71.2,71.02,71.002,71.0002, 73.4,73.04,73.004,73.0004, 75.6,75.06,75.006,75.0006, 77.8,77.08,77.008,77.0008, 79.1,79.01,79.001,79.0001};
362     std::copy(arr2,arr2+20,tmp);
363     fieldOnCells->setStartTime(6.7,25,26);
364     fieldOnCells->setEndTime(17.2,125,126);
365     fieldOnCells->checkCoherency();
366     return fieldOnCells;
367   }
368
369   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldGaussPt2DWT()
370   {
371     const double _a=0.446948490915965;
372     const double _b=0.091576213509771;
373     const double _p1=0.11169079483905;
374     const double _p2=0.0549758718227661;
375     const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
376     const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
377                               2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
378     const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
379     std::vector<double> _refCoo1(refCoo1,refCoo1+6);
380     std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
381     std::vector<double> _wg1(wg1,wg1+6);
382     ParaMEDMEM::MEDCouplingUMesh *m=build2DMesh();
383     ParaMEDMEM::MEDCouplingFieldDouble *f=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_GAUSS_PT,ParaMEDMEM::ONE_TIME);
384     f->setTime(6.7,1,4);
385     f->setMesh(m);
386     m->decrRef();
387     f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
388     const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
389     std::vector<double> _refCoo2(refCoo2,refCoo2+8);
390     _gsCoo1.resize(4); _wg1.resize(2);
391     f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
392     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
393     array->alloc(18,2);
394     array->setInfoOnComponent(0,"Power [MW]");
395     array->setInfoOnComponent(1,"Density [kg/m^3]");
396     double *ptr=array->getPointer();
397     for(int i=0;i<18*2;i++)
398       ptr[i]=(double)(i+1);
399     f->setArray(array);
400     f->setName("MyFirstFieldOnGaussPoint");
401     f->setTimeUnit("ms");
402     f->setDescription("mmmmmmmmmmmm");
403     array->decrRef();
404     f->checkCoherency();
405     return f;
406   }
407
408   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldGaussPtNE2DWT()
409   {
410     ParaMEDMEM::MEDCouplingUMesh *m=build2DMesh();
411     ParaMEDMEM::MEDCouplingFieldDouble *f=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_GAUSS_NE,ParaMEDMEM::ONE_TIME);
412     f->setTime(6.8,11,8);
413     f->setMesh(m);
414     f->setTimeUnit("ms");
415     f->setName("MyFirstFieldOnNE");
416     f->setDescription("MyDescriptionNE");
417     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
418     array->alloc(18,2);
419     array->setInfoOnComponent(0,"Power [MW]");
420     array->setInfoOnComponent(1,"Density [kg/m^3]");
421     double *ptr=array->getPointer();
422     for(int i=0;i<18*2;i++)
423       ptr[i]=(double)(i+7);
424     f->setArray(array);
425     array->decrRef();
426     //
427     f->checkCoherency();
428     m->decrRef();
429     return f;
430   }
431
432   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldVectorOnExtrudedWT()
433   {
434     ParaMEDMEM::MEDCouplingUMesh *m2D=0;
435     ParaMEDMEM::MEDCouplingExtrudedMesh *ext=buildExtrudedMesh(m2D);
436     //
437     ParaMEDMEM::MEDCouplingFieldDouble *f=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
438     f->setTime(6.8,11,8);
439     f->setMesh(ext);
440     f->setName("MyFieldOnExtruM");
441     f->setDescription("desc of MyFiOnExtruM");
442     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
443     int nbOfCells=ext->getNumberOfCells();
444     array->alloc(nbOfCells,2);
445     array->setInfoOnComponent(0,"Power [MW]");
446     array->setInfoOnComponent(1,"Density [kg/m^3]");
447     double *ptr=array->getPointer();
448     for(int i=0;i<nbOfCells*2;i++)
449       ptr[i]=(double)(i/2+7)+(double)((i%2)*1000);
450     f->setArray(array);
451     array->decrRef();
452     //
453     f->checkCoherency();
454     //
455     m2D->decrRef();
456     ext->decrRef();
457     return f;
458   }
459
460   ParaMEDMEM::MEDCouplingFieldDouble *MEDCouplingCorbaServBasicsTest::buildFieldVectorOnCMeshWT()
461   {
462     ParaMEDMEM::MEDCouplingCMesh *m=buildCMesh();
463     ParaMEDMEM::MEDCouplingFieldDouble *f=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
464     f->setTime(6.8,11,8);
465     f->setMesh(m);
466     m->decrRef();
467     f->setName("MyFieldOnCMesh");
468     f->setDescription("desc of MyFiOnCMesh");
469     ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
470     int nbOfCells=m->getNumberOfCells();
471     array->alloc(nbOfCells,2);
472     array->setInfoOnComponent(0,"Power [GW]");
473     array->setInfoOnComponent(1,"Density [kg/m^3]");
474     double *ptr=array->getPointer();
475     for(int i=0;i<nbOfCells*2;i++)
476       ptr[i]=(double)(i/2+7)+(double)((i%2)*1000);
477     f->setArray(array);
478     array->decrRef();
479     //
480     f->checkCoherency();
481     //
482     return f;
483   }
484
485   ParaMEDMEM::MEDCouplingFieldTemplate *MEDCouplingCorbaServBasicsTest::buildFieldTemplateCellOn2D()
486   {
487     ParaMEDMEM::MEDCouplingFieldDouble *f1=buildFieldScalarOn2DNT();
488     ParaMEDMEM::MEDCouplingFieldTemplate *f2=ParaMEDMEM::MEDCouplingFieldTemplate::New(*f1);
489     f2->setNature(ParaMEDMEM::NoNature);
490     f1->decrRef();
491     return f2;
492   }
493
494   ParaMEDMEM::MEDCouplingFieldTemplate *MEDCouplingCorbaServBasicsTest::buildFieldTemplateNodeOn2D()
495   {
496     ParaMEDMEM::MEDCouplingFieldDouble *f1=buildFieldNodeScalarOn2DNT();
497     ParaMEDMEM::MEDCouplingFieldTemplate *f2=ParaMEDMEM::MEDCouplingFieldTemplate::New(*f1);
498     f2->setNature(ParaMEDMEM::ConservativeVolumic);
499     f1->decrRef();
500     return f2;
501   }
502
503   ParaMEDMEM::MEDCouplingFieldTemplate *MEDCouplingCorbaServBasicsTest::buildFieldTemplateGaussPtOn2D()
504   {
505     ParaMEDMEM::MEDCouplingFieldDouble *f1=buildFieldGaussPt2DWT();
506     ParaMEDMEM::MEDCouplingFieldTemplate *f2=ParaMEDMEM::MEDCouplingFieldTemplate::New(*f1);
507     f2->setNature(ParaMEDMEM::Integral);
508     f1->decrRef();
509     return f2;
510   }
511
512   ParaMEDMEM::MEDCouplingFieldTemplate *MEDCouplingCorbaServBasicsTest::buildFieldTemplateGaussNEOn2D()
513   {
514     ParaMEDMEM::MEDCouplingFieldDouble *f1=buildFieldGaussPtNE2DWT();
515     ParaMEDMEM::MEDCouplingFieldTemplate *f2=ParaMEDMEM::MEDCouplingFieldTemplate::New(*f1);
516     f2->setNature(ParaMEDMEM::IntegralGlobConstraint);
517     f1->decrRef();
518     return f2;
519   }
520
521   ParaMEDMEM::MEDCouplingMultiFields *MEDCouplingCorbaServBasicsTest::buildMultiFields1()
522   {
523     ParaMEDMEM::MEDCouplingUMesh *m1=build2DMesh();
524     m1->setName("m1");
525     ParaMEDMEM::MEDCouplingUMesh *m2=build2DMesh();
526     m2->setName("m2");
527     const double vals0[]={-0.7,-1.,-2.,-3.,-4.};
528     const double vals1[]={0.,1.,2.,3.,4.,0.1,0.2,0.3,0.4};
529     const double vals1_1[]={170.,171.,172.,173.,174.,170.1,170.2,170.3,170.4};
530     const double vals2[]={5.,6.,7.,8.,9.};
531     const double vals4[]={15.,16.,17.,18.,19.};
532     //
533     ParaMEDMEM::DataArrayDouble *d0=ParaMEDMEM::DataArrayDouble::New(); d0->alloc(5,1); std::copy(vals0,vals0+5,d0->getPointer());
534     ParaMEDMEM::DataArrayDouble *d1=ParaMEDMEM::DataArrayDouble::New(); d1->alloc(9,1); std::copy(vals1,vals1+9,d1->getPointer());
535     ParaMEDMEM::DataArrayDouble *d1_1=ParaMEDMEM::DataArrayDouble::New(); d1_1->alloc(9,1); std::copy(vals1_1,vals1_1+9,d1_1->getPointer());
536     ParaMEDMEM::DataArrayDouble *d2=ParaMEDMEM::DataArrayDouble::New(); d2->alloc(5,1); std::copy(vals2,vals2+5,d2->getPointer());
537     ParaMEDMEM::DataArrayDouble *d4=ParaMEDMEM::DataArrayDouble::New(); d4->alloc(5,1); std::copy(vals4,vals4+5,d4->getPointer());
538     //
539     d0->setName("d0"); d1->setName("d1"); d1_1->setName("d1_1"); d2->setName("d2"); d4->setName("d4");
540     d0->setInfoOnComponent(0,"c1");
541     d1->setInfoOnComponent(0,"c6");
542     d1_1->setInfoOnComponent(0,"c9");
543     d2->setInfoOnComponent(0,"c5");
544     d4->setInfoOnComponent(0,"c7");
545     //
546     ParaMEDMEM::MEDCouplingFieldDouble *f0=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
547     f0->setMesh(m1);
548     f0->setArray(d0);
549     f0->setTime(0.2,5,6);
550     f0->setName("f0");
551     ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::LINEAR_TIME);
552     f1->setMesh(m1);
553     std::vector<ParaMEDMEM::DataArrayDouble *> d1s(2); d1s[0]=d1; d1s[1]=d1_1;
554     f1->setArrays(d1s);
555     f1->setStartTime(0.7,7,8);
556     f1->setEndTime(1.2,9,10);
557     f1->setName("f1");
558     ParaMEDMEM::MEDCouplingFieldDouble *f2=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
559     f2->setMesh(m2);
560     f2->setArray(d2);
561     f2->setTime(1.2,11,12);
562     f2->setEndTime(1.5,13,14);
563     f2->setName("f2");
564     ParaMEDMEM::MEDCouplingFieldDouble *f3=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
565     f3->setMesh(m1);
566     f3->setArray(d2);
567     f3->setTime(1.7,15,16);
568     f3->setName("f3");
569     ParaMEDMEM::MEDCouplingFieldDouble *f4=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
570     f4->setMesh(m2);
571     f4->setArray(d4);
572     f4->setName("f4");
573     //
574     std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> fs(5);
575     fs[0]=f0; fs[1]=f1; fs[2]=f2; fs[3]=f3; fs[4]=f4;
576     ParaMEDMEM::MEDCouplingMultiFields *ret=ParaMEDMEM::MEDCouplingMultiFields::New(fs);
577     //
578     m1->decrRef();
579     m2->decrRef();
580     d0->decrRef();
581     d1->decrRef();
582     d1_1->decrRef();
583     d2->decrRef();
584     d4->decrRef();
585     f0->decrRef();
586     f1->decrRef();
587     f2->decrRef();
588     f3->decrRef();
589     f4->decrRef();
590     //
591     return ret;
592   }
593
594   ParaMEDMEM::DataArrayDouble *MEDCouplingCorbaServBasicsTest::buildArrayDouble1()
595   {
596     ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
597     ret->alloc(4,3);
598     const double vals[12]={2.4,3.2,5.6,9.6,47.6,20.4,24.6,278.1,2.01,3.3,2.4,9.4};
599     std::copy(vals,vals+12,ret->getPointer());
600     ret->setName("toto");
601     ret->setInfoOnComponent(0,"sss");
602     ret->setInfoOnComponent(1,"ppp");
603     ret->setInfoOnComponent(2,"ttt");
604     return ret;
605   }
606
607   ParaMEDMEM::DataArrayDouble *MEDCouplingCorbaServBasicsTest::buildArrayDouble2()
608   {
609     ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
610     ret->setName("titi");
611     return ret;
612   }
613
614   ParaMEDMEM::DataArrayDouble *MEDCouplingCorbaServBasicsTest::buildArrayDouble3()
615   {
616     ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
617     ret->setName("titi");
618     ret->alloc(0,3);
619     ret->setInfoOnComponent(0,"sss");
620     ret->setInfoOnComponent(1,"ppp");
621     ret->setInfoOnComponent(2,"ttt");
622     return ret;
623   }
624
625   ParaMEDMEM::DataArrayInt *MEDCouplingCorbaServBasicsTest::buildArrayInt1()
626   {
627     ParaMEDMEM::DataArrayInt *ret=ParaMEDMEM::DataArrayInt::New();
628     ret->alloc(4,3);
629     const int vals[12]={2,3,5,9,47,20,24,278,2,3,2,9};
630     std::copy(vals,vals+12,ret->getPointer());
631     ret->setName("toto");
632     ret->setInfoOnComponent(0,"sss");
633     ret->setInfoOnComponent(1,"ppp");
634     ret->setInfoOnComponent(2,"ttt");
635     return ret;
636   }
637
638   ParaMEDMEM::DataArrayInt *MEDCouplingCorbaServBasicsTest::buildArrayInt2()
639   {
640     ParaMEDMEM::DataArrayInt *ret=ParaMEDMEM::DataArrayInt::New();
641     ret->setName("titi");
642     return ret;
643   }
644
645   ParaMEDMEM::DataArrayInt *MEDCouplingCorbaServBasicsTest::buildArrayInt3()
646   {
647     ParaMEDMEM::DataArrayInt *ret=ParaMEDMEM::DataArrayInt::New();
648     ret->setName("titi");
649     ret->alloc(0,3);
650     ret->setInfoOnComponent(0,"sss");
651     ret->setInfoOnComponent(1,"ppp");
652     ret->setInfoOnComponent(2,"ttt");
653     return ret;
654   }
655
656   ParaMEDMEM::MEDCouplingFieldOverTime *MEDCouplingCorbaServBasicsTest::buildMultiFields2()
657   {
658     ParaMEDMEM::MEDCouplingUMesh *m1=build2DMesh();
659     m1->setName("m1");
660     ParaMEDMEM::MEDCouplingUMesh *m2=build2DMesh();
661     m2->setName("m2");
662     const double vals0[]={-0.7,-1.,-2.,-3.,-4.};
663     const double vals1[]={0.,1.,2.,3.,4.};
664     const double vals1_1[]={170.,171.,172.,173.,174.};
665     const double vals2[]={5.,6.,7.,8.,9.};
666     const double vals4[]={15.,16.,17.,18.,19.};
667     //
668     ParaMEDMEM::DataArrayDouble *d0=ParaMEDMEM::DataArrayDouble::New(); d0->alloc(5,1); std::copy(vals0,vals0+5,d0->getPointer());
669     ParaMEDMEM::DataArrayDouble *d1=ParaMEDMEM::DataArrayDouble::New(); d1->alloc(5,1); std::copy(vals1,vals1+5,d1->getPointer());
670     ParaMEDMEM::DataArrayDouble *d1_1=ParaMEDMEM::DataArrayDouble::New(); d1_1->alloc(5,1); std::copy(vals1_1,vals1_1+5,d1_1->getPointer());
671     ParaMEDMEM::DataArrayDouble *d2=ParaMEDMEM::DataArrayDouble::New(); d2->alloc(5,1); std::copy(vals2,vals2+5,d2->getPointer());
672     ParaMEDMEM::DataArrayDouble *d4=ParaMEDMEM::DataArrayDouble::New(); d4->alloc(5,1); std::copy(vals4,vals4+5,d4->getPointer());
673     //
674     d0->setName("d0"); d1->setName("d1"); d1_1->setName("d1_1"); d2->setName("d2"); d4->setName("d4");
675     d0->setInfoOnComponent(0,"c1");
676     d1->setInfoOnComponent(0,"c6");
677     d1_1->setInfoOnComponent(0,"c9");
678     d2->setInfoOnComponent(0,"c5");
679     d4->setInfoOnComponent(0,"c7");
680     //
681     ParaMEDMEM::MEDCouplingFieldDouble *f0=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
682     f0->setMesh(m1);
683     f0->setArray(d0);
684     f0->setTime(0.2,5,6);
685     f0->setName("f0");
686     ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::LINEAR_TIME);
687     f1->setMesh(m1);
688     std::vector<ParaMEDMEM::DataArrayDouble *> d1s(2); d1s[0]=d1; d1s[1]=d1_1;
689     f1->setArrays(d1s);
690     f1->setStartTime(0.7,7,8);
691     f1->setEndTime(1.2,9,10);
692     f1->setName("f1");
693     ParaMEDMEM::MEDCouplingFieldDouble *f2=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
694     f2->setMesh(m2);
695     f2->setArray(d2);
696     f2->setTime(1.2,11,12);
697     f2->setEndTime(1.5,13,14);
698     f2->setName("f2");
699     ParaMEDMEM::MEDCouplingFieldDouble *f3=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
700     f3->setMesh(m1);
701     f3->setArray(d2);
702     f3->setTime(1.7,15,16);
703     f3->setName("f3");
704     ParaMEDMEM::MEDCouplingFieldDouble *f4=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
705     f4->setMesh(m2);
706     f4->setArray(d4);
707     f4->setName("f4");
708     f4->setTime(2.7,25,26);
709     //
710     std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> fs(5);
711     fs[0]=f0; fs[1]=f1; fs[2]=f2; fs[3]=f3; fs[4]=f4;
712     ParaMEDMEM::MEDCouplingFieldOverTime *ret=ParaMEDMEM::MEDCouplingFieldOverTime::New(fs);
713     ret->checkCoherency();
714     //
715     m1->decrRef();
716     m2->decrRef();
717     d0->decrRef();
718     d1->decrRef();
719     d1_1->decrRef();
720     d2->decrRef();
721     d4->decrRef();
722     f0->decrRef();
723     f1->decrRef();
724     f2->decrRef();
725     f3->decrRef();
726     f4->decrRef();
727     //
728     return ret;
729   }
730
731   std::string MEDCouplingCorbaServBasicsTest::buildFileNameForIOR()
732   {
733     std::string ret;
734     ret+=getenv("TMP");
735     ret+="/entryPointMEDCouplingCorba.ior";
736     return ret;
737   }
738 }