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 std;
39 using namespace Nektar;
40 
41 #if defined(_MSC_VER) && BOOST_VERSION > 104700
42 #include <windows.h>
43 #undef MoveFile
44 #endif
45 
47 void Mvdir(string dir, NekDouble dir_ending);
48 
49 int main(int argc, char *argv[])
50 {
51  try
52  {
53  VortexWaveInteraction vwi(argc,argv);
54 
55  for(int i = 0; i < vwi.GetMaxWaveForceMagIter(); ++i)
56  {
58 
59  NekDouble WaveForce = vwi.GetWaveForceMag();
60 
61  vwi.AppendEvlToFile("ConvergedSolns",WaveForce);
62 
63  vwi.SetWaveForceMag(WaveForce + vwi.GetWaveForceMagStep());
64  vwi.SetPrevAlpha(vwi.GetAlpha());
65  //vwi.SetAlpha(vwi.GetAlpha() + vwi.GetDAlphaDWaveForceMag()*vwi.GetWaveForceMagStep());
66  vwi.SetAlpha(vwi.GetAlpha() + (vwi.GetWaveForceMagStep() > 0?vwi.GetAlphaStep():(-vwi.GetAlphaStep())));
67 
68  // Save data directories.
70  {
71  Mvdir("Save",WaveForce);
72  }
73  else
74  {
75  Mvdir("Save_Outer",WaveForce);
76  // Execute Another loop so that not same initial conditions as last iteration
77  vwi.ExecuteLoop();
78  }
79  }
80  }
81 
82  catch (const std::runtime_error&)
83  {
84  return 1;
85  }
86 
87  catch (const std::string& eStr)
88  {
89  cout << "Error: " << eStr << endl;
90  }
91 }
92 
93 void Mvdir(string dir, NekDouble dir_ending)
94 {
95  // save OuterIter.his if exists
96  string saveOuterIter = "mv -f OuterIter.his "+ dir;
97  if(system(saveOuterIter.c_str()))
98  {
99  ASSERTL0(false,saveOuterIter.c_str());
100  }
101 
102  // Mv directory
103  string newdir = dir + boost::lexical_cast<std::string>(dir_ending);
104  string syscall = "mv -f " + dir + " " + newdir;
105 
106  if(system(syscall.c_str()))
107  {
108  ASSERTL0(false,syscall.c_str());
109  }
110 
111  // make new directory
112  syscall = "mkdir " + dir;
113  system(syscall.c_str());
114 }
115 
117 {
118 
119  // Reset eigenvalue checker in case used in previous iterations
120  vwi.CheckEigIsStationary(true);
121 
122  switch(vwi.GetVWIIterationType())
123  {
124  case eFixedAlpha:
125  {
126  int i;
127  int nouter_iter = vwi.GetNOuterIterations();
128  bool exit_iteration = false;
129 
130  while(exit_iteration == false)
131  {
132  // Reset eigenvalue checker in case used in previous iterations
133  vwi.CheckEigIsStationary(true);
134 
135  for(i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
136  {
137  vwi.ExecuteLoop();
138  vwi.SaveLoopDetails("Save", i);
139  vwi.AppendEvlToFile("conv.his",i);
140 
141  if(vwi.CheckEigIsStationary())
142  {
143  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
144  break;
145  }
146  }
147 
148  // check to see if growth was converged.
149  if(i == vwi.GetIterEnd())
150  {
151  cout << "Failed to converge growth rate in" <<
152  " inner iteration after " << vwi.GetIterEnd()
153  << " loops" << endl;
154  exit(1);
155  }
156 
157  vwi.AppendEvlToFile("OuterIter.his",nouter_iter++);
158  exit_iteration = vwi.CheckIfAtNeutralPoint();
159  if(exit_iteration == false)
160  {
161  vwi.UpdateWaveForceMag(nouter_iter);
162  }
163 
164  if(nouter_iter >= vwi.GetMaxOuterIterations())
165  {
166  cerr << "Failed to converge after "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
167  exit_iteration = true;
168  }
169  }
170 
171  }
172  case eFixedWaveForcing:
173  {
174  int i;
175  int nouter_iter = vwi.GetNOuterIterations();
176  bool exit_iteration = false;
177  NekDouble saveEigRelTol = vwi.GetEigRelTol();
178  int saveMinIters = vwi.GetMinInnerIterations();
179  int init_search = 0;
180 
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);
187  vwi.SetMinInnerIterations(2);
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 "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
245  exit_iteration = true;
246  }
247  }
248 
250 
251  }
252  break;
254 
255  for(int i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
256  {
257  vwi.ExecuteLoop();
258  vwi.SaveLoopDetails("Save",i);
259  vwi.AppendEvlToFile("conv.his",i);
260  }
261  break;
263  {
264  int i;
265  int nouter_iter = vwi.GetNOuterIterations();
266  bool exit_iteration = false;
267 
268  while(exit_iteration == false)
269  {
270  bool exit_alphaIter = false;
271 
272  vwi.ExecuteLoop(false);
273 
274  // Sub iterate Alpha
275  for(i = 0; i < vwi.GetIterEnd(); ++i)
276  {
277  vwi.SaveLoopDetails("Save", i);
278 
279  vwi.AppendEvlToFile("AlphaIter.his",i);
280 
281  exit_alphaIter = vwi.CheckIfAtNeutralPoint();
282  if(exit_alphaIter == false)
283  {
284  vwi.UpdateAlpha(i+1);
285  vwi.ExecuteWave();
286  }
287  else
288  {
290  break;
291  }
292  }
293 
294  // check to see if growth was converged.
295  if(i == vwi.GetIterEnd())
296  {
297  cout << "Failed to converge growth rate in" <<
298  " inner iteration after " << vwi.GetIterEnd()
299  << " loops" << endl;
300  exit(1);
301  }
302 
303  vwi.MoveFile("AlphaIter.his","Save_Outer", nouter_iter);
304  vwi.SaveLoopDetails("Save_Outer", nouter_iter);
305  vwi.AppendEvlToFile("OuterIter.his",nouter_iter++);
306 
307  // assume that if only previous inner loop has
308  // only done one iteration then we are at neutral
309  // point
310  if (i == 0 && vwi.IfIterInterface()==false)
311  {
312  exit_iteration = true;
313  }
314 
315 
316  if(nouter_iter >= vwi.GetMaxOuterIterations())
317  {
318  cerr << "Failed to converge after "<< vwi.GetMaxOuterIterations() << " outer iterations" << endl;
319  exit_iteration = true;
320  }
321  }
322  }
323  break;
324  default:
325  ASSERTL0(false,"Unknown iteration type");
326  }
327 
328 }
329 
330 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void ExecuteLoop(bool CalcWaveForce=true)
STL namespace.
bool CheckEigIsStationary(bool reset=false)
VWIIterationType GetVWIIterationType(void)
void UpdateDAlphaDWaveForceMag(NekDouble alphainit)
void MoveFile(std::string fileend, std::string dir, int n)
void DoFixedForcingIteration(VortexWaveInteraction &vwi)
void SaveLoopDetails(std::string dir, int i)
double NekDouble
int main(int argc, char *argv[])
void Mvdir(string dir, NekDouble dir_ending)
void AppendEvlToFile(std::string file, int n)