|
[Sponsors] |
![]() |
![]() |
#1 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Hello everyone,
I am a college student trying to model the flow of acid through a porous rock sample. After some research, I have come to the conclusion that I need to write a UDF for the change in porosity as a function of time due to the acid reacting with the rock. From what I understand, I need to use the DEFINE_PROFILE macro. Inside the macro, I need to loop over each of the cells to define the new porosity at each new time. For the sake of simplicity, the porosity formula (of the solid) I will be using is as follows: Quote:
Code:
#include "udf.h" DEFINE_PROFILE(porosity_variation,t,i) { real delta_t = CURRENT_TIMESTEP; /* not sure if this should be PREVIOUS_TIMESTEP instead */ real X = 1.0; /* this is an arbitrary value */ cell_t c; begin_c_loop(c,t) { C_PROFILE(c,t,i) = 1 - (X * delta_t - phi_0 ^ 2 + phi_0) / (X * delta_t - phi_0 + 1); } end_c_loop(c,t) } Last edited by Baden; June 8, 2016 at 12:47. |
||
![]() |
![]() |
![]() |
![]() |
#2 | ||
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
Quote:
|
|||
![]() |
![]() |
![]() |
![]() |
#3 | ||
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Thank you so much for the response.
Quote:
Quote:
|
|||
![]() |
![]() |
![]() |
![]() |
#4 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
2) yes, my mistake, typed it quickly and did not check the right macro. the DEFINE_EXECUTE_AT_END executes a command at the end of each iteration. what you can do is an if statement that storage the value of porosity in the UDMI with dependence in a relation of time and current time step. |
||
![]() |
![]() |
![]() |
![]() |
#5 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
I'm relatively new to Fluent and there aren't many examples on the internet of what I'm trying to do so I'm having a hard time following. Is there a chance you could post a sample UDF code or a modification to the code I wrote to demonstrate how I would make the porosity dependent on time? Again, I really appreciate you taking the time to answer my questions. Last edited by Baden; June 7, 2016 at 17:17. |
||
![]() |
![]() |
![]() |
![]() |
#6 |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Here is an update of the code I have so far, which is based on this thread.
Code:
#include "udf.h" DEFINE_PROFILE(porosity_variation,t,i) { real X = 1; /* arbitrary constant */ real delta_t = CURRENT_TIMESTEP; cell_t c; begin_c_loop(c,t) { if (N_TIME == 1) { C_PROFILE(c,t,i) = 0.8; } else { real phi_0 = C_UDMI(c,t,0); C_PROFILE(c,t,i) = 1 - (-(phi_0 * phi_0) + phi_0 + X * delta_t) / (-phi_0 + X * delta_t + 1); } C_UDMI(c,t,0) = C_PROFILE(c,t,i); } end_c_loop(c,t) } Last edited by Baden; June 8, 2016 at 12:47. |
|
![]() |
![]() |
![]() |
![]() |
#7 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
just couple of things. instead of using "1", use "1.0". I spent over a month trying to find a bug in my code and it was that the compiler was messing with a number because of the decimal place. and you have to initialize your UDMI, otherwise phi_0 has no value. You can initialize it in you initialization process as 0.8 and then use it like this. Code:
#include "udf.h" DEFINE_PROFILE(porosity_variation,t,i) { real X = 1.0; /* arbitrary constant */ real delta_t = CURRENT_TIMESTEP; cell_t c; begin_c_loop(c,t) { if (N_TIME == 1) { C_PROFILE(c,t,i) = C_UDMI(c,t,0); } else { real phi_0 = C_UDMI(c,t,0); C_PROFILE(c,t,i) = 1.0 - (-(phi_0 * phi_0) + phi_0 + X * delta_t) / (-phi_0 + X * delta_t + 1.0); } C_UDMI(c,t,0) = C_PROFILE(c,t,i); } end_c_loop(c,t) } |
||
![]() |
![]() |
![]() |
![]() |
#8 | ||
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
Code:
#include "udf.h" DEFINE_PROFILE(porosity_variation,t,i) { real X = 1.0; real delta_t = CURRENT_TIMESTEP; cell_t c; begin_c_loop(c,t) { if (N_TIME == 1) { C_PROFILE(c,t,i) = C_UDMI(c,t,0); } else { real phi_0 = C_UDMI(c,t,0); C_PROFILE(c,t,i) = 1.0 - (-(phi_0 * phi_0) + phi_0 + X * delta_t) / (-phi_0 + X * delta_t + 1.0); } C_UDMI(c,t,0) = C_PROFILE(c,t,i); } end_c_loop(c,t) } DEFINE_INIT(UDMI0_init,d) { Thread *t; cell_t c; Thread *t_fluid = Lookup_Thread(d,3); /* 3 is the ID of the fluid */ thread_loop_c(t,d) { if (t == t_fluid) { begin_c_loop(c,t) { C_UDMI(c,t,0) = 0.8; } end_c_loop(c,t) } } } ![]() Also, earlier you said: Quote:
Last edited by Baden; June 8, 2016 at 17:18. |
|||
![]() |
![]() |
![]() |
![]() |
#9 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
"DEFINE_EXECUTE_AT_END is a general purpose macro that is executed at the end of an iteration in a steady state run, or at the end of a time step in a transient run.". It runs automatically at the end of each iteration/time step for stead-state/transient case. Did you hook it properly? |
||
![]() |
![]() |
![]() |
![]() |
#10 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
Let me outline what I think I need to do. Please correct me if I'm wrong.
|
||
![]() |
![]() |
![]() |
![]() |
#11 | ||
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
Quote:
In other words, it wont compute anything in the DEFINE_AT_THE_END unless at the end of the time step for transient cases. |
|||
![]() |
![]() |
![]() |
![]() |
#12 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#13 |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
||
![]() |
![]() |
![]() |
![]() |
#14 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
So how would I model a change in porosity as a function of time if there isn't a timestep? Is there another way to get change in time other than this? Code:
real dt = CURRENT_TIMESTEP; |
||
![]() |
![]() |
![]() |
![]() |
#15 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
This macro is for transient case, which is the way you gotta run your case if you want time variation on it. Have a look about the transient problem in the manual and you can also have a look in youtube, there are many videos of time dependent variation. |
||
![]() |
![]() |
![]() |
![]() |
#16 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
I will report back if I encounter any more problems. |
||
![]() |
![]() |
![]() |
![]() |
#17 |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
I do have one question about the DEFINE_EXECUTE_AT_END macro.
I'm trying to store the calculated value of porosity in the UDMI using the DEFINE_EXECUTE_AT_END macro but I'm not quite sure how to reference the porosity since the C_PROFILE macro requires an index (i). Code:
#define ID 3.0 /* ID of the fluid */ DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d; Thread *t; Thread *t_fluid = Lookup_Thread(d,ID); cell_t c; d = Get_Domain(1); /* mixture domain if multiphase */ thread_loop_c(t,d) { if (t == t_fluid) { begin_c_loop(c,t) { C_UDMI(c,t,0) = C_PROFILE(c,t,???) } end_c_loop(c,t) } } } |
|
![]() |
![]() |
![]() |
![]() |
#18 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 ![]() |
Quote:
Code:
#include "udf.h" #define ID 3.0 /* ID of the fluid */ /* in this part, the value of the porosity is initialised as 0.8 */ DEFINE_INIT(UDMI0_init,d) { Thread *t; cell_t c; Thread *t_fluid = Lookup_Thread(d,3); /* 3 is the ID of the fluid */ thread_loop_c(t,d) { if (t == t_fluid) { begin_c_loop(c,t) { C_UDMI(c,t,0) = 0.8; } end_c_loop(c,t) } } } /* this macro will read the value of the UDMI_0. For the first time step, it will be 0.8, after that, it will use the value of the UDMI_0 calculated in the DEFINE_EXECUTE_AT_END */ DEFINE_PROFILE(porosity_variation,t,i) { cell_t c; begin_c_loop(c,t) { C_PROFILE(c,t,i) = C_UDMI(c,t,0); } end_c_loop(c,t) } /*Since this macro is only executed at the end of each time step, there is no need to an IF statement. This command will define that phi_0 is the value of the old porosity, then the porosity_new can be solved and followed by the definition of the new value of the UDMI_0. This value will be read by the DEFINE_PROFILE as the new value of the porosity at the end of each time step*/ DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d; Thread *t; Thread *t_fluid = Lookup_Thread(d,ID); cell_t c; d = Get_Domain(1); /* mixture domain if multiphase */ real porosity; real X = 1.0; /* arbitrary constant */ real delta_t = CURRENT_TIMESTEP; thread_loop_c(t,d) { if (t == t_fluid) { begin_c_loop(c,t) { real phi_0 = C_UDMI(c,t,0); porosity_new = 1.0 - (-(phi_0 * phi_0) + phi_0 + X * delta_t) / (-phi_0 + X * delta_t + 1.0); C_UDMI(c,t,0) = porosity_new; } } end_c_loop(c,t) } } } |
||
![]() |
![]() |
![]() |
![]() |
#19 | |
Member
Join Date: Jun 2016
Posts: 64
Rep Power: 10 ![]() |
Quote:
I did notice one oddity when interpreting the code (I don't compile it because I've read the manual and still have no idea how to). I received a parse error whenever the "d = Get_Domain(1);" was placed on any line above where it is now in the following code: Code:
DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d; Thread *t; Thread *t_fluid = Lookup_Thread(d,ID); cell_t c; real X = 1.0; real dt = CURRENT_TIMESTEP; d = Get_Domain(1); thread_loop_c(t,d) { if (t == t_fluid) { begin_c_loop(c,t) { real phi_0 = C_UDMI(c,t,0); real phi = 1.0 - (-(phi_0 * phi_0) + phi_0 + X * dt) / (-phi_0 + X * dt + 1.0); C_UDMI(c,t,0) = phi; } end_c_loop(c,t) } } } |
||
![]() |
![]() |
![]() |
![]() |
#20 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 ![]() |
Fluent uses ANSI C which follows a number of strict rules including the requirement of declaring all variables at the beginning of a code block. However, you can declare and initialise the domain thread on one line with:
Code:
Domain *d = Get_Domain(1); |
|
![]() |
![]() |
![]() |
Tags |
acid, porosity, time, transient, udf |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
decomposePar problem: Cell 0contains face labels out of range | vaina74 | OpenFOAM Pre-Processing | 37 | July 20, 2020 05:38 |
simpleFoam error - "Floating point exception" | mbcx4jc2 | OpenFOAM Running, Solving & CFD | 12 | August 4, 2015 02:20 |
Help for the small implementation in turbulence model | shipman | OpenFOAM Programming & Development | 25 | March 19, 2014 10:08 |
pisoFoam with k-epsilon turb blows up - Some questions | Heroic | OpenFOAM Running, Solving & CFD | 26 | December 17, 2012 03:34 |
Orifice Plate with a fully developed flow - Problems with convergence | jonmec | OpenFOAM Running, Solving & CFD | 3 | July 28, 2011 05:24 |