Personal tools
You are here: Home / openCMISS / Wiki / Looping over nodes on distributed mesh
Navigation
Log in


Forgot your password?
 

Looping over nodes on distributed mesh

There are two ways to loop over all of the nodes local to the processor.

The first loops over every node in the mesh, ignoring nodes outside of my local scope. It is used as follows:

MeshBase::const_node_iterator       node_it  = mesh.nodes_begin();
const MeshBase::const_node_iterator node_end = mesh.nodes_end();

for ( ; node_it != node_end; ++node_it)
  {

    const Node* nd = *node_it;

    if( ( nd->dof_number(0,0,0) >= nu.first_local_index()) &&
        (nd->dof_number(0,0,0) <  nu.last_local_index()))
      {
        // Get current degree of freedom number
        const unsigned int dof_num = nd->dof_number(0,0,0);

        // Get iion term for updating vm and slow variable (nu)
        Real* iion = aliev_model.react(dof_num,soln(dof_num),nu(dof_num),dt);

        // Store Current Vm and Nu (slow variable) in temporary variable
        Real tmpu = soln(dof_num);
        Real tmpv = nu(dof_num);

        // Update with reaction Current Vm and Nu
        soln.set(dof_num,tmpu+(iion[0]/Cm));
        nu.set(dof_num,(tmpv+iion[1]));

      }
  }

The second only loops over my local nodes. It requires a recent CVS version of libmesh as it was only recently added. It is used as follows:

MeshBase::const_node_iterator       node_it  = mesh.local_nodes_begin();
const MeshBase::const_node_iterator node_end = mesh.local_nodes_end();

for ( ; node_it != node_end; ++node_it)
  {

    const Node* nd = *node_it;

    // Get current degree of freedom number
    const unsigned int dof_num = nd->dof_number(0,0,0);

    // Get iion term for updating vm and slow variable (nu)
    Real* iion = aliev_model.react(dof_num,soln(dof_num),nu(dof_num),dt);

    // Store Current Vm and Nu (slow variable) in temporary variable
    Real tmpu = soln(dof_num);
    Real tmpv = nu(dof_num);

    // Update with reaction Current Vm and Nu
    soln.set(dof_num,tmpu+(iion[0]/Cm));
    nu.set(dof_num,(tmpv+iion[1]));

  }