Author Topic: [SOLVED] GetDof method slowing down the DEM code.  (Read 905 times)

Miguel Angel Celigueta

  • Administrator
  • Newbie
  • *****
  • Posts: 38
[SOLVED] GetDof method slowing down the DEM code.
« on: April 01, 2016, 09:32:46 PM »
Hello all,
As you may know, for the DEM it is very important the performance of the application. We are using currnently using explicit methods, so every operation we do can have a significant cost if you are not cautious. In my pursuit of a decent speed, I have come across this little function that takes, according with the profiler, 10% of the total computation time:
(I use flags for performance, but I am still maintaining the Dofs to allow anyone to fix them from Python).

void ResetPrescribedMotionFlagsRespectingImposedDofs() {
        KRATOS_TRY
        ModelPart& r_model_part = BaseType::GetModelPart();

        NodesArrayType& r_model_part_nodes = r_model_part.Nodes();

        #pragma omp parallel for
        for (int i = 0; i < (int)r_model_part_nodes.size(); i++) {
            typename NodesArrayType::iterator node_i = r_model_part_nodes.ptr_begin() + i;
            if (node_i->Is(BLOCKED)) continue;
            Node<3>& node = *node_i;
           
            if (node.GetDof(VELOCITY_X).IsFixed())         {node.Set(DEMFlags::FIXED_VEL_X,true);}
            else                                           {node.Set(DEMFlags::FIXED_VEL_X,false);}
            if (node.GetDof(VELOCITY_Y).IsFixed())         {node.Set(DEMFlags::FIXED_VEL_Y,true);}
            else                                           {node.Set(DEMFlags::FIXED_VEL_Y,false);}
            if (node.GetDof(VELOCITY_Z).IsFixed())         {node.Set(DEMFlags::FIXED_VEL_Z,true);}
            else                                           {node.Set(DEMFlags::FIXED_VEL_Z,false);}
            if (node.GetDof(ANGULAR_VELOCITY_X).IsFixed()) {node.Set(DEMFlags::FIXED_ANG_VEL_X,true);}
            else                                           {node.Set(DEMFlags::FIXED_ANG_VEL_X,false);}
            if (node.GetDof(ANGULAR_VELOCITY_Y).IsFixed()) {node.Set(DEMFlags::FIXED_ANG_VEL_Y,true);}
            else                                           {node.Set(DEMFlags::FIXED_ANG_VEL_Y,false);}
            if (node.GetDof(ANGULAR_VELOCITY_Z).IsFixed()) {node.Set(DEMFlags::FIXED_ANG_VEL_Z,true);}
            else                                           {node.Set(DEMFlags::FIXED_ANG_VEL_Z,false);}         
        }
        KRATOS_CATCH("")
    }

The profiler says that most the time is spent on the method GetDof and Kratos::Flags::Set takes 0% of the total time.
Any ideas about how could I speed up this?

Thanks,
Miguel Angel
« Last Edit: April 02, 2016, 06:55:46 PM by Miguel Angel Celigueta »

riccardo

  • Global Moderator
  • Newbie
  • *****
  • Posts: 47
Re: GetDof method slowing down the DEM code.
« Reply #1 on: April 02, 2016, 06:20:59 PM »
Hi MA,
        looking for a dof inevitably incurs in a search penalty, which i guess is what is affecting you.

in order to minimize the search penalty you could modify your call to something like

GetDof(VELOCITY_X,vel_x_dof_position)

where you compute just once at the beginning the "vel_x_dof_position" as

const unsigned int vel_x_dof_position = (ModelPart.NodesBegin())->GetDofPosition(VELOCITY_X);

compute this outside of the loop and do not forget to define it as "firstprivate".


other than that a good solution is to manage to fixity by defining and calling a "Process" with this purpose from python...

cheers
Riccardo


Miguel Angel Celigueta

  • Administrator
  • Newbie
  • *****
  • Posts: 38
Re: GetDof method slowing down the DEM code.
« Reply #2 on: April 02, 2016, 06:55:10 PM »
Thanks Riccardo,
your trick worked like a charm!
Best regards,
Miguel Angel