average path length from each injection


The following udf can be used to calculate average path length and residence time
from each injection and can also be used to find out the average path length
of all injections.



#include "udf.h"
#define NMAX 100000

static int last_id = -1;
int count =-1;
int i=-1,k=0;
real x0,x1,x2,time_p[100],time_pinit[100];
real len[NMAX];
int count1[100],count_check=0;
char so[100]="";
char sn[100]="";
int no_of_tries[100];
DEFINE_DPM_SCALAR_UPDATE(store-path,c,t,in,p)
{
real xn0,xn1,xn2;
int id_n = p->part_id;

sprintf(sn,p->injection->name);
if(strcmp(sn,so)!=0 || k==0){
count1[k]=p->injection->n_particles;
no_of_tries[k]=1;
if(p->injection->stochastic_p !=0)
no_of_tries[k]=p->injection->ntries;
k++;
}

if(strcmp(sn,so)!= 0 || id_n != last_id){
last_id=id_n;
count = -1;
i++;
}
count ++ ;
if(count==0){
len[i]=0.0;
time_pinit[i]=P_TIME(p);
x0=P_POS(p)[0];
x1=P_POS(p)[1];
x2=P_POS(p)[2];
}

xn0=P_POS(p)[0];
xn1=P_POS(p)[1];
xn2=P_POS(p)[2];
len[i] += sqrt(pow((xn0-x0),2)+pow((xn1-x1),2)+pow((xn2-x2),2));
time_p[i]=P_TIME(p);
x0=P_POS(p)[0];
x1=P_POS(p)[1];
x2=P_POS(p)[2];
sprintf(so,sn);
}


DEFINE_ON_DEMAND(on_demand_exec)
{
int j,jc,kc=0,kc1=0,counter=0;
real avg[100],sum[100],avg_glob,t_sum=0.0,sum_time[100];
for(jc=0;jc<k;jc++){
sum[jc]=0.0;
sum_time[jc]=0.0;
if(jc>0)
kc += count1[jc-1]* no_of_tries[jc-1];
kc1 += count1[jc] * no_of_tries[jc];
for(j=kc;j<kc1;j++){
Message("Path length for particle- %d in injection-%d is %fn",j,jc,len[j]);
sum[jc] += len[j];
sum_time[jc] +=(time_p[j]-time_pinit[j]);
}
Message("avg path length from injection-%d is %fn",jc,sum[jc]/(count1[jc]*no_of_tries[jc]));
Message("avg res time from injection-%d is %fn",jc,sum_time[jc]/(no_of_tries[jc]*count1[jc]));
}
}





Show Form
No comments yet. Be the first to add a comment!