- **OpenFOAM Programming & Development**
(*https://www.cfd-online.com/Forums/openfoam-programming-development/*)

- - **do_while loop for coupling two equations (convergence criteria?)**
(*https://www.cfd-online.com/Forums/openfoam-programming-development/85469-do_while-loop-coupling-two-equations-convergence-criteria.html*)

do_while loop for coupling two equations (convergence criteria?)hi
I have a question regarding coupling two scalar transport equations. the equations are coupled through their source term. from the programmer's guide, source term can explicitly be added to the equation: solve(fvm::laplacian(phi) == f), f being a vol<type>Field. I want to solve them sequentially and constructing a loop to reach to converge iteratively. in order to see the convergence, I have one problem, how I can save the previous iteration result and subtract them to see if it meets the convergence tolerance. do{ solve(equation of C1, with a source term of C2) solve (equation of C2, with a source term of C1) error1=C1(n-1)-C1; //n-1 represent previous iteration results error2=C2(n-1)-C2;//n-1 represent previous iteration results }while(error1<0.001 && error2<0.001) //0.001 is the convergence tolerance if you can help me, it means a lot. thanks in forward. p.s. I have declare the errors as volScalarField and I don't know is it ok, and I have faced errors using declaration of this errors and using relational operators (>=). any suggestion? |

Muhammad, error1 and error2 will be fields and comparing them with scalar is inappropriate, I think. May be you can take the average of error1 and errors absolute values in order to have only on scalar, then compare it with your error criterion.
volScalarField C1nminus1=C1; solve(equation of C1, with a source term of C2) error1=Foam::average(Foam::mag(C1nminus1-C1)); //n-1 represent previous iteration results Or something like this. Regards |

Why not use the residual as done in simpleFoam? Something like:
Code:
` eqnResidual = solve` |

Yes, I thought in the same thing, but it supposes you're judging convergence based on residuals. Which I can understand at all is the purpose of this loop, Is this a sort of outer loop in order to better couple the solution in each time-step?
Regards. |

All times are GMT -4. The time now is 02:00. |