|
[Sponsors] |
May 3, 2016, 05:29 |
how to get a momentum source from a txt?
|
#1 |
New Member
Lvan Lee
Join Date: Apr 2016
Posts: 3
Rep Power: 10 |
It was a simulation about mold electromagnetic stirring in continuous casting.
I worked out the lorentz force from Ansys Maxwell, now I want to add the lorentz force as source terms using the DEFINE_SOURCE macro. First, I got the cell centroid coordinates of the model mesh with the UDF. #include"udf.h" FILE*fout;float xx[ND_ND]; DEFINE_ON_DEMAND(get_coords) { Domain *domain; face_t f; cell_t c;Thread *t; domain=Get_Domain(1); t=Lookup_Thread(domain,2); fout=fopen("coordinates.out","w"); if (fout==NULL) Message("Can't open the file"); else { begin_c_loop(c,t) { C_CENTROID(xx,c,t); fprintf(fout,"%d %g %g %g\n",c,xx[0],xx[1],xx[2]); } end_c_loop(c,t) fprintf(fout,"\n"); fclose(fout); } } From this I get the coordinates.out, and I worked out the lorentz force on every coordinate as a constant. Then I need to put the lorentz force on every coordinate as a momentum source. This is the udf that I worte, but I don't know whether it could match the grids or not.(one-to-one correspondence) #include "udf.h" #define cnum 83325 /*number of cell*/ float fx[cnum],fy[cnum],cn[cnum],fz[cnum]; DEFINE_ON_DEMAND(getmagforce) { FILE *file; int i; file=fopen("lforce.txt","r"); /*external files*/ if (file==NULL) {Message("Can't open file");} else { for(i=1;i<=cnum;i++) { fscanf(file,"%f",&cn[i]); fscanf(file,"%f",&fx[i]); fscanf(file,"%f",&fy[i]); fscanf(file,"%f",&fz[i]); } fclose(file); } } DEFINE_SOURCE(x_momentum_source,c,t,dS,eqn) {int m; real source; m=c+1; source=fx[m]; dS[eqn]=0; return source; } DEFINE_SOURCE(y_momentum_source,c,t,dS,eqn) {int m; real source; m=c+1; source=fy[m]; dS[eqn]=0; return source; } DEFINE_SOURCE(z_momentum_source,c,t,dS,eqn) {int m; real source; m=c+1; source=fz[m]; dS[eqn]=0; return source; } Plz help me! Thanks very much! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
[swak4Foam] build problem swak4Foam OF 2.2.0 | mcathela | OpenFOAM Community Contributions | 14 | April 23, 2013 14:59 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
Problem with Mass source, Momentum source theory | diffo | Fluent UDF and Scheme Programming | 0 | August 20, 2009 07:10 |