53 #include "fv_reader_tags.h"
55 static const int FVHEX = 2;
56 static const int FVPRISM = 3;
57 static const int FVPYRAMID = 4;
58 static const int FVTET = 1;
59 static const int ITYPE = 1;
61 unsigned int fv_encode_elem_header(
int elem_type,
int wall_info[]);
62 void time_step_get_value(
float*,
int,
int*,
float*,
int*);
63 void fv_error_msg(
const char*,
const char*);
65 void reg_single_unstruct_reader
70 char*,
int*,
int*,
int*,
int*,
int*,
int*,
71 int[],
int*,
char[][80],
int[],
int*,
char[][80],
int*
75 int*,
int*,
int*,
float[],
int*,
float[],
int*
79 int create_tet(
const int,
const int[8],
const int[]);
80 int create_pyramid(
const int,
const int[8],
const int[]);
81 int create_prism(
const int,
const int[8],
const int[]);
82 int create_hex(
const int,
const int[8],
const int[]);
84 typedef unsigned char uChar;
85 extern uChar create_bndry_face_buffered
98 void ftn_register_data_readers()
105 void ftn_register_functions()
112 void register_functions()
126 static void errorMsg(
const string& msg)
128 fv_error_msg(
"Foam Reader", msg.c_str());
133 static bool validCase(
const fileName& rootAndCase)
136 if (
isDir(rootAndCase/
"constant"))
149 static bool hasTopoChange(
const instantList& times)
151 label lastIndex = times.
size()-1;
156 runTime.
setTime(times[lastIndex], lastIndex);
162 if (facesInst != runTime.
constant().name())
164 Info<<
"Found cells file in " << facesInst <<
" so case has "
165 <<
"topological changes" <<
endl;
171 Info<<
"Found cells file in " << facesInst <<
" so case has "
172 <<
"no topological changes" <<
endl;
179 static bool selectTime(
const instantList& times,
int* iret)
185 fvTimes[2*timeI] = float(timeI);
186 fvTimes[2*timeI+1] = float(times[timeI].value());
195 time_step_get_value(fvTimes.begin(), times.
size(), &istep, &time, iret);
199 errorMsg(
"Out of memory.");
210 errorMsg(
"Unspecified error.");
214 Info<<
"Selected timeStep:" << istep <<
" time:" << scalar(time) <<
endl;
217 db_.
setTime(times[istep], istep);
224 static void createFieldNames
247 wordList vsNames(objects.names(volScalarField::typeName));
251 volScalarHash.
insert(vsNames[fieldI]);
254 wordList vvNames(objects.names(volVectorField::typeName));
258 volVectorHash.
insert(vvNames[fieldI]);
267 static void storeScalarField
270 const word& fieldName,
276 label nTotPoints = nPoints + db_.
polys().
size();
288 if (ioHeader.headerOk())
290 Info<<
"Storing " << nTotPoints <<
" of interpolated " << fieldName
299 vars[pointI++] = float(psf[i]);
306 label cellI = polys[i];
308 vars[pointI++] = float(field[cellI]);
313 Info<<
"Storing " << nTotPoints <<
" of dummy values of " << fieldName
316 for(label i = 0; i <
nPoints; i++)
318 vars[pointI++] = 0.0;
325 vars[pointI++] = 0.0;
332 static void storeVectorField
335 const word& fieldName,
342 label nTotPoints = nPoints + db_.
polys().
size();
354 if (ioHeader.headerOk())
356 Info<<
"Storing " << nTotPoints <<
" of interpolated " << fieldName
370 vars[pointI++] = float(psf[i]);
377 label cellI = polys[i];
379 vars[pointI++] = float(comp[cellI]);
385 Info<<
"Storing " << nTotPoints <<
" of dummy values of " << fieldName
390 for(label i = 0; i <
nPoints; i++)
392 vars[pointI++] = 0.0;
399 vars[pointI++] = 0.0;
407 static label getFvType(
const polyMesh&
mesh,
const label faceI)
414 static label getFaceType
426 label faceI = faceLabels[i];
428 if (f == faces[faceI])
431 return getFvType(mesh, faceI);
436 <<
"Cannot find face " << f <<
" in mesh face subset " << faceLabels
455 faceLabels[i] = getFaceType(mesh, cellFaces, cellShapeFaces[i]);
464 void user_query_file_function
479 char face_type_names[][80],
482 char var_names[][80],
486 fprintf(stderr,
"\n** user_query_file_function\n");
488 string rootAndCaseString(fname, *lenf);
490 fileName rootAndCase(rootAndCaseString);
494 if (!validCase(rootAndCase))
496 setName = rootAndCase.
name();
498 rootAndCase = rootAndCase.
path();
502 rootAndCase = rootAndCase.
path();
506 rootAndCase = rootAndCase.
path();
507 rootAndCase = rootAndCase.
path();
512 && meshDir == polyMesh::typeName
513 && validCase(rootAndCase)
522 "Could not find system/ and constant/ directory in\n"
524 +
"\nPlease select a Foam case directory."
539 if (caseName.empty())
546 <<
"caseName : " << caseName << endl
547 <<
"setName : " << setName <<
endl;
563 if (hasTopoChange(Times))
565 if (!selectTime(Times, iret))
570 else if (caseChanged)
587 num_nodes[0] = nTotPoints;
589 Info<<
"setting num_nodes:" << num_nodes[0] <<
endl;
595 if (*num_face_types > *max_face_types)
597 errorMsg(
"Too many patches. FieldView limit:" +
name(*max_face_types));
609 strcpy(face_type_names[patchI], patch.
name().c_str());
611 if (isA<wallPolyPatch>(patch))
613 wall_flags[patchI] = 1;
617 wall_flags[patchI] = 0;
619 Info<<
"Patch " << patch.
name() <<
" is wall:"
620 << wall_flags[patchI] <<
endl;
624 createFieldNames(db_.
runTime(), Times, setName);
628 if (*num_vars > *max_vars)
630 errorMsg(
"Too many variables. FieldView limit:" +
name(*max_vars));
646 strcpy(var_names[nameI++], fvName.c_str());
655 strcpy(var_names[nameI++], (fvName +
"x;" + fvName).c_str());
656 strcpy(var_names[nameI++], (fvName +
"y").c_str());
657 strcpy(var_names[nameI++], (fvName +
"z").c_str());
667 void user_read_one_grid_function
678 fprintf(stderr,
"\n** user_read_one_grid_function\n");
682 errorMsg(
"Illegal grid number " +
Foam::name(*igrid));
696 if (!selectTime(Times, iret))
707 if (*nodecnt != nTotPoints)
711 "nodecnt differs from number of points in mesh.\nnodecnt:"
729 errorMsg(
"Illegal number of variables " +
name(*num_vars));
743 int yIndex = xIndex + nTotPoints;
744 int zIndex = yIndex + nTotPoints;
749 xyz[xIndex++] = points[pointI].x();
750 xyz[yIndex++] = points[pointI].y();
751 xyz[zIndex++] = points[pointI].z();
761 label cellI = polys[i];
763 xyz[xIndex++] = ctrs[cellI].x();
764 xyz[yIndex++] = ctrs[cellI].y();
765 xyz[zIndex++] = ctrs[cellI].z();
773 static const cellModel& tet = *(cellModeller::lookup(
"tet"));
774 static const cellModel& tetWedge = *(cellModeller::lookup(
"tetWedge"));
775 static const cellModel& pyr = *(cellModeller::lookup(
"pyr"));
776 static const cellModel& prism = *(cellModeller::lookup(
"prism"));
777 static const cellModel& wedge = *(cellModeller::lookup(
"wedge"));
778 static const cellModel&
hex = *(cellModeller::lookup(
"hex"));
795 label nPoints = mesh.
nPoints();
804 label nWallCells = 0;
808 label cellI = owner[faceI];
810 if (!wallCell[cellI])
812 wallCell[cellI] =
true;
824 const cell& cellFaces = cells[cellI];
828 if (cellModel == tet)
830 tetVerts[0] = cellShape[3] + 1;
831 tetVerts[1] = cellShape[0] + 1;
832 tetVerts[2] = cellShape[1] + 1;
833 tetVerts[3] = cellShape[2] + 1;
838 getFaceTypes(mesh, cellFaces, cellShape.
faces());
840 tetFaces[0] = faceTypes[2];
841 tetFaces[1] = faceTypes[3];
842 tetFaces[2] = faceTypes[0];
843 tetFaces[3] = faceTypes[1];
845 istat = create_tet(ITYPE, tetVerts, tetFaces);
850 istat = create_tet(ITYPE, tetVerts, internalFaces.begin());
853 else if (cellModel == tetWedge)
855 prismVerts[0] = cellShape[0] + 1;
856 prismVerts[1] = cellShape[3] + 1;
857 prismVerts[2] = cellShape[4] + 1;
858 prismVerts[3] = cellShape[1] + 1;
859 prismVerts[4] = cellShape[4] + 1;
860 prismVerts[5] = cellShape[2] + 1;
865 getFaceTypes(mesh, cellFaces, cellShape.
faces());
867 prismFaces[0] = faceTypes[1];
868 prismFaces[1] = faceTypes[2];
869 prismFaces[2] = faceTypes[3];
870 prismFaces[3] = faceTypes[0];
871 prismFaces[4] = faceTypes[3];
873 istat = create_prism(ITYPE, prismVerts, prismFaces);
877 istat = create_prism(ITYPE, prismVerts, internalFaces.begin());
880 else if (cellModel == pyr)
882 pyrVerts[0] = cellShape[0] + 1;
883 pyrVerts[1] = cellShape[1] + 1;
884 pyrVerts[2] = cellShape[2] + 1;
885 pyrVerts[3] = cellShape[3] + 1;
886 pyrVerts[4] = cellShape[4] + 1;
891 getFaceTypes(mesh, cellFaces, cellShape.
faces());
893 pyrFaces[0] = faceTypes[0];
894 pyrFaces[1] = faceTypes[3];
895 pyrFaces[2] = faceTypes[2];
896 pyrFaces[3] = faceTypes[1];
897 pyrFaces[4] = faceTypes[4];
899 istat = create_pyramid(ITYPE, pyrVerts, pyrFaces);
903 istat = create_pyramid(ITYPE, pyrVerts, internalFaces.begin());
906 else if (cellModel == prism)
908 prismVerts[0] = cellShape[0] + 1;
909 prismVerts[1] = cellShape[3] + 1;
910 prismVerts[2] = cellShape[4] + 1;
911 prismVerts[3] = cellShape[1] + 1;
912 prismVerts[4] = cellShape[5] + 1;
913 prismVerts[5] = cellShape[2] + 1;
918 getFaceTypes(mesh, cellFaces, cellShape.
faces());
920 prismFaces[0] = faceTypes[4];
921 prismFaces[1] = faceTypes[2];
922 prismFaces[2] = faceTypes[3];
923 prismFaces[3] = faceTypes[0];
924 prismFaces[4] = faceTypes[1];
926 istat = create_prism(ITYPE, prismVerts, prismFaces);
930 istat = create_prism(ITYPE, prismVerts, internalFaces.begin());
933 else if (cellModel == wedge)
935 hexVerts[0] = cellShape[0] + 1;
936 hexVerts[1] = cellShape[1] + 1;
937 hexVerts[2] = cellShape[0] + 1;
938 hexVerts[3] = cellShape[2] + 1;
939 hexVerts[4] = cellShape[3] + 1;
940 hexVerts[5] = cellShape[4] + 1;
941 hexVerts[6] = cellShape[6] + 1;
942 hexVerts[7] = cellShape[5] + 1;
947 getFaceTypes(mesh, cellFaces, cellShape.
faces());
949 hexFaces[0] = faceTypes[2];
950 hexFaces[1] = faceTypes[3];
951 hexFaces[2] = faceTypes[0];
952 hexFaces[3] = faceTypes[1];
953 hexFaces[4] = faceTypes[4];
954 hexFaces[5] = faceTypes[5];
956 istat = create_hex(ITYPE, hexVerts, hexFaces);
960 istat = create_hex(ITYPE, hexVerts, internalFaces.begin());
963 else if (cellModel == hex)
965 hexVerts[0] = cellShape[0] + 1;
966 hexVerts[1] = cellShape[1] + 1;
967 hexVerts[2] = cellShape[3] + 1;
968 hexVerts[3] = cellShape[2] + 1;
969 hexVerts[4] = cellShape[4] + 1;
970 hexVerts[5] = cellShape[5] + 1;
971 hexVerts[6] = cellShape[7] + 1;
972 hexVerts[7] = cellShape[6] + 1;
977 getFaceTypes(mesh, cellFaces, cellShape.
faces());
979 hexFaces[0] = faceTypes[0];
980 hexFaces[1] = faceTypes[1];
981 hexFaces[2] = faceTypes[4];
982 hexFaces[3] = faceTypes[5];
983 hexFaces[4] = faceTypes[2];
984 hexFaces[5] = faceTypes[3];
986 istat = create_hex(ITYPE, hexVerts, hexFaces);
990 istat = create_hex(ITYPE, hexVerts, internalFaces.begin());
997 label faceI = cellFaces[cFaceI];
1000 label fvFaceType = getFvType(mesh, faceI);
1002 const face& f = faces[faceI];
1023 label polyCentrePoint = nPoints + nPolys;
1025 for (label i=0; i<nTris; i++)
1027 if (cellI == owner[faceI])
1029 tetVerts[0] = triFaces[i][0] + 1;
1030 tetVerts[1] = triFaces[i][1] + 1;
1031 tetVerts[2] = triFaces[i][2] + 1;
1032 tetVerts[3] = polyCentrePoint + 1;
1036 tetVerts[0] = triFaces[i][2] + 1;
1037 tetVerts[1] = triFaces[i][1] + 1;
1038 tetVerts[2] = triFaces[i][0] + 1;
1039 tetVerts[3] = polyCentrePoint + 1;
1042 if (wallCell[cellI])
1045 tetFaces[0] = fvFaceType;
1050 istat = create_tet(ITYPE, tetVerts, tetFaces);
1059 internalFaces.begin()
1064 for (label i=0; i<nQuads; i++)
1066 if (cellI == owner[faceI])
1068 pyrVerts[0] = quadFaces[i][3] + 1;
1069 pyrVerts[1] = quadFaces[i][2] + 1;
1070 pyrVerts[2] = quadFaces[i][1] + 1;
1071 pyrVerts[3] = quadFaces[i][0] + 1;
1072 pyrVerts[4] = polyCentrePoint + 1;
1077 pyrVerts[0] = quadFaces[i][0] + 1;
1078 pyrVerts[1] = quadFaces[i][1] + 1;
1079 pyrVerts[2] = quadFaces[i][2] + 1;
1080 pyrVerts[3] = quadFaces[i][3] + 1;
1081 pyrVerts[4] = polyCentrePoint + 1;
1084 if (wallCell[cellI])
1087 pyrFaces[0] = fvFaceType;
1093 istat = create_pyramid(ITYPE, pyrVerts, pyrFaces);
1102 internalFaces.begin()
1109 errorMsg(
"Error during adding cell " +
name(cellI));
1122 errorMsg(
"Error during adding cell " +
name(cellI));
1146 storeScalarField(pInterp, fieldName, vars, pointI);
1154 storeVectorField(pInterp, fieldName, vars, pointI);
1162 void register_data_readers()
1197 reg_single_unstruct_reader (
1199 user_query_file_function,
1200 user_read_one_grid_function