OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fieldview9Reader.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Reader module for Fieldview9 to read OpenFOAM mesh and data.
00027 
00028     Creates new 'fvbin' type executable which needs to be installed in place
00029     of bin/fvbin.
00030 
00031     Implements a reader for combined mesh&results on an unstructured mesh.
00032 
00033     See Fieldview Release 9 Reference Manual and coding in user/ directory
00034     of the Fieldview release.
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #include "fvCFD.H"
00039 #include "IOobjectList.H"
00040 #include "GeometricField.H"
00041 #include "pointFields.H"
00042 #include "volPointInterpolation.H"
00043 #include "readerDatabase.H"
00044 #include "wallPolyPatch.H"
00045 #include "ListOps.H"
00046 #include "cellModeller.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 extern "C"
00051 {
00052 // Define various Fieldview constants and prototypes
00053 
00054 #include "fv_reader_tags.h"
00055 
00056 static const int FVHEX     = 2;
00057 static const int FVPRISM   = 3;
00058 static const int FVPYRAMID = 4;
00059 static const int FVTET     = 1;
00060 static const int ITYPE     = 1;
00061 
00062 unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
00063 void time_step_get_value(float*, int, int*, float*, int*);
00064 void fv_error_msg(const char*, const char*);
00065 
00066 void reg_single_unstruct_reader
00067 (
00068     char *,
00069     void
00070     (
00071         char*, int*, int*, int*, int*, int*, int*,
00072         int[], int*, char[][80], int[], int*, char[][80], int*
00073     ),
00074     void
00075     (
00076         int*, int*, int*, float[], int*, float[], int*
00077     )
00078 );
00079 
00080 int create_tet(const int, const int[8], const int[]);
00081 int create_pyramid(const int, const int[8], const int[]);
00082 int create_prism(const int, const int[8], const int[]);
00083 int create_hex(const int, const int[8], const int[]);
00084 
00085 typedef unsigned char uChar;
00086 extern uChar create_bndry_face_buffered
00087 (
00088     int bndry_type,
00089     int num_verts,
00090     int verts[],
00091     int *normals_flags,
00092     int num_grid_nodes
00093 );
00094 
00095 /*
00096  * just define empty readers here for ease of linking.
00097  * Comment out if you have doubly defined linking error on this symbol
00098  */
00099 void ftn_register_data_readers()
00100 {}
00101 
00102 /*
00103  * just define empty readers here for ease of linking.
00104  * Comment out if you have doubly defined linking error on this symbol
00105  */
00106 void ftn_register_functions()
00107 {}
00108 
00109 /*
00110  * just define empty readers here for ease of linking.
00111  * Comment out if you have doubly defined linking error on this symbol
00112  */
00113 void register_functions()
00114 {}
00115 
00116 
00117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00118 
00119 
00120 //
00121 // Storage for all Foam state (mainly database & mesh)
00122 //
00123 static readerDatabase db_;
00124 
00125 
00126 // Write fv error message.
00127 static void errorMsg(const string& msg)
00128 {
00129     fv_error_msg("Foam Reader", msg.c_str());
00130 }
00131 
00132 
00133 // Simple check if directory is valid case directory.
00134 static bool validCase(const fileName& rootAndCase)
00135 {
00136     //if (isDir(rootAndCase/"system") && isDir(rootAndCase/"constant"))
00137     if (isDir(rootAndCase/"constant"))
00138     {
00139         return true;
00140     }
00141     else
00142     {
00143         return false;
00144     }
00145 }
00146 
00147 
00148 // Check whether case has topo changes by looking back from last time
00149 // to first directory with polyMesh/cells.
00150 static bool hasTopoChange(const instantList& times)
00151 {
00152     label lastIndex = times.size()-1;
00153 
00154     const Time& runTime = db_.runTime();
00155 
00156     // Only set time; do not update mesh.
00157     runTime.setTime(times[lastIndex], lastIndex);
00158 
00159     fileName facesInst(runTime.findInstance(polyMesh::meshSubDir, "faces"));
00160 
00161     // See if cellInst is constant directory. Note extra .name() is for
00162     // parallel cases when runTime.constant is '../constant'
00163     if (facesInst != runTime.constant().name())
00164     {
00165         Info<< "Found cells file in " << facesInst << " so case has "
00166             << "topological changes" << endl;
00167 
00168         return true;
00169     }
00170     else
00171     {
00172         Info<< "Found cells file in " << facesInst << " so case has "
00173             << "no topological changes" << endl;
00174 
00175         return false;
00176     }
00177 }
00178 
00179 
00180 static bool selectTime(const instantList& times, int* iret)
00181 {
00182     List<float> fvTimes(2*times.size());
00183 
00184     forAll(times, timeI)
00185     {
00186         fvTimes[2*timeI]   = float(timeI);
00187         fvTimes[2*timeI+1] = float(times[timeI].value());
00188     }
00189 
00190     int istep;
00191 
00192     float time;
00193 
00194     *iret=0;
00195 
00196     time_step_get_value(fvTimes.begin(), times.size(), &istep, &time, iret);
00197 
00198     if (*iret == -5)
00199     {
00200         errorMsg("Out of memory.");
00201 
00202         return false;
00203     }
00204     if (*iret == -15)
00205     {
00206         // Cancel action.
00207         return false;
00208     }
00209     if (*iret != 0)
00210     {
00211         errorMsg("Unspecified error.");
00212 
00213         return false;
00214     }
00215     Info<< "Selected timeStep:" << istep << "  time:" << scalar(time) << endl;
00216 
00217     // Set time and load mesh.
00218     db_.setTime(times[istep], istep);
00219 
00220     return true;
00221 }
00222 
00223 
00224 // Gets (names of) all fields in all timesteps.
00225 static void createFieldNames
00226 (
00227     const Time& runTime,
00228     const instantList& Times,
00229     const word& setName
00230 )
00231 {
00232     // From foamToFieldView9/getFieldNames.H:
00233 
00234     HashSet<word> volScalarHash;
00235     HashSet<word> volVectorHash;
00236     HashSet<word> surfScalarHash;
00237     HashSet<word> surfVectorHash;
00238 
00239     if (setName.empty())
00240     {
00241         forAll(Times, timeI)
00242         {
00243             const word& timeName = Times[timeI].name();
00244 
00245             // Add all fields to hashtable
00246             IOobjectList objects(runTime, timeName);
00247 
00248             wordList vsNames(objects.names(volScalarField::typeName));
00249 
00250             forAll(vsNames, fieldI)
00251             {
00252                 volScalarHash.insert(vsNames[fieldI]);
00253             }
00254 
00255             wordList vvNames(objects.names(volVectorField::typeName));
00256 
00257             forAll(vvNames, fieldI)
00258             {
00259                 volVectorHash.insert(vvNames[fieldI]);
00260             }
00261         }
00262     }
00263     db_.setFieldNames(volScalarHash.toc(), volVectorHash.toc());
00264 }
00265 
00266 
00267 // Appends interpolated values of fieldName to vars array.
00268 static void storeScalarField
00269 (
00270     const volPointInterpolation& pInterp,
00271     const word& fieldName,
00272     float vars[],
00273     label& pointI
00274 )
00275 {
00276     label nPoints = db_.mesh().nPoints();
00277     label nTotPoints = nPoints + db_.polys().size();
00278 
00279     // Check if present
00280     IOobject ioHeader
00281     (
00282         fieldName,
00283         db_.runTime().timeName(),
00284         db_.runTime(),
00285         IOobject::MUST_READ,
00286         IOobject::NO_WRITE
00287     );
00288 
00289     if (ioHeader.headerOk())
00290     {
00291         Info<< "Storing " << nTotPoints << " of interpolated " << fieldName
00292             << endl;
00293 
00294         volScalarField field(ioHeader, db_.mesh());
00295 
00296         pointScalarField psf(pInterp.interpolate(field));
00297 
00298         forAll(psf, i)
00299         {
00300             vars[pointI++] = float(psf[i]);
00301         }
00302 
00303         const labelList& polys = db_.polys();
00304 
00305         forAll(polys, i)
00306         {
00307             label cellI = polys[i];
00308 
00309             vars[pointI++] = float(field[cellI]);
00310         }
00311     }
00312     else
00313     {
00314         Info<< "Storing " << nTotPoints << " of dummy values of " << fieldName
00315             << endl;
00316 
00317         for(label i = 0; i < nPoints; i++)
00318         {
00319             vars[pointI++] = 0.0;
00320         }
00321 
00322         const labelList& polys = db_.polys();
00323 
00324         forAll(polys, i)
00325         {
00326             vars[pointI++] = 0.0;
00327         }
00328     }
00329 }
00330 
00331 
00332 // Appends interpolated values of fieldName to vars array.
00333 static void storeVectorField
00334 (
00335     const volPointInterpolation& pInterp,
00336     const word& fieldName,
00337     float vars[],
00338     label& pointI
00339 )
00340 {
00341     label nPoints = db_.mesh().nPoints();
00342 
00343     label nTotPoints = nPoints + db_.polys().size();
00344 
00345     // Check if present
00346     IOobject ioHeader
00347     (
00348         fieldName,
00349         db_.runTime().timeName(),
00350         db_.runTime(),
00351         IOobject::MUST_READ,
00352         IOobject::NO_WRITE
00353     );
00354 
00355     if (ioHeader.headerOk())
00356     {
00357         Info<< "Storing " << nTotPoints << " of interpolated " << fieldName
00358             << endl;
00359 
00360         volVectorField field(ioHeader, db_.mesh());
00361 
00362         for (direction d = 0; d < vector::nComponents; d++)
00363         {
00364             tmp<volScalarField> tcomp = field.component(d);
00365             const volScalarField& comp = tcomp();
00366 
00367             pointScalarField psf(pInterp.interpolate(comp));
00368 
00369             forAll(psf, i)
00370             {
00371                 vars[pointI++] = float(psf[i]);
00372             }
00373 
00374             const labelList& polys = db_.polys();
00375 
00376             forAll(polys, i)
00377             {
00378                 label cellI = polys[i];
00379 
00380                 vars[pointI++] = float(comp[cellI]);
00381             }
00382         }
00383     }
00384     else
00385     {
00386         Info<< "Storing " << nTotPoints << " of dummy values of " << fieldName
00387             << endl;
00388 
00389         for (direction d = 0; d < vector::nComponents; d++)
00390         {
00391             for(label i = 0; i < nPoints; i++)
00392             {
00393                 vars[pointI++] = 0.0;
00394             }
00395 
00396             const labelList& polys = db_.polys();
00397 
00398             forAll(polys, i)
00399             {
00400                 vars[pointI++] = 0.0;
00401             }
00402         }
00403     }
00404 }
00405 
00406 
00407 // Returns Fieldview face_type of mesh face faceI.
00408 static label getFvType(const polyMesh& mesh, const label faceI)
00409 {
00410     return mesh.boundaryMesh().whichPatch(faceI) + 1;
00411 }
00412 
00413 
00414 // Returns Fieldview face_type of face f.
00415 static label getFaceType
00416 (
00417     const polyMesh& mesh,
00418     const labelList& faceLabels,
00419     const face& f
00420 )
00421 {
00422     // Search in subset faceLabels of faces for index of face f.
00423     const faceList& faces = mesh.faces();
00424 
00425     forAll(faceLabels, i)
00426     {
00427         label faceI = faceLabels[i];
00428 
00429         if (f == faces[faceI])
00430         {
00431             // Convert patch to Fieldview face_type.
00432             return getFvType(mesh, faceI);
00433         }
00434     }
00435 
00436     FatalErrorIn("getFaceType")
00437         << "Cannot find face " << f << " in mesh face subset " << faceLabels
00438         << abort(FatalError);
00439 
00440     return -1;
00441 }
00442 
00443 
00444 // Returns Fieldview face_types for set of faces
00445 static labelList getFaceTypes
00446 (
00447     const polyMesh& mesh,
00448     const labelList& cellFaces,
00449     const faceList& cellShapeFaces
00450 )
00451 {
00452     labelList faceLabels(cellShapeFaces.size());
00453 
00454     forAll(cellShapeFaces, i)
00455     {
00456         faceLabels[i] = getFaceType(mesh, cellFaces, cellShapeFaces[i]);
00457     }
00458     return faceLabels;
00459 }
00460 
00461 
00462 /*
00463  * Callback for querying file contents. Taken from user/user_unstruct_combined.f
00464  */
00465 void user_query_file_function
00466 (
00467     /* input */
00468     char* fname,        /* filename */
00469     int* lenf,          /* length of fName */
00470     int* iunit,         /* fortran unit to use */
00471     int* max_grids,     /* maximum number of grids allowed */
00472     int* max_face_types,/* maximum number of face types allowed */
00473     int* max_vars,      /* maximum number of result variables allowed per */
00474                         /* grid point*/
00475 
00476     /* output */
00477     int* num_grids,     /* number of grids that will be read from data file */
00478     int  num_nodes[],   /* (array of node counts for all grids) */
00479     int* num_face_types,        /* number of special face types */
00480     char face_type_names[][80], /* array of face-type names */
00481     int  wall_flags[],          /* array of flags for the "wall" behavior */
00482     int* num_vars,              /* number of result variables per grid point */
00483     char var_names[][80],       /* array of variable names */
00484     int* iret                   /* return value */
00485 )
00486 {
00487     fprintf(stderr, "\n** user_query_file_function\n");
00488 
00489     string rootAndCaseString(fname, *lenf);
00490 
00491     fileName rootAndCase(rootAndCaseString);
00492 
00493     word setName("");
00494 
00495     if (!validCase(rootAndCase))
00496     {
00497         setName = rootAndCase.name();
00498 
00499         rootAndCase = rootAndCase.path();
00500 
00501         word setDir = rootAndCase.name();
00502 
00503         rootAndCase = rootAndCase.path();
00504 
00505         word meshDir = rootAndCase.name();
00506 
00507         rootAndCase = rootAndCase.path();
00508         rootAndCase = rootAndCase.path();
00509 
00510         if
00511         (
00512             setDir == "sets"
00513          && meshDir == polyMesh::typeName
00514          && validCase(rootAndCase)
00515         )
00516         {
00517             // Valid set (hopefully - cannot check contents of setName yet).
00518         }
00519         else
00520         {
00521             errorMsg
00522             (
00523                 "Could not find system/ and constant/ directory in\n"
00524               + rootAndCase
00525               + "\nPlease select a Foam case directory."
00526             );
00527 
00528             *iret = 1;
00529 
00530             return;
00531         }
00532 
00533     }
00534 
00535     fileName rootDir(rootAndCase.path());
00536 
00537     fileName caseName(rootAndCase.name());
00538 
00539     // handle trailing '/'
00540     if (caseName.empty())
00541     {
00542         caseName = rootDir.name();
00543         rootDir  = rootDir.path();
00544     }
00545 
00546     Info<< "rootDir  : " << rootDir << endl
00547         << "caseName : " << caseName << endl
00548         << "setName  : " << setName << endl;
00549 
00550     //
00551     // Get/reuse database and mesh
00552     //
00553 
00554     bool caseChanged = db_.setRunTime(rootDir, caseName, setName);
00555 
00556 
00557     //
00558     // Select time
00559     //
00560 
00561     instantList Times = db_.runTime().times();
00562 
00563     // If topo case set database time and update mesh.
00564     if (hasTopoChange(Times))
00565     {
00566         if (!selectTime(Times, iret))
00567         {
00568             return;
00569         }
00570     }
00571     else if (caseChanged)
00572     {
00573         // Load mesh (if case changed) to make sure we have nPoints etc.
00574         db_.loadMesh();
00575     }
00576 
00577 
00578     //
00579     // Set output variables
00580     //
00581 
00582     *num_grids = 1;
00583 
00584     const fvMesh& mesh = db_.mesh();
00585 
00586     label nTotPoints = mesh.nPoints() + db_.polys().size();
00587 
00588     num_nodes[0] = nTotPoints;
00589 
00590     Info<< "setting num_nodes:" << num_nodes[0] << endl;
00591 
00592     Info<< "setting num_face_types:" << mesh.boundary().size() << endl;
00593 
00594     *num_face_types = mesh.boundary().size();
00595 
00596     if (*num_face_types > *max_face_types)
00597     {
00598         errorMsg("Too many patches. FieldView limit:" + name(*max_face_types));
00599 
00600         *iret = 1;
00601 
00602         return;
00603     }
00604 
00605 
00606     forAll(mesh.boundaryMesh(), patchI)
00607     {
00608         const polyPatch& patch = mesh.boundaryMesh()[patchI];
00609 
00610         strcpy(face_type_names[patchI], patch.name().c_str());
00611 
00612         if (isType<wallPolyPatch>(patch))
00613         {
00614             wall_flags[patchI] = 1;
00615         }
00616         else
00617         {
00618             wall_flags[patchI] = 0;
00619         }
00620         Info<< "Patch " << patch.name() << " is wall:"
00621             <<  wall_flags[patchI] << endl;
00622     }
00623 
00624     //- Find all volFields and add them to database
00625     createFieldNames(db_.runTime(), Times, setName);
00626 
00627     *num_vars = db_.volScalarNames().size() + 3*db_.volVectorNames().size();
00628 
00629     if (*num_vars > *max_vars)
00630     {
00631         errorMsg("Too many variables. FieldView limit:" + name(*max_vars));
00632 
00633         *iret = 1;
00634 
00635         return;
00636     }
00637 
00638 
00639     int nameI = 0;
00640 
00641     forAll(db_.volScalarNames(), i)
00642     {
00643         const word& fieldName = db_.volScalarNames()[i];
00644 
00645         const word& fvName = db_.getFvName(fieldName);
00646 
00647         strcpy(var_names[nameI++], fvName.c_str());
00648     }
00649 
00650     forAll(db_.volVectorNames(), i)
00651     {
00652         const word& fieldName = db_.volVectorNames()[i];
00653 
00654         const word& fvName = db_.getFvName(fieldName);
00655 
00656         strcpy(var_names[nameI++], (fvName + "x;" + fvName).c_str());
00657         strcpy(var_names[nameI++], (fvName + "y").c_str());
00658         strcpy(var_names[nameI++], (fvName + "z").c_str());
00659     }
00660 
00661     *iret = 0;
00662 }
00663 
00664 
00665 /*
00666  * Callback for reading timestep. Taken from user/user_unstruct_combined.f
00667  */
00668 void user_read_one_grid_function
00669 (
00670     int* iunit,     /* in: fortran unit number */
00671     int* igrid,     /* in: grid number to read */
00672     int* nodecnt,   /* in: number of nodes to read */
00673     float xyz[],    /* out: coordinates of nodes: x1..xN y1..yN z1..zN */
00674     int* num_vars,  /* in: number of results per node */
00675     float vars[],   /* out: values per node */
00676     int* iret       /* out: return value */
00677 )
00678 {
00679     fprintf(stderr, "\n** user_read_one_grid_function\n");
00680 
00681     if (*igrid != 1)
00682     {
00683         errorMsg("Illegal grid number " + Foam::name(*igrid));
00684 
00685         *iret = 1;
00686 
00687         return;
00688     }
00689 
00690     // Get current time
00691     instantList Times = db_.runTime().times();
00692 
00693     // Set database time and update mesh.
00694     // Note: this should not be nessecary here. We already have the correct
00695     // time set and mesh loaded. This is only nessecary because Fieldview
00696     // otherwise thinks the case is non-transient.
00697     if (!selectTime(Times, iret))
00698     {
00699         return;
00700     }
00701 
00702 
00703     const fvMesh& mesh = db_.mesh();
00704 
00705     // With mesh now loaded check for change in number of points.
00706     label nTotPoints = mesh.nPoints() + db_.polys().size();
00707 
00708     if (*nodecnt != nTotPoints)
00709     {
00710         errorMsg
00711         (
00712             "nodecnt differs from number of points in mesh.\nnodecnt:"
00713           + Foam::name(*nodecnt)
00714           + "  mesh:"
00715           + Foam::name(nTotPoints)
00716         );
00717 
00718         *iret = 1;
00719 
00720         return;
00721     }
00722 
00723 
00724     if
00725     (
00726         *num_vars
00727      != (db_.volScalarNames().size() + 3*db_.volVectorNames().size())
00728     )
00729     {
00730         errorMsg("Illegal number of variables " + name(*num_vars));
00731 
00732         *iret = 1;
00733 
00734         return;
00735     }
00736 
00737     //
00738     // Set coordinates
00739     //
00740 
00741     const pointField& points = mesh.points();
00742 
00743     int xIndex = 0;
00744     int yIndex = xIndex + nTotPoints;
00745     int zIndex = yIndex + nTotPoints;
00746 
00747     // Add mesh points first.
00748     forAll(points, pointI)
00749     {
00750         xyz[xIndex++] = points[pointI].x();
00751         xyz[yIndex++] = points[pointI].y();
00752         xyz[zIndex++] = points[pointI].z();
00753     }
00754 
00755     // Add cell centres of polys
00756     const pointField& ctrs = mesh.cellCentres();
00757 
00758     const labelList& polys = db_.polys();
00759 
00760     forAll(polys, i)
00761     {
00762         label cellI = polys[i];
00763 
00764         xyz[xIndex++] = ctrs[cellI].x();
00765         xyz[yIndex++] = ctrs[cellI].y();
00766         xyz[zIndex++] = ctrs[cellI].z();
00767     }
00768 
00769 
00770     //
00771     // Define elements by calling fv routines
00772     //
00773 
00774     static const cellModel& tet = *(cellModeller::lookup("tet"));
00775     static const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
00776     static const cellModel& pyr = *(cellModeller::lookup("pyr"));
00777     static const cellModel& prism = *(cellModeller::lookup("prism"));
00778     static const cellModel& wedge = *(cellModeller::lookup("wedge"));
00779     static const cellModel& hex = *(cellModeller::lookup("hex"));
00780     //static const cellModel& splitHex = *(cellModeller::lookup("splitHex"));
00781 
00782     int tetVerts[4];
00783     int pyrVerts[5];
00784     int prismVerts[6];
00785     int hexVerts[8];
00786 
00787     int tetFaces[4];
00788     int pyrFaces[5];
00789     int prismFaces[5];
00790     int hexFaces[6];
00791 
00792     const cellShapeList& cellShapes = mesh.cellShapes();
00793     const faceList& faces = mesh.faces();
00794     const cellList& cells = mesh.cells();
00795     const labelList& owner = mesh.faceOwner();
00796     label nPoints = mesh.nPoints();
00797 
00798     // Fieldview face_types array with all faces marked as internal.
00799     labelList internalFaces(6, 0);
00800 
00801     // Mark all cells next to boundary so we don't have to calculate
00802     // wall_types for internal cells and can just pass internalFaces.
00803     boolList wallCell(mesh.nCells(), false);
00804 
00805     label nWallCells = 0;
00806 
00807     for (label faceI = mesh.nInternalFaces(); faceI < mesh.nFaces(); faceI++)
00808     {
00809         label cellI = owner[faceI];
00810 
00811         if (!wallCell[cellI])
00812         {
00813             wallCell[cellI] = true;
00814 
00815             nWallCells++;
00816         }
00817     }
00818 
00819     label nPolys = 0;
00820 
00821     forAll(cellShapes, cellI)
00822     {
00823         const cellShape& cellShape = cellShapes[cellI];
00824         const cellModel& cellModel = cellShape.model();
00825         const cell& cellFaces = cells[cellI];
00826 
00827         int istat = 0;
00828 
00829         if (cellModel == tet)
00830         {
00831             tetVerts[0] = cellShape[3] + 1;
00832             tetVerts[1] = cellShape[0] + 1;
00833             tetVerts[2] = cellShape[1] + 1;
00834             tetVerts[3] = cellShape[2] + 1;
00835 
00836             if (wallCell[cellI])
00837             {
00838                 labelList faceTypes =
00839                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00840 
00841                 tetFaces[0] = faceTypes[2];
00842                 tetFaces[1] = faceTypes[3];
00843                 tetFaces[2] = faceTypes[0];
00844                 tetFaces[3] = faceTypes[1];
00845 
00846                 istat = create_tet(ITYPE, tetVerts, tetFaces);
00847             }
00848             else
00849             {
00850                 // All faces internal so use precalculated zero.
00851                 istat = create_tet(ITYPE, tetVerts, internalFaces.begin());
00852             }
00853         }
00854         else if (cellModel == tetWedge)
00855         {
00856             prismVerts[0] = cellShape[0] + 1;
00857             prismVerts[1] = cellShape[3] + 1;
00858             prismVerts[2] = cellShape[4] + 1;
00859             prismVerts[3] = cellShape[1] + 1;
00860             prismVerts[4] = cellShape[4] + 1;
00861             prismVerts[5] = cellShape[2] + 1;
00862 
00863             if (wallCell[cellI])
00864             {
00865                 labelList faceTypes =
00866                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00867 
00868                 prismFaces[0] = faceTypes[1];
00869                 prismFaces[1] = faceTypes[2];
00870                 prismFaces[2] = faceTypes[3];
00871                 prismFaces[3] = faceTypes[0];
00872                 prismFaces[4] = faceTypes[3];
00873 
00874                 istat = create_prism(ITYPE, prismVerts, prismFaces);
00875             }
00876             else
00877             {
00878                 istat = create_prism(ITYPE, prismVerts, internalFaces.begin());
00879             }
00880         }
00881         else if (cellModel == pyr)
00882         {
00883             pyrVerts[0] = cellShape[0] + 1;
00884             pyrVerts[1] = cellShape[1] + 1;
00885             pyrVerts[2] = cellShape[2] + 1;
00886             pyrVerts[3] = cellShape[3] + 1;
00887             pyrVerts[4] = cellShape[4] + 1;
00888 
00889             if (wallCell[cellI])
00890             {
00891                 labelList faceTypes =
00892                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00893 
00894                 pyrFaces[0] = faceTypes[0];
00895                 pyrFaces[1] = faceTypes[3];
00896                 pyrFaces[2] = faceTypes[2];
00897                 pyrFaces[3] = faceTypes[1];
00898                 pyrFaces[4] = faceTypes[4];
00899 
00900                 istat = create_pyramid(ITYPE, pyrVerts, pyrFaces);
00901             }
00902             else
00903             {
00904                 istat = create_pyramid(ITYPE, pyrVerts, internalFaces.begin());
00905             }
00906         }
00907         else if (cellModel == prism)
00908         {
00909             prismVerts[0] = cellShape[0] + 1;
00910             prismVerts[1] = cellShape[3] + 1;
00911             prismVerts[2] = cellShape[4] + 1;
00912             prismVerts[3] = cellShape[1] + 1;
00913             prismVerts[4] = cellShape[5] + 1;
00914             prismVerts[5] = cellShape[2] + 1;
00915 
00916             if (wallCell[cellI])
00917             {
00918                 labelList faceTypes =
00919                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00920 
00921                 prismFaces[0] = faceTypes[4];
00922                 prismFaces[1] = faceTypes[2];
00923                 prismFaces[2] = faceTypes[3];
00924                 prismFaces[3] = faceTypes[0];
00925                 prismFaces[4] = faceTypes[1];
00926 
00927                 istat = create_prism(ITYPE, prismVerts, prismFaces);
00928             }
00929             else
00930             {
00931                 istat = create_prism(ITYPE, prismVerts, internalFaces.begin());
00932             }
00933         }
00934         else if (cellModel == wedge)
00935         {
00936             hexVerts[0] = cellShape[0] + 1;
00937             hexVerts[1] = cellShape[1] + 1;
00938             hexVerts[2] = cellShape[0] + 1;
00939             hexVerts[3] = cellShape[2] + 1;
00940             hexVerts[4] = cellShape[3] + 1;
00941             hexVerts[5] = cellShape[4] + 1;
00942             hexVerts[6] = cellShape[6] + 1;
00943             hexVerts[7] = cellShape[5] + 1;
00944 
00945             if (wallCell[cellI])
00946             {
00947                 labelList faceTypes =
00948                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00949 
00950                 hexFaces[0] = faceTypes[2];
00951                 hexFaces[1] = faceTypes[3];
00952                 hexFaces[2] = faceTypes[0];
00953                 hexFaces[3] = faceTypes[1];
00954                 hexFaces[4] = faceTypes[4];
00955                 hexFaces[5] = faceTypes[5];
00956 
00957                 istat = create_hex(ITYPE, hexVerts, hexFaces);
00958             }
00959             else
00960             {
00961                 istat = create_hex(ITYPE, hexVerts, internalFaces.begin());
00962             }
00963         }
00964         else if (cellModel == hex)
00965         {
00966             hexVerts[0] = cellShape[0] + 1;
00967             hexVerts[1] = cellShape[1] + 1;
00968             hexVerts[2] = cellShape[3] + 1;
00969             hexVerts[3] = cellShape[2] + 1;
00970             hexVerts[4] = cellShape[4] + 1;
00971             hexVerts[5] = cellShape[5] + 1;
00972             hexVerts[6] = cellShape[7] + 1;
00973             hexVerts[7] = cellShape[6] + 1;
00974 
00975             if (wallCell[cellI])
00976             {
00977                 labelList faceTypes =
00978                     getFaceTypes(mesh, cellFaces, cellShape.faces());
00979 
00980                 hexFaces[0] = faceTypes[0];
00981                 hexFaces[1] = faceTypes[1];
00982                 hexFaces[2] = faceTypes[4];
00983                 hexFaces[3] = faceTypes[5];
00984                 hexFaces[4] = faceTypes[2];
00985                 hexFaces[5] = faceTypes[3];
00986 
00987                 istat = create_hex(ITYPE, hexVerts, hexFaces);
00988             }
00989             else
00990             {
00991                 istat = create_hex(ITYPE, hexVerts, internalFaces.begin());
00992             }
00993         }
00994         else
00995         {
00996             forAll(cellFaces, cFaceI)
00997             {
00998                 label faceI = cellFaces[cFaceI];
00999 
01000                 // Get Fieldview facetype (internal/on patch)
01001                 label fvFaceType = getFvType(mesh, faceI);
01002 
01003                 const face& f = faces[faceI];
01004 
01005                 // Indices into storage
01006                 label nQuads = 0;
01007                 label nTris = 0;
01008 
01009                 // Storage for triangles and quads created by face
01010                 // decomposition (sized for worst case)
01011                 faceList quadFaces((f.size() - 2)/2);
01012                 faceList triFaces(f.size() - 2);
01013 
01014                 f.trianglesQuads
01015                 (
01016                     points,
01017                     nTris,
01018                     nQuads,
01019                     triFaces,
01020                     quadFaces
01021                 );
01022 
01023                 // Label of cell centre in fv point list.
01024                 label polyCentrePoint = nPoints + nPolys;
01025 
01026                 for (label i=0; i<nTris; i++)
01027                 {
01028                     if (cellI == owner[faceI])
01029                     {
01030                         tetVerts[0] = triFaces[i][0] + 1;
01031                         tetVerts[1] = triFaces[i][1] + 1;
01032                         tetVerts[2] = triFaces[i][2] + 1;
01033                         tetVerts[3] = polyCentrePoint + 1;
01034                     }
01035                     else
01036                     {
01037                         tetVerts[0] = triFaces[i][2] + 1;
01038                         tetVerts[1] = triFaces[i][1] + 1;
01039                         tetVerts[2] = triFaces[i][0] + 1;
01040                         tetVerts[3] = polyCentrePoint + 1;
01041                     }
01042 
01043                     if (wallCell[cellI])
01044                     {
01045                         // Outside face is one without polyCentrePoint
01046                         tetFaces[0] = fvFaceType;
01047                         tetFaces[1] = 0;
01048                         tetFaces[2] = 0;
01049                         tetFaces[3] = 0;
01050 
01051                         istat = create_tet(ITYPE, tetVerts, tetFaces);
01052                     }
01053                     else
01054                     {
01055                         istat =
01056                             create_tet
01057                             (
01058                                 ITYPE,
01059                                 tetVerts,
01060                                 internalFaces.begin()
01061                             );
01062                     }
01063                 }
01064 
01065                 for (label i=0; i<nQuads; i++)
01066                 {
01067                     if (cellI == owner[faceI])
01068                     {
01069                         pyrVerts[0] = quadFaces[i][3] + 1;
01070                         pyrVerts[1] = quadFaces[i][2] + 1;
01071                         pyrVerts[2] = quadFaces[i][1] + 1;
01072                         pyrVerts[3] = quadFaces[i][0] + 1;
01073                         pyrVerts[4] = polyCentrePoint + 1;
01074 
01075                     }
01076                     else
01077                     {
01078                         pyrVerts[0] = quadFaces[i][0] + 1;
01079                         pyrVerts[1] = quadFaces[i][1] + 1;
01080                         pyrVerts[2] = quadFaces[i][2] + 1;
01081                         pyrVerts[3] = quadFaces[i][3] + 1;
01082                         pyrVerts[4] = polyCentrePoint + 1;
01083                     }
01084 
01085                     if (wallCell[cellI])
01086                     {
01087                         // Outside face is one without polyCentrePoint
01088                         pyrFaces[0] = fvFaceType;
01089                         pyrFaces[1] = 0;
01090                         pyrFaces[2] = 0;
01091                         pyrFaces[3] = 0;
01092                         pyrFaces[4] = 0;
01093 
01094                         istat = create_pyramid(ITYPE, pyrVerts, pyrFaces);
01095                     }
01096                     else
01097                     {
01098                         istat =
01099                             create_pyramid
01100                             (
01101                                 ITYPE,
01102                                 pyrVerts,
01103                                 internalFaces.begin()
01104                             );
01105                     }
01106                 }
01107 
01108                 if (istat != 0)
01109                 {
01110                     errorMsg("Error during adding cell " + name(cellI));
01111 
01112                     *iret = 1;
01113 
01114                     return;
01115                 }
01116             }
01117 
01118             nPolys++;
01119         }
01120 
01121         if (istat != 0)
01122         {
01123             errorMsg("Error during adding cell " + name(cellI));
01124 
01125             *iret = 1;
01126 
01127             return;
01128         }
01129     }
01130 
01131 
01132 
01133     //
01134     // Set fieldvalues
01135     //
01136 
01137     pointMesh pMesh(mesh);
01138 
01139     volPointInterpolation pInterp(mesh, pMesh);
01140 
01141     int pointI = 0;
01142 
01143     forAll(db_.volScalarNames(), i)
01144     {
01145         const word& fieldName = db_.volScalarNames()[i];
01146 
01147         storeScalarField(pInterp, fieldName, vars, pointI);
01148     }
01149 
01150 
01151     forAll(db_.volVectorNames(), i)
01152     {
01153         const word& fieldName = db_.volVectorNames()[i];
01154 
01155         storeVectorField(pInterp, fieldName, vars, pointI);
01156     }
01157 
01158     // Return without failure.
01159     *iret = 0;
01160 }
01161 
01162 
01163 void register_data_readers()
01164 {
01165     /*
01166     **
01167     ** You should edit this file to "register" a user-defined data
01168     ** reader with FIELDVIEW, if the user functions being registered
01169     ** here are written in C.
01170     ** You should edit "ftn_register_data_readers.f" if the user functions
01171     ** being registered are written in Fortran.
01172     ** In either case, the user functions being registered may call other
01173     ** functions written in either language (C or Fortran); only the
01174     ** language of the "query" and "read" functions referenced here matters
01175     ** to FIELDVIEW.
01176     **
01177     ** The following shows a sample user-defined data reader being
01178     ** "registered" with FIELDVIEW.
01179     **
01180     ** The "extern void" declarations should match the names of the
01181     ** query and grid-reading functions you are providing. It is
01182     ** strongly suggested that all such names begin with "user" so
01183     ** as not to conflict with global names in FIELDVIEW.
01184     **
01185     ** You may call any combination of the data reader registration
01186     ** functions shown below ("register_two_file_reader" and/or
01187     ** "register_single_file_reader" and/or "register_single_unstruct_reader"
01188     ** and/or "register_double_unstruct_reader") as many times as you like,
01189     ** in order to create several different data readers. Each data reader
01190     ** should of course have different "query" and "read" functions, all of
01191     ** which should also appear in "extern void" declarations.
01192     **
01193     */
01194 
01195     /*
01196     ** like this for combined unstructured grids & results in a single file
01197     */
01198     reg_single_unstruct_reader (
01199     "Foam Reader",             /* title you want for data reader */
01200     user_query_file_function,      /* whatever you called this */
01201     user_read_one_grid_function    /* whatever you called this */
01202     );
01203 }
01204 
01205 
01206 
01207 
01208 }
01209 
01210 
01211 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd