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

Command line for fluent to run visual studio

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 15, 2021, 19:59
Default Command line for fluent to run visual studio
  #1
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
Hi,
Here is my issue:
I am generating profile file for a boundary at every timestep in fluent (using execute command option), I need to edit this file (edit coordinates) at ever timestep as well. I made a C code (not for fluent, but general C code)that can edit this text file generated by fluent.
My question is, can I be able to run this C code from fluent "Execute Command"? Like can I open this C file on visual studio and run on visual studio by using fluent "execute command"? If so, what will be the command line?

Just to be clear, Code is not designed for fluent, it need to be run by Visual studio, which in turn edits text file. All fluent has to do is open a c code file and run the visual studio. Not sure if fluent can actually do this. If not visual studio, Matlab also works too.
soankerabhinay is offline   Reply With Quote

Old   September 17, 2021, 01:20
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
look for "fluent as server"

however, most likely, it will be much easier to modify your C code to make it works directly by fluent
soankerabhinay likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   September 17, 2021, 02:19
Default
  #3
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
Thank you Alexander for your response. I am new to fluent UDFs. My model is a closed loop heat exchanger. Since, it's a closedloop system, my outlet and inlet should have same velocity and temperature profile.
To achieve this, I am generating outlet boundary profile (text file) for temperature and velocity. Then I need to edit y-coordinates in this file (to match the coordinates with the inlet boundary) and apply this profile on to inlet boundary. I need to do this at every timestep.
I wrote a C code which successfully edited outlet profile file y-coordinates lines and created a new inlet profile file, but as you suggested it looks like making this code compatible with fluent would be a better option. If possible, would you suggest any changes to my current C code (see below) that needs to be done to make it work with the fluent? If you need more details, let me know.

I need to run this code at every timestep, so I am hoping to call this code using "Execute command" in the fluent. Again thank you so much for your suggestion and help.

**************** C - Code *****************
#include <stdio.h>
#include <string.h>
#define replica "inlet.prof"

int main(void)
{
char s[150];

FILE *fp1, *fp2;

int co;

co=0;

float s2= 0.08;

fp1= fopen("outlet_112.prof","r+"); /* outlet_112.prof is the outlet profile file generated by the fluent*/

fp2 = fopen(replica, "w"); /* create a new file replica (inlet.prof) and all the lines from fp1 is copied to fp2 except the lines from 313 to 624)*/

while(!feof(fp1))
{
fgets(s,150,fp1);

printf("%s",s);

if(co>313 && co<624)
{
fprintf(fp2, "%f\n", s2);
}

else
{
fputs(s,fp2);
}
co++;
}
fclose(fp1);
fclose(fp2);
return(0);
}
Attached Images
File Type: jpg closedloop_diagram.jpg (36.2 KB, 2 views)
Attached Files
File Type: txt outlet_112.txt (11.7 KB, 1 views)
soankerabhinay is offline   Reply With Quote

Old   September 17, 2021, 08:10
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
you may try to use this code,
I'd test it and debug
this code reads velocity in 3 dimensions and applies through define_profile macro

there is not guarantee it works well

you should
1. check zone IDs for inlet and outlet in your model (in code they are random 1 and 2)
2. compile and load this code
3. hook all functions
4. allocate 4 UDMs

Code:
#include "udf.h"

DEFINE_INIT(init_udms, d)
{
	face_t f_in,f_out;
	Thread *t,*t_in,*t_out;
	real x_in[ND_ND],x_out[ND_ND]; 	/* vectors to store coordinates */
	real delta = 1e-6;
	int ID_outlet = 2;
	int ID_inlet = 1;
	*t_in = Lookup_Thread (d, ID_inlet);
	*t_out = Lookup_Thread (d, ID_outlet);
	
	begin_f_loop(f_out,t_out)
	{
		F_CENTROID(x_out,f_out,t_out);
		begin_f_loop(f_in,t_in)
		{
			F_CENTROID(x_in,f_in,t_in);
			if (x_in[0] <= x_out[0] + delta) && (x_in[0] >= x_out[0] - delta)
				if (x_in[1] <= x_out[1] + delta) && (x_in[1] >= x_out[1] - delta)
					F_UDMI(f_out,t_out,0) = f_in;
			break;
		}
		end_f_loop(f_in,t_in)
	}
	end_f_loop(f_out,t_out)
	
	begin_f_loop(f_in,t_in)
	{
		F_UDMI(f_in,t_in,1) = 1.0;	/* initialize with 1 m/s in x direction */
		F_UDMI(f_in,t_in,2) = 0.0;	/* initialize with 0 m/s in y direction */
		F_UDMI(f_in,t_in,3) = 0.0;	/* initialize with 0 m/s in z direction */
	}
	end_f_loop(f_in,t_in)
}

