mhamadmahdialloush / uFVM

Learning the Finite Volume Method in CFD with MATLAB Programming
https://www.aub.edu.lb/msfea/research/Pages/cfd.aspx
135 stars 44 forks source link

Questions about only one-time call to cfdUpdateGradients #7

Open zongy17 opened 3 years ago

zongy17 commented 3 years ago

In function cfdRunFalseTransientCase, why cfdUpdateGradients is called only for one-time outside the main loop?

This problem results in that the gradient used throughout the whole computation process is the same! (Notice that in _cfdAssembleAndCorrect_xxxEquation functions, gradient is used to calculate non-orthogonal correction terms.) Thus, I think an additional call to cfdUpdateGradients should be placed at the end of the main loop body.

mhamadmahdialloush commented 3 years ago

Putting a gradient update at the beginning of the coefficient loop is sufficient for laminar flows. We need to update the gradient of the field at the beginning only. Adding a gradient update at the end will change nothing to the result, because you are in fact updating the gradient at the end, and also again at the beginning of the next loop

zongy17 commented 3 years ago

Thank you for the reply! I tried making cfdRunFalseTransientCase.m like this:

% Pre-updates (necessary on startup)
cfdUpdateFieldsForAllBoundaryPatches;
% cfdUpdateGradients;
cfdUpdateScales;

% Start steady false transience loop
totalNumberOfIterations = 0;
while (cfdDoFalseTransientLoop)
    % Update number of iters
    totalNumberOfIterations = totalNumberOfIterations + 1;   

    % Time settings
    cfdUpdateRunTime;

    % Print
    cfdPrintIteration(totalNumberOfIterations);
    cfdPrintResidualsHeader;

    % Updates
    cfdUpdatePrevIter;
    cfdUpdateProperties;

    cfdUpdateGradients; % I add the update here

    % Navier-Stokes and pressure correction
    cfdAssembleAndCorrectNSSystem

    % Energy
    cfdAssembleAndCorrectEnergyEquation;

    % Post actions
    cfdPlotRes;
    cfdPostResults(totalNumberOfIterations);    
    cfdWriteResults(totalNumberOfIterations);
end

But it does seem that results do not change much. I do not understand why omitting those updates inside the loop could work, since the non-orthogonal terms need gradients of the new fields. It looks incredible. Could you explain the mysterious reason?