0
meaning of : for (const auto& element : elements(fvGridGeometry->gridView()))
I'm new to programming. I have just started working on a modeling code written in C ++ and I am blocking certain lines (your help would be greatly appreciated), for example: for (const auto& element : elements(fvGridGeometry->gridView())) { const auto eIdx = fvGridGeometry->elementMapper().index(element); const auto globalPos = element.geometry().center(); K_[eIdx] = isInLens_(globalPos) ? KLens(rand) : K(rand); } Could someone literally translate the first line to me. Thank you
2 Answers
+ 4
"Perform the following steps on each element (which you promise not to modify) that is visible inside the grid." (I guessed the last part from the function name since I don't exactly know what the function call does).
Essentially, the syntax
for ( auto element : elements ) ...
simply lets you iterate over the set of objects contained in "elements", where the compiler automatically deduces the objects' type so you don't have to worry about it and the only restriction is that "elements" (the container) can actually be iterated over.
+ 1
Shadow : thank you so much for your answer