FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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