Nektar++
VortexWaveInteractionSolver.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: VortexWaveInteractionSolver.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Vortex Wave Interaction solver
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37using namespace std;
38using namespace Nektar;
39
41void Mvdir(string dir, NekDouble dir_ending);
42
43int main(int argc, char *argv[])
44{
45 try
46 {
47 VortexWaveInteraction vwi(argc, argv);
48
49 for (int i = 0; i < vwi.GetMaxWaveForceMagIter(); ++i)
50 {
52
53 NekDouble WaveForce = vwi.GetWaveForceMag();
54
55 vwi.AppendEvlToFile("ConvergedSolns", WaveForce);
56
57 vwi.SetWaveForceMag(WaveForce + vwi.GetWaveForceMagStep());
58 vwi.SetPrevAlpha(vwi.GetAlpha());
59 // vwi.SetAlpha(vwi.GetAlpha() +
60 // vwi.GetDAlphaDWaveForceMag()*vwi.GetWaveForceMagStep());
61 vwi.SetAlpha(vwi.GetAlpha() + (vwi.GetWaveForceMagStep() > 0
62 ? vwi.GetAlphaStep()
63 : (-vwi.GetAlphaStep())));
64
65 // Save data directories.
67 {
68 Mvdir("Save", WaveForce);
69 }
70 else
71 {
72 Mvdir("Save_Outer", WaveForce);
73 // Execute Another loop so that not same initial conditions as
74 // last iteration
75 vwi.ExecuteLoop();
76 }
77 }
78 }
79
80 catch (const std::runtime_error &)
81 {
82 return 1;
83 }
84
85 catch (const std::string &eStr)
86 {
87 cout << "Error: " << eStr << endl;
88 }
89}
90
91void Mvdir(string dir, NekDouble dir_ending)
92{
93 // save OuterIter.his if exists
94 string saveOuterIter = "mv -f OuterIter.his " + dir;
95 if (system(saveOuterIter.c_str()))
96 {
97 ASSERTL0(false, saveOuterIter.c_str());
98 }
99
100 // Mv directory
101 string newdir = dir + boost::lexical_cast<std::string>(dir_ending);
102 string syscall = "mv -f " + dir + " " + newdir;
103
104 if (system(syscall.c_str()))
105 {
106 ASSERTL0(false, syscall.c_str());
107 }
108
109 // make new directory
110 syscall = "mkdir " + dir;
111 ASSERTL0(system(syscall.c_str()) == 0,
112 "Failed to make directory '" + dir + "'");
113}
114
116{
117
118 // Reset eigenvalue checker in case used in previous iterations
119 vwi.CheckEigIsStationary(true);
120
121 switch (vwi.GetVWIIterationType())
122 {
123 case eFixedAlpha:
124 {
125 int i;
126 int nouter_iter = vwi.GetNOuterIterations();
127 bool exit_iteration = false;
128
129 while (exit_iteration == false)
130 {
131 // Reset eigenvalue checker in case used in previous iterations
132 vwi.CheckEigIsStationary(true);
133
134 for (i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
135 {
136 vwi.ExecuteLoop();
137 vwi.SaveLoopDetails("Save", i);
138 vwi.AppendEvlToFile("conv.his", i);
139
140 if (vwi.CheckEigIsStationary())
141 {
142 vwi.SaveLoopDetails("Save_Outer", nouter_iter);
143 break;
144 }
145 }
146
147 // check to see if growth was converged.
148 if (i == vwi.GetIterEnd())
149 {
150 cout << "Failed to converge growth rate in"
151 << " inner iteration after " << vwi.GetIterEnd()
152 << " loops" << endl;
153 exit(1);
154 }
155
156 vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
157 exit_iteration = vwi.CheckIfAtNeutralPoint();
158 if (exit_iteration == false)
159 {
160 vwi.UpdateWaveForceMag(nouter_iter);
161 }
162
163 if (nouter_iter >= vwi.GetMaxOuterIterations())
164 {
165 cerr << "Failed to converge after "
166 << vwi.GetMaxOuterIterations() << " outer iterations"
167 << endl;
168 exit_iteration = true;
169 }
170 }
171 }
172 break;
174 {
175 int i;
176 int nouter_iter = vwi.GetNOuterIterations();
177 bool exit_iteration = false;
178 NekDouble saveEigRelTol = vwi.GetEigRelTol();
179 int saveMinIters = vwi.GetMinInnerIterations();
180 int init_search = 0;
181
182 if (init_search)
183 {
184 // initial set m_eigelTol to 1e-1 and inner iterations to 1 for
185 // quick search
186 vwi.SetEigRelTol(1e-1);
188 }
189
190 while (exit_iteration == false)
191 {
192 // Reset eigenvalue checker in case used in previous iterations
193 vwi.CheckEigIsStationary(true);
194
195 for (i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
196 {
197 vwi.ExecuteLoop();
198 vwi.SaveLoopDetails("Save", i);
199 vwi.AppendEvlToFile("conv.his", i);
200
201 if (vwi.CheckEigIsStationary())
202 {
203 vwi.SaveLoopDetails("Save_Outer", nouter_iter);
204 break;
205 }
206 }
207
208 // check to see if growth was converged.
209 if (i == vwi.GetIterEnd())
210 {
211 cout << "Failed to converge growth rate in"
212 << " inner iteration after " << vwi.GetIterEnd()
213 << " loops" << endl;
214 exit(1);
215 }
216
217 vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
218
219 exit_iteration = vwi.CheckIfAtNeutralPoint();
220
221 cout << "m_alpha[0] is " << vwi.GetAlpha() << endl;
222
223 if (exit_iteration == false)
224 {
225 vwi.UpdateAlpha(nouter_iter);
226 if (vwi.IfIterInterface() == true)
227 {
229 }
230 }
231
232 // Redo iteration if at first coarse search
233 if ((exit_iteration == true) && (init_search == 1))
234 {
235 init_search = 0;
236 vwi.SetEigRelTol(saveEigRelTol);
237 vwi.SetMinInnerIterations(saveMinIters);
238 nouter_iter = 1;
239 exit_iteration = false;
240 }
241
242 if (nouter_iter >= vwi.GetMaxOuterIterations())
243 {
244 cerr << "Failed to converge after "
245 << vwi.GetMaxOuterIterations() << " outer iterations"
246 << endl;
247 exit_iteration = true;
248 }
249 }
250
252 }
253 break;
255
256 for (int i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
257 {
258 vwi.ExecuteLoop();
259 vwi.SaveLoopDetails("Save", i);
260 vwi.AppendEvlToFile("conv.his", i);
261 }
262 break;
264 {
265 int i;
266 int nouter_iter = vwi.GetNOuterIterations();
267 bool exit_iteration = false;
268
269 while (exit_iteration == false)
270 {
271 bool exit_alphaIter = false;
272
273 vwi.ExecuteLoop(false);
274
275 // Sub iterate Alpha
276 for (i = 0; i < vwi.GetIterEnd(); ++i)
277 {
278 vwi.SaveLoopDetails("Save", i);
279
280 vwi.AppendEvlToFile("AlphaIter.his", i);
281
282 exit_alphaIter = vwi.CheckIfAtNeutralPoint();
283 if (exit_alphaIter == false)
284 {
285 vwi.UpdateAlpha(i + 1);
286 vwi.ExecuteWave();
287 }
288 else
289 {
291 break;
292 }
293 }
294
295 // check to see if growth was converged.
296 if (i == vwi.GetIterEnd())
297 {
298 cout << "Failed to converge growth rate in"
299 << " inner iteration after " << vwi.GetIterEnd()
300 << " loops" << endl;
301 exit(1);
302 }
303
304 vwi.MoveFile("AlphaIter.his", "Save_Outer", nouter_iter);
305 vwi.SaveLoopDetails("Save_Outer", nouter_iter);
306 vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
307
308 // assume that if only previous inner loop has
309 // only done one iteration then we are at neutral
310 // point
311 if (i == 0 && vwi.IfIterInterface() == false)
312 {
313 exit_iteration = true;
314 }
315
316 if (nouter_iter >= vwi.GetMaxOuterIterations())
317 {
318 cerr << "Failed to converge after "
319 << vwi.GetMaxOuterIterations() << " outer iterations"
320 << endl;
321 exit_iteration = true;
322 }
323 }
324 }
325 break;
326 default:
327 ASSERTL0(false, "Unknown iteration type");
328 }
329}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
int main(int argc, char *argv[])
void Mvdir(string dir, NekDouble dir_ending)
void DoFixedForcingIteration(VortexWaveInteraction &vwi)
bool CheckEigIsStationary(bool reset=false)
void SaveLoopDetails(std::string dir, int i)
void ExecuteLoop(bool CalcWaveForce=true)
void MoveFile(std::string fileend, std::string dir, int n)
void AppendEvlToFile(std::string file, int n)
void UpdateDAlphaDWaveForceMag(NekDouble alphainit)
VWIIterationType GetVWIIterationType(void)
@ eFixedWaveForcingWithSubIterationOnAlpha
double NekDouble