How to Export Particle History Data every Particle Time Step

LumonoLumono Member Posts: 1

Hello everyone,

I am simulating discrete particles and I am interested in the particle-particle collisions. Therefore, I am using the DEM collision model available in Fluent. This forces me to work with instationary particles (although I am looking for a steady solution, where the particle collisions dictate the spread).

My idea is to inject particles, until the fluid and the particles have achieved a steady state.

Due to the use of the DEM model, and the collisions between different sized particles, I am forced to use a very small particle time step size (10^-8) in order to get “physical” collisions/the right overlap.

Since I am continuously injecting particles, the simulation would be too slow if I had 1 particle time step for each fluid time step, so I increased the number of particle iterations per time step to speed the process up.

Desirable would be e.g. a number of Time Steps=1e6 for particle time step size 1e-8 so that I get 0,01sec simulation time with only one fluid iteration.

So far, I have worked out a solution that fits my needs:

Setup->General->Time: Steady

Setup->Models->Discrete Phase (On)

Discrete Phase Model:

               Interaction with Continuous Phase (On)

               DPM Iteration Interval: 1

Unsteady Particle Tracking (On)

Particle Time Step Size: 1e-8

Number of Time Steps: 1e6

Physical Models->DEM Collision (On)

Injections:

               File Injection using a unsteady file.inj as described in the Manual

               Start Time: 0

               Stop Time: 5

               Start Flow-time in File: 0

               Repeat Interval in File: 1e-6 (so that a new particle is injected every particle time step)

Run Calculation -> Number of Iterations: 1

 

The simulation runs as desired and is obviously much faster than the setup (Particle Time Step Size:1e-8/No of Steps:1/DPM Iteration Interval:1/Number of (Fluid) Iterations:1e6).

 

However, I encounter problems when it comes to view the results:

I want to investigate the collisions etc. in CFD-Post and therefore I want to export the particle history data.

The way Solution->Calculation Activities->Automatic Export -> Create Particle History Data Export does not work for me, since it only is executed every fluid time step.

I do not need an export every fluid time step but every (nth) Particle Time Step, because I want to visualize the collisions and particle trajectories properly.

I could increase the number of fluid time steps and decrease number of particle time steps but this would slow down my simulation.

Furthermore, it seems possible with a transient simulation, but this is also not what I want.

 

I made two more ideas to approach a solution but was not successful with them:

1.)

I had the idea to use an UDF, more accurate the “DEFINE_DPM_SCALAR_UPDATE” and in this UDF execute the following scheme text command:

(ti-menu-load-string

(format #f "file/export/particle-history-data cfdpost tracktest injection-0 , acc-total-mag force-coll-mag force-total-mag , ,"))

But I get a compiling error when trying it.

I read that it is eventually not possible to execute TI-commands by UDF.

It might be an option to export the data to a .txt file, e.g. like this:

https://www.cfd-online.com/Forums/fluent-udf/215456-udf-current-particle-position.html

#include "udf.h"

#include "dpm.h"


DEFINE_DPM_SCALAR_UPDATE(gpif,c,t,initialize,p)

{

int n;

n = N_TIME;

char filename[50];

real current_time = CURRENT_TIME;

snprintf(filename,50,"particleposition_%d.txt",n);

FILE *fid1;

fid1 = fopen(filename,"a");

if (P_TIME(p) == CURRENT_TIME)

{

fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);

}

else

{

printf("time is not reached");

}

fclose(fid1);

}

 but then I cannot use it in CFD-Post. Maybe there would be a way if someone knows the structure of the .xml files - I could not find any documentation on that.


2.)

Inspired by this discussion: https://www.cfd-online.com/Forums/fluent/34386-getting-data-injected-particles.html

Print the data in a file/console using:

Solution -> Particle Tracks->Reporting->Report Type:Current Positions -> Report to: File/Console

Here, my problems were, that I only was able to print the data of the current time step in the console. Also, the possible file type is not .xml and not readable in cfdpost either.

 

Is there a possible solution to get the particle data exported for every particle time step or do you possibly have other suggestions without getting huge simulation times?

Thanks a lot in advance, any advice is highly appreciated!

