meaning of : for (const auto& element : elements(fvGridGeometry->gridView())) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

10th Mar 2020, 2:53 PM
sara
sara - avatar
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.
10th Mar 2020, 3:38 PM
Shadow
Shadow - avatar
+ 1
Shadow : thank you so much for your answer
10th Mar 2020, 9:21 PM
sara
sara - avatar