DPM Loop UDF Help

  • 25 Views
  • Last Post 2 days ago
eannakennedy posted this 2 weeks ago

I am trying to calculate the standard deviation of particles about the centre of a channel at a sampling plane near the exit and I am having trouble getting my UDF to work. The UDF compiles and loads fine, but it causes fluent to crash when i try to run it. I have included my code below. I think the problem is probably due to the need to loop through all particles in a Macro that doesn't take in any DPM arguments. Any advice would be really appreciated.

I have tried to get the same results in a few different ways now, and I am wondering is it even possible to loop through all particles outside of a DEFINE_DPM macro?

Thanks.

 

Order By: Standard | Newest | Votes
abenhadj posted this 2 weeks ago

I will just provide with some things to get started but as ANSYS-Stuff we won't comment much on UDF.  But to get started check DEFINE_DPM_INJECTION_INIT from manual as it contains some tipps how to loop over particles. You will need at first to loop over all injections and you first need to get a list of all the injections you have defined: Injection Ilist = Get_dpm_injections();

2/You need to define a generic injection pointer Injection *I;

3/Looping over all the injections can be done using the following command loop(I, Ilist)

The rest to be found in the manual.

That is what I can share on open community.

Best regards,

Amine

eannakennedy posted this 2 weeks ago

Hi Amine, 

Thanks for the help! This was very useful and I am able to get the particle data now. However I want to read the particle data at a sampling plane downstream.

Is it possible to use the begin... end_c_loop and PP_POS0 to get the particle data at the specified cells? I tried this but the macro was taking a long time to execute. One of the particles remains trapped in the channel, this is expected, but could this be the reason that the function could not finish?

 

 

 

abenhadj posted this 2 weeks ago

Why not using Define Dpm Output macro to do everything at the sampling plane?

Best regards,

Amine

eannakennedy posted this 2 weeks ago

When the code is working I will change it to a DEFINE_EXECUTE_AT_EXIT then use use DEFINE_REPORT_DEFINITION to create an output parameter (standard deviation) that I can use to optimise the channel geometry. From what I understand I wouldn't be able to automatically update the output parameter from a DPM_OUTPUT macro, and I couldn't figure out how to pass the arguments needed for the DPM_OUTPUT into it from another function.

abenhadj posted this 2 weeks ago

By reading the output of DPM_OUTPUT macro back into Fluent.

Best regards,

Amine

eannakennedy posted this 2 weeks ago

So I should write a UDF that reads the .dpm file? I will need to run a lot of simulations so how would I be able to automate the sample report to be written everytime a simulation is run?

eannakennedy posted this 2 weeks ago

Sorry to bother you again, but I really am not sure what you mean. I'll write out my understanding as clearly as I can.

 

I want to measure the standard deviation of particles at a plane and use that as an output parameter for optimisation. I'd like to be able to do this automatically at the end of the solver because the code will have to run for a large number of designs.

So as far as I can see I have three options.

Option 1: I can use DEFINE_DPM_OUTPUT (nameheaderfptptplane)  to access the tracked particle data and write it to a .dpm file. I could then use another function to read this file and do the calculations I need. But how do I automatically create the .dpm file at the end of each design simulation?

Option 2: Call DEFINE_DPM_OUTPUT (nameheaderfptptplane inside of an EXECUTE_AT_EXIT macro to do everything at once. But with this option, how do I pass the arguments (header, fp, tp, t, plane) from fluent into the DPM_OUTPUT?

Option 3: Use the DPM data access macros PP_POS(p)[i] inside a function which loops over all cells on the plane and all particle streams in the injection. I have tried to implement this in the image below. The code compiles but doesn't execute correctly, it doesn't seem to run through the innermost loop at all. I have also tried using PP_POS0(p)[i] instead, but this gives a compile error. (error C2109: subscript requires array or pointer type)

Any advice you can offer on these options would be really appreciated, I've been struggling to get this to work for some time now.

abenhadj posted this 2 weeks ago

What I was think about is use DEFINE_DPM_OUTPUT to output the variables one requires, then read the output file, build the mean values or whatever and create a parameter for it.

Best regards,

Amine

abenhadj posted this 2 weeks ago

The reading will be done via ON_DEMAND and the output parameter can be created via User Defined Report definition or via DEFINE_OUTPUT_PARAMETER

Best regards,

Amine

eannakennedy posted this 2 weeks ago

Hi again Amine, 

Thanks for the advice, I see now why I would have to use DPM_OUTPUT. I am using Ansys 19.2 so I think I have to use DEFINE_REPORT_DEFINITION_FN instead, is that correct?

My code can now compute the value I need, but when i try to return this to fluent it returns nan instead. I also included a Message output in the code and even though I only included it once it returns 2 messages with 2 different values, first it returns -nan(ind) then returns the correct the value. I included this code below. Do you have any idea why this is? 

 

abenhadj posted this 2 weeks ago

The macro I was talking about is DEFINE_OUTPUT_PARAMETER but DEFINE_REPORT_DEFINITION_FN can do the same.

I cannot tell you why you are getting "nan", as you are only showing the screenshot of this macro. You need to restrict the calculation only at host as I imagine the values are only available at host. Perhaps division by zero.. You need to debug.

Best regards,

Amine

eannakennedy posted this 2 weeks ago

I am trying to debug now, but why would the message output two different values?

 

abenhadj posted this 2 weeks ago

I do not understand the question.

Best regards,

Amine

eannakennedy posted this 2 weeks ago

also in another section of the code i use a for loop and i print out the counter every iteration it always prints 0 even though I am increasing the counter every iteration. I'm really confused by this. I'm running in serial mode and I have used #if RP_HOST for this section of the code. 

The Message no longer prints twice but even when I declare a variable as some integer and print it immediately it still returns zero.

eannakennedy posted this 2 weeks ago

sorry I did not see your last message before typing my last one,I'll try and explain a bit clearer

eannakennedy posted this 2 weeks ago

While debugging I wrote the below code in one of the functions yet this still returns 0 as the output. I don't understand this at all.

 

count = 148;

Message("Count: %g\n", count);

abenhadj posted this 2 weeks ago

I am sorry but I am not understanding what you are talking about. Anyway I cannot help you debugging the UDF you are using. I have already provided with a way one can follow.

Best regards,

Amine

eannakennedy posted this 2 days ago

Hi Amine, 

I have gotten my UDF working but still having problems with automating the design optimization. It seems that to get the particle data that I need I must run a dpm-sample report after a calculation is complete. Is there anyway that I can do this automatically at the end of every calculation? 

I know that I can record a journal file which can create the sample report but then I still have the problemof how to run the journal file at the end of every calculation.

Thanks again!

Close