ForAll Loop
Hello Guys,
Is there an alternative to the forAll loop? Basically I need to run the following code every time step and as a result it takes a long time. The code is: forAll(alpha1, celli) { if (alpha1[celli] < 0) { alpha1[celli] = 0; } else if (alpha1[celli] > 1) { alpha1[celli]=1; } else { alpha1[celli]=alpha1[celli]; } }//end for loop This ensures that alpha1 in any cell is always between 0 and 1. I have heard about field operations to make it faster but dont know how to implement it. Can some one please shed some light on this matter. Thanks, Sanj |
I don't think there is a lot of alternative, but you can already simplify (read 'speed up') it a little bit by removing the identity alpha1[celli]=alpha1[celli]:
Code:
forAll(alpha1, celli) Cheers, L |
Try this:
alpha1 = max(min(alpha1,1.0), 0.0); |
Dear Liven and Anton,
Thanks for your swift responses. I appreciate taking the time to help me. Lieven: Yes thanks for the code it works perfectly but as you said it is still time expensive. Anotn: I understand that the max and min will bound the alpha1 values. But, how will it update each cell if celli is missing? Pardon me for my poor knowledge in openfoam and c++. Thanks, Sanj |
Foam functions are smart. Foam::min / Foam::max will see that you are passing a vol*Field and then automatically know to loop over all cells. You can completely throw out the forAll loop - just this single line will do.
|
Anton,
Thank you so much it worked like a charm!!! Sanj |
All times are GMT -4. The time now is 10:53. |