~fluidity-core/fluidity/embedded_models

« back to all changes in this revision

Viewing changes to libadaptivity/load_balance/src/exports.cpp

  • Committer: Timothy Bond
  • Date: 2011-04-14 15:40:24 UTC
  • Revision ID: timothy.bond@imperial.ac.uk-20110414154024-116ci9gq6mwigmaw
Following the move from svn to bzr we change the nature of inclusion of these
four software libraries. Previously, they were included as svn externals and
pulled at latest version for trunk, pinned to specific versions for release
and stable trunk. Since bzr is less elegant at dealing with externals we have
made the decision to include the packages directly into the trunk instead.

At this import the versions are:

libadaptivity: r163
libvtkfortran: r67
libspud: r545
libmba2d: r28

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006 Imperial College London and others.
 
2
 
 
3
 Please see the AUTHORS file in the main source directory for a full list
 
4
 of copyright holders.
 
5
 
 
6
 Dr Gerard J Gorman
 
7
 Applied Modelling and Computation Group
 
8
 Department of Earth Science and Engineering
 
9
 Imperial College London
 
10
 
 
11
 g.gorman@imperial.ac.uk
 
12
 
 
13
 This library is free software; you can redistribute it and/or
 
14
 modify it under the terms of the GNU Lesser General Public
 
15
 License as published by the Free Software Foundation; either
 
16
 version 2.1 of the License.
 
17
 
 
18
 This library is distributed in the hope that it will be useful,
 
19
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
21
 Lesser General Public License for more details.
 
22
 
 
23
 You should have received a copy of the GNU Lesser General Public
 
24
 License along with this library; if not, write to the Free Software
 
25
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 
26
 USA
 
27
*/
 
28
#include <mpi.h>
 
29
#include <string.h>
 
30
#include <vector>
 
31
#include <deque>
 
32
#include <string>
 
33
#include <map>
 
34
#include <set>
 
35
#include <assert.h>
 
36
 
 
37
 
 
38
#include "Mesh.h"
 
39
#include "samtypes.h"
 
40
#include "c++debug.h"
 
41
 
 
42
using namespace std;
 
