<div dir="ltr"><div dir="ltr">On Fri, Aug 21, 2020 at 11:49 AM Smit Thijs <<a href="mailto:thijs.smit@hest.ethz.ch">thijs.smit@hest.ethz.ch</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="DE-CH">
<div class="gmail-m_6523791852542561519WordSection1">
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span lang="EN-GB">I am having the following error when I try to do a mapping with vectors and I can’t figure out how to solve this or what is going wrong:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)">error: invalid types ‘PetscScalar* {aka double*}[PetscScalar {aka double}]’ for array subscript<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> xpMMA[i] = xp[indicesMap[i]];<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">Herewith two code snippets:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // total number of elements on core<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)">
</span><span lang="IT" style="color:rgb(31,78,121)">PetscInt nel;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"> VecGetLocalSize(xPhys, &nel);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"> // create xPassive vector<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"> ierr = VecDuplicate(xPhys, &xPassive);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="color:rgb(31,78,121)">
</span><span lang="EN-GB" style="color:rgb(31,78,121)">// create mapping vector<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> ierr = VecDuplicate(xPhys, &indicator);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // index set for xPassive and indicator<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscScalar *xpPassive, *xpIndicator;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> ierr = VecGetArray(xPassive, &xpPassive);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> ierr = VecGetArray(indicator, &xpIndicator);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // counters for total and active elements on this processor<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscInt tcount = 0; // total number of elements<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscInt acount = 0; // number of active elements<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscInt scount = 0; // number of solid elements<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscInt rcount = 0; // number of rigid element<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // loop over all elements and update xPassive from wrapper data<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // count number of active elements, acount<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // set indicator vector<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> for (PetscInt el = 0; el < nel; el++) {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> if (data.xPassive_w.size() > 1) {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> xpPassive[el] = data.xPassive_w[el];<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> tcount++;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> if (xpPassive[el] < 0) {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> xpIndicator[acount] =
</span><span lang="EN-GB">el;<span style="color:rgb(31,78,121)"><u></u><u></u></span></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> acount++;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> }
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> } else {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> xpPassive[el] = -1.0; // default, if no xPassive_w than all elements are active = -1.0<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // printing<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> //PetscPrintf(PETSC_COMM_WORLD, "tcount: %i\n", tcount);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> //PetscPrintf(PETSC_COMM_WORLD, "acount: %i\n", acount);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // Allreduce, get number of active elements over all processes<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // tmp number of var on proces<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> // acount total number of var sumed<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> PetscInt tmp = acount;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> acount = 0.0;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> MPI_Allreduce(&tmp, &(acount), 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(31,78,121)"> //// create xMMA vector<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(31,78,121)">VecCreateMPI(PETSC_COMM_WORLD, tmp, acount, &xMMA);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> // Pointers to the vectors<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> PetscScalar *xp, *xpMMA, *indicesMap;</span></p></div></div></blockquote><div><br></div><div>Here you declare indicesMap as PetscScalar[]. You cannot index an array with this. I see that you</div><div>want to store these indices in a Vec. You should use an IS instead.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DE-CH"><div class="gmail-m_6523791852542561519WordSection1"><p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> //PetscInt indicesMap;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecGetArray(MMAVector, &xpMMA);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecGetArray(elementVector, &xp);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> // Index set<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> PetscInt nLocalVar;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> VecGetLocalSize(xMMA, &nLocalVar);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> // print number of var on pocessor<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> PetscPrintf(PETSC_COMM_WORLD, "Local var: %i\n", nLocalVar);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecGetArray(indicator,
</span><span lang="EN-GB">&indicesMap<span style="color:rgb(132,60,12)">);<u></u><u></u></span></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> // Run through the indices<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> for (PetscInt i = 0; i < nLocalVar; i++) {<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> if (updateDirection > 0) {<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> //PetscPrintf(PETSC_COMM_WORLD, "i: %i, xp[%i] = %f\n", i, indicesMap[i], xp[indicesMap[i]]);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> xpMMA[i] = xp[indicesMap[i]];<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> } else if (updateDirection < 0) {<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> xp[indicesMap[i]] = xpMMA[i];<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> //PetscPrintf(PETSC_COMM_WORLD, "i: %i, xp[%i] = %f\n", i, indicesMap[i], xp[indicesMap[i]]);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> // Restore<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecRestoreArray(elementVector, &xp);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecRestoreArray(MMAVector, &xpMMA);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> ierr = VecRestoreArray(indicator, &indicesMap);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> CHKERRQ(ierr);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:9.75pt"><span lang="EN-GB" style="color:rgb(132,60,12)"> PetscPrintf(PETSC_COMM_WORLD, "FINISHED UpdateVariables \n");<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(132,60,12)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">The error message says that the type with which I try to index is wrong, I think. But VecGetArray only excepts scalars. Furthermore, the el variable is an int, but is seams like to turn out to be a scalar. Does anybody
see how to proceed with this? <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(36,41,46)">Best regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(36,41,46)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:rgb(36,41,46)">Thijs Smit<u></u><u></u></span></p>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>