/[escript]/branches/domexper/dudley/src/Mesh_saveVTK.c
ViewVC logotype

Annotation of /branches/domexper/dudley/src/Mesh_saveVTK.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1866 - (hide annotations)
Thu Oct 9 04:01:06 2008 UTC (10 years, 7 months ago) by ksteube
Original Path: trunk/finley/src/Mesh_saveVTK.c
File MIME type: text/plain
File size: 67056 byte(s)
Repair to saveVTK similar to revision 1677 (there we got the number of offsets correct
and in this revision we got the number of types correct).
In case of MPI > 1 do not run saveDX tests since saveDX is not MPI parallel.

1 jgs 110
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 110 /**************************************************************/
16    
17     /* writes data and mesh in a vtk file */
18 ksteube 1312 /* nodal data needs to be given on FINLEY_NODES or FINLEY_REDUCED_NODES */
19 jgs 110
20     /**************************************************************/
21    
22 dhawcroft 793
23 jgs 110 #include "Mesh.h"
24 gross 1062 #include "Assemble.h"
25 jgs 113 #include "vtkCellType.h" /* copied from vtk source directory !!! */
26 gross 1669 #include "paso/PasoUtil.h"
27 jgs 110
28 ksteube 1312 #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 dhawcroft 793 }
45 gross 1741 #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 dhawcroft 793
49 ksteube 1312 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 dhawcroft 793 {
55 ksteube 1705 #ifdef USE_VTK
56 ksteube 1312 char error_msg[LenErrorMsg_MAX], *txt_buffer=NULL, tmp_buffer[LEN_TMP_BUFFER];
57 gross 1741 double sampleAvg[NCOMP_MAX], *values, rtmp, *QuadNodes;
58 phornby 1628 size_t txt_buffer_in_use;
59     dim_t len_txt_buffer, max_len_names;
60 ksteube 1312 FILE * fileHandle_p = NULL;
61 gross 1741 int mpi_size, i, j, l, cellType;
62     dim_t i_data, hits, hits_old;
63 phornby 1628 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 gross 1741 bool_t *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE, reduced_elements=FALSE;
67 ksteube 1312 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 gross 1669 /* 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 ksteube 1312 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 dhawcroft 793 int elementtype=FINLEY_UNKNOWN;
81     char elemTypeStr[32];
82 ksteube 1312 Finley_NodeMapping *nodeMapping=NULL;
83 dhawcroft 793 Finley_ElementFile* elements=NULL;
84 ksteube 1312 ElementTypeId TypeId;
85    
86    
87     /****************************************/
88     /* */
89     /* tags in the vtk file */
90 dhawcroft 793
91 ksteube 1312 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 dhawcroft 793
107 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 };
108     /* if there is no mesh we just return */
109     if (mesh_p==NULL) return;
110 dhawcroft 793
111 ksteube 1312 my_mpi_rank = mesh_p->Nodes->MPIInfo->rank;
112     mpi_size = mesh_p->Nodes->MPIInfo->size;
113     nDim = mesh_p->Nodes->numDim;
114 dhawcroft 796
115 ksteube 1312 if (! ( (nDim ==2) || (nDim == 3) ) ) {
116     Finley_setError(IO_ERROR, "saveVTK: spatial dimension 2 or 3 is supported only.");
117     return;
118 dhawcroft 793 }
119 ksteube 1312 /*************************************************************************************/
120 dhawcroft 793
121 ksteube 1312 /* open the file and check handle */
122 dhawcroft 793
123 ksteube 1312 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 gross 1669 if ( my_mpi_rank == 0) {
140     if (Paso_fileExists(filename_p)) remove(filename_p);
141     }
142 ksteube 1312 ierr=MPI_File_open(mesh_p->Nodes->MPIInfo->comm, (char*)filename_p, amode,mpi_info, &mpi_fileHandle_p);
143 gross 1562 if (ierr != MPI_SUCCESS) {
144 ksteube 1347 perror(filename_p);
145     sprintf(error_msg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);
146 ksteube 1312 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 dhawcroft 793 }
158 ksteube 1312 if (! Paso_MPIInfo_noError(mesh_p->Nodes->MPIInfo) ) return;
159     /*************************************************************************************/
160 dhawcroft 793
161 ksteube 1312 /* find the mesh type to be written */
162 dhawcroft 793
163 ksteube 1312 isCellCentered=TMPMEMALLOC(num_data,bool_t);
164     max_len_names=0;
165     if (!Finley_checkPtr(isCellCentered)) {
166 gross 1741 reduced_elements=FALSE;
167 gross 1338 nodetype=FINLEY_UNKNOWN;
168     elementtype=FINLEY_UNKNOWN;
169 ksteube 1312 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 gross 1741 case FINLEY_REDUCED_ELEMENTS:
191     reduced_elements=TRUE;
192 ksteube 1312 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 gross 1741 case FINLEY_REDUCED_FACE_ELEMENTS:
201     reduced_elements=TRUE;
202 ksteube 1312 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 gross 1741 case FINLEY_REDUCED_CONTACT_ELEMENTS_1:
219     reduced_elements=TRUE;
220 ksteube 1312 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 gross 1741 case FINLEY_REDUCED_CONTACT_ELEMENTS_2:
229     reduced_elements=TRUE;
230 ksteube 1312 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 phornby 1628 max_len_names =MAX(max_len_names,(dim_t)strlen(names_p[i_data]));
248 ksteube 1312 }
249     }
250 gross 1338 nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;
251 dhawcroft 793 }
252 ksteube 1312 if (Finley_noError()) {
253 dhawcroft 793
254 ksteube 1312 /***************************************/
255 dhawcroft 793
256 ksteube 1312 /* select number of points and the mesh component */
257 gross 1741
258 ksteube 1312 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 gross 1476 if (nodetype==FINLEY_REDUCED_NODES) {
295 ksteube 1312 TypeId = elements->LinearReferenceElement->Type->TypeId;
296 gross 1741 if (reduced_elements) {
297     QuadNodes=elements->LinearReferenceElementReducedOrder->QuadNodes;
298     } else {
299     QuadNodes=elements->LinearReferenceElement->QuadNodes;
300     }
301 ksteube 1312 } else {
302     TypeId = elements->ReferenceElement->Type->TypeId;
303 gross 1741 if (reduced_elements) {
304     QuadNodes=elements->ReferenceElementReducedOrder->QuadNodes;
305     } else {
306     QuadNodes=elements->ReferenceElement->QuadNodes;
307     }
308 ksteube 1312 }
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 gross 1741
354     case Rec9:
355     numCellFactor=4;
356     cellType = VTK_QUAD;
357     numVTKNodesPerElement = 4;
358     strcpy(elemTypeStr, "VTK_QUAD");
359     break;
360 ksteube 1312
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 gross 1741
421     case Hex27:
422     numCellFactor=8;
423     cellType = VTK_HEXAHEDRON;
424     numVTKNodesPerElement = 8;
425     strcpy(elemTypeStr, "VTK_HEXAHEDRON");
426     break;
427 ksteube 1312
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 dhawcroft 793 }
434 ksteube 1312 /***************************************/
435 dhawcroft 793
436 ksteube 1312 /***************************************/
437     /* */
438     /* allocate text buffer */
439     /* */
440     max_name_len=0;
441 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]));
442 ksteube 1312 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 phornby 1628 len_txt_buffer=MAX(len_txt_buffer, (dim_t)strlen(tag_Float_DataArray) + LEN_PRINTED_INT_FORMAT + max_len_names);
447 ksteube 1312 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 dhawcroft 793
454 ksteube 1312 /* select number of points and the mesh component */
455 dhawcroft 793
456 ksteube 1312 sprintf(txt_buffer,tags_header,globalNumPoints,numCellFactor*globalNumCells,3);
457 dhawcroft 793
458 ksteube 1312 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 dhawcroft 793
469 ksteube 1312 /* write the nodes */
470    
471     if (mpi_size > 1) {
472 dhawcroft 793
473 ksteube 1312 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 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
499 ksteube 1312 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 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
700 ksteube 1312 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 gross 1741 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 ksteube 1312 for (i = 0; i < numCells; i++) {
815 gross 1741 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 ksteube 1312 } 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 dhawcroft 796
830 ksteube 1312 }
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 dhawcroft 793 }
839 ksteube 1312 } else {
840     fprintf(fileHandle_p,tags_End_Conn_and_Start_Offset);
841     }
842 dhawcroft 796
843 ksteube 1312 /* write the offsets */
844    
845     if ( mpi_size > 1) {
846     txt_buffer[0] = '\0';
847     txt_buffer_in_use=0;
848 gross 1677 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 ksteube 1312 }
852     #ifdef PASO_MPI
853 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
854 ksteube 1312 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 dhawcroft 818 }
860 ksteube 1312
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 dhawcroft 793 }
873 ksteube 1312 /* 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 ksteube 1866 for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=(myFirstCell+myNumCells)*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
879     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
880     }
881 ksteube 1312 #ifdef PASO_MPI
882 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
883 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
884     #endif
885     } else {
886     for (i=0; i<numCells*numCellFactor; i++) fprintf(fileHandle_p, tmp_buffer);
887     }
888     /* finalize cell information */
889     if ( mpi_size > 1) {
890     if ( my_mpi_rank == 0) {
891     #ifdef PASO_MPI
892     MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Type_And_Cells,strlen(tags_End_Type_And_Cells),MPI_CHAR,&mpi_req);
893     MPI_Wait(&mpi_req,&mpi_status);
894     #endif
895 dhawcroft 793 }
896 ksteube 1312 } else {
897     fprintf(fileHandle_p,tags_End_Type_And_Cells);
898 dhawcroft 793 }
899 ksteube 1312 }
900 dhawcroft 818
901 ksteube 1312 /* Write cell data */
902     if (write_celldata && Finley_noError()) {
903     /* mark the active data arrays */
904     txt_buffer[0] = '\0';
905     set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
906     strcat(txt_buffer, "<CellData");
907     for (i_data =0 ;i_data<num_data;++i_data) {
908     if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
909     /* if the rank == 0: --> scalar data */
910     /* if the rank == 1: --> vector data */
911     /* if the rank == 2: --> tensor data */
912 dhawcroft 793
913 ksteube 1312 switch(getDataPointRank(data_pp[i_data])) {
914 dhawcroft 793 case 0:
915 ksteube 1312 if (! set_scalar) {
916     strcat(txt_buffer," Scalars=\"");
917     strcat(txt_buffer,names_p[i_data]);
918     strcat(txt_buffer,"\"");
919 dhawcroft 793 set_scalar=TRUE;
920     }
921     break;
922     case 1:
923 ksteube 1312 if (! set_vector) {
924     strcat(txt_buffer," Vectors=\"");
925     strcat(txt_buffer,names_p[i_data]);
926     strcat(txt_buffer,"\"");
927 dhawcroft 793 set_vector=TRUE;
928     }
929     break;
930     case 2:
931 ksteube 1312 if (! set_tensor) {
932     strcat(txt_buffer," Tensors=\"");
933     strcat(txt_buffer,names_p[i_data]);
934     strcat(txt_buffer,"\"");
935 dhawcroft 793 set_tensor=TRUE;
936     }
937     break;
938     default:
939     sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
940     Finley_setError(VALUE_ERROR,error_msg);
941     return;
942     }
943     }
944     }
945 ksteube 1312 strcat(txt_buffer, ">\n");
946     if ( mpi_size > 1) {
947     if ( my_mpi_rank == 0) {
948     #ifdef PASO_MPI
949     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
950     MPI_Wait(&mpi_req,&mpi_status);
951     #endif
952 dhawcroft 793 }
953 ksteube 1312 } else {
954     fprintf(fileHandle_p,txt_buffer);
955     }
956     /* write the arrays */
957     for (i_data =0 ;i_data<num_data;++i_data) {
958     if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
959     txt_buffer[0] = '\0';
960     txt_buffer_in_use=0;
961     numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
962     rank = getDataPointRank(data_pp[i_data]);
963     nComp = getDataPointSize(data_pp[i_data]);
964     nCompReqd=1; /* the number of components mpi_required by vtk */
965     shape=0;
966     if (rank == 0) {
967     nCompReqd = 1;
968     } else if (rank == 1) {
969     shape=getDataPointShape(data_pp[i_data], 0);
970     if (shape>3) {
971     Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
972     }
973     nCompReqd = 3;
974 gross 903 } else {
975 ksteube 1312 shape=getDataPointShape(data_pp[i_data], 0);
976     if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
977     Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
978     }
979     nCompReqd = 9;
980 gross 903 }
981 ksteube 1312 if (Finley_noError()) {
982     sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
983     if ( mpi_size > 1) {
984     if ( my_mpi_rank == 0) {
985     #ifdef PASO_MPI
986     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
987     MPI_Wait(&mpi_req,&mpi_status);
988     #endif
989     }
990     } else {
991     fprintf(fileHandle_p,txt_buffer);
992     }
993 gross 1741
994 ksteube 1312 for (i=0; i<numCells; i++) {
995     if (elements->Owner[i] == my_mpi_rank) {
996     values = getSampleData(data_pp[i_data], i);
997 gross 1741 for (l=0; l< numCellFactor;++l) {
998     /* averaging over the number of points in the sample */
999 ksteube 1312 if (isExpanded(data_pp[i_data])) {
1000 gross 1741 for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k]=0;
1001     hits=0;
1002     for (j=0; j<numPointsPerSample; j++) {
1003     hits_old=hits;
1004     if (TypeId==Rec9) {
1005     switch(l) {
1006     case 0:
1007     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.25,0.25)) hits++;
1008     break;
1009     case 1:
1010     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.25,0.25)) hits++;
1011     break;
1012     case 2:
1013     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.75,0.25)) hits++;
1014     break;
1015     case 3:
1016     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.75,0.25)) hits++;
1017     break;
1018     }
1019     } else if (TypeId==Hex27) {
1020     switch(l) {
1021     case 0:
1022     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.25,0.25)) hits++;
1023     break;
1024     case 1:
1025     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.25,0.25)) hits++;
1026     break;
1027     case 2:
1028     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.25,0.25)) hits++;
1029     break;
1030     case 3:
1031     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.25,0.25)) hits++;
1032     break;
1033     case 4:
1034     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.75,0.25)) hits++;
1035     break;
1036     case 5:
1037     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.75,0.25)) hits++;
1038     break;
1039     case 6:
1040     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.75,0.25)) hits++;
1041     break;
1042     case 7:
1043     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.75,0.25)) hits++;
1044     break;
1045     }
1046     } else {
1047     hits++;
1048     }
1049     if (hits_old<hits) for (k=0; k<MIN(nComp,NCOMP_MAX); k++) {
1050     sampleAvg[k] += values[INDEX2(k,j,nComp)];
1051     }
1052     }
1053     for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] /=MAX(hits,1);
1054     } else {
1055     for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] = values[k];
1056     }
1057     /* if the number of required components is more than the number
1058     * of actual components, pad with zeros
1059     */
1060     /* probably only need to get shape of first element */
1061     /* write the data different ways for scalar, vector and tensor */
1062     if (nCompReqd == 1) {
1063     sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,sampleAvg[0]);
1064     } else if (nCompReqd == 3) {
1065     if (shape==1) {
1066     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],0.,0.);
1067     } else if (shape==2) {
1068     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],0.);
1069     } else if (shape==3) {
1070     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2]);
1071     }
1072     } else if (nCompReqd == 9) {
1073     if (shape==1) {
1074     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],0.,0.,
1075     0.,0.,0.,
1076 ksteube 1312 0.,0.,0.);
1077 gross 1741 } else if (shape==2) {
1078     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],0.,
1079     sampleAvg[2],sampleAvg[3],0.,
1080     0.,0.,0.);
1081     } else if (shape==3) {
1082     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2],
1083     sampleAvg[3],sampleAvg[4],sampleAvg[5],
1084     sampleAvg[6],sampleAvg[7],sampleAvg[8]);
1085     }
1086     }
1087     /* this needs a bit mor work!!! */
1088     if ( mpi_size > 1) {
1089     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1090     } else {
1091     fprintf(fileHandle_p,tmp_buffer);
1092     }
1093 ksteube 1312 }
1094 gross 1741 }
1095 ksteube 1312 }
1096     if ( mpi_size > 1) {
1097     #ifdef PASO_MPI
1098 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1099 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1100     #endif
1101     if ( my_mpi_rank == 0) {
1102     #ifdef PASO_MPI
1103     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1104     MPI_Wait(&mpi_req,&mpi_status);
1105     #endif
1106     }
1107     } else {
1108     fprintf(fileHandle_p,tag_End_DataArray);
1109     }
1110 dhawcroft 793 }
1111 ksteube 1312 }
1112     }
1113     if ( mpi_size > 1) {
1114     if ( my_mpi_rank == 0) {
1115     #ifdef PASO_MPI
1116     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_CellData,strlen(tag_End_CellData),MPI_CHAR,&mpi_req);
1117     MPI_Wait(&mpi_req,&mpi_status);
1118     #endif
1119 dhawcroft 793 }
1120 ksteube 1312 } else {
1121     fprintf(fileHandle_p,tag_End_CellData);
1122 dhawcroft 793 }
1123     }
1124 ksteube 1312 /* point data */
1125     if (write_pointdata && Finley_noError()) {
1126     /* mark the active data arrays */
1127     set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
1128     txt_buffer[0] = '\0';
1129     strcat(txt_buffer, "<PointData");
1130     for (i_data =0 ;i_data<num_data;++i_data) {
1131     if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1132     /* if the rank == 0: --> scalar data */
1133     /* if the rank == 1: --> vector data */
1134     /* if the rank == 2: --> tensor data */
1135 dhawcroft 793
1136 ksteube 1312 switch(getDataPointRank(data_pp[i_data])) {
1137 dhawcroft 793 case 0:
1138 ksteube 1312 if (! set_scalar) {
1139     strcat(txt_buffer," Scalars=\"");
1140     strcat(txt_buffer,names_p[i_data]);
1141     strcat(txt_buffer,"\"");
1142 dhawcroft 793 set_scalar=TRUE;
1143     }
1144     break;
1145     case 1:
1146 ksteube 1312 if (! set_vector) {
1147     strcat(txt_buffer," Vectors=\"");
1148     strcat(txt_buffer,names_p[i_data]);
1149     strcat(txt_buffer,"\"");
1150 dhawcroft 793 set_vector=TRUE;
1151     }
1152     break;
1153     case 2:
1154 ksteube 1312 if (! set_tensor) {
1155     strcat(txt_buffer," Tensors=\"");
1156     strcat(txt_buffer,names_p[i_data]);
1157     strcat(txt_buffer,"\"");
1158 dhawcroft 793 set_tensor=TRUE;
1159     }
1160     break;
1161     default:
1162     sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
1163     Finley_setError(VALUE_ERROR,error_msg);
1164     return;
1165     }
1166     }
1167     }
1168 ksteube 1312 strcat(txt_buffer, ">\n");
1169     if ( mpi_size > 1) {
1170     if ( my_mpi_rank == 0) {
1171     #ifdef PASO_MPI
1172     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1173     MPI_Wait(&mpi_req,&mpi_status);
1174     #endif
1175 gross 1062 }
1176 ksteube 1312 } else {
1177     fprintf(fileHandle_p,txt_buffer);
1178     }
1179     /* write the arrays */
1180     for (i_data =0 ;i_data<num_data;++i_data) {
1181     if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1182     txt_buffer[0] = '\0';
1183     txt_buffer_in_use=0;
1184     numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
1185     rank = getDataPointRank(data_pp[i_data]);
1186     nComp = getDataPointSize(data_pp[i_data]);
1187     if (getFunctionSpaceType(data_pp[i_data]) == FINLEY_REDUCED_NODES) {
1188     nodeMapping=mesh_p->Nodes->reducedNodesMapping;
1189     } else {
1190     nodeMapping=mesh_p->Nodes->nodesMapping;
1191 dhawcroft 818 }
1192 ksteube 1312 nCompReqd=1; /* the number of components mpi_required by vtk */
1193     shape=0;
1194     if (rank == 0) {
1195     nCompReqd = 1;
1196     } else if (rank == 1) {
1197     shape=getDataPointShape(data_pp[i_data], 0);
1198     if (shape>3) {
1199     Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
1200 dhawcroft 818 }
1201 ksteube 1312 nCompReqd = 3;
1202     } else {
1203     shape=getDataPointShape(data_pp[i_data], 0);
1204     if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
1205     Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
1206 dhawcroft 818 }
1207 ksteube 1312 nCompReqd = 9;
1208 dhawcroft 793 }
1209 ksteube 1312 if (Finley_noError()) {
1210     sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
1211     if ( mpi_size > 1) {
1212     if ( my_mpi_rank == 0) {
1213     #ifdef PASO_MPI
1214     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1215     MPI_Wait(&mpi_req,&mpi_status);
1216     #endif
1217     }
1218     } else {
1219     fprintf(fileHandle_p,txt_buffer);
1220     }
1221     for (i=0; i<mesh_p->Nodes->numNodes; i++) {
1222     k=globalNodeIndex[i];
1223     if ( (myFirstNode <= k) && (k < myLastNode) ) {
1224     values = getSampleData(data_pp[i_data], nodeMapping->target[i]);
1225     /* if the number of mpi_required components is more than the number
1226     * of actual components, pad with zeros
1227     */
1228     /* probably only need to get shape of first element */
1229     /* write the data different ways for scalar, vector and tensor */
1230     if (nCompReqd == 1) {
1231     sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,values[0]);
1232     } else if (nCompReqd == 3) {
1233     if (shape==1) {
1234     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],0.,0.);
1235     } else if (shape==2) {
1236     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],0.);
1237     } else if (shape==3) {
1238     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],values[2]);
1239     }
1240     } else if (nCompReqd == 9) {
1241     if (shape==1) {
1242     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],0.,0.,
1243     0.,0.,0.,
1244     0.,0.,0.);
1245     } else if (shape==2) {
1246     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],0.,
1247     values[2],values[3],0.,
1248     0.,0.,0.);
1249     } else if (shape==3) {
1250     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],values[2],
1251     values[3],values[4],values[5],
1252     values[6],values[7],values[8]);
1253     }
1254     }
1255     if ( mpi_size > 1) {
1256     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1257     } else {
1258     fprintf(fileHandle_p,tmp_buffer);
1259     }
1260     }
1261     }
1262     if ( mpi_size > 1) {
1263     #ifdef PASO_MPI
1264 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1265 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1266     #endif
1267     if ( my_mpi_rank == 0) {
1268     #ifdef PASO_MPI
1269     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1270     MPI_Wait(&mpi_req,&mpi_status);
1271     #endif
1272     }
1273     } else {
1274     fprintf(fileHandle_p,tag_End_DataArray);
1275     }
1276 dhawcroft 793 }
1277     }
1278     }
1279 ksteube 1312 if ( mpi_size > 1) {
1280     if ( my_mpi_rank == 0) {
1281     #ifdef PASO_MPI
1282 gross 1665 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_PointData,strlen(tag_End_PointData),MPI_CHAR,&mpi_req);
1283 ksteube 1312 MPI_Wait(&mpi_req,&mpi_status);
1284     #endif
1285 dhawcroft 793 }
1286 gross 1062 } else {
1287 ksteube 1312 fprintf(fileHandle_p,tag_End_PointData);
1288 gross 1062 }
1289 jgs 110 }
1290 ksteube 1312 if (Finley_noError()) {
1291     if ( mpi_size > 1) {
1292     if ( my_mpi_rank == 0) {
1293     #ifdef PASO_MPI
1294     MPI_File_iwrite_shared(mpi_fileHandle_p,footer,strlen(footer),MPI_CHAR,&mpi_req);
1295     MPI_Wait(&mpi_req,&mpi_status);
1296     #ifdef MPIO_HINTS
1297     MPI_Info_free(&mpi_info);
1298     #undef MPIO_HINTS
1299     #endif
1300     #endif
1301 dhawcroft 793 }
1302 gross 1562 #ifdef PASO_MPI
1303     MPI_File_close(&mpi_fileHandle_p);
1304     #endif
1305 ksteube 1312 } else {
1306     fprintf(fileHandle_p,footer);
1307     fclose(fileHandle_p);
1308     }
1309 jgs 153 }
1310 gross 1028 TMPMEMFREE(isCellCentered);
1311 ksteube 1312 TMPMEMFREE(txt_buffer);
1312 jgs 110 return;
1313 ksteube 1705 #else
1314     /* Don't kill the job if saveVTK() doesn't work */
1315     fprintf(stderr, "\n\nsaveVTK warning: VTK is not available\n\n\n");
1316     #endif
1317 jgs 110 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26