43
 
 
44
void Mesh::export_fluidity(int int_memory[],         int int_memory_len,  int &IPT,
 
45
                           samfloat_t real_memory[], int real_memory_len, int &RPT,
 
46
                           const int MXNODS,
 
47
                           /* Based pointers into memory*/
 
48
                           int& NewPNodes, int& NewNNodes, int& NewNElems, int& NewNSElems, 
 
49
                           int& NewSCATER, int NewATOREC[],
 
50
                           int& NewGATHER, int NewATOSEN[],
 
51
                           int& NewENLIST, int& NewSNLIST, int& NewSURFID,
 
52
                           // Pressure stuff
 
53
                           int& NewPPressureNodes, int& NewNPressureNodes,
 
54
                           int& NewpSCATER,        int NewpATOREC[],
 
55
                           int& NewpGATHER,        int NewpATOSEN[],
 
56
                           int& NewpENLIST,
 
57
                           int& NewNODX, int& NewNODY, int& NewNODZ, samfloat_t Metric[]){ 
 
58
  ECHO("void Mesh::export_fluidity( ... )");
 
59
  CHECK(int_memory_len);
 
60
  CHECK(IPT);
 
61
 
 
62
  CHECK(real_memory_len);
 
63
  CHECK(RPT);
 
64
 
 
65
  //
 
66
  // Start exporting meshes
 
67
  //
 
68
  //  node_list.refresh_unn2gnn();
 
69
 
 
70
  NewPNodes = node_list.psize();
 
71
  NewNNodes = node_list.size();
 
72
  
 
73
  CHECK(NewPNodes);
 
74
  CHECK(NewNNodes);
 
75
 
 
76
  do_element_headcount();
 
77
  NewNElems = num_elements("volume");
 
78
  NewNSElems= num_elements("surface");
 
79
 
 
80
  // Start base pointer into the free integer memory.
 
81
  int bptr = IPT-1;
 
82
  
 
83
  {// Compress halo info..
 
84
    NewATOREC[0] = 1;
 
85
    for(int i=0; i<NProcs; i++){
 
86
      NewATOREC[i+1] =  NewATOREC[i] + halo_nodes[i].size();
 
87
    }
 
88
    
 
89
    NewSCATER = bptr + 1; // +1's is for bloody fortran
 
90
    for(int i=0; i<NProcs; i++){
 
91
      ECHO("Processor - " << i);
 
92
      for(set<unsigned>::iterator n = halo_nodes[i].begin(); n != halo_nodes[i].end(); ++n){
 
93
        int gnn = unn2gnn(*n);
 
94
        
 
95
        assert(gnn <  NewNNodes);
 
96
        assert(gnn >= NewPNodes);
 
97
 
 
98
        ECHO("SCATER = " << *n << " -> " << gnn + 1);
 
99
        
 
100
        int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
 
101
      }
 
102
    }
 
103
  }
 
104
  
 
105
  {// Compress shared info...
 
106
    NewATOSEN[0] = 1;
 
107
    for(int i=0; i<NProcs; i++){
 
108
      NewATOSEN[i+1] = NewATOSEN[i] + shared_nodes[i].size();
 
109
    }
 
110
    
 
111
    NewGATHER = bptr + 1;
 
112
    for(int i = 0; i<NProcs; i++){
 
113
      ECHO("Processor - " << i);
 
114
      for(set<unsigned>::iterator n = shared_nodes[i].begin(); n != shared_nodes[i].end(); ++n){
 
115
        int gnn = unn2gnn(*n);
 
116
        
 
117
        assert(gnn <  NewPNodes);
 
118
        assert(gnn >= 0);
 
119
 
 
120
        ECHO("GATHER = " << *n << " -> " << gnn + 1);
 
121
        
 
122
        int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
 
123
      }
 
124
    }
 
125
  } // end compressing shared
 
126
  
 
127
  { // Compress volume element-node lists
 
128
    NewENLIST = bptr + 1;
 
129
    for(deque<Element>::iterator et = element_list.begin(); et != element_list.end(); ++et){
 
130
      
 
131
      unsigned char type = (*et).get_flags();
 
132
      if( type & ELM_VOLUME ){
 
133
        vector<unn_t> enl( (*et).get_enlist() );
 
134
        for(vector<unn_t>::iterator it = enl.begin(); it != enl.end(); ++it){
 
135
          int gnn = unn2gnn(*it);
 
136
          
 
137
          assert(bptr < int_memory_len );
 
138
          assert(NewNNodes > gnn);
 
139
          int_memory[bptr++] = gnn + 1;
 
140
        }
 
141
      }
 
142
    
 
143
    }
 
144
  }
 
145
 
 
146
  { 
 
147
    // Compress surface element-node list and write the surface id's.    
 
148
    vector<int> surfid( NewNSElems );
 
149
    unsigned pos=0;
 
150
    
 
151
    NewSNLIST = bptr + 1;
 
152
    for(deque<Element>::iterator et = element_list.begin(); et != element_list.end(); ++et){
 
153
      
 
154
      unsigned char type = (*et).get_flags();
 
155
      if( type & ELM_SURFACE ){
 
156
        
 
157
        assert(pos<NewNSElems);
 
158
        const vector<int>& ifields = (*et).get_ifields();
 
159
        surfid[pos++] = ifields[0];
 
160
        
 
161
        vector<unn_t> enl( (*et).get_enlist() );
 
162
        
 
163
        for(vector<unn_t>::iterator it = enl.begin(); it != enl.end(); ++it){
 
164
          int gnn = unn2gnn(*it);
 
165
          
 
166
          assert(bptr < int_memory_len);
 
167
          assert(NewNNodes > gnn);
 
168
          int_memory[bptr++] = gnn + 1;
 
169
        }
 
170
      }
 
171
      
 
172
    }
 
173
    NewSURFID = bptr + 1;
 
174
    assert(NewNSElems == pos);
 
175
    for(size_t i=0; i<(size_t)NewNSElems; i++)
 
176
      int_memory[bptr++] = surfid[i];
 
177
    
 
178
  }
 
179
 
 
180
  // Export pressure nodes
 
181
  NewNPressureNodes = MFnode_list.size();
 
182
  NewPPressureNodes = MFnode_list.psize();
 
183
  CHECK(NewPPressureNodes);
 
184
  CHECK(NewNPressureNodes);
 
185
  
 
186
  if( mixed_formulation() ){
 
187
    ECHO("Doing mixed-formulation exporting thing.");
 
188
    
 
189
    {// Compress halo info..
 
190
      NewpATOREC[0]=1;
 
191
      for(int i = 0; i< NProcs; i++){
 
192
        NewpATOREC[i+1] = NewpATOREC[i] + halo_pnodes[i].size();
 
193
      }
 
194
      
 
195
      NewpSCATER = bptr + 1;
 
196
      for(int i=0; i<NProcs; i++){
 
197
        ECHO("Processor - " << i);
 
198
        for(set<unsigned>::iterator n = halo_pnodes[i].begin(); n != halo_pnodes[i].end(); ++n){
 
199
          int gnn = MFunn2gnn(*n);
 
200
          
 
201
          assert(gnn <  NewNPressureNodes);
 
202
          assert(gnn >= NewPPressureNodes);
 
203
          ECHO("pSCATER = " << *n << " -> " << gnn + 1);
 
204
  
 
205
          int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
 
206
        }
 
207
      }
 
208
    } // finished compressing halo info.
 
209
    
 
210
    {// Compress shared info...
 
211
      NewpATOSEN[0]=1;
 
212
      for(int i=0; i<NProcs; i++){
 
213
        NewpATOSEN[i+1] = NewpATOSEN[i] + shared_pnodes[i].size();
 
214
      }
 
215
      
 
216
      NewpGATHER = bptr + 1;
 
217
      for(int i = 0; i<NProcs; i++){
 
218
        ECHO("Processor - " << i);
 
219
        for(set<unsigned>::iterator n = shared_pnodes[i].begin(); n != shared_pnodes[i].end(); ++n){
 
220
          int gnn = MFunn2gnn(*n);
 
221
          
 
222
          assert(gnn <  NewPPressureNodes);
 
223
          assert(gnn >= 0);
 
224
          ECHO("pGATHER = " << *n << " -> " << gnn + 1);
 
225
          
 
226
          int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
 
227
        }
 
228
      }
 
229
    } // end compressing shared
 
230
 
 
231
    ECHO("Writting pressure elements...");
 
232
    
 
233
    NewpENLIST = bptr + 1;
 
234
    for(ElementVector<Element>::iterator et = element_list.begin(); et != element_list.end(); ++et){
 
235
      if((*et).get_flags() & ELM_SURFACE)
 
236
        continue;
 
237
      
 
238
      const vector<unn_t>& enl = (*et).get_MFenlist();
 
239
      for(vector<unn_t>::const_iterator it = enl.begin(); it != enl.end(); ++it){
 
240
        int gnn = MFunn2gnn(*it);
 
241
 
 
242
        assert(bptr<int_memory_len);
 
243
        assert(NewNPressureNodes>gnn);
 
244
        int_memory[bptr++] = gnn + 1;
 
245
      }
 
246
    }
 
247
    ECHO("...done.");
 
248
 
 
249
  }
 
250
 
 
251
  IPT = bptr+1;
 
252
 
 
253
  // Start base pointer into the free real memory.
 
254
  { // Write coordinates, field data and metric.
 
255
    assert((3*MXNODS)<real_memory_len);
 
256
    bptr = RPT-1;
 
257
    RPT += MXNODS;
 
258
    NewNODX = bptr + 1;
 
259
    for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
 
260
      real_memory[bptr++] = (*in).get_x();
 
261
    
 
262
    bptr = RPT-1;
 
263
    RPT += MXNODS;
 
264
    NewNODY = bptr + 1;  
 
265
    for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
 
266
      real_memory[bptr++] = (*in).get_y();
 
267
    
 
268
    bptr = RPT-1;
 
269
    RPT += MXNODS;
 
270
    NewNODZ = bptr + 1;
 
271
    for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
 
272
      real_memory[bptr++] = (*in).get_z();
 
273
    
 
274
    bptr = RPT-1;
 
275
    unsigned nfields = node_list[0].get_fields().size();
 
276
    RPT += (MXNODS*nfields);
 
277
    
 
278
    assert(RPT<real_memory_len);
 
279
    
 
280
    for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in){
 
281
      CHECK(*in);
 
282
      
 
283
      const vector<samfloat_t>& flds = (*in).get_fields();
 
284
      assert(flds.size() == nfields);
 
285
      
 
286
      for(unsigned f=0; f<nfields; f++)
 
287
        real_memory[bptr + f*MXNODS] = flds[f];
 
288
      bptr++;
 
289
    }
 
290
    ECHO(RPT<<" should be the same as PYSFU2");
 
291
 
 
292
    int n=0;
 
293
    for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); in++,n++)
 
