new bc
[OpenFOAM-1.5.x.git] / applications / solvers / heatTransfer / chtMultiRegionFoam / coupleManager / coupleManager.C
blob58c7bdaa399611f75148ca026cabc725d97718f6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "coupleManager.H"
28 #include "OFstream.H"
29 #include "regionProperties.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 Foam::coupleManager::coupleManager(const fvPatch& patch)
35     patch_(patch),
36     neighbourRegionName_("undefined-neighbourRegionName"),
37     neighbourPatchName_("undefined-neighbourPatchName"),
38     neighbourFieldName_("undefined-neighbourFieldName"),
39     localRegion_(patch_.boundaryMesh().mesh())
43 Foam::coupleManager::coupleManager
45     const fvPatch& patch,
46     const dictionary& dict
49     patch_(patch),
50     neighbourRegionName_(dict.lookup("neighbourRegionName")),
51     neighbourPatchName_(dict.lookup("neighbourPatchName")),
52     neighbourFieldName_(dict.lookup("neighbourFieldName")),
53     localRegion_(patch_.boundaryMesh().mesh())
57 Foam::coupleManager::coupleManager
59     const coupleManager& cm
62     patch_(cm.patch()),
63     neighbourRegionName_(cm.neighbourRegionName()),
64     neighbourPatchName_(cm.neighbourPatchName()),
65     neighbourFieldName_(cm.neighbourFieldName()),
66     localRegion_(patch_.boundaryMesh().mesh())
70 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
72 Foam::coupleManager::~coupleManager()
76 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
78 bool Foam::coupleManager::regionOwner() const
80     const fvMesh& nbrRegion = neighbourRegion();
82     const regionProperties& props =
83         localRegion_.objectRegistry::parent().lookupObject<regionProperties>
84         (
85             "regionProperties"
86         );
88     label myIndex = findIndex(props.fluidRegionNames(), localRegion_.name());
89     if (myIndex == -1)
90     {
91         label i = findIndex(props.solidRegionNames(), localRegion_.name());
93         if (i == -1)
94         {
95             FatalErrorIn("coupleManager::regionOwner() const")
96                 << "Cannot find region " << localRegion_.name()
97                 << " neither in fluids " << props.fluidRegionNames()
98                 << " nor in solids " << props.solidRegionNames()
99                 << exit(FatalError);
100         }
101         myIndex = props.fluidRegionNames().size() + i;
102     }
103     label nbrIndex = findIndex(props.fluidRegionNames(), nbrRegion.name());
104     if (nbrIndex == -1)
105     {
106         label i = findIndex(props.solidRegionNames(), nbrRegion.name());
108         if (i == -1)
109         {
110             FatalErrorIn("coupleManager::regionOwner() const")
111                 << "Cannot find region " << nbrRegion.name()
112                 << " neither in fluids " << props.fluidRegionNames()
113                 << " nor in solids " << props.solidRegionNames()
114                 << exit(FatalError);
115         }
116         nbrIndex = props.fluidRegionNames().size() + i;
117     }
119     return myIndex < nbrIndex;
123 void Foam::coupleManager::checkCouple() const
125     Info<< "neighbourRegionName_ = " << neighbourRegionName_ << endl;
126     Info<< "neighbourPatchName_ = " << neighbourPatchName_ << endl;
127     Info<< "neighbourFieldName_ = " << neighbourFieldName_ << endl;
129     const fvPatch& nPatch = neighbourPatch();
131     if (patch_.size() != nPatch.size())
132     {
133         FatalErrorIn("Foam::coupleManager::checkCouple()")
134             << "Unequal patch sizes:" << nl
135             << "    patch name (size) = " << patch_.name()
136             << "(" << patch_.size() << ")" << nl
137             << "    neighbour patch name (size) = "
138             << nPatch.name() << "(" << patch_.size() << ")" << nl
139             << abort(FatalError);
140     }
144 void Foam::coupleManager::coupleToObj() const
146     const fvPatch& nPatch = neighbourPatch();
148     OFstream obj
149         (
150              patch_.name() + "_to_" + nPatch.name() + "_couple.obj"
151         );
152     const vectorField& c1 = patch_.Cf();
153     const vectorField& c2 = neighbourPatch().Cf();
155     if (c1.size() != c2.size())
156     {
157         FatalErrorIn("coupleManager::coupleToObj() const")
158             << "Coupled patches are of unequal size:" << nl
159             << "    patch0 = " << patch_.name()
160             << "(" << patch_.size() <<  ")" << nl
161             << "    patch1 = " << nPatch.name()
162             << "(" << nPatch.size() <<  ")" << nl
163             << abort(FatalError);
164     }
166     forAll(c1, i)
167     {
168         obj << "v " << c1[i].x() << " " << c1[i].y() << " " << c1[i].z() << nl
169             << "v " << c2[i].x() << " " << c2[i].y() << " " << c2[i].z() << nl
170             << "l " << (2*i + 1) << " " << (2*i + 2) << endl;
171     }
175 void Foam::coupleManager::writeEntries(Ostream& os) const
177     os.writeKeyword("neighbourRegionName");
178     os << neighbourRegionName_ << token::END_STATEMENT << nl;
179     os.writeKeyword("neighbourPatchName");
180     os << neighbourPatchName_ << token::END_STATEMENT << nl;
181     os.writeKeyword("neighbourFieldName");
182     os << neighbourFieldName_ << token::END_STATEMENT << nl;
186 // ************************************************************************* //