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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26