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

Scheme File Needed For UDF to Work?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 21, 2018, 18:21
Default Scheme File Needed For UDF to Work?
  #1
Member
 
Matt Ridzon
Join Date: Jun 2014
Posts: 91
Rep Power: 12
m_ridzon is on a distinguished road
See the attached *.SCM file (scheme file) and *.C file (UDF). These were given to me in response to an inquiry about printing results to a text file along a line in the domain. I've never heard of scheme files until this. And my UDF knowledge is quite limited. The UDF uses "DEFINE_ON_DEMAND," but if you execute it on demand from the GUI without the scheme file (via Ribbon > User Defined > Execute On Demand), the FOR loop at line 45 of the UDF does not seem to work. This leads me to believe the scheme file activates something that permits the FOR loop to work. But I don't know what.

My end goal would be to scrap the scheme file and just use the UDF to simplify things (more files means more complexity, which I don't want). But I don't know what the scheme file is doing that the UDF requires.

Note, I'm using v182 Fluent.

Thanks in advance,
M Ridzon
Attached Files
File Type: zip Data.zip (1.0 KB, 26 views)
m_ridzon is offline   Reply With Quote

Old   December 23, 2018, 23: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
Scheme file
Code:
(if (not (rp-var-object 'line_id))(rp-var-define 'line_id 999 'int #f))
(if (not (rp-var-object 'line_name))(rp-var-define 'line_name 'axis 'string #f))

(define (idnumb idname)
   (let ()
    (rpsetvar 'line_id (surface-name->id idname))
    (rpsetvar 'line_name idname)
    (ti-menu-load-string (format #f "di s-m (~a)" (rpgetvar 'line_id)))
    (ti-menu-load-string "de ud eod \"write_line_data::libudf\"")   
))
it makes line_id and line_name variables, so you may create any line at the same case and easily write to file data from that line by changing ID and name of line (changing variable values)

for instance to set your line name "name" and ID "414" you should execute in Fluent console following command:
Code:
(rpsetvar 'line_id 414)
(rpsetvar 'line_name name)
to get the values of you variables:
Code:
(rpgetvar 'line_id)
(rpgetvar 'line_name)
the second part of the scheme script creates function called idnumb which takes the name of line/surface you want, check it's ID, write ID to line_id variable, write name to line_name variable and executes your UDF (execute_on_demand function)

so lets assume you've created line called "myline1", than after you've read scheme file (in fluent GUI file->read -> scheme), put in fluent console following:
Code:
(idnumb 'myline1)
script will modify line_id and line_name variables, and execute on_demand UDF function -> write data from "myline1" to file

best regards
AlexanderZ is offline   Reply With Quote

Old   December 23, 2018, 23:24
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
udf
Code:
#include "udf.h"
#include "surf.h"
#include "cxsurf.h"
#include "cxiface.h"
#include "dx.h"

DEFINE_ON_DEMAND(write_line_data)
{
	Surface *s;
	Surf_Point *p;
	Domain *d = Get_Domain(1);
	int i, j, k, l,index, nw,nfp;
	real value, x, y, z;
	char *what;
	char *datafn;
	int line_id;
	FILE *fp;

	datafn = RP_Get_String("line_name");
	line_id = RP_Get_Integer("line_id");

	fp = fopen(datafn,"w+");

	/* s is the surface having data of surface id SID */
	/* s->np no of points
	  s->nf no of faces
	  s->points points to array of np points
	  s->ip pointer to interpolation vector of np points
	  s->cells pointer to cells of each point
	  s->nfl facet list
    */

	s = SurfaceList+line_id;

	what = "x-velocity";

	/* header */
	fprintf(fp,"    x-coordinate,    y-coordinate,    z-coordinate,");
	fprintf(fp,"%16s",what);
	fprintf(fp,"\n");

	Node_Function_Values(d,what);
	p = s->points;

	for(i=0;i<s->np;i++)
	{
		x = Get_Surface_Point_Coord(p,X_DIM);
		y = Get_Surface_Point_Coord(p,Y_DIM);
		z = Get_Surface_Point_Coord(p,Z_DIM);
		value = Surface_Value(p);
		fprintf(fp,"% 16.9E,% 16.9E,% 16.9E",x,y,z);
		fprintf(fp,",% 16.9E",value);
		fprintf(fp,"\n");
		p += 1;
	}
	fclose(fp);
}
is you don't want to use scheme, you may do it by hard copy name and line ID. But once you will need to use other line, you must recompile udf library.
Code:
	datafn = RP_Get_String("line_name");
	line_id = RP_Get_Integer("line_id");
So these line may be modified, for instance for line "myline1" with id 111:
Code:
datafn = "myline1";
	line_id = 111;
best regards
AlexanderZ is offline   Reply With Quote

Old   December 29, 2018, 09:36
Default
  #4
Member
 
Matt Ridzon
Join Date: Jun 2014
Posts: 91
Rep Power: 12
m_ridzon is on a distinguished road
@AlexanderZ, thank you! This was very helpful information. As I was troubleshooting further, I learned something very odd, that maybe you can comment about. I modified the UDF to omit the scheme file. I opened Fluent and loaded the Case and Data files. I then loaded the UDF and executed it. I learned that the UDF outputs no data (i.e., blank file except for its header line), unless you first "display" the lines. That is, go to the Ribbon > Setting Up Domain > Display. Then display the whole model including the line(s). This led me to believe the software has no awareness of lines existing in the Case file when it's initially loaded. In fact, I noticed the following in the TUI when loading the Case file:

Code:
              Welcome to ANSYS Fluent Release 18.2.2

              Copyright 2017 SAS IP, Inc. All Rights Reserved.
              Unauthorized use, distribution or duplication is prohibited.
              This product is subject to U.S. laws governing export and re-export.
              For full Legal Notice, see documentation.

Build Time: Jul 25 2017 20:06:56  Build Id: 10098  
 


Cleanup script file is C:\Users\Ridzon\Documents\_P\cleanup-fluent-Ridzon-E6530-22600.bat

> Reading "\"| gunzip -c \"C:/Users/Ridzon/Documents/_P/manifold.cas.gz\"\""...


   77880 tetrahedral cells, zone  2, binary.
   17940 triangular wall faces, zone  3, binary.
      54 triangular outflow faces, zone  4, binary.
      54 triangular velocity-inlet faces, zone  5, binary.
      54 triangular velocity-inlet faces, zone  6, binary.
      54 triangular velocity-inlet faces, zone  7, binary.
  146682 triangular interior faces, zone  9, binary.
   17880 nodes, binary.
   17880 node flags, binary.

Opening library "C:\Users\Ridzon\Documents\_P\libudf"...
Library "C:\Users\Ridzon\Documents\_P\libudf\win64\3ddp\libudf.dll" opened
	write_line_data
Done.


  WARNING -- More than one Viscous Model found active.
             ---- Changing Viscous Model to k-epsilon...


Building...
     mesh
     materials,
     interface,
     domains,
	mixture
     zones,
	wall-group.1
	outlet.1
	inlet.3
	inlet.2
	inlet.1
	default-interior
	fluid.1
Done.

Preparing mesh for display...
Done.
Reading "\"| gunzip -c \"C:/Users/Ridzon/Documents/_P/manifold.dat.gz\"\""...


Done.
Notice the latter part in the "Building" list where no lines are mentioned, despite them existing in the Case file. Is there a way to get the software to "build" and recognize the existence of the line(s) upon reading the Case file, without having to "Display" them? Once the software knows they exist, the UDF works nicely.
m_ridzon is offline   Reply With Quote

Old   December 30, 2018, 21:53
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your line is not a part of mesh, that is why you will never see lines at BUILD part
If the line exists, you dont need to display it

best regards
AlexanderZ is offline   Reply With Quote

Old   December 31, 2018, 09:34
Default
  #6
Member
 
Matt Ridzon
Join Date: Jun 2014
Posts: 91
Rep Power: 12
m_ridzon is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
If the line exists, you dont need to display it
This doesn't seem to make sense, because the UDF does not work unless I first "display" the line. Displaying it seems to trigger and acknowledge the line's existence in the model, which then allows the UDF to output meaningful data. If I don't "display" the line first, the UDF output is blank.
m_ridzon 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
OpenFoam "Permission denied" and "command not found" problems. iyidaniel@yahoo.co.uk OpenFOAM Running, Solving & CFD 11 January 2, 2018 07:47
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit ParaView 60 September 18, 2013 04:23
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 17:28.