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 "molConfig.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 void Foam::molConfig::createMolecules()
33 Info<< nl << "Creating molecules from zone specifications\n" << endl;
35 DynamicList<vector> initialPositions(0);
37 DynamicList<label> initialIds(0);
39 DynamicList<scalar> initialMasses(0);
41 DynamicList<label> initialCelli(0);
43 DynamicList<vector> initialVelocities(0);
45 DynamicList<vector> initialAccelerations(0);
47 DynamicList<label> initialTethered(0);
49 DynamicList<vector> initialTetherPositions(0);
55 Random rand(clock::getTime());
57 // * * * * * * * * Building the IdList * * * * * * * * * //
59 //Notes: - each processor will have an identical idList_.
60 // - The order of id's inside the idList_ depends on the order
61 // of subDicts inside the molConigDict.
63 Info<< "Building the idList: " ;
65 forAll(molConfigDescription_.toc(), cZs)
67 word subDictName (molConfigDescription_.toc()[cZs]);
69 word iD (molConfigDescription_.subDict(subDictName).lookup("id"));
71 if (findIndex(idList_,iD) == -1)
79 Info << " " << idList_[i];
84 // * * * * * * * * Filling the Mesh * * * * * * * * * //
86 const cellZoneMesh& cellZoneI = mesh_.cellZones();
90 Info<< "Filling the zones with molecules." << nl << endl;
94 FatalErrorIn("void createMolecules()\n")
95 << "No cellZones found in mesh description."
99 forAll (cellZoneI, cZ)
101 if (cellZoneI[cZ].size())
103 if (!molConfigDescription_.found(cellZoneI[cZ].name()))
105 Info << "Zone specification subDictionary: "
106 << cellZoneI[cZ].name() << " not found." << endl;
112 label totalZoneMols = 0;
114 label molsPlacedThisIteration;
116 # include "readZoneSubDict.H"
118 idAssign = findIndex(idList_,id);
120 # include "startingPoint.H"
122 // Continue trying to place molecules as long as at
123 // least one molecule is placed in each iteration.
124 // The "|| totalZoneMols == 0" condition means that the
125 // algorithm will continue if the origin is outside the
126 // zone - it will cause an infinite loop if no molecules
127 // are ever placed by the algorithm.
129 if (latticeStructure != "empty")
134 molsPlacedThisIteration != 0
135 || totalZoneMols == 0
138 molsPlacedThisIteration = 0;
140 bool partOfLayerInBounds = false;
142 # include "createPositions.H"
147 && !partOfLayerInBounds
150 WarningIn("molConfig::createMolecules()")
151 << "A whole layer of unit cells was placed "
152 << "outside the bounds of the mesh, but no "
153 << "molecules have been placed in zone '"
154 << cellZoneI[cZ].name()
155 << "'. This is likely to be because the zone "
157 << cellZoneI[cZ].size()
158 << " in this case) and no lattice position "
159 << "fell inside them. "
160 << "Aborting filling this zone."
166 totalZoneMols += molsPlacedThisIteration;
176 molN < totalMols + totalZoneMols;
180 initialIds.append(idAssign);
182 initialMasses.append(mass);
184 initialAccelerations.append(vector::zero);
188 initialTethered.append(1);
190 initialTetherPositions.append
192 initialPositions[molN]
198 initialTethered.append(0);
200 initialTetherPositions.append(vector::zero);
204 # include "createVelocities.H"
206 # include "correctVelocities.H"
210 totalMols += totalZoneMols;
217 positions_ = initialPositions;
219 positions_.setSize(initialPositions.size());
223 id_.setSize(initialIds.size());
225 mass_ = initialMasses;
227 mass_.setSize(initialMasses.size());
229 cells_ = initialCelli;
231 cells_.setSize(initialCelli.size());
233 U_ = initialVelocities;
235 U_.setSize(initialVelocities.size());
237 A_ = initialAccelerations;
239 A_.setSize(initialAccelerations.size());
241 tethered_ = initialTethered;
243 tethered_.setSize(initialTethered.size());
245 tetherPositions_ = initialTetherPositions;
247 tetherPositions_.setSize(initialTetherPositions.size());
253 // ************************************************************************* //