|
[Sponsors] |
December 14, 2016, 13:05 |
Momentum source
|
#1 |
New Member
Johannes Hall
Join Date: Sep 2016
Posts: 21
Rep Power: 10 |
Hello everyone!
I created this thread in the common forum aswell, didn't realise there was a special one for UDFs. I am trying to create an increase of velocity in a flow over a wing in order to simulate a gust wind. The idea is to apply a momentum source in a region upstream of the wing and let the perturbation flow downstream through convection. I found this https://www.sharcnet.ca/Software/Flu...ug/node309.htm When I use the UDF below I get strange changes in the velocity field where smaller cells gets a much higher velocity than larger. I suppose it sort of makes sense the source term divides by the volume and I fear I have misunderstood something. If anyone have experience with this kind of implementation, or has another suggestion of achieving a similar result, it would be of great help. Below you find the udf and a picture of the flowfield. #include "udf.h" real A[ND_ND]; /* Declared as global variables*/ real area; DEFINE_ON_DEMAND(face_area) { Domain *d = Get_Domain(1); Thread *ft; face_t f; thread_loop_f(ft,d) /* Finding the area of the cell face with a define on demand macro. Found this in another thread here on CFD-online */ { begin_f_loop(f,ft) { real NV_VEC(A); F_AREA(A,f,ft); area = NV_MAG(A); } end_f_loop(f,ft) } } DEFINE_SOURCE(source_still_in_sharp_smooth, c,t,dS,eqn) { real x[ND_ND]; C_CENTROID(x,c,t) real x_0 = x[0]; real pi = 3.14159265359; real Wg = 10; /* amplitude gust */ real start_g = -5; /* start gust source region */ real length_g = 1; /* length gust source region */ real end_g = (start_g + length_g); /* end gust source region */ real real_time = CURRENT_TIME; real start_time_gust = 0.01; /* start time gust */ real end_time_gust = 0.51; /* end time gust */ real gust_time = (real_time - start_time_gust); real gust; if(0 <= gust_time && gust_time <= end_time_gust) { if(start_g <= x_0 && x_0 <= end_g) { gust = (C_U(c,t) + 5) * C_R(c,t) * area / C_VOLUME(c,t); /* flux through cell, 5 [m/s] is the perturbation */ } else { gust = 0.0; } } else { gust = 0.0; } real source = gust; /* whetever your source is */ dS[eqn] = C_R(c,t) * area / C_VOLUME(c,t); /* derivative source term */ return source; } |
|
December 14, 2016, 15:50 |
|
#2 |
Member
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14 |
your problem is the area variable... the initial loop that finds the area, loops over all faces and keeps rewriting over the variable. In the end it is saving the area of the last face into the area variable. Then you area using that same number for all cells. You have to use the area of each cell individually.
|
|
December 15, 2016, 03:45 |
|
#3 |
New Member
Johannes Hall
Join Date: Sep 2016
Posts: 21
Rep Power: 10 |
Thank you very much for your answer!
I suspected it was something off with using the macros in that way. Do you perhaps have a recommendation of how I could include finding the area in the define_source macro? I tried to run it with just a static source, divided by the volume for a certain domain. For example: source = 100/C_VOLUME(c,t); but the same error with the higher velocity at smaller cells appear. Maybe I am interpreting the momentum source terms unit wrong? As I understood it it is N/m3, meaning I should divide by the volume for each cell? Regards! |
|
December 15, 2016, 05:32 |
|
#4 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
No, you should not divide by the cell volume anymore. Fluent will assign the cell volume-weighted source value when going through the cell loop. What Fluent asks of you as input is indeed a volumetric source term, but that is based on the zone volume, not the cell volume. I.e., if you want to prescribe a constant source of 100N on a volume of 2m^3, you should enter a value of 50. Fluent will then solve the source term on a cell basis (i.e., a smaller cell will have a smaller net source (in N)). In your case, when dividing by the cell-volume, you're basically saying all cells have an identical net source (larger volumetric source for smaller cells), regardless of their size. Thus resulting in a larger velocity in smaller cells
|
|
December 15, 2016, 07:59 |
|
#5 |
Member
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14 |
So, I guess, basically remove the area and volume factors?
|
|
December 15, 2016, 11:52 |
|
#6 |
New Member
Johannes Hall
Join Date: Sep 2016
Posts: 21
Rep Power: 10 |
Thank you for your replies!
I see that helps and explains a lot. So let's say I want a source term that is dependent on the velocity of each cell. What I'm trying to do is force the momentum equation to converge to the u_target velocity in the region of the source. S = (u_gust_total * sin(2* pi * t) - C_U(c,t)); say that u_gust_total is 85 m/s and the free stream is 80 m/s, so the C_U values in the source region are around 80 as well but slightly different varying. The expression above would then be sufficient and I wouldn't need a volume or time-step term? Thank you very much, regards! |
|
December 15, 2016, 12:32 |
|
#7 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
You can do something like that, but make sure your units are correct. Your source needs to be of unit N/m^3, so do something like:
S = C_R(c,t)*(u_gust_total - C_U(c,t))/tau, Here, tau is a time-scale, giving you some flexibility on how fast it will converge towards your desired velocity. |
|
December 15, 2016, 18:36 |
|
#8 |
New Member
Johannes Hall
Join Date: Sep 2016
Posts: 21
Rep Power: 10 |
Thank you so much for your help, I will try it and come back with the result!
Best regards, Johannes |
|
February 2, 2017, 15:11 |
|
#9 | |
Member
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14 |
Quote:
My geometry is just a tube, with 0-shear walls, and inlet and an outlet, a separate cell-zone in the middle(1 cell thick and 0.02 m thick), and a porous-jump with the the dP at zero(just to capture particles). What I tried was dividing by the thickness of the cells. This works when the orientation of the geometry is parallel to the x axis. But whenever I try different orientations or geometries (like a cilindrical surface) the values go crazy. please help |
||
February 3, 2017, 09:41 |
|
#10 |
New Member
Johannes Hall
Join Date: Sep 2016
Posts: 21
Rep Power: 10 |
I am still not an expert on UDF:s nor Fluid dynamics, but couldn't you set pressure boundary conditions at inlet and outlet with a difference of 3 pa?
Maybe I have misunderstood what it is you actually want though |
|
February 3, 2017, 12:23 |
|
#11 | |
Member
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14 |
Quote:
well, yes, I think I could do that. But I'm trying to simulate a filter, and this source term is supposed to stand in for the resistance to fluid flow that the filter has. So I'm testing my code and the difference in pressure is my tell if the code is working. While I can set the difference in pressure to whatever I want, that won't mean that the code is working. |
||
February 7, 2017, 08:25 |
|
#12 | |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
Quote:
As for different orientations of your geometry, the used thickness is the one perpendicular to the normal of the areas). Also, I'd guess you need to properly decompose it in x,y and z components if it's not parallel to either axis. |
||
February 7, 2017, 09:00 |
|
#13 |
Member
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14 |
Actually, I got something that works pretty well by just dividing the target pressure by the cell thickness... I have a different problem now: let's say I inject 3 kg/s in an area of 1m2; my pressure is a function of the mass area density (so like dP=C1+(mass density)/C2). The problem is if I want to predict the pressure value after 1 second after first impact, I'd like to plug in 3kg/m2 into this formula and get the dP. That makes sense right? And this works pretty well if the mass distribution is even (when I force it to be completely even the formula works). if there is any variation though, the simulated value is a bit lower than the expected one. And this makes sense I guess: If there is a low density area, the flow will tend to go through there lowering the pressure in the process.
Anyways, my question is how can I predict the global pressure drop. I thought about trying to use a different mass density average (like a harmonic average, maybe?) because I need and average that is lower. Any help and ideas are appreciated. |
|
November 16, 2017, 09:32 |
|
#14 | |
New Member
Misa
Join Date: Oct 2017
Posts: 10
Rep Power: 9 |
Quote:
Can you please update about the final udf used for your above referred problem? Any help in this regard will be much appreciated. Thankyou and Regards. |
||
November 24, 2017, 12:06 |
Y momentum source
|
#15 |
New Member
Misa
Join Date: Oct 2017
Posts: 10
Rep Power: 9 |
Dear all,
Can anyone please help why is the Y-velocity in source region not coming equal to 15 m/s. I think i made a mistake somewhere in the Y-momentum source UDF? Thanks in advance # include "udf.h" DEFINE_SOURCE(V-gust,cell,thread,dS,eqn) { real source=0.0; real XGS=-7.5; /* X-center of source*/ real YGS=0.0; /* Y-center of source*/ real ZGS=0.0; /* Z-center of source*/ real X= 1.0; /* X, Y, Z dimensions are such so as to make the source-Volume=1m^3*/ real Y= 1.0; real Z= 1.0; real t = CURRENT_TIME; real centroid[3]; C_CENTROID(centroid,cell,thread); real x_loc=centroid[0]; real y_loc=centroid[1]; real z_loc=centroid[2]; if (t>1.0 && t<1.5) { if (fabs(x_loc-XGS)<X && fabs(y_loc-YGS)<Y && fabs(z_loc-ZGS)<Z) { real rho=C_R(cell,thread); source=rho*(15-C_V(cell,thread))/CURRENT_TIMESTEP; /*15(m/s) is perturbation in Y direction*/ dS[eqn]=0.0; } } else { source=0.0; dS[eqn]=0.0; } return source; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
polynomial BC | srv537 | OpenFOAM Pre-Processing | 4 | December 3, 2016 10:07 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
[swak4Foam] swak4Foam-groovyBC build problem | zxj160 | OpenFOAM Community Contributions | 18 | July 30, 2013 14:14 |
[swak4Foam] build problem swak4Foam OF 2.2.0 | mcathela | OpenFOAM Community Contributions | 14 | April 23, 2013 14:59 |