I check for whether the node is owned by a processor:

const unsigned int local_id      = elem->local_node(current_nodes[n]);
libmesh_assert (local_id < elem->n_nodes());

I close the solution and update it as well. The point is when I try accessing 
the solution vector later (after it has been set by this function), every 
element has a value of 0. All of this is even more confusing because like I 
said, when I write out the equation system using the write_equation_system 
function, the correct nodal values that were set are being outputted.

Regards
Amal

________________________________
From: John Peterson [[email protected]]
Sent: Wednesday, April 01, 2015 1:05 PM
To: Sahai, Amal
Cc: [email protected]; [email protected]
Subject: Re: [Libmesh-users] Solution vector



On Wed, Apr 1, 2015 at 10:57 AM, Sahai, Amal 
<[email protected]<mailto:[email protected]>> wrote:
I've been trying to figure this out for some time now and I really don't 
understand whats going on. I have a system called RAD which has been inherited 
from System class. I am setting values at node points using the following 
function:

void set_nodal_value(const Node *n, System& sys, unsigned int varnum, Real 
value)
{
    const unsigned int dof_index = n->dof_number(sys.number(), varnum, 0);
    sys.solution->set(dof_index, value);
}

Be careful doing this in parallel.  If dof_index is not owned by the current 
processor you probably don't want to call solution->set().  Also a small point 
is that you should catch dof_index as a dof_id_type, not an unsigned int.



The code which calls this looks like:

set_nodal_value(current_node, rad_system, r_distance_var, (*current_node - 
*first_node).size());

const unsigned int dof_index = current_node->dof_number(rad_system.number(), 
r_distance_var, 0);
std::cout<< dof_index <<"\t"<<(*rad_system.solution)(dof_index)<<"\n";

Right after assigning some value to a certain dof_index, when I try outputting 
the value at the same dof index in the solution vector (in the 2nd and 3rd 
lines), this value turns out to be zero. But later when I use the 
write_equation_systems command to write out a solution value, the values that I 
had previously assigned are written out.

Even after doing a system.solution->update, the solution vector seems to be 
comprised of only 0's.

Why is this happening?

When using PETSc, solution->set() calls VecSetValues() but doesn't call 
VecAssemblyBegin()/End().

As David said, calling close() on the vector triggers the call to 
VecAssemblyBegin()/End()

System::update() updates the current_local_solution to reflect values in the 
solution vector.

--
John
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to