1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ParaMEDMEMTest.hxx"
22 #include "CommInterface.hxx"
23 #include "ProcessorGroup.hxx"
24 #include "MPIProcessorGroup.hxx"
26 #include "InterpKernelDEC.hxx"
29 #include "ICoCoTrioField.hxx"
34 using namespace ParaMEDMEM;
35 using namespace ICoCo;
37 typedef enum {sync_and,sync_or} synctype;
38 void synchronize_bool(bool& stop, synctype s)
41 int my_stop_temp = stop?1:0;
43 MPI_Allreduce(&my_stop_temp,&my_stop,1,MPI_INTEGER,MPI_MIN,MPI_COMM_WORLD);
45 MPI_Allreduce(&my_stop_temp,&my_stop,1,MPI_INTEGER,MPI_MAX,MPI_COMM_WORLD);
49 void synchronize_dt(double& dt)
52 MPI_Allreduce(&dttemp,&dt,1,MPI_DOUBLE,MPI_MIN,MPI_COMM_WORLD);
56 void affiche( const TrioField& field)
58 cout <<field.getName()<<endl;
59 for (int ele=0;ele<field._nb_elems;ele++)
60 cout <<ele <<": "<<field._field[ele]<<endl;;
64 void remplit_coord(double* coords)
86 coords[i*3+d]=coords[(i-4)*3+d];
92 void init_quad(TrioField& champ_quad)
95 champ_quad.setName("champ_quad");
96 champ_quad._space_dim=3;
97 champ_quad._mesh_dim=2;
98 champ_quad._nbnodes=8;
99 champ_quad._nodes_per_elem=4;
100 champ_quad._nb_elems=2;
101 champ_quad._itnumber=0;
104 champ_quad._nb_field_components=1;
106 champ_quad._coords=new double[champ_quad._nbnodes*champ_quad._space_dim];
107 //memcpy(afield._coords,sommets.addr(),champ_quad._nbnodes*champ_quad._space_dim*sizeof(double));
109 remplit_coord(champ_quad._coords);
112 champ_quad._connectivity=new int[champ_quad._nb_elems*champ_quad._nodes_per_elem];
113 champ_quad._connectivity[0*champ_quad._nodes_per_elem+0]=0;
114 champ_quad._connectivity[0*champ_quad._nodes_per_elem+1]=1;
115 champ_quad._connectivity[0*champ_quad._nodes_per_elem+2]=3;
116 champ_quad._connectivity[0*champ_quad._nodes_per_elem+3]=2;
117 champ_quad._connectivity[1*champ_quad._nodes_per_elem+0]=4;
118 champ_quad._connectivity[1*champ_quad._nodes_per_elem+1]=5;
119 champ_quad._connectivity[1*champ_quad._nodes_per_elem+2]=7;
120 champ_quad._connectivity[1*champ_quad._nodes_per_elem+3]=6;
123 champ_quad._has_field_ownership=false;
125 //champ_quad._field=new double[champ_quad._nb_elems];
126 // assert(champ_quad._nb_field_components==1);
128 void init_triangle(TrioField& champ_triangle)
131 champ_triangle.setName("champ_triangle");
132 champ_triangle._space_dim=3;
133 champ_triangle._mesh_dim=2;
134 champ_triangle._nbnodes=8;
135 champ_triangle._nodes_per_elem=3;
136 champ_triangle._nb_elems=4;
137 champ_triangle._itnumber=0;
138 champ_triangle._time1=0;
139 champ_triangle._time2=1;
140 champ_triangle._nb_field_components=1;
142 champ_triangle._coords=new double[champ_triangle._nbnodes*champ_triangle._space_dim];
143 //memcpy(afield._coords,sommets.addr(),champ_triangle._nbnodes*champ_triangle._space_dim*sizeof(double));
144 remplit_coord(champ_triangle._coords);
146 champ_triangle._connectivity=new int[champ_triangle._nb_elems*champ_triangle._nodes_per_elem];
147 champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+0]=0;
148 champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+1]=1;
149 champ_triangle._connectivity[0*champ_triangle._nodes_per_elem+2]=2;
150 champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+0]=1;
151 champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+1]=3;
152 champ_triangle._connectivity[1*champ_triangle._nodes_per_elem+2]=2;
154 champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+0]=4;
155 champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+1]=5;
156 champ_triangle._connectivity[2*champ_triangle._nodes_per_elem+2]=7;
157 champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+0]=4;
158 champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+1]=7;
159 champ_triangle._connectivity[3*champ_triangle._nodes_per_elem+2]=6;
161 champ_triangle._has_field_ownership=false;
162 // champ_triangle._field=new double[champ_triangle._nb_elems];
163 champ_triangle._field=0;
166 void ParaMEDMEMTest::testICocoTrio1()
170 MPI_Comm_size(MPI_COMM_WORLD,&size);
171 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
173 //the test is meant to run on five processors
174 if (size !=2) return ;
177 set<int> emetteur_ids;
178 set<int> recepteur_ids;
179 emetteur_ids.insert(0);
180 recepteur_ids.insert(1);
182 MPIProcessorGroup recepteur_group(comm,recepteur_ids);
183 MPIProcessorGroup emetteur_group(comm,emetteur_ids);
187 if (recepteur_group.containsMyRank())
195 InterpKernelDEC dec_emetteur(emetteur_group, recepteur_group);
197 TrioField champ_emetteur, champ_recepteur;
199 init_triangle(champ_emetteur);
200 //init_triangle(champ_emetteur);
201 init_quad(champ_recepteur);
202 //init_emetteur(champ_recepteur);
206 champ_emetteur._field=new double[champ_emetteur._nb_elems];
207 for (int ele=0;ele<champ_emetteur._nb_elems;ele++)
208 champ_emetteur._field[ele]=1;
210 champ_emetteur._has_field_ownership=true;
214 MPI_Barrier(MPI_COMM_WORLD);
216 clock_t clock0= clock ();
219 bool init=true; // first time step ??
221 //boucle sur les pas de quads
225 clock_t clocki= clock ();
226 cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl;
227 for (int non_unif=0;non_unif<2;non_unif++)
229 // if (champ_recepteur._field)
230 // delete [] champ_recepteur._field;
231 champ_recepteur._field=0;
232 // champ_recepteur._has_field_ownership=false;
238 champ_emetteur._field[0]=40;
239 //bool ok=false; // Is the time interval successfully solved ?
241 // Loop on the time interval tries
245 dec_emetteur.attachLocalField((ICoCo::Field*) &champ_emetteur);
247 dec_emetteur.attachLocalField((ICoCo::Field*) &champ_recepteur);
249 dec_emetteur.setNature(ConservativeVolumic);
252 dec_emetteur.synchronize();
257 dec_emetteur.sendData();
258 affiche(champ_emetteur);
260 else if (cas=="recepteur")
262 dec_emetteur.recvData();
263 affiche(champ_recepteur);