294
      memcpy(Metric+n*9, &(in->get_metric()[0]), 9*sizeof(samfloat_t));
 
295
    
 
296
    RPT = bptr+1;
 
297
  }
 
298
 
 
299
}
 
300
 
 
301
void Mesh::export_halo(int* colgat, int* atosen, int* scater, int* atorec, const int* ncolga, const int* nscate, const int* nprocs)
 
302
{
 
303
  // Input check
 
304
  assert(*ncolga == get_ncolga());
 
305
  assert(*nscate == get_nscate());
 
306
  assert(*nprocs == this->NProcs);
 
307
  
 
308
  atosen[0]= 0;
 
309
  int index = 0;
 
310
  for(int i = 0;i < this->NProcs;i++)
 
311
  {
 
312
    assert(i < *nprocs);
 
313
    atosen[i + 1] = atosen[i] + shared_nodes[i].size();
 
314
    for(set<unsigned>::iterator n = shared_nodes[i].begin(); n != shared_nodes[i].end(); ++n)
 
315
    {
 
316
      int gnn = unn2gnn(*n);    
 
317
      assert(index < *ncolga);
 
318
            colgat[index++] = gnn + 1;
 
319
    }
 
320
  }
 
321
 
 
322
  atorec[0] = 0;
 
323
  index = 0;
 
324
  for(int i = 0;i < this->NProcs;i++)
 
325
  {
 
326
    assert(i < *nprocs);
 
327
    atorec[i + 1] = atorec[i] + halo_nodes[i].size();
 
328
    for(set<unsigned>::iterator n = halo_nodes[i].begin(); n != halo_nodes[i].end(); ++n)
 
329
    {
 
330
      int gnn = unn2gnn(*n);    
 
331
      assert(index < *nscate);
 
332
            scater[index++] = gnn + 1;
 
333
    }
 
334
  }
 
335
  
 
336
  return;
 
337
}
 
