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