E - More is better

本文介绍了一种使用并查集算法解决复杂社交网络中最大朋友圈规模的问题,通过输入直接朋友对来计算最大可能保留的朋友数量。

点击打开链接


Mr Wang wants some boys to help him with a project. Because the project is rather complex,  the more boys come, the better it will be. Of course there are certain requirements. 

Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way. 
Input
The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
Output
The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep. 
Sample Input
4
1 2
3 4
5 6
1 6
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100010
int par[maxn],num[maxn],sum[maxn];
void init()
{
	for(int i=1;i<=maxn;i++)
	{
	par[i]=i;
	num[i]=1;
    }
}
int find(int x)
{ if(x!=par[x])
 par[x]=find(par[x]);  
    return par[x];  
}
void unite(int a,int b)
{
	int fa=find(a);
	int fb=find(b);
	if(fa!=fb)
    {
	par[fa]=fb;
  }
}
int main()
{int n,a,b;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
printf("%d\n",1);
else{
	init();
	int max=0;
	while(n--)
	{
	scanf("%d%d",&a,&b);
	if(a>max)
	max=a;
	if(b>max)
	max=b;
	unite(a,b);
   }
   memset(sum,0,sizeof(sum));
   for(int i=1;i<=max;i++)
   sum[find(i)]++; 
int max1=0;
for(int i=1;i<=max;i++)
{
	if(sum[find(i)]>max1)
	max1=sum[find(i)];
}
printf("%d\n",max1);
}
}
	return 0;
}

41 23 45 67 8
Sample Output
4
2


        
  
Hint
A and B are friends(direct or indirect), B and C are friends(direct or indirect), 
then A and C are also friends(indirect).

 In the first sample {1,2,5,6} is the result.
In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.
 
        
 


分析:平时有时候会让求集合(畅通工程题),而本题用并查集求得每个集合的元素的个数,最后输出最大的集合的元素个数;



代码:


#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100010
int par[maxn],num[maxn],sum[maxn];
void init()
{
	for(int i=1;i<=maxn;i++)
	{
	par[i]=i;
	num[i]=1;
    }
}
int find(int x)
{ if(x!=par[x])
 par[x]=find(par[x]);  
    return par[x];  
}
void unite(int a,int b)
{
	int fa=find(a);
	int fb=find(b);
	if(fa!=fb)
    {
	par[fa]=fb;
  }
}
int main()
{int n,a,b;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
printf("%d\n",1);
else{
	init();
	int max=0;
	while(n--)
	{
	scanf("%d%d",&a,&b);
	if(a>max)
	max=a;
	if(b>max)
	max=b;
	unite(a,b);
   }
   memset(sum,0,sizeof(sum));
   for(int i=1;i<=max;i++)//统计各个集合的个数
   sum[find(i)]++; 
int max1=0;
for(int i=1;i<=max;i++)
{
	if(sum[find(i)]>max1)
	max1=sum[find(i)];
}
printf("%d\n",max1);
}
}
	return 0;
}


