Question about assign a value to custom property

Raheem Sterling_22160
Raheem Sterling_22160 Altair Community Member
edited July 2023 in Community Q&A

Hi,

I wrote some custom properties as below:

        m_NormalStressDelta[0] = 1.0;
        double tmp1 = m_NormalStress[0];

but when I debug the code, I saw the values of tmp changes from 0 to 1 to 2 etc. Increasing with time.

But what I want is to give a m_NormalStress a certain value, means 1.0 all the time. But seems that for m_NormalStress it was "+=‘’ with time, not "=" even I wrote like this.

Thanks

Tagged:

Answers

  • RWood
    RWood
    Altair Employee
    edited July 2023

    Hi,

    Custom property deltas are just that, deltas that are added to a value. There is no resetting of the value by default. In your case you're adding 1 to the value every time. If you want to reset the value to 0 before adding your delta, you can either do that in configForTimestep( ) or depending on how you're updating the delta, you can also do:

    delta = 1.0 - value;

    However, this only works if it's being called once. If there are multiple calls to update the custom property, then you should use the configForTimestep( )->resetCustomProperty approach.

    Richard

  • Stefan Pantaleev_21979
    Stefan Pantaleev_21979
    Altair Employee
    edited July 2023

    Hi Raheem,

     

    The delta gets added to the normal stress every time step so the normal stress is increasing by one each time step. The value of tmp1 is equal to the value of the normal stress so it is also increasing by 1 each time step.

    If you'd like to keep the normal stress constant you can set the delta to 1 - normal stress value:

    m_NormalStressDelta[0] = 1.0 - m_NormalStress[0]

    Best regards,

    Stefan

     

  • Raheem Sterling_22160
    Raheem Sterling_22160 Altair Community Member
    edited July 2023

    Hi,

    Custom property deltas are just that, deltas that are added to a value. There is no resetting of the value by default. In your case you're adding 1 to the value every time. If you want to reset the value to 0 before adding your delta, you can either do that in configForTimestep( ) or depending on how you're updating the delta, you can also do:

    delta = 1.0 - value;

    However, this only works if it's being called once. If there are multiple calls to update the custom property, then you should use the configForTimestep( )->resetCustomProperty approach.

    Richard

    Hi Richard,

    Thanks for answering, because I want to store the value of each contact between pair at every step which not calculated incrementally, I think the only way is used configForTimestep( )->resetCustomProperty. 

    Can this just reset the selected CustomProperty, or are there anly examples about this function?

    Regards!

    Raheem 

  • Raheem Sterling_22160
    Raheem Sterling_22160 Altair Community Member
    edited July 2023

    Hi Raheem,

     

    The delta gets added to the normal stress every time step so the normal stress is increasing by one each time step. The value of tmp1 is equal to the value of the normal stress so it is also increasing by 1 each time step.

    If you'd like to keep the normal stress constant you can set the delta to 1 - normal stress value:

    m_NormalStressDelta[0] = 1.0 - m_NormalStress[0]

    Best regards,

    Stefan

     

    Thanks Stefan,

    It helps a lot. But my normal stress dependent on the contact force at each timestep, I think retCustomProperty may be more appropriate, I am searching for examples about this function.

    Regards!

    Raheem