|
[Sponsors] | |||||
|
|
|
#1 |
|
New Member
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 8 ![]() |
Could someone, please, help me with this udf code? It's write in the right way but it doesn't work and don't do function in the "else" https://pastebin.com/raw/SMazER3X
Code:
#include "udf.h"
#include"udf.h"
#include"metric.h"
#include"stdio.h"
#include"math.h"
#include"stdlib.h"
#include"mem.h"
DEFINE_DELTAT(deltat,d)
{
real time_step;
real tx=CURRENT_TIME;
Thread *t,*t0, *t1 =NULL;
cell_t c0, c1 =-1;
face_t f;
Domain *domain;
real x0[ND_ND];
real x1[ND_ND];
int n =0;
real dx =0.0, dy =0.0;
domain = Get_Domain(1);
n =0;
real cent[2];
double centr_x, centr_y;
double vel_x, vel_y;
if ( tx<=1 ) {
time_step=0.01;
} else {
DEFINE_ON_DEMAND(calc_distance)
{
thread_loop_f(t,domain)
{
begin_f_loop (f,t)
{
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
if (BOUNDARY_FACE_THREAD_P(t))
{}
else
{
n+=1;
t1 = F_C1_THREAD(f,t);
c1 = F_C1(f,t);
C_CENTROID(x0,c0,t0);
C_CENTROID(x1,c1,t1);
dx = x1[0]-x0[0];
dy = x1[1]-x0[1];
}
}
end_f_loop (f,t)
}
DEFINE_ADJUST(velocity_profile_face,d)
{
thread_loop_f(t,d)
{
begin_f_loop(f,t)
{
F_CENTROID(cent,f,t);
centr_x = cent[0];
centr_y = cent[1];
vel_x = F_U(f,t);
vel_y = F_U(f,t);
}
end_f_loop(f,t)
}
time_step=MAX (time_step, (dx / vel_x) *0.8);
time_step=MAX (time_step, (dy / vel_y) *0.8);
}
}
}
return time_step;
}
|
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 430
Rep Power: 16 ![]() |
The 'else' block starts with a 'DEFINE_ON_DEMAND(calc_distance)', is this intentional?
|
|
|
|
|
|
|
|
|
#3 | |
|
New Member
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 8 ![]() |
Quote:
Yes, but i saw this is wrong, because i read that it's a function that read value at the end of calculations, anyway i would like to understand how to write a function that in the "else" compute max of the division between velocity and cell dimension, and after calculate the time step as time_step = max (dx/velx) * CFL max (0,8 in my case) |
||
|
|
|
||
|
|
|
#4 |
|
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 35 ![]() ![]() |
DEFINE_DELTAT DEFINE_ADJUST and DEFINE_ON_DEMAND
are independent macros, you cant use them inside each other start from this, compile UDF, read logs and fix errors Code:
#include "udf.h"
#include"udf.h"
#include"metric.h"
#include"stdio.h"
#include"math.h"
#include"stdlib.h"
#include"mem.h"
DEFINE_DELTAT(deltat,d)
{
real time_step;
real tx=CURRENT_TIME;
Thread *t,*t0, *t1 =NULL;
cell_t c0, c1 =-1;
face_t f;
real x0[ND_ND];
real x1[ND_ND];
int n =0;
real dx =0.0, dy =0.0;
real cent[2];
double centr_x, centr_y;
double vel_x, vel_y;
n =0;
time_step=0.01;
if ( tx<=1 ) {
time_step=0.01;
} else {
thread_loop_f(t,domain)
{
begin_f_loop (f,t)
{
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
if (BOUNDARY_FACE_THREAD_P(t))
{}
else
{
n+=1;
t1 = F_C1_THREAD(f,t);
c1 = F_C1(f,t);
C_CENTROID(x0,c0,t0);
C_CENTROID(x1,c1,t1);
dx = x1[0]-x0[0];
dy = x1[1]-x0[1];
F_CENTROID(cent,f,t);
centr_x = cent[0];
centr_y = cent[1];
vel_x = F_U(f,t);
vel_y = F_U(f,t);
time_step=MAX (time_step, (dx / vel_x) *0.8);
time_step=MAX (time_step, (dy / vel_y) *0.8);
}
end_f_loop(f,t)
}
}
}
return time_step;
}
time_step=MAX (time_step, (dy / vel_y) *0.8); are calculated on each face, if you don't want -> fix it best regards |
|
|
|
|
|
|
|
|
#5 | ||
|
New Member
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 8 ![]() |
Quote:
https://ibb.co/mBv9WxF Actual code is this ( i added the definition of domain ) Quote:
|
|||
|
|
|
|||
|
|
|
#6 |
|
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 35 ![]() ![]() |
You've made mistake
best regards |
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| bash script for pseudo-parallel usage of reconstructPar | kwardle | OpenFOAM Post-Processing | 43 | October 28, 2025 04:19 |
| Transient simulation not converging | skabilan | OpenFOAM Running, Solving & CFD | 14 | December 17, 2019 00:12 |
| Setting up Lid driven Cavity Benchmark with 1M cells for multiple cores | puneet336 | OpenFOAM Running, Solving & CFD | 11 | April 7, 2019 01:58 |
| AMI interDyMFoam for mixer nu problem | danny123 | OpenFOAM Programming & Development | 8 | September 6, 2013 03:34 |
| pisoFoam with k-epsilon turb blows up - Some questions | Heroic | OpenFOAM Running, Solving & CFD | 26 | December 17, 2012 04:34 |