49 "Driver",
"SteadyState",0);
110 if (
m_comm->GetRank() == 0)
122 if (
m_session->GetSolverInfo(
"EqType") ==
"EulerCFE" ||
123 m_session->GetSolverInfo(
"EqType") ==
"NavierStokesCFE")
128 if(
m_session->DefinesSolverInfo(
"HOMOGENEOUS"))
130 if (
m_session->GetSolverInfo(
"HOMOGENEOUS") ==
"1D")
142 cout <<
"Besed on the dominant EV given in the xml file,"
143 <<
"a 1D model is used to evaluate the optumum parameters"
144 <<
"of the SFD method:" << endl;
157 ofstream
m_file(
"ConvergenceHistory.txt", ios::out | ios::trunc);
159 Array<OneD, Array<OneD, NekDouble> > q0(NumVar_SFD);
160 Array<OneD, Array<OneD, NekDouble> > q1(NumVar_SFD);
161 Array<OneD, Array<OneD, NekDouble> > qBar0(NumVar_SFD);
162 Array<OneD, Array<OneD, NekDouble> > qBar1(NumVar_SFD);
166 q0[i] = Array<OneD, NekDouble> (
m_equ[
m_nequ-1]->GetTotPoints(),
168 qBar0[i] = Array<OneD, NekDouble> (
m_equ[
m_nequ-1]->GetTotPoints(),
218 if (
m_comm->GetRank() == 0)
220 cout <<
"\n\t The SFD method is converging: we compute "
221 <<
"stability analysis using the 'partially "
222 <<
"converged' steady state as base flow:\n" << endl;
228 A->GetAdvObject()->SetBaseFlow(q0);
231 if (
m_comm->GetRank() == 0)
254 if (
m_comm->GetRank() == 0)
256 cout <<
"\n\t We compute stability analysis using"
257 <<
" the current flow field as base flow:\n"
264 A->GetAdvObject()->SetBaseFlow(q0);
267 if (
m_comm->GetRank() == 0)
316 M11 = coeff*(1.0 + X*Delta*exp(-(X + 1.0/Delta)));
317 M12 = coeff*(X*Delta*(1.0 - exp(-(X + 1.0/Delta))));
318 M21 = coeff*(1.0 - exp(-(X + 1.0/Delta)));
319 M22 = coeff*(X*Delta + exp(-(X + 1.0/Delta)));
324 const Array<
OneD,
const Array<OneD, NekDouble> > &q0,
325 const Array<
OneD,
const Array<OneD, NekDouble> > &qBar0,
326 Array<
OneD, Array<OneD, NekDouble> > &q1,
327 Array<
OneD, Array<OneD, NekDouble> > &qBar1)
329 q1[i] = Array<OneD, NekDouble> (
m_equ[
m_nequ - 1]->GetTotPoints(),0.0);
330 qBar1[i] = Array<OneD, NekDouble> (
m_equ[
m_nequ - 1]->GetTotPoints(),0.0);
333 Vmath::Svtvp(q1[i].num_elements(),
M11, q0[i], 1, q1[i], 1, q1[i], 1 );
334 Vmath::Svtvp(q1[i].num_elements(),
M12, qBar0[i], 1, q1[i], 1, q1[i], 1 );
352 cout <<
"\n\tgrowthEV = " << growthEV << endl;
353 cout <<
"\tfrequencyEV = " << frequencyEV << endl;
355 complex<NekDouble> ApproxEV = polar(exp(growthEV), frequencyEV);
374 const complex<NekDouble> &alpha,
378 cout <<
"\n\tWe enter the Gradient Descent Method [...]" << endl;
379 bool OptParmFound =
false;
380 bool Descending =
true;
398 while (OptParmFound ==
false)
406 s = abs(0.000001/dirx);
407 X_output = X_input + s*dirx;
408 Delta_output = Delta_input + s*diry;
411 while (Descending ==
true)
415 Delta_input = Delta_output;
425 X_output = X_input + s*dirx;
426 Delta_output = Delta_input + s*diry;
429 if(stepCounter > 9999999)
435 Delta_init = Delta_init + Delta_init*0.1;
436 Delta_input = Delta_init;
444 cout <<
"\tThe Gradient Descent Method has converged!" << endl;
446 cout <<
"\n\tThe updated parameters are: X_tilde = " << X_output
447 <<
" and Delta_tilde = " << Delta_output << endl;
462 const complex<NekDouble> &alpha,
465 NekDouble A11 = ( 1.0 + X_input * Delta_input *
466 exp(-(X_input + 1.0/Delta_input)) )/(1.0 + X_input*Delta_input);
467 NekDouble A12 = ( X_input*Delta_input - X_input * Delta_input *
468 exp(-(X_input + 1.0/Delta_input)) )/(1.0 + X_input*Delta_input);
470 exp(-(X_input + 1.0/Delta_input)) )/(1 + X_input*Delta_input);
471 NekDouble A22 = ( X_input*Delta_input + 1.0 *
472 exp(-(X_input + 1.0/Delta_input)) )/(1.0 + X_input*Delta_input);
474 complex<NekDouble> B11 = alpha;
479 complex<NekDouble> a = A11*B11 + A12*B21;
481 complex<NekDouble> c = A21*B11 + A22*B21;
484 complex<NekDouble> delt = sqrt((a-d)*(a-d) + 4.0*b*c);
485 complex<NekDouble> lambda_1 = 0.5*(a+d + delt);
486 complex<NekDouble> lambda_2 = 0.5*(a+d - delt);
491 MaxEV = max(NORM_1, NORM_2);
496 int &KrylovSubspaceDim,
502 std::string EVfileName =
m_session->GetSessionName() +
".evl";
503 std::ifstream EVfile(EVfileName.c_str());
505 int NumLinesInFile(0);
514 while(getline(EVfile, line))
523 if(NumLinesInFile < KrylovSubspaceDim*2.0
524 + KrylovSubspaceDim*(KrylovSubspaceDim+1.0)/2.0)
526 for(
int i = 1; i <= KrylovSubspaceDim; ++i)
528 if(NumLinesInFile == i*2.0 + i*(i+1.0)/2.0)
530 KrylovSubspaceDim = i;
536 std::ifstream EVfile(EVfileName.c_str());
540 for(
int i = 0; i < (NumLinesInFile - KrylovSubspaceDim); ++i)
542 std::getline(EVfile, line);
546 EVfile >> NonReleventNumber;
547 EVfile >> NonReleventNumber;
548 EVfile >> NonReleventNumber;
553 EVfile >> frequencyEV;
557 cout <<
"An error occured when openning the .evl file" << endl;
568 const Array<
OneD,
const Array<OneD, NekDouble> > &qBar1,
569 const Array<
OneD,
const Array<OneD, NekDouble> > &q0,
573 Array<OneD, NekDouble > NormDiff_q_qBar(
NumVar_SFD, 1.0);
574 Array<OneD, NekDouble > NormDiff_q1_q0(
NumVar_SFD, 1.0);
575 MaxNormDiff_q_qBar=0.0;
576 MaxNormDiff_q1_q0=0.0;
580 NormDiff_q_qBar[i] =
m_equ[
m_nequ - 1]->LinfError(i, qBar1[i]);
581 NormDiff_q1_q0[i] =
m_equ[
m_nequ - 1]->LinfError(i, q0[i]);
583 if (MaxNormDiff_q_qBar < NormDiff_q_qBar[i])
585 MaxNormDiff_q_qBar = NormDiff_q_qBar[i];
587 if (MaxNormDiff_q1_q0 < NormDiff_q1_q0[i])
589 MaxNormDiff_q1_q0 = NormDiff_q1_q0[i];
598 if (
m_comm->GetRank() == 0)
601 <<
";\tTime: " << left <<
m_equ[
m_nequ - 1]->GetFinalTime()
602 <<
";\tCPU time = " << left <<
cpuTime <<
" s"
603 <<
";\tTot time = " << left <<
totalTime <<
" s"
604 <<
";\tX = " << left <<
m_X
605 <<
";\tDelta = " << left <<
m_Delta
606 <<
";\t|q-qBar|inf = " << left << MaxNormDiff_q_qBar << endl;
607 std::ofstream
m_file(
"ConvergenceHistory.txt", std::ios_base::app);
611 << MaxNormDiff_q_qBar <<
"\t"
612 << MaxNormDiff_q1_q0 << endl;
623 cout <<
"\n====================================="
624 "=================================="
626 cout <<
"Parameters for the SFD method:" << endl;
627 cout <<
"\tControl Coefficient: X = " <<
m_X << endl;
628 cout <<
"\tFilter Width: Delta = " <<
m_Delta << endl;
629 cout <<
"The simulation is stopped when |q-qBar|inf < " <<
TOL << endl;
632 cout <<
"\nWe use the adaptive SFD method:" << endl;
633 cout <<
" The parameters are updated every " <<
AdaptiveTime
634 <<
" time units;" << endl;
635 cout <<
" until |q-qBar|inf becomes smaller than " <<
AdaptiveTOL
638 cout <<
"====================================="
639 "==================================\n" << endl;