Fill a volScalarField
I start to try to programming in OF only in the last month, so sorry if I ask some stupid things.
I have created a volScalarField and with a boolList I want fill the value inside each cells. In particular if the bool is equal true, the cell value should be 1 otherwise should be 0.
I post the volScalarField costructor:
and the costructor of the boolList:
boolList zoneCell(mesh_.nCells(), false);
const labelList& cellLabels = mesh_.cellZones()[cellZoneID_];
zoneCell[cellLabels[i]] = true;
obviously mesh_ is a reference to the fvMesh.
If someone can help me I'll be very great-full.
I'm agree with you David, the reason is simply that I'm modifying a pre-exist class so for the moment I prefer to don't change much the original code.
In any case your way to fill the alfa is use-full, so thank you very much.
Would you not loose the conditional variable setting by setting alfa directly?? The idea was to set alfa = 1 if the value of the boolList was true and 0 if it was false no?
The explicit looping itself is not a problem performance-wise. The looping is implemented in a way that makes it extremely fast.
Yes, but my impression is that boollist is only true in cells that are members of the cellLabels, so unless he needs boollist for some other reason as well, it's more direct to just set alfa based on the cellLabels list and skip the intermediate step. Maybe I'm reading his code wrong.
As far as avoiding the loop, I just thought it would be clever if there was a way to cast the entire boolList into a scalarList in one command. I feel like a failure every time I have to explicitly code a loop into OpenFOAM. :)
By the way, if zoneCell is the boolList containing the true and false values, and it has the same number of elements as alfa, could you not try:
Hum... I focused more on the explanation of what he was trying to do than on the code he provided.. But code-wise I can only agree!
As for the explicit looping there is a possibility of avoiding the looping when doing operations among similar data types when using the +, -, *, /, = and == operators. What I understood from Hrvoje was that the different operators have been overloaded quite powerfully, and could, in some cases, even do a variable re-sizing automatically if necessary. But for very specific details, you should refer to the source code because I'm afraid I did not memorize all the examples he was giving :o.. They were coming quite fast in a very short period of time..
The operator overloadings are sometimes also kind enough to allows inter-data operations without looping I noticed.
And downcasting also works quite well from personal experience. (like casting a volScalarField into a scalarField/scalarList.)
I hope it helps!
Ps: I feel the same way about every explicit code loop I implement..... :P
|All times are GMT -4. The time now is 09:36.|