1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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"
29 #include "regionProperties.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::coupleManager::coupleManager(const fvPatch& patch)
36 neighbourRegionName_("undefined-neighbourRegionName"),
37 neighbourPatchName_("undefined-neighbourPatchName"),
38 neighbourFieldName_("undefined-neighbourFieldName"),
39 localRegion_(patch_.boundaryMesh().mesh())
43 Foam::coupleManager::coupleManager
46 const dictionary& dict
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
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>
88 label myIndex = findIndex(props.fluidRegionNames(), localRegion_.name());
91 label i = findIndex(props.solidRegionNames(), localRegion_.name());
95 FatalErrorIn("coupleManager::regionOwner() const")
96 << "Cannot find region " << localRegion_.name()
97 << " neither in fluids " << props.fluidRegionNames()
98 << " nor in solids " << props.solidRegionNames()
101 myIndex = props.fluidRegionNames().size() + i;
103 label nbrIndex = findIndex(props.fluidRegionNames(), nbrRegion.name());
106 label i = findIndex(props.solidRegionNames(), nbrRegion.name());
110 FatalErrorIn("coupleManager::regionOwner() const")
111 << "Cannot find region " << nbrRegion.name()
112 << " neither in fluids " << props.fluidRegionNames()
113 << " nor in solids " << props.solidRegionNames()
116 nbrIndex = props.fluidRegionNames().size() + i;
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())
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);
144 void Foam::coupleManager::coupleToObj() const
146 const fvPatch& nPatch = neighbourPatch();
150 patch_.name() + "_to_" + nPatch.name() + "_couple.obj"
152 const vectorField& c1 = patch_.Cf();
153 const vectorField& c2 = neighbourPatch().Cf();
155 if (c1.size() != c2.size())
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);
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;
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 // ************************************************************************* //