DEFINE_PROFILE(inlet_x,t,i)
{
	face_t f;
	
	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,1);
	}
	end_f_loop(f,t)
}

DEFINE_PROFILE(inlet_y,t,i)
{
	face_t f;
	
	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,2);
	}
	end_f_loop(f,t)
}

DEFINE_PROFILE(inlet_z,t,i)
{
	face_t f;
	
	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,3);
	}
	end_f_loop(f,t)
}

DEFINE_EXECUTE_AT_END(execute_at_end)
{
	Domain *d;
	face_t f_in,f_out;
	Thread *t,*t_in,*t_out;
	int ID_outlet = 2;
	int ID_inlet = 1;
	
	begin_f_loop(f_out,t_out)
	{
		f_in = F_UDMI(f_out,t_out,0)
		F_UDMI(f_in,t_in,1) = F_U(f_out,t_out);
		F_UDMI(f_in,t_in,2) = F_V(f_out,t_out);
		F_UDMI(f_in,t_in,3) = F_W(f_out,t_out);
	}
	end_f_loop(f_out,t_out)
}
soankerabhinay likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   September 17, 2021, 22:55
Default
  #5
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
Thank you so much, Alexander. It is so kind of you to write and share this code. I wanted to check the code and understand it before responding.

I got the overall idea and the approach now. There are few things that I had little bit difficulty to understand.
In the code:
I did not understand this below line under DEFINE_INIT(init_udms, d) function:

F_UDMI(f_out,t_out,0) = f_in;

I think I am not clear what data exactly F_UDMI is storing. Is this assigning the inlet velocity value to the corresponding/adjacent node on the outlet boundary?

Question 2:
Do I need to parallelize this UDF? I will be running my fluent cases in parallel mode. Not sure if this code need any modifications to run on Parallel processing

Question 3:
I will work on temperature UDF. For temperature, do I need an UDF to initialize? Can I initialize directly through GUI?

Currently, I have an issue with my fluent running UDFs, I suspect problem with Visual code installation. Once I fix this issue I will check the code and see if it needs any modification.

I really appreciate your help.
soankerabhinay is offline   Reply With Quote

Old   September 23, 2021, 03:41
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
Question 1:

No.
The assigning of inlet velocity is here
Code:
DEFINE_EXECUTE_AT_END(execute_at_end)
{
	Domain *d;
	face_t f_in,f_out;
	Thread *t,*t_in,*t_out;
	int ID_outlet = 2;
	int ID_inlet = 1;
	
	begin_f_loop(f_out,t_out)
	{
		f_in = F_UDMI(f_out,t_out,0)
		F_UDMI(f_in,t_in,1) = F_U(f_out,t_out);
		F_UDMI(f_in,t_in,2) = F_V(f_out,t_out);
		F_UDMI(f_in,t_in,3) = F_W(f_out,t_out);
	}
	end_f_loop(f_out,t_out)
}
in idea, this:
Code:
F_UDMI(f_out,t_out,0) = f_in
is a link between finite face at outlet and finite face at inlet.

code is been made for 3D model
in DEFINE_INIT(init_udms, d)
we are comparing coordinates of each finite element at outlet with elements at inlet zone, if coordinate values in x and y directions are in range of delta we consider that face at inlet (f_in) corresponds to face at outlet (f_out).
f_in and f_out are just integer numbers
F_UDMI is user defined memory which stores a specific variable for each finite element in domain (for example temperature, pressure, density, or our own variable)

Question 2:
you don't need to modify this code to work in parallel

Question 3:
don't understand your question.
you can initialize temperature in GUI.
DEFINE_INIT is using when it is hard to initialize using GUI, or you need something to be done before very first iteration

read ansys fluent customization manual to check how to hook UDF functions properly
soankerabhinay likes this.
__________________
best regards


******************************
press LIKE if this message was helpful

Last edited by AlexanderZ; September 23, 2021 at 07:14.
AlexanderZ is offline   Reply With Quote

Old   September 23, 2021, 04:49
Default
  #7
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
Thank you Alexander, your response answered all my questions. I will spend more time and go through Ansys UDF manual and improve my coding knowledge. I really appreciate your help.
soankerabhinay is offline   Reply With Quote

Old   October 5, 2021, 04:46
Default Segmentation fault (error)
  #8
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
Hi Alexander,
Sorry to bother you again. I wrote temperature UDF, but I keep getting segmentation fault. I am trying to transfer outlet temperature to inlet at every time step. As mentioned before, my system is a closed loop heat exchanger (see picture attached), so my inlet boundary temperature needs to be same as outlet boundary at every timestep. I wrote two UDFs, Define_init and Define_execute_at_end. Both complied without any errors, but when I run the simulation, I get Segmentation error. I assigned 2 user defined memory locations. Below is my code.

