AcouSTO  version 2.0

◆ pre_mic()

void pre_mic ( COMPLEX  cfreq,
int  icounter 
)

Evaluates solution at microphones. Coefficients are read on disk. This function is called when pre_calculate_coefs == 1.

Parameters
[in]cfreqCOMPLEX frequency
[in]icounterfrequency index
36  {
37  int i;
38  int iphiu;
39  int nphiu;
40  int nphib;
41 
42  int mpi_ncntr,mpi_nelmu;
43  int bstride,cstride;
44 
45  int locRows,locCols,locCRows;
46  int gRows,gCols,gCRows;
47  int ielmb,ielmu;
48  int j;
49  int descpsiu[9];
50  int descgpsiu[9];
51  int mm,nn;
52  int ione = 1;
53  int izero = 0;
54  int info;
55  struct vector g;
56  struct vector un;
57  struct panel4* mpi_elements;
58 
59  DOUBLE gdotn;
60 
61 
62  COMPLEX cexpo;
63  DOUBLE bb,cc,dd,theta;
64  COMPLEX rho_s;
65 
66  Vec psincvec;
67  Vec phincvec;
68 
69  COMPLEX phiscval = COMPLEX_ZERO; // Cauchy Data
70  COMPLEX phincval = COMPLEX_ZERO;
71  COMPLEX phitcval = COMPLEX_ZERO;
72 
73  COMPLEX psincval = COMPLEX_ZERO;
74  COMPLEX psiscval = COMPLEX_ZERO;
75  COMPLEX psitcval = COMPLEX_ZERO;
76 
77  COMPLEX phincmval = COMPLEX_ZERO; // Potential at microphones
78  COMPLEX phiscmval = COMPLEX_ZERO;
79  COMPLEX phitmval = COMPLEX_ZERO;
80 
81  COMPLEX prescmval = COMPLEX_ZERO;
82  COMPLEX pretmval = COMPLEX_ZERO;
83 
84  DOUBLE* ctmp;
85  int ic,is;
86  int bsymmoffset,csymmoffset;
87 
88 
89  FILE* fbcoef = NULL;
90  FILE* fccoef = NULL;
91  int nrow,nrowi,iloop,nloop,irow,nio,nrlast;
92  char fbname[MAX_PATH];
93  char fcname[MAX_PATH];
94 
95 #ifdef _ACOUSTO_DEBUG
96  int imics;
97  char fname[MAX_PATH];
98  FILE* f;
99 #endif
100 
101  COMPLEX lambda;
102  COMPLEX gamma;
103  COMPLEX func;
104  COMPLEX gamma_over_lambda;
105  COMPLEX lambda_over_gamma;
106 
107  mpi_elements = geometry->elements;
108  mpi_ncntr = modgeominfo->ncntr + modgeominfo->nchief;
109  mpi_nelmu = modgeominfo->ncntr;
110  nphiu = modgeominfo->ncntr;
111 
112  gRows = modgeominfo->nmics;
113  gCols = modgeominfo->ncntr;
114  gCRows = nphiu;
115 
116  locRows = numroc_(&gRows ,&runinfo->mics_block_size,&runinfo->myrow,&izero,&runinfo->nprows);
117  locCols = numroc_(&gCols ,&runinfo->col_block_size,&runinfo->mycol,&izero,&runinfo->npcols);
118  locCRows = numroc_(&gCRows ,&runinfo->row_block_size,&runinfo->myrow,&izero,&runinfo->nprows);
119 
120  nrow = runinfo->krow;
121  if(runinfo->krow <=0 || runinfo->krow >= locRows) nrow = locRows;
122 
123  if(runinfo->krow > 0){
124  micscoefs->B = calloc(2*nrow*locCols*runinfo->nsymm,sizeof(DOUBLE));
125  micscoefs->C = calloc(3*nrow*locCols*runinfo->nsymm,sizeof(DOUBLE));
126  }
127  ctmp = calloc(locRows,sizeof(DOUBLE));
128 
129  nphib = modgeominfo->nelmb;
130 
131  if(0==icounter){
132  CREATE_VEC(solution->vecPhium ,locRows);
133  CREATE_VEC(solution->vecPrescm,locRows);
134  CREATE_VEC(solution->vecPretm ,locRows);
135  }
136  VecZeroEntries(solution->vecPhium ,locRows);
137  VecZeroEntries(solution->vecPrescm ,locRows);
138  VecZeroEntries(solution->vecPretm ,locRows);
139 
140  psincvec = calloc(nphiu,sizeof(COMPLEX)); // allocating vector
141  phincvec = calloc(nphiu,sizeof(COMPLEX)); // allocating vector
142 
143  // Gathering psiu on node 0 and broadcasting
144  // Collecting solution on node zero and broadcasting to everyone
145  mm = gCRows;// * runinfo->nprows;
146  nn = runinfo->npcols;
147  descinit_(descpsiu , &gCRows ,&ione, &runinfo->row_block_size ,&ione,&izero,&izero,&runinfo->ctxt,&gCRows ,&info);
148  descinit_(descgpsiu , &mm ,&ione, &gCRows ,&ione,&izero,&izero,&runinfo->ctxt,&gCRows ,&info);
149  pzgemr2d_(&gCRows,&ione,solution->vecPsinc,&ione, &ione,descpsiu, psincvec,&ione,&ione,descgpsiu,&runinfo->ctxt);
150  pzgemr2d_(&gCRows,&ione,solution->vecPhinc,&ione, &ione,descpsiu, phincvec,&ione,&ione,descgpsiu,&runinfo->ctxt);
151 
152  MPI_Bcast(psincvec,gCRows,MPI_ACOUSTO_COMPLEX,0,MPI_COMM_WORLD);
153  MPI_Bcast(phincvec,gCRows,MPI_ACOUSTO_COMPLEX,0,MPI_COMM_WORLD);
154 
155  rho_s = cfreq*modsolinfo->rho;
156 
157 
158  /* Since we are splitting also on columns Pressure on microphones must be summed on the columns
159  * of the grid.
160  * e.g.:
161  * for pressure on microphones in row 0 of the process grid (PRE00, PRE01, PRE02)
162  * the actual pressure on the microphones is the sum on the colums (PRE00+PRE01+PRE02)
163  *
164  * This is due to the choice of splitting the body elements along the column of the process
165  * grid and to the fact that the evaluation of pressure is simply additive.
166  *
167  * This also applies to potential at microphones
168  *
169  * 0 1 2
170  * --------------------------------
171  * | | | |
172  * 0 | PRE00 | PRE01 | PRE02 |
173  * | | | |
174  * --------------------------------
175  * | | | |
176  * 1 | PRE11 | PRE11 | PRE12 |
177  * | | | |
178  * --------------------------------
179  *
180  **/
181 
182  if(runinfo->krow > 0){
183  get_filename(fbname,"mbcoefs.bin.%d",rank);
184  get_filename(fcname,"mccoefs.bin.%d",rank);
185  fbcoef = fopen(fbname,"rb"); fccoef = fopen(fcname,"rb");
186  }
187 
188  j12(locRows,nrow,&nrlast,&nloop);
189  for(iloop=0;iloop<nloop;iloop++){ // LOOP ON NLOOP
190  ic = 0;
191  nrowi = nrow;
192  if(iloop == nloop-1) nrowi = nrlast;
193  bstride = nrowi*locCols;
194  cstride = nrowi*locCols;
195  if(runinfo->krow > 0){
196  nio = fread(micscoefs->B,sizeof(DOUBLE),2*nrowi*locCols*runinfo->nsymm,fbcoef);
197  nio = fread(micscoefs->C,sizeof(DOUBLE),3*nrowi*locCols*runinfo->nsymm,fccoef);
198  }
199  for(irow=0;irow<nrowi;irow++){ // LOOP ON NROW
200 
201  i= j21(irow ,iloop,nrow);
202  phiscmval = COMPLEX_ZERO;
203 
204  for(j=0;j<locCols;j++){
205  // getting local indices
207 
208  for(is=0;is<runinfo->nsymm;is++){
209 
210  bsymmoffset = is * 2*nrowi*locCols;
211  csymmoffset = is * 3*nrowi*locCols;
212  ielmb = ielmu + is*mpi_nelmu;
213  iphiu = ielmu;
214 
215  ic = irow*locCols +j;
216 
217  /* Coefficients at microphones */
218  bb = micscoefs->B[ic + bsymmoffset];
219  cc = micscoefs->C[ic + csymmoffset];
220  dd = micscoefs->C[ic + cstride + csymmoffset];
221  theta = micscoefs->C[ic + cstride*2 + csymmoffset];
222 
223  cexpo = CEXP(-cfreq*theta);
224 
225  psincval = psincvec[iphiu]; // Psi_incident on surface
226  phincval = phincvec[iphiu]; // Phi_incident on surface
227 
228  vec_copy(&un,mpi_elements[ielmb].n);
229  lambda = bc.lambda[ielmu];
230  gamma = bc.gamma[ielmu];
231  func = bc.func[ielmu];
232  gamma_over_lambda = gamma/lambda;
233  lambda_over_gamma = lambda/gamma;
234  g.x = bc.g.x;
235  g.y = bc.g.y;
236  g.z = bc.g.z;
237  gdotn = vec_dot(g,un);
238 
239  if (1 == modsolinfo->dirneu){ // Dirichlet-type formulation
240 
241  if(1 == modsolinfo->knw){ // Phi scatttering on surface
242  psitcval = solution->sol[iphiu];
243  psiscval = solution->sol[iphiu] - psincval; // Form A
244  phitcval = (func+gdotn)/gamma - lambda_over_gamma * psitcval;
245  phiscmval += bb*cexpo*psitcval + (cc + cfreq*dd)*phitcval*cexpo;
246  }else if (2 == modsolinfo->knw){
247  psiscval = solution->sol[iphiu];
248  psitcval = psiscval + psincval; // Form B
249  phitcval = (func+gdotn)/gamma - lambda_over_gamma * psitcval;
250  phiscval = phitcval - phincval;
251  phiscmval += bb*cexpo*psiscval + (cc + cfreq*dd)*phiscval*cexpo;
252  }
253 
254  }else if (2 == modsolinfo->dirneu){
255 
256  if(1 == modsolinfo->knw){ // Phi scatttering on surface
257  phitcval = solution->sol[iphiu];
258  phiscval = solution->sol[iphiu] - phincval; // Form A
259  }else if (2 == modsolinfo->knw){
260  phiscval = solution->sol[iphiu];
261  phitcval = phiscval + phincval; // Form B
262  }
263 
264  if(1 == modsolinfo->knw){
265  phiscmval += bb*cexpo*((func+gdotn)/lambda - gamma_over_lambda * phitcval) + (cc + cfreq*dd)*phitcval*cexpo;
266  }else if (2 == modsolinfo->knw){
267  phiscmval += bb*cexpo*((func+gdotn)/lambda - gamma_over_lambda * phincval - gamma_over_lambda*phiscval - psincval) + (cc+cfreq*dd)*phiscval*cexpo;
268  }
269  }
270  }
271  }
272 
273  phincmval = solution->vecPhincm[i];
274  phitmval = phincmval + phiscmval;
275 
276  // prescmval = -rho_s * phiscmval;
277  // pretmval = -rho_s * phitmval;
278 
279  prescmval = phiscmval;
280  pretmval = phitmval;
281 
282  solution->vecPhium [i] = phiscmval;
283 
284  solution->vecPrescm[i] = prescmval;
285  solution->vecPretm [i] = pretmval;
286 
287  } // END OF LOOP ON NROW
288  } // END OF LOOP ON NLOOP
289  if(runinfo->krow > 0){
290  fclose(fbcoef); fclose(fccoef);
291  }
292  Czgsum2d(runinfo->ctxt,"R"," ",locRows,1,solution->vecPhium ,locRows,-1,-1);
293  Czgsum2d(runinfo->ctxt,"R"," ",locRows,1,solution->vecPrescm ,locRows,-1,-1);
294  Czgsum2d(runinfo->ctxt,"R"," ",locRows,1,solution->vecPretm ,locRows,-1,-1);
295 
296 
297  // summing on process columns
298 
299 #ifdef _ACOUSTO_DEBUG
300  sprintf(fname,"pre.%d%d",runinfo->myrow,runinfo->mycol);
301  f = fopen(fname,"w");
302  for(i=0;i<locRows;i++){
304  fprintf(f," %d %f %f %f %f %f %f\n",imics,
308  );
309  }
310  fclose(f);
311 #endif
312 
313  /* Printing pressures */
314 
315  if(modsolinfo->printout){
316  print_premic_on_master(cfreq);
317  }
318 
319  VecDestroy(psincvec);
320  VecDestroy(phincvec);
321 
322  if(runinfo->krow > 0){
323  free(micscoefs->B);
324  free(micscoefs->C);
325  }
326 
327 }
struct run_info * runinfo
Definition: globals.h:34
#define Vec
Definition: types.h:63
int npcols
Definition: structs.h:113
#define VecDestroy(v)
Definition: allocation.h:111
int ncntr
Definition: structs.h:299
DOUBLE * C
Definition: structs.h:372
#define CREAL(x)
Definition: functions.h:49
void Czgsum2d(int ctxt, char *scope, char *top, int m, int n, COMPLEX *A, int llda, int recr, int recc)
#define MPI_ACOUSTO_COMPLEX
Definition: types.h:56
Vec vecPsinc
Definition: structs.h:580
int myrow
Definition: structs.h:115
void vec_copy(struct vector *vdest, const struct vector vsrc)
Definition: math.c:158
int nprows
Definition: structs.h:111
void get_filename(char *filename, const char *format,...)
Definition: utils.c:59
vector struct to hold triplets.
Definition: structs.h:29
#define CIMAG(x)
Definition: functions.h:50
COMPLEX * lambda
Definition: structs.h:623
int nchief
Definition: structs.h:301
COMPLEX * sol
Definition: structs.h:607
int mics_block_size
Definition: structs.h:124
void pzgemr2d_(int *m, int *n, COMPLEX *A, int *ia, int *ja, int *desca, COMPLEX *B, int *ib, int *jb, int *descb, int *ictxt)
Copies a (m x n) submatrix of A from element (ia,ja) on a submatrix of B from element (ib...
struct bc_struct bc
Definition: globals.h:54
int nelmb
Definition: structs.h:295
#define CEXP(x)
Definition: functions.h:48
DOUBLE * B
Definition: structs.h:370
Vec vecPhinc
Definition: structs.h:578
#define COMPLEX_ZERO
Definition: constants.h:44
int ctxt
Definition: structs.h:109
int knw
Definition: structs.h:446
Definition of a quadrilateral panel.
Definition: structs.h:44
struct vector n
Definition: structs.h:48
DOUBLE rho
Definition: structs.h:476
void descinit_(int *desc, int *m, int *n, int *mb, int *nb, int *ia, int *ja, int *ictxt, int *llda, int *info)
struct solution_struct * solution
Definition: globals.h:52
#define COMPLEX
Definition: types.h:48
Vec vecPhincm
Definition: structs.h:582
BOOL printout
Definition: structs.h:486
struct modsol_info * modsolinfo
Definition: globals.h:44
int nmics
Definition: structs.h:304
DOUBLE z
Definition: structs.h:35
void j12(int i12, int n1, int *i1, int *i2)
Definition: math.c:206
struct vector g
Definition: structs.h:626
DOUBLE vec_dot(struct vector v1, struct vector v2)
Definition: math.c:34
COMPLEX * gamma
Definition: structs.h:624
int j21(int i1, int i2, int n1)
Definition: math.c:202
Vec vecPhium
Definition: structs.h:586
int mycol
Definition: structs.h:117
int nsymm
Definition: structs.h:97
Vec vecPrescm
Definition: structs.h:588
double DOUBLE
Definition: types.h:44
int numroc_(int *m, int *mb, int *p, int *ia, int *npr)
int rank
Definition: globals.h:79
DOUBLE x
Definition: structs.h:31
#define CREATE_VEC(v, lsize)
Definition: allocation.h:90
int col_block_size
Definition: structs.h:121
COMPLEX * func
Definition: structs.h:625
int krow
Definition: structs.h:105
Geometry info structure.
Definition: structs.h:161
struct micscoefs_struct * micscoefs
Definition: globals.h:50
void print_premic_on_master(COMPLEX cfreq)
Definition: pre_mic.c:604
Vec vecPretm
Definition: structs.h:590
#define MAX_PATH
Definition: constants.h:29
int row_block_size
Definition: structs.h:119
#define calloc(n, size)
Definition: allocation.h:37
struct modgeom_info * modgeominfo
Definition: globals.h:38
void sc_l2g(int il, int p, int n, int np, int nb, int *i)
Definition: matutils.c:116
#define VecZeroEntries(V, n)
Definition: allocation.h:99
DOUBLE y
Definition: structs.h:33
int dirneu
Definition: structs.h:444