27 |
#include "Mesh.h" |
#include "Mesh.h" |
28 |
#include "vtkCellType.h" /* copied from vtk source directory !!! */ |
#include "vtkCellType.h" /* copied from vtk source directory !!! */ |
29 |
|
|
30 |
|
#define CLIP_VALUE(__VAL_) (ABS(__VAL_)<1.e-44 ? (float) 0 : (float)(__VAL_)) |
31 |
|
|
32 |
/**************************************************************/ |
/**************************************************************/ |
33 |
|
|
34 |
void Finley_Mesh_saveVTK(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p, escriptDataC* *data_pp) { |
void Finley_Mesh_saveVTK(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p, escriptDataC* *data_pp) { |
326 |
if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM) { |
if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM) { |
327 |
for (i = 0; i < mesh_p->Nodes->numNodes; i++) { |
for (i = 0; i < mesh_p->Nodes->numNodes; i++) { |
328 |
if (mesh_p->Nodes->toReduced[i]>=0) { |
if (mesh_p->Nodes->toReduced[i]>=0) { |
329 |
for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %e",(float) (mesh_p->Nodes->Coordinates[INDEX2(j, i, nDim)])); |
for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %e",CLIP_VALUE(mesh_p->Nodes->Coordinates[INDEX2(j, i, nDim)])); |
330 |
for (k=0; k<3-nDim; k++) fprintf(fileHandle_p, " %e",(float) 0.); |
for (k=0; k<3-nDim; k++) fprintf(fileHandle_p, " %e",CLIP_VALUE(0.)); |
331 |
fprintf(fileHandle_p, "\n"); |
fprintf(fileHandle_p, "\n"); |
332 |
} |
} |
333 |
} |
} |
334 |
} else { |
} else { |
335 |
for (i = 0; i < mesh_p->Nodes->numNodes; i++) { |
for (i = 0; i < mesh_p->Nodes->numNodes; i++) { |
336 |
for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %e",(float) (mesh_p->Nodes->Coordinates[INDEX2(j, i, nDim)])); |
for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %e",CLIP_VALUE(mesh_p->Nodes->Coordinates[INDEX2(j, i, nDim)])); |
337 |
for (k=0; k<3-nDim; k++) fprintf(fileHandle_p, " %e",(float) 0.); |
for (k=0; k<3-nDim; k++) fprintf(fileHandle_p, " %e",CLIP_VALUE(0.)); |
338 |
fprintf(fileHandle_p, "\n"); |
fprintf(fileHandle_p, "\n"); |
339 |
} |
} |
340 |
} |
} |
486 |
/* probably only need to get shape of first element */ |
/* probably only need to get shape of first element */ |
487 |
/* write the data different ways for scalar, vector and tensor */ |
/* write the data different ways for scalar, vector and tensor */ |
488 |
if (nCompReqd == 1) { |
if (nCompReqd == 1) { |
489 |
fprintf(fileHandle_p, " %e", (float) sampleAvg[0]); |
fprintf(fileHandle_p, " %e", CLIP_VALUE(sampleAvg[0])); |
490 |
} else if (nCompReqd == 3) { |
} else if (nCompReqd == 3) { |
491 |
/* write out the data */ |
/* write out the data */ |
492 |
for (int m=0; m<shape; m++) fprintf(fileHandle_p, " %e", (float) sampleAvg[m]); |
for (int m=0; m<shape; m++) fprintf(fileHandle_p, " %e", CLIP_VALUE(sampleAvg[m])); |
493 |
for (int m=0; m<nCompReqd-shape; m++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int m=0; m<nCompReqd-shape; m++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
494 |
} else if (nCompReqd == 9) { |
} else if (nCompReqd == 9) { |
495 |
/* tensor data, so have a 3x3 matrix to output as a row |
/* tensor data, so have a 3x3 matrix to output as a row |
496 |
* of 9 data points */ |
* of 9 data points */ |
497 |
int count = 0; |
int count = 0; |
498 |
for (int m=0; m<shape; m++) { |
for (int m=0; m<shape; m++) { |
499 |
for (int n=0; n<shape; n++) { |
for (int n=0; n<shape; n++) { |
500 |
fprintf(fileHandle_p, " %e", (float) sampleAvg[count]); |
fprintf(fileHandle_p, " %e", CLIP_VALUE(sampleAvg[count])); |
501 |
count++; |
count++; |
502 |
} |
} |
503 |
for (int n=0; n<3-shape; n++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int n=0; n<3-shape; n++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
504 |
} |
} |
505 |
for (int m=0; m<3-shape; m++) |
for (int m=0; m<3-shape; m++) |
506 |
for (int n=0; n<3; n++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int n=0; n<3; n++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
507 |
} |
} |
508 |
fprintf(fileHandle_p, "\n"); |
fprintf(fileHandle_p, "\n"); |
509 |
} |
} |
616 |
/* write the data different ways for scalar, vector and tensor */ |
/* write the data different ways for scalar, vector and tensor */ |
617 |
if (do_write) { |
if (do_write) { |
618 |
if (nCompReqd == 1) { |
if (nCompReqd == 1) { |
619 |
fprintf(fileHandle_p, " %e", (float) values[0]); |
fprintf(fileHandle_p, " %e", CLIP_VALUE(values[0])); |
620 |
} else if (nCompReqd == 3) { |
} else if (nCompReqd == 3) { |
621 |
for (int m=0; m<shape; m++) fprintf(fileHandle_p, " %e", (float) values[m]); |
for (int m=0; m<shape; m++) fprintf(fileHandle_p, " %e", CLIP_VALUE(values[m])); |
622 |
for (int m=0; m<nCompReqd-shape; m++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int m=0; m<nCompReqd-shape; m++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
623 |
} else if (nCompReqd == 9) { |
} else if (nCompReqd == 9) { |
624 |
/* tensor data, so have a 3x3 matrix to output as a row |
/* tensor data, so have a 3x3 matrix to output as a row |
625 |
* of 9 data points */ |
* of 9 data points */ |
626 |
int count = 0; |
int count = 0; |
627 |
for (int m=0; m<shape; m++) { |
for (int m=0; m<shape; m++) { |
628 |
for (int n=0; n<shape; n++) { |
for (int n=0; n<shape; n++) { |
629 |
fprintf(fileHandle_p, " %e", (float) values[count]); |
fprintf(fileHandle_p, " %e", CLIP_VALUE(values[count])); |
630 |
count++; |
count++; |
631 |
} |
} |
632 |
for (int n=0; n<3-shape; n++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int n=0; n<3-shape; n++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
633 |
} |
} |
634 |
for (int m=0; m<3-shape; m++) |
for (int m=0; m<3-shape; m++) |
635 |
for (int n=0; n<3; n++) fprintf(fileHandle_p, " %e", (float) 0.); |
for (int n=0; n<3; n++) fprintf(fileHandle_p, " %e", CLIP_VALUE(0.)); |
636 |
} |
} |
637 |
fprintf(fileHandle_p, "\n"); |
fprintf(fileHandle_p, "\n"); |
638 |
} |
} |