#include "udf.h"

DEFINE_INIT(init_udms_1, d)
{
Domain *d_1;
face_t f_in,f_out;
Thread *t_in,*t_out;
real x_in[ND_ND], x_out[ND_ND];
int ID_outlet = 9;
int ID_inlet = 8;
t_in = Lookup_Thread (d_1, ID_inlet);
t_out = Lookup_Thread (d_1, ID_outlet);

begin_f_loop(f_out,t_out)
{
F_CENTROID(x_out,f_out,t_out);
F_T(f_out,t_out) = 300;
F_UDMI(f_out, t_out, 1) = F_T(f_out, t_out);
}
end_f_loop(f_out,t_out)

begin_f_loop(f_in,t_in)
{
F_CENTROID(x_in,f_in,t_in);
F_T(f_in,t_in) = 300;
F_UDMI(f_in, t_in, 0) = F_T(f_in, t_in);
}
end_f_loop(f_in,t_in)

}

#include "udf.h"
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
face_t f_in,f_out;
/*Thread *t,*t_in,*t_out;*/
real x_in[ND_ND],x_out[ND_ND]; /* vectors to store coordinates */
real delta = 1e-6;
int ID_outlet = 9;
int ID_inlet = 8;
Thread *t_in = Lookup_Thread(d, ID_inlet);
Thread *t_out = Lookup_Thread(d, ID_outlet);

begin_f_loop(f_out,t_out)
{
F_CENTROID(x_out,f_out,t_out);
begin_f_loop(f_in,t_in)
{
F_CENTROID(x_in,f_in,t_in);
if ((x_in[0] <= x_out[0] + delta) && (x_in[0] >= x_out[0] - delta))
{
if ((x_in[2] <= x_out[2] + delta) && (x_in[2] >= x_out[2] - delta))
{
F_UDMI(f_in, t_in, 0) = F_T(f_out,t_out);
break;
}
}
}
end_f_loop(f_in,t_in)
}
end_f_loop(f_out,t_out)
}
Attached Images
File Type: jpg closedloop_diagram.jpg (36.3 KB, 1 views)
Attached Files
File Type: c init_udms_1.c (607 Bytes, 0 views)
File Type: c execute_at_end.c (771 Bytes, 0 views)
soankerabhinay is offline   Reply With Quote

Old   October 11, 2021, 19:53
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
try to change
Code:
t_in = Lookup_Thread (d, ID_inlet);
t_out = Lookup_Thread (d, ID_outlet);
delta should be the width of minimum finite face at your inlet/outlet

did you try to run the code, which I've showed above?

actually, your code is doing nothing, it calculates something, but there is no way to apply calculated variables.

to apply something as boundary condition DEFINE_PROFILE macro is in use
soankerabhinay likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 20, 2021, 20:33
Default
  #10
New Member
 
Abhinay
Join Date: Feb 2015
Location: Bethlehem, Pennsylvania
Posts: 23
Rep Power: 11
soankerabhinay is on a distinguished road
So sorry for the late response. I realized that I did not include Define_profile. I did write that code later. Onething I noticed is when I ran the code with the below condition:

begin_f_loop(f_out,t_out)
{
F_CENTROID(x_out,f_out,t_out);
begin_f_loop(f_in,t_in)
{
F_CENTROID(x_in,f_in,t_in);
if (x_in[0] <= x_out[0] + delta) && (x_in[0] >= x_out[0] - delta)
if (x_in[1] <= x_out[1] + delta) && (x_in[1] >= x_out[1] - delta)
F_UDMI(f_out,t_out,0) = f_in;
break;
}
end_f_loop(f_in,t_in)

x_in[1] and x_out[1] doesn't match for most of the points. I think fluent is considering different set of coordinate points for both inlet and outlet boundaries. similar with x_in[0] and x_out[0]. This is happening even when both inlet and outlet boundaries have the matching mesh.
I figured out other way to do a closedloop using just execute command and updating outlet profiles at every timestep/iterations and transferring it to inlet boundary. This method doesn't required UDF. But, I think I need to run more simulations to ensure execute commend method is reliable.
Thank you so much, based on your code and inputs I understood so much about fluent UDFs and now able to code some basic UDFs by myself.

-Abhinay
soankerabhinay is offline   Reply With Quote

Reply

Tags
c code, fluent, matlab, profile edit, visual studio


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
Visual studio community 2019 wiki123 Fluent UDF and Scheme Programming 4 July 30, 2021 11:59
UDF Compiling MayTheFlowBeWithYou Fluent UDF and Scheme Programming 2 July 25, 2017 12:43
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
Working directory via command line Luiz CFX 4 March 6, 2011 20:02
UDF Error Sid FLUENT 3 July 2, 2007 10:34


All times are GMT -4. The time now is 00:56.