Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 116 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().

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 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void ExecuteLoop(bool CalcWaveForce=true)
bool CheckEigIsStationary(bool reset=false)
VWIIterationType GetVWIIterationType(void)
void UpdateDAlphaDWaveForceMag(NekDouble alphainit)
void MoveFile(std::string fileend, std::string dir, int n)
void SaveLoopDetails(std::string dir, int i)
double NekDouble
void AppendEvlToFile(std::string file, int n)
int main ( int  argc,
char *  argv[] 
)

Definition at line 49 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().

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

Definition at line 93 of file VortexWaveInteractionSolver.cpp.

References ASSERTL0.

Referenced by main().

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