Back to index

salome-med  6.5.0
ParaMEDMEMTest_ICocoTrio.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 <string>
00022 #include "CommInterface.hxx"
00023 #include "ProcessorGroup.hxx"
00024 #include "MPIProcessorGroup.hxx"
00025 #include "DEC.hxx"
00026 #include "InterpKernelDEC.hxx"
00027 #include <set>
00028 #include <time.h>
00029 #include "ICoCoTrioField.hxx"
00030 #include <iostream>
00031 #include <assert.h>
00032 
00033 using namespace std;
00034 using namespace ParaMEDMEM;
00035 using namespace ICoCo;
00036 
00037 typedef enum {sync_and,sync_or} synctype;
00038 void synchronize_bool(bool& stop, synctype s)
00039 {
00040   int my_stop;
00041   int my_stop_temp = stop?1:0;
00042   if (s==sync_and)
00043     MPI_Allreduce(&my_stop_temp,&my_stop,1,MPI_INTEGER,MPI_MIN,MPI_COMM_WORLD);
00044   else if (s==sync_or)
00045     MPI_Allreduce(&my_stop_temp,&my_stop,1,MPI_INTEGER,MPI_MAX,MPI_COMM_WORLD);
00046   stop =(my_stop==1);
00047 }
00048 
00049 void synchronize_dt(double& dt)
00050 {
00051   double dttemp=dt;
00052   MPI_Allreduce(&dttemp,&dt,1,MPI_DOUBLE,MPI_MIN,MPI_COMM_WORLD);
00053 }
00054 
00055 
00056 void affiche( const TrioField&   field)
00057 {
00058   cout <<field.getName()<<endl;
00059   for (int ele=0;ele<field._nb_elems;ele++)
00060     cout <<ele <<": "<<field._field[ele]<<endl;;
00061   
00062 }
00063 
00064 void remplit_coord(double* coords)
00065 {
00066   coords[0*3+0]=0.;
00067   coords[0*3+1]=0.;
00068   coords[0*3+2]=0.;
00069   
00070   coords[1*3+0]=1.;
00071   coords[1*3+1]=0.;
00072   coords[1*3+2]=0.;
00073   
00074     
00075   coords[2*3+0]=0.;
00076   coords[2*3+1]=0.;
00077   coords[2*3+2]=1.;
00078   
00079   coords[3*3+0]=1.;
00080   coords[3*3+1]=0.;
00081   coords[3*3+2]=1.;
00082   
00083   for (int i=4;i<8;i++)
00084     {
00085       for (int d=0;d<3;d++)
00086         coords[i*3+d]=coords[(i-4)*3+d];
00087       coords[i*3+1]+=1e-5;
00088     }
00089 
00090 }
00091 
00092 void init_quad(TrioField& champ_quad)
00093 {
00094   
00095   champ_quad.setName("champ_quad");
00096   champ_quad._space_dim=3;
00097   champ_quad._mesh_dim=2;
00098   champ_quad._nbnodes=8;
00099   champ_quad._nodes_per_elem=4;
00100   champ_quad._nb_elems=2;
00101   champ_quad._itnumber=0;
00102   champ_quad._time1=0;
00103   champ_quad._time2=1;
00104   champ_quad._nb_field_components=1;
00105   
00106   champ_quad._coords=new double[champ_quad._nbnodes*champ_quad._space_dim];
00107   //memcpy(afield._coords,sommets.addr(),champ_quad._nbnodes*champ_quad._space_dim*sizeof(double));
00108   
00109   remplit_coord(champ_quad._coords);
00110   
00111   
00112   champ_quad._connectivity=new int[champ_quad._nb_elems*champ_quad._nodes_per_elem];
00113   champ_quad._connectivity[0*champ_quad._nodes_per_elem+0]=0;
00114   champ_quad._connectivity[0*champ_quad._nodes_per_elem+1]=1;
00115   champ_quad._connectivity[0*champ_quad._nodes_per_elem+2]=3;
00116   champ_quad._connectivity[0*champ_quad._nodes_per_elem+3]=2;
00117   champ_quad._connectivity[1*champ_quad._nodes_per_elem+0]=4;
00118   champ_quad._connectivity[1*champ_quad._nodes_per_elem+1]=5;
00119   champ_quad._connectivity[1*champ_quad._nodes_per_elem+2]=7;
00120   champ_quad._connectivity[1*champ_quad._nodes_per_elem+3]=6;
00121   
00122   
00123   champ_quad._has_field_ownership=false;
00124   champ_quad._field=0;
00125   //champ_quad._field=new double[champ_quad._nb_elems];
00126   //  assert(champ_quad._nb_field_components==1);
00127 }
00128 void init_triangle(TrioField& champ_triangle)
00129 {
00130    
00131   champ_triangle.setName("champ_triangle");
00132   champ_triangle._space_dim=3;
00133   champ_triangle._mesh_dim=2;
00134   champ_triangle._nbnodes=8;
00135   champ_triangle._nodes_per_elem=3;
00136   champ_triangle._nb_elems=4;
00137   champ_triangle._itnumber=0;
00138   champ_triangle._time1=0;
00139   champ_triangle._time2=1;
00140   champ_triangle._nb_field_components=1;
00141     
00142   champ_triangle._coords=new double[champ_triangle._nbnodes*champ_triangle._space_dim];
00143   //memcpy(afield._coords,sommets.addr(),champ_triangle._nbnodes*champ_triangle._space_dim*sizeof(double));
00144   remplit_coord(champ_triangle._coords);
00145 
00146   champ_triangle._connectivity=new int[champ_triangle._nb_elems*champ_triangle._nodes_per_elem];
00147   champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+0]=0;
00148   champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+1]=1;
00149   champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+2]=2;
00150   champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+0]=1;
00151   champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+1]=3;
00152   champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+2]=2;
00153   
00154   champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+0]=4;
00155   champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+1]=5;
00156   champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+2]=7;
00157   champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+0]=4;
00158   champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+1]=7;
00159   champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+2]=6;
00160   
00161   champ_triangle._has_field_ownership=false;
00162   // champ_triangle._field=new double[champ_triangle._nb_elems];
00163   champ_triangle._field=0;
00164 }
00165 
00166 void ParaMEDMEMTest::testICocoTrio1()
00167 {
00168   int size;
00169   int rank;
00170   MPI_Comm_size(MPI_COMM_WORLD,&size);
00171   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00172 
00173   //the test is meant to run on five processors
00174   if (size !=2) return ;
00175   
00176   CommInterface comm;
00177   set<int> emetteur_ids;
00178   set<int> recepteur_ids;
00179   emetteur_ids.insert(0);
00180   recepteur_ids.insert(1);
00181 
00182   MPIProcessorGroup recepteur_group(comm,recepteur_ids);
00183   MPIProcessorGroup emetteur_group(comm,emetteur_ids);
00184 
00185 
00186   string cas;
00187   if (recepteur_group.containsMyRank())
00188     {
00189       cas="recepteur";
00190       
00191     }
00192   else
00193     cas="emetteur";
00194 
00195   InterpKernelDEC dec_emetteur(emetteur_group, recepteur_group);
00196 
00197   TrioField champ_emetteur, champ_recepteur;
00198    
00199   init_triangle(champ_emetteur);
00200   //init_triangle(champ_emetteur);
00201   init_quad(champ_recepteur);
00202   //init_emetteur(champ_recepteur);
00203   
00204   if (cas=="emetteur") 
00205     {
00206       champ_emetteur._field=new double[champ_emetteur._nb_elems];
00207       for (int ele=0;ele<champ_emetteur._nb_elems;ele++)
00208         champ_emetteur._field[ele]=1;
00209       
00210       champ_emetteur._has_field_ownership=true;
00211     }
00212   
00213   
00214   MPI_Barrier(MPI_COMM_WORLD);
00215 
00216   clock_t clock0= clock ();
00217   int compti=0;
00218 
00219   bool init=true; // first time step ??
00220   bool stop=false;
00221   //boucle sur les pas de quads
00222   while (!stop) {
00223   
00224     compti++;
00225     clock_t clocki= clock ();
00226     cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl; 
00227     for (int non_unif=0;non_unif<2;non_unif++)
00228       {
00229         // if (champ_recepteur._field)
00230         //   delete [] champ_recepteur._field;
00231         champ_recepteur._field=0;
00232         // champ_recepteur._has_field_ownership=false;
00233   
00234 
00235   
00236         if (cas=="emetteur") 
00237           if (non_unif)
00238             champ_emetteur._field[0]=40;
00239         //bool ok=false; // Is the time interval successfully solved ?
00240     
00241         // Loop on the time interval tries
00242         if(1)
00243           {
00244             if (cas=="emetteur")
00245               dec_emetteur.attachLocalField((ICoCo::Field*) &champ_emetteur);
00246             else
00247               dec_emetteur.attachLocalField((ICoCo::Field*) &champ_recepteur);
00248             
00249             dec_emetteur.setNature(ConservativeVolumic);
00250             
00251             if(init)
00252               dec_emetteur.synchronize();
00253             init=false;
00254             
00255             if (cas=="emetteur")
00256               {
00257                 dec_emetteur.sendData();
00258                 affiche(champ_emetteur);
00259               }
00260             else if (cas=="recepteur")
00261               {
00262                 dec_emetteur.recvData();
00263                 affiche(champ_recepteur);
00264               }
00265             else
00266               throw 0;
00267           }
00268         stop=true;
00269       }
00270   }
00271 }