Coordinates of Each Component of a solution Vector

Asked by Pietro Maximoff

Hi

For a solution vector from a Function, i.e.,
Function solution(V);
*solution.vector()
Is there a way to obtain the coordinates of each component in 'exactly' the order in which they are set in the vector.

This is because I need to create objects based on coordinates of each component, carry out some manipulations and set the solution vector in exactly the correct(same) order.

Prior to the 1.1 release, I was able to do the following:

<START>

for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
      // create objects based on vertex coordinates
      // store objects in a std::vector
}

// Manipulate objects here

//Store solution values in correct order
double block[mesh.num_vertices()];
dolfin::uint rows[mesh.num_vertices()];
for (unsigned int i = 0; i < mesh.num_vertices(); ++i)
        rows[i] = i;

// Iterate through objects
for (...)
{
        //store solution in appropriate location
        block[i] = some_function();
}

Function new_solution(V)
new_solution.set(block, mesh.num_vertices(), rows);

</END>

Granted, this works only for P1 elements but now all my code is broken and I've been trying to fix it to no avail.

Is there a way I can do this?

Many thanks

Pietro

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

I am working on a function to tabulate this map. It will work for
elements which has dofs only on vertices. So also CG1 vector elements.
The syntax should look something like:

  vert_map = V.dofmap().tabulate_vertex_map(mesh)
  u = Function(V)
  u_verts = u.vector().array()[vert_map]

for Python and in C++ vert_map will be a std::vector<std::size_t>.

Johan

On 01/25/2013 11:11 PM, Pietro Maximoff wrote:
> New question #220174 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/220174
>
> Hi
>
> For a solution vector from a Function, i.e.,
> Function solution(V);
> *solution.vector()
> Is there a way to obtain the coordinates of each component in 'exactly' the order in which they are set in the vector.
>
> This is because I need to create objects based on coordinates of each component, carry out some manipulations and set the solution vector in exactly the correct(same) order.
>
> Prior to the 1.1 release, I was able to do the following:
>
> <START>
>
> for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
> // create objects based on vertex coordinates
> // store objects in a std::vector
> }
>
> // Manipulate objects here
>
> //Store solution values in correct order
> double block[mesh.num_vertices()];
> dolfin::uint rows[mesh.num_vertices()];
> for (unsigned int i = 0; i < mesh.num_vertices(); ++i)
> rows[i] = i;
>
> // Iterate through objects
> for (...)
> {
> //store solution in appropriate location
> block[i] = some_function();
> }
>
> Function new_solution(V)
> new_solution.set(block, mesh.num_vertices(), rows);
>
> </END>
>
> Granted, this works only for P1 elements but now all my code is broken and I've been trying to fix it to no avail.
>
> Is there a way I can do this?
>
> Many thanks
>
> Pietro
>
>

Revision history for this message
Pietro Maximoff (segment-x) said :
#2

Excellent!!!

I'd really appreciate it if you could let us know when it's done so I can download one of the snapshots.

Many thanks,

Pietro

Revision history for this message
Pietro Maximoff (segment-x) said :
#3

Hi Johan,

While you're working on the function, is there a way to revert to 1.0 via dorsal ?

Pietro

Can you help with this problem?

Provide an answer of your own, or ask Pietro Maximoff for more information if necessary.

To post a message you must log in.