<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 30, 2014 at 3:29 PM, Justin Chang <span dir="ltr"><<a href="mailto:jychang48@gmail.com" target="_blank">jychang48@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi all,<br><br></div>So I am writing an FEM code where it reads input data (e.g., auxiliary coefficients, source terms, etc) from a text file. I have preprocessed the data text file so that each vertex point has its corresponding data. For instance, if my source term for a diffusion problem has a sin or cos function of the coordinates, then this data is already tabulated and simply needs to be fed into my PETSc program. The data text file containing both the auxiliary data and the coordinate/connectivities will also be used to provide the input arguments for the DMPlexCreateFromDAG() function. <br><br></div>Normally, I would hard-code the sin/cos functions into the source code itself, but i want my program to be "universal" in that it can take as input any user-defined function for not only these auxiliaries but for other things like boundary conditions. I see that PETSc has a lot of examples on how to read data into vectors and matrices, but I guess my question is is there a way to project data from a text file into a vector that has already been created with a defined DM structure? <br></div></div></blockquote><div><br></div><div>If you have the functions available, I think it is far more universal to use the function itself, since then you can be independent</div><div>of mesh and discretization when specifying input and BC.</div><div><br></div><div>However, if you want to read it in, and you guarantee that it matches the mesh and discretization, I think the easiest thing to do is</div><div>demand that it come in the same order as the vertices and use</div><div><br></div><div>VecGetArray(V, &a);</div><div>for (v = vStart, i = 0; v < vEnd; ++v) {</div><div> PetscSectionGetDof(s, v, &dof);</div><div> PetscSectionGetOffset(s, v, &off);</div><div> for (d = 0; d < dof; ++d) a[off+d] = text_data[i++];</div><div>}</div><div>VecRestoreArray(V, &a);</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div></div><div>Thanks,<br>Justin<br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>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>