foamSetupCHT.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  foamSetupCHT
26 
27 Description
28  This utility sets up a multi-region case using template files for
29  material properties, field and system files.
30 
31  The utility reads constant/materialProperties to create a
32  regionProperties file and to create region directories containing
33  required files within the 0, system and constant directories. The
34  materialProperties file contains mesh region names with an
35  associated physical region type and a material:
36 
37  bottomAir
38  {
39  type fluid;
40  material air;
41  }
42 
43  The case must contain a directory called templates, with e.g. the
44  following directories and files:
45  + 0
46  + fluid: p, p_rgh, U, T, k, omega, epsilon, nut, alphat
47  + solid: p, T
48  + system
49  + fluid: fvSchemes, fvSolution, decomposeParDict
50  + solid: fvSchemes, fvSolution, decomposeParDict
51  + constant
52  + fluid: g
53  + solid
54  + materials
55  + air: radiationProperties, thermophysicalProperties, turbulenceProperties
56  + aluminium: radiationProperties, thermophysicalProperties
57  + ...
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #include "argList.H"
62 #include "Time.H"
63 #include "IOdictionary.H"
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 int main(int argc, char *argv[])
70 {
71  #include "setRootCase.H"
72  #include "createTime.H"
73 
74  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76  Info<< "Reading material properties\n" << endl;
77 
78  IOdictionary materialProperties
79  (
80  IOobject
81  (
82  "materialProperties",
83  runTime.constant(),
84  runTime,
87  )
88  );
89 
91  (
92  IOobject
93  (
94  "regionProperties",
95  runTime.constant(),
96  runTime
97  ),
99  );
100 
101  const fileName currentDir(runTime.path());
102  const fileName materialsDir(currentDir/"templates"/"materials");
103  const fileName systemDir(currentDir/"templates"/"system");
104  const fileName constantDir(currentDir/"templates"/"constant");
105  const fileName timeDir(currentDir/"templates"/"0");
106 
107  HashTable<wordList> regionInfo;
108 
109  forAllConstIter(dictionary, materialProperties, regionIter)
110  {
111  // Read region subdict name, then its type and material entries
112  const word& regionName = regionIter().keyword();
113  const dictionary& regionDict = regionIter().dict();
114  const word regionType(regionDict.lookup("type"));
115  const word regionMaterial(regionDict.lookup("material"));
116 
117  Info<< "\nRegion " << regionName << ":\n"
118  << "\tCreating 0/" << regionName
119  << " directory" << endl;
120 
121  // Create fluid and solid lists for regionProperties, e.g.
122  // fluid ( bottomAir ... )
123  HashTable<wordList>::iterator iter = regionInfo.find(regionType);
124 
125  if (iter == regionInfo.end())
126  {
127  // Add fluid or solid list if does not exist
128  regionInfo.insert(regionType, wordList(1, regionName));
129  }
130  else
131  {
132  wordList& regionNames = iter();
133  if (findIndex(regionNames, regionName) == -1)
134  {
135  // Append region name to fluid/solid list
136  regionNames.append(regionName);
137  }
138  }
139 
140  // 0/<region>: from fluid/solid template
141  const fileName sourceDir(timeDir/regionType);
142  if (isDir(sourceDir))
143  {
144  cpFiles(sourceDir, currentDir/"0"/regionName);
145  }
146  else
147  {
148  // This needs checking ...
149  FatalIOErrorIn(args.executable().c_str(), materialProperties)
150  << "Cannot find region type file "
151  << sourceDir << exit(FatalIOError);
152  }
153 
154  Info<< "\tCreating constant/" << regionName
155  << " directory with " << regionMaterial
156  << " material" << endl;
157  cpFiles(constantDir/regionType, currentDir/"constant"/regionName);
158  cpFiles(materialsDir/regionMaterial, currentDir/"constant"/regionName);
159 
160  // system/<region>: from fluid or solid templ
161  Info<< "\tCreating system/" << regionName
162  << " directory" << endl;
163  cpFiles(systemDir/regionType, currentDir/"system"/regionName);
164  }
165 
166  regionProperties.add("regions", regionInfo);
167 
168  Info<< "\nWriting region properties\n" << endl;
169 
170  regionProperties.regIOobject::write();
171 
172  Info<< "End\n" << endl;
173 
174  return 0;
175 }
176 
177 
178 // ************************************************************************* //
const word & executable() const
Name of executable without the path.
Definition: argListI.H:30
fileName path() const
Return path.
Definition: Time.H:266
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:110
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void cpFiles(const fileName &srcDir, const fileName &targetDir)
Copy all the files from the source to the target directory.
static const dictionary null
Null dictionary.
Definition: dictionary.H:202
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Simple class to hold region information for coupled region simulations.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:528
A class for handling words, derived from string.
Definition: word.H:59
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
List< word > wordList
A List of words.
Definition: fileName.H:54
messageStream Info
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
IOerror FatalIOError