the result of cl and cd is not acceptable and i need to modify the file the result of the code which give not coverge Writing the forces breakdown file (forces_breakdown.dat). +-----------------------------------------------------------------------+ +----------------------------------------------------------------+ | Inner_Iter| Time(sec)| Time_Iter| CL| CD| +----------------------------------------------------------------+ | 19510| 6.6939e-02| 0| 0.004081| 0.156430| | 19520| 6.6938e-02| 0| 0.011526| 0.146708| | 19530| 6.6936e-02| 0| 0.020145| 0.136572| | 19540| 6.6936e-02| 0| 0.029911| 0.126056| | 19550| 6.6936e-02| 0| 0.040790| 0.115191| | 19560| 6.6937e-02| 0| 0.052748| 0.104011| | 19570| 6.6936e-02| 0| 0.065747| 0.092552| | 19580| 6.6937e-02| 0| 0.079750| 0.080846| | 19590| 6.6937e-02| 0| 0.094710| 0.068930| | 19600| 6.6937e-02| 0| 0.110578| 0.056842| | 19610| 6.6936e-02| 0| 0.127301| 0.044617| | 19620| 6.6936e-02| 0| 0.144820| 0.032294| | 19630| 6.6936e-02| 0| 0.163072| 0.019912| | 19640| 6.6936e-02| 0| 0.181996| 0.007507| | 19650| 6.6938e-02| 0| 0.201529| -0.004880| | 19660| 6.6938e-02| 0| 0.221605| -0.017212| | 19670| 6.6939e-02| 0| 0.242152| -0.029450| | 19680| 6.6939e-02| 0| 0.263099| -0.041557| | 19690| 6.6939e-02| 0| 0.284374| -0.053493| | 19700| 6.6938e-02| 0| 0.305902| -0.065223| | 19710| 6.6939e-02| 0| 0.327610| -0.076709| | 19720| 6.6939e-02| 0| 0.349426| -0.087915| | 19730| 6.6940e-02| 0| 0.371270| -0.098806| | 19740| 6.6939e-02| 0| 0.393065| -0.109348| | 19750| 6.6938e-02| 0| 0.414740| -0.119507| | 19760| 6.6937e-02| 0| 0.436215| -0.129251| | 19770| 6.6936e-02| 0| 0.457421| -0.138551| | 19780| 6.6935e-02| 0| 0.478285| -0.147374| | 19790| 6.6936e-02| 0| 0.498731| -0.155695| | 19800| 6.6935e-02| 0| 0.518687| -0.163486| | 19810| 6.6934e-02| 0| 0.538085| -0.170724| | 19820| 6.6933e-02| 0| 0.556863| -0.177383| | 19830| 6.6933e-02| 0| 0.574961| -0.183444| | 19840| 6.6933e-02| 0| 0.592319| -0.188885| | 19850| 6.6933e-02| 0| 0.608878| -0.193688| | 19860| 6.6932e-02| 0| 0.624578| -0.197837| | 19870| 6.6934e-02| 0| 0.639369| -0.201318| | 19880| 6.6934e-02| 0| 0.653203| -0.204118| | 19890| 6.6933e-02| 0| 0.666041| -0.206226| | 19900| 6.6932e-02| 0| 0.677843| -0.207635| | 19910| 6.6932e-02| 0| 0.688573| -0.208341| | 19920| 6.6932e-02| 0| 0.698202| -0.208341| | 19930| 6.6932e-02| 0| 0.706704| -0.207633| | 19940| 6.6932e-02| 0| 0.714061| -0.206219| | 19950| 6.6932e-02| 0| 0.720254| -0.204105| | 19960| 6.6932e-02| 0| 0.725271| -0.201298| | 19970| 6.6932e-02| 0| 0.729098| -0.197808| | 19980| 6.6931e-02| 0| 0.731734| -0.193645| | 19990| 6.6930e-02| 0| 0.733176| -0.188822| | 19999| 6.6930e-02| 0| 0.733451| -0.183929| ----------------------------- Solver Exit ------------------------------- Maximum number of iterations reached (ITER = 20000) before convergence. +-----------------------------------------------------------------------+ | Convergence Field | Value | Criterion | Converged | +-----------------------------------------------------------------------+ | rms[P]| -4.74136| < -12| No| +-----------------------------------------------------------------------+ ------------------------------------------------------------------------- +-----------------------------------------------------------------------+ | File Writing Summary | Filename | +-----------------------------------------------------------------------+ |SU2 binary restart |restart_flow.dat | | | (3796.74 MB/s)| Writing the forces breakdown file (forces_breakdown.dat). |Paraview surface |surface_flow.vtu | | | (385.216 MB/s)| Writing the forces breakdown file (forces_breakdown.dat). +-----------------------------------------------------------------------+ --------------------------- Finalizing Solver --------------------------- Deleted CNumerics container. Deleted CIntegration container. Deleted CSolver container. Deleted CIteration container. Deleted CInterface container. Deleted CGeometry container. Deleted CFreeFormDefBox class. Deleted CSurfaceMovement class. Deleted CVolumetricMovement class. Deleted CConfig container. Deleted nInst container. Deleted COutput class. ------------------------------------------------------------------------- -------------------------- Performance Summary -------------------------- Simulation totals: Wall-clock time (hrs): 0.371884 | Core-hrs: 0.371884 Cores: 1 | DOFs/point: 6 Points/core: 38442 | Ghost points/core: 0 Ghost/Owned Point Ratio: 0 | Preprocessing phase: Preproc. Time (s): 0.156802 | Preproc. Time (%): 0.0117123 Compute phase: Compute Time (s): 1338.6 | Compute Time (%): 99.9867 Iteration count: 20000 | Avg. s/iter: 0.0669302 Core-s/iter/Mpoints: 1.74107 | Mpoints/s: 0.574359 Output phase: Output Time (s): 0.021299 | Output Time (%): 0.00159092 Output count: 1 | Avg. s/output: 0.021299 Restart Aggr. BW (MB/s): 142429 | MB/s/core: 142429 ------------------------------------------------------------------------- ------------------------- Exit Success (SU2_CFD) ------------------------ the code i use it as foolowing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------% % SOLVER= INC_RANS % KIND_TURB_MODEL= SST KIND_TRANS_MODEL= LM %FREESTREAM_TURBULENCEINTENSITY= 0.001 %FREESTREAM_TURB2LAMVISCRATIO = 2.0 %HROUGHNESS = 3.3E-6 % MATH_PROBLEM= DIRECT % RESTART_SOL= NO % OBJECTIVE_FUNCTION=DRAG % -------------------- INCOMPRESSIBLE FREE-STREAM DEFINITION ------------------% % INC_DENSITY_INIT= 1.225 INC_TEMPERATURE_INIT= 288.15 % -------------- COMPRESSIBLE AND INCOMPRESSIBLE FLUID CONSTANTS --------------% % %GAMMA_VALUE= 1.4 %GAS_CONSTANT= 287.87 % % AoA 0.0 deg INC_VELOCITY_INIT= ( 14.60799973614140 , 0.00277648930504, 0.0 ) % INC_NONDIM= INITIAL_VALUES % --------------------------- VISCOSITY MODEL ---------------------------------% % VISCOSITY_MODEL= CONSTANT_VISCOSITY % MU_CONSTANT= 1.789e-05 % ---------------------- REFERENCE VALUE DEFINITION ---------------------------% % REF_ORIGIN_MOMENT_X= 0.25 REF_ORIGIN_MOMENT_Y = 0.00 REF_ORIGIN_MOMENT_Z = 0.00 % REF_LENGTH= 1.0 % REF_AREA= 1.0 % -------------------------- CL DRIVER DEFINITION -----------------------------% % % Activate fixed lift mode (specify a CL instead of AoA, NO/YES) FIXED_CL_MODE= NO % % Target coefficient of lift for fixed lift mode (0.80 by default) TARGET_CL= 0.724 % % Estimation of dCL/dAlpha (0.2 per degree by default) DCL_DALPHA= 0.2 % % Maximum number of iterations between AoA updates UPDATE_AOA_ITER_LIMIT= 100 % % Number of iterations to evaluate dCL/dAlpha at the end of the simulation ITER_DCL_DALPHA= 500 % % Evaluate dObjFunc/dCL during runtime (YES) or use the value stored in the % direct solution file (NO). EVAL_DOF_DCX= NO % -------------------- BOUNDARY CONDITION DEFINITION --------------------------% % MARKER_HEATFLUX= ( AIRFOIL, 0.0 ) % MARKER_FAR= ( FARFIELD ) % MARKER_PLOTTING= ( AIRFOIL ) % MARKER_MONITORING= ( AIRFOIL ) % ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------% % NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES % CFL_NUMBER= 1.0 % %MAX_DELTA_TIME= 1E10 % CFL_ADAPT= NO % CFL_ADAPT_PARAM= ( 0.1, 2.0, 40.0, 1e10, 0.001 ) %CFL_ADAPT_PARAM= ( 0.5, 1.0, 0.5, 1000, 0.001 ) % Less aggressive adaptation % ITER= 20000 % ------------------------ LINEAR SOLVER DEFINITION ---------------------------% % LINEAR_SOLVER= FGMRES % LINEAR_SOLVER_PREC= LU_SGS % LINEAR_SOLVER_ERROR= 1E-6 % LINEAR_SOLVER_ITER= 5 % -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------% % % CONV_NUM_METHOD_FLOW= FDS % MUSCL_FLOW= YES % SLOPE_LIMITER_FLOW= VENKATAKRISHNAN % JST_SENSOR_COEFF= ( 0.5, 0.02 ) % TIME_DISCRE_FLOW= EULER_IMPLICIT % ----------------------- SLOPE LIMITER DEFINITION ----------------------------% % VENKAT_LIMITER_COEFF= 0.05 % LIMITER_ITER= 99999 % -------------------- TURBULENT NUMERICAL METHOD DEFINITION ------------------% % CONV_NUM_METHOD_TURB= SCALAR_UPWIND % MUSCL_TURB= NO % SLOPE_LIMITER_TURB= NONE % TIME_DISCRE_TURB= EULER_IMPLICIT % CFL_REDUCTION_TURB= 1.0 % --------------------------- CONVERGENCE PARAMETERS --------------------------% % % %CONV_CRITERIA= CAUCHY % CONV_RESIDUAL_MINVAL= -12 % CONV_FIELD= ( RMS_PRESSURE ) % % Start convergence criteria at iteration number CONV_STARTITER= 500 % ------------------------- INPUT/OUTPUT INFORMATION --------------------------% % %HISTORY_WRT_FREQ_INNER=0 MESH_FILENAME= mesh_211_ffd.su2 % MESH_FORMAT= SU2 % SOLUTION_FILENAME= restart_flow.dat % OUTPUT_FILES= (RESTART, SURFACE_PARAVIEW) WRT_FORCES_BREAKDOWN= YES VOLUME_OUTPUT= (COORDINATES, SOLUTION, PRIMITIVE, RESIDUAL) HISTORY_OUTPUT= (ITER, LINSOL, RMS_RES, MAX_RES, AERO_COEFF, CFL_NUMBER) % CONV_FILENAME= history % RESTART_FILENAME= restart_flow.dat % SOLUTION_ADJ_FILENAME = solution_adj.dat TABULAR_FORMAT= CSV VOLUME_FILENAME= flow % SURFACE_FILENAME= surface_flow % OUTPUT_WRT_FREQ= 500 % SCREEN_WRT_FREQ_INNER= 10 % %SCREEN_OUTPUT=(INNER_ITER, WALL_TIME, RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T, LIFT, DRAG, LINSOL_ITER_TRANS, LINSOL_RESIDUAL_TRANS, TAVG_DRAG) SCREEN_OUTPUT=(INNER_ITER,WALL_TIME, TIME_ITER, RMS_ADJ_DENSITY, RMS_DENSITY, , REL_RMS_DENSITY,REL_RMS_ADJ_DENSITY, LIFT,DRAG) % WRT_PERFORMANCE = YES % ----------------------- DESIGN VARIABLE PARAMETERS --------------------------% % DV_KIND= FFD_CONTROL_POINT_2D DV_MARKER= ( AIRFOIL ) DV_PARAM= ( AIRFOIL_BOX, 0.0, 0.0, 1.0, 0.0) DV_VALUE= 0.01 %DV_FILENAME= mesh_motion.dat % % ------------------------ GRID DEFORMATION PARAMETERS ------------------------% % DEFORM_LINEAR_SOLVER_ITER= 1000 DEFORM_NONLINEAR_ITER= 1 DEFORM_CONSOLE_OUTPUT= YES DEFORM_LINEAR_SOLVER_ERROR = 1E-6 DEFORM_STIFFNESS_TYPE= INVERSE_VOLUME OPT_ITERATIONS= 100 OPT_OBJECTIVE= DRAG * 1.0 OPT_GRADIENT_FACTOR= 0.1 OPT_RELAX_FACTOR= 1 OPT_BOUND_UPPER= 0.01 OPT_BOUND_LOWER= -0.01 %OPT_CONSTRAINT= ( AIRFOIL_THICKNESS > 0.21 ) * 1.0 OPT_CONSTRAINT= ( LIFT > 0.724 ) * 1.0; ( AIRFOIL_THICKNESS > 0.21 ) * 1.0 DEFINITION_DV= ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 0, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 1, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 2, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 3, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 4, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 5, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 6, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 7, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 8, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 9, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 10, 0, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 0, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 1, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 2, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 3, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 4, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 5, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 6, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 7, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 8, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 9, 1, 0.0, 1.0 ); ( 19, 1.0 | AIRFOIL | AIRFOIL_BOX, 10, 1, 0.0, 1.0 )
最新发布
08-27
<think>We are facing a convergence issue in an SU2 simulation for an incompressible RANS case with the SST turbulence model and transition model (LM). The simulation reached the maximum number of iterations (20000) without converging the RMS pressure residual to the desired criterion (1e-12). The output shows that the lift (CL) and drag (CD) coefficients are changing significantly and not stabilizing. Looking at the provided configuration file, we can identify several parameters that might need adjustment to improve convergence. Here are some suggestions: 1. **Increase the CFL number gradually**: The current CFL is set to 1.0. We can try using CFL ramping to start with a lower CFL and then increase it. This can be done by setting `CFL_ADAPT=YES` and providing appropriate parameters. The current setting for `CFL_ADAPT_PARAM` is (0.1, 2.0, 40.0, 1e10, 0.001). This means: - Initial CFL: 0.1 - Minimum CFL: 2.0 - Maximum CFL: 40.0 - Maximum CFL after which we stop increasing: 1e10 (practically no limit) - Factor to reduce CFL when divergence is detected: 0.001 (which is very aggressive) We might want to adjust the ramping to be less aggressive. For example, we can start with a lower initial CFL and then ramp up more slowly. 2. **Adjust the linear solver settings**: The current linear solver is FGMRES with LU_SGS preconditioner and 5 inner iterations. We might need to increase the number of inner iterations for the linear solver (especially for the turbulence equations) or use a stronger preconditioner. 3. **Reduce the time step or adjust the CFL**: The current CFL might be too high for the problem. We can try reducing the initial CFL to 0.5 or 1.0 and then ramp up more slowly. 4. **Check the convergence criteria**: The convergence criterion is set to `CONV_FIELD= ( RMS_PRESSURE )` and `CONV_RESIDUAL_MINVAL= -12`. However, we see that the RMS_PRESSURE is not converging. We might consider adding more variables to monitor for convergence, such as the turbulence variables. 5. **Use a different numerical scheme for the turbulence equations**: Currently, the turbulence equations are solved with a scalar upwind scheme. We might try using a more accurate scheme, such as FDS (like the flow equations) if stability allows. 6. **Adjust the turbulence model constants or transition model settings**: Sometimes, the default constants might not be optimal for the case. However, this is less common. 7. **Increase the relaxation factor for the turbulence equations**: The current setting for `CFL_REDUCTION_TURB=1.0` means no reduction. We can try reducing the CFL for the turbulence equations by setting a lower value (e.g., 0.5). 8. **Check the mesh quality**: Poor mesh quality can lead to convergence issues. We should check the mesh for negative volumes, high aspect ratios, etc. 9. **Use a different slope limiter**: The Venkatakrishnan limiter is used for the flow equations. We can try adjusting the coefficient (currently 0.05) or using a different limiter. 10. **Increase the number of iterations**: Although we set 20000 iterations, it might be that the problem requires more iterations to converge. However, the residuals are not decreasing anymore at the end, so we need to improve the convergence behavior. Let's modify the configuration file with the following changes: - Adjust the CFL ramping to start at a lower CFL and ramp up more gradually. For example, set `CFL_ADAPT_PARAM= (0.5, 1.0, 40.0, 10000.0, 0.5)`. This means: - Start at CFL=0.5 - Minimum CFL=1.0 (so we won't go below 1.0 when reducing due to divergence) - Maximum CFL=40.0 - We will stop increasing at 10000.0 (so we will increase until we hit 40.0 and then stay there) - Reduce by a factor of 0.5 when divergence is detected (less aggressive than 0.001) - Increase the number of linear iterations for the flow and turbulence equations. We can set `LINEAR_SOLVER_ITER= 10` for the flow and also set a separate one for turbulence? But note: the configuration doesn't have separate settings for turbulence. So we set the same for all. - We might also try increasing the linear solver error tolerance to 1e-4 to make the linear solution less strict and faster, but this might affect convergence. Alternatively, we can leave it at 1e-6. - Add the turbulence variables to the convergence monitoring. Change `CONV_FIELD= ( RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T )` if using the transition model. Note: The transition model has two equations: `nu_tilde` and `Re_theta_t`. We should monitor both. - We can also try reducing the CFL reduction factor for turbulence to 0.5: `CFL_REDUCTION_TURB= 0.5`. - Adjust the screen output to monitor more residuals: `SCREEN_OUTPUT= (INNER_ITER, WALL_TIME, RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T, LINSOL_ITER, LINSOL_RESIDUAL, LIFT, DRAG)` - We note that the problem is set to fixed lift mode? Actually, `FIXED_CL_MODE=NO`. So we are not adjusting the angle of attack during the simulation. This is acceptable. - We are using an implicit time integration. We might also try using a lower order time integration for the turbulence equations? But it's already Euler implicit. Let's write the modified configuration file with these changes: Note: We are going to make the following changes in the config file: 1. Adjust CFL_ADAPT_PARAM to (0.5, 1.0, 40.0, 10000.0, 0.5) 2. Increase LINEAR_SOLVER_ITER to 10 3. Change CONV_FIELD to ( RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T ) 4. Set CFL_REDUCTION_TURB=0.5 5. Adjust screen output to include more residuals. We'll also change the convergence criteria to start after 1000 iterations (CONV_STARTITER=1000) to avoid early termination checks when the solution is still changing. Here is the modified configuration file (only the changed parts are shown, the rest remains the same): ```config % ... [previous content] ... % --------------------------- CONVERGENCE PARAMETERS --------------------------% % % %CONV_CRITERIA= CAUCHY % CONV_RESIDUAL_MINVAL= -12 % % Monitor pressure and turbulence variables CONV_FIELD= ( RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T ) % % Start convergence criteria at iteration number CONV_STARTITER= 1000 % ... [previous content] ... % ------------------------ LINEAR SOLVER DEFINITION ---------------------------% % LINEAR_SOLVER= FGMRES % LINEAR_SOLVER_PREC= LU_SGS % LINEAR_SOLVER_ERROR= 1E-6 % % Increase the number of linear iterations LINEAR_SOLVER_ITER= 10 % ... [previous content] ... % -------------------- TURBULENT NUMERICAL METHOD DEFINITION ------------------% % CONV_NUM_METHOD_TURB= SCALAR_UPWIND % MUSCL_TURB= NO % SLOPE_LIMITER_TURB= NONE % TIME_DISCRE_TURB= EULER_IMPLICIT % % Reduce the CFL for turbulence equations CFL_REDUCTION_TURB= 0.5 % ... [previous content] ... % CFL ramping CFL_ADAPT= YES CFL_ADAPT_PARAM= ( 0.5, 1.0, 40.0, 10000.0, 0.5 ) % ... [previous content] ... % Adjust screen output to include residuals of interest SCREEN_OUTPUT= (INNER_ITER, WALL_TIME, RMS_PRESSURE, RMS_NU_TILDE, RMS_RE_THETA_T, LINSOL_ITER, LINSOL_RESIDUAL, LIFT, DRAG) % ... [previous content] ... ``` We hope that these changes will lead to better convergence. If not, we may need to further adjust the CFL ramping, try a different linear solver, or check the mesh. Let me know if you would like to try these changes and run the simulation again. §§相关问题§§: 1. 如何检查SU2模拟中的网格质量? 2. 在SU2中,如何设置多重网格以加速收敛? 3. 对于高雷诺数流动,SU2中有哪些推荐的湍流模型设置? 4. 如何在后处理中可视化SU2模拟的残差历史?</think>### 问题分析与解决方案 您的SU2模拟未能收敛,主要问题在于: 1. RMS压力残差未达到收敛标准(-12数量级) 2. 升力系数(CL)和阻力系数(CD)在迭代后期出现剧烈振荡 3. 最大迭代次数(20000)到达时仍未收敛 ### 需要修改的关键配置参数 #### 1. 时间步长和CFL设置(当前过于激进) ```config % 原设置 CFL_NUMBER = 1.0 CFL_ADAPT = NO % 修改为 CFL_NUMBER = 0.5 % 降低初始CFL CFL_ADAPT = YES CFL_ADAPT_PARAM = (0.1, 0.5, 1.0, 10000, 0.01) % 更保守的CFL自适应 ``` #### 2. 收敛标准和残差监控(当前设置不足) ```config % 原设置 CONV_FIELD = ( RMS_PRESSURE ) CONV_RESIDUAL_MINVAL = -12 % 修改为 CONV_FIELD = (RMS_PRESSURE, RMS_VELOCITY-X, RMS_NU_TILDE) % 增加监控变量 CONV_RESIDUAL_MINVAL = -10 % 放宽收敛标准 CONV_STARTITER = 1000 % 更早开始检查收敛 ``` #### 3. 线性求解器设置(当前迭代不足) ```config % 原设置 LINEAR_SOLVER_ITER = 5 LINEAR_SOLVER_ERROR = 1E-6 % 修改为 LINEAR_SOLVER_ITER = 20 % 增加线性求解器迭代次数 LINEAR_SOLVER_ERROR = 1E-4 % 放宽线性求解精度 ``` #### 4. 湍流模型设置(需要更稳定配置) ```config % 原设置 KIND_TURB_MODEL = SST KIND_TRANS_MODEL = LM % 修改为 KIND_TURB_MODEL = SA % 先使用更简单的SA模型确保收敛 KIND_TRANS_MODEL = NONE % 暂时禁用转捩模型 ``` #### 5. 数值格式优化 ```config % 原设置 MUSCL_FLOW = YES SLOPE_LIMITER_FLOW = VENKATAKRISHNAN % 修改为 MUSCL_FLOW = NO % 暂时禁用高阶格式 SLOPE_LIMITER_FLOW = BARTH_JESPERSEN % 改用更鲁棒的限幅器 VENKAT_LIMITER_COEFF = 0.01 % 减小限幅器系数 ``` ### 完整修改后的配置文件(关键部分) ```config SOLVER = INC_RANS MATH_PROBLEM = DIRECT ITER = 50000 % 增加最大迭代次数 % 收敛控制 CONV_FIELD = (RMS_PRESSURE, RMS_VELOCITY-X, RMS_NU_TILDE) CONV_RESIDUAL_MINVAL = -10 CONV_STARTITER = 1000 % 时间步长设置 CFL_NUMBER = 0.5 CFL_ADAPT = YES CFL_ADAPT_PARAM = (0.1, 0.5, 1.0, 10000, 0.01) CFL_REDUCTION_TURB = 0.5 % 湍流方程更小CFL % 线性求解器 LINEAR_SOLVER = FGMRES LINEAR_SOLVER_PREC = LU_SGS LINEAR_SOLVER_ERROR = 1E-4 LINEAR_SOLVER_ITER = 20 % 湍流模型 KIND_TURB_MODEL = SA % 简化模型 KIND_TRANS_MODEL = NONE % 禁用转捩模型 % 数值格式 CONV_NUM_METHOD_FLOW = FDS MUSCL_FLOW = NO % 一阶格式确保稳定 SLOPE_LIMITER_FLOW = BARTH_JESPERSEN VENKAT_LIMITER_COEFF = 0.01 % 输出设置 OUTPUT_WRT_FREQ = 100 SCREEN_WRT_FREQ_INNER = 50 SCREEN_OUTPUT = (INNER_ITER, WALL_TIME, RMS_PRESSURE, RMS_VELOCITY-X, LIFT, DRAG) ``` ### 解决方案说明 1. **CFL自适应调整**:降低初始CFL值并启用自适应,防止计算发散 2. **收敛标准优化**: - 增加监控变量(速度、湍流变量) - 放宽收敛标准到1e-10 - 延迟收敛检查开始迭代 3. **线性求解器增强**: - 迭代次数从5增加到20 - 求解精度从1e-6放宽到1e-4 4. **湍流模型简化**: - 暂时使用SA模型替代SST - 禁用转捩模型减少复杂度 5. **数值格式调整**: - 暂时使用一阶格式确保稳定性 - 改用BARTH_JESPERSEN限幅器 6. **输出优化**: - 增加残差输出频率 - 屏幕输出添加速度残差监控 ### 后续诊断建议 如果修改后仍不收敛,建议: 1. 检查网格质量(特别是边界层和近壁区域) 2. 验证边界条件设置(特别是远场和壁面条件) 3. 分阶段运行: ```bash # 先运行1000步检查初始收敛性 SU2_CFD config.cfg -n 1000 # 再逐步增加迭代次数 SU2_CFD config.cfg -n 5000 -s restart_flow.dat ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值