How to pass a variable to a different __device__ in CUDA Code?

Clemenslischka
Clemenslischka Altair Community Member
edited February 2 in Community Q&A

Hi,

i'm sure it's a rather simple question but i need to calculate the contact forces between the geometry and all particles interacting with this geometry. I use the following code in the calculateForce device:

__device__
void calculateForce(NCudaApiTypesV1_0_0::CApiElement& element1,
    NCudaApiTypesV1_0_0::CApiElement& element2,
    NCudaApiTypesV1_0_0::CApiInteraction& interaction,
    NCudaApiTypesV1_0_0::CApiContact& contactData,
    NCudaApiTypesV1_0_0::CApiSimulation& simulationData,
    NCudaApiTypesV1_0_0::CApiContactResults& contactResult)
{  
    real ID                     = element1.getID();
    bool isPart                 = element2.isParticle();
    real normForce              = contactResult.getNormalForce().length();
    real tangForce              = contactResult.getTangentialForce().length();
    real totalForce             = normForce + tangForce;
    customPropReal* ForceDelta  = element2.getCustomPropertyDelta(0);
    const customPropReal* Force = element2.getCustomPropertyValue(0);

    if (ID >= REAL_CONST(13663.0) && ID <= REAL_CONST(61934.0) && isPart == true)
    //if (isPart == true)
    {
        ForceDelta[0] += totalForce;
    }
    return;
}

However i now need to use the momentary (cumulated) value of the contact force to scale my particles. I think this is only possible in the externalForce device as it has the setScale-function. How can i pass the cumulated total Force to externalForce and use it to scale my particles?

Thank you

Tagged:

Best Answer

  • RWood
    RWood
    Altair Employee
    edited February 2 Answer ✓

    Hi,

    Custom properties with the same name are the same custom property. By that I mean if you want to access your 'Force' custom property, that you have defined in your contact model, in a particle body force, then you simply need to setup the custom property again for a body force plugin. So if it's called "myForce" in the .cpp, register it again for a PBF plugin, access whatever the correct index is in externalForce( ) in the .cu file and use the value there.

    Cheers,

    Richard

Answers

  • RWood
    RWood
    Altair Employee
    edited February 2 Answer ✓

    Hi,

    Custom properties with the same name are the same custom property. By that I mean if you want to access your 'Force' custom property, that you have defined in your contact model, in a particle body force, then you simply need to setup the custom property again for a body force plugin. So if it's called "myForce" in the .cpp, register it again for a PBF plugin, access whatever the correct index is in externalForce( ) in the .cu file and use the value there.

    Cheers,

    Richard

  • Clemenslischka
    Clemenslischka Altair Community Member
    edited January 31

    Hi Richard,

    thanks seems to work just fine!

    Is there a function to access the geometry directly and not via the ID function? I found a getTypeIndex (Returns the index of the particletype/geometry group. ) function but i don't know the index of my geometry group. Where can i find that?

     

    Thank you

     

  • RWood
    RWood
    Altair Employee
    edited February 1

    Hi Richard,

    thanks seems to work just fine!

    Is there a function to access the geometry directly and not via the ID function? I found a getTypeIndex (Returns the index of the particletype/geometry group. ) function but i don't know the index of my geometry group. Where can i find that?

     

    Thank you

     

    Hi,

    On CPU, through the geometryManager( ) you can access quite a few different helper functions. I think the one you're going to want to use is:

    image

    So what I'd do is something like:
    1) Declare a member variable in my plugin to hold the manager, so I can use it anywhere in your plugin

    2) Initialise it in starting( ), with something like the following (although this is for a different manager that I'm using in the plugin I'm working on)
    image

    3) Pass in your geometry/geometries to the get geometry index call for whichever geometries you want. There is also a function to get all your geometry names in the manager too, to simplify this

    image

    4) Once you know which index is which, pass it across to the GPU through one of the parameterData functions and use it how you need.

    Hopefully that makes sense, though I realise it's a little convoluted.

    Cheers,

    Richard

    Edit: I'm using v1.4 of the geometry manager here. Depending on which version of EDEM/the API you're using, you might not have all these functions.

  • Clemenslischka
    Clemenslischka Altair Community Member
    edited February 2

    Hi,

    On CPU, through the geometryManager( ) you can access quite a few different helper functions. I think the one you're going to want to use is:

    image

    So what I'd do is something like:
    1) Declare a member variable in my plugin to hold the manager, so I can use it anywhere in your plugin

    2) Initialise it in starting( ), with something like the following (although this is for a different manager that I'm using in the plugin I'm working on)
    image

    3) Pass in your geometry/geometries to the get geometry index call for whichever geometries you want. There is also a function to get all your geometry names in the manager too, to simplify this

    image

    4) Once you know which index is which, pass it across to the GPU through one of the parameterData functions and use it how you need.

    Hopefully that makes sense, though I realise it's a little convoluted.

    Cheers,

    Richard

    Edit: I'm using v1.4 of the geometry manager here. Depending on which version of EDEM/the API you're using, you might not have all these functions.

    Thank you Richard, very much appreciate your help and answer.

    I ended up using the ID and isParticle function approach, as it is working with CUDA as well. I forgot that "element.1" is always a particle, so it gave me weird results in the first run..

    Works now!

    Regards

  • RWood
    RWood
    Altair Employee
    edited February 2

    Thank you Richard, very much appreciate your help and answer.

    I ended up using the ID and isParticle function approach, as it is working with CUDA as well. I forgot that "element.1" is always a particle, so it gave me weird results in the first run..

    Works now!

    Regards

    Glad to hear you got it working :)