Odd problem with reference to cell centres
Hello all, suppose I have the following code
Code:
volScalarField ypos = mesh.C().component(1); Code:
const volScalarField& ypos = mesh.C().component(1); |
Hi Anton,
Possibly because the component method is giving a result as its own variable, not as a reference to the real variable. And the reference value is pointing to the variable space of the method itself. Although, if I found the correct method (source): Code:
00062 template<class Form, class Cmpt, int nCmpt> Which Gcc version are you using? It might influence this result you're getting, since this method is part of a template. Best regards, Bruno |
Thanks for digging in the code for me, I should have done that myself as a first step. The method returns "const Cmpt& v_[d];", which is part of the array "Cmpt v_[nCmpt];". I think it's not possible to reference an element within an array, I should have used a pointer. But I'll investigate further and report back.
I'm using gcc 4.4.6. |
Ok, so I still do not fully understand whats happening with the references, but I do now see that I was doing something very stupid :o
mesh.C().component(N) gives back a tmp field, which is already kind of a reference. I then forced unpacking of the tmp field by using () and was then able to copy over the reference. Of course this doesn't make sense. I conclude that finally the original formulation without any explicit reference/pointer-handling was already the optimal solution. |
I did think about "tmp" being the culprit here, but since I couldn't find it in a quick search via Doxygen, I simply didn't have the proof to point the finger :rolleyes:
|
All times are GMT -4. The time now is 14:26. |