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 
37 using namespace std;
38 using namespace Nektar;
39 
40 #if defined(_MSC_VER)
41 #include <windows.h>
42 #undef MoveFile
43 #endif
44 
46 void Mvdir(string dir, NekDouble dir_ending);
47 
48 int main(int argc, char *argv[])
49 {
50  try
51  {
52  VortexWaveInteraction vwi(argc, argv);
53 
54  for (int i = 0; i < vwi.GetMaxWaveForceMagIter(); ++i)
55  {
57 
58  NekDouble WaveForce = vwi.GetWaveForceMag();
59 
60  vwi.AppendEvlToFile("ConvergedSolns", WaveForce);
61 
62  vwi.SetWaveForceMag(WaveForce + vwi.GetWaveForceMagStep());
63  vwi.SetPrevAlpha(vwi.GetAlpha());
64  // vwi.SetAlpha(vwi.GetAlpha() +
65  // vwi.GetDAlphaDWaveForceMag()*vwi.GetWaveForceMagStep());
66  vwi.SetAlpha(vwi.GetAlpha() + (vwi.GetWaveForceMagStep() > 0
67  ? vwi.GetAlphaStep()
68  : (-vwi.GetAlphaStep())));
69 
70  // Save data directories.
72  {
73  Mvdir("Save", WaveForce);
74  }
75  else
76  {
77  Mvdir("Save_Outer", WaveForce);
78  // Execute Another loop so that not same initial conditions as
79  // last iteration
80  vwi.ExecuteLoop();
81  }
82  }
83  }
84 
85  catch (const std::runtime_error &)
86  {
87  return 1;
88  }
89 
90  catch (const std::string &eStr)
91  {
92  cout << "Error: " << eStr << endl;
93  }
94 }
95 
96 void Mvdir(string dir, NekDouble dir_ending)
97 {
98  // save OuterIter.his if exists
99  string saveOuterIter = "mv -f OuterIter.his " + dir;
100  if (system(saveOuterIter.c_str()))
101  {
102  ASSERTL0(false, saveOuterIter.c_str());
103  }
104 
105  // Mv directory
106  string newdir = dir + boost::lexical_cast<std::string>(dir_ending);
107  string syscall = "mv -f " + dir + " " + newdir;
108 
109  if (system(syscall.c_str()))
110  {
111  ASSERTL0(false, syscall.c_str());
112  }
113 
114  // make new directory
115  syscall = "mkdir " + dir;
116  ASSERTL0(system(syscall.c_str()) == 0,
117  "Failed to make directory '" + dir + "'");
118 }
119 
121 {
122 
123  // Reset eigenvalue checker in case used in previous iterations
124  vwi.CheckEigIsStationary(true);
125 
126  switch (vwi.GetVWIIterationType())
127  {
128  case eFixedAlpha:
129  {
130  int i;
131  int nouter_iter = vwi.GetNOuterIterations();
132  bool exit_iteration = false;
133 
134  while (exit_iteration == false)
135  {
136  // Reset eigenvalue checker in case used in previous iterations
137  vwi.CheckEigIsStationary(true);
138 
139  for (i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
140  {
141  vwi.ExecuteLoop();
142  vwi.SaveLoopDetails("Save", i);
143  vwi.AppendEvlToFile("conv.his", i);
144 
145  if (vwi.CheckEigIsStationary())
146  {
147  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
148  break;
149  }
150  }
151 
152  // check to see if growth was converged.
153  if (i == vwi.GetIterEnd())
154  {
155  cout << "Failed to converge growth rate in"
156  << " inner iteration after " << vwi.GetIterEnd()
157  << " loops" << endl;
158  exit(1);
159  }
160 
161  vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
162  exit_iteration = vwi.CheckIfAtNeutralPoint();
163  if (exit_iteration == false)
164  {
165  vwi.UpdateWaveForceMag(nouter_iter);
166  }
167 
168  if (nouter_iter >= vwi.GetMaxOuterIterations())
169  {
170  cerr << "Failed to converge after "
171  << vwi.GetMaxOuterIterations() << " outer iterations"
172  << endl;
173  exit_iteration = true;
174  }
175  }
176  }
177  break;
178  case eFixedWaveForcing:
179  {
180  int i;
181  int nouter_iter = vwi.GetNOuterIterations();
182  bool exit_iteration = false;
183  NekDouble saveEigRelTol = vwi.GetEigRelTol();
184  int saveMinIters = vwi.GetMinInnerIterations();
185  int init_search = 0;
186 
187  if (init_search)
188  {
189  // initial set m_eigelTol to 1e-1 and inner iterations to 1 for
190  // quick search
191  vwi.SetEigRelTol(1e-1);
192  vwi.SetMinInnerIterations(2);
193  }
194 
195  while (exit_iteration == false)
196  {
197  // Reset eigenvalue checker in case used in previous iterations
198  vwi.CheckEigIsStationary(true);
199 
200  for (i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
201  {
202  vwi.ExecuteLoop();
203  vwi.SaveLoopDetails("Save", i);
204  vwi.AppendEvlToFile("conv.his", i);
205 
206  if (vwi.CheckEigIsStationary())
207  {
208  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
209  break;
210  }
211  }
212 
213  // check to see if growth was converged.
214  if (i == vwi.GetIterEnd())
215  {
216  cout << "Failed to converge growth rate in"
217  << " inner iteration after " << vwi.GetIterEnd()
218  << " loops" << endl;
219  exit(1);
220  }
221 
222  vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
223 
224  exit_iteration = vwi.CheckIfAtNeutralPoint();
225 
226  cout << "m_alpha[0] is " << vwi.GetAlpha() << endl;
227 
228  if (exit_iteration == false)
229  {
230  vwi.UpdateAlpha(nouter_iter);
231  if (vwi.IfIterInterface() == true)
232  {
234  }
235  }
236 
237  // Redo iteration if at first coarse search
238  if ((exit_iteration == true) && (init_search == 1))
239  {
240  init_search = 0;
241  vwi.SetEigRelTol(saveEigRelTol);
242  vwi.SetMinInnerIterations(saveMinIters);
243  nouter_iter = 1;
244  exit_iteration = false;
245  }
246 
247  if (nouter_iter >= vwi.GetMaxOuterIterations())
248  {
249  cerr << "Failed to converge after "
250  << vwi.GetMaxOuterIterations() << " outer iterations"
251  << endl;
252  exit_iteration = true;
253  }
254  }
255 
257  }
258  break;
260 
261  for (int i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
262  {
263  vwi.ExecuteLoop();
264  vwi.SaveLoopDetails("Save", i);
265  vwi.AppendEvlToFile("conv.his", i);
266  }
267  break;
269  {
270  int i;
271  int nouter_iter = vwi.GetNOuterIterations();
272  bool exit_iteration = false;
273 
274  while (exit_iteration == false)
275  {
276  bool exit_alphaIter = false;
277 
278  vwi.ExecuteLoop(false);
279 
280  // Sub iterate Alpha
281  for (i = 0; i < vwi.GetIterEnd(); ++i)
282  {
283  vwi.SaveLoopDetails("Save", i);
284 
285  vwi.AppendEvlToFile("AlphaIter.his", i);
286 
287  exit_alphaIter = vwi.CheckIfAtNeutralPoint();
288  if (exit_alphaIter == false)
289  {
290  vwi.UpdateAlpha(i + 1);
291  vwi.ExecuteWave();
292  }
293  else
294  {
296  break;
297  }
298  }
299 
300  // check to see if growth was converged.
301  if (i == vwi.GetIterEnd())
302  {
303  cout << "Failed to converge growth rate in"
304  << " inner iteration after " << vwi.GetIterEnd()
305  << " loops" << endl;
306  exit(1);
307  }
308 
309  vwi.MoveFile("AlphaIter.his", "Save_Outer", nouter_iter);
310  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
311  vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
312 
313  // assume that if only previous inner loop has
314  // only done one iteration then we are at neutral
315  // point
316  if (i == 0 && vwi.IfIterInterface() == false)
317  {
318  exit_iteration = true;
319  }
320 
321  if (nouter_iter >= vwi.GetMaxOuterIterations())
322  {
323  cerr << "Failed to converge after "
324  << vwi.GetMaxOuterIterations() << " outer iterations"
325  << endl;
326  exit_iteration = true;
327  }
328  }
329  }
330  break;
331  default:
332  ASSERTL0(false, "Unknown iteration type");
333  }
334 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
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)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
@ eFixedWaveForcingWithSubIterationOnAlpha
double NekDouble