24 int i, k_current, k_new = 0, numbf = 1, frc, firstn, lastn, flag_in = 0, parts_fracture;
26 double parts_dist = 0;
27 int zonenumb_in = 0, first_ind = 0, last_ind = 0;
28 double ixmin = 0, ixmax = 0, iymin = 0, iymax = 0, izmin = 0, izmax = 0;
29 double px[4] = {0.0, 0.0, 0.0, 0.0}, py[4] = {0.0, 0.0, 0.0, 0.0};
30 double weight_p = 0.0;
44 if ((numbf == 0) && (
nzone_in != 0)) {
48 printf(
" %d fracture(s) in in-flow boundary zone \n", numbf);
50 unsigned int firstind[numbf], lastind[numbf], firstnode[numbf], lastnode[numbf], numberf = 1, curfr = 0;
60 lastind[numberf - 1] = i - 1;
65 firstind[numberf - 1] = i;
74 if (numberf > numbf) {
75 printf(
"check the boundary zone file\n");
79 double inter_p[numbf][4];
83 res = strncmp(initfile.
filename,
"yes", 3);
90 parts_fracture = initfile.
flag;
91 printf(
"\n %d particles per boundary fracture edge \n", parts_fracture);
92 npart = (numbf + 1) * parts_fracture;
97 res = strncmp(initfile.
filename,
"yes", 3);
106 parts_fracture = initfile.
flag;
107 npart = (numbf) * parts_fracture * 2;
111 double length2 = 0.0, t_length = 0.0;
113 for (i = 0; i < numbf; i++) {
114 length2 = pow((
node[firstnode[i] - 1].coord[0] -
node[lastnode[i] - 1].coord[0]), 2) + pow((
node[firstnode[i] - 1].coord[1] -
node[lastnode[i] - 1].coord[1]), 2) + pow((
node[firstnode[i] - 1].coord[2] -
node[lastnode[i] - 1].coord[2]), 2);
115 t_length = t_length + sqrt(length2);
118 parts_dist = t_length / (parts_fracture * numbf);
119 printf(
"\n Particles placed on %f [m] from each other. Total length %lf \n", parts_dist, t_length);
122 res = strncmp(initfile.
filename,
"yes", 3);
133 printf(
"\n Initially particles have the same starting region \n");
135 ixmin = initfile.
param;
137 ixmax = initfile.
param;
139 iymin = initfile.
param;
141 iymax = initfile.
param;
143 izmin = initfile.
param;
145 izmax = initfile.
param;
147 zonenumb_in = initfile.
flag;
150 if ((zonenumb_in == 1) || (zonenumb_in == 2)) {
161 if ((zonenumb_in == 3) || (zonenumb_in == 5)) {
172 if ((zonenumb_in == 4) || (zonenumb_in == 6)) {
185 res = strncmp(initfile.
filename,
"yes", 3);
193 printf(
"\n Initially particles will be distributed randomly over all fracture surfaces \n");
194 double random_number = 0, sum_aperture = 0.0;
195 unsigned int currentcell, k_curr = 0;
198 random_number = drand48();
199 currentcell = random_number *
ncells;
201 if ((currentcell != 0) && (((
node[
cell[currentcell - 1].node_ind[0] - 1].typeN < 200) || (
node[
cell[currentcell - 1].node_ind[0] - 1].typeN > 250)) && ((
node[
cell[currentcell - 1].node_ind[1] - 1].typeN < 200) || (
node[
cell[currentcell - 1].node_ind[1] - 1].typeN > 250)) && ((
node[
cell[currentcell - 1].node_ind[2] - 1].typeN < 200) || (
node[
cell[currentcell - 1].node_ind[2] - 1].typeN > 250)))) {
214 }
while(k_curr !=
npart);
218 for (i = 0; i <
npart; i++) {
226 if (initfile.
flag > 0) {
227 res = strncmp(initfile.
filename,
"yes", 3);
230 printf(
" Initially particles are placed in rock matrix randomly. ");
231 printf(
" The closest cells to initial particles positions ");
232 printf(
" will be set as starting point in DFN. ");
239 res = strncmp(initfile.
filename,
"yes", 3);
249 printf(
"\n The requested number of particles (%d) is less than number of nodes in in-flow boundary (\%d). The initial number of particles is changed to number of nodes in in-flow boundary. \n",
npart,
nzone_in);
254 printf(
"\n Requested number of particles %d with flux weight %5.12e (Total Flux %5.12e) \n",
npart, weight_p,
totalFluxIn);
256 npart_alloc =
npart * 3;
262 res = strncmp(initfile.
filename,
"yes", 3);
268 int nodepart = 0, npartalloc = 0;
270 nodepart = initfile.
flag;
271 npartalloc = (
nzone_in + 1 ) * nodepart;
287 if ((flag_in <= 2) || (flag_in == 6)) {
288 for (i = 0; i < numberf; i++) {
289 if (lastnode[i] != firstnode[i]) {
297 k_new =
InitParticles_eq (k_current, firstnode[i], lastnode[i], parts_dist, firstind[i], lastind[i]);
302 k_new =
InitParticles_np (k_current, firstnode[i], lastnode[i], parts_fracture, firstind[i], lastind[i]);
313 double thirdcoor = 0.0;
314 int firstcoor = 0, secondcoor = 0, frc_count = 0;
335 for (i = 0; i <
nzone_in - 1; i++) {
373 if (firstn == lastn) {
377 if (firstn != lastn) {
379 double cx1 = 0, cx2 = 0, cy1 = 0, cy2 = 0;
381 inter_p[frc_count][0] = 1e-10;
382 inter_p[frc_count][1] = 1e-10;
383 inter_p[frc_count][2] = 1e-10;
384 inter_p[frc_count][3] = 1e-10;
386 if ((zonenumb_in == 1) || (zonenumb_in == 2)) {
390 if ((cx1 > ixmin) && (cx1 < ixmax) && (cy1 > iymin) && (cy1 < iymax)) {
391 inter_p[frc_count][0] = cx1;
392 inter_p[frc_count][1] = cy1;
398 if ((cx2 > ixmin) && (cx2 < ixmax) && (cy2 > iymin) && (cy2 < iymax)) {
399 inter_p[frc_count][0] = cx2;
400 inter_p[frc_count][1] = cy2;
406 if ((zonenumb_in == 3) || (zonenumb_in == 5)) {
410 if ((cx1 > izmin) && (cx1 < izmax) && (cy1 > iymin) && (cy1 < iymax)) {
411 inter_p[frc_count][0] = cx1;
412 inter_p[frc_count][1] = cy1;
418 if ((cx2 > izmin) && (cx2 < izmax) && (cy2 > iymin) && (cy2 < iymax)) {
419 inter_p[frc_count][0] = cx2;
420 inter_p[frc_count][1] = cy2;
426 if ((zonenumb_in == 4) || (zonenumb_in == 6)) {
430 if ((cx1 > ixmin) && (cx1 < ixmax) && (cy1 > izmin) && (cy1 < izmax)) {
431 inter_p[frc_count][0] = cx1;
432 inter_p[frc_count][1] = cy1;
438 if ((cx2 > ixmin) && (cx2 < ixmax) && (cy2 > izmin) && (cy2 < izmax)) {
439 inter_p[frc_count][0] = cx2;
440 inter_p[frc_count][1] = cy2;
446 double pr1, pr2, pr3, pr4, p_x, p_y;
450 for (ii = 0; ii < 4; ii++) {
458 pr1 = (px[ii] - cx1) * (py[kk] - cy1) - (py[ii] - cy1) * (px[kk] - cx1);
459 pr2 = (cx1 - px[ii]) * (cy2 - py[ii]) - (cy1 - py[ii]) * (cx2 - px[ii]);
460 pr3 = (px[ii] - cx2) * (py[kk] - cy2) - (py[ii] - cy2) * (px[kk] - cx2);
461 pr4 = (cx1 - px[kk]) * (cy2 - py[kk]) - (cy1 - py[kk]) * (cx2 - px[kk]);
463 if ((pr1 * pr3 < 0) && (pr2 * pr4 < 0)) {
464 pr1 = cx1 * cy2 - cy1 * cx2;
465 pr2 = px[ii] * py[kk] - py[ii] * px[kk];
466 pr3 = (cx1 - cx2) * (py[ii] - py[kk]) - (cy1 - cy2) * (px[ii] - px[kk]);
467 p_x = ((px[ii] - px[kk]) * pr1 - (cx1 - cx2) * pr2) / pr3;
468 p_y = ((py[ii] - py[kk]) * pr1 - (cy1 - cy2) * pr2) / pr3;
470 if (inter_p[frc_count][0] == 1e-10) {
471 inter_p[frc_count][0] = p_x;
472 inter_p[frc_count][1] = p_y;
474 inter_fr[frc_count] = frc;
475 inter_p[frc_count][2] = p_x;
476 inter_p[frc_count][3] = p_y;
512 if ((flag_in == 3) && (frc_count == 0)) {
513 printf(
"\n There is no fracture crosses the given range. Try to increase the range. \n");
514 printf(
"\n Program is terminated. \n");
521 for (i = 0; i < frc_count; i++) {
522 parts_fracture = (int)
npart / frc_count;
523 k_new =
InitParticles_ones (k_current, inter_p, inter_fr[i], parts_fracture, i, thirdcoor, zonenumb_in, first_ind, last_ind);
531 printf(
"\n There is no option specified for particles initial positions! \n");
532 printf(
"\n Program is terminated. \n");
545 int i, j, k, curcel, insc = 0;
549 for (k = 0; k < 4; k++)
578 int InitParticles_np (
int k_current,
int firstnd,
int lastnd,
int parts_fracture,
int first_ind,
int last_ind)
581 double deltax, deltay;
584 int ii, jj, k, curcel, insc = 0;
590 for (j = 0; j < pf; j++) {
591 if (
node[firstnd - 1].coord_xy[0] <
node[lastnd - 1].coord_xy[0]) {
597 if (
node[firstnd - 1].coord_xy[1] <
node[lastnd - 1].coord_xy[1]) {
612 if (k_current >
npart) {
613 printf(
" \n Number of particles with allocated memory is less than number of particles set up initially. \n");
614 printf(
" Increase the number of particles. Program is terminated. \n");
623 int InitParticles_eq (
int k_current,
int firstn,
int lastn,
double parts_dist,
int first_ind,
int last_ind)
626 double deltax, deltay, edgelength, eqdist_x, eqdist_y;
630 edgelength = sqrt(deltax * deltax + deltay * deltay);
631 pf = (int)(edgelength / parts_dist);
635 eqdist_x = deltax / 2.0;
636 eqdist_y = deltay / 2.0;
638 eqdist_x = deltax / pf;
639 eqdist_y = deltay / pf;
642 for (j = 0; j < pf; j++) {
658 if (k_current >
npart) {
659 printf(
"\n Number of particles with allocated memory is less than number of particles set up initially. \n");
660 printf(
" Increase the number of particles. Program is terminated. \n");
668 int InitParticles_ones (
int k_current,
double inter_p[][4],
int fracture_n,
int parts_fracture,
int ii,
double thirdcoor,
int zonenumb_in,
int first_ind,
int last_ind)
671 int j = fracture_n - 1;
672 double x_1 = 0, y_1 = 0, z_1 = 0, x_2 = 0, z_2 = 0, y_2 = 0;
673 double x1cor = 0.0, y1cor = 0.0, z1cor = 0, x2cor = 0.0, y2cor = 0.0, z2cor = 0;
675 if ((zonenumb_in == 1) || (zonenumb_in == 2)) {
676 x1cor = inter_p[ii][0];
677 y1cor = inter_p[ii][1];
679 x2cor = inter_p[ii][2];
680 y2cor = inter_p[ii][3];
684 if ((zonenumb_in == 3) || (zonenumb_in == 5)) {
687 z1cor = inter_p[ii][0];
688 z2cor = inter_p[ii][2];
689 y1cor = inter_p[ii][1];
690 y2cor = inter_p[ii][3];
693 if ((zonenumb_in == 4) || (zonenumb_in == 6)) {
696 x1cor = inter_p[ii][0];
697 x2cor = inter_p[ii][2];
698 z1cor = inter_p[ii][1];
699 z2cor = inter_p[ii][3];
719 double deltax, deltay;
722 deltax = (x_2 - x_1);
723 deltay = (y_2 - y_1);
725 for (j = 0; j < pf; j++) {
726 particle[k_current].
position[0] = x_1 + (deltax / pf) * (j) + deltax / (2.0 * pf);
727 particle[k_current].
position[1] = y_1 + (deltay / pf) * (j) + deltay / (2.0 * pf);
737 if (k_current >
npart) {
738 printf(
" \n Number of particles with allocated memory is less than number of particles set up initially. \n");
739 printf(
" Increase the number of particles. Program is terminated. \n");
750 int ind1 = 0, ind2 = 0, ver1 = 0, ver2 = 0, ver3 = 0, incell = 0, n1in = 0, n2in = 0, jj;
752 double sumflux1 = 0, sumflux2 = 0, particleflux[numberpart], totalflux = 0;
754 for (
np = 0;
np < numberpart;
np++) {
767 if (
node[ver1 - 1].typeN >= 300) {
772 if (
node[ver2 - 1].typeN >= 300) {
782 if (
node[ver3 - 1].typeN >= 300) {
792 if ((n1in != 0) && (n2in != 0)) {
797 sumflux1 = sumflux1 + fabs(
node[n1in - 1].flux[jj]);
801 sumflux2 = sumflux2 + fabs(
node[n2in - 1].flux[jj]);
805 totalflux = totalflux + particleflux[
np];
814 sumflux1 = sumflux1 + fabs(
node[ncent - 1].flux[jj]);
817 particleflux[
np] = sumflux1;
818 totalflux = totalflux + particleflux[
np];
824 for (
np = 0;
np < numberpart;
np++) {
840 printf(
"\n OPEN AND READ FILE: %s \n \n", inputfile.
filename);
843 printf(
"\n OPEN AND READ FILE: %s \n \n", inputfile.
filename);
846 unsigned int number, no;
849 if (fscanf(mn,
"%d %d %d %d %d \n", &no, &no, &number, &no, &no) != 5) {
853 for (i = 0; i < (number + 1); i++) {
856 }
while (cs !=
'\n');
859 if (fscanf(mc,
" %d \n", &
npart) != 1) {
865 double* distance = malloc ((
npart + 1) *
sizeof(
double));
866 double xp, yp, zp, sum_distance = 0.0, xp2, yp2, zp2;
868 for (ii = 0; ii <
npart; ii++) {
869 if (fscanf(mn,
" %d %d %d %d %d %d \n", &no, &no, &no, &no, &no, &number) != 6) {
873 if (fscanf(mc,
" %lf %lf %lf \n ", &xp, &yp, &zp) != 1) {
877 xp2 = (
node[number - 1].
coord[0] - xp) * (
node[number - 1].coord[0] - xp);
878 yp2 = (
node[number - 1].
coord[1] - yp) * (
node[number - 1].coord[1] - yp);
879 zp2 = (
node[number - 1].
coord[2] - zp) * (
node[number - 1].coord[2] - zp);
880 distance[ii] = sqrt(xp2 + yp2 + zp2);
898 sum_distance = sum_distance + distance[ii];
905 for (i = 0; i <
npart; i++) {
917 double ptime = 0.0, ptime1 = 0.0, ptime2 = 0.0;
918 double randomnumber = 0.0;
919 randomnumber = drand48();
920 double mporosity = 0.0;
921 double mdiffcoeff = 0.0;
923 mporosity = inputfile.
param;
925 mdiffcoeff = inputfile.
param;
927 double retardation_factor = 1.0;
928 double inverse_erfc = 0.0;
930 z = 1 - randomnumber;
931 inverse_erfc = 0.5 * sqrt(
pi) * (z + (
pi / 12) * pow(z, 3) + ((7 * pow(
pi, 2)) / 480) * pow(z, 5) + ((127 * pow(
pi, 3)) / 40320) * pow(z, 7) + ((4369 * pow(
pi, 4)) / 5806080) * pow(z, 9) + ((34807 * pow(
pi, 5)) / 182476800) * pow(z, 11));
932 ptime2 = (1.0 / inverse_erfc) * (1.0 / inverse_erfc);
933 ptime1 = (pdist * pdist) / (4.0 * (mporosity * mdiffcoeff / retardation_factor));
934 ptime = (ptime1 * ptime2) /
timeunit;
943 double deltax, deltay, edgelength, eqdist_x, eqdist_y, sumflux = 0, startpos_x, startpos_y, sumdelta = 0.0;
944 double sumfluxfract = 0.0;
945 unsigned int i, k, j, jj, pf, curcel = 0, insc = 0,
np, np_init;
946 struct posit3d particle3dposition;
952 for (j = first_ind; j <= last_ind; j++) {
961 sumfluxfract = sumfluxfract + sumflux;
963 pf = ceilf(fabs(sumflux) / weight_p);
967 if ((j > first_ind) && (j < last_ind)) {
976 if (j == first_ind) {
996 eqdist_x = deltax / 2.0;
997 eqdist_y = deltay / 2.0;
999 eqdist_x = deltax / pf;
1000 eqdist_y = deltay / pf;
1003 for (jj = 0; jj < pf; jj++) {
1017 if (k_current >
npart * 3) {
1019 printf(
" Increase the number of particles. Program is terminated. \n");
1030 int i = 0, j = 0, k_current = 0;
1031 float sum_aperture = 0.0;
1034 for (j = 0; j < node_part; j++) {
1049 for (i = 0; i < k_current; i++) {
FILE * OpenFile(char filen[120], char fileopt[2])
struct inpfile Control_File(char fileobject[], int ctr)
struct inpfile Control_File_Optional(char fileobject[], int ctr)
int InsideCell(unsigned int numc)
void Moving2Center(int nnp, int cellnumber)
struct inpfile Control_Param(char fileobject[], int ctr)
struct inpfile Control_Data(char fileobject[], int ctr)
struct material * fracture
unsigned int * nodezonein
int InitParticles_eq(int k_current, int firstn, int lastn, double parts_dist, int first_ind, int last_ind)
double TimeFromMatrix(double pdist)
int InitParticles_ones(int k_current, double inter_p[][4], int fracture_n, int parts_fracture, int ii, double thirdcoor, int zonenumb_in, int first_ind, int last_ind)
int InitParticles_np(int k_current, int firstnd, int lastnd, int parts_fracture, int first_ind, int last_ind)
void FlowInWeight(int numberpart)
int InitParticles_flux(int k_current, int first_ind, int last_ind, double weight_p)
int InitInWell(int node_part)