338
 
 
339
 
 
340
void Mesh::export_phalo(int* pcolgat, int* patosen, int* pscater, int* patorec, const int* pncolga, const int* pnscate, const int* nprocs)
 
341
{
 
342
  // Input check
 
343
  assert(*pncolga == get_pncolga());
 
344
  assert(*pnscate == get_pnscate());
 
345
  assert(*nprocs == this->NProcs);
 
346
  
 
347
  patosen[0]= 0;
 
348
  int index = 0;
 
349
  for(int i = 0;i < this->NProcs;i++)
 
350
  {
 
351
    assert(i < *nprocs);
 
352
    patosen[i + 1] = patosen[i] + shared_pnodes[i].size();
 
353
    for(set<unsigned>::iterator n = shared_pnodes[i].begin(); n != shared_pnodes[i].end(); ++n)
 
354
    {
 
355
      int gnn = unn2gnn(*n);    
 
356
      assert(index < *pncolga);
 
357
            pcolgat[index++] = gnn + 1;
 
358
    }
 
359
  }
 
360
 
 
361
  patorec[0] = 0;
 
362
  index = 0;
 
363
  for(int i = 0;i < this->NProcs;i++)
 
364
  {
 
365
    assert(i < *nprocs);
 
366
    patorec[i + 1] = patorec[i] + halo_pnodes[i].size();
 
367
    for(set<unsigned>::iterator n = halo_pnodes[i].begin(); n != halo_pnodes[i].end(); ++n)
 
368
    {
 
369
      int gnn = unn2gnn(*n);    
 
370
      assert(index < *pnscate);
 
371
            pscater[index++] = gnn + 1;
 
372
    }
 
373
  }
 
374
  
 
375
  return;
 
376
}