Loading...
Searching...
No Matches
ITHACAsystem.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8
9 * In real Time Highly Advanced Computational Applications for Finite Volumes
10 * Copyright (C) 2017 by the ITHACA-FV authors
11-------------------------------------------------------------------------------
12License
13 This file is part of ITHACA-FV
14 ITHACA-FV is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18 ITHACA-FV is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
24\*---------------------------------------------------------------------------*/
25#include "ITHACAsystem.H"
26
27namespace ITHACAutilities
28{
29
30void createSymLink(word folder)
31{
32 if (!Pstream::parRun())
33 {
34 mkDir(folder);
35 word command1("ln -s $(readlink -f constant/) " + folder + "/" +
36 " >/dev/null 2>&1");
37 word command2("ln -s $(readlink -f system/) " + folder + "/" +
38 " >/dev/null 2>&1");
39 word command3("ln -s $(readlink -f 0/) " + folder + "/" + " >/dev/null 2>&1");
40 std::cout.setstate(std::ios_base::failbit);
41 system(command1);
42 system(command2);
43 system(command3);
44 std::cout.clear();
45 }
46 else
47 {
48 // Serial Part
49 mkDir(folder);
50 word command1s("ln -s $(readlink -f constant/) " + folder + "/" +
51 " >/dev/null 2>&1");
52 word command2s("ln -s $(readlink -f system/) " + folder + "/" +
53 " >/dev/null 2>&1");
54 word command3s("ln -s $(readlink -f 0/) " + folder + "/" + " >/dev/null 2>&1");
55 std::cout.setstate(std::ios_base::failbit);
56 system(command1s);
57 system(command2s);
58 system(command3s);
59 std::cout.clear();
60 // Parallel Part
61 mkDir(folder + "/processor" + name(Pstream::myProcNo()));
62 word command1("ln -s $(readlink -f processor" + name(Pstream::myProcNo()) +
63 "/constant/) " + folder + "/processor" +
64 name(Pstream::myProcNo()) + "/ >/dev/null 2>&1");
65 word command2("ln -s $(readlink -f system/) " + folder + "/processor" +
66 name(Pstream::myProcNo()) + "/ >/dev/null 2>&1");
67 word command3("ln -s $(readlink -f processor" + name(Pstream::myProcNo()) +
68 "/0/) " + folder + "/processor" +
69 name(Pstream::myProcNo()) + "/ >/dev/null 2>&1");
70 std::cout.setstate(std::ios_base::failbit);
71 system(command1);
72 system(command2);
73 system(command3);
74 std::cout.clear();
75 }
76}
77
78void createSymLink(word linkFolder, word destFolder)
79{
80 if (!check_folder(destFolder))
81 {
82 mkDir(destFolder);
83 }
84
85 system("ln -s $(readlink -f " + linkFolder + ") " + destFolder +
86 " >/dev/null 2>&1");
87}
88
89bool check_folder(word folder)
90{
91 struct stat sb;
92 bool exist;
93
94 if (stat(folder.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))
95 {
96 exist = true;
97 }
98 else
99 {
100 exist = false;
101 }
102
103 return exist;
104}
105
106// Check if the offline data exist
108{
109 bool off_exist = 0;
110
111 if (Pstream::master())
112 {
113 if (check_folder("./ITHACAoutput/Offline"))
114 {
115 off_exist = true;
116 Info << "Offline data already exist, reading existing data" << endl;
117 }
118 else
119 {
120 off_exist = false;
121 Info << "Offline don't exist, performing the Offline Solve" << endl;
122 mkDir("./ITHACAoutput/Offline");
123 }
124 }
125
126 reduce(off_exist, sumOp<label>());
127
128 if (!off_exist)
129 {
130 createSymLink("./ITHACAoutput/Offline");
131 }
132
133 return off_exist;
134}
135
136bool check_file(std::string fileName)
137{
138 std::ifstream infile(fileName);
139 return infile.good();
140}
141
142// Check if the modes exists
144{
145 bool pod_exist = 0;
146
147 if (Pstream::master())
148 {
149 if (check_folder("./ITHACAoutput/POD"))
150 {
151 pod_exist = true;
152 Info << "POD data already exist, reading existing modes" << endl;
153 }
154 else if (!Pstream::parRun())
155 {
156 pod_exist = false;
157 Info << "POD don't exist, performing a POD decomposition" << endl;
158 mkDir("./ITHACAoutput/POD");
159 }
160 }
161
162 reduce(pod_exist, sumOp<label>());
163
164 if (!pod_exist)
165 {
166 createSymLink("./ITHACAoutput/POD");
167 }
168
169 return pod_exist;
170}
171
172// Check if the supremizer data exist
174{
175 bool sup_exist = 0;
176
177 if (Pstream::master())
178 {
179 if (check_folder("./ITHACAoutput/supremizer"))
180 {
181 sup_exist = true;
182 Info << "Supremizer data already exist, reading existing data" << endl;
183 }
184 else
185 {
186 sup_exist = false;
187 Info << "Supremizers don't exist, performing a POD decomposition" << endl;
188 mkDir("./ITHACAoutput/supremizer");
189 }
190 }
191
192 reduce(sup_exist, sumOp<label>());
193
194 if (!sup_exist)
195 {
196 createSymLink("./ITHACAoutput/supremizer");
197 }
198
199 return sup_exist;
200}
201
202
203}
Header file of the ITHACAsystem file.
Namespace to implement some useful assign operation of OF fields.
bool check_pod()
Check if the POD data folder "./ITHACAoutput/POD" exists.
bool check_off()
Check if the offline data folder "./ITHACAoutput/Offline" exists.
bool check_folder(word folder)
Checks if a folder exists.
bool check_file(std::string fileName)
Function that returns true if a file exists.
bool check_sup()
Check if the supremizer folder exists.
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.