|
[Sponsors] |
In parallel computing, how to make a variable have the same value in all nodes? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 23, 2015, 00:15 |
In parallel computing, how to make a variable have the same value in all nodes?
|
#1 |
New Member
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11 |
Hi,
I tried to control my boundary conditions by judging the temperature of one cell. For example, if the temperature is larger than a value, make inlet velocity be 1, if lower, make it 0. I wrote a code that works well if I use only one CPU to compute, even if node number is 2, it also works. But when the node number are bigger, like 4 and 8. The temperature criterion don't work anymore. When I run the code using multiple nodes, I can see that the temperature value I used to do the judgement is different in every nodes. Like this: I am node 0 with thermocouple temperature out: 296.163788 I am node 1 with thermocouple temperature out: 0.000000 I don't know how to make the value be the same in all nodes. I tried to use the function PRF_GRSUM1(). But fluent told me error. I interpreted my udf. Do I need to compile it if I want to use the functions like the above one? But if I try to compile, I meet more errors. I really don't know what to do now. I know there are experts in this forum. Hope somebody can help me, I really appreciate! The code I write is listed below: /*get rid of if(myid==0) first to see which node the thermocouple point is in, and then let node number equal to "myid"*/ /*also, at last, the judgement of the temperature value is decided by the thermosensor_temperature of node 0's value*/ #include "udf.h" #define upTemp 300.35 #define lowTemp 299.95 #define dterm1 0.43 #define dterm2 0.43 #define dterm3 0.43 #define dterm4 0.43 real thermosensor_T; DEFINE_EXECUTE_AT_END(tsensor) { real thermosensor_coordinate[ND_ND]; real thermosensor_temperature; real xmin; real xmax; real ymin; real ymax; int nt; real x=1,y=1; cell_t c; Domain *d; Thread *t; d = Get_Domain(1); /*get domain id, single phase is 1*/ xmin=0.2449; xmax=0.2453; ymin=-0.001; ymax=0.001; /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */ if(myid==0) { thread_loop_c(t,d) { nt=0; begin_c_loop(c,t) { C_CENTROID(thermosensor_coordinate,c,t); x=thermosensor_coordinate[0]; y=thermosensor_coordinate[1]; if ((x >= xmin) && (x <= xmax)) { if ((y >= ymin) && (y <= ymax)) { thermosensor_temperature=thermosensor_temperature + C_T(c,t); /* get thermocouple temperature */ nt=nt+1; /* count number */ printf("x: %f\n", x); printf("y: %f\n", y); // printf("nt1: %d\n", nt); // printf("I am node %d with thermocouple temperature: %f\n", myid, thermosensor_temperature); } } } end_c_loop(c,t) // printf("nt2: %d\n", nt); } thermosensor_T=thermosensor_temperature/2; printf("nt outside loop2: %d\n", nt); printf("I am node %d with thermocouple temperature: %f\n", myid, thermosensor_T); } printf("I am node %d with thermocouple temperature out: %f\n", myid, thermosensor_T); } DEFINE_PROFILE(inlet_V,t,i) { face_t f; //printf("temperature: %f\n", thermosensor_T); if (thermosensor_T>=upTemp) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 1.38; } end_f_loop(f,t) } else if (thermosensor_T<lowTemp) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 0; } end_f_loop(f,t) } } DEFINE_SOURCE(heat_gen1,cell,thread,dS,eqn) { real source; real temp; temp=CURRENT_TIME; if (temp<740) { source = dterm1*(5.240E-06*temp*temp*temp + 9.837E-03*temp*temp - 6.883*temp + 4.582E+04);} else {source=0;} dS[eqn] = 0; return source; } DEFINE_SOURCE(heat_gen2,cell,thread,dS,eqn) { real source; real temp; temp=CURRENT_TIME; if (temp<740) { source=dterm2*(-2.359E-05*temp*temp*temp + 3.599E-02*temp*temp - 1.271E+01*temp + 5.216E+04);} else {source=0;} dS[eqn] = 0; return source; } DEFINE_SOURCE(heat_gen3,cell,thread,dS,eqn) { real source; real temp; temp=CURRENT_TIME; if (temp<740) { source=dterm3*(-1.048E-05*temp*temp*temp + 2.116E-02*temp*temp - 7.338*temp + 5.118E+04);} else {source=0;} dS[eqn] = 0; return source; } DEFINE_SOURCE(heat_gen4,cell,thread,dS,eqn) { real source; real temp; temp=CURRENT_TIME; if (temp<770) { source=dterm4*(-1.048E-05*temp*temp*temp + 2.062E-02*temp*temp - 7.338*temp + 4.977E+04);} else {source=0;} dS[eqn] = 0; return source; } |
|
January 23, 2015, 11:36 |
|
#2 |
Senior Member
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 14 |
Global reductions such as PRF_GRSUM1 need to be compiled, not interpreted. Maybe someday they'll call that out in the UDF Manual, but for now, all you can do is find it out the hard way.
Off the top of my head, I can't think of any workaround to be able to do this without compiling. Once you do get it compiled, though, I suggest you use PRF_GRHIGH1 rather than PRF_GRSUM1; as long as you're only sampling one cell, they won't be different, but if you decide to sample more than one cell (either intentionally or from a bug), the maximum will be less affected than the sum. |
|
January 23, 2015, 13:47 |
|
#3 | |
New Member
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11 |
Thanks for your reply! I really don't know they needs to be compiled...
Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] some errors in compiling groovyBC in OF220 | immortality | OpenFOAM Community Contributions | 10 | April 1, 2013 04:46 |
unchangeable continuity residuals in parallel computing | wlt_1985 | FLUENT | 0 | August 1, 2011 13:15 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 05:35 |
Prob with UDF on parallel computing | mainamunna | FLUENT | 0 | February 12, 2008 09:26 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 21:09 |