/[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 1990 - (hide annotations)
Fri Nov 7 04:19:07 2008 UTC (10 years, 11 months ago) by ksteube
File MIME type: text/plain
File size: 66555 byte(s)
Changes to avoid compiler warnings
Finley files now pass -Wall on gcc 4.3.2
	saveVTK.c: replaced printf(string) with printf("%s", string)
	MeshAdapterFactory.cpp: moved a few lines to avoid possible use of uninitialized vars
	MeshAdapter.cpp: initialized ncdims in mesh dump
There is still a warning from a boost include file

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 caltinay 1985 double sampleAvg[NCOMP_MAX], *values, *QuadNodes=NULL;
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 caltinay 1985 int mpi_size, i, j, l, cellType=0;
62 gross 1741 dim_t i_data, hits, hits_old;
63 caltinay 1985 dim_t nDim, globalNumPoints=0, numCells=0, globalNumCells=0, numVTKNodesPerElement=0;
64     dim_t myNumPoints=0, numPointsPerSample, rank, nComp, nCompReqd;
65     dim_t shape, NN=0, numCellFactor=0, myNumCells=0, max_name_len;
66     bool_t *isCellCentered=NULL, write_celldata=FALSE, write_pointdata=FALSE, reduced_elements=FALSE;
67     bool_t set_scalar=FALSE, set_vector=FALSE, set_tensor=FALSE;
68     index_t myFirstNode=0, myLastNode=0, *globalNodeIndex=NULL;
69     index_t k, *node_index, myFirstCell=0;
70 ksteube 1312 #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 ksteube 1312 Finley_NodeMapping *nodeMapping=NULL;
83 dhawcroft 793 Finley_ElementFile* elements=NULL;
84 caltinay 1985 ElementTypeId TypeId=0;
85 ksteube 1312
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 caltinay 1985 char* tag_End_DataArray = "</DataArray>\n";
98     char* tag_End_PointData = "</PointData>\n";
99 ksteube 1312 char* tag_End_CellData = "</CellData>\n";
100 caltinay 1985 char* footer = "</Piece>\n</UnstructuredGrid>\n</VTKFile>\n";
101 ksteube 1312 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 caltinay 1985 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 caltinay 1985
109 ksteube 1312 /* 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     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     break;
333    
334     case Tri3:
335     case Tet4Face:
336     case Tet4Face_Contact:
337     numCellFactor=1;
338     cellType = VTK_TRIANGLE;
339     numVTKNodesPerElement = 3;
340     break;
341    
342     case Rec4:
343     case Hex8Face:
344     case Rec4_Contact:
345     case Hex8Face_Contact:
346     numCellFactor=1;
347     cellType = VTK_QUAD;
348     numVTKNodesPerElement = 4;
349     break;
350 gross 1741
351     case Rec9:
352     numCellFactor=4;
353     cellType = VTK_QUAD;
354     numVTKNodesPerElement = 4;
355     break;
356 ksteube 1312
357     case Tet4:
358     numCellFactor=1;
359     cellType = VTK_TETRA;
360     numVTKNodesPerElement = 4;
361     break;
362    
363     case Hex8:
364     numCellFactor=1;
365     cellType = VTK_HEXAHEDRON;
366     numVTKNodesPerElement = 8;
367     break;
368    
369     case Line3:
370     case Tri6Face:
371     case Rec8Face:
372     case Line3_Contact:
373     case Tri6Face_Contact:
374     case Rec8Face_Contact:
375     numCellFactor=1;
376     cellType = VTK_QUADRATIC_EDGE;
377     numVTKNodesPerElement = 3;
378     break;
379    
380     case Tri6:
381     case Tet10Face:
382     case Tri6_Contact:
383     case Tet10Face_Contact:
384     numCellFactor=1;
385     cellType = VTK_QUADRATIC_TRIANGLE;
386     numVTKNodesPerElement = 6;
387     break;
388    
389     case Rec8:
390     case Hex20Face:
391     case Rec8_Contact:
392     case Hex20Face_Contact:
393     numCellFactor=1;
394     cellType = VTK_QUADRATIC_QUAD;
395     numVTKNodesPerElement = 8;
396     break;
397    
398     case Tet10:
399     numCellFactor=1;
400     cellType = VTK_QUADRATIC_TETRA;
401     numVTKNodesPerElement = 10;
402     break;
403    
404     case Hex20:
405     numCellFactor=1;
406     cellType = VTK_QUADRATIC_HEXAHEDRON;
407     numVTKNodesPerElement = 20;
408     break;
409 gross 1741
410     case Hex27:
411     numCellFactor=8;
412     cellType = VTK_HEXAHEDRON;
413     numVTKNodesPerElement = 8;
414     break;
415 ksteube 1312
416     default:
417     sprintf(error_msg, "saveVTK: Element type %s is not supported by VTK",elements->ReferenceElement->Type->Name);
418     Finley_setError(VALUE_ERROR,error_msg);
419     }
420     }
421 dhawcroft 793 }
422 ksteube 1312 /***************************************/
423 dhawcroft 793
424 ksteube 1312 /***************************************/
425     /* */
426     /* allocate text buffer */
427     /* */
428     max_name_len=0;
429 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]));
430 ksteube 1312 len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT + (30+3*max_name_len); /* header */
431     if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints * LEN_TMP_BUFFER);
432     if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*(LEN_PRINTED_INT_FORMAT*numVTKNodesPerElement+1));
433     len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);
434 phornby 1628 len_txt_buffer=MAX(len_txt_buffer, (dim_t)strlen(tag_Float_DataArray) + LEN_PRINTED_INT_FORMAT + max_len_names);
435 ksteube 1312 if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
436     if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
437     txt_buffer=TMPMEMALLOC(len_txt_buffer+1,char);
438     Finley_checkPtr(txt_buffer);
439    
440     if (Finley_noError()) {
441 dhawcroft 793
442 ksteube 1312 /* select number of points and the mesh component */
443 dhawcroft 793
444 ksteube 1312 sprintf(txt_buffer,tags_header,globalNumPoints,numCellFactor*globalNumCells,3);
445 dhawcroft 793
446 ksteube 1312 if (mpi_size > 1) {
447     if ( my_mpi_rank == 0) {
448     #ifdef PASO_MPI
449     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
450     MPI_Wait(&mpi_req,&mpi_status);
451     #endif
452     }
453     } else {
454 ksteube 1990 fprintf(fileHandle_p, "%s", txt_buffer);
455 ksteube 1312 }
456 dhawcroft 793
457 ksteube 1312 /* write the nodes */
458    
459     if (mpi_size > 1) {
460 dhawcroft 793
461 ksteube 1312 txt_buffer[0] = '\0';
462     txt_buffer_in_use=0;
463     if (nDim==2) {
464     for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
465     if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
466     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,
467     mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
468     mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
469     0.);
470     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
471     }
472     }
473     } else {
474     for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
475     if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
476     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,
477     mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
478     mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
479     mesh_p->Nodes->Coordinates[INDEX2(2, i, nDim)]);
480     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
481     }
482     }
483    
484     }
485     #ifdef PASO_MPI
486 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
487 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p, txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
488     #endif
489     } else {
490     if (nDim==2) {
491     for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
492     if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
493     fprintf(fileHandle_p,FLOAT_VECTOR_FORMAT,
494     mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
495     mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
496     0.);
497     }
498     }
499     } else {
500     for (i = 0; i < mesh_p->Nodes->numNodes; i++) {
501     if ( (myFirstNode <= globalNodeIndex[i]) && (globalNodeIndex[i] < myLastNode) ) {
502     fprintf(fileHandle_p,FLOAT_VECTOR_FORMAT,
503     mesh_p->Nodes->Coordinates[INDEX2(0, i, nDim)],
504     mesh_p->Nodes->Coordinates[INDEX2(1, i, nDim)],
505     mesh_p->Nodes->Coordinates[INDEX2(2, i, nDim)]);
506     }
507     }
508    
509     }
510     }
511 dhawcroft 796
512 ksteube 1312 /* close the Points and open connectivity */
513 dhawcroft 793
514 ksteube 1312 if (mpi_size > 1) {
515     if ( my_mpi_rank == 0) {
516     #ifdef PASO_MPI
517     MPI_File_iwrite_shared(mpi_fileHandle_p, tags_End_Points_and_Start_Conn, strlen(tags_End_Points_and_Start_Conn), MPI_CHAR, &mpi_req);
518     MPI_Wait(&mpi_req,&mpi_status);
519     #endif
520     }
521     } else {
522 ksteube 1990 fprintf(fileHandle_p, "%s", tags_End_Points_and_Start_Conn);
523 dhawcroft 793 }
524    
525 ksteube 1312 /* write the cells */
526     if (nodetype == FINLEY_REDUCED_NODES) {
527     node_index=elements->ReferenceElement->Type->linearNodes;
528     } else if (VTK_QUADRATIC_HEXAHEDRON==cellType) {
529     node_index=VTK_QUADRATIC_HEXAHEDRON_INDEX;
530 gross 1741 } else if ( (numVTKNodesPerElement!=NN) && (TypeId!=Rec9) && (TypeId!=Hex27) ) {
531 ksteube 1312 node_index=elements->ReferenceElement->Type->geoNodes;
532     } else {
533     node_index=NULL;
534     }
535 dhawcroft 793
536 ksteube 1312 if ( mpi_size > 1) {
537     txt_buffer[0] = '\0';
538     txt_buffer_in_use=0;
539     if (node_index == NULL) {
540 gross 1741 if (TypeId==Rec9) {
541     for (i = 0; i < numCells; i++) {
542     if (elements->Owner[i] == my_mpi_rank) {
543     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(0, i, NN)]]);
544     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
545     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
546     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
547     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
548     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
549    
550     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
551     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(1, i, NN)]]);
552     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
553     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
554     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
555     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
556    
557     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
558     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
559     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
560     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(3, i, NN)]]);
561     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
562     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
563    
564     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
565     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
566     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(2, i, NN)]]);
567     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
568     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
569     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
570     }
571     }
572     } else if (TypeId==Hex27) {
573     for (i = 0; i < numCells; i++) {
574     if (elements->Owner[i] == my_mpi_rank) {
575     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 0, i, NN)]]);
576     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
577     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
578     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
579     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
580     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
581     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
582     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
583     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
584     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
585    
586     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
587     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 1, i, NN)]]);
588     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, 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(21, i, NN)]]);
591     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
592     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
593     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
594     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
595     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
596    
597     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
598     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
599     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
600     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 3, i, NN)]]);
601     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
602     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
603     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
604     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
605     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
606     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
607    
608     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
609     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
610     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 2, 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(26, i, NN)]]);
613     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
614     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
615     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
616     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
617     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
618    
619     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
620     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
621     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
622     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
623     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 4, i, NN)]]);
624     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
625     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
626     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
627     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
628     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
629    
630     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
631     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
632     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, 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(16, i, NN)]]);
635     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 5, i, NN)]]);
636     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
637     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
638     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
639     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
640    
641     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
642     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
643     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
644     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
645     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
646     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
647     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
648     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 7, i, NN)]]);
649     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
650     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
651    
652     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
653     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
654     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, 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(25, i, NN)]]);
657     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
658     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 6, i, NN)]]);
659     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
660     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
661     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
662 ksteube 1312 }
663     }
664 gross 1741 } else {
665     for (i = 0; i < numCells; i++) {
666     if (elements->Owner[i] == my_mpi_rank) {
667     for (j = 0; j < numVTKNodesPerElement; j++) {
668     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(j, i, NN)]]);
669     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
670     }
671     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
672     }
673     }
674 ksteube 1312 }
675     } else {
676     for (i = 0; i < numCells; i++) {
677     if (elements->Owner[i] == my_mpi_rank) {
678     for (j = 0; j < numVTKNodesPerElement; j++) {
679     sprintf(tmp_buffer,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(node_index[j], i, NN)]]);
680     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use)
681     }
682     __STRCAT(txt_buffer,NEWLINE,txt_buffer_in_use)
683     }
684     }
685     }
686     #ifdef PASO_MPI
687 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
688 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
689     #endif
690     } else {
691     if (node_index == NULL) {
692 gross 1741 if (TypeId==Rec9) {
693     for (i = 0; i < numCells; i++) {
694     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(0, i, NN)]]);
695     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
696     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
697     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, i, NN)]]);
698     fprintf(fileHandle_p,NEWLINE);
699    
700     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(4, i, NN)]]);
701     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(1, i, NN)]]);
702     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(5, i, NN)]]);
703     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, i, NN)]]);
704     fprintf(fileHandle_p,NEWLINE);
705    
706     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(7, 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(6, i, NN)]]);
709     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(3, i, NN)]]);
710     fprintf(fileHandle_p,NEWLINE);
711    
712     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(8, 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(2, i, NN)]]);
715     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(6, i, NN)]]);
716     fprintf(fileHandle_p,NEWLINE);
717     }
718    
719     } else if (TypeId==Hex27) {
720     for (i = 0; i < numCells; i++) {
721     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 0, i, NN)]]);
722     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
723     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
724     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
725     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
726     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
727     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
728     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
729     fprintf(fileHandle_p,NEWLINE);
730    
731     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 8, i, NN)]]);
732     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 1, i, NN)]]);
733     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, 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(21, i, NN)]]);
736     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
737     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
738     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
739     fprintf(fileHandle_p,NEWLINE);
740    
741     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(11, i, NN)]]);
742     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
743     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(10, i, NN)]]);
744     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 3, i, NN)]]);
745     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
746     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
747     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
748     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
749     fprintf(fileHandle_p,NEWLINE);
750    
751     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(20, i, NN)]]);
752     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 9, i, NN)]]);
753     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 2, 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(26, i, NN)]]);
756     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
757     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, i, NN)]]);
758     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
759     fprintf(fileHandle_p,NEWLINE);
760    
761     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(12, i, NN)]]);
762     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
763     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
764     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
765     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 4, i, NN)]]);
766     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(16, i, NN)]]);
767     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
768     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
769     fprintf(fileHandle_p,NEWLINE);
770    
771     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(21, i, NN)]]);
772     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(13, i, NN)]]);
773     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, 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(16, i, NN)]]);
776     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 5, i, NN)]]);
777     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
778     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
779     fprintf(fileHandle_p,NEWLINE);
780    
781     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(24, i, NN)]]);
782     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
783     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(23, i, NN)]]);
784     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(15, i, NN)]]);
785     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(19, i, NN)]]);
786     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(25, i, NN)]]);
787     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
788     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 7, i, NN)]]);
789     fprintf(fileHandle_p,NEWLINE);
790    
791     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(26, i, NN)]]);
792     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(22, i, NN)]]);
793     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(14, 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(25, i, NN)]]);
796     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(17, i, NN)]]);
797     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2( 6, i, NN)]]);
798     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(18, i, NN)]]);
799     fprintf(fileHandle_p,NEWLINE);
800     }
801     } else {
802 ksteube 1312 for (i = 0; i < numCells; i++) {
803 gross 1741 for (j = 0; j < numVTKNodesPerElement; j++) {
804     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(j, i, NN)]]);
805     }
806     fprintf(fileHandle_p,NEWLINE);
807     }
808     }
809 ksteube 1312 } else {
810     for (i = 0; i < numCells; i++) {
811     for (j = 0; j < numVTKNodesPerElement; j++) {
812     fprintf(fileHandle_p,INT_FORMAT,globalNodeIndex[elements->Nodes[INDEX2(node_index[j], i, NN)]]);
813     }
814     fprintf(fileHandle_p,NEWLINE);
815     }
816     }
817 dhawcroft 796
818 ksteube 1312 }
819     /* finalize the connection and start the offset section */
820     if (mpi_size > 1) {
821     if( my_mpi_rank == 0) {
822     #ifdef PASO_MPI
823     MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Conn_and_Start_Offset,strlen(tags_End_Conn_and_Start_Offset),MPI_CHAR,&mpi_req);
824     MPI_Wait(&mpi_req,&mpi_status);
825     #endif
826 dhawcroft 793 }
827 ksteube 1312 } else {
828 ksteube 1990 fprintf(fileHandle_p, "%s", tags_End_Conn_and_Start_Offset);
829 ksteube 1312 }
830 dhawcroft 796
831 ksteube 1312 /* write the offsets */
832    
833     if ( mpi_size > 1) {
834     txt_buffer[0] = '\0';
835     txt_buffer_in_use=0;
836 gross 1677 for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=(myFirstCell+myNumCells)*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
837     sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);
838     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
839 ksteube 1312 }
840     #ifdef PASO_MPI
841 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
842 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
843     #endif
844     } else {
845     for (i=numVTKNodesPerElement; i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
846     fprintf(fileHandle_p, INT_NEWLINE_FORMAT, i);
847 dhawcroft 818 }
848 ksteube 1312
849     }
850     /* finalize the offset section and start the type section */
851     if ( mpi_size > 1) {
852     if ( my_mpi_rank == 0) {
853     #ifdef PASO_MPI
854     MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Offset_and_Start_Type,strlen(tags_End_Offset_and_Start_Type),MPI_CHAR,&mpi_req);
855     MPI_Wait(&mpi_req,&mpi_status);
856     #endif
857     }
858     } else {
859 ksteube 1990 fprintf(fileHandle_p, "%s", tags_End_Offset_and_Start_Type);
860 dhawcroft 793 }
861 ksteube 1312 /* write element type */
862     sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);
863     if ( mpi_size > 1) {
864     txt_buffer[0] = '\0';
865     txt_buffer_in_use=0;
866 ksteube 1866 for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=(myFirstCell+myNumCells)*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
867     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
868     }
869 ksteube 1312 #ifdef PASO_MPI
870 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
871 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
872     #endif
873     } else {
874 ksteube 1990 for (i=0; i<numCells*numCellFactor; i++) fprintf(fileHandle_p, "%s", tmp_buffer);
875 ksteube 1312 }
876     /* finalize cell information */
877     if ( mpi_size > 1) {
878     if ( my_mpi_rank == 0) {
879     #ifdef PASO_MPI
880     MPI_File_iwrite_shared(mpi_fileHandle_p,tags_End_Type_And_Cells,strlen(tags_End_Type_And_Cells),MPI_CHAR,&mpi_req);
881     MPI_Wait(&mpi_req,&mpi_status);
882     #endif
883 dhawcroft 793 }
884 ksteube 1312 } else {
885 ksteube 1990 fprintf(fileHandle_p, "%s", tags_End_Type_And_Cells);
886 dhawcroft 793 }
887 ksteube 1312 }
888 dhawcroft 818
889 ksteube 1312 /* Write cell data */
890     if (write_celldata && Finley_noError()) {
891     /* mark the active data arrays */
892     txt_buffer[0] = '\0';
893     set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
894     strcat(txt_buffer, "<CellData");
895     for (i_data =0 ;i_data<num_data;++i_data) {
896     if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
897     /* if the rank == 0: --> scalar data */
898     /* if the rank == 1: --> vector data */
899     /* if the rank == 2: --> tensor data */
900 dhawcroft 793
901 ksteube 1312 switch(getDataPointRank(data_pp[i_data])) {
902 dhawcroft 793 case 0:
903 ksteube 1312 if (! set_scalar) {
904     strcat(txt_buffer," Scalars=\"");
905     strcat(txt_buffer,names_p[i_data]);
906     strcat(txt_buffer,"\"");
907 dhawcroft 793 set_scalar=TRUE;
908     }
909     break;
910     case 1:
911 ksteube 1312 if (! set_vector) {
912     strcat(txt_buffer," Vectors=\"");
913     strcat(txt_buffer,names_p[i_data]);
914     strcat(txt_buffer,"\"");
915 dhawcroft 793 set_vector=TRUE;
916     }
917     break;
918     case 2:
919 ksteube 1312 if (! set_tensor) {
920     strcat(txt_buffer," Tensors=\"");
921     strcat(txt_buffer,names_p[i_data]);
922     strcat(txt_buffer,"\"");
923 dhawcroft 793 set_tensor=TRUE;
924     }
925     break;
926     default:
927     sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
928     Finley_setError(VALUE_ERROR,error_msg);
929     return;
930     }
931     }
932     }
933 ksteube 1312 strcat(txt_buffer, ">\n");
934     if ( mpi_size > 1) {
935     if ( my_mpi_rank == 0) {
936     #ifdef PASO_MPI
937     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
938     MPI_Wait(&mpi_req,&mpi_status);
939     #endif
940 dhawcroft 793 }
941 ksteube 1312 } else {
942 ksteube 1990 fprintf(fileHandle_p, "%s", txt_buffer);
943 ksteube 1312 }
944     /* write the arrays */
945     for (i_data =0 ;i_data<num_data;++i_data) {
946     if (! isEmpty(data_pp[i_data]) && isCellCentered[i_data]) {
947     txt_buffer[0] = '\0';
948     txt_buffer_in_use=0;
949     numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
950     rank = getDataPointRank(data_pp[i_data]);
951     nComp = getDataPointSize(data_pp[i_data]);
952     nCompReqd=1; /* the number of components mpi_required by vtk */
953     shape=0;
954     if (rank == 0) {
955     nCompReqd = 1;
956     } else if (rank == 1) {
957     shape=getDataPointShape(data_pp[i_data], 0);
958     if (shape>3) {
959     Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
960     }
961     nCompReqd = 3;
962 gross 903 } else {
963 ksteube 1312 shape=getDataPointShape(data_pp[i_data], 0);
964     if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
965     Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
966     }
967     nCompReqd = 9;
968 gross 903 }
969 ksteube 1312 if (Finley_noError()) {
970     sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
971     if ( mpi_size > 1) {
972     if ( my_mpi_rank == 0) {
973     #ifdef PASO_MPI
974     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
975     MPI_Wait(&mpi_req,&mpi_status);
976     #endif
977     }
978     } else {
979 ksteube 1990 fprintf(fileHandle_p, "%s", txt_buffer);
980 ksteube 1312 }
981 gross 1741
982 ksteube 1312 for (i=0; i<numCells; i++) {
983     if (elements->Owner[i] == my_mpi_rank) {
984     values = getSampleData(data_pp[i_data], i);
985 gross 1741 for (l=0; l< numCellFactor;++l) {
986     /* averaging over the number of points in the sample */
987 ksteube 1312 if (isExpanded(data_pp[i_data])) {
988 gross 1741 for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k]=0;
989     hits=0;
990     for (j=0; j<numPointsPerSample; j++) {
991     hits_old=hits;
992     if (TypeId==Rec9) {
993     switch(l) {
994     case 0:
995     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.25,0.25)) hits++;
996     break;
997     case 1:
998     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.25,0.25)) hits++;
999     break;
1000     case 2:
1001     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.25,0.75,0.25)) hits++;
1002     break;
1003     case 3:
1004     if (INSIDE_2D(QuadNodes[2*j],QuadNodes[2*j+1],0.75,0.75,0.25)) hits++;
1005     break;
1006     }
1007     } else if (TypeId==Hex27) {
1008     switch(l) {
1009     case 0:
1010     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.25,0.25)) hits++;
1011     break;
1012     case 1:
1013     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.25,0.25)) hits++;
1014     break;
1015     case 2:
1016     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.25,0.25)) hits++;
1017     break;
1018     case 3:
1019     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.25,0.25)) hits++;
1020     break;
1021     case 4:
1022     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.25,0.75,0.25)) hits++;
1023     break;
1024     case 5:
1025     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.25,0.75,0.25)) hits++;
1026     break;
1027     case 6:
1028     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.25,0.75,0.75,0.25)) hits++;
1029     break;
1030     case 7:
1031     if (INSIDE_3D(QuadNodes[3*j],QuadNodes[3*j+1],QuadNodes[3*j+2],0.75,0.75,0.75,0.25)) hits++;
1032     break;
1033     }
1034     } else {
1035     hits++;
1036     }
1037     if (hits_old<hits) for (k=0; k<MIN(nComp,NCOMP_MAX); k++) {
1038     sampleAvg[k] += values[INDEX2(k,j,nComp)];
1039     }
1040     }
1041     for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] /=MAX(hits,1);
1042     } else {
1043     for (k=0; k<MIN(nComp,NCOMP_MAX); k++) sampleAvg[k] = values[k];
1044     }
1045     /* if the number of required components is more than the number
1046     * of actual components, pad with zeros
1047     */
1048     /* probably only need to get shape of first element */
1049     /* write the data different ways for scalar, vector and tensor */
1050     if (nCompReqd == 1) {
1051     sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,sampleAvg[0]);
1052     } else if (nCompReqd == 3) {
1053     if (shape==1) {
1054     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],0.,0.);
1055     } else if (shape==2) {
1056     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],0.);
1057     } else if (shape==3) {
1058     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2]);
1059     }
1060     } else if (nCompReqd == 9) {
1061     if (shape==1) {
1062     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],0.,0.,
1063     0.,0.,0.,
1064 ksteube 1312 0.,0.,0.);
1065 gross 1741 } else if (shape==2) {
1066     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],0.,
1067     sampleAvg[2],sampleAvg[3],0.,
1068     0.,0.,0.);
1069     } else if (shape==3) {
1070     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,sampleAvg[0],sampleAvg[1],sampleAvg[2],
1071     sampleAvg[3],sampleAvg[4],sampleAvg[5],
1072     sampleAvg[6],sampleAvg[7],sampleAvg[8]);
1073     }
1074     }
1075     /* this needs a bit mor work!!! */
1076     if ( mpi_size > 1) {
1077     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1078     } else {
1079 ksteube 1990 fprintf(fileHandle_p, "%s", tmp_buffer);
1080 gross 1741 }
1081 ksteube 1312 }
1082 gross 1741 }
1083 ksteube 1312 }
1084     if ( mpi_size > 1) {
1085     #ifdef PASO_MPI
1086 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1087 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1088     #endif
1089     if ( my_mpi_rank == 0) {
1090     #ifdef PASO_MPI
1091     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1092     MPI_Wait(&mpi_req,&mpi_status);
1093     #endif
1094     }
1095     } else {
1096 ksteube 1990 fprintf(fileHandle_p, "%s", tag_End_DataArray);
1097 ksteube 1312 }
1098 dhawcroft 793 }
1099 ksteube 1312 }
1100     }
1101     if ( mpi_size > 1) {
1102     if ( my_mpi_rank == 0) {
1103     #ifdef PASO_MPI
1104     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_CellData,strlen(tag_End_CellData),MPI_CHAR,&mpi_req);
1105     MPI_Wait(&mpi_req,&mpi_status);
1106     #endif
1107 dhawcroft 793 }
1108 ksteube 1312 } else {
1109 ksteube 1990 fprintf(fileHandle_p, "%s", tag_End_CellData);
1110 dhawcroft 793 }
1111     }
1112 ksteube 1312 /* point data */
1113     if (write_pointdata && Finley_noError()) {
1114     /* mark the active data arrays */
1115     set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
1116     txt_buffer[0] = '\0';
1117     strcat(txt_buffer, "<PointData");
1118     for (i_data =0 ;i_data<num_data;++i_data) {
1119     if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1120     /* if the rank == 0: --> scalar data */
1121     /* if the rank == 1: --> vector data */
1122     /* if the rank == 2: --> tensor data */
1123 dhawcroft 793
1124 ksteube 1312 switch(getDataPointRank(data_pp[i_data])) {
1125 dhawcroft 793 case 0:
1126 ksteube 1312 if (! set_scalar) {
1127     strcat(txt_buffer," Scalars=\"");
1128     strcat(txt_buffer,names_p[i_data]);
1129     strcat(txt_buffer,"\"");
1130 dhawcroft 793 set_scalar=TRUE;
1131     }
1132     break;
1133     case 1:
1134 ksteube 1312 if (! set_vector) {
1135     strcat(txt_buffer," Vectors=\"");
1136     strcat(txt_buffer,names_p[i_data]);
1137     strcat(txt_buffer,"\"");
1138 dhawcroft 793 set_vector=TRUE;
1139     }
1140     break;
1141     case 2:
1142 ksteube 1312 if (! set_tensor) {
1143     strcat(txt_buffer," Tensors=\"");
1144     strcat(txt_buffer,names_p[i_data]);
1145     strcat(txt_buffer,"\"");
1146 dhawcroft 793 set_tensor=TRUE;
1147     }
1148     break;
1149     default:
1150     sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
1151     Finley_setError(VALUE_ERROR,error_msg);
1152     return;
1153     }
1154     }
1155     }
1156 ksteube 1312 strcat(txt_buffer, ">\n");
1157     if ( mpi_size > 1) {
1158     if ( my_mpi_rank == 0) {
1159     #ifdef PASO_MPI
1160     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1161     MPI_Wait(&mpi_req,&mpi_status);
1162     #endif
1163 gross 1062 }
1164 ksteube 1312 } else {
1165 ksteube 1990 fprintf(fileHandle_p, "%s", txt_buffer);
1166 ksteube 1312 }
1167     /* write the arrays */
1168     for (i_data =0 ;i_data<num_data;++i_data) {
1169     if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
1170     txt_buffer[0] = '\0';
1171     txt_buffer_in_use=0;
1172     numPointsPerSample=getNumDataPointsPerSample(data_pp[i_data]);
1173     rank = getDataPointRank(data_pp[i_data]);
1174     nComp = getDataPointSize(data_pp[i_data]);
1175     if (getFunctionSpaceType(data_pp[i_data]) == FINLEY_REDUCED_NODES) {
1176     nodeMapping=mesh_p->Nodes->reducedNodesMapping;
1177     } else {
1178     nodeMapping=mesh_p->Nodes->nodesMapping;
1179 dhawcroft 818 }
1180 ksteube 1312 nCompReqd=1; /* the number of components mpi_required by vtk */
1181     shape=0;
1182     if (rank == 0) {
1183     nCompReqd = 1;
1184     } else if (rank == 1) {
1185     shape=getDataPointShape(data_pp[i_data], 0);
1186     if (shape>3) {
1187     Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
1188 dhawcroft 818 }
1189 ksteube 1312 nCompReqd = 3;
1190     } else {
1191     shape=getDataPointShape(data_pp[i_data], 0);
1192     if (shape>3 || shape != getDataPointShape(data_pp[i_data], 1)) {
1193     Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
1194 dhawcroft 818 }
1195 ksteube 1312 nCompReqd = 9;
1196 dhawcroft 793 }
1197 ksteube 1312 if (Finley_noError()) {
1198     sprintf(txt_buffer,tag_Float_DataArray,names_p[i_data], nCompReqd);
1199     if ( mpi_size > 1) {
1200     if ( my_mpi_rank == 0) {
1201     #ifdef PASO_MPI
1202     MPI_File_iwrite_shared(mpi_fileHandle_p,txt_buffer,strlen(txt_buffer),MPI_CHAR,&mpi_req);
1203     MPI_Wait(&mpi_req,&mpi_status);
1204     #endif
1205     }
1206     } else {
1207 ksteube 1990 fprintf(fileHandle_p, "%s", txt_buffer);
1208 ksteube 1312 }
1209     for (i=0; i<mesh_p->Nodes->numNodes; i++) {
1210     k=globalNodeIndex[i];
1211     if ( (myFirstNode <= k) && (k < myLastNode) ) {
1212     values = getSampleData(data_pp[i_data], nodeMapping->target[i]);
1213     /* if the number of mpi_required components is more than the number
1214     * of actual components, pad with zeros
1215     */
1216     /* probably only need to get shape of first element */
1217     /* write the data different ways for scalar, vector and tensor */
1218     if (nCompReqd == 1) {
1219     sprintf(tmp_buffer,FLOAT_SCALAR_FORMAT,values[0]);
1220     } else if (nCompReqd == 3) {
1221     if (shape==1) {
1222     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],0.,0.);
1223     } else if (shape==2) {
1224     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],0.);
1225     } else if (shape==3) {
1226     sprintf(tmp_buffer,FLOAT_VECTOR_FORMAT,values[0],values[1],values[2]);
1227     }
1228     } else if (nCompReqd == 9) {
1229     if (shape==1) {
1230     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],0.,0.,
1231     0.,0.,0.,
1232     0.,0.,0.);
1233     } else if (shape==2) {
1234     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],0.,
1235     values[2],values[3],0.,
1236     0.,0.,0.);
1237     } else if (shape==3) {
1238     sprintf(tmp_buffer,FLOAT_TENSOR_FORMAT,values[0],values[1],values[2],
1239     values[3],values[4],values[5],
1240     values[6],values[7],values[8]);
1241     }
1242     }
1243     if ( mpi_size > 1) {
1244     __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
1245     } else {
1246 ksteube 1990 fprintf(fileHandle_p, "%s", tmp_buffer);
1247 ksteube 1312 }
1248     }
1249     }
1250     if ( mpi_size > 1) {
1251     #ifdef PASO_MPI
1252 ksteube 1743 if (txt_buffer_in_use==0) { strcpy(txt_buffer, " "); txt_buffer_in_use = 1; } /* avoid zero-length writes */
1253 ksteube 1312 MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
1254     #endif
1255     if ( my_mpi_rank == 0) {
1256     #ifdef PASO_MPI
1257     MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_DataArray,strlen(tag_End_DataArray),MPI_CHAR,&mpi_req);
1258     MPI_Wait(&mpi_req,&mpi_status);
1259     #endif
1260     }
1261     } else {
1262 ksteube 1990 fprintf(fileHandle_p, "%s", tag_End_DataArray);
1263 ksteube 1312 }
1264 dhawcroft 793 }
1265     }
1266     }
1267 ksteube 1312 if ( mpi_size > 1) {
1268     if ( my_mpi_rank == 0) {
1269     #ifdef PASO_MPI
1270 gross 1665 MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_PointData,strlen(tag_End_PointData),MPI_CHAR,&mpi_req);
1271 ksteube 1312 MPI_Wait(&mpi_req,&mpi_status);
1272     #endif
1273 dhawcroft 793 }
1274 gross 1062 } else {
1275 ksteube 1990 fprintf(fileHandle_p, "%s", tag_End_PointData);
1276 gross 1062 }
1277 jgs 110 }
1278 ksteube 1312 if (Finley_noError()) {
1279     if ( mpi_size > 1) {
1280     if ( my_mpi_rank == 0) {
1281     #ifdef PASO_MPI
1282     MPI_File_iwrite_shared(mpi_fileHandle_p,footer,strlen(footer),MPI_CHAR,&mpi_req);
1283     MPI_Wait(&mpi_req,&mpi_status);
1284     #ifdef MPIO_HINTS
1285     MPI_Info_free(&mpi_info);
1286     #undef MPIO_HINTS
1287     #endif
1288     #endif
1289 dhawcroft 793 }
1290 gross 1562 #ifdef PASO_MPI
1291     MPI_File_close(&mpi_fileHandle_p);
1292     #endif
1293 ksteube 1312 } else {
1294 ksteube 1990 fprintf(fileHandle_p, "%s", footer);
1295 ksteube 1312 fclose(fileHandle_p);
1296     }
1297 jgs 153 }
1298 gross 1028 TMPMEMFREE(isCellCentered);
1299 ksteube 1312 TMPMEMFREE(txt_buffer);
1300 jgs 110 return;
1301 ksteube 1705 #else
1302     /* Don't kill the job if saveVTK() doesn't work */
1303     fprintf(stderr, "\n\nsaveVTK warning: VTK is not available\n\n\n");
1304     #endif
1305 jgs 110 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26