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 115 of file VortexWaveInteractionSolver.cpp.

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 "
166 << vwi.GetMaxOuterIterations() << " outer iterations"
167 << endl;
168 exit_iteration = true;
169 }
170 }
171 }
172 break;
174 {
175 int i;
176 int nouter_iter = vwi.GetNOuterIterations();
177 bool exit_iteration = false;
178 NekDouble saveEigRelTol = vwi.GetEigRelTol();
179 int saveMinIters = vwi.GetMinInnerIterations();
180 int init_search = 0;
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);
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 "
245 << vwi.GetMaxOuterIterations() << " outer iterations"
246 << endl;
247 exit_iteration = true;
248 }
249 }
250
252 }
253 break;
255
256 for (int i = vwi.GetIterStart(); i < vwi.GetIterEnd(); ++i)
257 {
258 vwi.ExecuteLoop();
259 vwi.SaveLoopDetails("Save", i);
260 vwi.AppendEvlToFile("conv.his", i);
261 }
262 break;
264 {
265 int i;
266 int nouter_iter = vwi.GetNOuterIterations();
267 bool exit_iteration = false;
268
269 while (exit_iteration == false)
270 {
271 bool exit_alphaIter = false;
272
273 vwi.ExecuteLoop(false);
274
275 // Sub iterate Alpha
276 for (i = 0; i < vwi.GetIterEnd(); ++i)
277 {
278 vwi.SaveLoopDetails("Save", i);
279
280 vwi.AppendEvlToFile("AlphaIter.his", i);
281
282 exit_alphaIter = vwi.CheckIfAtNeutralPoint();
283 if (exit_alphaIter == false)
284 {
285 vwi.UpdateAlpha(i + 1);
286 vwi.ExecuteWave();
287 }
288 else
289 {
291 break;
292 }
293 }
294
295 // check to see if growth was converged.
296 if (i == vwi.GetIterEnd())
297 {
298 cout << "Failed to converge growth rate in"
299 << " inner iteration after " << vwi.GetIterEnd()
300 << " loops" << endl;
301 exit(1);
302 }
303
304 vwi.MoveFile("AlphaIter.his", "Save_Outer", nouter_iter);
305 vwi.SaveLoopDetails("Save_Outer", nouter_iter);
306 vwi.AppendEvlToFile("OuterIter.his", nouter_iter++);
307
308 // assume that if only previous inner loop has
309 // only done one iteration then we are at neutral
310 // point
311 if (i == 0 && vwi.IfIterInterface() == false)
312 {
313 exit_iteration = true;
314 }
315
316 if (nouter_iter >= vwi.GetMaxOuterIterations())
317 {
318 cerr << "Failed to converge after "
319 << vwi.GetMaxOuterIterations() << " outer iterations"
320 << endl;
321 exit_iteration = true;
322 }
323 }
324 }
325 break;
326 default:
327 ASSERTL0(false, "Unknown iteration type");
328 }
329}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
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 43 of file VortexWaveInteractionSolver.cpp.

44{
45 try
46 {
47 VortexWaveInteraction vwi(argc, argv);
48
49 for (int i = 0; i < vwi.GetMaxWaveForceMagIter(); ++i)
50 {
52
53 NekDouble WaveForce = vwi.GetWaveForceMag();
54
55 vwi.AppendEvlToFile("ConvergedSolns", WaveForce);
56
57 vwi.SetWaveForceMag(WaveForce + vwi.GetWaveForceMagStep());
58 vwi.SetPrevAlpha(vwi.GetAlpha());
59 // vwi.SetAlpha(vwi.GetAlpha() +
60 // vwi.GetDAlphaDWaveForceMag()*vwi.GetWaveForceMagStep());
61 vwi.SetAlpha(vwi.GetAlpha() + (vwi.GetWaveForceMagStep() > 0
62 ? vwi.GetAlphaStep()
63 : (-vwi.GetAlphaStep())));
64
65 // Save data directories.
66 if (vwi.GetVWIIterationType() == eFixedAlphaWaveForcing)
67 {
68 Mvdir("Save", WaveForce);
69 }
70 else
71 {
72 Mvdir("Save_Outer", WaveForce);
73 // Execute Another loop so that not same initial conditions as
74 // last iteration
75 vwi.ExecuteLoop();
76 }
77 }
78 }
79
80 catch (const std::runtime_error &)
81 {
82 return 1;
83 }
84
85 catch (const std::string &eStr)
86 {
87 cout << "Error: " << eStr << endl;
88 }
89}
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 91 of file VortexWaveInteractionSolver.cpp.

92{
93 // save OuterIter.his if exists
94 string saveOuterIter = "mv -f OuterIter.his " + dir;
95 if (system(saveOuterIter.c_str()))
96 {
97 ASSERTL0(false, saveOuterIter.c_str());
98 }
99
100 // Mv directory
101 string newdir = dir + boost::lexical_cast<std::string>(dir_ending);
102 string syscall = "mv -f " + dir + " " + newdir;
103
104 if (system(syscall.c_str()))
105 {
106 ASSERTL0(false, syscall.c_str());
107 }
108
109 // make new directory
110 syscall = "mkdir " + dir;
111 ASSERTL0(system(syscall.c_str()) == 0,
112 "Failed to make directory '" + dir + "'");
113}

References ASSERTL0.

Referenced by main().