Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Vortex Wave Interaction solver
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace Nektar;
39 
40 #if defined(_MSC_VER) && BOOST_VERSION > 104700
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() + vwi.GetDAlphaDWaveForceMag()*vwi.GetWaveForceMagStep());
65  vwi.SetAlpha(vwi.GetAlpha() + (vwi.GetWaveForceMagStep() > 0?vwi.GetAlphaStep():(-vwi.GetAlphaStep())));
66 
67  // Save data directories.
69  {
70  Mvdir("Save",WaveForce);
71  }
72  else
73  {
74  Mvdir("Save_Outer",WaveForce);
75  // Execute Another loop so that not same initial conditions as last iteration
76  vwi.ExecuteLoop();
77  }
78  }
79  }
80 
81  catch (const std::runtime_error&)
82  {
83  return 1;
84  }
85 
86  catch (const std::string& eStr)
87  {
88  cout << "Error: " << eStr << endl;
89  }
90 }
91 
92 void Mvdir(string dir, NekDouble dir_ending)
93 {
94  // save OuterIter.his if exists
95  string saveOuterIter = "mv -f OuterIter.his "+ dir;
96  if(system(saveOuterIter.c_str()))
97  {
98  ASSERTL0(false,saveOuterIter.c_str());
99  }
100 
101  // Mv directory
102  string newdir = dir + boost::lexical_cast<std::string>(dir_ending);
103  string syscall = "mv -f " + dir + " " + newdir;
104 
105  if(system(syscall.c_str()))
106  {
107  ASSERTL0(false,syscall.c_str());
108  }
109 
110  // make new directory
111  syscall = "mkdir " + dir;
112  system(syscall.c_str());
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 "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
166  exit_iteration = true;
167  }
168  }
169 
170  }
171  case eFixedWaveForcing:
172  {
173  int i;
174  int nouter_iter = vwi.GetNOuterIterations();
175  bool exit_iteration = false;
176  NekDouble saveEigRelTol = vwi.GetEigRelTol();
177  int saveMinIters = vwi.GetMinInnerIterations();
178  int init_search = 0;
179 
180 
181  if(init_search)
182  {
183  // initial set m_eigelTol to 1e-1 and inner iterations to 1 for
184  // quick search
185  vwi.SetEigRelTol(1e-1);
186  vwi.SetMinInnerIterations(2);
187  }
188 
189  while(exit_iteration == false)
190  {
191  // Reset eigenvalue checker in case used in previous iterations
192  vwi.CheckEigIsStationary(true);
193 
194  for(i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
195  {
196  vwi.ExecuteLoop();
197  vwi.SaveLoopDetails("Save", i);
198  vwi.AppendEvlToFile("conv.his",i);
199 
200  if(vwi.CheckEigIsStationary())
201  {
202  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
203  break;
204  }
205  }
206 
207  // check to see if growth was converged.
208  if(i == vwi.GetIterEnd() )
209  {
210  cout << "Failed to converge growth rate in" <<
211  " inner iteration after " << vwi.GetIterEnd()
212  << " loops" << endl;
213  exit(1);
214  }
215 
216  vwi.AppendEvlToFile("OuterIter.his",nouter_iter++);
217 
218  exit_iteration = vwi.CheckIfAtNeutralPoint();
219 
220  cout << "m_alpha[0] is " << vwi.GetAlpha() << endl;
221 
222  if(exit_iteration == false)
223  {
224  vwi.UpdateAlpha(nouter_iter);
225  if(vwi.IfIterInterface()==true)
226  {
228  }
229  }
230 
231  // Redo iteration if at first coarse search
232  if((exit_iteration == true) && (init_search == 1))
233  {
234  init_search = 0;
235  vwi.SetEigRelTol(saveEigRelTol);
236  vwi.SetMinInnerIterations(saveMinIters);
237  nouter_iter = 1;
238  exit_iteration = false;
239  }
240 
241  if(nouter_iter >= vwi.GetMaxOuterIterations())
242  {
243  cerr << "Failed to converge after "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
244  exit_iteration = true;
245  }
246  }
247 
249 
250  }
251  break;
253 
254  for(int i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
255  {
256  vwi.ExecuteLoop();
257  vwi.SaveLoopDetails("Save",i);
258  vwi.AppendEvlToFile("conv.his",i);
259  }
260  break;
262  {
263  int i;
264  int nouter_iter = vwi.GetNOuterIterations();
265  bool exit_iteration = false;
266 
267  while(exit_iteration == false)
268  {
269  bool exit_alphaIter = false;
270 
271  vwi.ExecuteLoop(false);
272 
273  // Sub iterate Alpha
274  for(i = 0; i < vwi.GetIterEnd(); ++i)
275  {
276  vwi.SaveLoopDetails("Save", i);
277 
278  vwi.AppendEvlToFile("AlphaIter.his",i);
279 
280  exit_alphaIter = vwi.CheckIfAtNeutralPoint();
281  if(exit_alphaIter == false)
282  {
283  vwi.UpdateAlpha(i+1);
284  vwi.ExecuteWave();
285  }
286  else
287  {
289  break;
290  }
291  }
292 
293  // check to see if growth was converged.
294  if(i == vwi.GetIterEnd())
295  {
296  cout << "Failed to converge growth rate in" <<
297  " inner iteration after " << vwi.GetIterEnd()
298  << " loops" << endl;
299  exit(1);
300  }
301 
302  vwi.MoveFile("AlphaIter.his","Save_Outer", nouter_iter);
303  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
304  vwi.AppendEvlToFile("OuterIter.his",nouter_iter++);
305 
306  // assume that if only previous inner loop has
307  // only done one iteration then we are at neutral
308  // point
309  if (i == 0 && vwi.IfIterInterface()==false)
310  {
311  exit_iteration = true;
312  }
313 
314 
315  if(nouter_iter >= vwi.GetMaxOuterIterations())
316  {
317  cerr << "Failed to converge after "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
318  exit_iteration = true;
319  }
320  }
321  }
322  break;
323  default:
324  ASSERTL0(false,"Unknown iteration type");
325  }
326 
327 }
328 
329 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void MoveFile(string fileend, string dir, int n)
void ExecuteLoop(bool CalcWaveForce=true)
bool CheckEigIsStationary(bool reset=false)
VWIIterationType GetVWIIterationType(void)
void UpdateDAlphaDWaveForceMag(NekDouble alphainit)
void DoFixedForcingIteration(VortexWaveInteraction &vwi)
double NekDouble
int main(int argc, char *argv[])
void SaveLoopDetails(string dir, int i)
void Mvdir(string dir, NekDouble dir_ending)
void AppendEvlToFile(std::string file, int n)