/** Calculate the local fluid stress. * The calculation is implemented explicitly for the special case of D3Q19. * @param index The local lattice site (Input). * @param pi local fluid pressure */ inline void lb_calc_local_pi(index_t index, double *pi) { double rho; double j[3]; if (!(lattice_switch & LATTICE_LB)) { runtimeErrorMsg() <<"Error in lb_calc_local_pi in " << __FILE__ << __LINE__ << ": CPU LB not switched on."; j[0] = j[1] = j[2] = 0; return; } lb_calc_local_fields(index, &rho, j, pi); }
/** Calculate the local fluid stress. * The calculation is implemented explicitly for the special case of D3Q19. * @param index The local lattice site (Input). * @param pi local fluid pressure */ inline void lb_calc_local_pi(index_t index, double *pi) { double rho; double j[3]; if (!(lattice_switch & LATTICE_LB)) { ERROR_SPRINTF(runtime_error(128), "{ Error in lb_calc_local_pi in %s %d: CPU LB not switched on. } ", __FILE__, __LINE__); j[0] = j[1] = j[2] = 0; return; } lb_calc_local_fields(index, &rho, j, pi); }
/** Calculate temperature of the LB fluid. * \param result Fluid temperature */ void lb_calc_fluid_temp(double *result) { int x, y, z, index; double rho, j[3]; double temp = 0.0; for (x=1; x<=lblattice.grid[0]; x++) { for (y=1; y<=lblattice.grid[1]; y++) { for (z=1; z<=lblattice.grid[2]; z++) { index = get_linear_index(x,y,z,lblattice.halo_grid); lb_calc_local_fields(index, &rho, j, NULL); temp += scalar(j,j); } } } temp *= 1./(3.*lbpar.rho*lblattice.grid_volume*lbpar.tau*lbpar.tau*lblattice.agrid); MPI_Reduce(&temp, result, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); }
/** Calculate a velocity profile for the LB fluid. */ void lb_calc_velprof(double *result, int *params) { int index, dir[3], grid[3]; int newroot=0, subrank, involved=0; double rho, j[3], *velprof; MPI_Comm slice_comm = NULL; MPI_Status status; if (this_node != 0) params = malloc(4*sizeof(int)); MPI_Bcast(params, 4, MPI_INT, 0, MPI_COMM_WORLD); int vcomp = params[0]; int pdir = params[1]; int x1 = params[2]; int x2 = params[3]; dir[pdir] = 0; dir[(pdir+1)%3] = x1; dir[(pdir+2)%3] = x2; //fprintf(stderr,"%d: (%d,%d,%d)\n",this_node,dir[0],dir[1],dir[2]); newroot = map_lattice_to_node(&lblattice, dir, grid); map_node_array(this_node, node_pos); //fprintf(stderr,"%d: newroot=%d (%d,%d,%d)\n",this_node,newroot,grid[0],grid[1],grid[2]); if ( (grid[(pdir+1)%3] == node_pos[(pdir+1)%3]) && (grid[(pdir+2)%3] == node_pos[(pdir+2)%3]) ) { involved = 1; } MPI_Comm_split(MPI_COMM_WORLD, involved, this_node, &slice_comm); MPI_Comm_rank(slice_comm, &subrank); if (this_node == newroot) result = realloc(result,box_l[pdir]/lblattice.agrid*sizeof(double)); //fprintf(stderr,"%d (%d,%d): result=%p vcomp=%d pdir=%d x1=%d x2=%d involved=%d\n",this_node,subrank,newroot,result,vcomp,pdir,x1,x2,involved); if (involved) { velprof = malloc(lblattice.grid[pdir]*sizeof(double)); //dir[(pdir+1)%3] += 1; //dir[(pdir+2)%3] += 1; for (dir[pdir]=1;dir[pdir]<=lblattice.grid[pdir];dir[pdir]++) { index = get_linear_index(dir[0],dir[1],dir[2],lblattice.halo_grid); lb_calc_local_fields(index, &rho, j, NULL); //fprintf(stderr,"%p %d %.12e %.12e %d\n",lbfluid[0],index,rho,j[0],vcomp); if (rho < ROUND_ERROR_PREC) { velprof[dir[pdir]-1] = 0.0; } else { //velprof[dir[pdir]-1] = local_j / (SQR(lbpar.agrid)*lbpar.tau); velprof[dir[pdir]-1] = j[vcomp]/rho * lblattice.agrid/lbpar.tau; //fprintf(stderr,"%f %f %f\n",velprof[dir[pdir]-1],local_j,local_rho); } //if (dir[pdir]==lblattice.grid[pdir]) { // int i; // fprintf(stderr,"(%d,%d,%d)\n",dir[0],dir[1],dir[2]); // fprintf(stderr,"%d\n",lbfluid[index].boundary); // for (i=0;i<lbmodel.n_veloc;i++) fprintf(stderr,"local_n[%p][%d]=%.12e\n",lbfluid[index].n,i,lbfluid[index].n[i]+lbmodel.coeff[i][0]*lbpar.rho); // fprintf(stderr,"local_rho=%e\n",local_rho); // fprintf(stderr,"local_j=%e\n",local_j); //} } MPI_Gather(velprof, lblattice.grid[pdir], MPI_DOUBLE, result, lblattice.grid[pdir], MPI_DOUBLE, newroot, slice_comm); free(velprof); } MPI_Comm_free(&slice_comm); if (newroot != 0) { if (this_node == newroot) { MPI_Send(result, lblattice.grid[pdir]*node_grid[pdir], MPI_DOUBLE, 0, REQ_VELPROF, MPI_COMM_WORLD); free(result); } if (this_node == 0) { //fprintf(stderr,"%d: I'm just here!\n",this_node); MPI_Recv(result, lblattice.grid[pdir]*node_grid[pdir], MPI_DOUBLE, newroot, REQ_VELPROF, MPI_COMM_WORLD, &status); //fprintf(stderr,"%d: And now I'm here!\n",this_node); } } if (this_node !=0) free(params); }