How to assign a value to customer particle property

Yangyang_Shen
Yangyang_Shen Altair Community Member
edited February 16 in Community Q&A

When writing an API, I know how to take the value from a customer property using the getValue function. My question is what function to use to assign a value to a customer property, while the value is calculated in the code? 

 

For example below, I use the "Particle Pore Filling" to calculate the "Particle Moisture". 

      const string CComputation::PARTICLE_POREFILLING = "Particle Pore Filling";

      const string CComputation::PARTICLE_MOISTURE = "Particle Moisture";

      const double* elem1PoreFilling = elem1PropData->getValue(PARTICLE_POREFILLING.c_str());

      double elem1Moisture = *elem1PoreFilling * elem1Mass;  

Then I want to assign the value of elem1Moisture to the PARTICLE_MOISTURE customer property. How can I do this? 

Any advice will be much appreciated! 

 

Tagged:

Best Answer

  • Richard Wood_20774
    Richard Wood_20774
    Altair Employee
    edited February 16 Answer ✓

    Hi,

    As you say, getValue( ) retrieves a custom property value. The corresponding function for changing the value of a cutstom property is through getDelta( ), as you can't change the value directly (it was implemented this way to be threadsafe). So if you want to change a custom property value, you do so through a delta. It's important to note though that, as the name suggests, this is just a delta/increment. So if you want to set an exact value, you must first subtract off its existing value. So the code will look something lilke:

    double* elem1Moisture_delta = elem1PropData->getDelta(PARTICLE_MOISTURE .c_str());
    const double* elem1Moisture_value = elem1PropData->getValue(PARTICLE_MOISTURE .c_str());

    double elem1Moisture = *elem1PoreFilling * elem1Mass;  

    *elem1Moisture_delta = elem1Moisture  - *elem1Moisture_value;

    Where the last line is changing the value of the custom property by adding on what I want it to be (elem1Moisture) but I also need to subtract the current value (*elem1Moisture_value).

    I'd recommend going through some of the API tutorials for more familiarity with custom properties.

    Cheers,

    Richard

Answers

  • Richard Wood_20774
    Richard Wood_20774
    Altair Employee
    edited February 16 Answer ✓

    Hi,

    As you say, getValue( ) retrieves a custom property value. The corresponding function for changing the value of a cutstom property is through getDelta( ), as you can't change the value directly (it was implemented this way to be threadsafe). So if you want to change a custom property value, you do so through a delta. It's important to note though that, as the name suggests, this is just a delta/increment. So if you want to set an exact value, you must first subtract off its existing value. So the code will look something lilke:

    double* elem1Moisture_delta = elem1PropData->getDelta(PARTICLE_MOISTURE .c_str());
    const double* elem1Moisture_value = elem1PropData->getValue(PARTICLE_MOISTURE .c_str());

    double elem1Moisture = *elem1PoreFilling * elem1Mass;  

    *elem1Moisture_delta = elem1Moisture  - *elem1Moisture_value;

    Where the last line is changing the value of the custom property by adding on what I want it to be (elem1Moisture) but I also need to subtract the current value (*elem1Moisture_value).

    I'd recommend going through some of the API tutorials for more familiarity with custom properties.

    Cheers,

    Richard

  • Yangyang_Shen
    Yangyang_Shen Altair Community Member
    edited February 16

    Thank you! It all makes sense.