<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 24, 2014 at 11:31 AM, Miguel Angel Salazar de Troya <span dir="ltr"><<a href="mailto:salazardetroya@gmail.com" target="_blank">salazardetroya@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">Thanks for your response. My discretization is based on spring elements. For the linear one dimensional case in which each spring has a coefficient k, their jacobian would be this two by two matrix.<div><br></div><div>[ k -k ]</div><div>[ -k k ]</div><div><br></div><div>and the internal force</div><div><br></div><div>[ k ( Ui - Uj) ]</div><div>[ k ( Uj - Ui) ]</div><div><br></div><div>where Ui and Uj are the node displacements (just one displacement per node because it's one dimensional)</div><div><br></div><div>For the two dimensional case, assuming small deformations, we have a four-by-four matrix. Each node has two degrees of freedom. We obtain it by performing the outer product of the vector (t , -t) where "t" is the vector that connects both nodes in a spring. This is for the case of small deformations. I would need to assemble each spring contribution to the jacobian and the residual like they were finite elements. The springs share nodes, that's how they are connected. This example is just the linear case, I will have to implement a nonlinear case in a similar fashion.</div><div><br></div><div>Seeing the DMNetwork example, I think it's what I need, although I don't know much of power electric grids and it's hard for me to understand what's going on. Do you have a good reference to be able to follow the code? For example, why are they adding components to the edges?</div></div></blockquote><div><br></div><div>Okay, I understand what you want now. I would recommend doing a simple example by hand first. The PetscSection is very simple,</div><div>just 'dim' degrees of freedom for each vertex. It should look something like</div><div><br></div><div>DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);</div><div>PetscSectionCreate(comm, &s);</div><div>PetscSectionSetNumFields(s, 1);</div><div>PetscSectionSetChart(s, vStart, vEnd);</div><div>for (v = vStart; v < vEnd; ++v) {</div><div> PetscSectionSetDof(s, v, dim);</div><div>}</div><div>PetscSectionSetUp(s);</div><div>DMSetDefaultSection(dm, s);</div><div>PetscSectionDestroy(&s);</div><div><br></div><div>Then when you form the residual, you loop over edges and add a contribution to each vertex (I think, its still not</div><div>clear to me how your residual is defined)</div><div><br></div><div>VecGetArray(locF, &residual);</div><div>DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);</div><div>for (c = cStart; c < cEnd; ++c) {</div><div> const PetscInt *cone;</div><div> PetscInt offA, offB;</div><div><br></div><div> DMPlexGetCone(c, &cone);</div><div> PetscSectionGetOffset(s, cone[0], &offA);</div><div> PetscSectionGetOffset(s, cone[1], &offB);</div><div> residual[offA] = <contribution for vertex A>;</div><div> residual[offB] = <contribution for vertex B>;</div><div>}</div><div>VecRestoreArray(locF, &residual);</div><div><do LocalToGlobal unless PETSc is doing it for you></div><div><br></div><div>After that works, using DMNetwork should be much easier.</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-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><pre width="80" style="color:rgb(0,0,0)"><a name="148a8814bcba5062_line475">475: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-as/petsc-current/docs/manualpages/DM/DMNetworkAddComponent.html#DMNetworkAddComponent" target="_blank">DMNetworkAddComponent</a>(networkdm,i,componentkey[0],&pfdata.branch[i-eStart]);</pre><pre width="80" style="color:rgb(0,0,0)">Miguel</pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 23, 2014 at 11:13 PM, Abhyankar, Shrirang G. <span dir="ltr"><<a href="mailto:abhyshr@mcs.anl.gov" target="_blank">abhyshr@mcs.anl.gov</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">You may also want to take a look at the DMNetwork framework that can be<br>
used for general unstructured networks that don't use PDEs. Its<br>
description is given in the manual and an example is in<br>
src/snes/examples/tutorials/network/pflow.<br>
<br>
Shri<br>
<br>
From: Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
Date: Tue, 23 Sep 2014 22:40:52 -0400<br>
To: Miguel Angel Salazar de Troya <<a href="mailto:salazardetroya@gmail.com" target="_blank">salazardetroya@gmail.com</a>><br>
Cc: "<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>" <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
Subject: Re: [petsc-users] DMPlex with spring elements<br>
<div><div><br>
<br>
>On Tue, Sep 23, 2014 at 4:01 PM, Miguel Angel Salazar de Troya<br>
><<a href="mailto:salazardetroya@gmail.com" target="_blank">salazardetroya@gmail.com</a>> wrote:<br>
><br>
>Hi all<br>
>I was wondering if it could be possible to build a model similar to the<br>
>example snes/ex12.c, but with spring elements (for elasticity) instead of<br>
>simplicial elements. Spring elements in a grid, therefore each element<br>
>would have two nodes and each node two components. There would be more<br>
>differences, because instead of calling the functions f0,f1,g0,g1,g2 and<br>
>g3 to build the residual and the jacobian, I would call a routine that<br>
>would build the residual vector and the jacobian matrix directly. I would<br>
>not have shape functions whatsoever. My problem is discrete, I don't have<br>
>a PDE and my equations are algebraic. What is the best way in petsc to<br>
>solve this problem? Is there any example that I can follow? Thanks in<br>
>advance<br>
><br>
><br>
><br>
><br>
>Yes, ex12 is fairly specific to FEM. However, I think the right tools for<br>
>what you want are<br>
>DMPlex and PetscSection. Here is how I would proceed:<br>
><br>
> 1) Make a DMPlex that encodes a simple network that you wish to simulate<br>
><br>
> 2) Make a PetscSection that gets the data layout right. Its hard from<br>
>the above<br>
> for me to understand where you degrees of freedom actually are.<br>
>This is usually<br>
> the hard part.<br>
><br>
> 3) Calculate the residual, so you can check an exact solution. Here you<br>
>use the<br>
> PetscSectionGetDof/Offset() for each mesh piece that you are<br>
>interested in. Again,<br>
> its hard to be more specific when I do not understand your<br>
>discretization.<br>
><br>
> Thanks,<br>
><br>
> Matt<br>
><br>
><br>
>Miguel<br>
><br>
><br>
><br>
>--<br>
>Miguel Angel Salazar de Troya<br>
>Graduate Research Assistant<br>
>Department of Mechanical Science and Engineering<br>
>University of Illinois at Urbana-Champaign<br>
</div></div>><a href="tel:%28217%29%20550-2360" value="+12175502360" target="_blank">(217) 550-2360</a> <tel:%28217%29%20550-2360><br>
<div><div>><a href="mailto:salaza11@illinois.edu" target="_blank">salaza11@illinois.edu</a><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
>--<br>
>What most experimenters take for granted before they begin their<br>
>experiments is infinitely more interesting than any results to which<br>
>their experiments lead.<br>
>-- Norbert Wiener<br>
<br><span class=""><font color="#888888">
</font></span></div></div></blockquote></div><span class=""><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><font face="verdana, sans-serif"><b>Miguel Angel Salazar de Troya</b></font><span><font color="#888888"><br><font face="arial,helvetica,sans-serif">Graduate Research Assistant<br>Department of Mechanical Science and Engineering<br></font>University of Illinois at Urbana-Champaign<br><a href="tel:%28217%29%20550-2360" value="+12175502360" target="_blank">(217) 550-2360</a><br>
<a href="mailto:salaza11@illinois.edu" target="_blank">salaza11@illinois.edu</a></font></span><div><br></div></div>
</font></span></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>