/[escript]/trunk/finley/src/Mesh_saveVTK.c
ViewVC logotype

Contents of /trunk/finley/src/Mesh_saveVTK.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years ago) by ksteube
File MIME type: text/plain
File size: 66931 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* writes data and mesh in a vtk file */
18 /* nodal data needs to be given on FINLEY_NODES or FINLEY_REDUCED_NODES */
19
20 /**************************************************************/
21
22
23 #include "Mesh.h"
24 #include "Assemble.h"
25 #include "vtkCellType.h" /* copied from vtk source directory !!! */
26 #include "paso/PasoUtil.h"
27
28 #define LEN_PRINTED_INT_FORMAT (9+1)
29 #define INT_FORMAT "%d "
30 #define INT_NEWLINE_FORMAT "%d\n"
31 #define FLOAT_SCALAR_FORMAT "%12.6e\n"
32 #define FLOAT_VECTOR_FORMAT "%12.6e %12.6e %12.6e\n"
33 #define FLOAT_TENSOR_FORMAT "%12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n"
34 #define LEN_PRINTED_FLOAT_SCALAR_FORMAT (12+1)
35 #define LEN_PRINTED_FLOAT_VECTOR_FORMAT (3*(12+1)+1)
36 #define LEN_PRINTED_FLOAT_TENSOR_FORMAT (9*(12+1)+1)
37 #define NEWLINE "\n"
38 #define LEN_TMP_BUFFER LEN_PRINTED_FLOAT_TENSOR_FORMAT+(MAX_numNodes*LEN_PRINTED_INT_FORMAT+1)+2
39 #define NCOMP_MAX 9
40 #define __STRCAT(dest,chunk,dest_in_use) \
41 { \
42 strcpy(&dest[dest_in_use], chunk); \
43 dest_in_use+=strlen(chunk); \
44 }
45 #define INSIDE_1D(_X_,_C_,_R_) ( ABS((_X_)-(_C_)) <= (_R_) )
46 #define INSIDE_2D(_X_,_Y_,_CX_,_CY_,_R_) ( INSIDE_1D(_X_,_CX_,_R_) && INSIDE_1D(_Y_,_CY_,_R_))
47 #define INSIDE_3D(_X_,_Y_,_Z_,_CX_,_CY_,_CZ_,_R_) ( INSIDE_1D(_X_,_CX_,_R_) && INSIDE_1D(_Y_,_CY_,_R_) && INSIDE_1D(_Z_,_CZ_,_R_) )
48
49 void Finley_Mesh_saveVTK(const char * filename_p,
50 Finley_Mesh *mesh_p,
51 const dim_t num_data,
52 char* *names_p,
53 escriptDataC* *data_pp)
54 {
55 #ifdef USE_VTK
56 char error_msg[LenErrorMsg_MAX], *txt_buffer=NULL, tmp_buffer[LEN_TMP_BUFFER];
57 double sampleAvg[NCOMP_MAX], *values, rtmp, *QuadNodes;
58 size_t txt_buffer_in_use;
59 dim_t len_txt_buffer, max_len_names;
60 FILE * fileHandle_p = NULL;
61 int mpi_size, i, j, l, cellType;
62 dim_t i_data, hits, hits_old;
63 dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement;
64 dim_t myNumPoints, numPointsPerSample, rank, nComp, nCompReqd;
65 dim_t shape, NN, numCellFactor, myNumCells, max_name_len;
66 bool_t *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE, reduced_elements=FALSE;
67 bool_t set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
68 index_t myFirstNode, myLastNode, *globalNodeIndex, k, *node_index, myFirstCell;
69 #ifdef PASO_MPI
70 int ierr;
71 /* int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_SEQUENTIAL; */
72 const int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_UNIQUE_OPEN;
73 MPI_File mpi_fileHandle_p;
74 MPI_Status mpi_status;
75 MPI_Request mpi_req;
76 MPI_Info mpi_info=MPI_INFO_NULL;
77 #endif
78 Paso_MPI_rank my_mpi_rank;
79 int nodetype=FINLEY_NODES;
80 int elementtype=FINLEY_UNKNOWN;
81 char elemTypeStr[32];
82 Finley_NodeMapping *nodeMapping=NULL;
83 Finley_ElementFile* elements=NULL;
84 ElementTypeId TypeId;
85
86
87 /****************************************/
88 /* */
89 /* tags in the vtk file */
90
91 char* tags_header="<?xml version=\"1.0\"?>\n" \
92 "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\">\n" \
93 "<UnstructuredGrid>\n" \
94 "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n" \
95 "<Points>\n" \
96 "<DataArray NumberOfComponents=\"%d\" type=\"Float64\" format=\"ascii\">\n";
97 char *tag_End_DataArray = "</DataArray>\n";
98 char* tag_End_PointData = "</PointData>\n";
99 char* tag_End_CellData = "</CellData>\n";
100 char *footer = "</Piece>\n</UnstructuredGrid>\n</VTKFile>\n";
101 char* tags_End_Points_and_Start_Conn = "</DataArray>\n</Points>\n<Cells>\n<DataArray Name=\"connectivity\" type=\"Int32\" format=\"ascii\">\n" ;
102 char* tags_End_Conn_and_Start_Offset = "</DataArray>\n<DataArray Name=\"offsets\" type=\"Int32\" format=\"ascii\">\n";
103 char* tags_End_Offset_and_Start_Type = "</DataArray>\n<DataArray Name=\"types\" type=\"UInt8\" format=\"ascii\">\n";
104 char* tag_Float_DataArray="<DataArray Name=\"%s\" type=\"Float64\" NumberOfComponents=\"%d\" format=\"ascii\">\n";
105 char *tags_End_Type_And_Cells = "</DataArray>\n</Cells>\n";
106
107 int VTK_QUADRATIC_HEXAHEDRON_INDEX[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 12, 13, 14, 15 };
108 /* if there is no mesh we just return */
109 if (mesh_p==NULL) return;
110
111 my_mpi_rank = mesh_p->Nodes->MPIInfo->rank;
112 mpi_size = mesh_p->Nodes->MPIInfo->size;
113 nDim = mesh_p->Nodes->numDim;
114
115 if (! ( (nDim ==2) || (nDim == 3) ) ) {
116 Finley_setError(IO_ERROR, "saveVTK: spatial dimension 2 or 3 is supported only.");
117 return;
118 }
119 /*************************************************************************************/
120
121 /* open the file and check handle */
122
123 if (mpi_size > 1) {
124 #ifdef PASO_MPI
125 /* Collective Call */
126 #ifdef MPIO_HINTS
127 MPI_Info_create(&mpi_info);
128 /* MPI_Info_set(mpi_info, "striping_unit", "424288"); */
129 /* MPI_Info_set(mpi_info, "striping_factor", "16"); */
130 /* MPI_Info_set(mpi_info, "collective_buffering", "true"); */
131 /* MPI_Info_set(mpi_info, "cb_block_size", "131072"); */
132 /* MPI_Info_set(mpi_info, "cb_buffer_size", "1048567"); */
133 /* MPI_Info_set(mpi_info, "cb_nodes", "8"); */
134 /* MPI_Info_set(mpi_info, "access_style", "write_once, sequential"); */
135
136 /*XFS only */
137 /* MPI_Info_set(mpi_info, "direct_write", "true"); */
138 #endif
139 if ( my_mpi_rank == 0) {
140 if (Paso_fileExists(filename_p)) remove(filename_p);
141 }
142 ierr=MPI_File_open(mesh_p->Nodes->MPIInfo->comm, (char*)filename_p, amode,mpi_info, &mpi_fileHandle_p);
143 if (ierr != MPI_SUCCESS) {
144 perror(filename_p);
145 sprintf(error_msg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);
146 Finley_setError(IO_ERROR,error_msg);
147 } else {
148 MPI_File_set_view(mpi_fileHandle_p,MPI_DISPLACEMENT_CURRENT,MPI_CHAR, MPI_CHAR, "native" , mpi_info);
149 }
150 #endif
151 } else {
152 fileHandle_p = fopen(filename_p, "w");
153 if (fileHandle_p==NULL) {
154 sprintf(error_msg, "saveVTK: File %s could not be opened for writing.", filename_p);
155 Finley_setError(IO_ERROR,error_msg);
156 }
157 }
158 if (! Paso_MPIInfo_noError(mesh_p->Nodes->MPIInfo) ) return;
159 /*************************************************************************************/
160
161 /* find the mesh type to be written */
162
163 isCellCentered=TMPMEMALLOC(num_data,bool_t);
164 max_len_names=0;
165 if (!Finley_checkPtr(isCellCentered)) {
166 reduced_elements=FALSE;
167 nodetype=FINLEY_UNKNOWN;
168 elementtype=FINLEY_UNKNOWN;
169 for (i_data=0;i_data<num_data;++i_data) {
170 if (! isEmpty(data_pp[i_data])) {
171 switch(getFunctionSpaceType(data_pp[i_data]) ) {
172 case FINLEY_NODES:
173 nodetype = (nodetype == FINLEY_REDUCED_NODES) ? FINLEY_REDUCED_NODES : FINLEY_NODES;
174 isCellCentered[i_data]=FALSE;
175 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {
176 elementtype=FINLEY_ELEMENTS;
177 } else {
178 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
179 }
180 break;
181 case FINLEY_REDUCED_NODES:
182 nodetype = FINLEY_REDUCED_NODES;
183 isCellCentered[i_data]=FALSE;
184 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {
185 elementtype=FINLEY_ELEMENTS;
186 } else {
187 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
188 }
189 break;
190 case FINLEY_REDUCED_ELEMENTS:
191 reduced_elements=TRUE;
192 case FINLEY_ELEMENTS:
193 isCellCentered[i_data]=TRUE;
194 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {
195 elementtype=FINLEY_ELEMENTS;
196 } else {
197 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
198 }
199 break;
200 case FINLEY_REDUCED_FACE_ELEMENTS:
201 reduced_elements=TRUE;
202 case FINLEY_FACE_ELEMENTS:
203 isCellCentered[i_data]=TRUE;
204 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_FACE_ELEMENTS) {
205 elementtype=FINLEY_FACE_ELEMENTS;
206 } else {
207 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
208 }
209 break;
210 case FINLEY_POINTS:
211 isCellCentered[i_data]=TRUE;
212 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_POINTS) {
213 elementtype=FINLEY_POINTS;
214 } else {
215 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
216 }
217 break;
218 case FINLEY_REDUCED_CONTACT_ELEMENTS_1:
219 reduced_elements=TRUE;
220 case FINLEY_CONTACT_ELEMENTS_1:
221 isCellCentered[i_data]=TRUE;
222 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {
223 elementtype=FINLEY_CONTACT_ELEMENTS_1;
224 } else {
225 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
226 }
227 break;
228 case FINLEY_REDUCED_CONTACT_ELEMENTS_2:
229 reduced_elements=TRUE;
230 case FINLEY_CONTACT_ELEMENTS_2:
231 isCellCentered[i_data]=TRUE;
232 if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {
233 elementtype=FINLEY_CONTACT_ELEMENTS_1;
234 } else {
235 Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
236 }
237 break;
238 default:
239 sprintf(error_msg,"saveVTK: unknown function space type %d",getFunctionSpaceType(data_pp[i_data]));
240 Finley_setError(TYPE_ERROR,error_msg);
241 }
242 if (isCellCentered[i_data]) {
243 write_celldata=TRUE;
244 } else {
245 write_pointdata=TRUE;
246 }
247 max_len_names =MAX(max_len_names,(dim_t)strlen(names_p[i_data]));
248 }
249 }
250 nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;
251 }
252 if (Finley_noError()) {
253
254 /***************************************/
255
256 /* select number of points and the mesh component */
257
258 if (nodetype == FINLEY_REDUCED_NODES) {
259 myFirstNode = Finley_NodeFile_getFirstReducedNode(mesh_p->Nodes);
260 myLastNode = Finley_NodeFile_getLastReducedNode(mesh_p->Nodes);
261 globalNumPoints = Finley_NodeFile_getGlobalNumReducedNodes(mesh_p->Nodes);
262 globalNodeIndex= Finley_NodeFile_borrowGlobalReducedNodesIndex(mesh_p->Nodes);
263 } else {
264 myFirstNode = Finley_NodeFile_getFirstNode(mesh_p->Nodes);
265 myLastNode = Finley_NodeFile_getLastNode(mesh_p->Nodes);
266 globalNumPoints = Finley_NodeFile_getGlobalNumNodes(mesh_p->Nodes);
267 globalNodeIndex= Finley_NodeFile_borrowGlobalNodesIndex(mesh_p->Nodes);
268 }
269 myNumPoints = myLastNode - myFirstNode;
270 if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;
271 switch(elementtype) {
272 case FINLEY_ELEMENTS:
273 elements=mesh_p->Elements;
274 break;
275 case FINLEY_FACE_ELEMENTS:
276 elements=mesh_p->FaceElements;
277 break;
278 case FINLEY_POINTS:
279 elements=mesh_p->Points;
280 break;
281 case FINLEY_CONTACT_ELEMENTS_1:
282 elements=mesh_p->ContactElements;
283 break;
284 }
285 if (elements==NULL) {
286 Finley_setError(SYSTEM_ERROR,"saveVTK: undefined element file");
287 } else {
288 /* map finley element type to VTK element type */
289 numCells = elements->numElements;
290 globalNumCells = Finley_ElementFile_getGlobalNumElements(elements);
291 myNumCells= Finley_ElementFile_getMyNumElements(elements);
292 myFirstCell= Finley_ElementFile_getFirstElement(elements);
293 NN = elements->numNodes;
294 if (nodetype==FINLEY_REDUCED_NODES) {
295 TypeId = elements->LinearReferenceElement->Type->TypeId;
296 if (reduced_elements) {
297 QuadNodes=elements->LinearReferenceElementReducedOrder->QuadNodes;
298 } else {
299 QuadNodes=elements->LinearReferenceElement->QuadNodes;
300 }
301 } else {
302 TypeId = elements->ReferenceElement->Type->TypeId;
303 if (reduced_elements) {
304 QuadNodes=elements->ReferenceElementReducedOrder->QuadNodes;
305 } else {
306 QuadNodes=elements->ReferenceElement->QuadNodes;
307 }
308 }
309 switch(TypeId) {
310 case Point1:
311 case Line2Face:
312 case Line3Face:
313 case Point1_Contact:
314 case Line2Face_Contact:
315 case Line3Face_Contact:
316 numCellFactor=1;
317 cellType = VTK_VERTEX;
318 numVTKNodesPerElement = 1;
319 strcpy(elemTypeStr, "VTK_VERTEX");
320 break;
321
322 case Line2:
323 case Tri3Face:
324 case Rec4Face:
325 case Line2_Contact:
326 case Tri3_Contact:
327 case Tri3Face_Contact:
328 case Rec4Face_Contact:
329 numCellFactor=1;
330 cellType = VTK_LINE;
331 numVTKNodesPerElement = 2;
332 strcpy(elemTypeStr, "VTK_LINE");
333 break;
334
335 case Tri3:
336 case Tet4Face:
337 case Tet4Face_Contact:
338 numCellFactor=1;
339 cellType = VTK_TRIANGLE;
340 numVTKNodesPerElement = 3;
341 strcpy(elemTypeStr, "VTK_TRIANGLE");
342 break;
343
344 case Rec4:
345 case Hex8Face:
346 case Rec4_Contact:
347 case Hex8Face_Contact:
348 numCellFactor=1;
349 cellType = VTK_QUAD;
350 numVTKNodesPerElement = 4;
351 strcpy(elemTypeStr, "VTK_QUAD");
352 break;
353
354 case Rec9:
355 numCellFactor=4;
356 cellType = VTK_QUAD;
357 numVTKNodesPerElement = 4;
358 strcpy(elemTypeStr, "VTK_QUAD");
359 break;
360
361 case Tet4:
362 numCellFactor=1;
363 cellType = VTK_TETRA;
364 numVTKNodesPerElement = 4;
365 strcpy(elemTypeStr, "VTK_TETRA");
366 break;
367
368 case Hex8:
369 numCellFactor=1;
370 cellType = VTK_HEXAHEDRON;
371 numVTKNodesPerElement = 8;
372 strcpy(elemTypeStr, "VTK_HEXAHEDRON");
373 break;
374
375 case Line3:
376 case Tri6Face:
377 case Rec8Face:
378 case Line3_Contact:
379 case Tri6Face_Contact:
380 case Rec8Face_Contact:
381 numCellFactor=1;
382 cellType = VTK_QUADRATIC_EDGE;
383 numVTKNodesPerElement = 3;
384 strcpy(elemTypeStr, "VTK_QUADRATIC_EDGE");
385 break;
386
387 case Tri6:
388 case Tet10Face:
389 case Tri6_Contact:
390 case Tet10Face_Contact:
391 numCellFactor=1;
392 cellType = VTK_QUADRATIC_TRIANGLE;
393 numVTKNodesPerElement = 6;
394 strcpy(elemTypeStr, "VTK_QUADRATIC_TRIANGLE");
395 break;
396
397 case Rec8:
398 case Hex20Face:
399 case Rec8_Contact:
400 case Hex20Face_Contact:
401 numCellFactor=1;
402 cellType = VTK_QUADRATIC_QUAD;
403 numVTKNodesPerElement = 8;
404 strcpy(elemTypeStr, "VTK_QUADRATIC_QUAD");
405 break;
406
407 case Tet10:
408 numCellFactor=1;
409 cellType = VTK_QUADRATIC_TETRA;
410 numVTKNodesPerElement = 10;
411 strcpy(elemTypeStr, "VTK_QUADRATIC_TETRA");
412 break;
413
414 case Hex20:
415 numCellFactor=1;
416 cellType = VTK_QUADRATIC_HEXAHEDRON;
417 numVTKNodesPerElement = 20;
418 strcpy(elemTypeStr, "VTK_QUADRATIC_HEXAHEDRON");
419 break;
420
421 case Hex27:
422 numCellFactor=8;
423 cellType = VTK_HEXAHEDRON;
424 numVTKNodesPerElement = 8;
425 strcpy(elemTypeStr, "VTK_HEXAHEDRON");
426 break;
427
428 default:
429 sprintf(error_msg, "saveVTK: Element type %s is not supported by VTK",elements->ReferenceElement->Type->Name);
430 Finley_setError(VALUE_ERROR,error_msg);
431 }
432 }
433 }
434 /***************************************/
435
436 /***************************************/
437 /* */
438 /* allocate text buffer */
439 /* */
440 max_name_len=0;
441 for (i_data =0 ;i_data<num_data;++i_data) max_name_len=MAX(max_name_len,(dim_t)strlen(names_p[i_data]));
442 len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT + (30+3*max_name_len); /* header */
443 if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints * LEN_TMP_BUFFER);
444 if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*(LEN_PRINTED_INT_FORMAT*numVTKNodesPerElement+1));
445 len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);
446 len_txt_buffer=MAX(len_txt_buffer, (dim_t)strlen(tag_Float_DataArray) + LEN_PRINTED_INT_FORMAT + max_len_names);
447 if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
448 if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
449 txt_buffer=TMPMEMALLOC(len_txt_buffer+1,char);
450 Finley_checkPtr(txt_buffer);
451
452 if (Finley_noError()) {
453
454 /* select number of points and the mesh component */
455
456 sprintf(txt_buffer,tags_header,globalNumPoints,numCellFactor*globalNumCells,3);
457
458 if (mpi_size > 1) {
459 if ( my_mpi_rank == 0) {
460 #ifdef PASO_MPI
461 MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
462 MPI_Wait(&mpi_req,&mpi_status);
463 #endif
464 }
465 } else {
466 fprintf(fileHandle_p,txt_buffer);
467 }
468
469 /* write the nodes */
470
471 if (mpi_size > 1) {
472
473 txt_buffer[0] = '\0';
474 txt_buffer_in_use=0;
475 if (nDim==2) {
476 for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
477 if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
478 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,
479 mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
480 mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
481 0.);
482 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
483 }
484 }
485 } else {
486 for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
487 if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
488 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,
489 mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
490 mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
491 mesh_p->Nodes->Coordinates[INDEX2(2, i, nDim)]);
492 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
493 }
494 }
495
496 }
497 #ifdef PASO_MPI
498 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
499 MPI_File_write_ordered(mpi_fileHandle_p, txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
500 #endif
501 } else {
502 if (nDim==2) {
503 for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
504 if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
505 fprintf(fileHandle_p,FLOAT_VECTOR_FORMAT,
506 mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
507 mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
508 0.);
509 }
510 }
511 } else {
512 for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
513 if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
514 fprintf(fileHandle_p,FLOAT_VECTOR_FORMAT,
515 mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
516 mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
517 mesh_p->Nodes->Coordinates[INDEX2(2, i, nDim)]);
518 }
519 }
520
521 }
522 }
523
524 /* close the Points and open connectivity */
525
526 if (mpi_size > 1) {
527 if ( my_mpi_rank == 0) {
528 #ifdef PASO_MPI
529 MPI_File_iwrite_shared(mpi_fileHandle_p, tags_End_Points_and_Start_Conn, strlen(tags_End_Points_and_Start_Conn), MPI_CHAR, &mpi_req);
530 MPI_Wait(&mpi_req,&mpi_status);
531 #endif
532 }
533 } else {
534 fprintf(fileHandle_p,tags_End_Points_and_Start_Conn);
535 }
536
537 /* write the cells */
538 if (nodetype == FINLEY_REDUCED_NODES) {
539 node_index=elements->ReferenceElement->Type->linearNodes;
540 } else if (VTK_QUADRATIC_HEXAHEDRON==cellType) {
541 node_index=VTK_QUADRATIC_HEXAHEDRON_INDEX;
542 } else if ( (numVTKNodesPerElement!=NN) && (TypeId!=Rec9) && (TypeId!=Hex27) ) {
543 node_index=elements->ReferenceElement->Type->geoNodes;
544 } else {
545 node_index=NULL;
546 }
547
548 if ( mpi_size > 1) {
549 txt_buffer[0] = '\0';
550 txt_buffer_in_use=0;
551 if (node_index == NULL) {
552 if (TypeId==Rec9) {
553 for (i = 0; i < numCells; i++) {
554 if (elements->Owner[i] == my_mpi_rank) {
555 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(0, i, NN)]]);
556 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
557 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
558 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
559 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
560 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
561
562 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
563 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(1, i, NN)]]);
564 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
565 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
566 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
567 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
568
569 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
570 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
571 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
572 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(3, i, NN)]]);
573 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
574 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
575
576 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
577 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
578 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(2, i, NN)]]);
579 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
580 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
581 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
582 }
583 }
584 } else if (TypeId==Hex27) {
585 for (i = 0; i < numCells; i++) {
586 if (elements->Owner[i] == my_mpi_rank) {
587 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 0, i, NN)]]);
588 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
589 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
590 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
591 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
592 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
593 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
594 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
595 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
596 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
597
598 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
599 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 1, i, NN)]]);
600 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
601 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
602 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
603 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
604 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
605 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
606 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
607 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
608
609 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
610 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
611 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
612 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 3, i, NN)]]);
613 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
614 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
615 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
616 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
617 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
618 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
619
620 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
621 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
622 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 2, i, NN)]]);
623 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
624 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
625 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
626 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
627 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
628 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
629 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
630
631 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
632 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
633 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
634 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
635 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 4, i, NN)]]);
636 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
637 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
638 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
639 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
640 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
641
642 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
643 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
644 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
645 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
646 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
647 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 5, i, NN)]]);
648 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
649 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
650 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
651 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
652
653 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
654 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
655 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
656 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
657 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
658 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
659 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
660 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 7, i, NN)]]);
661 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
662 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
663
664 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
665 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
666 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
667 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
668 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
669 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
670 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 6, i, NN)]]);
671 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
672 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
673 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
674 }
675 }
676 } else {
677 for (i = 0; i < numCells; i++) {
678 if (elements->Owner[i] == my_mpi_rank) {
679 for (j = 0; j < numVTKNodesPerElement; j++) {
680 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(j, i, NN)]]);
681 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
682 }
683 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
684 }
685 }
686 }
687 } else {
688 for (i = 0; i < numCells; i++) {
689 if (elements->Owner[i] == my_mpi_rank) {
690 for (j = 0; j < numVTKNodesPerElement; j++) {
691 sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(node_index[j], i, NN)]]);
692 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
693 }
694 __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
695 }
696 }
697 }
698 #ifdef PASO_MPI
699 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
700 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
701 #endif
702 } else {
703 if (node_index == NULL) {
704 if (TypeId==Rec9) {
705 for (i = 0; i < numCells; i++) {
706 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(0, i, NN)]]);
707 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
708 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
709 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
710 fprintf(fileHandle_p,NEWLINE);
711
712 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
713 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(1, i, NN)]]);
714 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
715 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
716 fprintf(fileHandle_p,NEWLINE);
717
718 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
719 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
720 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
721 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(3, i, NN)]]);
722 fprintf(fileHandle_p,NEWLINE);
723
724 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
725 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
726 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(2, i, NN)]]);
727 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
728 fprintf(fileHandle_p,NEWLINE);
729 }
730
731 } else if (TypeId==Hex27) {
732 for (i = 0; i < numCells; i++) {
733 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 0, i, NN)]]);
734 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
735 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
736 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
737 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
738 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
739 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
740 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
741 fprintf(fileHandle_p,NEWLINE);
742
743 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
744 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 1, i, NN)]]);
745 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
746 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
747 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
748 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
749 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
750 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
751 fprintf(fileHandle_p,NEWLINE);
752
753 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
754 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
755 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
756 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 3, i, NN)]]);
757 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
758 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
759 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
760 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
761 fprintf(fileHandle_p,NEWLINE);
762
763 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
764 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
765 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 2, i, NN)]]);
766 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
767 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
768 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
769 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
770 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
771 fprintf(fileHandle_p,NEWLINE);
772
773 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
774 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
775 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
776 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
777 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 4, i, NN)]]);
778 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
779 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
780 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
781 fprintf(fileHandle_p,NEWLINE);
782
783 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
784 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
785 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
786 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
787 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
788 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 5, i, NN)]]);
789 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
790 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
791 fprintf(fileHandle_p,NEWLINE);
792
793 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
794 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
795 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
796 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
797 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
798 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
799 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
800 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 7, i, NN)]]);
801 fprintf(fileHandle_p,NEWLINE);
802
803 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
804 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
805 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
806 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
807 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
808 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
809 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 6, i, NN)]]);
810 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
811 fprintf(fileHandle_p,NEWLINE);
812 }
813 } else {
814 for (i = 0; i < numCells; i++) {
815 for (j = 0; j < numVTKNodesPerElement; j++) {
816 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(j, i, NN)]]);
817 }
818 fprintf(fileHandle_p,NEWLINE);
819 }
820 }
821 } else {
822 for (i = 0; i < numCells; i++) {
823 for (j = 0; j < numVTKNodesPerElement; j++) {
824 fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(node_index[j], i, NN)]]);
825 }
826 fprintf(fileHandle_p,NEWLINE);
827 }
828 }
829
830 }
831 /* finalize the connection and start the offset section */
832 if (mpi_size > 1) {
833 if( my_mpi_rank == 0) {
834 #ifdef PASO_MPI
835 MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Conn_and_Start_Offset,strlen(tags_End_Conn_and_Start_Offset),MPI_CHAR,&mpi_req);
836 MPI_Wait(&mpi_req,&mpi_status);
837 #endif
838 }
839 } else {
840 fprintf(fileHandle_p,tags_End_Conn_and_Start_Offset);
841 }
842
843 /* write the offsets */
844
845 if ( mpi_size > 1) {
846 txt_buffer[0] = '\0';
847 txt_buffer_in_use=0;
848 for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=(myFirstCell+myNumCells)*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
849 sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);
850 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
851 }
852 #ifdef PASO_MPI
853 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
854 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
855 #endif
856 } else {
857 for (i=numVTKNodesPerElement; i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
858 fprintf(fileHandle_p, INT_NEWLINE_FORMAT, i);
859 }
860
861 }
862 /* finalize the offset section and start the type section */
863 if ( mpi_size > 1) {
864 if ( my_mpi_rank == 0) {
865 #ifdef PASO_MPI
866 MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Offset_and_Start_Type,strlen(tags_End_Offset_and_Start_Type),MPI_CHAR,&mpi_req);
867 MPI_Wait(&mpi_req,&mpi_status);
868 #endif
869 }
870 } else {
871 fprintf(fileHandle_p,tags_End_Offset_and_Start_Type);
872 }
873 /* write element type */
874 sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);
875 if ( mpi_size > 1) {
876 txt_buffer[0] = '\0';
877 txt_buffer_in_use=0;
878 for (i=0; i<numCells*numCellFactor; i++) __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
879 #ifdef PASO_MPI
880 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
881 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
882 #endif
883 } else {
884 for (i=0; i<numCells*numCellFactor; i++) fprintf(fileHandle_p, tmp_buffer);
885 }
886 /* finalize cell information */
887 if ( mpi_size > 1) {
888 if ( my_mpi_rank == 0) {
889 #ifdef PASO_MPI
890 MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Type_And_Cells,strlen(tags_End_Type_And_Cells),MPI_CHAR,&mpi_req);
891 MPI_Wait(&mpi_req,&mpi_status);
892 #endif
893 }
894 } else {
895 fprintf(fileHandle_p,tags_End_Type_And_Cells);
896 }
897 }
898
899 /* Write cell data */
900 if (write_celldata && Finley_noError()) {
901 /* mark the active data arrays */
902 txt_buffer[0] = '\0';
903 set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
904 strcat(txt_buffer, "<CellData");
905 for (i_data =0 ;i_data<num_data;++i_data) {
906 if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
907 /* if the rank == 0: --> scalar data */
908 /* if the rank == 1: --> vector data */
909 /* if the rank == 2: --> tensor data */
910
911 switch(getDataPointRank(data_pp[i_data])) {
912 case 0:
913 if (! set_scalar) {
914 strcat(txt_buffer," Scalars=\"");
915 strcat(txt_buffer,names_p[i_data]);
916 strcat(txt_buffer,"\"");
917 set_scalar=TRUE;
918 }
919 break;
920 case 1:
921 if (! set_vector) {
922 strcat(txt_buffer," Vectors=\"");
923 strcat(txt_buffer,names_p[i_data]);
924 strcat(txt_buffer,"\"");
925 set_vector=TRUE;
926 }
927 break;
928 case 2:
929 if (! set_tensor) {
930 strcat(txt_buffer," Tensors=\"");
931 strcat(txt_buffer,names_p[i_data]);
932 strcat(txt_buffer,"\"");
933 set_tensor=TRUE;
934 }
935 break;
936 default:
937 sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
938 Finley_setError(VALUE_ERROR,error_msg);
939 return;
940 }
941 }
942 }
943 strcat(txt_buffer, ">\n");
944 if ( mpi_size > 1) {
945 if ( my_mpi_rank == 0) {
946 #ifdef PASO_MPI
947 MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
948 MPI_Wait(&mpi_req,&mpi_status);
949 #endif
950 }
951 } else {
952 fprintf(fileHandle_p,txt_buffer);
953 }
954 /* write the arrays */
955 for (i_data =0 ;i_data<num_data;++i_data) {
956 if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
957 txt_buffer[0] = '\0';
958 txt_buffer_in_use=0;
959 numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
960 rank = getDataPointRank(data_pp[i_data]);
961 nComp = getDataPointSize(data_pp[i_data]);
962 nCompReqd=1; /* the number of components mpi_required by vtk */
963 shape=0;
964 if (rank == 0) {
965 nCompReqd = 1;
966 } else if (rank == 1) {
967 shape=getDataPointShape(data_pp[i_data], 0);
968 if (shape>3) {
969 Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
970 }
971 nCompReqd = 3;
972 } else {
973 shape=getDataPointShape(data_pp[i_data], 0);
974 if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
975 Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
976 }
977 nCompReqd = 9;
978 }
979 if (Finley_noError()) {
980 sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
981 if ( mpi_size > 1) {
982 if ( my_mpi_rank == 0) {
983 #ifdef PASO_MPI
984 MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
985 MPI_Wait(&mpi_req,&mpi_status);
986 #endif
987 }
988 } else {
989 fprintf(fileHandle_p,txt_buffer);
990 }
991
992 for (i=0; i<numCells; i++) {
993 if (elements->Owner[i] == my_mpi_rank) {
994 values = getSampleData(data_pp[i_data], i);
995 for (l=0; l< numCellFactor;++l) {
996 /* averaging over the number of points in the sample */
997 if (isExpanded(data_pp[i_data])) {
998 for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k]=0;
999 hits=0;
1000 for (j=0; j<numPointsPerSample; j++) {
1001 hits_old=hits;
1002 if (TypeId==Rec9) {
1003 switch(l) {
1004 case 0:
1005 if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.25,0.25)) hits++;
1006 break;
1007 case 1:
1008 if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.25,0.25)) hits++;
1009 break;
1010 case 2:
1011 if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.75,0.25)) hits++;
1012 break;
1013 case 3:
1014 if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.75,0.25)) hits++;
1015 break;
1016 }
1017 } else if (TypeId==Hex27) {
1018 switch(l) {
1019 case 0:
1020 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.25,0.25)) hits++;
1021 break;
1022 case 1:
1023 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.25,0.25)) hits++;
1024 break;
1025 case 2:
1026 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.25,0.25)) hits++;
1027 break;
1028 case 3:
1029 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.25,0.25)) hits++;
1030 break;
1031 case 4:
1032 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.75,0.25)) hits++;
1033 break;
1034 case 5:
1035 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.75,0.25)) hits++;
1036 break;
1037 case 6:
1038 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.75,0.25)) hits++;
1039 break;
1040 case 7:
1041 if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.75,0.25)) hits++;
1042 break;
1043 }
1044 } else {
1045 hits++;
1046 }
1047 if (hits_old<hits) for (k=0; k<MIN(nComp,NCOMP_MAX); k++) {
1048 sampleAvg[k] += values[INDEX2(k,j,nComp)];
1049 }
1050 }
1051 for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] /=MAX(hits,1);
1052 } else {
1053 for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] = values[k];
1054 }
1055 /* if the number of required components is more than the number
1056 * of actual components, pad with zeros
1057 */
1058 /* probably only need to get shape of first element */
1059 /* write the data different ways for scalar, vector and tensor */
1060 if (nCompReqd == 1) {
1061 sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,sampleAvg[0]);
1062 } else if (nCompReqd == 3) {
1063 if (shape==1) {
1064 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],0.,0.);
1065 } else if (shape==2) {
1066 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],0.);
1067 } else if (shape==3) {
1068 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2]);
1069 }
1070 } else if (nCompReqd == 9) {
1071 if (shape==1) {
1072 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],0.,0.,
1073 0.,0.,0.,
1074 0.,0.,0.);
1075 } else if (shape==2) {
1076 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],0.,
1077 sampleAvg[2],sampleAvg[3],0.,
1078 0.,0.,0.);
1079 } else if (shape==3) {
1080 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2],
1081 sampleAvg[3],sampleAvg[4],sampleAvg[5],
1082 sampleAvg[6],sampleAvg[7],sampleAvg[8]);
1083 }
1084 }
1085 /* this needs a bit mor work!!! */
1086 if ( mpi_size > 1) {
1087 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1088 } else {
1089 fprintf(fileHandle_p,tmp_buffer);
1090 }
1091 }
1092 }
1093 }
1094 if ( mpi_size > 1) {
1095 #ifdef PASO_MPI
1096 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1097 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1098 #endif
1099 if ( my_mpi_rank == 0) {
1100 #ifdef PASO_MPI
1101 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1102 MPI_Wait(&mpi_req,&mpi_status);
1103 #endif
1104 }
1105 } else {
1106 fprintf(fileHandle_p,tag_End_DataArray);
1107 }
1108 }
1109 }
1110 }
1111 if ( mpi_size > 1) {
1112 if ( my_mpi_rank == 0) {
1113 #ifdef PASO_MPI
1114 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_CellData,strlen(tag_End_CellData),MPI_CHAR,&mpi_req);
1115 MPI_Wait(&mpi_req,&mpi_status);
1116 #endif
1117 }
1118 } else {
1119 fprintf(fileHandle_p,tag_End_CellData);
1120 }
1121 }
1122 /* point data */
1123 if (write_pointdata && Finley_noError()) {
1124 /* mark the active data arrays */
1125 set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
1126 txt_buffer[0] = '\0';
1127 strcat(txt_buffer, "<PointData");
1128 for (i_data =0 ;i_data<num_data;++i_data) {
1129 if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1130 /* if the rank == 0: --> scalar data */
1131 /* if the rank == 1: --> vector data */
1132 /* if the rank == 2: --> tensor data */
1133
1134 switch(getDataPointRank(data_pp[i_data])) {
1135 case 0:
1136 if (! set_scalar) {
1137 strcat(txt_buffer," Scalars=\"");
1138 strcat(txt_buffer,names_p[i_data]);
1139 strcat(txt_buffer,"\"");
1140 set_scalar=TRUE;
1141 }
1142 break;
1143 case 1:
1144 if (! set_vector) {
1145 strcat(txt_buffer," Vectors=\"");
1146 strcat(txt_buffer,names_p[i_data]);
1147 strcat(txt_buffer,"\"");
1148 set_vector=TRUE;
1149 }
1150 break;
1151 case 2:
1152 if (! set_tensor) {
1153 strcat(txt_buffer," Tensors=\"");
1154 strcat(txt_buffer,names_p[i_data]);
1155 strcat(txt_buffer,"\"");
1156 set_tensor=TRUE;
1157 }
1158 break;
1159 default:
1160 sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
1161 Finley_setError(VALUE_ERROR,error_msg);
1162 return;
1163 }
1164 }
1165 }
1166 strcat(txt_buffer, ">\n");
1167 if ( mpi_size > 1) {
1168 if ( my_mpi_rank == 0) {
1169 #ifdef PASO_MPI
1170 MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1171 MPI_Wait(&mpi_req,&mpi_status);
1172 #endif
1173 }
1174 } else {
1175 fprintf(fileHandle_p,txt_buffer);
1176 }
1177 /* write the arrays */
1178 for (i_data =0 ;i_data<num_data;++i_data) {
1179 if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1180 txt_buffer[0] = '\0';
1181 txt_buffer_in_use=0;
1182 numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
1183 rank = getDataPointRank(data_pp[i_data]);
1184 nComp = getDataPointSize(data_pp[i_data]);
1185 if (getFunctionSpaceType(data_pp[i_data]) == FINLEY_REDUCED_NODES) {
1186 nodeMapping=mesh_p->Nodes->reducedNodesMapping;
1187 } else {
1188 nodeMapping=mesh_p->Nodes->nodesMapping;
1189 }
1190 nCompReqd=1; /* the number of components mpi_required by vtk */
1191 shape=0;
1192 if (rank == 0) {
1193 nCompReqd = 1;
1194 } else if (rank == 1) {
1195 shape=getDataPointShape(data_pp[i_data], 0);
1196 if (shape>3) {
1197 Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
1198 }
1199 nCompReqd = 3;
1200 } else {
1201 shape=getDataPointShape(data_pp[i_data], 0);
1202 if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
1203 Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
1204 }
1205 nCompReqd = 9;
1206 }
1207 if (Finley_noError()) {
1208 sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
1209 if ( mpi_size > 1) {
1210 if ( my_mpi_rank == 0) {
1211 #ifdef PASO_MPI
1212 MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1213 MPI_Wait(&mpi_req,&mpi_status);
1214 #endif
1215 }
1216 } else {
1217 fprintf(fileHandle_p,txt_buffer);
1218 }
1219 for (i=0; i<mesh_p->Nodes->numNodes; i++) {
1220 k=globalNodeIndex[i];
1221 if ( (myFirstNode <= k) && (k < myLastNode) ) {
1222 values = getSampleData(data_pp[i_data], nodeMapping->target[i]);
1223 /* if the number of mpi_required components is more than the number
1224 * of actual components, pad with zeros
1225 */
1226 /* probably only need to get shape of first element */
1227 /* write the data different ways for scalar, vector and tensor */
1228 if (nCompReqd == 1) {
1229 sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,values[0]);
1230 } else if (nCompReqd == 3) {
1231 if (shape==1) {
1232 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],0.,0.);
1233 } else if (shape==2) {
1234 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],0.);
1235 } else if (shape==3) {
1236 sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],values[2]);
1237 }
1238 } else if (nCompReqd == 9) {
1239 if (shape==1) {
1240 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],0.,0.,
1241 0.,0.,0.,
1242 0.,0.,0.);
1243 } else if (shape==2) {
1244 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],0.,
1245 values[2],values[3],0.,
1246 0.,0.,0.);
1247 } else if (shape==3) {
1248 sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],values[2],
1249 values[3],values[4],values[5],
1250 values[6],values[7],values[8]);
1251 }
1252 }
1253 if ( mpi_size > 1) {
1254 __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1255 } else {
1256 fprintf(fileHandle_p,tmp_buffer);
1257 }
1258 }
1259 }
1260 if ( mpi_size > 1) {
1261 #ifdef PASO_MPI
1262 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1263 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1264 #endif
1265 if ( my_mpi_rank == 0) {
1266 #ifdef PASO_MPI
1267 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1268 MPI_Wait(&mpi_req,&mpi_status);
1269 #endif
1270 }
1271 } else {
1272 fprintf(fileHandle_p,tag_End_DataArray);
1273 }
1274 }
1275 }
1276 }
1277 if ( mpi_size > 1) {
1278 if ( my_mpi_rank == 0) {
1279 #ifdef PASO_MPI
1280 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_PointData,strlen(tag_End_PointData),MPI_CHAR,&mpi_req);
1281 MPI_Wait(&mpi_req,&mpi_status);
1282 #endif
1283 }
1284 } else {
1285 fprintf(fileHandle_p,tag_End_PointData);
1286 }
1287 }
1288 if (Finley_noError()) {
1289 if ( mpi_size > 1) {
1290 if ( my_mpi_rank == 0) {
1291 #ifdef PASO_MPI
1292 MPI_File_iwrite_shared(mpi_fileHandle_p,footer,strlen(footer),MPI_CHAR,&mpi_req);
1293 MPI_Wait(&mpi_req,&mpi_status);
1294 #ifdef MPIO_HINTS
1295 MPI_Info_free(&mpi_info);
1296 #undef MPIO_HINTS
1297 #endif
1298 #endif
1299 }
1300 #ifdef PASO_MPI
1301 MPI_File_close(&mpi_fileHandle_p);
1302 #endif
1303 } else {
1304 fprintf(fileHandle_p,footer);
1305 fclose(fileHandle_p);
1306 }
1307 }
1308 TMPMEMFREE(isCellCentered);
1309 TMPMEMFREE(txt_buffer);
1310 return;
1311 #else
1312 /* Don't kill the job if saveVTK() doesn't work */
1313 fprintf(stderr, "\n\nsaveVTK warning: VTK is not available\n\n\n");
1314 #endif
1315 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26