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

faceZoneToCell.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 "faceZoneToCell.H"
00028 #include "polyMesh.H"
00029 
00030 #include "addToRunTimeSelectionTable.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(faceZoneToCell, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
00047 (
00048     faceZoneToCell::typeName,
00049     "\n    Usage: faceZoneToCell zone master|slave\n\n"
00050     "    Select master or slave side of the faceZone."
00051     " Note:accepts wildcards for zone.\n\n"
00052 );
00053 
00054 
00055 template<>
00056 const char* Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>::names[] =
00057 {
00058     "master",
00059     "slave"
00060 };
00061 
00062 
00063 const Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>
00064     Foam::faceZoneToCell::faceActionNames_;
00065 
00066 
00067 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00068 
00069 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
00070 {
00071     bool hasMatched = false;
00072 
00073     forAll(mesh_.faceZones(), i)
00074     {
00075         const faceZone& zone = mesh_.faceZones()[i];
00076 
00077         if (zoneName_.match(zone.name()))
00078         {
00079             const labelList& cellLabels =
00080             (
00081                 option_ == MASTER
00082               ? zone.masterCells()
00083               : zone.slaveCells()
00084             );
00085 
00086             Info<< "    Found matching zone " << zone.name()
00087                 << " with " << cellLabels.size() << " cells on selected side."
00088                 << endl;
00089 
00090             hasMatched = true;
00091 
00092             forAll(cellLabels, i)
00093             {
00094                 // Only do active cells
00095                 if (cellLabels[i] < mesh_.nCells())
00096                 {
00097                     addOrDelete(set, cellLabels[i], add);
00098                 }
00099             }
00100         }
00101     }
00102 
00103     if (!hasMatched)
00104     {
00105         WarningIn("faceZoneToCell::combine(topoSet&, const bool)")
00106             << "Cannot find any faceZone named " << zoneName_ << endl
00107             << "Valid names are " << mesh_.faceZones().names() << endl;
00108     }
00109 }
00110 
00111 
00112 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00113 
00114 // Construct from components
00115 Foam::faceZoneToCell::faceZoneToCell
00116 (
00117     const polyMesh& mesh,
00118     const word& zoneName,
00119     const faceAction option
00120 )
00121 :
00122     topoSetSource(mesh),
00123     zoneName_(zoneName),
00124     option_(option)
00125 {}
00126 
00127 
00128 // Construct from dictionary
00129 Foam::faceZoneToCell::faceZoneToCell
00130 (
00131     const polyMesh& mesh,
00132     const dictionary& dict
00133 )
00134 :
00135     topoSetSource(mesh),
00136     zoneName_(dict.lookup("name")),
00137     option_(faceActionNames_.read(dict.lookup("option")))
00138 {}
00139 
00140 
00141 // Construct from Istream
00142 Foam::faceZoneToCell::faceZoneToCell
00143 (
00144     const polyMesh& mesh,
00145     Istream& is
00146 )
00147 :
00148     topoSetSource(mesh),
00149     zoneName_(checkIs(is)),
00150     option_(faceActionNames_.read(checkIs(is)))
00151 {}
00152 
00153 
00154 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00155 
00156 Foam::faceZoneToCell::~faceZoneToCell()
00157 {}
00158 
00159 
00160 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00161 
00162 void Foam::faceZoneToCell::applyToSet
00163 (
00164     const topoSetSource::setAction action,
00165     topoSet& set
00166 ) const
00167 {
00168     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00169     {
00170         Info<< "    Adding all " << faceActionNames_[option_]
00171             << " cells of faceZone " << zoneName_ << " ..." << endl;
00172 
00173         combine(set, true);
00174     }
00175     else if (action == topoSetSource::DELETE)
00176     {
00177         Info<< "    Removing all " << faceActionNames_[option_]
00178             << " cells of faceZone " << zoneName_ << " ..." << endl;
00179 
00180         combine(set, false);
00181     }
00182 }
00183 
00184 
00185 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd