|
[Sponsors] |
January 30, 2019, 18:00 |
Creating an external file with data
|
#1 |
New Member
GenD
Join Date: Nov 2017
Posts: 23
Rep Power: 9 |
Hi,
I'm trying to create an external file with data after each time step. To do this I use DEFINE_EXECUTE_AT_END macro, but I've some problems. First of all, in the generated file, the only thing that is saving is the data for the last time step, but I want to have it for every one, so I suppose it just overwrites every time step. I thought I will omit this issue by using arrays, but I just can't get through with them. Could you please help me solve it? Secondly, there happen to be another problem with macros for temperature (C_T(c,t)) and other, cause ANSYS says that there are no initialized variables of c and t, but in my code I have them. I will put code in here. Maybe whole idea is wrong? Could you please assist me with this? Code:
#include "udf.h" int i = 0; real rho[10000]; real T[10000]; real velocity[10000]; real r_num[10000]; real time[10000]; DEFINE_EXECUTE_AT_END(write_file) { Thread *t; cell_t c; T[i] = C_T(c, t); rho[i] = C_R(c, t); real mu = 0.001003; velocity[i] = C_V(c, t); real diameter = 0.038; r_num[i] = ((rho[i] * pow(diameter, 2) * velocity[i]) / mu); time[i] = CURRENT_TIME; FILE *fptr; fptr = fopen("example.txt", "w"); fprintf(fptr, "Temperature Density Viscosity Reynolds number Time\n"); fprintf(fptr, "%4.2f %4.2f %4.6f %4.2f %4.3f\n", T[i], rho[i], mu, r_num[i], time[i]); fclose(fptr); i++; } |
|
January 30, 2019, 21:30 |
|
#2 | |
Senior Member
Join Date: Feb 2010
Posts: 164
Rep Power: 17 |
Quote:
fptr = fopen("example.txt", "a+"); |
||
January 31, 2019, 20:05 |
|
#3 |
New Member
GenD
Join Date: Nov 2017
Posts: 23
Rep Power: 9 |
Thank you gearboy. It really helped me.
Now, I struggle with the second problem. The code looks now like this. Code:
#include "udf.h" int i = 0; real rho[10000]; real T[10000]; real velocity[10000]; real r_num[10000]; real time[10000]; cell_t c; Thread *t; DEFINE_ON_DEMAND(on_demand_write) { FILE *fptr; fptr = fopen("example.txt", "w"); fprintf(fptr, "Temperature Density Viscosity Reynolds number Time\n"); fclose(fptr); } DEFINE_EXECUTE_AT_END(write_file_at_end) { T[i] = C_T(c, t); rho[i] = C_R(c, t); real mu = 0.001003; velocity[i] = C_V(c, t); real diameter = 0.038; r_num[i] = ((rho[i] * pow(diameter, 2) * velocity[i]) / mu); time[i] = CURRENT_TIME; FILE *fptr; fptr = fopen("example.txt", "a+"); fprintf(fptr, "%4.2f %4.2f %4.6f %4.2f %4.3f\n", T[i], rho[i], mu, r_num[i], time[i]); fclose(fptr); i++; Node 0: Process 14620: Received signal SIGSEGV. ================================================== ============================ MPI Application rank 0 exited before MPI_Finalize() with status 2 The fl process could not be started. I think it is connected with macros C_T(c, t), C_R(c, t) and C_V(c, t), because, when I put instead of those macros just some numbers, it works fine. Do you have any idea, how to solve this? |
|
February 1, 2019, 05:11 |
|
#4 | |
Senior Member
Join Date: Feb 2010
Posts: 164
Rep Power: 17 |
Quote:
|
||
February 1, 2019, 07:36 |
|
#5 |
New Member
GenD
Join Date: Nov 2017
Posts: 23
Rep Power: 9 |
Yes, that's exactly what I've done and it proved that a problem is with macros C_T(c, t), C_R(c, t) and C_V(c, t), and I don't know why. Does anyone know the reason?
|
|
February 2, 2019, 08:25 |
|
#6 |
New Member
GenD
Join Date: Nov 2017
Posts: 23
Rep Power: 9 |
I've been working to make UDF work by the use of Customization Manual and cases written in all kinds of forums and I've developed a code. BUT it does not work for me, what is funny because the errors are with macros. I've tried to replace macros (C_T(c,t), C_R(c,t), C_V(c,t), C_VOLUME(c,t) ) with number 1 and it worked properly, so i don't get how to omit this. Actual version of the code is below, so if somebody knows the issue, I will be glad if you help me.
In addition I can say that I've tried to use final, proper codes from forums and Customization Manual connected with macros given above and those didn't work too. Code:
#include "udf.h" cell_t c; Thread *t; Domain *d; DEFINE_EXECUTE_AT_END(write_file_at_end) { real vol_tot = 0; real volume = 0; real mu = 0; real rho = 0; real T = 0; real velocity = 0; real r_num = 0; real time = 0; real Tavg = 0; real rhoavg = 0; real velavg = 0; d = Get_Domain(1); int thread_num = 6; t = Lookup_Thread(d, thread_num); thread_loop_c(t, d) { begin_c_loop(c, t) { T = C_T(c, t); rho = C_R(c, t); velocity = C_V(c, t); time = CURRENT_TIME; volume = C_VOLUME(c, t); vol_tot += volume; Tavg += T * volume; rhoavg += rho * volume; velavg += velocity * volume; } end_c_loop(c, t) Tavg /= vol_tot; rhoavg /= vol_tot; velavg /= vol_tot; mu = 0.001003; real diameter = 0.038; r_num = ((rhoavg * pow(diameter, 2) * velavg) / mu); } FILE *fptr; fptr = fopen("example.txt", "a+"); fprintf(fptr, "%4.2f %4.2f %4.6f %4.2f %4.3f\n", Tavg, rhoavg, mu, r_num, time); fclose(fptr); } DEFINE_ON_DEMAND(on_demand_write) { FILE *fptr; fptr = fopen("example.txt", "w"); fprintf(fptr, "Temperature Density Viscosity Reynolds number Time\n"); fclose(fptr); } |
|
February 4, 2019, 11:22 |
|
#7 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
You replaced macros C_T(c,t), C_R(c,t), C_V(c,t) and C_VOLUME(c,t) with number 1, and it worked.
Did you try to replace macros C_T(c,t) and C_R(c,t) with one (so leaving C_V(c,t) and C_VOLUME(c,t))? If that gives no error, you know the problem is in C_T or C_R. If so, try only C_T. And make sure (double sure) that you initialize your data before you run this macro. |
|
February 7, 2019, 16:14 |
|
#8 |
New Member
GenD
Join Date: Nov 2017
Posts: 23
Rep Power: 9 |
Hi,
I've applied your plan of troubleshooting and as a result I got that C_T(c, t) (so temperature) is a problem. Any other like macros for density, volume, etc. work well. Do you have any idea, why is that? Yes, of course I initialize data before calculations. It is impossible do to so without it. |
|
Tags |
execute at end, external file, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CFD by anderson, chp 10.... supersonic flow over flat plate | varunjain89 | Main CFD Forum | 18 | May 11, 2018 08:31 |
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 | tlcoons | OpenFOAM Installation | 13 | April 20, 2016 18:34 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 | Seroga | OpenFOAM Community Contributions | 9 | June 12, 2015 18:18 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |