| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file pded.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief PDE definition file. |
| 5 |
c* @version $Id: pdef.f,v 1.2 2010/08/12 05:53:09 fetk Exp $ |
| 6 |
c* @attention |
| 7 |
c* @verbatim |
| 8 |
c* |
| 9 |
c* PMG -- Parallel algebraic MultiGrid |
| 10 |
c* Copyright (C) 1994-- Michael Holst. |
| 11 |
c* |
| 12 |
c* Michael Holst <[email protected]> |
| 13 |
c* University of California, San Diego |
| 14 |
c* Department of Mathematics, 5739 AP&M |
| 15 |
c* 9500 Gilman Drive, Dept. 0112 |
| 16 |
c* La Jolla, CA 92093-0112 USA |
| 17 |
c* http://math.ucsd.edu/~mholst |
| 18 |
c* |
| 19 |
c* This file is part of PMG. |
| 20 |
c* |
| 21 |
c* PMG is free software; you can redistribute it and/or modify |
| 22 |
c* it under the terms of the GNU General Public License as published by |
| 23 |
c* the Free Software Foundation; either version 2 of the License, or |
| 24 |
c* (at your option) any later version. |
| 25 |
c* |
| 26 |
c* PMG is distributed in the hope that it will be useful, |
| 27 |
c* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
c* GNU General Public License for more details. |
| 30 |
c* |
| 31 |
c* You should have received a copy of the GNU General Public License |
| 32 |
c* along with PMG; if not, write to the Free Software |
| 33 |
c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 34 |
c* |
| 35 |
c* Linking PMG statically or dynamically with other modules is making a |
| 36 |
c* combined work based on PMG. Thus, the terms and conditions of the GNU |
| 37 |
c* General Public License cover the whole combination. |
| 38 |
c* |
| 39 |
c* SPECIAL GPL EXCEPTION |
| 40 |
c* In addition, as a special exception, the copyright holders of PMG |
| 41 |
c* give you permission to combine the PMG program with free software |
| 42 |
c* programs and libraries that are released under the GNU LGPL or with |
| 43 |
c* code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision. |
| 44 |
c* Such combined software may be linked with PMG and redistributed together |
| 45 |
c* in original or modified form as mere aggregation without requirement that |
| 46 |
c* the entire work be under the scope of the GNU General Public License. |
| 47 |
c* This special exception permission is also extended to any software listed |
| 48 |
c* in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries. |
| 49 |
c* |
| 50 |
c* Note that people who make modified versions of PMG are not obligated |
| 51 |
c* to grant this special exception for their modified versions; it is |
| 52 |
c* their choice whether to do so. The GNU General Public License gives |
| 53 |
c* permission to release a modified version without this exception; this |
| 54 |
c* exception also makes it possible to release a modified version which |
| 55 |
c* carries forward this exception. |
| 56 |
c* |
| 57 |
c* @endverbatim |
| 58 |
c* /////////////////////////////////////////////////////////////////////////// |
| 59 |
|
| 60 |
c* ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ |
| 61 |
c* |
| 62 |
c* DIFFERENTIAL EQUATION: Poisson's |
| 63 |
c* |
| 64 |
c* BOUNDARY CONDITIONS: |
| 65 |
c* |
| 66 |
c* East Face (xmin): Dirichlet, homogeneous |
| 67 |
c* West Face (xmax): Dirichlet, homogeneous |
| 68 |
c* North Face (ymin): Dirichlet, homogeneous |
| 69 |
c* South Face (ymax): Dirichlet, homogeneous |
| 70 |
c* Top Face (zmin): Dirichlet, homogeneous |
| 71 |
c* Bottom Face (zmax): Dirichlet, homogeneous |
| 72 |
c* |
| 73 |
c* MESH: hx = (xmax-xmin) / (nx-1) |
| 74 |
c* hy = (ymax-ymin) / (ny-1) |
| 75 |
c* hz = (zmax-zmin) / (nz-1) |
| 76 |
c* xi = xmin + (i-1) * hx, i=1,...,nx |
| 77 |
c* yi = ymin + (j-1) * hy, j=1,...,ny |
| 78 |
c* zi = zmin + (k-1) * hk, k=1,...,nz |
| 79 |
c* |
| 80 |
c* CHOSEN TRUE SOLUTION: u(x,y,z) = Sin(n pi x)*Sin(m pi y)*Sin(l pi z) |
| 81 |
c* |
| 82 |
c* author: michael holst |
| 83 |
c* ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ |
| 84 |
c* |
| 85 |
function c_scal(coef,u,ipkey) |
| 86 |
c* ********************************************************************* |
| 87 |
c* purpose: |
| 88 |
c* |
| 89 |
c* define the nonlinearity (scalar version) |
| 90 |
c* |
| 91 |
c* author: michael holst |
| 92 |
c* ********************************************************************* |
| 93 |
implicit none |
| 94 |
double precision coef,u,c_scal |
| 95 |
integer ipkey |
| 96 |
c* |
| 97 |
c* *** create the nonlinear term *** |
| 98 |
c_scal = coef * u |
| 99 |
c* |
| 100 |
c* *** end it *** |
| 101 |
return |
| 102 |
end |
| 103 |
function dc_scal(coef,u,ipkey) |
| 104 |
c* ********************************************************************* |
| 105 |
c* purpose: |
| 106 |
c* |
| 107 |
c* define the derivative of the nonlinearity (scalar version) |
| 108 |
c* |
| 109 |
c* author: michael holst |
| 110 |
c* ********************************************************************* |
| 111 |
implicit none |
| 112 |
double precision coef,u,dc_scal |
| 113 |
integer ipkey |
| 114 |
c* |
| 115 |
c* *** create the nonlinear term *** |
| 116 |
dc_scal = coef |
| 117 |
c* |
| 118 |
c* *** end it *** |
| 119 |
return |
| 120 |
end |
| 121 |
subroutine c_vec(coef,uin,uout,nx,ny,nz,ipkey) |
| 122 |
c* ********************************************************************* |
| 123 |
c* purpose: |
| 124 |
c* |
| 125 |
c* define the nonlinearity (vector version) |
| 126 |
c* |
| 127 |
c* author: michael holst |
| 128 |
c* ********************************************************************* |
| 129 |
implicit none |
| 130 |
integer nx,ny,nz,ipkey |
| 131 |
double precision uin(*),uout(*),coef(*) |
| 132 |
integer n,i,ii,nproc,ipara,ivect |
| 133 |
parameter (nproc=1) |
| 134 |
c* |
| 135 |
cmdir 0 0 |
| 136 |
c* |
| 137 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 138 |
n = nx * ny * nz |
| 139 |
ipara = n / nproc |
| 140 |
ivect = mod(n,nproc) |
| 141 |
c* |
| 142 |
c* *** do parallel loops *** |
| 143 |
cmdir 2 1 |
| 144 |
do 10 ii = 1, nproc |
| 145 |
cmdir 2 2 |
| 146 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 147 |
uout(i) = coef(i) * uin(i) |
| 148 |
11 continue |
| 149 |
10 continue |
| 150 |
c* |
| 151 |
c* *** do vector loops *** |
| 152 |
cmdir 1 1 |
| 153 |
do 20 i = ipara*nproc+1, n |
| 154 |
uout(i) = coef(i) * uin(i) |
| 155 |
20 continue |
| 156 |
c* |
| 157 |
c* *** end it *** |
| 158 |
return |
| 159 |
end |
| 160 |
subroutine dc_vec(coef,uin,uout,nx,ny,nz,ipkey) |
| 161 |
c* ********************************************************************* |
| 162 |
c* purpose: |
| 163 |
c* |
| 164 |
c* define the derivative of the nonlinearity (vector version) |
| 165 |
c* |
| 166 |
c* author: michael holst |
| 167 |
c* ********************************************************************* |
| 168 |
implicit none |
| 169 |
integer nx,ny,nz,ipkey |
| 170 |
double precision uin(*),uout(*),coef(*) |
| 171 |
integer n,i,ii,nproc,ipara,ivect |
| 172 |
parameter (nproc=1) |
| 173 |
c* |
| 174 |
cmdir 0 0 |
| 175 |
c* |
| 176 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 177 |
n = nx * ny * nz |
| 178 |
ipara = n / nproc |
| 179 |
ivect = mod(n,nproc) |
| 180 |
c* |
| 181 |
c* *** do parallel loops *** |
| 182 |
cmdir 2 1 |
| 183 |
do 10 ii = 1, nproc |
| 184 |
cmdir 2 2 |
| 185 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 186 |
uout(i) = coef(i) |
| 187 |
11 continue |
| 188 |
10 continue |
| 189 |
c* |
| 190 |
c* *** do vector loops *** |
| 191 |
cmdir 1 1 |
| 192 |
do 20 i = ipara*nproc+1, n |
| 193 |
uout(i) = coef(i) |
| 194 |
20 continue |
| 195 |
c* |
| 196 |
c* *** end it *** |
| 197 |
return |
| 198 |
end |
| 199 |
subroutine fillco(iparm,rparm,nx,ny,nz, |
| 200 |
2 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 201 |
c* ********************************************************************* |
| 202 |
c* purpose: |
| 203 |
c* |
| 204 |
c* this subroutine defines poisson's equation on the unit cube. |
| 205 |
c* boundary conditions are zero dirichlet. |
| 206 |
c* |
| 207 |
c* details: |
| 208 |
c* |
| 209 |
c* this routine sets up the coefficients of the following |
| 210 |
c* three-dimensional, 2nd order linear elliptic partial |
| 211 |
c* differential equation: |
| 212 |
c* |
| 213 |
c* lu = f, u in omega |
| 214 |
c* u = g, u on boundary of omega |
| 215 |
c* |
| 216 |
c* where |
| 217 |
c* omega = [xmin,xmax]x[ymin,ymax]x[zmin,zmax] |
| 218 |
c* |
| 219 |
c* and l is taken to be in the following form: |
| 220 |
c* |
| 221 |
c* lu = - \nabla \cdot (a \nabla u) + c u |
| 222 |
c* |
| 223 |
c* the coefficients must be supplied as follows: |
| 224 |
c* |
| 225 |
c* a1cf(,,,): at x-half grid points, hence array is: (nx-1)*ny*nz |
| 226 |
c* a2cf(,,,): at y-half grid points, hence array is: nx*(ny-1)*nz |
| 227 |
c* a3cf(,,,): at z-half grid points, hence array is: nx*ny*(nz-1) |
| 228 |
c* (we index all three as: nx*ny*nz however) |
| 229 |
c* |
| 230 |
c* ccf: at grid points, hence array is: nx*ny*nz |
| 231 |
c* fcf: at grid points, hence array is: nx*ny*nz |
| 232 |
c* u: must be set to have appropriate boundary values |
| 233 |
c* |
| 234 |
c* author: michael holst |
| 235 |
c* ********************************************************************* |
| 236 |
implicit none |
| 237 |
integer iparm(*),nx,ny,nz |
| 238 |
double precision rparm(*) |
| 239 |
double precision a1cf(nx,ny,nz),a2cf(nx,ny,nz),a3cf(nx,ny,nz) |
| 240 |
double precision ccf(nx,ny,nz),fcf(nx,ny,nz),tcf(nx,ny,nz) |
| 241 |
double precision xf(nx),yf(ny),zf(nz) |
| 242 |
double precision gxcf(ny,nz,*),gycf(nx,nz,*),gzcf(nx,ny,*) |
| 243 |
c* |
| 244 |
c* *** variable declarations *** |
| 245 |
integer i,j,k,iinfo |
| 246 |
double precision hx,hy,hz,xmin,xmax,ymin,ymax,zmin,zmax |
| 247 |
double precision hxo2,hyo2,hzo2 |
| 248 |
c* |
| 249 |
c* *** some parameters *** |
| 250 |
double precision zn,zm,zl,pi |
| 251 |
parameter (zn=1.0d0,zm=1.0d0,zl=1.0d0) |
| 252 |
pi = 4.0d0 * datan(1.0d0) |
| 253 |
c* |
| 254 |
cmdir 0 0 |
| 255 |
c* |
| 256 |
c* *** info messages *** |
| 257 |
iinfo = iparm(12) |
| 258 |
c* |
| 259 |
c* ********************************************************************* |
| 260 |
c* *** definition of the domain |
| 261 |
c* ********************************************************************* |
| 262 |
c* |
| 263 |
c* *** set the correct boundary ranges *** |
| 264 |
xmin = 0.0d0 |
| 265 |
xmax = 1.0d0 |
| 266 |
ymin = 0.0d0 |
| 267 |
ymax = 1.0d0 |
| 268 |
zmin = 0.0d0 |
| 269 |
zmax = 1.0d0 |
| 270 |
c* |
| 271 |
c* *** store in rparm array *** |
| 272 |
rparm(3) = xmin |
| 273 |
rparm(4) = xmax |
| 274 |
rparm(5) = ymin |
| 275 |
rparm(6) = ymax |
| 276 |
rparm(7) = zmin |
| 277 |
rparm(8) = zmax |
| 278 |
c* |
| 279 |
c* ********************************************************************* |
| 280 |
c* *** boundary value definitions |
| 281 |
c* ********************************************************************* |
| 282 |
c* |
| 283 |
c* *** determine mesh widths *** |
| 284 |
hx = (xmax-xmin) / dble(nx-1) |
| 285 |
hy = (ymax-ymin) / dble(ny-1) |
| 286 |
hz = (zmax-zmin) / dble(nz-1) |
| 287 |
hxo2= hx / 2.0d0 |
| 288 |
hyo2= hy / 2.0d0 |
| 289 |
hzo2= hz / 2.0d0 |
| 290 |
c* |
| 291 |
c* ********************************************************************* |
| 292 |
c* *** pde coefficient value definitions |
| 293 |
c* ********************************************************************* |
| 294 |
c* |
| 295 |
c* *** fill coefficient arrays *** |
| 296 |
cmdir 3 1 |
| 297 |
do 10 k = 1, nz |
| 298 |
zf(k) = zmin + dble(k-1) * hz |
| 299 |
cmdir 3 2 |
| 300 |
do 11 j = 1, ny |
| 301 |
yf(j) = ymin + dble(j-1) * hy |
| 302 |
cmdir 3 3 |
| 303 |
do 12 i = 1, nx |
| 304 |
xf(i) = xmin + dble(i-1) * hx |
| 305 |
c* |
| 306 |
c* *** the diagonal tensor (2nd derivative) entries *** |
| 307 |
a1cf(i,j,k) = (1.0d0) |
| 308 |
a2cf(i,j,k) = (1.0d0) |
| 309 |
a3cf(i,j,k) = (1.0d0) |
| 310 |
c* |
| 311 |
c* *** the scalar (0th derivative) entry *** |
| 312 |
ccf(i,j,k) = (0.0d0) |
| 313 |
c* |
| 314 |
c* *** the rhs entry *** |
| 315 |
CZZZ fcf(i,j,k) = ((zn*zn+zm*zm+zl*zl)*pi*pi |
| 316 |
CZZZ 2 *dsin(zn*pi*xf(i))*dsin(zm*pi*yf(j))*dsin(zl*pi*zf(k))) |
| 317 |
fcf(i,j,k) = 1.0 |
| 318 |
c* |
| 319 |
c* *** the chosen true solution *** |
| 320 |
tcf(i,j,k) = |
| 321 |
2 (dsin(zn*pi*xf(i))*dsin(zm*pi*yf(j))*dsin(zl*pi*zf(k))) |
| 322 |
12 continue |
| 323 |
11 continue |
| 324 |
10 continue |
| 325 |
c* |
| 326 |
c* *** the (i=1) and (i=nx) boundaries (dirichlet) *** |
| 327 |
cmdir 2 1 |
| 328 |
do 50 k = 1, nz |
| 329 |
cmdir 2 2 |
| 330 |
do 51 j = 1, ny |
| 331 |
gxcf(j,k,1) = tcf(1 ,j,k) |
| 332 |
gxcf(j,k,2) = tcf(nx,j,k) |
| 333 |
gxcf(j,k,3) = 0.0d0 |
| 334 |
gxcf(j,k,4) = 0.0d0 |
| 335 |
51 continue |
| 336 |
50 continue |
| 337 |
c* |
| 338 |
c* *** the (j=1) and (j=ny) boundaries (dirichlet) *** |
| 339 |
cmdir 2 1 |
| 340 |
do 60 k = 1, nz |
| 341 |
cmdir 2 2 |
| 342 |
do 61 i = 1, nx |
| 343 |
gycf(i,k,1) = tcf(i,1 ,k) |
| 344 |
gycf(i,k,2) = tcf(i,ny,k) |
| 345 |
gycf(i,k,3) = 0.0d0 |
| 346 |
gycf(i,k,4) = 0.0d0 |
| 347 |
61 continue |
| 348 |
60 continue |
| 349 |
c* |
| 350 |
c* *** the (k=1) and (k=nz) boundaries (dirichlet) *** |
| 351 |
cmdir 2 1 |
| 352 |
do 70 j = 1, ny |
| 353 |
cmdir 2 2 |
| 354 |
do 71 i = 1, nx |
| 355 |
gzcf(i,j,1) = tcf(i,j,1 ) |
| 356 |
gzcf(i,j,2) = tcf(i,j,nz) |
| 357 |
gzcf(i,j,3) = 0.0d0 |
| 358 |
gzcf(i,j,4) = 0.0d0 |
| 359 |
71 continue |
| 360 |
70 continue |
| 361 |
c* |
| 362 |
c* *** end it *** |
| 363 |
return |
| 364 |
end |
| 365 |
|