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

edgeVertex.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "edgeVertex.H"
00030 #include "meshTools.H"
00031 #include "refineCell.H"
00032 
00033 
00034 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
00035 
00036 
00037 // Update stored refine list using map
00038 void Foam::edgeVertex::updateLabels
00039 (
00040     const labelList& map,
00041     List<refineCell>& refCells
00042 )
00043 {
00044     label newRefI = 0;
00045 
00046     forAll(refCells, refI)
00047     {
00048         const refineCell& refCell = refCells[refI];
00049 
00050         label oldCellI = refCell.cellNo();
00051 
00052         label newCellI = map[oldCellI];
00053 
00054         if (newCellI != -1)
00055         {
00056             refCells[newRefI++] = refineCell(newCellI, refCell.direction());
00057         }
00058     }
00059     refCells.setSize(newRefI);
00060 }
00061 
00062 
00063 // Update stored cell numbers using map.
00064 // Do in two passes to prevent allocation if nothing changed.
00065 void Foam::edgeVertex::updateLabels
00066 (
00067     const labelList& map,
00068     Map<label>& cellPairs
00069 )
00070 {
00071     // Iterate over map to see if anything changed
00072     bool changed = false;
00073 
00074     for
00075     (
00076         Map<label>::const_iterator iter = cellPairs.begin();
00077         iter != cellPairs.end();
00078         ++iter
00079     )
00080     {
00081         label newMaster = map[iter.key()];
00082 
00083         label newSlave = -1;
00084 
00085         if (iter() != -1)
00086         {
00087             newSlave = map[iter()];
00088         }
00089 
00090         if ((newMaster != iter.key()) || (newSlave != iter()))
00091         {
00092             changed = true;
00093 
00094             break;
00095         }
00096     }
00097 
00098     // Relabel (use second Map to prevent overlapping)
00099     if (changed)
00100     {
00101         Map<label> newCellPairs(2*cellPairs.size());
00102 
00103         for
00104         (
00105             Map<label>::const_iterator iter = cellPairs.begin();
00106             iter != cellPairs.end();
00107             ++iter
00108         )
00109         {
00110             label newMaster = map[iter.key()];
00111 
00112             label newSlave = -1;
00113 
00114             if (iter() != -1)
00115             {
00116                 newSlave = map[iter()];
00117             }
00118 
00119             if (newMaster == -1)
00120             {
00121                 WarningIn
00122                 (
00123                     "edgeVertex::updateLabels(const labelList&, "
00124                     "Map<label>&)"
00125                 )   << "master cell:" << iter.key()
00126                     << " has disappeared" << endl;
00127             }
00128             else
00129             {
00130                 newCellPairs.insert(newMaster, newSlave);
00131             }
00132         }
00133 
00134         cellPairs = newCellPairs;
00135     }
00136 }
00137 
00138 
00139 // Update stored cell numbers using map.
00140 // Do in two passes to prevent allocation if nothing changed.
00141 void Foam::edgeVertex::updateLabels
00142 (
00143     const labelList& map,
00144     labelHashSet& cells
00145 )
00146 {
00147     // Iterate over map to see if anything changed
00148     bool changed = false;
00149 
00150     for
00151     (
00152         labelHashSet::const_iterator iter = cells.begin();
00153         iter != cells.end();
00154         ++iter
00155     )
00156     {
00157         label newCellI = map[iter.key()];
00158 
00159         if (newCellI != iter.key())
00160         {
00161             changed = true;
00162 
00163             break;
00164         }
00165     }
00166 
00167     // Relabel (use second Map to prevent overlapping)
00168     if (changed)
00169     {
00170         labelHashSet newCells(2*cells.size());
00171 
00172         for
00173         (
00174             labelHashSet::const_iterator iter = cells.begin();
00175             iter != cells.end();
00176             ++iter
00177         )
00178         {
00179             label newCellI = map[iter.key()];
00180 
00181             if (newCellI != -1)
00182             {
00183                 newCells.insert(newCellI);
00184             }
00185         }
00186 
00187         cells = newCells;
00188     }
00189 }
00190 
00191 
00192 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00193 
00194 Foam::point Foam::edgeVertex::coord
00195 (
00196     const primitiveMesh& mesh,
00197     const label cut,
00198     const scalar weight
00199 )
00200 {
00201     const pointField& pts = mesh.points();
00202 
00203     if (isEdge(mesh, cut))
00204     {
00205         const edge& e = mesh.edges()[getEdge(mesh, cut)];
00206 
00207         return weight*pts[e.end()] + (1-weight)*pts[e.start()];
00208     }
00209     else
00210     {
00211         return pts[getVertex(mesh, cut)];
00212     }
00213 }
00214 
00215 
00216 Foam::label Foam::edgeVertex::cutPairToEdge
00217 (
00218     const primitiveMesh& mesh,
00219     const label cut0,
00220     const label cut1
00221 )
00222 {
00223     if (!isEdge(mesh, cut0) && !isEdge(mesh, cut1))
00224     {
00225         return meshTools::findEdge
00226         (
00227             mesh,
00228             getVertex(mesh, cut0),
00229             getVertex(mesh, cut1)
00230         );
00231     }
00232     else
00233     {
00234         return -1;
00235     }
00236 }
00237 
00238 
00239 Foam::Ostream& Foam::edgeVertex::writeCut
00240 (
00241     Ostream& os,
00242     const label cut,
00243     const scalar weight
00244 ) const
00245 {
00246     if (isEdge(cut))
00247     {
00248         label edgeI = getEdge(cut);
00249 
00250         const edge& e = mesh().edges()[edgeI];
00251 
00252         os  << "edge:" << edgeI << e << ' ' << coord(cut, weight);
00253     }
00254     else
00255     {
00256         label vertI = getVertex(cut);
00257 
00258         os << "vertex:" << vertI << ' ' << coord(cut, weight);
00259     }
00260     return os;
00261 }
00262 
00263 
00264 Foam::Ostream& Foam::edgeVertex::writeCuts
00265 (
00266     Ostream& os,
00267     const labelList& cuts,
00268     const scalarField& weights
00269 ) const
00270 {
00271     forAll(cuts, cutI)
00272     {
00273         if (cutI > 0)
00274         {
00275             os << ' ';
00276         }
00277         writeCut(os, cuts[cutI], weights[cutI]);
00278     }
00279     return os;
00280 }
00281 
00282 
00283 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd