|
[Sponsors] |
March 11, 2021, 13:02 |
controlDict function coded
|
#1 |
New Member
Mahdi
Join Date: May 2020
Posts: 10
Rep Power: 5 |
Hi Guys,
I have been trying to add a small function at the end of controlDict to calculate \int(alpha.dv) above and below the line y=0 in my geometry. So I have put an "if" condition to separate y=0 and then the integral will be simply sum of alpha*Cellvolume. The codes works fine, but it produces different results when I am running it in a "single core" or when it is run in "parallel". REALLY ODD! I have used other functions both in parallel and in single core with the same solver and none of them have this issue. Am I missing something here? Does anyone have any idea what I am doing wrong? the code is provided bellow: functions { Wout { functionObjectLibs ("libutilityFunctionObjects.so"); type coded; redirectType calCd; writeControl timeStep; writeInterval 10; enabled yes; codeWrite #{ // Lookup/create variables const volScalarField& alpha1 = mesh().lookupObject<volScalarField>("alpha"); const volVectorField& C = mesh().C(); const scalarField& volume = mesh().V(); scalar totalVolumeUp(0.0); scalar totalVolumeDown(0.0); forAll(C,idx) { if (C[idx].component(1)>0) { totalVolumeUp += volume[idx]*alpha1[idx]; } if (C[idx].component(1)<0) { totalVolumeDown += volume[idx]*alpha1[idx]; } } scalarList list; list.append(mesh().time().value()); // Time (col 0) list.append(totalVolumeUp); // vol up (col 1) list.append(totalVolumeDown); // vol down (col 2) list.append(totalVolumeDown+totalVolumeUp); // sum vol (col 3) list.append((totalVolumeDown-totalVolumeUp)/(totalVolumeDown+totalVolumeUp)); //the lifting parameter (col 4) // Write data string comsh; string filename("LiftingParameter.txt"); std::stringstream doub2str; doub2str.precision(18); comsh = "./writeData " + filename; forAll(list, id) { doub2str.str(std::string()); doub2str << list[id]; comsh += " " + doub2str.str(); } if (Pstream::master()) { system(comsh); } #}; } } Last edited by M.Davoodi; March 12, 2021 at 04:01. |
|
March 12, 2021, 04:44 |
|
#2 | |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14 |
Quote:
|
||
March 12, 2021, 05:15 |
|
#3 | |
New Member
Mahdi
Join Date: May 2020
Posts: 10
Rep Power: 5 |
Quote:
Thanks for your reply. This is exactly what I was thinking and was worries about. I agree gsum would be an excellent choice but I am not sure if there is a way that I can use the "if" condition to separate the line y=0 in combination with gsum. Are you aware of a way for doing this? Cheers |
||
March 12, 2021, 07:14 |
|
#4 |
New Member
Giovanni Luddeni
Join Date: Jan 2021
Posts: 14
Rep Power: 5 |
I'm not sure if it's relevant, but you could try to implement the function in the solver itself.
I had a similar issue, where I needed to evaluate the maximum of a field in a BC: doing it in the BC itself would lead to the maximum being evaluated in the partial domain only, while doing it in the solver solved the problem. I know it doesn't answer your question, but might be an alternative way to achieve what you need. |
|
March 12, 2021, 08:06 |
|
#5 | |
New Member
Mahdi
Join Date: May 2020
Posts: 10
Rep Power: 5 |
Quote:
Thanks for the response. I actually managed to sort the issue out by adding this line at the end of the forAll loop condition: reduce(totalVolumeDown, sumOp<scalar>());// Sync sum across processors You might find it helpful too |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 17:22 |
Coded function object in openfoam v5 | kit607 | OpenFOAM Post-Processing | 3 | September 29, 2020 15:43 |
Unknown character in name of output variable when using coded function object | pvergnol | OpenFOAM Post-Processing | 5 | August 12, 2020 13:29 |
Compilation errors in ThirdPartymallochoard | feng_w | OpenFOAM Installation | 1 | January 25, 2009 06:59 |
Problem with compile the setParabolicInlet | ivanyao | OpenFOAM Running, Solving & CFD | 6 | September 5, 2008 20:50 |