CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Udf for adaptive time step, error in loop

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 6, 2019, 02:04
Default Udf for adaptive time step, error in loop
  #1
New Member
 
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 6
francescolab is on a distinguished road
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;
}
francescolab is offline   Reply With Quote

Old   July 6, 2019, 06:29
Default
  #2
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 407
Rep Power: 14
Светлана is on a distinguished road
The 'else' block starts with a 'DEFINE_ON_DEMAND(calc_distance)', is this intentional?
Светлана is offline   Reply With Quote

Old   July 6, 2019, 06:32
Default
  #3
New Member
 
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 6
francescolab is on a distinguished road
Quote:
Originally Posted by Светлана View Post
The 'else' block starts with a 'DEFINE_ON_DEMAND(calc_distance)', is this intentional?

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)
francescolab is offline   Reply With Quote

Old   July 8, 2019, 00:04
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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, (dx / vel_x) *0.8);
time_step=MAX (time_step, (dy / vel_y) *0.8);
are calculated on each face, if you don't want -> fix it

best regards
AlexanderZ is offline   Reply With Quote

Old   July 8, 2019, 05:39
Default
  #5
New Member
 
Francesco Labianca
Join Date: Jun 2019
Posts: 6
Rep Power: 6
francescolab is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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, (dx / vel_x) *0.8);
time_step=MAX (time_step, (dy / vel_y) *0.8);
are calculated on each face, if you don't want -> fix it

best regards
This code is okay and fluent compiled it, anyway it gives me an error of this type now:


https://ibb.co/mBv9WxF

Actual code is this ( i added the definition of domain )
Quote:
#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;
Domain *domain;
domain = Get_Domain(1);
time_step=0.01;
if ( tx<=0 ) {
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;
}

francescolab is offline   Reply With Quote

Old   July 8, 2019, 06:20
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
You've made mistake

best regards
AlexanderZ is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 41 August 23, 2023 02:48
Transient simulation not converging skabilan OpenFOAM Running, Solving & CFD 14 December 16, 2019 23:12
Setting up Lid driven Cavity Benchmark with 1M cells for multiple cores puneet336 OpenFOAM Running, Solving & CFD 11 April 7, 2019 00:58
AMI interDyMFoam for mixer nu problem danny123 OpenFOAM Programming & Development 8 September 6, 2013 02:34
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 03:34


All times are GMT -4. The time now is 14:18.