Nektar++
Functions
VortexWaveInteractionSolver.cpp File Reference
#include <VortexWaveInteraction/VortexWaveInteraction.h>
Include dependency graph for VortexWaveInteractionSolver.cpp:

Go to the source code of this file.

Functions

void DoFixedForcingIteration (VortexWaveInteraction &vwi)
 
void Mvdir (string dir, NekDouble dir_ending)
 
int main (int argc, char *argv[])
 

Function Documentation

void DoFixedForcingIteration ( VortexWaveInteraction vwi)

Definition at line 115 of file VortexWaveInteractionSolver.cpp.

References Nektar::VortexWaveInteraction::AppendEvlToFile(), ASSERTL0, Nektar::VortexWaveInteraction::CalcNonLinearWaveForce(), Nektar::VortexWaveInteraction::CheckEigIsStationary(), Nektar::VortexWaveInteraction::CheckIfAtNeutralPoint(), Nektar::eFixedAlpha, Nektar::eFixedAlphaWaveForcing, Nektar::eFixedWaveForcing, Nektar::eFixedWaveForcingWithSubIterationOnAlpha, Nektar::VortexWaveInteraction::ExecuteLoop(), Nektar::VortexWaveInteraction::ExecuteWave(), Nektar::VortexWaveInteraction::GetAlpha(), Nektar::VortexWaveInteraction::GetEigRelTol(), Nektar::VortexWaveInteraction::GetIterEnd(), Nektar::VortexWaveInteraction::GetIterStart(), Nektar::VortexWaveInteraction::GetMaxOuterIterations(), Nektar::VortexWaveInteraction::GetMinInnerIterations(), Nektar::VortexWaveInteraction::GetNOuterIterations(), Nektar::VortexWaveInteraction::GetPrevAlpha(), Nektar::VortexWaveInteraction::GetVWIIterationType(), Nektar::VortexWaveInteraction::IfIterInterface(), Nektar::VortexWaveInteraction::MoveFile(), Nektar::VortexWaveInteraction::SaveLoopDetails(), Nektar::VortexWaveInteraction::SetEigRelTol(), Nektar::VortexWaveInteraction::SetMinInnerIterations(), Nektar::VortexWaveInteraction::UpdateAlpha(), Nektar::VortexWaveInteraction::UpdateDAlphaDWaveForceMag(), and Nektar::VortexWaveInteraction::UpdateWaveForceMag().

Referenced by main().

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 }
#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)
double NekDouble
void SaveLoopDetails(string dir, int i)
void AppendEvlToFile(std::string file, int n)
int main ( int  argc,
char *  argv[] 
)

Definition at line 48 of file VortexWaveInteractionSolver.cpp.

References Nektar::VortexWaveInteraction::AppendEvlToFile(), DoFixedForcingIteration(), Nektar::eFixedAlphaWaveForcing, Nektar::VortexWaveInteraction::ExecuteLoop(), Nektar::VortexWaveInteraction::GetAlpha(), Nektar::VortexWaveInteraction::GetAlphaStep(), Nektar::VortexWaveInteraction::GetMaxWaveForceMagIter(), Nektar::VortexWaveInteraction::GetVWIIterationType(), Nektar::VortexWaveInteraction::GetWaveForceMag(), Nektar::VortexWaveInteraction::GetWaveForceMagStep(), Mvdir(), Nektar::VortexWaveInteraction::SetAlpha(), Nektar::VortexWaveInteraction::SetPrevAlpha(), and Nektar::VortexWaveInteraction::SetWaveForceMag().

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.
68  if(vwi.GetVWIIterationType() == eFixedAlphaWaveForcing)
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 }
void DoFixedForcingIteration(VortexWaveInteraction &vwi)
double NekDouble
void Mvdir(string dir, NekDouble dir_ending)
void Mvdir ( string  dir,
NekDouble  dir_ending 
)

Definition at line 92 of file VortexWaveInteractionSolver.cpp.

References ASSERTL0.

Referenced by main().

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 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161