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

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