[Libmesh-users] Finding solution at a node From: David Knezevic - 2006-06-05 22:43 ```Hi all, In an application I am iterating over the nodes of a mesh and I want to find the value of the solution at each node (I am using Lagrange elements). I would like to use the node id number to index directly into the global solution vector, but the difficulty is that I have 3 variables in this system. Is there a simple way to do this? Are the dofs in the solution vector are organised in a way that would be easy to index (I'm not sure where to look in the library source to find out myself...), e.g. can I do something like this: var1 = system.current_solution(node->id()); var2 = system.current_solution(2*node->id()); var3 = system.current_solution(3*node->id()); This is just a guess, maybe I'm way off...? My naive alternative approach would be to locate which element the node is in (using PointLocatorTree) and then update a dof_indices vector for each variable so that I can access the appropriate entries of the solution vector. This seems ungainly though. Thanks, David ```
 Re: [Libmesh-users] Finding solution at a node From: Roy Stogner - 2006-06-06 02:53 ```On Mon, 5 Jun 2006, David Knezevic wrote: > In an application I am iterating over the nodes of a mesh and I want > to find the value of the solution at each node (I am using Lagrange > elements). > > I would like to use the node id number to index directly into the > global solution vector, but the difficulty is that I have 3 variables > in this system. Is there a simple way to do this? Not only is it not simple, for many common combinations of geometric and finite element it's not possible, even with Lagrange elements. Take a mixed biquadratic pressure / bilinear velocity element, for example - how do you get the pressure DoF index at the midedge nodes? You can't, because pressure DoFs are only on vertex nodes. If you're certain that the node you're looking at has the degree of freedom you're looking for, then it's possible to extract the global degree of freedom number directly from the node - I've had to put some such ugly hacks in system_projection.C, I think. But the best solution is usually to first iterate over elements, then iterate over the local nodes on each element. Presumably you're putting the results of your per-node calculations into some vector which you can also use to avoid working on the same node twice. Once you've got an element associated with each node you're working on, you can then use dof_indices() and FEInterface::shape() to build variable values that will be correct regardless of finite element and geometric element type. --- Roy ```
 [Libmesh-users] Finding solution at a node From: John Peterson - 2006-06-06 03:05 ```David Knezevic writes: > Hi all, > > In an application I am iterating over the nodes of a mesh and I want > to find the value of the solution at each node (I am using Lagrange > elements). > > I would like to use the node id number to index directly into the > global solution vector, but the difficulty is that I have 3 variables > in this system. Is there a simple way to do this? Are the dofs in the > solution vector are organised in a way that would be easy to index > (I'm not sure where to look in the library source to find out > myself...), e.g. can I do something like this: > > var1 = system.current_solution(node->id()); > var2 = system.current_solution(2*node->id()); > var3 = system.current_solution(3*node->id()); > > This is just a guess, maybe I'm way off...? Something like this would probably work for Lagrange elements. See src/mesh/gmv_io.C line 469.... Although I can't see any obvious problems, I'd still double-check everything and be careful :) > My naive alternative approach would be to locate which element the > node is in (using PointLocatorTree) and then update a dof_indices > vector for each variable so that I can access the appropriate entries > of the solution vector. This seems ungainly though. > ```
 Re: [Libmesh-users] Finding solution at a node From: Roy Stogner - 2006-06-06 05:25 ```On Mon, 5 Jun 2006, John Peterson wrote: > David Knezevic writes: > > var1 = system.current_solution(node->id()); > > var2 = system.current_solution(2*node->id()); > > var3 = system.current_solution(3*node->id()); > > > > This is just a guess, maybe I'm way off...? > > Something like this would probably work for Lagrange elements. > > See src/mesh/gmv_io.C line 469.... > > Although I can't see any obvious problems, I'd still double-check > everything and be careful :) I see one obvious problem - the vector "v" being handled in that function is not a standard libMesh coefficient vector, it's something that's been processed. It looks like it's created in EquationSystems::build_solution_vector(), which loops over elements and uses FEInterface::nodal_soln() on each. I'd forgotten nodal_soln() exists, but I think I recall upgrading some of the non-Lagrange elements to support it correctly. David, you might want to give that a look. --- Roy ```