|
[Sponsors] |
UDF for reading file and assigning temperature values to boundary faces |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 25, 2014, 02:19 |
UDF for reading file and assigning temperature values to boundary faces
|
#1 |
Senior Member
Srivathsan N
Join Date: Jan 2013
Location: India
Posts: 101
Rep Power: 13 |
Hi !
I would like to apply a varying temperature boundary condition at one of the boundary faces in my geometry by reading the temperature values from a data file (.txt) present in the case folder. I read the data into a global variable (as an array), but am confused as to how I would assign each of those temperatures to the face centroids while looping over the faces of the boundary. (The current way assigned in the C file attached, obviously throws an error while interpreting- incorrect type conversion) This is my first time writing a udf, so any help is welcome. pls find the C file attached.
__________________
Regards, Srivaths |
|
November 25, 2014, 04:42 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I think you made a good start. Here is a hint for the rest:
Code:
DEFINE_PROFILE(dropSurfaceTemp,thread,position) { real coord[ND_ND]; /* this will hold the position vector */ real x; face_t f; begin_f_loop(f,thread) { F_CENTROID(coord,f,thread); x=coord[0]; /*Here you need to find i such that x1[i] is close to x */ F_PROFILE(f,thread,position)= Temp[i]; /*Notice the [i] added */ } end_f_loop(f,thread) } |
|
November 25, 2014, 08:01 |
|
#3 |
Senior Member
Srivathsan N
Join Date: Jan 2013
Location: India
Posts: 101
Rep Power: 13 |
How silly of me!
Thank you!
__________________
Regards, Srivaths |
|
March 11, 2015, 09:09 |
Error while fitting polynomial temperature distribution
|
#4 |
Senior Member
Srivathsan N
Join Date: Jan 2013
Location: India
Posts: 101
Rep Power: 13 |
Hi!
I am attempting to assign a temperature variation on a face using a polynomial, with coefficients defined in the UDF. However I'm getting a strange error where the temperatures vary from 265-275 K on the face when the actual variation according to the polynomial should've been between 289-294 K. I don't seem to find a reason for the mismatch. Could it be because of the data type used, or the extremely large coefficients? Should I increase precision for them? Open to suggestions. Attached are the UDF and the plot.
__________________
Regards, Srivaths |
|
March 11, 2015, 09:29 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
A solution that might work:
change your evaluation scheme to something numerically more stable. What I mean in practice: replace Code:
(p1*x1*x1*x1*x1) + (p2*x1*x1*x1) + (p3*x1*x1) + (p4*x1) + p5; Code:
p5+(x1*(p4+x1*(p3+(x1*(p2+x1*p1))))); |
|
March 11, 2015, 11:22 |
|
#6 |
Senior Member
Srivathsan N
Join Date: Jan 2013
Location: India
Posts: 101
Rep Power: 13 |
So you think that it could be because of the extremely large polynomial coefficients? I'm afraid I can't use a piecewise linear or a linear fit. I shall try the 6th order polynomial with the expression suggested.
Thank you.
__________________
Regards, Srivaths |
|
March 11, 2015, 11:41 |
|
#7 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
What do you mean, you can't use a piecewise linear fit? Computationally it is no problem, it will be easier to implement, and easier to understand. And the results will be virtually indistinguishable from the sixth order polynomial.
Where does your sixth order polynomial come from? If it is really from a fit, I would strongly suggest to use a piecewise linear fit. What makes you say you have to use the sixth order fit??? |
|
June 13, 2016, 10:20 |
|
#8 |
New Member
Negar Saeidi
Join Date: Dec 2015
Location: Sudbury, ON, Canada
Posts: 18
Rep Power: 10 |
Hello Srivaths!
Did you manage to make your code work? I am trying to apply a UDF to the inlet boundary of my porous zone. My C file is at the end of this text. After I compile the UDF and Hook the read_data function, this message shows up in Console: “temperature limited to 1.000000e+00 in 141630 cells on zone 4” Zone 4 is my porous zone. My temperature limit setting is from 1K to 5000K. I don’t face this problem when I set constant inlet BC or when I don’t have a read_data function in the UDF. Do you have any idea what could be the problem? Here is my Code: /* ************************************************** ********* */ // UDF for time-varying temperature at the inlet /* ************************************************** ********* */ #include "udf.h" double Temp[15]; FILE *fp; DEFINE_INIT(read_data, d) { int i; fp=fopen("Env-Temp.txt","r"); for (i=1;i<15;i++) { fscanf(fp,"%ld", &Temp[i]); } fclose(fp); } DEFINE_PROFILE(Tinlet, thread, position) { face_t f; real t = CURRENT_TIME*pow(1,-1); int i = t; begin_f_loop(f, thread) { F_PROFILE(f, thread, position) = Temp[i]; } end_f_loop(f, thread) } Here is the text file that I read from: 273 278 283 288 293 298 293 288 283 278 273 268 263 258 253 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting cell variable values in a fluid zone using UDF | eromon84 | Fluent UDF and Scheme Programming | 6 | March 28, 2021 12:59 |
timeVaryingMappedFixedValue: large data mapping on complex inlet boundaries | vkrastev | OpenFOAM Pre-Processing | 7 | June 2, 2016 16:50 |
Assigning values to a cartesian grid from a binary image (or stl) | Cyp | OpenFOAM Pre-Processing | 1 | August 5, 2014 19:02 |