| 1 |
/* /////////////////////////////////////////////////////////////////////////// |
| 2 |
// @file main.c |
| 3 |
// @author Michael Holst |
| 4 |
// @brief Main C driver for PMG. |
| 5 |
// @version $Id: mainc.c,v 1.2 2010/08/12 05:53:00 fetk Exp $ |
| 6 |
// @attention |
| 7 |
// @verbatim |
| 8 |
// |
| 9 |
// PMG -- Parallel algebraic MultiGrid |
| 10 |
// Copyright (C) 1994-- Michael Holst. |
| 11 |
// |
| 12 |
// Michael Holst <[email protected]> |
| 13 |
// University of California, San Diego |
| 14 |
// Department of Mathematics, 5739 AP&M |
| 15 |
// 9500 Gilman Drive, Dept. 0112 |
| 16 |
// La Jolla, CA 92093-0112 USA |
| 17 |
// http://math.ucsd.edu/~mholst |
| 18 |
// |
| 19 |
// This file is part of PMG. |
| 20 |
// |
| 21 |
// PMG is free software; you can redistribute it and/or modify |
| 22 |
// it under the terms of the GNU General Public License as published by |
| 23 |
// the Free Software Foundation; either version 2 of the License, or |
| 24 |
// (at your option) any later version. |
| 25 |
// |
| 26 |
// PMG is distributed in the hope that it will be useful, |
| 27 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
// GNU General Public License for more details. |
| 30 |
// |
| 31 |
// You should have received a copy of the GNU General Public License |
| 32 |
// along with PMG; if not, write to the Free Software |
| 33 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 34 |
// |
| 35 |
// Linking PMG statically or dynamically with other modules is making a |
| 36 |
// combined work based on PMG. Thus, the terms and conditions of the GNU |
| 37 |
// General Public License cover the whole combination. |
| 38 |
// |
| 39 |
// SPECIAL GPL EXCEPTION |
| 40 |
// In addition, as a special exception, the copyright holders of PMG |
| 41 |
// give you permission to combine the PMG program with free software |
| 42 |
// programs and libraries that are released under the GNU LGPL or with |
| 43 |
// code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision. |
| 44 |
// Such combined software may be linked with PMG and redistributed together |
| 45 |
// in original or modified form as mere aggregation without requirement that |
| 46 |
// the entire work be under the scope of the GNU General Public License. |
| 47 |
// This special exception permission is also extended to any software listed |
| 48 |
// in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries. |
| 49 |
// |
| 50 |
// Note that people who make modified versions of PMG are not obligated |
| 51 |
// to grant this special exception for their modified versions; it is |
| 52 |
// their choice whether to do so. The GNU General Public License gives |
| 53 |
// permission to release a modified version without this exception; this |
| 54 |
// exception also makes it possible to release a modified version which |
| 55 |
// carries forward this exception. |
| 56 |
// |
| 57 |
// @endverbatim |
| 58 |
// //////////////////////////////////////////////////////////////////////// */ |
| 59 |
|
| 60 |
/* /////////////////////////////////////////////////////////////////////////// |
| 61 |
// Welcome to PMG (MG/XMG). |
| 62 |
// /////////////////////////////////////////////////////////////////////////// |
| 63 |
// |
| 64 |
// ====================== |
| 65 |
// The Author Information |
| 66 |
// ====================== |
| 67 |
// |
| 68 |
// The computer codes PMG (MG/XMG, "the Code"), including FORTRAN/C/C++ |
| 69 |
// language multilevel subroutines called "MG" and the C-language X-Window |
| 70 |
// interface called "XMG", were developed by: |
| 71 |
// |
| 72 |
// Michael Holst TELE: (858) 534-4899 |
| 73 |
// Department of Mathematics FAX: (858) 534-5273 |
| 74 |
// UC San Diego, AP&M 5739 EMAIL: [email protected] |
| 75 |
// La Jolla, CA 92093 USA WEB: http://www.scicomp.ucsd.edu/~mholst |
| 76 |
// |
| 77 |
// ==================================================== |
| 78 |
// Licensing, permission to use, modify, and distribute |
| 79 |
// ==================================================== |
| 80 |
// |
| 81 |
// The code has been placed under the GNU General Public License (GPL). |
| 82 |
// |
| 83 |
// This means that essentially you can use and modify the code as you like, |
| 84 |
// under a few conditions, such as acknowledging the authors of the original |
| 85 |
// code in any derived works, such as new programs or research results using |
| 86 |
// the code. |
| 87 |
// |
| 88 |
// Please have a look at the GPL which should have accompanied the code. |
| 89 |
// If it is missing, please write to the Free Software Foundation, Inc., |
| 90 |
// 675 Mass Ave, Cambridge, MA 02139, USA. |
| 91 |
// |
| 92 |
// It would have been easier for me to just keep the code completely private, |
| 93 |
// or to hand out very restricted use copies. However, in the interests of |
| 94 |
// freedom of information, the advancement of science, the future of the |
| 95 |
// planet, and so on, I decided to distribute the code in this very free way. |
| 96 |
// The GNU world functions very much on the honor system. I want you to have |
| 97 |
// all of my source code because I think it will do more toward helping you |
| 98 |
// understand the ideas in there than anything else. The GNU idea is that in |
| 99 |
// return for all of my work on the source code and the ideas behind it, all I |
| 100 |
// ask for is some acknowledgment in your derived works for using my original |
| 101 |
// code and the original ideas that went into the code. For GNU to be viable, |
| 102 |
// we all need to abide by this very minimal requirement. |
| 103 |
// |
| 104 |
// I'm typing this on a nearly all-GNU system right now, namely Linux 1.2.8, |
| 105 |
// a GNU version of UN*X available under the same conditions as PMG. |
| 106 |
// I.e., you get all of the source code for the entire UN*X operating system. |
| 107 |
// For more information about Linux, see: http://sunsite.unc.edu/mdw/linux.html |
| 108 |
// |
| 109 |
// ==================================================================== |
| 110 |
// Pointers to Papers and other Reference Materials Related to the Code |
| 111 |
// ==================================================================== |
| 112 |
// |
| 113 |
// The methods and techniques implemented in the Code were developed by |
| 114 |
// Michael Holst as a part of his PhD research, and are described in detail in |
| 115 |
// the PhD thesis: |
| 116 |
// |
| 117 |
// @phdthesis{Hols93a, |
| 118 |
// author = "M. Holst", |
| 119 |
// title = "Multilevel Methods for the {Poisson-Boltzmann} Equation", |
| 120 |
// note = "Also published as Tech. Rep. UIUCDCS-R-03-1821", |
| 121 |
// school = "Numerical Computing Group, |
| 122 |
// Department of Computer Science, |
| 123 |
// University of Illinois at Urbana-Champaign", |
| 124 |
// year = 1993 } |
| 125 |
// |
| 126 |
// Also refer to the supporting papers: |
| 127 |
// |
| 128 |
// @manual{Hols94d, |
| 129 |
// author = "M. Holst", |
| 130 |
// title = "The {Poisson-Boltzmann} Equation: |
| 131 |
// Analysis and Multilevel Numerical Solution", |
| 132 |
// note = "Monograph (updated and extended form of the |
| 133 |
// Ph.D. thesis~\cite{Hols93a})." } |
| 134 |
// |
| 135 |
// @article{SHHN94, |
| 136 |
// author = "R. Sampogna and J. Hecht and M. Holst and A. Nicholls |
| 137 |
// and B. Honig", |
| 138 |
// title = "Nonlinear {Poisson-Boltzmann} Calculation of {pKa} |
| 139 |
// Values", |
| 140 |
// journal = "Biophysics", |
| 141 |
// note = "(In Progress?)", |
| 142 |
// year = 1994 } |
| 143 |
// |
| 144 |
// @article{HoVa94b, |
| 145 |
// author = "M. Holst and S. Vandewalle", |
| 146 |
// title = "Schwarz Methods: to Symmetrize or not to Symmetrize", |
| 147 |
// journal = SINUM, |
| 148 |
// note = "(Accepted)", |
| 149 |
// year = 1994 } |
| 150 |
// |
| 151 |
// @article{Hols94e, |
| 152 |
// author = "M. Holst and F. Saied", |
| 153 |
// title = "Numerical Solution of the Nonlinear {Poisson-Boltzmann} |
| 154 |
// Equation: Developing More Robust and Efficient Methods", |
| 155 |
// journal = JCC, |
| 156 |
// volume = "16", |
| 157 |
// number = "3", |
| 158 |
// pages = "337--364", |
| 159 |
// year = 1995 } |
| 160 |
// |
| 161 |
// @article{HoSa93a, |
| 162 |
// author = "M. Holst and F. Saied", |
| 163 |
// title = "Multigrid Solution of the {Poisson-Boltzmann} Equation", |
| 164 |
// journal = JCC, |
| 165 |
// volume = "14", |
| 166 |
// number = "1", |
| 167 |
// pages = "105--113", |
| 168 |
// year = 1993 } |
| 169 |
// |
| 170 |
// @article{HKSS94, |
| 171 |
// author = "M. Holst and R. Kozack and F. Saied and S. Subramaniam", |
| 172 |
// title = "Protein Electrostatics: Rapid Multigrid-based {Newton} |
| 173 |
// Algorithm for Solution of the Full Nonlinear |
| 174 |
// {Poisson-Boltzmann} Equation", |
| 175 |
// journal = "J. Biomol. Struct. Dyn.", |
| 176 |
// volume = "11", |
| 177 |
// pages = "1437--1445", |
| 178 |
// year = 1994 } |
| 179 |
// |
| 180 |
// @article{HKSS93b, |
| 181 |
// author = "M. Holst and R. Kozack and F. Saied and S. Subramaniam", |
| 182 |
// title = "Treatment of Electrostatic Effects in Proteins: |
| 183 |
// Multigrid-based-{Newton} Iterative Method for Solution |
| 184 |
// of the Full Nonlinear {Poisson-Boltzmann} Equation", |
| 185 |
// journal = "Proteins: Structure, Function, and Genetics", |
| 186 |
// volume = "18", |
| 187 |
// number = "3", |
| 188 |
// pages = "231--245", |
| 189 |
// year = 1994 } |
| 190 |
// |
| 191 |
// @techreport{Hols94h, |
| 192 |
// author = "M. Holst", |
| 193 |
// title = "A Theoretical Analysis of the {Poisson-Boltzmann} |
| 194 |
// Equation: A priori Estimates and Well-posedness", |
| 195 |
// institution = "Applied Mathematics and CRPC, |
| 196 |
// California Institute of Technology", |
| 197 |
// year = 1994 } |
| 198 |
// |
| 199 |
// @inproceedings{HoVa95a, |
| 200 |
// author = "M. Holst and S. Vandewalle", |
| 201 |
// title = "Schwarz Methods: To Symmetrize or not to Symmetrize", |
| 202 |
// booktitle = "Proceedings of the Seventh Copper Mountain Conference on |
| 203 |
// Multigrid Methods, April 2-7, 1995, Copper Mountain, |
| 204 |
// Colorado", |
| 205 |
// editor = "J. Mandel and S. McCormick", |
| 206 |
// publisher = "NASA Langley Research Center", |
| 207 |
// year = "1995" } |
| 208 |
// |
| 209 |
// @inproceedings{HoSa93b, |
| 210 |
// author = "M. Holst and F. Saied", |
| 211 |
// title = "Multigrid and Domain Decomposition Methods for |
| 212 |
// Electrostatics Problems", |
| 213 |
// booktitle = "Domain Decomposition Methods in Science and Engineering |
| 214 |
// (Proceedings of the Seventh International Conference on |
| 215 |
// Domain Decomposition, October 27-30, 1993, |
| 216 |
// The Pennsylvania State University)", |
| 217 |
// editor = "D. E. Keyes and J. Xu", |
| 218 |
// publisher = "American Mathematical Society, Providence", |
| 219 |
// year = "1995" } |
| 220 |
// |
| 221 |
// @techreport{HoVa94a, |
| 222 |
// author = "M. Holst and S. Vandewalle", |
| 223 |
// title = "Schwarz Methods: to Symmetrize or not to Symmetrize", |
| 224 |
// institution = "Applied Mathematics and CRPC, |
| 225 |
// California Institute of Technology", |
| 226 |
// number = "CRPC-94-13", |
| 227 |
// year = 1994 } |
| 228 |
// |
| 229 |
// @techreport{Hols94c, |
| 230 |
// author = "M. Holst", |
| 231 |
// title = "{An} {Algebraic} {Schwarz} {Theory}", |
| 232 |
// institution = "Applied Mathematics and CRPC, |
| 233 |
// California Institute of Technology", |
| 234 |
// number = "CRPC-94-12", |
| 235 |
// year = 1994 } |
| 236 |
// |
| 237 |
// @techreport{Hols94f, |
| 238 |
// author = "M. Holst", |
| 239 |
// title = "A Robust and Efficient Numerical Method for Nonlinear |
| 240 |
// Protein Modeling Equations", |
| 241 |
// institution = "Applied Mathematics and CRPC, |
| 242 |
// California Institute of Technology", |
| 243 |
// number = "CRPC-94-9", |
| 244 |
// year = 1994 } |
| 245 |
// |
| 246 |
// @techreport{HoSa93c, |
| 247 |
// author = "M. Holst and F. Saied", |
| 248 |
// title = "A Short Note Comparing Multigrid and Domain Decomposition |
| 249 |
// for Protein Modeling Equations", |
| 250 |
// institution = "Applied Mathematics and CRPC, |
| 251 |
// California Institute of Technology", |
| 252 |
// number = "CRPC-94-10", |
| 253 |
// year = 1994 } |
| 254 |
// |
| 255 |
// ===================== |
| 256 |
// PMG Bugs and Notes |
| 257 |
// ===================== |
| 258 |
// |
| 259 |
// The timing routine, found in "secd.c", is machine dependent. We have |
| 260 |
// implemented a number of routines for different machines, including a |
| 261 |
// generic routine for a standard unix machine with the getrusage system |
| 262 |
// routine. |
| 263 |
// |
| 264 |
// ============================= |
| 265 |
// PMG Last Modification Date |
| 266 |
// ============================= |
| 267 |
// |
| 268 |
// MG: 10-01-95 |
| 269 |
// XMG: 10-01-95 |
| 270 |
// |
| 271 |
// //////////////////////////////////////////////////////////////////////// */ |
| 272 |
|
| 273 |
/* /////////////////////////////////////////////////////////////////////////// |
| 274 |
// pupose: |
| 275 |
// ------- |
| 276 |
// |
| 277 |
// this program uses a numerical method to solve the following |
| 278 |
// three-dimensional, 2nd order linear elliptic partial |
| 279 |
// differential equation: |
| 280 |
// |
| 281 |
// lu = f, u in omega |
| 282 |
// u = g, u on boundary of omega |
| 283 |
// |
| 284 |
// where |
| 285 |
// |
| 286 |
// omega = [xmin,xmax] x [ymin,ymax] x [zmin,zmax] |
| 287 |
// |
| 288 |
// the multigrid code requires the operator in the form: |
| 289 |
// |
| 290 |
// - \nabla \cdot (a \nabla u) + c u = f |
| 291 |
// |
| 292 |
// with; |
| 293 |
// |
| 294 |
// a=(a1(x,y,z),a2(x,y,z),a3(x,y,z)), c(x,y,z), f(x,y,z), |
| 295 |
// all scalar functions (possibly discontinuous) on omega. |
| 296 |
// (the discontinuities must be along grid lines on fine grid.) |
| 297 |
// the boundary function g(x,y,z) is smooth on boundary of omega. |
| 298 |
// |
| 299 |
// user inputs: |
| 300 |
// ------------ |
| 301 |
// |
| 302 |
// the user selects one of several possible methods: |
| 303 |
// (1) multigrid |
| 304 |
// (2) ... |
| 305 |
// |
| 306 |
// the calls to each of the routines are as follows: |
| 307 |
// |
| 308 |
// call mgdriv (iparm,rparm,iwork,rwork,u, |
| 309 |
// . xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 310 |
// |
| 311 |
// where the parameters are as follows: |
| 312 |
// |
| 313 |
// iparm = integer parameters for the solver |
| 314 |
// rparm = real parameters for the solver |
| 315 |
// iwork = some integer work space |
| 316 |
// rwork = some real work space |
| 317 |
// u = solution (perhaps some initial approximation) |
| 318 |
// xf = the x-coordinates of the tensor-product mesh |
| 319 |
// yf = the y-coordinates of the tensor-product mesh |
| 320 |
// zf = the z-coordinates of the tensor-product mesh |
| 321 |
// gxcf = the x=xmin and x=xmax boundary types and conditions |
| 322 |
// gycf = the y=ymin and y=ymax boundary types and conditions |
| 323 |
// gzcf = the z=zmin and z=zmax boundary types and conditions |
| 324 |
// a1cf = entry (1,1) of the diagonal tensor "a" above |
| 325 |
// a2cf = entry (2,2) of the diagonal tensor "a" above |
| 326 |
// a3cf = entry (3,3) of the diagonal tensor "a" above |
| 327 |
// ccf = the coefficient "c" above |
| 328 |
// fcf = the sourse function "f" above |
| 329 |
// tcf = the true solution of the pde if available (for testing) |
| 330 |
// (must always be provided as may be used for storage) |
| 331 |
// |
| 332 |
// the sizes of the arrays must be as follows: |
| 333 |
// |
| 334 |
// nxm = number of x-points in the tensor-product mesh |
| 335 |
// nym = number of y-points in the tensor-product mesh |
| 336 |
// nzm = number of z-points in the tensor-product mesh |
| 337 |
// nf = nxm * nym * nzm (total number of nodes) |
| 338 |
// |
| 339 |
// ifudge = 1000 |
| 340 |
// nfarr = nf + nf/6 + ifudge |
| 341 |
// niwk = calculated by multigrid code based on input parameters |
| 342 |
// nrwk = calculated by multigrid code based on input parameters |
| 343 |
// |
| 344 |
// iparm = iparm(100) |
| 345 |
// rparm = rparm(100) |
| 346 |
// iwork = iwork(niwk) |
| 347 |
// rwork = rwork(nrwk) |
| 348 |
// a1cf = a1cf(nfarr) |
| 349 |
// a2cf = a2cf(nfarr) |
| 350 |
// a3cf = a3cf(nfarr) |
| 351 |
// ccf = ccf(nfarr) |
| 352 |
// fcf = fcf(nfarr) |
| 353 |
// tcf = tcf(nfarr) |
| 354 |
// u = u(nfarr) |
| 355 |
// xf = xf(nxm*5) |
| 356 |
// yf = yf(nym*5) |
| 357 |
// zf = zf(nzm*5) |
| 358 |
// gxcf = gxcf(nym*nzm*10) |
| 359 |
// gycf = gycf(nxm*nzm*10) |
| 360 |
// gzcf = gzcf(nxm*nym*10) |
| 361 |
// |
| 362 |
// note that all of the above arrays are written over by the multigrid |
| 363 |
// code during processing; there is no extra storage here. |
| 364 |
// |
| 365 |
// the parameters that must be initialized in the iparm and rparm |
| 366 |
// arrays in different ways for the three methods. for example, |
| 367 |
// the multigrid code requires the following: |
| 368 |
// |
| 369 |
// *** integer parameters *** |
| 370 |
// iparm(1) = nrwk |
| 371 |
// iparm(2) = niwk |
| 372 |
// iparm(3) = nx |
| 373 |
// iparm(4) = ny |
| 374 |
// iparm(5) = nz |
| 375 |
// iparm(6) = nlev |
| 376 |
// iparm(7) = nu1 |
| 377 |
// iparm(8) = nu2 |
| 378 |
// iparm(9) = mgkey |
| 379 |
// iparm(10) = itmax |
| 380 |
// iparm(11) = istop |
| 381 |
// iparm(12) = iinfo |
| 382 |
// iparm(13) = irite |
| 383 |
// iparm(14) = ipkey |
| 384 |
// iparm(15) = ipcon |
| 385 |
// iparm(16) = nonlin |
| 386 |
// iparm(17) = mgprol |
| 387 |
// iparm(18) = mgcoar |
| 388 |
// iparm(19) = mgdisc |
| 389 |
// iparm(20) = mgsmoo |
| 390 |
// iparm(21) = mgsolv |
| 391 |
// iparm(22) = iperf |
| 392 |
// |
| 393 |
// *** real parameters *** |
| 394 |
// rparm(1) = errtol |
| 395 |
// rparm(3) = xmin |
| 396 |
// rparm(4) = xmax |
| 397 |
// rparm(5) = ymax |
| 398 |
// rparm(6) = ymax |
| 399 |
// rparm(7) = zmax |
| 400 |
// rparm(8) = zmax |
| 401 |
// rparm(9) = omegal |
| 402 |
// rparm(10) = omegan |
| 403 |
// |
| 404 |
// the following are returned from the multigrid solver: |
| 405 |
// |
| 406 |
// u = the computed solution |
| 407 |
// iparm(50) = iters (number of iters taken to reach tolerance) |
| 408 |
// iparm(51) = ierror (=0 if tolerance reached, <>0 if problems) |
| 409 |
// |
| 410 |
// author: michael holst |
| 411 |
// //////////////////////////////////////////////////////////////////////// */ |
| 412 |
|
| 413 |
/* |
| 414 |
* ********************************************************************* |
| 415 |
* parameter (ngrid=5, nrwk=2465, niwk=2000) |
| 416 |
* parameter (ngrid=9, nrwk=11885, niwk=2000) |
| 417 |
* parameter (ngrid=17, nrwk=130149, niwk=2000) |
| 418 |
* parameter (ngrid=25, nrwk=363620, niwk=2000) |
| 419 |
* parameter (ngrid=33, nrwk=837892, niwk=2000) |
| 420 |
* parameter (ngrid=49, nrwk=2827484, niwk=2000) |
| 421 |
* ********************************************************************* |
| 422 |
* parameter (ngrid=65, nrwk=3025573, niwk=2000) |
| 423 |
* parameter (ngrid=65, nrwk=3456041, niwk=2000) |
| 424 |
* parameter (ngrid=65, nrwk=6202291, niwk=2000) |
| 425 |
* ********************************************************************* |
| 426 |
* parameter (ngrid=97, nrwk=9960712, niwk=2000) |
| 427 |
* parameter (ngrid=97, nrwk=11320640, niwk=2000) |
| 428 |
* parameter (ngrid=97, nrwk=20447370, niwk=2000) |
| 429 |
* ********************************************************************* |
| 430 |
* parameter (ngrid=129, nrwk=23315466, niwk=2000) |
| 431 |
* ********************************************************************* |
| 432 |
* parameter (ngrid=193, nrwk=77735113, niwk=2000) |
| 433 |
* ********************************************************************* |
| 434 |
* parameter (ngrid=257, nrwk=183123727, niwk=2000) |
| 435 |
* ********************************************************************* |
| 436 |
* parameter (ngrid=65, nrwk=6202291, niwk=2000) |
| 437 |
* parameter (ngrid=65, nrwk=4005291, niwk=2000) |
| 438 |
* parameter (ngrid=97, nrwk=11320640, niwk=2000) |
| 439 |
* ********************************************************************* |
| 440 |
*/ |
| 441 |
|
| 442 |
#include <stdio.h> |
| 443 |
#include <stdlib.h> |
| 444 |
#include <math.h> |
| 445 |
|
| 446 |
#define TSTART tstart_ |
| 447 |
#define TSTOP tstop_ |
| 448 |
#define READIT readit_ |
| 449 |
#define WRITIT writit_ |
| 450 |
#define FILLCO fillco_ |
| 451 |
#define MGSIZE mgsize_ |
| 452 |
#define CGMGDRIV cgmgdriv_ |
| 453 |
#define NEWDRIV newdriv_ |
| 454 |
#define MGDRIV mgdriv_ |
| 455 |
#define NCGHSDRIV ncghsdriv_ |
| 456 |
#define NSORDRIV nsordriv_ |
| 457 |
#define NGSRBDRIV ngsrbdriv_ |
| 458 |
#define NWJACDRIV nwjacdriv_ |
| 459 |
#define NRICHDRIV nrichdriv_ |
| 460 |
|
| 461 |
#define NGRID 65 |
| 462 |
#define NRWK 6202291 |
| 463 |
#define NIWK 2000 |
| 464 |
#define NF (NGRID*NGRID*NGRID) |
| 465 |
#define IFUDGE 100 |
| 466 |
#define NFARR (NF+NF/6+IFUDGE) |
| 467 |
#define NXM NGRID |
| 468 |
#define NYM NGRID |
| 469 |
#define NZM NGRID |
| 470 |
|
| 471 |
int main(int argc, char **argv) |
| 472 |
{ |
| 473 |
int ngrid=NGRID; |
| 474 |
int nrwk=NRWK; |
| 475 |
int niwk=NIWK; |
| 476 |
|
| 477 |
int nxm=NXM; |
| 478 |
int nym=NYM; |
| 479 |
int nzm=NZM; |
| 480 |
int nf=NF; |
| 481 |
int ifudge=IFUDGE; |
| 482 |
int nfarr=NFARR; |
| 483 |
|
| 484 |
int nx,ny,nz,key,meth,nlev,mgcoar,mgdisc,mgsolv; |
| 485 |
int nrwk_tot,niwk_tot; |
| 486 |
int *iparm, *iwork; |
| 487 |
double *rparm, *rwork; |
| 488 |
double *a1cf, *a2cf, *a3cf, *ccf, *fcf, *tcf, *u; |
| 489 |
double *xf, *yf, *zf, *gxcf, *gycf, *gzcf; |
| 490 |
double bf,oh,cputme; |
| 491 |
|
| 492 |
iparm = (int*)calloc( 100, sizeof(int) ); |
| 493 |
rparm = (double*)calloc( 100, sizeof(double) ); |
| 494 |
|
| 495 |
iwork = (int*)calloc( NIWK, sizeof(int) ); |
| 496 |
rwork = (double*)calloc( NRWK, sizeof(double) ); |
| 497 |
|
| 498 |
a1cf = (double*)calloc( NFARR, sizeof(double) ); |
| 499 |
a2cf = (double*)calloc( NFARR, sizeof(double) ); |
| 500 |
a3cf = (double*)calloc( NFARR, sizeof(double) ); |
| 501 |
ccf = (double*)calloc( NFARR, sizeof(double) ); |
| 502 |
fcf = (double*)calloc( NFARR, sizeof(double) ); |
| 503 |
tcf = (double*)calloc( NFARR, sizeof(double) ); |
| 504 |
u = (double*)calloc( NFARR, sizeof(double) ); |
| 505 |
|
| 506 |
xf = (double*)calloc( NXM*5, sizeof(double) ); |
| 507 |
yf = (double*)calloc( NYM*5, sizeof(double) ); |
| 508 |
zf = (double*)calloc( NZM*5, sizeof(double) ); |
| 509 |
|
| 510 |
gxcf = (double*)calloc( NYM*NZM*10, sizeof(double) ); |
| 511 |
gycf = (double*)calloc( NXM*NZM*10, sizeof(double) ); |
| 512 |
gzcf = (double*)calloc( NXM*NYM*10, sizeof(double) ); |
| 513 |
|
| 514 |
TSTART(&bf,&oh); |
| 515 |
|
| 516 |
niwk_tot = 100 + niwk; |
| 517 |
nrwk_tot = 100 + nrwk + 7*nfarr + nxm*5 + nym*5 + nzm*5 |
| 518 |
+ nym*nzm*10 + nxm*nzm*10 + nxm*nym*10; |
| 519 |
|
| 520 |
fprintf(stderr,"%% ---------------------------------------------------\n"); |
| 521 |
fprintf(stderr,"%% MGMAIN: TOTAL FP STORAGE DECLARED: %d\n",nrwk_tot); |
| 522 |
fprintf(stderr,"%% MGMAIN: TOTAL INT STORAGE DECLARED: %d\n",niwk_tot); |
| 523 |
fprintf(stderr,"%% MGMAIN: max number of unknowns: %d\n",nf); |
| 524 |
fprintf(stderr,"%% MGMAIN: max vec length for all levels: %d\n",nfarr); |
| 525 |
fprintf(stderr,"%% MGMAIN: DECLARED fp work array size: %d\n",nrwk); |
| 526 |
fprintf(stderr,"%% MGMAIN: DECLARED int work array size: %d\n",niwk); |
| 527 |
fprintf(stderr,"%% ---------------------------------------------------\n"); |
| 528 |
|
| 529 |
READIT(iparm,rparm,&nx,&ny,&nz,&nlev,&nrwk,&niwk,&key,&meth); |
| 530 |
mgcoar = iparm[18]; |
| 531 |
mgdisc = iparm[19]; |
| 532 |
mgsolv = iparm[21]; |
| 533 |
MGSIZE(&mgcoar,&mgdisc,&mgsolv,&nx,&ny,&nz,&nlev); |
| 534 |
if ((nx>nxm) || (ny>nym) || (nz>nzm)) { |
| 535 |
fprintf(stderr,"%% MGMAIN: (nx,ny,nz) too large...\n"); |
| 536 |
exit(1); |
| 537 |
} |
| 538 |
|
| 539 |
FILLCO(iparm,rparm,&nx,&ny,&nz, |
| 540 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 541 |
|
| 542 |
TSTOP(&bf,&oh,&cputme); |
| 543 |
fprintf(stderr,"%% MGMAIN: time to read problem description: %g\n",cputme); |
| 544 |
|
| 545 |
TSTART(&bf,&oh); |
| 546 |
fprintf(stderr,"%% ---------------------------------------------------\n"); |
| 547 |
switch (meth) { |
| 548 |
|
| 549 |
case 0: |
| 550 |
fprintf(stderr,"%% MGMAIN: calling cgmg (linear) ... \n"); |
| 551 |
CGMGDRIV(iparm,rparm,iwork,rwork,u, |
| 552 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 553 |
break; |
| 554 |
|
| 555 |
case 1: |
| 556 |
fprintf(stderr,"%% MGMAIN: calling newton (nonlinear) ... \n"); |
| 557 |
NEWDRIV(iparm,rparm,iwork,rwork,u, |
| 558 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 559 |
break; |
| 560 |
|
| 561 |
case 2: |
| 562 |
fprintf(stderr,"%% MGMAIN: calling nmg (linear/nonlinear) ... \n"); |
| 563 |
MGDRIV(iparm,rparm,iwork,rwork,u, |
| 564 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 565 |
break; |
| 566 |
|
| 567 |
case 3: |
| 568 |
fprintf(stderr,"%% MGMAIN: calling ncg (linear/nonlinear) ... \n"); |
| 569 |
NCGHSDRIV(iparm,rparm,iwork,rwork,u, |
| 570 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 571 |
break; |
| 572 |
|
| 573 |
case 4: |
| 574 |
fprintf(stderr,"%% MGMAIN: calling nsor (linear/nonlinear) ... \n"); |
| 575 |
NSORDRIV(iparm,rparm,iwork,rwork,u, |
| 576 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 577 |
break; |
| 578 |
|
| 579 |
case 5: |
| 580 |
fprintf(stderr,"%% MGMAIN: calling ngsrb (linear/nonlinear) ... \n"); |
| 581 |
NGSRBDRIV(iparm,rparm,iwork,rwork,u, |
| 582 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 583 |
break; |
| 584 |
|
| 585 |
case 6: |
| 586 |
fprintf(stderr,"%% MGMAIN: calling nwjac (linear/nonlinear) ... \n"); |
| 587 |
NWJACDRIV(iparm,rparm,iwork,rwork,u, |
| 588 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 589 |
break; |
| 590 |
|
| 591 |
case 7: |
| 592 |
fprintf(stderr,"%% MGMAIN: calling nrich (linear/nonlinear) ... \n"); |
| 593 |
NRICHDRIV(iparm,rparm,iwork,rwork,u, |
| 594 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf); |
| 595 |
break; |
| 596 |
|
| 597 |
default: |
| 598 |
fprintf(stderr,"%% MGMAIN: bad method key ... \n"); |
| 599 |
break; |
| 600 |
} |
| 601 |
fprintf(stderr,"%% MGMAIN: returned from iterative solver.\n"); |
| 602 |
fprintf(stderr,"%% ---------------------------------------------------\n"); |
| 603 |
|
| 604 |
TSTOP(&bf,&oh,&cputme); |
| 605 |
fprintf(stderr,"%% MGMAIN: total time spent in solve: %g\n",cputme); |
| 606 |
fprintf(stderr,"%% ---------------------------------------------------\n"); |
| 607 |
|
| 608 |
WRITIT(iparm,rparm,&nx,&ny,&nz,u, |
| 609 |
xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf,&key); |
| 610 |
|
| 611 |
return 0; |
| 612 |
} |
| 613 |
|