Nektar++
Functions
VortexWaveInteractionSolver.cpp File Reference
#include <VortexWaveInteraction/VortexWaveInteraction.h>

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

◆ DoFixedForcingIteration()

void DoFixedForcingIteration ( VortexWaveInteraction vwi)

Definition at line 120 of file VortexWaveInteractionSolver.cpp.

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;
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);
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
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)
@ eFixedWaveForcingWithSubIterationOnAlpha
double NekDouble

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().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 48 of file VortexWaveInteractionSolver.cpp.

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

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().

◆ Mvdir()

void Mvdir ( string  dir,
NekDouble  dir_ending 
)

Definition at line 96 of file VortexWaveInteractionSolver.cpp.

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}

References ASSERTL0.

Referenced by main().