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

setToFaceZone.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 "setToFaceZone.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/faceZoneSet.H>
00029 
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(setToFaceZone, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, setToFaceZone, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, setToFaceZone, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::setToFaceZone::usage_
00047 (
00048     setToFaceZone::typeName,
00049     "\n    Usage: setToFaceZone <faceSet>\n\n"
00050     "    Select all faces in the faceSet."
00051     " Sets flipMap.\n\n"
00052 );
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00056 
00057 // Construct from components
00058 Foam::setToFaceZone::setToFaceZone
00059 (
00060     const polyMesh& mesh,
00061     const word& setName
00062 )
00063 :
00064     topoSetSource(mesh),
00065     setName_(setName)
00066 {}
00067 
00068 
00069 // Construct from dictionary
00070 Foam::setToFaceZone::setToFaceZone
00071 (
00072     const polyMesh& mesh,
00073     const dictionary& dict
00074 )
00075 :
00076     topoSetSource(mesh),
00077     setName_(dict.lookup("faceSet"))
00078 {}
00079 
00080 
00081 // Construct from Istream
00082 Foam::setToFaceZone::setToFaceZone
00083 (
00084     const polyMesh& mesh,
00085     Istream& is
00086 )
00087 :
00088     topoSetSource(mesh),
00089     setName_(checkIs(is))
00090 {}
00091 
00092 
00093 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00094 
00095 Foam::setToFaceZone::~setToFaceZone()
00096 {}
00097 
00098 
00099 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00100 
00101 void Foam::setToFaceZone::applyToSet
00102 (
00103     const topoSetSource::setAction action,
00104     topoSet& set
00105 ) const
00106 {
00107     if (!isA<faceZoneSet>(set))
00108     {
00109         WarningIn
00110         (
00111             "setToFaceZone::applyToSet(const topoSetSource::setAction"
00112             ", topoSet"
00113         )   << "Operation only allowed on a faceZoneSet." << endl;
00114     }
00115     else
00116     {
00117         faceZoneSet& fzSet = refCast<faceZoneSet>(set);
00118 
00119         if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00120         {
00121             Info<< "    Adding all faces from faceSet " << setName_
00122                 << " ..." << endl;
00123 
00124             // Load the sets
00125             faceSet fSet(mesh_, setName_);
00126 
00127             // Start off from copy
00128             DynamicList<label> newAddressing(fzSet.addressing());
00129             DynamicList<bool> newFlipMap(fzSet.flipMap());
00130 
00131             forAllConstIter(faceSet, fSet, iter)
00132             {
00133                 label faceI = iter.key();
00134 
00135                 if (!fzSet.found(faceI))
00136                 {
00137                     newAddressing.append(faceI);
00138                     newFlipMap.append(false);
00139                 }
00140             }
00141 
00142             fzSet.addressing().transfer(newAddressing);
00143             fzSet.flipMap().transfer(newFlipMap);
00144             fzSet.updateSet();
00145         }
00146         else if (action == topoSetSource::DELETE)
00147         {
00148             Info<< "    Removing all faces from faceSet " << setName_
00149                 << " ..." << endl;
00150 
00151             // Load the set
00152             faceSet loadedSet(mesh_, setName_);
00153 
00154             // Start off empty
00155             DynamicList<label> newAddressing(fzSet.addressing().size());
00156             DynamicList<bool> newFlipMap(fzSet.flipMap().size());
00157 
00158             forAll(fzSet.addressing(), i)
00159             {
00160                 if (!loadedSet.found(fzSet.addressing()[i]))
00161                 {
00162                     newAddressing.append(fzSet.addressing()[i]);
00163                     newFlipMap.append(fzSet.flipMap()[i]);
00164                 }
00165             }
00166             fzSet.addressing().transfer(newAddressing);
00167             fzSet.flipMap().transfer(newFlipMap);
00168             fzSet.updateSet();
00169         }
00170     }
00171 }
00172 
00173 
00174 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines