CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Defining stop criteria within solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 10, 2020, 11:56
Default Defining stop criteria within solver
  #1
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Hello to all,


I am using the solver pimpleFoam in openFoam v7 to do some calculations.


After I achieve convergence of the main fields I would like to solve another equation.


So, I place the following:


Code:
 if (pimple.finalPimpleIter())
             {
                bool switch_solver(true);
                label counter(0);
                while (switch_solver)
                {
                    #include "solveMyEquation.H" //has the solve statement inside

                    counter+=1;
                    if (counter==3)
                    {
                        switch_solver=false;
                    }

                }


            }


This works fine but I would like to end the loop by a predefined value of the residuals and not the number of cycles.
Something like:

Code:
   while (residue > myPredefinedResidue)
                {
                    #include "solveMyEquation.H"
                }




Does anyone know how to do this?


Best regards

Last edited by Shibi; December 11, 2020 at 08:22.
Shibi is offline   Reply With Quote

Old   December 11, 2020, 16:02
Default
  #2
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Update:


in solve statement within #include "solveMyEquation.H" I made


Code:
SymmTensor<scalar> Residue_ = solve(MyEquation).initialResidual();
Outside of the include:




Code:

counter+=1;



SymmTensor<scalar> tolerance_ (1e-05,1e-05,1e-05,1e-05,1e-05,1e-05);  
 
scalar checkConvergence_(1);

forAll(Residue_,i)
{
    checkConvergence_*=pos( tolerance_[i]-Residue_[i]);
}


if (checkConvergence_>0)
{
      switch_solver=false; // if checkConvergence_ is positive, all multiplications will result in the value 1 and the residue is smaller than the tolerance
                
}
else
{
      switch_solver=true;
}



// If solver takes more than 3 iteration to converge, leave the loop
 if ( counter==3)
 {
      end_orientation_loop=false;            

 }

It does the first pimple cycle and everything is Ok. During the 2nd cycle, I get the following error:


Code:
--> FOAM FATAL ERROR: 
index 3 out of range 0 ... 2

    From function void Foam::UList<T>::checkIndex(Foam::label) const [with T = Foam::SolverPerformance<Foam::SymmTensor<double> >; Foam::label = int]
      in file /home/pc/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/UListI.H at line 106.

Any suggestions on what to do?
Shibi is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unsteady Restart Divergence pro_ SU2 6 May 20, 2020 15:17
Hybrid discretisation - blend factor gcoopermax CFX 5 September 23, 2016 08:05
Quarter Burner mesh with periosic condition SamCanuck FLUENT 2 August 31, 2011 11:34
Working directory via command line Luiz CFX 4 March 6, 2011 20:02
Setting a B.C using UserFortran in 4.3 tokai CFX 10 July 17, 2001 16:25


All times are GMT -4. The time now is 03:24.