Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <finiteVolume/findRefCell.H>
00027 
00028 
00029 
00030 void Foam::setRefCell
00031 (
00032     const volScalarField& field,
00033     const volScalarField& fieldRef,
00034     const dictionary& dict,
00035     label& refCelli,
00036     scalar& refValue,
00037     const bool forceReference
00038 )
00039 {
00040     if (fieldRef.needReference() || forceReference)
00041     {
00042         word refCellName = field.name() + "RefCell";
00043         word refPointName = field.name() + "RefPoint";
00044 
00045         word refValueName = field.name() + "RefValue";
00046 
00047         if (dict.found(refCellName))
00048         {
00049             if (Pstream::master())
00050             {
00051                 refCelli = readLabel(dict.lookup(refCellName));
00052 
00053                 if (refCelli < 0 || refCelli >= field.mesh().nCells())
00054                 {
00055                     FatalIOErrorIn
00056                     (
00057                         "void Foam::setRefCell\n"
00058                          "(\n"
00059                          "    const volScalarField&,\n"
00060                          "    const volScalarField&,\n"
00061                          "    const dictionary&,\n"
00062                          "    label& scalar&,\n"
00063                          "    bool\n"
00064                          ")",
00065                         dict
00066                     )   << "Illegal master cellID " << refCelli
00067                         << ". Should be 0.." << field.mesh().nCells()
00068                         << exit(FatalIOError);
00069                 }
00070             }
00071             else
00072             {
00073                 refCelli = -1;
00074             }
00075         }
00076         else if (dict.found(refPointName))
00077         {
00078             point refPointi(dict.lookup(refPointName));
00079             refCelli = field.mesh().findCell(refPointi);
00080             label hasRef = (refCelli >= 0 ? 1 : 0);
00081             label sumHasRef = returnReduce<label>(hasRef, sumOp<label>());
00082             if (sumHasRef != 1)
00083             {
00084                 FatalIOErrorIn
00085                 (
00086                     "void Foam::setRefCell\n"
00087                      "(\n"
00088                      "    const volScalarField&,\n"
00089                      "    const volScalarField&,\n"
00090                      "    const dictionary&,\n"
00091                      "    label& scalar&,\n"
00092                      "    bool\n"
00093                      ")",
00094                     dict
00095                 )   << "Unable to set reference cell for field " << field.name()
00096                     << nl << "    Reference point " << refPointName
00097                     << " " << refPointi
00098                     << " found on " << sumHasRef << " domains (should be one)"
00099                     << nl << exit(FatalIOError);
00100             }
00101         }
00102         else
00103         {
00104             FatalIOErrorIn
00105             (
00106                 "void Foam::setRefCell\n"
00107                  "(\n"
00108                  "    const volScalarField&,\n"
00109                  "    const volScalarField&,\n"
00110                  "    const dictionary&,\n"
00111                  "    label& scalar&,\n"
00112                  "    bool\n"
00113                  ")",
00114                 dict
00115             )   << "Unable to set reference cell for field " << field.name()
00116                 << nl
00117                 << "    Please supply either " << refCellName
00118                 << " or " << refPointName << nl << exit(FatalIOError);
00119         }
00120 
00121         refValue = readScalar(dict.lookup(refValueName));
00122     }
00123 }
00124 
00125 
00126 void Foam::setRefCell
00127 (
00128     const volScalarField& field,
00129     const dictionary& dict,
00130     label& refCelli,
00131     scalar& refValue,
00132     const bool forceReference
00133 )
00134 {
00135     setRefCell(field, field, dict, refCelli, refValue, forceReference);
00136 }
00137 
00138 
00139 Foam::scalar Foam::getRefCellValue
00140 (
00141     const volScalarField& field,
00142     const label refCelli
00143 )
00144 {
00145     scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
00146     return returnReduce(refCellValue, sumOp<scalar>());
00147 }
00148 
00149 
00150