All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2022 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 regionSolvers list
32  and to create region directories containing required files within the 0,
33  system and constant directories. The materialProperties file contains mesh
34  region names with an associated solver and a material:
35 
36  bottomAir
37  {
38  solver fluid;
39  material air;
40  }
41 
42  The case must contain a directory called templates, with e.g. the
43  following directories and files:
44  + 0
45  + fluid: p, p_rgh, U, T, k, omega, epsilon, nut, alphat
46  + solid: p, T
47  + system
48  + fluid: fvSchemes, fvSolution, decomposeParDict
49  + solid: fvSchemes, fvSolution, decomposeParDict
50  + constant
51  + fluid: g
52  + solid
53  + materials
54  + air: radiationProperties, thermophysicalProperties, momentumTransport
55  + aluminium: radiationProperties, thermophysicalProperties
56  + ...
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include "argList.H"
61 #include "Time.H"
62 #include "IOdictionary.H"
63 #include "dictionaryEntry.H"
64 #include "OFstream.H"
65 
66 using namespace Foam;
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 int main(int argc, char *argv[])
71 {
72  #include "setRootCase.H"
73  #include "createTime.H"
74 
75  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77  Info<< "Reading material properties\n" << endl;
78 
79  IOdictionary materialProperties
80  (
81  IOobject
82  (
83  "materialProperties",
84  runTime.constant(),
85  runTime,
88  )
89  );
90 
91  const fileName currentDir(runTime.path());
92  const fileName materialsDir(currentDir/"templates"/"materials");
93  const fileName systemDir(currentDir/"templates"/"system");
94  const fileName constantDir(currentDir/"templates"/"constant");
95  const fileName timeDir(currentDir/"templates"/"0");
96 
98  (
99  "regionSolvers",
102  );
103 
104  forAllConstIter(dictionary, materialProperties, regionIter)
105  {
106  // Read region subdict name, then its type and material entries
107  const word& regionName = regionIter().keyword();
108  const dictionary& regionDict = regionIter().dict();
109  const word regionSolver(regionDict.lookup("solver"));
110  const word regionMaterial(regionDict.lookup("material"));
111 
112  Info<< "\nRegion " << regionName << ":\n"
113  << "\tCreating 0/" << regionName
114  << " directory" << endl;
115 
116  regionSolvers.add(regionName, regionSolver);
117 
118  // 0/<region>: from fluid/solid template
119  const fileName sourceDir(timeDir/regionSolver);
120  if (isDir(sourceDir))
121  {
122  cpFiles(sourceDir, currentDir/"0"/regionName);
123  }
124  else
125  {
126  FatalIOErrorIn(args.executable().c_str(), materialProperties)
127  << "Cannot find region type file "
128  << sourceDir << exit(FatalIOError);
129  }
130 
131  const fileName matDir(materialsDir/regionMaterial);
132  if (isDir(matDir))
133  {
134  Info<< "\tCreating constant/" << regionName
135  << " directory with " << regionMaterial
136  << " material" << endl;
137  cpFiles(constantDir/regionSolver, currentDir/"constant"/regionName);
138  cpFiles(matDir, currentDir/"constant"/regionName);
139 
140  // system/<region>: from fluid or solid template
141  Info<< "\tCreating system/" << regionName
142  << " directory" << endl;
143  cpFiles(systemDir/regionSolver, currentDir/"system"/regionName);
144  }
145  else
146  {
147  FatalIOErrorIn(args.executable().c_str(), materialProperties)
148  << "Cannot find region material folder "
149  << regionMaterial << exit(FatalIOError);
150  }
151  }
152 
153  Info<< "\nWriting regionSolvers\n" << endl;
154  {
155  OFstream regionSolversFile(currentDir/runTime.system()/"regionSolvers");
156  regionSolvers.write(regionSolversFile);
157  }
158 
159  Info<< "End\n" << endl;
160 
161  return 0;
162 }
163 
164 
165 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Output to file stream.
Definition: OFstream.H:86
const word & executable() const
Name of executable without the path.
Definition: argListI.H:36
A keyword and a list of tokens is a 'dictionaryEntry'.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
static const dictionary null
Null dictionary.
Definition: dictionary.H:258
A class for handling file names.
Definition: fileName.H:82
Class to hold the lists of region meshes and solvers.
Definition: regionSolvers.H:82
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:340
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void cpFiles(const fileName &srcDir, const fileName &targetDir)
Copy all the files from the source to the target directory.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
const word & regionName(const solver &region)
Definition: solver.H:209
messageStream Info
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
IOerror FatalIOError
Foam::argList args(argc, argv)