Question about implementing screening distance through API

satri
satri Altair Community Member
edited October 23 in Community Q&A

Hello, I have created a contact model using contact radius to perform charge transfer operation. I am able to compute columbic force only up to a particular distance value that is the contact radius.

I want to calculate the electrostatic force experienced by a particle due to a particle that is outside the contact radius. (I cannot increase the contact radius)

Please tell me how to use the API. I do not want to use the inbuilt model.

I can think of two solutions but I don't know how the computational time will increase.

1) I can increase the contact radius to a large value and then put a condition on distance for charge transfer. I fear this will increase the computational time significantly

2) Have a contact radius of 1.2*Radius of particle and constantly write positions of other particles then calculate columbic force in the body force part. (Please tell me if I can achieve this?)

3) or is there any other method to achieve this?

Tagged:

Answers

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 16

    Hi Shyam,

    It's a challenging problem that I don't have a good answer to, so happy to hear other comments from the community.

    The contact radius is the simplest option, but will increase computational time as you say.

    In the Body Force option this does run through every particle in the simulation, but you don't get all the positions all the time.  So you would have to run one body force to then store all the particle positions in an array and then implement a second body force model to calculate forces based on positions.

     

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited October 16
    Is array the only data structure that I can use?

    Can I use a hash table or anything else instead with key being time stamp? Because array is ok for two particle when I have many particles I will run out of memory in my computer.... I would much rather run simulation slower than running out of memory.

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 16

    Is array the only data structure that I can use?

    Can I use a hash table or anything else instead with key being time stamp? Because array is ok for two particle when I have many particles I will run out of memory in my computer.... I would much rather run simulation slower than running out of memory.

    Hi Shyam,

    For CPU you should be free to use any C++ method, if you also want to implement on GPU you'll need to check that this is something that can be ported to CUDA.


    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited October 17

    Hey Stephen,

    I dont want to use GPU. I am only using CPU. So I have thought of a solution but I am not sure if I can execute it or not. please tell me if this is possible or not and I have a question regarding how to write a file output

    I have created a dummy velocity field

    image

    now I use your tutorial "EDEMAPI Tutorial 4 - Field Data Coupling." to read this dummy data and apply body force which is 0 force. so its not affecting my simulation and now I am writing the particle positions when I do this step so my data looks like this at every time step. (For now I have only two particles)

    these are the data you see

    image

    image

    now my problem is this this is writing all the data I want only that particular time step data in this file

    can you please suggest how I could potentially modify my code to do this?

    and also tell me one thing. Charge is a custom property. I will have zero value of charge in this initial time step. How can I write this custom property when it has not even been initiated?

    image

    The charge exchange process will begin when the two particles reach the center lines

    so if this works I can put the screening distance inside my body force API and look for particles inside that zone only at that particular time step. this way I can avoid complicated data structures like hash map or storing arrays. I want to store data of only that particular time step.

    so Stephen these are the two questions I have for you

    1) How can I store the data for that particular time?

    Note:

    If I open it in write mode

    image

    I will get data from only one particular particle

    image

    2) How to access the custom property that has not been initiated yet at all. And I want to access this in body force, not contact force -

    These are my charges

    imageimage

    I might have asked this before but my confusion is can I declare these custom properties exactly inside body force API even if they are not initiated yet in the contact API? If yes can I just copy the same definition and use it or does the syntax change. Please let me know

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 18

    Hey Stephen,

    I dont want to use GPU. I am only using CPU. So I have thought of a solution but I am not sure if I can execute it or not. please tell me if this is possible or not and I have a question regarding how to write a file output

    I have created a dummy velocity field

    image

    now I use your tutorial "EDEMAPI Tutorial 4 - Field Data Coupling." to read this dummy data and apply body force which is 0 force. so its not affecting my simulation and now I am writing the particle positions when I do this step so my data looks like this at every time step. (For now I have only two particles)

    these are the data you see

    image

    image

    now my problem is this this is writing all the data I want only that particular time step data in this file

    can you please suggest how I could potentially modify my code to do this?

    and also tell me one thing. Charge is a custom property. I will have zero value of charge in this initial time step. How can I write this custom property when it has not even been initiated?

    image

    The charge exchange process will begin when the two particles reach the center lines

    so if this works I can put the screening distance inside my body force API and look for particles inside that zone only at that particular time step. this way I can avoid complicated data structures like hash map or storing arrays. I want to store data of only that particular time step.

    so Stephen these are the two questions I have for you

    1) How can I store the data for that particular time?

    Note:

    If I open it in write mode

    image

    I will get data from only one particular particle

    image

    2) How to access the custom property that has not been initiated yet at all. And I want to access this in body force, not contact force -

    These are my charges

    imageimage

    I might have asked this before but my confusion is can I declare these custom properties exactly inside body force API even if they are not initiated yet in the contact API? If yes can I just copy the same definition and use it or does the syntax change. Please let me know

     Hi Shyam,

    "I want only that particular time step data in this file can you please suggest how I could potentially modify my code to do this?"

    You can specify a specific point in time to action this e.g.

        if (timeStepData.time == 1.0)     {      }

    Although in the above case the time has to be exactly 1.0 and if you don't have a time-step that is a regular value then it may not hit exactly 1.0, so could be 1.0 += timestep / 2.

    If you want this to happen on the first time-step you could use:

        if (timeStepData.time == timeStepData.timeStep)     {      }

    This is guaranteed to go into the brackets in and only in the first timestep, so you could add your code there.

     can I declare these custom properties exactly inside body force API even if they are not initiated yet in the contact API? If yes can I just copy the same definition and use it or does the syntax change

    Yes, so long as you define the custom properties with the same name, same data type, number of elements and units then you can use the same custom property in the body force and contact model.  

    Its also worth noting that writing to files on your PC can be tricky when considering multi-processors.  If you are running a simulation on more than 1 processor then this function may be called multiple times simultaneously, only once per contact but EDEM will process multiple contacts at the same time, so may also be writing multiple data sets to the same file simultaneously. Which if you do see that problem you can use the threadID function to just specify which thread to use to write to the file.

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited October 18

     Hi Shyam,

    "I want only that particular time step data in this file can you please suggest how I could potentially modify my code to do this?"

    You can specify a specific point in time to action this e.g.

        if (timeStepData.time == 1.0)     {      }

    Although in the above case the time has to be exactly 1.0 and if you don't have a time-step that is a regular value then it may not hit exactly 1.0, so could be 1.0 += timestep / 2.

    If you want this to happen on the first time-step you could use:

        if (timeStepData.time == timeStepData.timeStep)     {      }

    This is guaranteed to go into the brackets in and only in the first timestep, so you could add your code there.

     can I declare these custom properties exactly inside body force API even if they are not initiated yet in the contact API? If yes can I just copy the same definition and use it or does the syntax change

    Yes, so long as you define the custom properties with the same name, same data type, number of elements and units then you can use the same custom property in the body force and contact model.  

    Its also worth noting that writing to files on your PC can be tricky when considering multi-processors.  If you are running a simulation on more than 1 processor then this function may be called multiple times simultaneously, only once per contact but EDEM will process multiple contacts at the same time, so may also be writing multiple data sets to the same file simultaneously. Which if you do see that problem you can use the threadID function to just specify which thread to use to write to the file.

    Regards

    Stephen

    Hello Stephen,

    I am trying to do the custom particle function, and I think it will work.

    but I am not sure if the logic you suggested will work for writing file. because I don't have integer time and also I do not want to write only at a first time step. I want to write the position of the particles at every time step. but when I write I want to write the data of only that particular time step.

    Can you please suggest any other logic? i doubt this will work.

  • satri
    satri Altair Community Member
    edited October 18

    say I want to make the contact radius large and do my calculations. I am encountering a problem: my contact API becomes active only if the particles physically overlap. But I want it to start calculating the moment the contact radius starts overlapping 

    so what is the condition for that?

    In the API, I do not have any conditions for contact. i was under the impression the moment the contact radius overlaps the calculations start but this is not the case

    I only have this condition because I don't want the particles to go through each other so this will prevent that

        // Although a contact might exist, we may not have actual physical overlap.
        if (contact.normalPhysicalOverlap <= 0.0)
        {
            return eSuccess;
        }   

    So why is the contact thing not working? should I specify it explicitly

        if (contact.normalContactOverlap <= 0.0)
        {
            if distancebetweenParticles< 2*1.2*R

             { do charge transfer }
        }

    please tell me which is the right way  

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 18

    Hello Stephen,

    I am trying to do the custom particle function, and I think it will work.

    but I am not sure if the logic you suggested will work for writing file. because I don't have integer time and also I do not want to write only at a first time step. I want to write the position of the particles at every time step. but when I write I want to write the data of only that particular time step.

    Can you please suggest any other logic? i doubt this will work.

    Hi Shyam,


    The code will only write the data at the time-step you specify, it doesn't have access to previous positions.  The code you shared previously is writing the position at each time-step and appending the file constantly every time it's called.  So if you want the positions at a specific time point then you would have to use the if(time ..) option. You could set it to overwrite the existing data but better to just write the data when it's required.

     

    Regards

    Stephen

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 18

    say I want to make the contact radius large and do my calculations. I am encountering a problem: my contact API becomes active only if the particles physically overlap. But I want it to start calculating the moment the contact radius starts overlapping 

    so what is the condition for that?

    In the API, I do not have any conditions for contact. i was under the impression the moment the contact radius overlaps the calculations start but this is not the case

    I only have this condition because I don't want the particles to go through each other so this will prevent that

        // Although a contact might exist, we may not have actual physical overlap.
        if (contact.normalPhysicalOverlap <= 0.0)
        {
            return eSuccess;
        }   

    So why is the contact thing not working? should I specify it explicitly

        if (contact.normalContactOverlap <= 0.0)
        {
            if distancebetweenParticles< 2*1.2*R

             { do charge transfer }
        }

    please tell me which is the right way  

    Hi Shyam,


    The contact model is always called when the two contact radii overlap.  If the contact radius is larger than the physical radius then initially it will give a negative physical radius value.

        if (contact.normalContactOverlap <= 0.0)     {         if distancebetweenParticles< 2*1.2*R           { do charge transfer }     }

    This looks correct to me, the only thing to consider is that this will only happen when there is no physical contact (-ve physical overlap), as soon as normalContactOverlap > 0.0 the charge transfer won't happen as this code won't be called.

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited October 20

    Hello Stephen 

    so there are two methods

    1) use dummy field 

     

    2) use contact radius

    -> 

        if (contact.normalPhysicalOverlap <= 0.0)
        {
            return eSuccess;
        }   

    So why is the contact thing not working? should I specify it explicitly

        if (contact.normalContactOverlap <= 0.0)
        {
            if distancebetweenParticles< 2*1.2*R

             { do charge transfer }
        }

    (I will try method 2 later.)

    I have a problem I am encountering in method 1

    This is what I have for method 1. I am attaching 4 particles

    I have this custom property called as m_ChargeIndexPtKl_Delta2, which will change after running body force API four times (Because I have four particles)

    I think the variable names are confusing in the previous post. I have tried to simplify them

    image

    at stop point 1

    image

    at stop point 3

    image

    at stop point 4

    image

    at stop point 5

    image

    at stop point 8

    image

    at stop point 9

    image

    if you see at stop points 1, 3, and 4 and stop points 5, 8, and 9 the address of chargeIndexPtkl_DeltaDL changes please tell me how I can detect this change.

    I see general cpp tutorials about how to do (how to check if the address of a pointer has changed in c++) this but in all those cases I don't have to reset the pointer and re assign. here after one round of iteration if I define any variable it will get redefined in the next step. so I am confused as to how to solve this problem

  • satri
    satri Altair Community Member
    edited October 21

    Hello Stephen

    Can you please suggest how to mitigate this problem?

    Because I am not sure how to solve this

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 22

    Hello Stephen

    Can you please suggest how to mitigate this problem?

    Because I am not sure how to solve this

    Hi Shyam,


    I'm not clear on what the issue is here.  m_ChargeIndexPtKl_Delta2 is a Delta and this is initialised at 0.0  You are then setting the delta = simulation time , and from the screenshot the delta is equal to the time, which is different in the first and last screenshots.

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited October 22
    The problem is delta value gets reset after all four particles are initiated and also the address of delta changes after cycling through four particles which is exactly what I want. But the issue is how can I detect this change and put in a if condition? I want to compare either the values or address of the custom property m_ChargeIndexPtkl_Delta2 after four times. I tried to give. It as simulation property even there I am not able to understand how to detect the change.

    In a typical cpp file I can give a variable oroginalPointer and changedPointer and compare both how to apply this concept here

  • satri
    satri Altair Community Member
    edited October 22

    I am under the impression that with custom property, I can access previous time step information and this time step information. So, mainly, what I am trying to do is compare the time at which the custom property changed, and based on that, I am resetting the file.

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited October 23

    I am under the impression that with custom property, I can access previous time step information and this time step information. So, mainly, what I am trying to do is compare the time at which the custom property changed, and based on that, I am resetting the file.

    Hi Shyam,

    The custom properties only give you the current Value of the property.  At time=t you get given the value of the property at this time, this is the same as querying in-built properties such as Velocity or Mass.

    Delta's are only there to modify the values for the next time-step.  EDEM will give you the sum of all the Delta's + Value to give the value at the next time-step.

    Regards

    Stephen