1
/* Copyright (C) 2006 Imperial College London and others.
3
Please see the AUTHORS file in the main source directory for a full list
7
Applied Modelling and Computation Group
8
Department of Earth Science and Engineering
9
Imperial College London
11
g.gorman@imperial.ac.uk
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.
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.
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
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,
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,
53
int& NewPPressureNodes, int& NewNPressureNodes,
54
int& NewpSCATER, int NewpATOREC[],
55
int& NewpGATHER, int NewpATOSEN[],
57
int& NewNODX, int& NewNODY, int& NewNODZ, samfloat_t Metric[]){
58
ECHO("void Mesh::export_fluidity( ... )");
59
CHECK(int_memory_len);
62
CHECK(real_memory_len);
66
// Start exporting meshes
68
// node_list.refresh_unn2gnn();
70
NewPNodes = node_list.psize();
71
NewNNodes = node_list.size();
76
do_element_headcount();
77
NewNElems = num_elements("volume");
78
NewNSElems= num_elements("surface");
80
// Start base pointer into the free integer memory.
83
{// Compress halo info..
85
for(int i=0; i<NProcs; i++){
86
NewATOREC[i+1] = NewATOREC[i] + halo_nodes[i].size();
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);
95
assert(gnn < NewNNodes);
96
assert(gnn >= NewPNodes);
98
ECHO("SCATER = " << *n << " -> " << gnn + 1);
100
int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
105
{// Compress shared info...
107
for(int i=0; i<NProcs; i++){
108
NewATOSEN[i+1] = NewATOSEN[i] + shared_nodes[i].size();
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);
117
assert(gnn < NewPNodes);
120
ECHO("GATHER = " << *n << " -> " << gnn + 1);
122
int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
125
} // end compressing shared
127
{ // Compress volume element-node lists
128
NewENLIST = bptr + 1;
129
for(deque<Element>::iterator et = element_list.begin(); et != element_list.end(); ++et){
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);
137
assert(bptr < int_memory_len );
138
assert(NewNNodes > gnn);
139
int_memory[bptr++] = gnn + 1;
147
// Compress surface element-node list and write the surface id's.
148
vector<int> surfid( NewNSElems );
151
NewSNLIST = bptr + 1;
152
for(deque<Element>::iterator et = element_list.begin(); et != element_list.end(); ++et){
154
unsigned char type = (*et).get_flags();
155
if( type & ELM_SURFACE ){
157
assert(pos<NewNSElems);
158
const vector<int>& ifields = (*et).get_ifields();
159
surfid[pos++] = ifields[0];
161
vector<unn_t> enl( (*et).get_enlist() );
163
for(vector<unn_t>::iterator it = enl.begin(); it != enl.end(); ++it){
164
int gnn = unn2gnn(*it);
166
assert(bptr < int_memory_len);
167
assert(NewNNodes > gnn);
168
int_memory[bptr++] = gnn + 1;
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];
180
// Export pressure nodes
181
NewNPressureNodes = MFnode_list.size();
182
NewPPressureNodes = MFnode_list.psize();
183
CHECK(NewPPressureNodes);
184
CHECK(NewNPressureNodes);
186
if( mixed_formulation() ){
187
ECHO("Doing mixed-formulation exporting thing.");
189
{// Compress halo info..
191
for(int i = 0; i< NProcs; i++){
192
NewpATOREC[i+1] = NewpATOREC[i] + halo_pnodes[i].size();
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);
201
assert(gnn < NewNPressureNodes);
202
assert(gnn >= NewPPressureNodes);
203
ECHO("pSCATER = " << *n << " -> " << gnn + 1);
205
int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
208
} // finished compressing halo info.
210
{// Compress shared info...
212
for(int i=0; i<NProcs; i++){
213
NewpATOSEN[i+1] = NewpATOSEN[i] + shared_pnodes[i].size();
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);
222
assert(gnn < NewPPressureNodes);
224
ECHO("pGATHER = " << *n << " -> " << gnn + 1);
226
int_memory[bptr++] = gnn + 1; // +1 is for the fortran offset.
229
} // end compressing shared
231
ECHO("Writting pressure elements...");
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)
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);
242
assert(bptr<int_memory_len);
243
assert(NewNPressureNodes>gnn);
244
int_memory[bptr++] = gnn + 1;
253
// Start base pointer into the free real memory.
254
{ // Write coordinates, field data and metric.
255
assert((3*MXNODS)<real_memory_len);
259
for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
260
real_memory[bptr++] = (*in).get_x();
265
for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
266
real_memory[bptr++] = (*in).get_y();
271
for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in)
272
real_memory[bptr++] = (*in).get_z();
275
unsigned nfields = node_list[0].get_fields().size();
276
RPT += (MXNODS*nfields);
278
assert(RPT<real_memory_len);
280
for(deque<Node>::iterator in=node_list.begin(); in != node_list.end(); ++in){
283
const vector<samfloat_t>& flds = (*in).get_fields();
284
assert(flds.size() == nfields);
286
for(unsigned f=0; f<nfields; f++)
287
real_memory[bptr + f*MXNODS] = flds[f];
290
ECHO(RPT<<" should be the same as PYSFU2");
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));
301
void Mesh::export_halo(int* colgat, int* atosen, int* scater, int* atorec, const int* ncolga, const int* nscate, const int* nprocs)
304
assert(*ncolga == get_ncolga());
305
assert(*nscate == get_nscate());
306
assert(*nprocs == this->NProcs);
310
for(int i = 0;i < this->NProcs;i++)
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)
316
int gnn = unn2gnn(*n);
317
assert(index < *ncolga);
318
colgat[index++] = gnn + 1;
324
for(int i = 0;i < this->NProcs;i++)
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)
330
int gnn = unn2gnn(*n);
331
assert(index < *nscate);
332
scater[index++] = gnn + 1;
340
void Mesh::export_phalo(int* pcolgat, int* patosen, int* pscater, int* patorec, const int* pncolga, const int* pnscate, const int* nprocs)
343
assert(*pncolga == get_pncolga());
344
assert(*pnscate == get_pnscate());
345
assert(*nprocs == this->NProcs);
349
for(int i = 0;i < this->NProcs;i++)
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)
355
int gnn = unn2gnn(*n);
356
assert(index < *pncolga);
357
pcolgat[index++] = gnn + 1;
363
for(int i = 0;i < this->NProcs;i++)
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)
369
int gnn = unn2gnn(*n);
370
assert(index < *pnscate);
371
pscater[index++] = gnn + 1;