🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

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

User: "Clemenslischka"
Altair Community Member
Updated by Clemenslischka

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

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "RWood"
    Altair Employee
    Accepted Answer
    Updated by RWood

    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