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

findRefCell.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "findRefCell.H"
00028 
00029 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00030 
00031 void Foam::setRefCell
00032 (
00033     const volScalarField& field,
00034     const dictionary& dict,
00035     label& refCelli,
00036     scalar& refValue,
00037     const bool forceReference
00038 )
00039 {
00040     if (field.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 dictionary&,\n"
00061                          "    label& scalar&,\n"
00062                          "    bool\n"
00063                          ")",
00064                         dict
00065                     )   << "Illegal master cellID " << refCelli
00066                         << ". Should be 0.." << field.mesh().nCells()
00067                         << exit(FatalIOError);
00068                 }
00069             }
00070             else
00071             {
00072                 refCelli = -1;
00073             }
00074         }
00075         else if (dict.found(refPointName))
00076         {
00077             point refPointi(dict.lookup(refPointName));
00078             refCelli = field.mesh().findCell(refPointi);
00079             label hasRef = (refCelli >= 0 ? 1 : 0);
00080             label sumHasRef = returnReduce<label>(hasRef, sumOp<label>());
00081             if (sumHasRef != 1)
00082             {
00083                 FatalIOErrorIn
00084                 (
00085                     "void Foam::setRefCell\n"
00086                      "(\n"
00087                      "    const volScalarField&,\n"
00088                      "    const dictionary&,\n"
00089                      "    label& scalar&,\n"
00090                      "    bool\n"
00091                      ")",
00092                     dict
00093                 )   << "Unable to set reference cell for field " << field.name()
00094                     << nl << "    Reference point " << refPointName
00095                     << " " << refPointi
00096                     << " found on " << sumHasRef << " domains (should be one)"
00097                     << nl << exit(FatalIOError);
00098             }
00099         }
00100         else
00101         {
00102             FatalIOErrorIn
00103             (
00104                 "void Foam::setRefCell\n"
00105                  "(\n"
00106                  "    const volScalarField&,\n"
00107                  "    const dictionary&,\n"
00108                  "    label& scalar&,\n"
00109                  "    bool\n"
00110                  ")",
00111                 dict
00112             )   << "Unable to set reference cell for field " << field.name()
00113                 << nl
00114                 << "    Please supply either " << refCellName
00115                 << " or " << refPointName << nl << exit(FatalIOError);
00116         }
00117 
00118         refValue = readScalar(dict.lookup(refValueName));
00119     }
00120 }
00121 
00122 
00123 Foam::scalar Foam::getRefCellValue
00124 (
00125     const volScalarField& field,
00126     const label refCelli
00127 )
00128 {
00129     scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
00130     return returnReduce<label>(refCellValue, sumOp<scalar>());
00131 }
00132 
00133 
00134 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd