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

USERD_set_filenames.H

Go to the documentation of this file.
00001 //======================================================================
00002 //  Setting filenames
00003 //======================================================================
00004 int USERD_set_filenames
00005 (
00006     char filename_1[],
00007     char filename_2[],
00008     char the_path[],
00009     int swapbytes
00010 )
00011 {
00012 #ifdef ENSIGHTDEBUG
00013     Info << "Entering: USERD_set_filenames" << endl << flush;
00014 #endif
00015 
00016     char tmp[100];
00017 
00018     label lRoot = strlen(the_path);
00019     label lCase = strlen(filename_1);
00020 
00021     bool cleared = false;
00022 
00023     while (!cleared)
00024     {
00025         lRoot = strlen(the_path);
00026         lCase = strlen(filename_1);
00027 
00028         // remove the last '/' from rootDir
00029         if (the_path[lRoot-1] == '/')
00030         {
00031             the_path[lRoot-1] = (char)NULL;
00032         }
00033         else
00034         {
00035             cleared = true;
00036         }
00037     }
00038 
00039     rootDir = the_path;
00040 
00041     // the path is pre-pended to filename_1
00042     // 1 is the 'Geometry' : 2 the 'Result' which is null here
00043     // since two_field is FALSE
00044     for (label i=0; i<lCase-lRoot;i++)
00045     {
00046         tmp[i] = filename_1[i+1+lRoot];
00047     }
00048     caseDir = tmp;
00049 
00050     if (!isDir(rootDir/caseDir))
00051     {
00052        Info<< rootDir/caseDir << " is not a valid directory."
00053            << endl;
00054        return Z_ERR;
00055     }
00056 
00057     // construct the global pointers to the database and mesh
00058 
00059     delete meshPtr;
00060     delete runTimePtr;
00061 
00062     runTimePtr = new Time
00063     (
00064         Time::controlDictName,
00065         rootDir,
00066         caseDir
00067     );
00068 
00069     Time& runTime = *runTimePtr;
00070 
00071     meshPtr = new fvMesh
00072     (
00073         IOobject
00074         (
00075             fvMesh::defaultRegion,
00076             runTime.timeName(),
00077             runTime
00078         )
00079     );
00080 
00081     // set the available number of time-steps
00082     timeDirs = Foam::Time::findTimes(rootDir/caseDir);
00083 
00084     Num_time_steps = timeDirs.size() - 1;
00085 
00086     nPatches = meshPtr->boundaryMesh().size();
00087 
00088     // set the number of fields and store their names
00089     // a valid field must exist for all time-steps
00090     runTime.setTime(timeDirs[timeDirs.size()-1], timeDirs.size()-1);
00091     IOobjectList objects(*meshPtr, runTime.timeName());
00092 
00093     fieldNames = objects.names();
00094 
00095     // because of the spray being a 'field' ...
00096     // get the availabe number of variables and
00097     // check for type (scalar/vector/tensor)
00098 
00099     label nVar = 0;
00100     wordList scalars = objects.names(scalarName);
00101 
00102     for (label n=0; n<fieldNames.size(); n++)
00103     {
00104         bool isitScalar = false;
00105         forAll(scalars,i)
00106         {
00107             if (fieldNames[n] == scalars[i])
00108             {
00109                 isitScalar = true;
00110                 var2field[nVar++] = n;
00111             }
00112         }
00113         isScalar[n] = isitScalar;
00114     }
00115 
00116     wordList vectors = objects.names(vectorName);
00117 
00118     for (label n=0; n<fieldNames.size(); n++)
00119     {
00120         bool isitVector = false;
00121         forAll(vectors,i)
00122         {
00123             if (fieldNames[n] == vectors[i])
00124             {
00125                 isitVector = true;
00126                 var2field[nVar++] = n;
00127             }
00128         }
00129         isVector[n] = isitVector;
00130     }
00131 
00132     wordList tensors = objects.names(tensorName);
00133 
00134     for (label n=0; n<fieldNames.size(); n++)
00135     {
00136         bool isitTensor = false;
00137         forAll(tensors,i)
00138         {
00139             if (fieldNames[n] == tensors[i])
00140             {
00141                 isitTensor = true;
00142                 var2field[nVar++] = n;
00143             }
00144         }
00145         isTensor[n] = isitTensor;
00146     }
00147 
00148     bool lagrangianNamesFound = false;
00149     label n = 0;
00150     while (!lagrangianNamesFound && n < Num_time_steps)
00151     {
00152         runTime.setTime(timeDirs[n+1], n+1);
00153 
00154         Cloud<passiveParticle> lagrangian(*meshPtr);
00155 
00156         n++;
00157         if (lagrangian.size())
00158         {
00159             lagrangianNamesFound = true;
00160         }
00161     }
00162 
00163     IOobject sprayHeader
00164     (
00165         "positions",
00166         runTime.timeName(),
00167         cloud::prefix,
00168         runTime,
00169         IOobject::NO_READ,
00170         IOobject::NO_WRITE,
00171         false
00172     );
00173 
00174     if (sprayHeader.headerOk())
00175     {
00176         Info << "[Found lagrangian]" << endl;
00177 
00178         delete sprayPtr;
00179 
00180         sprayPtr = new Cloud<passiveParticle>(*meshPtr);
00181 
00182         IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix);
00183 
00184         lagrangianScalarNames =
00185             (const wordList&)objects.names(sprayScalarFieldName);
00186         lagrangianVectorNames =
00187             (const wordList&)objects.names(sprayVectorFieldName);
00188 
00189         isSpray[fieldNames.size()] = true;
00190 
00191         nSprayVariables += lagrangianScalarNames.size();
00192         nSprayVariables += lagrangianVectorNames.size();
00193 
00194         Num_unstructured_parts++;
00195     }
00196 
00197     Current_time_step = Num_time_steps;
00198     runTime.setTime(timeDirs[Current_time_step], Current_time_step);
00199 
00200     Num_variables = nVar + nSprayVariables;
00201     Numparts_available = Num_unstructured_parts + Num_structured_parts + nPatches;
00202 
00203 #ifdef ENSIGHTDEBUG
00204     Info << "Leaving: USERD_set_filenames" << endl << flush;
00205 #endif
00206 
00207     return Z_OK;
00208 }
00209 
Copyright © 2000-2009 OpenCFD Ltd