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

cellSource.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) 2009-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 "cellSource.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <OpenFOAM/IOList.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     namespace fieldValues
00036     {
00037         defineTypeNameAndDebug(cellSource, 0);
00038     }
00039 
00040     template<>
00041     const char* NamedEnum<fieldValues::cellSource::sourceType, 2>::
00042         names[] = {"cellZone", "all"};
00043 
00044     const NamedEnum<fieldValues::cellSource::sourceType, 2>
00045         fieldValues::cellSource::sourceTypeNames_;
00046 
00047     template<>
00048     const char* NamedEnum<fieldValues::cellSource::operationType, 7>::
00049         names[] =
00050         {
00051             "none", "sum", "volAverage",
00052             "volIntegrate", "weightedAverage", "min", "max"
00053         };
00054 
00055     const NamedEnum<fieldValues::cellSource::operationType, 7>
00056         fieldValues::cellSource::operationTypeNames_;
00057 
00058 }
00059 
00060 
00061 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00062 
00063 void Foam::fieldValues::cellSource::setCellZoneCells()
00064 {
00065     switch (source_)
00066     {
00067         case stCellZone:
00068         {
00069             label zoneId = mesh().cellZones().findZoneID(sourceName_);
00070 
00071             if (zoneId < 0)
00072             {
00073                 FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
00074                     << "Unknown cell zone name: " << sourceName_
00075                     << ". Valid cell zones are: " << mesh().cellZones().names()
00076                     << nl << exit(FatalError);
00077             }
00078 
00079             cellId_ = mesh().cellZones()[zoneId];
00080             nCells_ = returnReduce(cellId_.size(), sumOp<label>());
00081             break;
00082         }
00083 
00084         case stAll:
00085         {
00086             cellId_ = identity(mesh().nCells());
00087             nCells_ = returnReduce(cellId_.size(), sumOp<label>());
00088             break;
00089         }
00090 
00091         default:
00092         {
00093             FatalErrorIn("cellSource::setCellZoneCells()")
00094                << "Unknown source type. Valid source types are:"
00095                 << sourceTypeNames_ << nl << exit(FatalError);
00096         }
00097     }
00098 
00099     if (debug)
00100     {
00101         Pout<< "Selected source size = " << cellId_.size() << endl;
00102     }
00103 }
00104 
00105 
00106 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00107 
00108 void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
00109 {
00110     setCellZoneCells();
00111 
00112     Info<< type() << " " << name_ << ":" << nl
00113         << "    total cells  = " << nCells_ << nl
00114         << "    total volume = " << gSum(filterField(mesh().V()))
00115         << nl << endl;
00116 
00117     if (operation_ == opWeightedAverage)
00118     {
00119         dict.lookup("weightField") >> weightFieldName_;
00120         if
00121         (
00122             obr().foundObject<volScalarField>(weightFieldName_)
00123         )
00124         {
00125             Info<< "    weight field = " << weightFieldName_;
00126         }
00127         else
00128         {
00129             FatalErrorIn("cellSource::initialise()")
00130                 << type() << " " << name_ << ": "
00131                 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
00132                 << nl << "    Weight field " << weightFieldName_
00133                 << " must be a " << volScalarField::typeName
00134                 << nl << exit(FatalError);
00135         }
00136     }
00137 
00138     Info<< nl << endl;
00139 }
00140 
00141 
00142 void Foam::fieldValues::cellSource::writeFileHeader()
00143 {
00144     if (outputFilePtr_.valid())
00145     {
00146         outputFilePtr_()
00147             << "# Source : " << sourceTypeNames_[source_] << " "
00148             << sourceName_ <<  nl << "# Cells  : " << nCells_ << nl
00149             << "# Time" << tab << "sum(V)";
00150 
00151         forAll(fields_, i)
00152         {
00153             outputFilePtr_()
00154                 << tab << operationTypeNames_[operation_]
00155                 << "(" << fields_[i] << ")";
00156         }
00157 
00158         outputFilePtr_() << endl;
00159     }
00160 }
00161 
00162 
00163 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00164 
00165 Foam::fieldValues::cellSource::cellSource
00166 (
00167     const word& name,
00168     const objectRegistry& obr,
00169     const dictionary& dict,
00170     const bool loadFromFiles
00171 )
00172 :
00173     fieldValue(name, obr, dict, loadFromFiles),
00174     source_(sourceTypeNames_.read(dict.lookup("source"))),
00175     operation_(operationTypeNames_.read(dict.lookup("operation"))),
00176     nCells_(0),
00177     cellId_()
00178 {
00179     read(dict);
00180 }
00181 
00182 
00183 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00184 
00185 Foam::fieldValues::cellSource::~cellSource()
00186 {}
00187 
00188 
00189 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00190 
00191 void Foam::fieldValues::cellSource::read(const dictionary& dict)
00192 {
00193     fieldValue::read(dict);
00194 
00195     if (active_)
00196     {
00197         // no additional info to read
00198         initialise(dict);
00199     }
00200 }
00201 
00202 
00203 void Foam::fieldValues::cellSource::write()
00204 {
00205     fieldValue::write();
00206 
00207     if (active_)
00208     {
00209         if (Pstream::master())
00210         {
00211             outputFilePtr_()
00212                 << obr_.time().value() << tab
00213                 << sum(filterField(mesh().V()));
00214         }
00215 
00216         forAll(fields_, i)
00217         {
00218             writeValues<scalar>(fields_[i]);
00219             writeValues<vector>(fields_[i]);
00220             writeValues<sphericalTensor>(fields_[i]);
00221             writeValues<symmTensor>(fields_[i]);
00222             writeValues<tensor>(fields_[i]);
00223         }
00224 
00225         if (Pstream::master())
00226         {
00227             outputFilePtr_()<< endl;
00228         }
00229 
00230         if (log_)
00231         {
00232             Info<< endl;
00233         }
00234     }
00235 }
00236 
00237 
00238 // ************************ vim: set sw=4 sts=4 et: ************************ //
00239 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines