Back to index

salome-med  6.5.0
ParaMEDMEMTest_Gauthier1.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "ParaMEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 
00023 #include <string>
00024 #include "CommInterface.hxx"
00025 #include "ProcessorGroup.hxx"
00026 #include "MPIProcessorGroup.hxx"
00027 #include "DEC.hxx"
00028 #include "InterpKernelDEC.hxx"
00029 #include <set>
00030 #include <time.h>
00031 #include "ICoCoTrioField.hxx"
00032 #include <iostream>
00033 #include <assert.h>
00034 #include <math.h>
00035 
00036 using namespace std;
00037 using namespace ParaMEDMEM;
00038 using namespace ICoCo;
00039 
00040 void afficheGauthier1( const TrioField&   field, const double *vals, int lgth)
00041 {
00042   CPPUNIT_ASSERT_EQUAL(lgth,field._nb_elems);
00043   for (int ele=0;ele<field._nb_elems;ele++)
00044     CPPUNIT_ASSERT_DOUBLES_EQUAL(vals[ele],field._field[ele],1e-12);
00045 }
00046 
00047 void remplit_coordGauthier1(double* coords)
00048 {
00049   double angle,epaisseur;
00050   angle=0*45*(asin(1.)/90);
00051   epaisseur=1e-0;
00052   coords[0*3+0]=0.;
00053   coords[0*3+1]=0.;
00054   coords[0*3+2]=0.;
00055   
00056   coords[1*3+0]=cos(angle);
00057   coords[1*3+1]=0.;
00058   coords[1*3+2]=sin(angle);
00059   
00060     
00061   coords[2*3+0]=-sin(angle);
00062   coords[2*3+1]=0.;
00063   coords[2*3+2]=cos(angle);
00064   
00065   for (int d=0;d<3;d++)
00066     coords[3*3+d]=coords[1*3+d]+ coords[2*3+d];
00067   
00068   for (int i=4;i<8;i++)
00069     {
00070       for (int d=0;d<3;d++)
00071         coords[i*3+d]=coords[(i-4)*3+d];
00072       coords[i*3+1]+=epaisseur;
00073     }
00074 
00075 }
00076 
00077 void init_quadGauthier1(TrioField& champ_quad,int is_master)
00078 {
00079   
00080   champ_quad.setName("champ_quad");
00081   champ_quad._space_dim=3;
00082   champ_quad._mesh_dim=2;
00083   champ_quad._nodes_per_elem=4;
00084   champ_quad._itnumber=0;
00085   champ_quad._time1=0;
00086   champ_quad._time2=1;
00087   champ_quad._nb_field_components=1;
00088 
00089   if (is_master)
00090     {
00091       champ_quad._nbnodes=8;
00092       champ_quad._nb_elems=2;
00093       
00094       champ_quad._coords=new double[champ_quad._nbnodes*champ_quad._space_dim];
00095       //memcpy(afield._coords,sommets.addr(),champ_quad._nbnodes*champ_quad._space_dim*sizeof(double));
00096       
00097       remplit_coordGauthier1(champ_quad._coords);
00098   
00099   
00100       champ_quad._connectivity=new int[champ_quad._nb_elems*champ_quad._nodes_per_elem];
00101       champ_quad._connectivity[0*champ_quad._nodes_per_elem+0]=0;
00102       champ_quad._connectivity[0*champ_quad._nodes_per_elem+1]=1;
00103       champ_quad._connectivity[0*champ_quad._nodes_per_elem+2]=3;
00104       champ_quad._connectivity[0*champ_quad._nodes_per_elem+3]=2;
00105       champ_quad._connectivity[1*champ_quad._nodes_per_elem+0]=4;
00106       champ_quad._connectivity[1*champ_quad._nodes_per_elem+1]=5;
00107       champ_quad._connectivity[1*champ_quad._nodes_per_elem+2]=7;
00108       champ_quad._connectivity[1*champ_quad._nodes_per_elem+3]=6;
00109       
00110     }
00111   else
00112     {
00113       champ_quad._nbnodes=0;
00114       champ_quad._nb_elems=0;
00115       champ_quad._coords=new double[champ_quad._nbnodes*champ_quad._space_dim];
00116     
00117     }
00118   champ_quad._has_field_ownership=false;
00119   champ_quad._field=0;
00120   //champ_quad._field=new double[champ_quad._nb_elems];
00121   //  assert(champ_quad._nb_field_components==1);
00122 }
00123 void init_triangleGauthier1(TrioField& champ_triangle,int is_master)
00124 {
00125    
00126   champ_triangle.setName("champ_triangle");
00127   champ_triangle._space_dim=3;
00128   champ_triangle._mesh_dim=2;
00129   champ_triangle._nodes_per_elem=3;
00130   champ_triangle._itnumber=0;
00131   champ_triangle._time1=0;
00132   champ_triangle._time2=1;
00133   champ_triangle._nb_field_components=1;
00134 
00135   if (is_master)
00136     {
00137       champ_triangle._nb_elems=4;
00138       champ_triangle._nbnodes=8;
00139     
00140       champ_triangle._coords=new double[champ_triangle._nbnodes*champ_triangle._space_dim];
00141       //memcpy(afield._coords,sommets.addr(),champ_triangle._nbnodes*champ_triangle._space_dim*sizeof(double));
00142       remplit_coordGauthier1(champ_triangle._coords);
00143       
00144       champ_triangle._connectivity=new int[champ_triangle._nb_elems*champ_triangle._nodes_per_elem];
00145       champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+0]=0;
00146       champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+1]=1;
00147       champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+2]=2;
00148       champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+0]=1;
00149       champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+1]=2;
00150       champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+2]=3;
00151       
00152       champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+0]=4;
00153       champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+1]=5;
00154       champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+2]=7;
00155       champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+0]=4;
00156       champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+1]=6;
00157       champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+2]=7;
00158     }
00159   else
00160     {
00161       champ_triangle._nb_elems=0;
00162       champ_triangle._nbnodes=0;
00163       champ_triangle._coords=new double[champ_triangle._nbnodes*champ_triangle._space_dim];
00164     
00165     }
00166   champ_triangle._has_field_ownership=false;
00167   // champ_triangle._field=new double[champ_triangle._nb_elems];
00168   champ_triangle._field=0;
00169   
00170 }
00171 
00172 
00173 void ParaMEDMEMTest::testGauthier1()
00174 {
00175   int num_cas=0;
00176   int rank, size;
00177   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00178   MPI_Comm_size(MPI_COMM_WORLD,&size);
00179   
00180   int is_master=0;
00181 
00182   CommInterface comm;
00183   set<int> emetteur_ids;
00184   set<int> recepteur_ids;
00185   emetteur_ids.insert(0);
00186   if(size!=4)
00187     return;
00188   recepteur_ids.insert(1);
00189   if (size >2) 
00190     recepteur_ids.insert(2);
00191   if (size >2) 
00192     emetteur_ids.insert(3);
00193   if ((rank==0)||(rank==1)) 
00194     is_master=1;
00195   
00196   MPIProcessorGroup recepteur_group(comm,recepteur_ids);
00197   MPIProcessorGroup emetteur_group(comm,emetteur_ids);
00198 
00199 
00200   string cas;
00201   if (recepteur_group.containsMyRank())
00202     {
00203       cas="recepteur";
00204       //freopen("recpeteur.out","w",stdout);
00205       //freopen("recepteur.err","w",stderr);
00206       
00207     }
00208   else
00209     {
00210       cas="emetteur";
00211       // freopen("emetteur.out","w",stdout);
00212       //freopen("emetteur.err","w",stderr);
00213     }
00214   double expected[8][4]={
00215     {1.,1.,1.,1.},
00216     {40., 40., 1., 1.},
00217     {1.,1.,1e200,1e200},
00218     {40.,1.,1e200,1e200},
00219     {1.,1.,1.,1.},
00220     {40.,1.,1.,1.},
00221     {1.,1.,1e200,1e200},
00222     {20.5,1.,1e200,1e200}
00223   };
00224 
00225   int expectedLgth[8]={4,4,2,2,4,4,2,2};
00226   
00227   for (int send=0;send<2;send++)
00228     for (int rec=0;rec<2;rec++)
00229       {
00230         InterpKernelDEC dec_emetteur(emetteur_group, recepteur_group);
00231         dec_emetteur.setOrientation(2);
00232         TrioField champ_emetteur, champ_recepteur;
00233    
00234         if (send==0)
00235           init_quadGauthier1(champ_emetteur,is_master);
00236         else
00237           init_triangleGauthier1(champ_emetteur,is_master);
00238         if (rec==0)
00239           init_triangleGauthier1(champ_recepteur,is_master);
00240         else
00241           init_quadGauthier1(champ_recepteur,is_master);
00242   
00243         if (cas=="emetteur") 
00244           {
00245             champ_emetteur._field=new double[champ_emetteur._nb_elems];
00246             for (int ele=0;ele<champ_emetteur._nb_elems;ele++)
00247               champ_emetteur._field[ele]=1;
00248       
00249             champ_emetteur._has_field_ownership=true;
00250           }
00251   
00252   
00253         MPI_Barrier(MPI_COMM_WORLD);
00254 
00255         //clock_t clock0= clock ();
00256         int compti=0;
00257 
00258         bool init=true; // first time step ??
00259         bool stop=false;
00260         //boucle sur les pas de quads
00261         while (!stop) {
00262   
00263           compti++;
00264           //clock_t clocki= clock ();
00265           //cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl; 
00266           for (int non_unif=0;non_unif<2;non_unif++)
00267             {
00268               // if (champ_recepteur._field)
00269               //   delete [] champ_recepteur._field;
00270               champ_recepteur._field=0;
00271               // champ_recepteur._has_field_ownership=false;
00272   
00273 
00274   
00275               if (cas=="emetteur") 
00276                 {
00277                   if (non_unif)
00278                     if(rank!=3)
00279                       champ_emetteur._field[0]=40;
00280                 }
00281               //bool ok=false; // Is the time interval successfully solved ?
00282     
00283               // Loop on the time interval tries
00284               if(1) {
00285       
00286 
00287                 if (cas=="emetteur")
00288                   dec_emetteur.attachLocalField((ICoCo::Field*) &champ_emetteur);
00289                 else
00290                   dec_emetteur.attachLocalField((ICoCo::Field*) &champ_recepteur);
00291 
00292 
00293                 if(init) dec_emetteur.synchronize();
00294                 init=false;
00295 
00296                 if (cas=="emetteur") {
00297                   //    affiche(champ_emetteur);
00298                   dec_emetteur.sendData();
00299                 }
00300                 else if (cas=="recepteur")
00301                   {
00302                     dec_emetteur.recvData();
00303                     if (is_master)
00304                       afficheGauthier1(champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
00305                   }
00306                 else
00307                   throw 0;
00308                 MPI_Barrier(MPI_COMM_WORLD);
00309               }
00310               stop=true;
00311               num_cas++;
00312             }
00313           // destruction des champs, des DEC, et des tableaux associés
00314         }
00315       }
00316 }
00317 
00318 void ParaMEDMEMTest::testGauthier2()
00319 {
00320   const char save_vit_in_2[]="VITESSE_P1_OUT\n1\n2\n3\n63\n3\n80\n0\n 0 1 2\n 3 4 5\n 6 7 8\n 9 10 11\n 12 13 14\n 15 16 17\n 18 19 20\n 21 22 23\n 24 25 26\n 27 28 29\n 30 2 1\n 31 5 4\n 32 8 7\n 33 11 10\n 34 14 13\n 35 17 16\n 36 20 19\n 37 23 22\n 38 26 25\n 39 29 28\n 30 40 2\n 31 41 5\n 32 42 8\n 33 43 11\n 34 44 14\n 35 45 17\n 36 46 20\n 37 47 23\n 38 48 26\n 39 49 29\n 31 2 40\n 32 5 41\n 33 8 42\n 34 11 43\n 35 14 44\n 36 17 45\n 37 20 46\n 38 23 47\n 39 26 48\n 50 29 49\n 3 2 4\n 6 5 7\n 9 8 10\n 12 11 13\n 15 14 16\n 18 17 19\n 21 20 22\n 24 23 25\n 27 26 28\n 51 29 52\n 31 4 2\n 32 7 5\n 33 10 8\n 34 13 11\n 35 16 14\n 36 19 17\n 37 22 20\n 38 25 23\n 39 28 26\n 50 52 29\n 0 2 53\n 3 5 54\n 6 8 55\n 9 11 56\n 12 14 57\n 15 17 58\n 18 20 59\n 21 23 60\n 24 26 61\n 27 29 62\n 3 53 2\n 6 54 5\n 9 55 8\n 12 56 11\n 15 57 14\n 18 58 17\n 21 59 20\n 24 60 23\n 27 61 26\n 51 62 29\n 0 0 0\n 0.5 0 0\n 0.5 0.05 0\n 0 0.1 0\n 0.5 0.1 0\n 0.5 0.15 0\n 0 0.2 0\n 0.5 0.2 0\n 0.5 0.25 0\n 0 0.3 0\n 0.5 0.3 0\n 0.5 0.35 0\n 0 0.4 0\n 0.5 0.4 0\n 0.5 0.45 0\n 0 0.5 0\n 0.5 0.5 0\n 0.5 0.55 0\n 0 0.6 0\n 0.5 0.6 0\n 0.5 0.65 0\n 0 0.7 0\n 0.5 0.7 0\n 0.5 0.75 0\n 0 0.8 0\n 0.5 0.8 0\n 0.5 0.85 0\n 0 0.9 0\n 0.5 0.9 0\n 0.5 0.95 0\n 1 0 0\n 1 0.1 0\n 1 0.2 0\n 1 0.3 0\n 1 0.4 0\n 1 0.5 0\n 1 0.6 0\n 1 0.7 0\n 1 0.8 0\n 1 0.9 0\n 1 0.05 0\n 1 0.15 0\n 1 0.25 0\n 1 0.35 0\n 1 0.45 0\n 1 0.55 0\n 1 0.65 0\n 1 0.75 0\n 1 0.85 0\n 1 0.95 0\n 1 1 0\n 0 1 0\n 0.5 1 0\n 0 0.05 0\n 0 0.15 0\n 0 0.25 0\n 0 0.35 0\n 0 0.45 0\n 0 0.55 0\n 0 0.65 0\n 0 0.75 0\n 0 0.85 0\n 0 0.95 0\n2.9268\n3.1707\n3\n1\n 0 0 0\n 0 0 0\n 0 0 0.05\n 0 0 0.1\n 0 0 0.1\n 0 0 0.15\n 0 0 0.2\n 0 0 0.2\n 0 0 0.25\n 0 0 0.3\n 0 0 0.3\n 0 0 0.35\n 0 0 0.4\n 0 0 0.4\n 0 0 0.45\n 0 0 0.5\n 0 0 0.5\n 0 0 0.55\n 0 0 0.6\n 0 0 0.6\n 0 0 0.65\n 0 0 0.7\n 0 0 0.7\n 0 0 0.75\n 0 0 0.8\n 0 0 0.8\n 0 0 0.85\n 0 0 0.9\n 0 0 0.9\n 0 0 0.95\n 0 0 0\n 0 0 0.1\n 0 0 0.2\n 0 0 0.3\n 0 0 0.4\n 0 0 0.5\n 0 0 0.6\n 0 0 0.7\n 0 0 0.8\n 0 0 0.9\n 0 0 0.05\n 0 0 0.15\n 0 0 0.25\n 0 0 0.35\n 0 0 0.45\n 0 0 0.55\n 0 0 0.65\n 0 0 0.75\n 0 0 0.85\n 0 0 0.95\n 0 0 1\n 0 0 1\n 0 0 1\n 0 0 0.05\n 0 0 0.15\n 0 0 0.25\n 0 0 0.35\n 0 0 0.45\n 0 0 0.55\n 0 0 0.65\n 0 0 0.75\n 0 0 0.85\n 0 0 0.95\n1\n";
00321 
00322   const char save_vit_out_0_2[]="vitesse_in_chaude\n0\n2\n3\n22\n4\n10\n-1081737852\n 0 1 3 2\n 2 3 5 4\n 4 5 7 6\n 6 7 9 8\n 8 9 11 10\n 10 11 13 12\n 12 13 15 14\n 14 15 17 16\n 16 17 19 18\n 18 19 21 20\n 0 0 0\n 1 0 0\n 0 0.1 0\n 1 0.1 0\n 0 0.2 0\n 1 0.2 0\n 0 0.3 0\n 1 0.3 0\n 0 0.4 0\n 1 0.4 0\n 0 0.5 0\n 1 0.5 0\n 0 0.6 0\n 1 0.6 0\n 0 0.7 0\n 1 0.7 0\n 0 0.8 0\n 1 0.8 0\n 0 0.9 0\n 1 0.9 0\n 0 1 0\n 1 1 0\n2.9268\n3.1707\n3\n1\n 0 0 0.05\n 0 0 0.15\n 0 0 0.25\n 0 0 0.35\n 0 0 0.45\n 0 0 0.55\n 0 0 0.65\n 0 0 0.75\n 0 0 0.85\n 0 0 0.95\n0\n";
00323   const char save_vit_out_1_2[]="vitesse_in_chaude\n1\n2\n3\n22\n4\n10\n-1081737852\n 0 1 3 2\n 2 3 5 4\n 4 5 7 6\n 6 7 9 8\n 8 9 11 10\n 10 11 13 12\n 12 13 15 14\n 14 15 17 16\n 16 17 19 18\n 18 19 21 20\n 0 0 0\n 1 0 0\n 0 0.1 0\n 1 0.1 0\n 0 0.2 0\n 1 0.2 0\n 0 0.3 0\n 1 0.3 0\n 0 0.4 0\n 1 0.4 0\n 0 0.5 0\n 1 0.5 0\n 0 0.6 0\n 1 0.6 0\n 0 0.7 0\n 1 0.7 0\n 0 0.8 0\n 1 0.8 0\n 0 0.9 0\n 1 0.9 0\n 0 1 0\n 1 1 0\n2.9268\n3.1707\n3\n1\n 0 0 0.029375\n 0 0 0.029375\n 0 0 0.1\n 0 0 0.1\n 0 0 0.2\n 0 0 0.2\n 0 0 0.3\n 0 0 0.3\n 0 0 0.4\n 0 0 0.4\n 0 0 0.5\n 0 0 0.5\n 0 0 0.6\n 0 0 0.6\n 0 0 0.7\n 0 0 0.7\n 0 0 0.8\n 0 0 0.8\n 0 0 0.9\n 0 0 0.9\n 0 0 0.970625\n 0 0 0.970625\n0\n";
00324 
00325   const char *save_vit_outs[2]={save_vit_out_1_2,save_vit_out_0_2};
00326 
00327   const char save_vit_out_1_0[]="vitesse_in_chaude\n1\n2\n3\n22\n4\n10\n-1081737852\n 0 1 3 2\n 2 3 5 4\n 4 5 7 6\n 6 7 9 8\n 8 9 11 10\n 10 11 13 12\n 12 13 15 14\n 14 15 17 16\n 16 17 19 18\n 18 19 21 20\n 0 0 0\n 1 0 0\n 0 0.1 0\n 1 0.1 0\n 0 0.2 0\n 1 0.2 0\n 0 0.3 0\n 1 0.3 0\n 0 0.4 0\n 1 0.4 0\n 0 0.5 0\n 1 0.5 0\n 0 0.6 0\n 1 0.6 0\n 0 0.7 0\n 1 0.7 0\n 0 0.8 0\n 1 0.8 0\n 0 0.9 0\n 1 0.9 0\n 0 1 0\n 1 1 0\n2.9268\n3.1707\n3\n1\n 0 0 0.029375\n 0 0 0.029375\n 0 0 0.1\n 0 0 0.1\n 0 0 0.2\n 0 0 0.2\n 0 0 0.3\n 0 0 0.3\n 0 0 0.4\n 0 0 0.4\n 0 0 0.5\n 0 0 0.5\n 0 0 0.6\n 0 0 0.6\n 0 0 0.7\n 0 0 0.7\n 0 0 0.8\n 0 0 0.8\n 0 0 0.9\n 0 0 0.9\n 0 0 0.970625\n 0 0 0.970625\n0\n";
00328   
00329   const char save_vit_in[]="VITESSE_P1_OUT\n1\n2\n3\n63\n3\n80\n0\n 0 1 2\n 3 4 5\n 6 7 8\n 9 10 11\n 12 13 14\n 15 16 17\n 18 19 20\n 21 22 23\n 24 25 26\n 27 28 29\n 30 2 1\n 31 5 4\n 32 8 7\n 33 11 10\n 34 14 13\n 35 17 16\n 36 20 19\n 37 23 22\n 38 26 25\n 39 29 28\n 30 40 2\n 31 41 5\n 32 42 8\n 33 43 11\n 34 44 14\n 35 45 17\n 36 46 20\n 37 47 23\n 38 48 26\n 39 49 29\n 31 2 40\n 32 5 41\n 33 8 42\n 34 11 43\n 35 14 44\n 36 17 45\n 37 20 46\n 38 23 47\n 39 26 48\n 50 29 49\n 3 2 4\n 6 5 7\n 9 8 10\n 12 11 13\n 15 14 16\n 18 17 19\n 21 20 22\n 24 23 25\n 27 26 28\n 51 29 52\n 31 4 2\n 32 7 5\n 33 10 8\n 34 13 11\n 35 16 14\n 36 19 17\n 37 22 20\n 38 25 23\n 39 28 26\n 50 52 29\n 0 2 53\n 3 5 54\n 6 8 55\n 9 11 56\n 12 14 57\n 15 17 58\n 18 20 59\n 21 23 60\n 24 26 61\n 27 29 62\n 3 53 2\n 6 54 5\n 9 55 8\n 12 56 11\n 15 57 14\n 18 58 17\n 21 59 20\n 24 60 23\n 27 61 26\n 51 62 29\n 0 0 0\n 0.5 0 0\n 0.5 0.05 0\n 0 0.1 0\n 0.5 0.1 0\n 0.5 0.15 0\n 0 0.2 0\n 0.5 0.2 0\n 0.5 0.25 0\n 0 0.3 0\n 0.5 0.3 0\n 0.5 0.35 0\n 0 0.4 0\n 0.5 0.4 0\n 0.5 0.45 0\n 0 0.5 0\n 0.5 0.5 0\n 0.5 0.55 0\n 0 0.6 0\n 0.5 0.6 0\n 0.5 0.65 0\n 0 0.7 0\n 0.5 0.7 0\n 0.5 0.75 0\n 0 0.8 0\n 0.5 0.8 0\n 0.5 0.85 0\n 0 0.9 0\n 0.5 0.9 0\n 0.5 0.95 0\n 1 0 0\n 1 0.1 0\n 1 0.2 0\n 1 0.3 0\n 1 0.4 0\n 1 0.5 0\n 1 0.6 0\n 1 0.7 0\n 1 0.8 0\n 1 0.9 0\n 1 0.05 0\n 1 0.15 0\n 1 0.25 0\n 1 0.35 0\n 1 0.45 0\n 1 0.55 0\n 1 0.65 0\n 1 0.75 0\n 1 0.85 0\n 1 0.95 0\n 1 1 0\n 0 1 0\n 0.5 1 0\n 0 0.05 0\n 0 0.15 0\n 0 0.25 0\n 0 0.35 0\n 0 0.45 0\n 0 0.55 0\n 0 0.65 0\n 0 0.75 0\n 0 0.85 0\n 0 0.95 0\n2.9268\n3.1707\n3\n1\n 0 0 0\n 0 0 0\n 0 0 0.05\n 0 0 0.1\n 0 0 0.1\n 0 0 0.15\n 0 0 0.2\n 0 0 0.2\n 0 0 0.25\n 0 0 0.3\n 0 0 0.3\n 0 0 0.35\n 0 0 0.4\n 0 0 0.4\n 0 0 0.45\n 0 0 0.5\n 0 0 0.5\n 0 0 0.55\n 0 0 0.6\n 0 0 0.6\n 0 0 0.65\n 0 0 0.7\n 0 0 0.7\n 0 0 0.75\n 0 0 0.8\n 0 0 0.8\n 0 0 0.85\n 0 0 0.9\n 0 0 0.9\n 0 0 0.95\n 0 0 0\n 0 0 0.1\n 0 0 0.2\n 0 0 0.3\n 0 0 0.4\n 0 0 0.5\n 0 0 0.6\n 0 0 0.7\n 0 0 0.8\n 0 0 0.9\n 0 0 0.05\n 0 0 0.15\n 0 0 0.25\n 0 0 0.35\n 0 0 0.45\n 0 0 0.55\n 0 0 0.65\n 0 0 0.75\n 0 0 0.85\n 0 0 0.95\n 0 0 1\n 0 0 1\n 0 0 1\n 0 0 0.05\n 0 0 0.15\n 0 0 0.25\n 0 0 0.35\n 0 0 0.45\n 0 0 0.55\n 0 0 0.65\n 0 0 0.75\n 0 0 0.85\n 0 0 0.95\n1\n";
00330 
00331   double valuesExpected1[2]={0.,0.};
00332   double valuesExpected2[2]={0.95,0.970625};
00333   
00334   double valuesExpected30[]={0., 0., 0.05, 0., 0., 0.15, 0., 0., 0.25, 0., 0., 0.35, 0., 0., 0.45, 0., 0., 0.55, 0., 0., 0.65, 0., 0., 0.75, 0., 0., 0.85, 0., 0., 0.95};
00335   double valuesExpected31[]={0.,  0.,  0.029375,  0.,  0.,  0.029375,  0.,  0.,  0.1,  0.,  0.,  0.1,  0.,  0.,  0.2,  0.,  0.,  0.2,  0.,  0.,  0.3,  0.,  0.,  0.3,  0.,  0.,  0.4,  0.,  0.,  0.4,  0.,  0.,  0.5,  0.,  0.,  0.5,  0.,  0.,  0.6,  0.,  0.,  0.6,  0.,  0.,  0.7,  0.,  0.,  0.7,  0.,  0.,  0.8,  0.,  0.,  0.8,  0.,  0.,  0.9,  0.,  0.,  0.9,  0.,  0.,  0.970625,  0.,  0.,  0.970625 };
00336 
00337   double *valuesExpected3[2]={valuesExpected30,valuesExpected31};
00338 
00339   int rank, size;
00340   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00341   MPI_Comm_size(MPI_COMM_WORLD,&size);
00342   if (size <2)
00343     return ;
00344   CommInterface comm;
00345   set<int> Genepi_ids;
00346   set<int> entree_chaude_ids;
00347   Genepi_ids.insert(0);
00348   for (int i=1;i<size;i++)
00349     entree_chaude_ids.insert(i);
00350   for (int type=0;type<2;type++)
00351     {
00352       MPIProcessorGroup entree_chaude_group(comm,entree_chaude_ids);
00353       MPIProcessorGroup Genepi_group(comm,Genepi_ids);
00354 
00355       TrioField vitesse;
00356       InterpKernelDEC dec_vit_in_chaude(entree_chaude_group, Genepi_group);
00357 
00358       if ( entree_chaude_group.containsMyRank())
00359         {
00360           istringstream save_vit(save_vit_in);
00361           vitesse.restore(save_vit);
00362         }
00363       else
00364         {
00365           istringstream save_vit(save_vit_out_1_0);
00366           vitesse.restore(save_vit);
00367           vitesse._has_field_ownership=false;
00368       
00369           if (vitesse._field)
00370             {
00371               delete [] vitesse._field;
00372               // cette ligne est super importante sinon c'est tout faux !!!!!!!
00373               vitesse._field=0;
00374             }
00375           // pour tester P1->P0
00376           vitesse._type=type;  
00377         }
00378   
00379       if (vitesse._type==1)
00380         dec_vit_in_chaude.setMethod("P1");
00381   
00382   
00383 
00384       dec_vit_in_chaude.attachLocalField((ICoCo::Field*) &vitesse);
00385       
00386       dec_vit_in_chaude.synchronize();
00387   
00388   
00389       // Envois - receptions
00390       if (entree_chaude_group.containsMyRank())
00391         {
00392           dec_vit_in_chaude.sendData();
00393         }
00394       else
00395         {
00396           dec_vit_in_chaude.recvData(); 
00397         }
00398       if (entree_chaude_group.containsMyRank() )
00399         {
00400           if (1)
00401             {
00402               ostringstream save_vit(save_vit_in_2);
00403               vitesse.save(save_vit);
00404             }
00405         }
00406       else
00407         {
00408       
00409           double pmin=1e38, pmax=-1e38;
00410       
00411           for(int i=0;i<vitesse.nb_values()*vitesse._nb_field_components;i++)
00412             {
00413               double p=*(vitesse._field+i);
00414               if (p<pmin) pmin=p;
00415               if (p>pmax) pmax=p;
00416             }
00417           CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected1[type],pmin,1e-12);
00418           CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[type],pmax,1e-12);
00419       
00420           ostringstream save_vit(save_vit_outs[type]);
00421           vitesse.save(save_vit);
00422 
00423           for(int i=0;i<vitesse.nb_values();i++)
00424             {
00425               for(int c=0;c<vitesse._nb_field_components;c++)
00426                 {
00427                   double p=vitesse._field[i*vitesse._nb_field_components+c];
00428                   CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[type][i*vitesse._nb_field_components+c],p,1e-12);
00429                 }
00430             }
00431       
00432         }
00433     }
00434 }
00435 
00439 void ParaMEDMEMTest::testGauthier3()
00440 {
00441   int num_cas=0;
00442   int rank, size;
00443   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00444   MPI_Comm_size(MPI_COMM_WORLD,&size);
00445   
00446   int is_master=0;
00447 
00448   CommInterface comm;
00449   set<int> emetteur_ids;
00450   set<int> recepteur_ids;
00451   emetteur_ids.insert(0);
00452   if(size!=4)
00453     return;
00454   recepteur_ids.insert(1);
00455   if (size >2) 
00456     recepteur_ids.insert(2);
00457   if (size >2) 
00458     emetteur_ids.insert(3);
00459   if ((rank==0)||(rank==1)) 
00460     is_master=1;
00461   
00462   MPIProcessorGroup recepteur_group(comm,recepteur_ids);
00463   MPIProcessorGroup emetteur_group(comm,emetteur_ids);
00464 
00465 
00466   string cas;
00467   if (recepteur_group.containsMyRank())
00468     {
00469       cas="recepteur";
00470       //freopen("recpeteur.out","w",stdout);
00471       //freopen("recepteur.err","w",stderr);
00472       
00473     }
00474   else
00475     {
00476       cas="emetteur";
00477       // freopen("emetteur.out","w",stdout);
00478       //freopen("emetteur.err","w",stderr);
00479     }
00480   double expected[8][4]={
00481     {1.,1.,1.,1.},
00482     {40., 40., 1., 1.},
00483     {1.,1.,1e200,1e200},
00484     {40.,1.,1e200,1e200},
00485     {1.,1.,1.,1.},
00486     {40.,1.,1.,1.},
00487     {1.,1.,1e200,1e200},
00488     {20.5,1.,1e200,1e200}
00489   };
00490 
00491   int expectedLgth[8]={4,4,2,2,4,4,2,2};
00492   
00493   for (int send=0;send<2;send++)
00494     for (int rec=0;rec<2;rec++)
00495       {
00496         
00497         std::vector<InterpKernelDEC> decu(1);
00498         decu[0]=InterpKernelDEC(emetteur_group, recepteur_group);
00499         InterpKernelDEC& dec_emetteur=decu[0];
00500 
00501         //InterpKernelDEC dec_emetteur(emetteur_group, recepteur_group);
00502         dec_emetteur.setOrientation(2);
00503         TrioField champ_emetteur, champ_recepteur;
00504    
00505         if (send==0)
00506           init_quadGauthier1(champ_emetteur,is_master);
00507         else
00508           init_triangleGauthier1(champ_emetteur,is_master);
00509         if (rec==0)
00510           init_triangleGauthier1(champ_recepteur,is_master);
00511         else
00512           init_quadGauthier1(champ_recepteur,is_master);
00513   
00514         if (cas=="emetteur") 
00515           {
00516             champ_emetteur._field=new double[champ_emetteur._nb_elems];
00517             for (int ele=0;ele<champ_emetteur._nb_elems;ele++)
00518               champ_emetteur._field[ele]=1;
00519       
00520             champ_emetteur._has_field_ownership=true;
00521           }
00522   
00523   
00524         MPI_Barrier(MPI_COMM_WORLD);
00525 
00526         //clock_t clock0= clock ();
00527         int compti=0;
00528 
00529         bool init=true; // first time step ??
00530         bool stop=false;
00531         //boucle sur les pas de quads
00532         while (!stop) {
00533   
00534           compti++;
00535           //clock_t clocki= clock ();
00536           //cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl; 
00537           for (int non_unif=0;non_unif<2;non_unif++)
00538             {
00539               // if (champ_recepteur._field)
00540               //   delete [] champ_recepteur._field;
00541               champ_recepteur._field=0;
00542               // champ_recepteur._has_field_ownership=false;
00543   
00544 
00545   
00546               if (cas=="emetteur") 
00547                 {
00548                   if (non_unif)
00549                     if(rank!=3)
00550                       champ_emetteur._field[0]=40;
00551                 }
00552               //bool ok=false; // Is the time interval successfully solved ?
00553     
00554               // Loop on the time interval tries
00555               if(1) {
00556       
00557 
00558                 if (cas=="emetteur")
00559                   dec_emetteur.attachLocalField((ICoCo::Field*) &champ_emetteur);
00560                 else
00561                   dec_emetteur.attachLocalField((ICoCo::Field*) &champ_recepteur);
00562 
00563 
00564                 if(init) dec_emetteur.synchronize();
00565                 init=false;
00566 
00567                 if (cas=="emetteur") {
00568                   //    affiche(champ_emetteur);
00569                   dec_emetteur.sendData();
00570                 }
00571                 else if (cas=="recepteur")
00572                   {
00573                     dec_emetteur.recvData();
00574                     if (is_master)
00575                       afficheGauthier1(champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
00576                   }
00577                 else
00578                   throw 0;
00579                 MPI_Barrier(MPI_COMM_WORLD);
00580               }
00581               stop=true;
00582               num_cas++;
00583             }
00584           // destruction des champs, des DEC, et des tableaux associés
00585         }
00586       }
00587 }