@@ -73,7 +73,7 @@ void CSinglezoneDriver::StartSolver() {
7373 Preprocess (TimeIter);
7474
7575 /* --- Run a time-step iteration of the single-zone problem. ---*/
76- PreRunSpectralRadius ();
76+
7777 Run ();
7878
7979 /* --- Perform some postprocessing on the solution before the update ---*/
@@ -83,7 +83,7 @@ void CSinglezoneDriver::StartSolver() {
8383 /* --- Update the solution for dual time stepping strategy ---*/
8484
8585 Update ();
86- PostRunSpectralRadius ();
86+
8787 /* --- Monitor the computations after each iteration. ---*/
8888
8989 Monitor (TimeIter);
@@ -312,213 +312,3 @@ bool CSinglezoneDriver::Monitor(unsigned long TimeIter){
312312bool CSinglezoneDriver::GetTimeConvergence () const {
313313 return output_container[ZONE_0]->GetCauchyCorrectedTimeConvergence (config_container[ZONE_0]);
314314}
315-
316- void CSinglezoneDriver::SeedAllDerivatives (const su2matrix<passivedouble>& derivatives, CGeometry *geometry) {
317- unsigned long pointOffset = 0 ;
318- unsigned long varOffset = 0 ;
319-
320- if (rank == MASTER_NODE) {
321- std::cout << " runnin SeedAllDerivatives function" << endl;
322- std::cout << " matrix size: " << derivatives.rows () << " x " << derivatives.cols () << endl;
323- }
324-
325- for (auto iSol = 0u ; iSol < MAX_SOLS; ++iSol) {
326- CSolver* solver = solver_container[ZONE_0][INST_0][MESH_0][iSol];
327- if (!solver) continue ;
328-
329- CVariable* nodes = solver->GetNodes ();
330- if (!nodes) continue ;
331-
332- unsigned short nVar = solver->GetnVar ();
333- unsigned long nPoint = geometry->GetnPointDomain ();
334-
335- if (rank == MASTER_NODE) {
336- std::cout << " solver " << iSol << " has nVar=" << nVar << " , nPoint=" << nPoint << endl;
337- }
338-
339- // seed derivatives (removed function from csolver to make debug easier)
340- for (unsigned long iPoint = 0 ; iPoint < nPoint; iPoint++) {
341- su2double* solution = nodes->GetSolution (iPoint);
342- for (unsigned short iVar = 0 ; iVar < nVar; iVar++) {
343- double derivative_value = derivatives (pointOffset + iPoint, varOffset + iVar);
344-
345- // debugging value and derivative
346- double original_value = SU2_TYPE::GetValue (solution[iVar]);
347- SU2_TYPE::SetDerivative (solution[iVar], derivative_value);
348- double extracted_derivative = SU2_TYPE::GetDerivative (solution[iVar]);
349-
350- // see if forward mode works- output for the first few points -
351- // WORKS WHEN RUNNING SU2_CFD_DIRECTDIFF, when SU2_CFD is run gives "Got= 0"
352- if (iPoint < 5 && iVar == 0 && rank == MASTER_NODE) {
353- std::cout << " Point " << iPoint << " , Var " << iVar << " : Set=" << derivative_value
354- << " , Got=" << extracted_derivative << " , Value=" << original_value << endl;
355- }
356- }
357- }
358- pointOffset += nPoint;
359- varOffset += nVar;
360- }
361-
362- if (rank == MASTER_NODE) {
363- std::cout << " Finished SeedAllDerivatives" << endl;
364- }
365- }
366-
367- void CSinglezoneDriver::GetAllDerivatives (su2matrix<passivedouble>& derivatives, CGeometry *geometry) {
368- unsigned long pointOffset = 0 ;
369- unsigned long varOffset = 0 ;
370-
371- if (rank == MASTER_NODE) {
372- std::cout << " runnin GetAllDerivatives function" << endl;
373- }
374-
375- for (auto iSol = 0u ; iSol < MAX_SOLS; ++iSol) {
376- CSolver* solver = solver_container[ZONE_0][INST_0][MESH_0][iSol];
377- if (!solver) continue ;
378-
379- CVariable* nodes = solver->GetNodes ();
380- if (!nodes) continue ;
381-
382- unsigned short nVar = solver->GetnVar ();
383- unsigned long nPoint = geometry->GetnPointDomain ();
384-
385- if (rank == MASTER_NODE) {
386- std::cout << " solver " << iSol << " has nVar=" << nVar << " , nPoint=" << nPoint << endl;
387- }
388-
389- // extract derivatives for solver
390- for (unsigned long iPoint = 0 ; iPoint < nPoint; iPoint++) {
391- su2double* solution = nodes->GetSolution (iPoint);
392- for (unsigned short iVar = 0 ; iVar < nVar; iVar++) {
393- double derivative_value = SU2_TYPE::GetDerivative (solution[iVar]);
394- derivatives (pointOffset + iPoint, varOffset + iVar) = derivative_value;
395-
396- // Debug: check if derivatives are being extracted correctly
397- if (iPoint == 0 && iVar == 0 && rank == MASTER_NODE) {
398- std::cout << " extracted derivative for solver " << iSol << " , point 0, var 0: " << derivative_value << endl;
399- }
400- }
401- }
402- pointOffset += nPoint;
403- varOffset += nVar;
404- }
405-
406- if (rank == MASTER_NODE) {
407- std::cout << " Finished GetAllDerivatives" << endl;
408- }
409- }
410-
411- void CSinglezoneDriver::PreRunSpectralRadius () {
412- if (!config_container[ZONE_0]->GetSpectralRadius_Analysis ()) return ;
413-
414- CGeometry* geometry = geometry_container[ZONE_0][INST_0][MESH_0];
415-
416- // get total number of variables and points
417- unsigned long nVarTotal = 0 ;
418- unsigned long nPoint = geometry->GetnPointDomain ();
419- for (auto iSol = 0u ; iSol < MAX_SOLS; ++iSol) {
420- CSolver* solver = solver_container[ZONE_0][INST_0][MESH_0][iSol];
421- if (solver) nVarTotal += solver->GetnVar ();
422- }
423-
424- // initialize power iteration matrix if needed
425- if (v_estimate.rows () != nPoint || v_estimate.cols () != nVarTotal) {
426- v_estimate.resize (nPoint, nVarTotal);
427-
428- passivedouble norm = 0.0 ;
429- // initialize with random values
430- for (unsigned long iPoint = 0 ; iPoint < nPoint; iPoint++) {
431- for (unsigned short iVar = 0 ; iVar < nVarTotal; iVar++) {
432- v_estimate (iPoint, iVar) = static_cast <passivedouble>(rand ()) / RAND_MAX;
433- norm += v_estimate (iPoint, iVar) * v_estimate (iPoint, iVar);
434- }
435- }
436- // Calculate the global norm
437- passivedouble local_norm = norm;
438- passivedouble global_norm;
439- SU2_MPI::Allreduce (&local_norm, &global_norm, 1 , MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm ());
440- global_norm = sqrt (local_norm);
441-
442- // normalize matrix
443- for (unsigned long iPoint = 0 ; iPoint < nPoint; iPoint++) {
444- for (unsigned short iVar = 0 ; iVar < nVarTotal; iVar++) {
445- v_estimate (iPoint, iVar) /= global_norm;
446- }
447- }
448- }
449-
450- // seed all solvers
451- SeedAllDerivatives (v_estimate, geometry);
452- if (rank == MASTER_NODE) { std::cout << " seeding done" << endl; }
453- }
454-
455- void CSinglezoneDriver::PostRunSpectralRadius () {
456- if (!config_container[ZONE_0]->GetSpectralRadius_Analysis ()) return ;
457- if (rank == MASTER_NODE) {
458- std::cout << " Running PostRunSpectralRadius" << endl;
459- }
460-
461- CGeometry* geometry = geometry_container[ZONE_0][INST_0][MESH_0];
462-
463- unsigned long nPoint = geometry->GetnPointDomain ();
464- unsigned short nVarTotal = 0 ;
465- for (auto iSol = 0u ; iSol < MAX_SOLS; ++iSol) {
466- CSolver* solver = solver_container[ZONE_0][INST_0][MESH_0][iSol];
467- if (solver) nVarTotal += solver->GetnVar ();
468- }
469-
470- if (rank == MASTER_NODE) {
471- std::cout << " total var: " << nVarTotal << " , total points: " << nPoint << endl;
472- }
473-
474- su2matrix<passivedouble> w_k (nPoint, nVarTotal);
475- if (rank == MASTER_NODE) {std::cout << " matrix w initialized with size: " << w_k.rows () << " x " << w_k.cols () << endl;}
476-
477- passivedouble rho_old = 0.0 ;
478- int max_iter = config_container[ZONE_0]->GetnPowerMethodIter ();
479- su2double tol = config_container[ZONE_0]->GetPowerMethodTolerance ();
480- int k = 0 ;
481-
482- while (k < max_iter) {
483- GetAllDerivatives (w_k, geometry);
484-
485- // compute local squared norm
486- passivedouble rho_local = 0.0 ;
487- for (unsigned long iPoint = 0 ; iPoint < nPoint; iPoint++) {
488- for (unsigned short iVar = 0 ; iVar < nVarTotal; iVar++) {
489- rho_local += w_k (iPoint, iVar) * w_k (iPoint, iVar);
490- }
491- }
492-
493- // global reduction
494- passivedouble rho_global = 0.0 ;
495- SU2_MPI::Allreduce (&rho_local, &rho_global, 1 , MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm ());
496- passivedouble rho_k = sqrt (rho_local);
497-
498- if (rank == MASTER_NODE) {
499- std::cout << " Spectral Radius Estimate for Iteration " << k << " is " << rho_k << endl;
500- }
501-
502- // convergence check
503- if (abs (rho_k - rho_old) < tol) {
504- if (rank == MASTER_NODE) {
505- std::cout << " Converged Eigenvalue after " << k << " iterations is " << rho_k << endl;
506- }
507- break ;
508- }
509-
510- // normalize w_k to form next seed w_{k+1}
511- for (unsigned long iPoint = 0 ; iPoint < nPoint; ++iPoint) {
512- for (unsigned short iVar = 0 ; iVar < nVarTotal; ++iVar) {
513- w_k (iPoint, iVar) /= rho_k;
514- }
515- }
516-
517- SeedAllDerivatives (w_k, geometry);
518- rho_old = rho_k;
519- k++;
520-
521- } // while
522-
523- w_k.resize (0 , 0 );
524- }
0 commit comments