Comments

  • LumonoLumono Posts: 4Member
    edited June 13

    Update: I did some more research about an possible UDF-solution.

    Preferably I would do something like this:

    #include "udf.h"
    #include "dpm.h"
    #include "cx.h"
    
    DEFINE_DPM_SCALAR_UPDATE(partikeldatacreator,c,t,initialize,p)
    {
    CX_Interpret_String((format #f "file/export/particle-history-data cfdpost tracktest injection-0 , acc-total-mag force-coll-mag force-total-mag , ,"))
    }
    

    I am able to compile this UDF but it seems like it cannot access the environment. When I start the simulation the error "unbound Variable" is printed in the console.

    I have found some old forum discussions (2006/2013) on the topic "use tui-commands via UDF" stating that back then, no way was known to call a tui-command by an UDF.

    Even though I wonder if this is possible now, since quite a bit time has passed since then?

    Or, like written in my first post, if there is any other possible way?

  • DrAmineDrAmine GermanyPosts: 7,186Forum Coordinator

    I think you can try to write from DPM_SCALAR_UPDATE to write the information into file (or DEFINE_DPM_OUTPUT) but you cannot use the TUI commands from UDF: forget about that. You cannot however visualize it in CFD-Post.

  • LumonoLumono Posts: 4Member

    Thank you for your reply!

    Okay, so it seems like there is no solution for my preferred idea to export the particle data every particle step without setting the number of particle steps= 1 per fluid iteration.

    For the UDF, I have a (working) sample:

    #include "udf.h"
    #include "dpm.h"
    
    DEFINE_DPM_SCALAR_UPDATE(partikeldatenersteller,c,t,initialize,p)
    {
    int n;
    n = 1;
    char filename[50];
    snprintf(filename,50,"particleposition_%d.txt",n);
    FILE *fid1;
    fid1 = fopen(filename,"a");
    fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);
    fclose(fid1);
    }
    

    Are there macros to access the other particle variables like collision force magnitude/ total acceleration magnitude/... in order to print them to the text file as well?

    In the UDF Guide I have only found documentation about (position x,y,z, velocity u,v,w, diameter and a few more).

  • DrAmineDrAmine GermanyPosts: 7,186Forum Coordinator

    If not documented I won't provide any input here. There is a collision pointer but is not documented.

  • LumonoLumono Posts: 4Member

    Thanks again @DrAmine for the answer.

    I have got one last question towards the UDF DPM_Scalar_Update.

    I used following UDF to create the text file "particleposition_1.txt"

    #include "udf.h"
    #include "dpm.h"
    
    DEFINE_DPM_SCALAR_UPDATE(partikeldatenersteller,c,t,initialize,p)
    {
    int n;
    n = 1;
    char filename[50];
    snprintf(filename,50,"particleposition_%d.txt",n);
    FILE *fid1;
    fid1 = fopen(filename,"a");
    fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);
    fclose(fid1);
    }
    


    Other (relevant) settings in Fluent were:

    Setup->General->Steady

    Setup->Models->Discrete Phase (On)


    I have sorted the printed data in "particleposition_1.txt" at first by Particle ID (last column) and second by P_Time(p) (second column from the right).


    According to the Theory Guide and this Information

    The Euler implicit discretization is used.

    I guess, this is the reason for the entries with P_time(p) different from Particle Time Steps (0,00001/0,00002/....).

    Is this assumption correct? If so, I still wonder why the number of "in-between" entries varies?

    Another thing I am not sure about are the rows where the fluid iterates (@N*5*10e-5).

    For instance, in row 24-26, at P_Time=0,00005s there are three entries.

    Compared to row 76-77, at P_Time=0,00015s where there are only two entries.

    Could you explain me what (particle time step/fluid iteration/implicite euler/ anything else?) and how influences the number of entries in my txt-File created by my UDF?

     

    Or, to sum up my problem:

    I want to get the values of the particle (x,y,z,u,v,w) at each particle time step. Am I right if I sort my entries by Particle_ID, then by P_Time from top to bottom and always take the LAST row for the relevant particle time steps?

    For Particle_ID=0 this would be for example row: 1, 5,10, 15, 20, 26 , …?

     Here, do I need two entries for the P_times where the fluid iterates?

    Thank you again for your time!

     

  • DrAmineDrAmine GermanyPosts: 7,186Forum Coordinator
    edited June 15

    No that is not due to the Euler Implicit Scheme. With DEM it is moreover recommended not to enable accuracy control.

    You need to to understand between the particle time step size you input in the panel and time step required for trajectory integration (which depends on your input under Tracking Parameters). For DEM we set that particle time step size to 1/20 of the collision time. Smallest of both times will be used for particle trajectory integration.


    You are writing from Scalar Update so it will go through all particles (all particle ID'S) and write information every time particle is tracked (so at entry to the cell, at exit, in the cell itself). If you look to the data you will for the lines that something is changing.

    What you are asking for is more that I can provide on this open community but I think you should go with that strategy with sorting the time (other ways will require more scripting and more help from me).

    PS: If you want to have data at each particle time step what about using Unsteady Particle Reporting.

  • DrAmineDrAmine GermanyPosts: 7,186Forum Coordinator

    TP_DT will provide you with particle integration time step used and it is mentioned in the one the examples using Scalar Update in the manual. Have a fun.

Sign In or Register to comment.