101 void calc_diffusion_curve_layer(
int nt,
int nz,
int nr,
int iprobe,
int jprobe,
int iz1,
int iz2,
int nolayer,
double dt,
double dr,
double sdelay,
double sduration,
double alpha_so,
double theta_so,
double kappa_so,
double alpha_sp,
double theta_sp,
double kappa_sp,
double alpha_sr,
double theta_sr,
double kappa_sr,
double dfree,
double *t,
double *s,
double *invr,
char *imagebasename,
double image_spacing,
double *p)
104 double dstar_so = theta_so * dfree;
105 double dstar_sp = theta_sp * dfree;
106 double dstar_sr = theta_sr * dfree;
107 double const_so1 = dstar_so * dt /
SQR(dr);
108 double const_so2 = dstar_so * dt / (2.0 * dr);
109 double const_sp1 = dstar_sp * dt /
SQR(dr);
110 double const_sp2 = dstar_sp * dt / (2.0 * dr);
111 double const_sr1 = dstar_sr * dt /
SQR(dr);
112 double const_sr2 = dstar_sr * dt / (2.0 * dr);
132 char imagefilename[FILENAME_MAX];
133 memset(imagefilename,
'\0', FILENAME_MAX);
134 FILE *image_file_ptr = NULL;
136 memset(timestring,
'\0', 20);
137 char infofilename[FILENAME_MAX];
138 memset(infofilename,
'\0', FILENAME_MAX);
139 FILE *info_file_ptr = NULL;
140 double *conc_out = NULL;
164 for (i=0; i<nz*(nr+1); i++)
168 int nds = lround(sdelay/dt);
170 error(
"nds=%d, nt=%d. Delay start should be < total expt time",
172 for (k=0; k<nds; k++)
177 if (image_spacing > 0.) {
178 conc_out =
create_array(nz*(2*nr-1),
"output concentration");
179 for (i=0; i<nz*(2*nr-1); i++)
183 snprintf(infofilename,
sizeof(infofilename),
184 "%s.info.txt", imagebasename);
187 if ((info_file_ptr = fopen(infofilename,
"w")) == NULL)
188 error(
"Error opening image info output file %s\n",
191 fprintf(info_file_ptr,
"Information about the images:\n" 192 "\tImage dimensions: %d x %d\n" 193 "\tPixels are 64-bit floating point (doubles)\n",
196 fclose(info_file_ptr);
200 for (k=nds; k<nt; k++) {
201 if (image_spacing > 0.) {
202 time = (k - nds) * dt;
204 if (time >= image_counter * image_spacing) {
206 snprintf(timestring,
sizeof(timestring),
"%ld",
207 (lround) (time * 1000.));
209 snprintf(imagefilename,
sizeof(imagefilename),
210 "%s.%sms.raw", imagebasename, timestring);
213 if ((image_file_ptr = fopen(imagefilename,
"w")) == NULL)
214 error(
"Error opening concentration image file %s\n",
225 for (j=0; j<nr+1; j++) {
226 for (i=0; i<nz; i++) {
227 conc = c[
INDEX(i,j)];
228 conc_min =
MIN(conc,conc_min);
229 conc_max =
MAX(conc,conc_max);
243 if (fwrite(conc_out,
sizeof(
double), nz*(2*nr-1),
244 image_file_ptr) == 0) {
245 printf(
"3layer: WARNING: Output image file %s " 246 "not written\n", imagefilename);
249 fclose(image_file_ptr);
252 snprintf(infofilename,
sizeof(infofilename),
253 "%s.info.txt", imagebasename);
256 if ((info_file_ptr = fopen(infofilename,
"a")) == NULL)
257 error(
"Error opening image info output file %s\n",
260 fprintf(info_file_ptr,
261 "Image file #%d: %s: max = %lf, min = %lf\n",
262 image_counter, imagefilename, conc_max, conc_min);
264 fclose(info_file_ptr);
270 p[k] = c[
INDEX(iprobe,jprobe)];
273 if (nolayer ==
FALSE) {
279 for (j=0; j<nr+1; j++) {
280 cb_sr[j] = ( dstar_sr * alpha_sr * c[
INDEX(iz1,j)]
281 + dstar_sp * alpha_sp * c[
INDEX(iz1+1,j)] )
282 / ( dstar_sr * alpha_sr + dstar_sp * alpha_sp );
284 cb_so[j] = ( dstar_sp * alpha_sp * c[
INDEX(iz2,j)]
285 + dstar_so * alpha_so * c[
INDEX(iz2+1,j)] )
286 / ( dstar_sp * alpha_sp + dstar_so * alpha_so );
289 for (j=0; j<nr+1; j++) {
290 for (i=0; i<iz1+1; i++)
292 c_sr[
INDEX(iz1+1,j)] = 2.0 * cb_sr[j] - c[
INDEX(iz1,j)];
294 c_sp[
INDEX(0,j)] = 2.0 * cb_sr[j] - c[
INDEX(iz1+1,j)];
295 for (i=iz1+1; i<iz2+1; i++)
297 c_sp[
INDEX(iz2-iz1+1,j)] = 2.0 * cb_so[j] - c[
INDEX(iz2,j)];
299 c_so[
INDEX(0,j)] = 2.0 * cb_so[j] - c[
INDEX(iz2+1,j)];
300 for (i=iz2+1; i<nz; i++)
305 convolve3(iz1+2, nr+1, c_sr, const_sr1, const_sr2, invr, dc_sr);
307 convolve3(iz2-iz1+2, nr+1, c_sp, const_sp1, const_sp2, invr,
309 convolve3(nz-iz2, nr+1, c_so, const_so1, const_so2, invr, dc_so);
312 for (j=0; j<nr+1; j++) {
313 for (i=0; i<iz1+1; i++)
317 for (i=iz1+1; i<iz2+1; i++)
319 + dc_sp[
INDEX(i-iz1,j)];
321 for (i=iz2+1; i<nz; i++)
323 + dc_so[
INDEX(i-iz2,j)];
328 if (k==0) printf(
"\nNOTE: nolayer = %d, " 329 "so using the 1 layer model\n\n", nolayer);
332 convolve3(nz, nr+1, c, const_sr1, const_sr2, invr, dc);
335 for (i=0; i<nz*(nr+1); i++)
343 if (t[k] + dt/2.0 < sdelay + sduration) {
344 for (i=0; i<nz*(nr+1); i++)
349 for (j=0; j<nr+1; j++) {
350 for (i=0; i<iz1+1; i++)
351 c[
INDEX(i,j)] *= (1. - kappa_sr * dt);
352 for (i=iz1+1; i<iz2+1; i++)
353 c[
INDEX(i,j)] *= (1. - kappa_sp * dt);
354 for (i=iz2+1; i<nz; i++)
355 c[
INDEX(i,j)] *= (1. - kappa_so * dt);
377 if (image_spacing > 0.)
void convolve3(int M, int N, double *a, double scale1, double scale2, double *invr, double *out)
Calculates updates to the concentration in a layer by applying the Laplacian in cylindrical coordinat...
void calc_diffusion_curve_layer(int nt, int nz, int nr, int iprobe, int jprobe, int iz1, int iz2, int nolayer, double dt, double dr, double sdelay, double sduration, double alpha_so, double theta_so, double kappa_so, double alpha_sp, double theta_sp, double kappa_sp, double alpha_sr, double theta_sr, double kappa_sr, double dfree, double *t, double *s, double *invr, char *imagebasename, double image_spacing, double *p)
Calculates the concentration as a function of space and time and returns the probe concentration as a...