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

sampledSurfacesTemplates.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 "sampledSurfaces.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/ListListOps.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 template<class Type>
00033 void Foam::sampledSurfaces::sampleAndWrite
00034 (
00035     const GeometricField<Type, fvPatchField, volMesh>& vField,
00036     const surfaceWriter<Type>& formatter
00037 )
00038 {
00039     // interpolator for this field
00040     autoPtr< interpolation<Type> > interpolator;
00041 
00042     const word& fieldName   = vField.name();
00043     const fileName outputDir = outputPath_/vField.time().timeName();
00044 
00045     forAll(*this, surfI)
00046     {
00047         const sampledSurface& s = operator[](surfI);
00048 
00049         Field<Type> values;
00050 
00051         if (s.interpolate())
00052         {
00053             if (interpolator.empty())
00054             {
00055                 interpolator = interpolation<Type>::New
00056                 (
00057                     interpolationScheme_,
00058                     vField
00059                 );
00060             }
00061 
00062             values = s.interpolate(interpolator());
00063         }
00064         else
00065         {
00066             values = s.sample(vField);
00067         }
00068 
00069         if (Pstream::parRun())
00070         {
00071             // Collect values from all processors
00072             List<Field<Type> > gatheredValues(Pstream::nProcs());
00073             gatheredValues[Pstream::myProcNo()] = values;
00074             Pstream::gatherList(gatheredValues);
00075 
00076             if (Pstream::master())
00077             {
00078                 // Combine values into single field
00079                 Field<Type> allValues
00080                 (
00081                     ListListOps::combine<Field<Type> >
00082                     (
00083                         gatheredValues,
00084                         accessOp<Field<Type> >()
00085                     )
00086                 );
00087 
00088                 // Renumber (point data) to correspond to merged points
00089                 if (mergeList_[surfI].pointsMap.size() == allValues.size())
00090                 {
00091                     inplaceReorder(mergeList_[surfI].pointsMap, allValues);
00092                     allValues.setSize(mergeList_[surfI].points.size());
00093                 }
00094 
00095                 // Write to time directory under outputPath_
00096                 // skip surface without faces (eg, a failed cut-plane)
00097                 if (mergeList_[surfI].faces.size())
00098                 {
00099                     formatter.write
00100                     (
00101                         outputDir,
00102                         s.name(),
00103                         mergeList_[surfI].points,
00104                         mergeList_[surfI].faces,
00105                         fieldName,
00106                         allValues
00107                     );
00108                 }
00109             }
00110         }
00111         else
00112         {
00113             // Write to time directory under outputPath_
00114             // skip surface without faces (eg, a failed cut-plane)
00115             if (s.faces().size())
00116             {
00117                 formatter.write
00118                 (
00119                     outputDir,
00120                     s.name(),
00121                     s.points(),
00122                     s.faces(),
00123                     fieldName,
00124                     values
00125                 );
00126             }
00127         }
00128     }
00129 }
00130 
00131 
00132 template<class Type>
00133 void Foam::sampledSurfaces::sampleAndWrite
00134 (
00135     fieldGroup<Type>& fields
00136 )
00137 {
00138     if (fields.size())
00139     {
00140         // create or use existing surfaceWriter
00141         if (fields.formatter.empty())
00142         {
00143             fields.formatter = surfaceWriter<Type>::New(writeFormat_);
00144         }
00145 
00146         forAll(fields, fieldI)
00147         {
00148             if (Pstream::master() && verbose_)
00149             {
00150                 Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
00151             }
00152 
00153             if (loadFromFiles_)
00154             {
00155                 sampleAndWrite
00156                 (
00157                     GeometricField<Type, fvPatchField, volMesh>
00158                     (
00159                         IOobject
00160                         (
00161                             fields[fieldI],
00162                             mesh_.time().timeName(),
00163                             mesh_,
00164                             IOobject::MUST_READ,
00165                             IOobject::NO_WRITE,
00166                             false
00167                         ),
00168                         mesh_
00169                     ),
00170                     fields.formatter()
00171                 );
00172             }
00173             else
00174             {
00175                 objectRegistry::const_iterator iter =
00176                     mesh_.find(fields[fieldI]);
00177 
00178                 if
00179                 (
00180                     iter != mesh_.objectRegistry::end()
00181                  && iter()->type()
00182                  == GeometricField<Type, fvPatchField, volMesh>::typeName
00183                 )
00184                 {
00185                    sampleAndWrite
00186                    (
00187                        mesh_.lookupObject
00188                        <GeometricField<Type, fvPatchField, volMesh> >
00189                        (
00190                            fields[fieldI]
00191                        ),
00192                        fields.formatter()
00193                    );
00194                 }
00195             }
00196         }
00197     }
00198 }
00199 
00200 
00201 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines