| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include "rheoplast.h" |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | #undef __FUNCT__ |
|---|
| 27 | #define __FUNCT__ "pseudolog" |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | static inline PetscScalar pseudolog (PetscScalar arg) |
|---|
| 38 | { return (arg>1e-10) ? log(arg) : log(1e-10) + 1e10*(arg - 1e-10); } |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | #undef __FUNCT__ |
|---|
| 42 | #define __FUNCT__ "psiprime2" |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | static inline PetscScalar psiprime2 (PetscScalar C2, PetscScalar C3, |
|---|
| 64 | chtparm *thechternary) |
|---|
| 65 | { |
|---|
| 66 | int ierr; |
|---|
| 67 | |
|---|
| 68 | if (thechternary->polymer) |
|---|
| 69 | { |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | PetscScalar chi_ns = 0.218 + 0.276/(1-0.622*C2/(1-C3)); |
|---|
| 98 | PetscScalar chi_sp = -1+0.5*C3; |
|---|
| 99 | PetscScalar chi_np = 3.5; |
|---|
| 100 | |
|---|
| 101 | PetscScalar dchins_dC2 = 0.276/(1-0.622*C2/(1-C3))/(1-0.622*C2/(1-C3)) * |
|---|
| 102 | 0.622*C2/(1-C3); |
|---|
| 103 | PetscScalar dchisp_dC2 = 0.0; |
|---|
| 104 | PetscScalar dchinp_dC2 = 0.0; |
|---|
| 105 | |
|---|
| 106 | return ((-1.0-pseudolog(1.-C2-C3))/thechternary->V_n + |
|---|
| 107 | (1.+pseudolog(C2))/thechternary->V_s + |
|---|
| 108 | (chi_ns*(1.-2.*C2-C3) + |
|---|
| 109 | dchins_dC2*(1.-C2-C3)*C2)/thechternary->V_n + |
|---|
| 110 | (chi_sp*C3 + dchisp_dC2*C2*C3)/thechternary->V_s + |
|---|
| 111 | (-chi_np*C3 + dchinp_dC2*(1.-C2-C3)*C3)/thechternary->V_n) * |
|---|
| 112 | thechternary->RT; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | PetscScalar chiMM =3.3; |
|---|
| 117 | PetscScalar chiMC =2.5; |
|---|
| 118 | PetscScalar chipMM =0.0; |
|---|
| 119 | PetscScalar chipMC =0.0; |
|---|
| 120 | |
|---|
| 121 | return log(C2) - log(1.0-C2) + chiMM*C3*(1.0-2.*C2)-(C3-0.5) + chipMM*C3*(2.*C2-6.*C2*C2 +4.*C2*C2*C2); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | #undef __FUNCT__ |
|---|
| 126 | #define __FUNCT__ "psiprime3" |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | static inline PetscScalar psiprime3 (PetscScalar C2, PetscScalar C3, |
|---|
| 148 | chtparm *thechternary) |
|---|
| 149 | { |
|---|
| 150 | int ierr; |
|---|
| 151 | |
|---|
| 152 | if (thechternary->polymer) |
|---|
| 153 | { |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | PetscScalar chi_ns = 0.218 + 0.276/(1-0.622*C2/(1-C3)); |
|---|
| 182 | PetscScalar chi_sp = -1+0.5*C3; |
|---|
| 183 | PetscScalar chi_np = 3.5; |
|---|
| 184 | |
|---|
| 185 | PetscScalar dchins_dC3 = 0.276/ (1-0.622*C2/(1-C3)) / (1-0.622*C2/(1-C3)) |
|---|
| 186 | * 0.622*C2/(1.-C3)/(1.-C3); |
|---|
| 187 | PetscScalar dchisp_dC3 = 0.5; |
|---|
| 188 | PetscScalar dchinp_dC3 = 0.0; |
|---|
| 189 | |
|---|
| 190 | return ((-1.0-pseudolog(1.-C2-C3))/thechternary->V_n + |
|---|
| 191 | (1.+pseudolog(C3))/thechternary->V_p + |
|---|
| 192 | (-chi_ns*C2 + dchins_dC3*(1.-C2-C3)*C2)/thechternary->V_n + |
|---|
| 193 | ( chi_sp*C2 + dchisp_dC3*C2*C3)/thechternary->V_s + |
|---|
| 194 | ( chi_np*(1.-C2-2.*C3) + dchinp_dC3*(1.-C2-C3)*C3) |
|---|
| 195 | /thechternary->V_n) * |
|---|
| 196 | thechternary->RT; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | PetscScalar chiMM =3.3; |
|---|
| 200 | PetscScalar chiMC =2.5; |
|---|
| 201 | PetscScalar chipMM =0.0; |
|---|
| 202 | PetscScalar chipMC =0.0; |
|---|
| 203 | |
|---|
| 204 | return chiMM*C2*(1.0-C2) - (C2-0.5) +log(C3)-log(1.0-C3) + chiMC*(1.0-2.*C3)+ |
|---|
| 205 | chipMC*(2.*C3-6.*C3*C3 +4.*C3*C3*C3) + chipMM*(C2*C2)*(1-C2)*(1-C2); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | #undef __FUNCT__ |
|---|
| 210 | #define __FUNCT__ "psi" |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | static inline PetscScalar psi (PetscScalar C2,PetscScalar C3,chtparm *thechternary) |
|---|
| 230 | { |
|---|
| 231 | int ierr; |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | if (thechternary->metal) |
|---|
| 249 | { |
|---|
| 250 | PetscScalar chiMM =3.3; |
|---|
| 251 | PetscScalar chiMC =2.5; |
|---|
| 252 | PetscScalar chipMM =0.0; |
|---|
| 253 | PetscScalar chipMC =0.0; |
|---|
| 254 | |
|---|
| 255 | return C2*log(C2)+(1-C2)*log(1.0-C2)+C3*log(C3)+(1-C3)*log(1.0-C3) + |
|---|
| 256 | chiMC*C3*(1.0-C3)+ chiMM*C2*C3*(1.0-C2) - (C2-0.5)*(C3-0.5) + |
|---|
| 257 | chipMC*C3*C3*(1-C3)*(1-C3) + chipMM*C3*(C2*C2)*(1-C2)*(1-C2); |
|---|
| 258 | } |
|---|
| 259 | else |
|---|
| 260 | { |
|---|
| 261 | ierr=PetscPrintf(PETSC_COMM_WORLD,"Can't find the specified free energy formula!!!\n Please choose between 'polymer' and 'metal'\n");CHKERRQ (ierr); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | return 0; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | #undef __FUNCT__ |
|---|
| 269 | #define __FUNCT__ "psiprime22" |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | static inline PetscScalar psiprime22 (PetscScalar C2, PetscScalar C3, |
|---|
| 291 | chtparm *thechternary) |
|---|
| 292 | { |
|---|
| 293 | int ierr; |
|---|
| 294 | |
|---|
| 295 | if (thechternary->polymer) |
|---|
| 296 | { |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | PetscScalar chi_ns = 0.218 + 0.276/(1-0.622*C2/(1-C3)); |
|---|
| 301 | PetscScalar chi_sp = 0.315; |
|---|
| 302 | PetscScalar chi_np = 3.53; |
|---|
| 303 | |
|---|
| 304 | PetscScalar dchins_dC2 = 0.276/(1-0.622*C2/(1-C3))/(1-0.622*C2/(1-C3)) * |
|---|
| 305 | 0.622*C2/(1-C3); |
|---|
| 306 | PetscScalar dchisp_dC2 = 0.0; |
|---|
| 307 | PetscScalar dchinp_dC2 = 0.0; |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | return ((-1.0-pseudolog(1.-C2-C3))/thechternary->V_n + |
|---|
| 313 | (1.+pseudolog(C2))/thechternary->V_s + |
|---|
| 314 | (chi_ns*(1.-2.*C2-C3) + |
|---|
| 315 | dchins_dC2*(1.-C2-C3)*C2)/thechternary->V_n + |
|---|
| 316 | (chi_sp*C3 + dchisp_dC2*C2*C3)/thechternary->V_s + |
|---|
| 317 | (-chi_np*C3 + dchinp_dC2*(1.-C2-C3)*C3)/thechternary->V_n) * |
|---|
| 318 | thechternary->RT; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | PetscScalar chiMM =3.3; |
|---|
| 323 | PetscScalar chiMC =2.5; |
|---|
| 324 | PetscScalar chipMM =0.0; |
|---|
| 325 | PetscScalar chipMC =0.0; |
|---|
| 326 | |
|---|
| 327 | return log(C2) - log(1.0-C2) + chiMM*C3*(1.0-2.*C2)-(C3-0.5) + chipMM*C3*(2.*C2-6.*C2*C2 +4.*C2*C2*C2); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | #undef __FUNCT__ |
|---|
| 332 | #define __FUNCT__ "chternary_first_setup" |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | int chternary_first_setup |
|---|
| 361 | (PetscTruth threedee, int *vars, int *tempvars, int *intvars, int *stencilwid, AppCtx *data) |
|---|
| 362 | { |
|---|
| 363 | chtparm *thechternary = &data->thechternary; |
|---|
| 364 | int ierr; |
|---|
| 365 | |
|---|
| 366 | data->jacobian = PETSC_FALSE; |
|---|
| 367 | |
|---|
| 368 | thechternary->C2var = (*vars)++; |
|---|
| 369 | thechternary->mu2var = (*tempvars)++; |
|---|
| 370 | thechternary->C3var = (*vars)++; |
|---|
| 371 | thechternary->mu3var = (*tempvars)++; |
|---|
| 372 | thechternary->psivar = (*intvars)++; |
|---|
| 373 | |
|---|
| 374 | ierr = PetscOptionsHasName(PETSC_NULL,"-cht_polymer",&thechternary->polymer); |
|---|
| 375 | CHKERRQ (ierr); |
|---|
| 376 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_metal", &thechternary->metal); |
|---|
| 377 | CHKERRQ (ierr); |
|---|
| 378 | if (!thechternary->polymer && !thechternary->metal) |
|---|
| 379 | { |
|---|
| 380 | ierr = PetscPrintf (PETSC_COMM_WORLD, "No chternary energy model selected, you need either -cht_polymer or -cht_metal\n"); |
|---|
| 381 | return data->chternary = PETSC_FALSE; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | thechternary->V_n = 18e-6; |
|---|
| 386 | thechternary->V_s = 77.44e-6; |
|---|
| 387 | thechternary->V_p = 180e-6; |
|---|
| 388 | thechternary->RT = 8.314*290.; |
|---|
| 389 | thechternary->ForceTerm=1.; |
|---|
| 390 | thechternary->uconst=0.; |
|---|
| 391 | thechternary->vconst=0.; |
|---|
| 392 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_Vn", |
|---|
| 393 | &thechternary->V_n, PETSC_NULL); CHKERRQ (ierr); |
|---|
| 394 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_Vs", |
|---|
| 395 | &thechternary->V_s, PETSC_NULL); CHKERRQ (ierr); |
|---|
| 396 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_Vp", |
|---|
| 397 | &thechternary->V_p, PETSC_NULL); CHKERRQ (ierr); |
|---|
| 398 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_ForceTerm", |
|---|
| 399 | &thechternary->ForceTerm, PETSC_NULL); |
|---|
| 400 | CHKERRQ (ierr); |
|---|
| 401 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_uUniform", |
|---|
| 402 | &thechternary->uconst, PETSC_NULL); |
|---|
| 403 | CHKERRQ (ierr); |
|---|
| 404 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_vUniform", |
|---|
| 405 | &thechternary->vconst, PETSC_NULL); |
|---|
| 406 | CHKERRQ (ierr); |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | if (thechternary->polymer) |
|---|
| 414 | { |
|---|
| 415 | thechternary->mobility22 = 1e-8; |
|---|
| 416 | thechternary->mobility23 = 0; |
|---|
| 417 | thechternary->mobility32 = 0; |
|---|
| 418 | thechternary->mobility33 = 1e-9; |
|---|
| 419 | thechternary->K22= 1e-2; |
|---|
| 420 | thechternary->K23= 0; |
|---|
| 421 | thechternary->K32= 0; |
|---|
| 422 | thechternary->K33= 1e-2; |
|---|
| 423 | } |
|---|
| 424 | else |
|---|
| 425 | { |
|---|
| 426 | thechternary->mobility22 = 20; |
|---|
| 427 | thechternary->mobility23 = 0; |
|---|
| 428 | thechternary->mobility32 = 0; |
|---|
| 429 | thechternary->mobility33 = 200; |
|---|
| 430 | thechternary->K22= 1e-2; |
|---|
| 431 | thechternary->K23= 1e-2; |
|---|
| 432 | thechternary->K32= 1e-2; |
|---|
| 433 | thechternary->K33= 1e-2; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-mobility_22",&thechternary->mobility22,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 437 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-mobility_23",&thechternary->mobility23,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 438 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-mobility_32",&thechternary->mobility32,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 439 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-mobility_33",&thechternary->mobility33,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 440 | |
|---|
| 441 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-K_22", &thechternary->K22,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 442 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-K_23", &thechternary->K23,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 443 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-K_32", &thechternary->K32,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 444 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-K_33", &thechternary->K33,PETSC_NULL); CHKERRQ (ierr); |
|---|
| 445 | *stencilwid = PetscMax (*stencilwid, 2); |
|---|
| 446 | |
|---|
| 447 | DPRINTF ("Vn=%g, Vs=%g, Vp=%g,\n", thechternary->V_n, thechternary->V_s, |
|---|
| 448 | thechternary->V_p); |
|---|
| 449 | DPRINTF ("mobility_22=%g, mobility_23=%g, mobility_32=%g, mobility_33=%g,\n", |
|---|
| 450 | thechternary->mobility22, thechternary->mobility23, |
|---|
| 451 | thechternary->mobility32, thechternary->mobility33); |
|---|
| 452 | DPRINTF ("K_22=%g, K_23=%g, K_32=%g, K_33=%g\n", thechternary->K22, |
|---|
| 453 | thechternary->K23, thechternary->K32, thechternary->K33); |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | thechternary->hd_22=-1.; |
|---|
| 457 | thechternary->hd_33=-1.; |
|---|
| 458 | thechternary->c2ref=0.; |
|---|
| 459 | thechternary->c3ref=0.; |
|---|
| 460 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-hd_22", &thechternary->hd_22, |
|---|
| 461 | PETSC_NULL); CHKERRQ (ierr); |
|---|
| 462 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-hd_33", &thechternary->hd_33, |
|---|
| 463 | PETSC_NULL); CHKERRQ (ierr); |
|---|
| 464 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-C2_ref", &thechternary->c2ref, |
|---|
| 465 | PETSC_NULL); CHKERRQ (ierr); |
|---|
| 466 | ierr = PetscOptionsGetScalar (PETSC_NULL,"-C3_ref", &thechternary->c3ref, |
|---|
| 467 | PETSC_NULL); CHKERRQ (ierr); |
|---|
| 468 | |
|---|
| 469 | if (thechternary->hd_22 >= 0. || thechternary->hd_33 >= 0.) |
|---|
| 470 | DPRINTF ("BC parameters: hd_22=%g, hd_33=%g, C2_ref=%g, C3_ref=%g\n", |
|---|
| 471 | thechternary->hd_22, thechternary->hd_33, thechternary->c2ref, |
|---|
| 472 | thechternary->c3ref); |
|---|
| 473 | |
|---|
| 474 | return 0; |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | #undef __FUNCT__ |
|---|
| 479 | #define __FUNCT__ "chternary_labels_initcond" |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | int chternary_labels_initcond |
|---|
| 549 | (PetscScalar *globalarray, int nx,int ny,int nz, int xm,int ym,int zm, int xs, |
|---|
| 550 | int ys,int zs, int vars, AppCtx *data, PetscScalar *max_explicit_deltat) |
|---|
| 551 | { |
|---|
| 552 | chtparm *thechternary = &data->thechternary; |
|---|
| 553 | PetscScalar temp; |
|---|
| 554 | int ix,iy,iz, ierr; |
|---|
| 555 | |
|---|
| 556 | PetscScalar delta = PetscMin (data->xwid/nx, data->ywid/ny); |
|---|
| 557 | |
|---|
| 558 | data->label[thechternary->C2var] = "C2"; |
|---|
| 559 | data->label[thechternary->C3var] = "C3"; |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | data->timestyle[thechternary->C2var]=TIME_CONST_BLEND_VAR+thechternary->C2var; |
|---|
| 564 | data->timestyle[thechternary->C3var] =TIME_CONST_BLEND_VAR+thechternary->C3var; |
|---|
| 565 | |
|---|
| 566 | data->plot_types[thechternary->C2var] = FIELD_TERNARY; |
|---|
| 567 | data->plot_types[thechternary->C3var] = FIELD_TERNARY; |
|---|
| 568 | data->symmtypes[thechternary->C2var] = |
|---|
| 569 | SYMMETRY_MIRROR_PLANE * SYMMETRY_XMIN_START | |
|---|
| 570 | SYMMETRY_MIRROR_PLANE * SYMMETRY_YMIN_START | |
|---|
| 571 | SYMMETRY_MIRROR_PLANE * SYMMETRY_ZMIN_START | |
|---|
| 572 | SYMMETRY_MIRROR_PLANE * SYMMETRY_XMAX_START | |
|---|
| 573 | SYMMETRY_MIRROR_PLANE * SYMMETRY_YMAX_START | |
|---|
| 574 | SYMMETRY_MIRROR_PLANE * SYMMETRY_ZMAX_START; |
|---|
| 575 | data->symmtypes[thechternary->C3var] = |
|---|
| 576 | SYMMETRY_MIRROR_PLANE * SYMMETRY_XMIN_START | |
|---|
| 577 | SYMMETRY_MIRROR_PLANE * SYMMETRY_YMIN_START | |
|---|
| 578 | SYMMETRY_MIRROR_PLANE * SYMMETRY_ZMIN_START | |
|---|
| 579 | SYMMETRY_MIRROR_PLANE * SYMMETRY_XMAX_START | |
|---|
| 580 | SYMMETRY_MIRROR_PLANE * SYMMETRY_YMAX_START | |
|---|
| 581 | SYMMETRY_MIRROR_PLANE * SYMMETRY_ZMAX_START; |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | *max_explicit_deltat = PetscMin |
|---|
| 585 | (*max_explicit_deltat, .025/nx/nx/nx/thechternary->mobility22); |
|---|
| 586 | DPRINTF ("calculated deltat = %g\n",*max_explicit_deltat); |
|---|
| 587 | |
|---|
| 588 | if (!data->load_data) |
|---|
| 589 | { |
|---|
| 590 | PetscTruth uniform, layers,trilayer, box,particles, triangle,sinusoidal; |
|---|
| 591 | int xmin,xmax, ymin,ymax, zmin,zmax, rank,size, random_counter; |
|---|
| 592 | PetscScalar fluct=0.005; |
|---|
| 593 | |
|---|
| 594 | PetscScalar C2_layer1=0.98,C3_layer1=0.98,C2_layer2=0.02,C3_layer2=0.02; |
|---|
| 595 | |
|---|
| 596 | PetscScalar C2_layer3=0.02, C3_layer3=0.98; |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C2_layer1", |
|---|
| 608 | &C2_layer1, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 609 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C3_layer1", |
|---|
| 610 | &C3_layer1, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 611 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C2_layer2", |
|---|
| 612 | &C2_layer2, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 613 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C3_layer2", |
|---|
| 614 | &C3_layer2, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 615 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C2_layer3", |
|---|
| 616 | &C2_layer3, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 617 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_C3_layer3", |
|---|
| 618 | &C3_layer3, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | ierr = PetscOptionsHasName (PETSC_NULL,"-cht_uniform_C2",&uniform); |
|---|
| 628 | CHKERRQ (ierr); |
|---|
| 629 | if (uniform) |
|---|
| 630 | { |
|---|
| 631 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_uniform_C2", |
|---|
| 632 | &C2_layer2, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 633 | DPRINTF ("Uniform C2=%g\n", C2_layer2); |
|---|
| 634 | } |
|---|
| 635 | ierr = PetscOptionsHasName (PETSC_NULL,"-cht_uniform_C3",&uniform); |
|---|
| 636 | CHKERRQ (ierr); |
|---|
| 637 | if (uniform) |
|---|
| 638 | { |
|---|
| 639 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_uniform_C3", |
|---|
| 640 | &C3_layer2, PETSC_NULL); CHKERRQ(ierr); |
|---|
| 641 | DPRINTF ("Uniform C3=%g\n", C3_layer2); |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | for (iz=0; iz<(data->threedee ? zm: 1); iz++) |
|---|
| 646 | for (iy=0; iy<ym; iy++) |
|---|
| 647 | for (ix=0; ix<xm; ix++) |
|---|
| 648 | { |
|---|
| 649 | globalarray [((iz*ym + iy)*xm + ix)*vars + thechternary->C2var] = |
|---|
| 650 | C2_layer2; |
|---|
| 651 | globalarray [((iz*ym + iy)*xm + ix)*vars + thechternary->C3var] = |
|---|
| 652 | C3_layer2; |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_particles",&particles); |
|---|
| 669 | CHKERRQ (ierr); |
|---|
| 670 | if (particles) |
|---|
| 671 | { |
|---|
| 672 | xmin = nx/4; |
|---|
| 673 | xmax = 3*nx/4; |
|---|
| 674 | ymin = 0; |
|---|
| 675 | ymax = nx/4; |
|---|
| 676 | zmin = 0; |
|---|
| 677 | zmax = nz/4; |
|---|
| 678 | data->bcflags |= (XMIN_SYMMETRY | YMIN_SYMMETRY | ZMAX_SYMMETRY); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_box", &box); |
|---|
| 692 | CHKERRQ (ierr); |
|---|
| 693 | if (box) |
|---|
| 694 | { |
|---|
| 695 | if ((data->bcflags & XMIN_SYMMETRY) && |
|---|
| 696 | (data->bcflags & YMIN_SYMMETRY)) |
|---|
| 697 | { |
|---|
| 698 | xmin = ymin = zmin = 0.; |
|---|
| 699 | xmax = nx/2; |
|---|
| 700 | ymax = ny/2; |
|---|
| 701 | zmax = nz/2; |
|---|
| 702 | } |
|---|
| 703 | else |
|---|
| 704 | { |
|---|
| 705 | xmin = nx/4; |
|---|
| 706 | xmax = 3*nx/4; |
|---|
| 707 | ymin = ny/4; |
|---|
| 708 | ymax = 3*ny/4; |
|---|
| 709 | zmin = nz/4; |
|---|
| 710 | zmax = 3*nz/4; |
|---|
| 711 | } |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_layers", &layers); |
|---|
| 723 | CHKERRQ (ierr); |
|---|
| 724 | if (layers) |
|---|
| 725 | { |
|---|
| 726 | PetscScalar layer_thickness; |
|---|
| 727 | |
|---|
| 728 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_layers", |
|---|
| 729 | &layer_thickness, PETSC_NULL); |
|---|
| 730 | CHKERRQ (ierr); |
|---|
| 731 | DPRINTF ("Layer thickness: %g\n", layer_thickness); |
|---|
| 732 | xmin=ymin=zmin=0; |
|---|
| 733 | xmax=nx; |
|---|
| 734 | zmax=nz; |
|---|
| 735 | ymax=layer_thickness * ny; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | for (iz = (data->threedee ? PetscMax (zs, zmin) : 0); |
|---|
| 740 | iz < (data->threedee ? PetscMin (zs+zm, zmax): 1); iz++) |
|---|
| 741 | for (iy=PetscMax(ys,ymin); iy<PetscMin(ys+ym,ymax); iy++) |
|---|
| 742 | for (ix=PetscMax(xs,xmin); ix<PetscMin(xs+xm,xmax); ix++) |
|---|
| 743 | { |
|---|
| 744 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 745 | thechternary->C2var] =C2_layer1; |
|---|
| 746 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 747 | thechternary->C3var] =C3_layer1; |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_amplitude",&sinusoidal); |
|---|
| 759 | CHKERRQ (ierr); |
|---|
| 760 | if (sinusoidal && layers) |
|---|
| 761 | { |
|---|
| 762 | PetscScalar amplitude=delta, layer_thickness; |
|---|
| 763 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_amplitude", |
|---|
| 764 | &litude, PETSC_NULL); |
|---|
| 765 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_layers", |
|---|
| 766 | &layer_thickness, PETSC_NULL); |
|---|
| 767 | |
|---|
| 768 | xmin=0; |
|---|
| 769 | xmax=nx; |
|---|
| 770 | zmin=0; |
|---|
| 771 | zmax=nz; |
|---|
| 772 | ymin=0; |
|---|
| 773 | for (iz = (data->threedee ? PetscMax (zs, zmin) : 0); |
|---|
| 774 | iz < (data->threedee ? PetscMin (zs+zm, zmax): 1); iz++) |
|---|
| 775 | for (ix=PetscMax(xs,xmin); ix<PetscMin(xs+xm,xmax); ix++) |
|---|
| 776 | { |
|---|
| 777 | PetscScalar ymax_scalar = layer_thickness*ny + |
|---|
| 778 | (amplitude/delta) * |
|---|
| 779 | (2. + sin (2.*PETSC_PI*ix/nx) + sin (2.*PETSC_PI*iz/nz)); |
|---|
| 780 | for (iy=PetscMax(ys,ymin); iy<PetscMin(ys+ym,ymax_scalar); |
|---|
| 781 | iy++) |
|---|
| 782 | { |
|---|
| 783 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 784 | thechternary->C2var] = C2_layer1; |
|---|
| 785 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 786 | thechternary->C3var] = C3_layer1; |
|---|
| 787 | if (iy>ymax_scalar && iy !=ys) |
|---|
| 788 | { |
|---|
| 789 | globalarray [(((iz-zs)*ym + iy-1-ys)*xm + ix-xs)*vars + |
|---|
| 790 | thechternary->C2var] = ymax_scalar - (iy-1); |
|---|
| 791 | globalarray [(((iz-zs)*ym + iy-1-ys)*xm + ix-xs)*vars + |
|---|
| 792 | thechternary->C3var] = ymax_scalar - (iy-1); |
|---|
| 793 | } |
|---|
| 794 | } |
|---|
| 795 | } |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | ierr = PetscOptionsHasName (PETSC_NULL, "-cht_trilayer", &trilayer); |
|---|
| 807 | CHKERRQ (ierr); |
|---|
| 808 | if (trilayer) |
|---|
| 809 | { |
|---|
| 810 | PetscScalar layer_thickness; |
|---|
| 811 | |
|---|
| 812 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_trilayer", |
|---|
| 813 | &layer_thickness, PETSC_NULL); |
|---|
| 814 | CHKERRQ (ierr); |
|---|
| 815 | DPRINTF ("Layer thickness: %g\n", layer_thickness); |
|---|
| 816 | |
|---|
| 817 | xmin = 0; |
|---|
| 818 | xmax = nx; |
|---|
| 819 | ymin = layer_thickness*ny; |
|---|
| 820 | ymax = ny; |
|---|
| 821 | zmin = 0; |
|---|
| 822 | zmax = nz; |
|---|
| 823 | |
|---|
| 824 | for (iz = (data->threedee ? PetscMax (zs, zmin) : 0); |
|---|
| 825 | iz < (data->threedee ? PetscMin (zs+zm, zmax): 1); iz++) |
|---|
| 826 | for (iy=PetscMax(ys,ymin); iy<PetscMin(ys+ym,ymax); iy++) |
|---|
| 827 | for (ix=PetscMax(xs,xmin); ix<PetscMin(xs+xm,xmax); ix++) |
|---|
| 828 | { |
|---|
| 829 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 830 | thechternary->C2var] =C2_layer3; |
|---|
| 831 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 832 | thechternary->C3var] =C3_layer3; |
|---|
| 833 | } |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | |
|---|
| 848 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_random_fluct",&fluct, |
|---|
| 849 | PETSC_NULL); CHKERRQ (ierr); |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | PetscScalar random_thickness=1.; |
|---|
| 859 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_random_layer", |
|---|
| 860 | &random_thickness, PETSC_NULL); |
|---|
| 861 | CHKERRQ (ierr); |
|---|
| 862 | ymax = ny * random_thickness; |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | #define SMALL_PRIME 1571 |
|---|
| 880 | #define MEDIUM_PRIME 524287 |
|---|
| 881 | #define LARGE_PRIME 2147483647 |
|---|
| 882 | #define MY_RANDOM(pseudo_random) \ |
|---|
| 883 | (((long long) (random_counter = (random_counter + MEDIUM_PRIME) % SMALL_PRIME) * RAND_MAX / SMALL_PRIME + pseudo_random) % RAND_MAX) |
|---|
| 884 | ierr = MPI_Comm_rank (PETSC_COMM_WORLD, &rank); CHKERRQ (ierr); |
|---|
| 885 | ierr = MPI_Comm_size (PETSC_COMM_WORLD, &size); CHKERRQ (ierr); |
|---|
| 886 | random_counter = ((long long) rank * LARGE_PRIME) % SMALL_PRIME; |
|---|
| 887 | #ifdef DEBUG |
|---|
| 888 | ierr = PetscSynchronizedPrintf (PETSC_COMM_WORLD, "[%d] random_counter initialized to %d\n", rank, random_counter); CHKERRQ (ierr); |
|---|
| 889 | ierr = PetscSynchronizedFlush (PETSC_COMM_WORLD); CHKERRQ (ierr); |
|---|
| 890 | #endif |
|---|
| 891 | |
|---|
| 892 | ierr = PetscOptionsGetScalar (PETSC_NULL, "-cht_random_fluct", |
|---|
| 893 | &fluct, PETSC_NULL); CHKERRQ (ierr); |
|---|
| 894 | if (fluct != 0.) |
|---|
| 895 | for (iz = (data->threedee ? zs : 0); |
|---|
| 896 | iz < (data->threedee ? zs+zm: 1); iz++) |
|---|
| 897 | for (iy=ys; iy<PetscMin(ys+ym,ymax); iy++) |
|---|
| 898 | for (ix=xs; ix<xs+xm; ix++){ |
|---|
| 899 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 900 | thechternary->C2var] += |
|---|
| 901 | -fluct + 2.*fluct*(PetscScalar)MY_RANDOM(rand())/RAND_MAX; |
|---|
| 902 | globalarray [(((iz-zs)*ym + iy-ys)*xm + ix-xs)*vars + |
|---|
| 903 | thechternary->C3var] += |
|---|
| 904 | -fluct + 2.*fluct*(PetscScalar)MY_RANDOM(rand())/RAND_MAX; |
|---|
| 905 | } |
|---|
| 906 | } |
|---|
| 907 | |
|---|
| 908 | return 0; |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | #define C2(point) (x [vars*(point) + thechternary->C2var]) |
|---|
| 912 | #define C3(point) (x [vars*(point) + thechternary->C3var]) |
|---|
| 913 | #define C2func(point) (func [vars*(point) + thechternary->C2var]) |
|---|
| 914 | #define C3func(point) (func [vars*(point) + thechternary->C3var]) |
|---|
| 915 | #define mu2(point) (temp [tempvars*(point) + thechternary->mu2var]) |
|---|
| 916 | #define mu3(point) (temp [tempvars*(point) + thechternary->mu3var]) |
|---|
| 917 | #define Psi(point) (integ [intvars*(point) + thechternary->psivar]) |
|---|
| 918 | |
|---|
| 919 | #define u(point) (x [vars*(point) + thevortex->uvar]) |
|---|
| 920 | #define v(point) (x [vars*(point) + thevortex->vvar]) |
|---|
| 921 | |
|---|
| 922 | #define sigma(point) (temp[tempvars*(point) + thepotential->sigmavar]) |
|---|
| 923 | #define V(point) (x[vars*(point) + thepotential->Vvar]) |
|---|
| 924 | |
|---|
| 925 | #define pu(point) (x [vars*(point) + thepressure->uvar]) |
|---|
| 926 | #define pv(point) (x [vars*(point) + thepressure->vvar]) |
|---|
| 927 | #define pw(point) (x [vars*(point) + thepressure->wvar]) |
|---|
| 928 | |
|---|
| 929 | #undef __FUNCT__ |
|---|
| 930 | #define __FUNCT__ "chternary_integrate_interior_line" |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
|