How to define V2 bond creation time in custom factory?

QinHe_321
QinHe_321 Altair Community Member

How to define V2 bond creation time in custom factory?

Tagged:

Best Answers

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    Hi Qin,

    You need to create a CREATIONTIME Custom Particle Property in your API factory, the details are in the Help:

    https://help.altair.com/edem/topics/creator_tree_physics/the_bonding_v2_model_r.htm

    Also the particle replacement tutorial has an API factory which uses this custom property. The tutorial contains the CReplacementFactory.cpp where this custom property is defined:

    Regards

    Stephen

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    Hi,

    The Bond Creation Time is a Custom Property, so it has to be defined and then used.

    Using the example, for the definition:

    • In CReplacementFactory.h specify the name as a string, this is the name of the property in the code

    static const std::string CREATIONTIME;

    • In CReplacementFactory.cpp specify the name that will show up in the EDEM Creator and Analyst:

    const string CReplacementFactory::CREATIONTIME = "Bond Creation Time";

    • Also in CReplacementFactory.cpp define the number of custom properties (1) and the type. This is specifying that its a Particle custom property with 1 element and unit of time.
    unsigned int CReplacementFactory::getNumberOfRequiredProperties(
    const NApi::EPluginPropertyCategory category)
    {
    if (eParticle == category)
    {
    return 1;
    }
    else
    {
    return 0;
    }
    } bool CReplacementFactory::getDetailsForProperty(
    unsigned int propertyIndex,
    NApi::EPluginPropertyCategory category,
    char name[NApi::CUSTOM_PROP_MAX_NAME_LENGTH],
    NApi::EPluginPropertyDataTypes& dataType,
    unsigned int& numberOfElements,
    NApi::EPluginPropertyUnitTypes& unitType,
    char initValBuff[NApi::BUFF_SIZE])
    {
    if (0 == propertyIndex &&
    eParticle == category)
    {

    strncpy(name, CREATIONTIME.c_str(), NApi::CUSTOM_PROP_MAX_NAME_LENGTH);
    dataType = eDouble;
    numberOfElements = 1;
    unitType = eTime;

    return true;
    }
    else
    {
    return false;
    }
    }

    The above is all the definition of the property and you should not change this, as the definition needs to match what is set in the internal EDEM models.

    We then need to set the value of the property. The particles will bond when they are in contact and both particles in contact have the same value of CREATIONTIME property and that value also matches the current simulation time.

    So to change the code here instead of += time you can set it to += 10 if you wanted the particles to bond at 10 s, or add in a variable you can read from a text file.

    		double* m_bond_creation_time = propData->getDelta(CREATIONTIME.c_str());
    m_bond_creation_time[0] += time;

    Regards

    Stephen

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    You may also need to add the usesCustomProperties if this is not set to true:

    For the .cpp:

    bool CReplacementFactory::usesCustomProperties()
    {
    return true;
    }

    for the .h

    	virtual bool usesCustomProperties();
    

Answers

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    Hi Qin,

    You need to create a CREATIONTIME Custom Particle Property in your API factory, the details are in the Help:

    https://help.altair.com/edem/topics/creator_tree_physics/the_bonding_v2_model_r.htm

    Also the particle replacement tutorial has an API factory which uses this custom property. The tutorial contains the CReplacementFactory.cpp where this custom property is defined:

    Regards

    Stephen

  • QinHe_321
    QinHe_321 Altair Community Member

    Thank you, this should be the right direction.

    But I still has few confusion.

    bond creation time appears three times in the code, which one is decided one?

    why does bond creation time in string form, not double?

  • QinHe_321
    QinHe_321 Altair Community Member

    If I only need a constant bonding creation time, which part should I change?

  • QinHe_321
    QinHe_321 Altair Community Member
    		double* m_bond_creation_time = propData->getDelta(CREATIONTIME.c_str());
    m_bond_creation_time[0] += time;

    static const std::string CREATIONTIME;
    

    I do not understand how these two parts are connected, and the exact value of bonding time.

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    Hi,

    The Bond Creation Time is a Custom Property, so it has to be defined and then used.

    Using the example, for the definition:

    • In CReplacementFactory.h specify the name as a string, this is the name of the property in the code

    static const std::string CREATIONTIME;

    • In CReplacementFactory.cpp specify the name that will show up in the EDEM Creator and Analyst:

    const string CReplacementFactory::CREATIONTIME = "Bond Creation Time";

    • Also in CReplacementFactory.cpp define the number of custom properties (1) and the type. This is specifying that its a Particle custom property with 1 element and unit of time.
    unsigned int CReplacementFactory::getNumberOfRequiredProperties(
    const NApi::EPluginPropertyCategory category)
    {
    if (eParticle == category)
    {
    return 1;
    }
    else
    {
    return 0;
    }
    } bool CReplacementFactory::getDetailsForProperty(
    unsigned int propertyIndex,
    NApi::EPluginPropertyCategory category,
    char name[NApi::CUSTOM_PROP_MAX_NAME_LENGTH],
    NApi::EPluginPropertyDataTypes& dataType,
    unsigned int& numberOfElements,
    NApi::EPluginPropertyUnitTypes& unitType,
    char initValBuff[NApi::BUFF_SIZE])
    {
    if (0 == propertyIndex &&
    eParticle == category)
    {

    strncpy(name, CREATIONTIME.c_str(), NApi::CUSTOM_PROP_MAX_NAME_LENGTH);
    dataType = eDouble;
    numberOfElements = 1;
    unitType = eTime;

    return true;
    }
    else
    {
    return false;
    }
    }

    The above is all the definition of the property and you should not change this, as the definition needs to match what is set in the internal EDEM models.

    We then need to set the value of the property. The particles will bond when they are in contact and both particles in contact have the same value of CREATIONTIME property and that value also matches the current simulation time.

    So to change the code here instead of += time you can set it to += 10 if you wanted the particles to bond at 10 s, or add in a variable you can read from a text file.

    		double* m_bond_creation_time = propData->getDelta(CREATIONTIME.c_str());
    m_bond_creation_time[0] += time;

    Regards

    Stephen

  • QinHe_321
    QinHe_321 Altair Community Member

    The packing goes smoothly, but EDEM flash quit.

  • Stephen Cole
    Stephen Cole
    Altair Employee
    Answer ✓

    You may also need to add the usesCustomProperties if this is not set to true:

    For the .cpp:

    bool CReplacementFactory::usesCustomProperties()
    {
    return true;
    }

    for the .h

    	virtual bool usesCustomProperties();
    

  • QinHe_321
    QinHe_321 Altair Community Member

    yes, it works well now.

    Thank you sir.

  • QinHe_321
    QinHe_321 Altair Community Member

    something's wrong with this method, the bonding is no longer created after I change the bonding time few times.

  • QinHe_321
    QinHe_321 Altair Community Member

    any more clear and simple way to define bonding time? those twists and turns makes it fragile and easy to error.