Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

vector_operations/vops.C

Go to the documentation of this file.
00001 /*
00002   File:        pvtest.C
00003   Package:     SAMRAI test
00004   Copyright:   (c) 1997-2002 The Regents of the University of California
00005   Release:     $Name: v_0_1_7 $
00006   Revision:    $Revision: 1.1.2.2 $
00007   Modified:    $Date: 2002/04/17 19:44:56 $
00008   Description: Main program to test SAMRAI-PETSc vector interface.
00009 */
00010 
00011 #include "SAMRAI_config.h"
00012 
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include "tbox_String.h"
00016 #include "tbox_MPI.h"
00017 #include "PIO.h"
00018 #ifndef included_assert
00019 #define included_assert
00020 #include <assert.h>
00021 #endif
00022 
00023 #include "SAMRAIManager.h"
00024 
00025 #include "Box3.h"
00026 #include "BoxArray3.h"
00027 #include "BoxList3.h"
00028 #include "CartesianGridGeometry3.h"
00029 #include "CartesianPatchGeometry3.h"
00030 #include "CellIndex3.h"
00031 #include "CellData3.h"
00032 #include "CellVariable3.h"
00033 #include "FaceData3.h"
00034 #include "FaceIndex3.h"
00035 #include "FaceVariable3.h"
00036 #include "HierarchyCellDataOpsReal3.h"
00037 #include "HierarchyDataOpsManager3.h"
00038 #include "HierarchyFaceDataOpsReal3.h"
00039 #include "HierarchyNodeDataOpsReal3.h"
00040 #include "Index3.h"
00041 #include "IntVector3.h"
00042 #include "NodeData3.h"
00043 #include "NodeIndex3.h"
00044 #include "NodeVariable3.h"
00045 #include "Patch3.h"
00046 #include "PatchHierarchy3.h"
00047 #include "PatchLevel3.h"
00048 #include "PETSc_SAMRAIVectorReal3.h"
00049 #include "Pointer.h"
00050 #include "ProcessorMapping.h"
00051 #include "SAMRAIVectorReal3.h"
00052 #include "tbox_Utilities.h"
00053 #include "VariableContext.h"
00054 #include "VariableDatabase3.h"
00055 
00056 
00057 #ifndef NULL
00058 #define NULL (0)
00059 #endif
00060 
00061 #define NCELL_VARS    2
00062 #define NFACE_VARS    2
00063 #define NNODE_VARS    4
00064 
00065 #ifndef LACKS_NAMESPACE
00066 using namespace SAMRAI;
00067 #endif
00068 
00069 int main( int argc, char *argv[] ) {
00070    tbox_MPI::init(&argc, &argv);
00071    SAMRAIManager::startup();
00072    PIO::logOnlyNodeZero("pvtest.log");
00073    // PIO::logAllNodes("pvtest.log");
00074 
00075 #ifdef HAVE_PETSC
00076 //   This causes some error related to PetscTrFreeDefault when a vector
00077 //   is deleted.  So I commented it out for now.  RDH 2/17/2000.
00078 //   This problem fixed, DAH 9/19/2001.  Problem arose from the PETSc
00079 //   libs not having world readable and executable permisions.
00080 //   Also added a matching PetscFinalize, to prevent memory leaks, etc.
00081    PetscInitialize(&argc,&argv,(char *)NULL,NULL);
00082 
00083    int ln, iv;
00084 
00085    // Make a dummy hierarchy domain
00086    double lo[3] = {0.0, 0.0, 0.0};
00087    double hi[3] = {1.0, 0.5, 0.5};
00088 
00089    Box3 coarse0(Index3(0,0,0), Index3(4,2,2));
00090    Box3 coarse1(Index3(5,0,0), Index3(9,2,2));
00091    Box3 coarse2(Index3(0,0,3), Index3(4,2,4));
00092    Box3 coarse3(Index3(5,0,3), Index3(9,2,4));
00093    Box3 coarse4(Index3(0,3,0), Index3(4,4,2));
00094    Box3 coarse5(Index3(5,3,0), Index3(9,4,2));
00095    Box3 coarse6(Index3(0,3,3), Index3(4,4,4));
00096    Box3 coarse7(Index3(5,3,3), Index3(9,4,4));
00097    Box3 fine0(Index3(4,4,4), Index3(7,5,5));
00098    Box3 fine1(Index3(4,4,6), Index3(7,5,7));
00099    Box3 fine2(Index3(4,6,4), Index3(7,7,5));
00100    Box3 fine3(Index3(4,6,6), Index3(7,7,7));
00101    Box3 fine4(Index3(8,4,4), Index3(13,5,5));
00102    Box3 fine5(Index3(8,4,6), Index3(13,5,7));
00103    Box3 fine6(Index3(8,6,4), Index3(13,7,5));
00104    Box3 fine7(Index3(8,6,6), Index3(13,7,7));
00105    IntVector3 ratio(2);
00106 
00107    BoxArray3 coarse_domain(8);
00108    BoxArray3 fine_boxes(8);
00109    coarse_domain(0) = coarse0;
00110    coarse_domain(1) = coarse1;
00111    coarse_domain(2) = coarse2;
00112    coarse_domain(3) = coarse3;
00113    coarse_domain(4) = coarse4;
00114    coarse_domain(5) = coarse5;
00115    coarse_domain(6) = coarse6;
00116    coarse_domain(7) = coarse7;
00117    fine_boxes(0) = fine0;
00118    fine_boxes(1) = fine1;
00119    fine_boxes(2) = fine2;
00120    fine_boxes(3) = fine3;
00121    fine_boxes(4) = fine4;
00122    fine_boxes(5) = fine5;
00123    fine_boxes(6) = fine6;
00124    fine_boxes(7) = fine7;
00125 
00126    BoxList3 coarse_domain_list(coarse_domain);
00127    BoxList3 fine_level_list(fine_boxes);
00128    coarse_domain_list.coalesceBoxes();
00129    fine_level_list.coalesceBoxes();
00130 
00131 #ifdef DEBUG_CHECK_ASSERTIONS
00132    assert(coarse_domain_list.getNumberItems() == 1);
00133    assert(fine_level_list.getNumberItems() == 1);
00134 #endif
00135 
00136    Box3 coarse_domain_box = coarse_domain_list.getFirstItem();
00137    Box3 fine_level_box = fine_level_list.getFirstItem();
00138 
00139    Pointer<CartesianGridGeometry3> geometry =
00140       new CartesianGridGeometry3("CartesianGeometry", lo, hi, coarse_domain);
00141 
00142    Pointer<PatchHierarchy3> hierarchy = new PatchHierarchy3("PatchHierarchy",
00143                                                             geometry);
00144 
00145    // Note: For these simple tests we allow at most 2 processors.
00146    const int nproc = tbox_MPI::getNodes();
00147 #ifdef DEBUG_CHECK_ASSERTIONS
00148    assert(nproc < 3);
00149 #endif
00150    const int n_coarse_boxes = coarse_domain.getNumberOfBoxes();
00151    const int n_fine_boxes = fine_boxes.getNumberOfBoxes();
00152    ProcessorMapping mapping0(n_coarse_boxes);
00153    ProcessorMapping mapping1(n_fine_boxes);
00154 
00155    int ib;
00156    for (ib = 0; ib < n_coarse_boxes; ib++) {
00157       if (nproc > 1) {
00158          mapping0.setProcessorAssignment(ib, ib);
00159       } else {
00160          mapping0.setProcessorAssignment(ib, 0);
00161       }
00162    }
00163 
00164    for (ib = 0; ib < n_fine_boxes; ib++) {
00165       if (nproc > 1) {
00166          mapping1.setProcessorAssignment(ib, ib);
00167       } else {
00168          mapping1.setProcessorAssignment(ib, 0);
00169       }
00170    }
00171 
00172    hierarchy->makeNewPatchLevel(0, IntVector3(1), coarse_domain, mapping0);
00173    hierarchy->makeNewPatchLevel(1, ratio, fine_boxes, mapping1);
00174 
00175    // Create instance of Variable database
00176    VariableDatabase3* variable_db = VariableDatabase3::getDatabase();
00177    Pointer< VariableContext > dummy = variable_db->getContext("dummy");
00178    const IntVector3 no_ghosts(0);
00179 
00180    // Make some dummy variables and data on the hierarchy
00181    Pointer< CellVariable3<double> > cvar[NCELL_VARS];
00182    int cvindx[NCELL_VARS];
00183    cvar[0] = new CellVariable3<double>("cvar0", 2);
00184    cvindx[0] = variable_db->registerVariableAndContext(
00185       cvar[0], dummy, no_ghosts);
00186    cvar[1] = new CellVariable3<double>("cvar1", 2);
00187    cvindx[1] = variable_db->registerVariableAndContext(
00188       cvar[1], dummy, no_ghosts);
00189 
00190    Pointer< CellVariable3<double> >
00191    cwgt = new CellVariable3<double>("cwgt", 1);
00192    int cwgt_id = variable_db->registerVariableAndContext(
00193       cwgt, dummy, no_ghosts);
00194 
00195    Pointer< FaceVariable3<double> > fvar[NFACE_VARS];
00196    int fvindx[NFACE_VARS];
00197    fvar[0] = new FaceVariable3<double>("fvar0", 1);
00198    fvindx[0] = variable_db->registerVariableAndContext(
00199       fvar[0], dummy, no_ghosts);
00200    fvar[1] = new FaceVariable3<double>("fvar1", 1);
00201    fvindx[1] = variable_db->registerVariableAndContext(
00202       fvar[1], dummy, no_ghosts);
00203 
00204    Pointer< FaceVariable3<double> >
00205    fwgt = new FaceVariable3<double>("fwgt", 1);
00206    int fwgt_id = variable_db->registerVariableAndContext(
00207       fwgt, dummy, no_ghosts);
00208 
00209    Pointer< NodeVariable3<double> > nvar[NNODE_VARS];
00210    int nvindx[NNODE_VARS];
00211    nvar[0] = new NodeVariable3<double>("nvar0", 1);
00212    nvindx[0] = variable_db->registerVariableAndContext(
00213       nvar[0], dummy, no_ghosts);
00214    nvar[1] = new NodeVariable3<double>("nvar1", 1);
00215    nvindx[1] = variable_db->registerVariableAndContext(
00216       nvar[1], dummy, no_ghosts);
00217    nvar[2] = new NodeVariable3<double>("nvar2", 1);
00218    nvindx[2] = variable_db->registerVariableAndContext(
00219       nvar[2], dummy, no_ghosts);
00220    nvar[3] = new NodeVariable3<double>("nvar3", 1);
00221    nvindx[3] = variable_db->registerVariableAndContext(
00222       nvar[3], dummy, no_ghosts);
00223 
00224    Pointer< NodeVariable3<double> > 
00225    nwgt = new NodeVariable3<double>("nwgt", 1);
00226    int nwgt_id = variable_db->registerVariableAndContext(
00227       nwgt, dummy, no_ghosts);
00228 
00229    for (ln = 0; ln < 2; ln++) {
00230       hierarchy->getPatchLevel(ln)->allocatePatchData(cwgt_id);
00231       hierarchy->getPatchLevel(ln)->allocatePatchData(fwgt_id);
00232       hierarchy->getPatchLevel(ln)->allocatePatchData(nwgt_id);
00233    }
00234 
00235    Pointer< HierarchyCellDataOpsReal3<double> > cell_ops = 
00236    HierarchyDataOpsManager3::getManager()->getOperationsDouble(cwgt, 
00237                                                                hierarchy);
00238    Pointer< HierarchyFaceDataOpsReal3<double> > face_ops = 
00239    HierarchyDataOpsManager3::getManager()->getOperationsDouble(fwgt,
00240                                                                hierarchy);
00241    Pointer< HierarchyNodeDataOpsReal3<double> > node_ops = 
00242    HierarchyDataOpsManager3::getManager()->getOperationsDouble(nwgt,
00243                                                                hierarchy);
00244 
00245    cell_ops->resetLevels(0,1); 
00246    face_ops->resetLevels(0,1); 
00247    node_ops->resetLevels(0,1); 
00248 
00249    Pointer<Patch3> patch;
00250    Pointer<CartesianPatchGeometry3> pgeom;
00251    Pointer< CellData3<double> > cdata; 
00252    Pointer< FaceData3<double> > fdata; 
00253    Pointer< NodeData3<double> > ndata; 
00254 
00255    // Set control volume data for vector components
00256    Box3 coarse_fine = fine_level_box;
00257    coarse_fine.coarsen(ratio);
00258 
00259    // Initialize control volume data for cell-centered components
00260 
00261    for (ln = 0; ln < 2; ln++) {
00262       for (PatchLevel3::Iterator ip(hierarchy->getPatchLevel(ln)); ip; ip++) {
00263          patch = hierarchy->getPatchLevel(ln)->getPatch(ip());
00264          pgeom = patch->getPatchGeometry();
00265          const double* dx = pgeom->getDx();
00266          const double cell_vol = dx[0]*dx[1]*dx[2];
00267          Pointer< CellData3<double> > cvdata = patch->getPatchData(cwgt_id);
00268          cvdata->fillAll(cell_vol);
00269          if (ln == 0) cvdata->fillAll(0.0, (coarse_fine * patch->getBox()) );
00270       }
00271    }
00272 
00273    // Initialize control volume data for face-centered components
00274    for (ln = 0; ln < 2; ln++) {
00275       for (PatchLevel3::Iterator ip(hierarchy->getPatchLevel(ln)); ip; ip++) {
00276          Pointer< FaceData3<double> > data;
00277          patch = hierarchy->getPatchLevel(ln)->getPatch(ip());
00278          pgeom = patch->getPatchGeometry();
00279          const double* dx = pgeom->getDx();
00280          const double face_vol = dx[0]*dx[1]*dx[2];
00281          data = patch->getPatchData(fwgt_id);
00282          data->fillAll(face_vol);
00283          FaceIndex3 fi;
00284          int plo0 = patch->getBox().lower(0);
00285          int phi0 = patch->getBox().upper(0);
00286          int plo1 = patch->getBox().lower(1);
00287          int phi1 = patch->getBox().upper(1);
00288          int plo2 = patch->getBox().lower(2);
00289          int phi2 = patch->getBox().upper(2);
00290          int ic, jc, kc;
00291          double bdry_face_factor;
00292          Box3 level_box;
00293  
00294          if (ln == 0) {
00295             data->fillAll(0.0, (coarse_fine * patch->getBox()) );
00296             bdry_face_factor = 0.5;
00297             level_box = coarse_domain_box;
00298          } else {
00299             bdry_face_factor = 1.5;
00300             level_box = fine_level_box; 
00301          }
00302          //X face boundaries
00303          if (plo0 == level_box.lower(0)) {
00304             for (kc = plo2; kc <= phi2; kc++) {
00305                for (jc = plo1; jc <= phi1; jc++) {
00306                   fi = FaceIndex3(Index3(plo0,jc,kc),
00307                                   FaceIndex3::X,
00308                                   FaceIndex3::Lower);
00309                   (*data)(fi) *= bdry_face_factor;
00310                }
00311             }
00312          } else {
00313             for (kc = plo2; kc <= phi2; kc++) {
00314                for (jc = plo1; jc <= phi1; jc++) {
00315                   fi = FaceIndex3(Index3(plo0,jc,kc),
00316                                   FaceIndex3::X,
00317                                   FaceIndex3::Lower);
00318                   (*data)(fi) = 0.0;
00319                }
00320             }
00321          }
00322          if (phi0 == level_box.upper(0)) {
00323              for (kc = plo2; kc <= phi2; kc++) {
00324                for (jc = plo1; jc <= phi1; jc++) {
00325                   fi = FaceIndex3(Index3(phi0,jc,kc),
00326                                   FaceIndex3::X,
00327                                   FaceIndex3::Upper);
00328                   (*data)(fi) *= bdry_face_factor;
00329                }
00330             }
00331          }
00332 
00333          //Y face boundaries
00334          if (plo1 == level_box.lower(1)) {
00335             for (kc = plo2; kc <= phi2; kc++) {
00336                for (ic = plo0; ic <= phi0; ic++) {
00337                   fi = FaceIndex3(Index3(ic,plo1,kc),
00338                                   FaceIndex3::Y,
00339                                   FaceIndex3::Lower);
00340                   (*data)(fi) *= bdry_face_factor;
00341                }
00342             }
00343          } else {
00344             for (kc = plo2; kc <= phi2; kc++) {
00345                for (ic = plo0; ic <= phi0; ic++) {
00346                   fi = FaceIndex3(Index3(ic,plo1,kc),
00347                                   FaceIndex3::Y,
00348                                   FaceIndex3::Lower);
00349                   (*data)(fi) = 0.0;
00350                }
00351             }
00352          }
00353          if (phi1 == level_box.upper(1)) {
00354              for (kc = plo2; kc <= phi2; kc++) {
00355                for (ic = plo0; ic <= phi0; ic++) {
00356                   fi = FaceIndex3(Index3(ic,phi1,kc),
00357                                   FaceIndex3::Y,
00358                                   FaceIndex3::Upper);
00359                   (*data)(fi) *= bdry_face_factor;
00360                }
00361             }
00362          }
00363 
00364          //Z face boundaries
00365          if (plo2 == level_box.lower(2)) {
00366             for (jc = plo1; jc <= phi1; jc++) {
00367                for (ic = plo0; ic <= phi0; ic++) {
00368                   fi = FaceIndex3(Index3(ic,jc,plo2),
00369                                   FaceIndex3::Z,
00370                                   FaceIndex3::Lower);
00371                   (*data)(fi) *= bdry_face_factor;
00372                }
00373             }
00374          } else {
00375             for (jc = plo1; jc <= phi1; jc++) {
00376                for (ic = plo0; ic <= phi0; ic++) {
00377                   fi = FaceIndex3(Index3(ic,jc,plo2),
00378                                   FaceIndex3::Z,
00379                                   FaceIndex3::Lower);
00380                   (*data)(fi) = 0.0;
00381                }
00382             }
00383          }
00384          if (phi2 == level_box.upper(2)) {
00385              for (jc = plo1; jc <= phi1; jc++) {
00386                for (ic = plo0; ic <= phi0; ic++) {
00387                   fi = FaceIndex3(Index3(ic,jc,phi2),
00388                                   FaceIndex3::Z,
00389                                   FaceIndex3::Upper);
00390                   (*data)(fi) *= bdry_face_factor;
00391                }
00392             }
00393          }
00394       }
00395    }
00396 
00397    for (ln = 0; ln < 2; ln++) {
00398       for (PatchLevel3::Iterator ip(hierarchy->getPatchLevel(ln)); ip; ip++) {
00399          Pointer< NodeData3<double> > data;
00400          patch = hierarchy->getPatchLevel(ln)->getPatch(ip());
00401          pgeom = patch->getPatchGeometry();
00402          const double* dx = pgeom->getDx();
00403          const double node_vol = dx[0]*dx[1]*dx[2];
00404          data = patch->getPatchData(nwgt_id);
00405          data->fillAll(node_vol);
00406          NodeIndex3 ni;
00407          Index3 plo = patch->getBox().lower();
00408          Index3 phi = patch->getBox().upper();
00409          int ic,jc,kc;
00410          double bdry_face_factor;
00411          double bdry_edge_factor;
00412          double bdry_node_factor;
00413          Box3 level_box;
00414   
00415          if (ln == 0) {
00416             data->fillAll(0.0, (coarse_fine * patch->getBox()) );
00417             bdry_face_factor = 0.5;
00418             bdry_edge_factor = 0.25;
00419             bdry_node_factor = 0.125;
00420             level_box = coarse_domain_box;
00421          } else {
00422             bdry_face_factor = 1.5;
00423             bdry_edge_factor = 2.25;
00424             bdry_node_factor = 3.375;
00425             level_box = fine_level_box;
00426          }
00427 
00428          //X faces
00429          if (plo(0) == level_box.lower(0)) {
00430             for (kc = plo(2); kc < phi(2); kc++) {
00431                for (jc = plo(1); jc < phi(1); jc++) {
00432                   ni = NodeIndex3(Index3(plo(0),jc,kc), NodeIndex3::LUU);
00433                   (*data)(ni) *= bdry_face_factor;
00434                }
00435             }
00436          } else {
00437             for (kc = plo(2); kc < phi(2); kc++) {
00438                for (jc = plo(1); jc < phi(1); jc++) {
00439                   ni = NodeIndex3(Index3(plo(0),jc,kc), NodeIndex3::LUU);
00440                   (*data)(ni) = 0.0;
00441                }
00442             }
00443          }
00444             if (phi(0) == level_box.upper(0)) {
00445             for (kc = plo(2); kc < phi(2); kc++) {
00446                for (jc = plo(1); jc < phi(1); jc++) {
00447                   ni = NodeIndex3(Index3(phi(0),jc,kc), NodeIndex3::UUU);
00448                   (*data)(ni) *= bdry_face_factor;
00449                }
00450             }
00451          }
00452 
00453          //Y faces
00454          if (plo(1) == level_box.lower(1)) {
00455             for (kc = plo(2); kc < phi(2); kc++) {
00456                for (ic = plo(0); ic < phi(0); ic++) {
00457                   ni = NodeIndex3(Index3(ic,plo(1),kc), NodeIndex3::ULU);
00458                   (*data)(ni) *= bdry_face_factor;
00459                }
00460             }
00461          } else {
00462             for (kc = plo(2); kc < phi(2); kc++) {
00463                for (ic = plo(0); ic < phi(0); ic++) {
00464                   ni = NodeIndex3(Index3(ic,plo(1),kc), NodeIndex3::ULU);
00465                   (*data)(ni) = 0.0;
00466                }
00467             }
00468          }
00469          if (phi(1) == level_box.upper(1)) {
00470             for (kc = plo(2); kc < phi(2); kc++) {
00471                for (ic = plo(0); ic < phi(0); ic++) {
00472                   ni = NodeIndex3(Index3(ic,phi(1),kc), NodeIndex3::UUU);
00473                   (*data)(ni) *= bdry_face_factor;
00474                }
00475             }
00476          }
00477 
00478          //Z faces
00479          if (plo(2) == level_box.lower(2)) {
00480             for (jc = plo(1); jc < phi(1); jc++) {
00481                for (ic = plo(0); ic < phi(0); ic++) {
00482                   ni = NodeIndex3(Index3(ic,jc,plo(2)), NodeIndex3::UUL);
00483                   (*data)(ni) *= bdry_face_factor;
00484                }
00485             }
00486          } else {
00487             for (jc = plo(1); jc < phi(1); jc++) {
00488                for (ic = plo(0); ic < phi(0); ic++) {
00489                   ni = NodeIndex3(Index3(ic,jc,plo(2)), NodeIndex3::UUL);
00490                   (*data)(ni) = 0.0;
00491                }
00492             }
00493          }
00494          if (phi(2) == level_box.upper(2)) {
00495             for (jc = plo(1); jc < phi(1); jc++) {
00496                for (ic = plo(0); ic < phi(0); ic++) {
00497                   ni = NodeIndex3(Index3(ic,jc,phi(2)), NodeIndex3::UUU);
00498                   (*data)(ni) *= bdry_face_factor;
00499                }
00500             }
00501          }
00502 
00503          // edge boundaries
00504          for (ic = plo(0); ic < phi(0); ic++) {
00505             ni = NodeIndex3(Index3(ic,plo(1),plo(2)), NodeIndex3::ULL);
00506             if (plo(1) == level_box.lower(1)) {
00507                if (plo(2) == level_box.lower(2)) {
00508                   (*data)(ni) *= bdry_edge_factor;
00509                } else {
00510                   (*data)(ni) = 0.0;
00511                }
00512             } else {
00513                (*data)(ni) = 0.0;
00514             }
00515             ni = NodeIndex3(Index3(ic,phi(1),plo(2)), NodeIndex3::UUL);
00516             if (phi(1) == level_box.upper(1)) {
00517                if (plo(2) == level_box.lower(2)) {
00518                   (*data)(ni) *= bdry_edge_factor;
00519                } else {
00520                   (*data)(ni) = 0.0;
00521                }
00522             } else {
00523                if (plo(2) == level_box.lower(2)) {
00524                   (*data)(ni) *= bdry_face_factor;
00525                } else { 
00526                   (*data)(ni) *= 0.0;
00527                }
00528             }
00529             ni = NodeIndex3(Index3(ic,plo(1),phi(2)), NodeIndex3::ULU);
00530             if (plo(1) == level_box.lower(1)) {
00531                if (phi(2) == level_box.upper(2)) {
00532                   (*data)(ni) *= bdry_edge_factor;
00533                } else {
00534                   (*data)(ni) *= bdry_face_factor;
00535                }
00536             } else {
00537                (*data)(ni) = 0.0;
00538             }
00539             ni = NodeIndex3(Index3(ic,phi(1),phi(2)), NodeIndex3::UUU);
00540             if (phi(1) == level_box.upper(1)) {
00541                if (phi(2) == level_box.upper(2)) {
00542                   (*data)(ni) *= bdry_edge_factor;
00543                } else {
00544                   (*data)(ni) *= bdry_face_factor;
00545                }
00546             } else {
00547                if (phi(2) == level_box.upper(2)) {
00548                   (*data)(ni) *= bdry_face_factor;
00549                }
00550             }
00551          }
00552 
00553          for (jc = plo(1); jc < phi(1); jc++) {
00554             ni = NodeIndex3(Index3(plo(0),jc,plo(2)), NodeIndex3::LUL);
00555             if (plo(0) == level_box.lower(0)) {
00556                if (plo(2) == level_box.lower(2)) {
00557                   (*data)(ni) *= bdry_edge_factor;
00558                } else {
00559                   (*data)(ni) = 0.0;
00560                }
00561             } else {
00562                (*data)(ni) = 0.0;
00563             }
00564             ni = NodeIndex3(Index3(phi(0),jc,plo(2)), NodeIndex3::UUL);
00565             if (phi(0) == level_box.upper(0)) {
00566                if (plo(2) == level_box.lower(2)) {
00567                   (*data)(ni) *= bdry_edge_factor;
00568                } else {
00569                   (*data)(ni) = 0.0;
00570                }
00571             } else {
00572                if (plo(2) == level_box.lower(2)) {
00573                   (*data)(ni) *= bdry_face_factor;
00574                } else { 
00575                   (*data)(ni) *= 0.0;
00576                }
00577             }
00578             ni = NodeIndex3(Index3(plo(0),jc,phi(2)), NodeIndex3::LUU);
00579             if (plo(0) == level_box.lower(0)) {
00580                if (phi(2) == level_box.upper(2)) {
00581                   (*data)(ni) *= bdry_edge_factor;
00582                } else {
00583                   (*data)(ni) *= bdry_face_factor;
00584                }
00585             } else {
00586                (*data)(ni) = 0.0;
00587             }
00588             ni = NodeIndex3(Index3(phi(0),jc,phi(2)), NodeIndex3::UUU);
00589             if (phi(0) == level_box.upper(0)) {
00590                if (phi(2) == level_box.upper(2)) {
00591                   (*data)(ni) *= bdry_edge_factor;
00592                } else {
00593                   (*data)(ni) *= bdry_face_factor;
00594                }
00595             } else {
00596                if (phi(2) == level_box.upper(2)) {
00597                   (*data)(ni) *= bdry_face_factor;
00598                }
00599             }
00600          }
00601 
00602          for (kc = plo(2); kc < phi(2); kc++) {
00603             ni = NodeIndex3(Index3(plo(0),plo(1),kc), NodeIndex3::LLU);
00604             if (plo(0) == level_box.lower(0)) {
00605                if (plo(1) == level_box.lower(1)) {
00606                   (*data)(ni) *= bdry_edge_factor;
00607                } else {
00608                   (*data)(ni) = 0.0;
00609                }
00610             } else {
00611                (*data)(ni) = 0.0;
00612             }
00613             ni = NodeIndex3(Index3(phi(0),plo(1),kc), NodeIndex3::ULU);
00614             if (phi(0) == level_box.upper(0)) {
00615                if (plo(1) == level_box.lower(1)) {
00616                   (*data)(ni) *= bdry_edge_factor;
00617                } else {
00618                   (*data)(ni) = 0.0;
00619                }
00620             } else {
00621                if (plo(1) == level_box.lower(1)) {
00622                   (*data)(ni) *= bdry_face_factor;
00623                } else { 
00624                   (*data)(ni) *= 0.0;
00625                }
00626             }
00627             ni = NodeIndex3(Index3(plo(0),phi(1),kc), NodeIndex3::LUU);
00628             if (plo(0) == level_box.lower(0)) {
00629                if (phi(1) == level_box.upper(1)) {
00630                   (*data)(ni) *= bdry_edge_factor;
00631                } else {
00632                   (*data)(ni) *= bdry_face_factor;
00633                }
00634             } else {
00635                (*data)(ni) = 0.0;
00636             }
00637             ni = NodeIndex3(Index3(phi(0),phi(1),kc), NodeIndex3::UUU);
00638             if (phi(0) == level_box.upper(0)) {
00639                if (phi(1) == level_box.upper(1)) {
00640                   (*data)(ni) *= bdry_edge_factor;
00641                } else {
00642                   (*data)(ni) *= bdry_face_factor;
00643                }
00644             } else {
00645                if (phi(1) == level_box.upper(1)) {
00646                   (*data)(ni) *= bdry_face_factor;
00647                }
00648             }
00649          }
00650 
00651          //corner boundaries
00652          ni = NodeIndex3(Index3(plo(0),plo(1),plo(2)), NodeIndex3::LLL);
00653          if (plo(0) == level_box.lower(0)) {
00654             if (plo(1) == level_box.lower(1)) {
00655                if (plo(2) == level_box.lower(2)) {
00656                   (*data)(ni) *= bdry_node_factor;
00657                } else {
00658                   (*data)(ni) = 0.0;
00659                }
00660             } else {
00661                (*data)(ni) = 0.0;
00662             }
00663          } else {
00664             (*data)(ni) = 0.0;
00665          }
00666 
00667          ni = NodeIndex3(Index3(plo(0),plo(1),phi(2)), NodeIndex3::LLU);
00668          if (plo(0) == level_box.lower(0)) {
00669             if (plo(1) == level_box.lower(1)) {
00670                if (phi(2) == level_box.upper(2)) {
00671                   (*data)(ni) *= bdry_node_factor;
00672                } else {
00673                   (*data)(ni) *= bdry_edge_factor;
00674                }
00675             } else {
00676                (*data)(ni) = 0.0;
00677             }
00678          } else {
00679             (*data)(ni) = 0.0;
00680          }
00681 
00682          ni = NodeIndex3(Index3(plo(0),phi(1),plo(2)), NodeIndex3::LUL);
00683          if (plo(0) == level_box.lower(0)) {
00684             if (phi(1) == level_box.upper(1)) {
00685                if (plo(2) == level_box.lower(2)) {
00686                   (*data)(ni) *= bdry_node_factor;
00687                } else {
00688                   (*data)(ni) = 0.0;
00689                }
00690             } else {
00691                if (plo(2) == level_box.lower(2)) {
00692                   (*data)(ni) *= bdry_edge_factor;
00693                } else {
00694                   (*data)(ni) = 0.0;
00695                }
00696             }
00697          } else {
00698             (*data)(ni) = 0.0;
00699          }
00700 
00701          ni = NodeIndex3(Index3(plo(0),phi(1),phi(2)), NodeIndex3::LUU);
00702          if (plo(0) == level_box.lower(0)) {
00703             if (phi(1) == level_box.upper(1)) {
00704                if (phi(2) == level_box.upper(2)) {
00705                   (*data)(ni) *= bdry_node_factor;
00706                } else {
00707                   (*data)(ni) *= bdry_edge_factor;
00708                }
00709             } else {
00710                if (phi(2) == level_box.upper(2)) {
00711                   (*data)(ni) *= bdry_edge_factor;
00712                } else {
00713                   (*data)(ni) *= bdry_face_factor;
00714                }
00715             }
00716          } else {
00717             (*data)(ni) = 0.0;
00718          }
00719 
00720          ni = NodeIndex3(Index3(phi(0),plo(1),plo(2)), NodeIndex3::ULL);
00721          if (phi(0) == level_box.upper(0)) {
00722             if (plo(1) == level_box.lower(1)) {
00723                if (plo(2) == level_box.lower(2)) {
00724                   (*data)(ni) *= bdry_node_factor;
00725                } else {
00726                   (*data)(ni) *= 0.0;
00727                }
00728             } else {
00729                (*data)(ni) = 0.0;
00730             }
00731          } else {
00732             if (plo(1) == level_box.lower(1)) {
00733                if (plo(2) == level_box.lower(2)) {
00734                   (*data)(ni) *= bdry_edge_factor;
00735                } else {
00736                   (*data)(ni) = 0.0;
00737                }
00738             } else {
00739                (*data)(ni) = 0.0;
00740             }
00741          }
00742 
00743          ni = NodeIndex3(Index3(phi(0),plo(1),phi(2)), NodeIndex3::ULU);
00744          if (phi(0) == level_box.upper(0)) {
00745             if (plo(1) == level_box.lower(1)) {
00746                if (phi(2) == level_box.upper(2)) {
00747                   (*data)(ni) *= bdry_node_factor;
00748                } else {
00749                   (*data)(ni) *= bdry_edge_factor;
00750                }
00751             } else {
00752                (*data)(ni) = 0.0;
00753             }
00754          } else {
00755             if (plo(1) == level_box.lower(1)) {
00756                if (phi(2) == level_box.upper(2)) {
00757                   (*data)(ni) *= bdry_edge_factor;
00758                } else {
00759                   (*data)(ni) *= bdry_face_factor;
00760                }
00761             } else {
00762                (*data)(ni) = 0.0;
00763             }
00764          }
00765 
00766          ni = NodeIndex3(Index3(phi(0),phi(1),plo(2)), NodeIndex3::UUL);
00767          if (phi(0) == level_box.upper(0)) {
00768             if (phi(1) == level_box.upper(1)) {
00769                if (plo(2) == level_box.lower(2)) {
00770                   (*data)(ni) *= bdry_node_factor;
00771                } else {
00772                   (*data)(ni) = 0.0;
00773                }
00774             } else {
00775                if (plo(2) == level_box.lower(2)) {
00776                   (*data)(ni) *= bdry_edge_factor;
00777                } else {
00778                   (*data)(ni) = 0.0;
00779                }
00780             }
00781          } else {
00782             if (phi(1) == level_box.upper(1)) {
00783                if (plo(2) == level_box.lower(2)) {
00784                   (*data)(ni) *= bdry_edge_factor;
00785                } else {
00786                   (*data)(ni) = 0.0;
00787                }
00788             } else {
00789                if (plo(2) == level_box.lower(2)) {
00790                   (*data)(ni) *= bdry_face_factor;
00791                } else {
00792                   (*data)(ni) = 0.0;
00793                }
00794             }
00795          }
00796 
00797          ni = NodeIndex3(Index3(phi(0),phi(1),phi(2)), NodeIndex3::UUU);
00798          if (phi(0) == level_box.upper(0)) {
00799             if (phi(1) == level_box.upper(1)) {
00800                if (phi(2) == level_box.upper(2)) {
00801                   (*data)(ni) *= bdry_node_factor;
00802                } else {
00803                   (*data)(ni) *= bdry_edge_factor;
00804                }
00805             } else {
00806                if (phi(2) == level_box.upper(2)) {
00807                   (*data)(ni) *= bdry_edge_factor;
00808                } else {
00809                   (*data)(ni) *= bdry_face_factor;
00810                }
00811             }
00812          } else {
00813             if (phi(1) == level_box.upper(1)) {
00814                if (phi(2) == level_box.upper(2)) {
00815                   (*data)(ni) *= bdry_edge_factor;
00816                } else {
00817                   (*data)(ni) *= bdry_face_factor;
00818                }
00819             } else {
00820                if (phi(2) == level_box.upper(2)) {
00821                   (*data)(ni) *= bdry_face_factor;
00822                }
00823             }
00824          }
00825       }
00826    }
00827 
00828    // Create SAMRAI vectors:
00829    // Each vector has four components (1 cell component with depth = 2,
00830    // 1 face component with depth = 1, and 2 node components with depth = 1). 
00831    Pointer< SAMRAIVectorReal3<double> > my_vec0 = 
00832       new SAMRAIVectorReal3<double>("my_vec0", hierarchy, 0, 1);
00833    my_vec0->addComponent(cvar[0], cvindx[0], cwgt_id); 
00834    my_vec0->addComponent(fvar[0], fvindx[0], fwgt_id); 
00835    my_vec0->addComponent(nvar[0], nvindx[0], nwgt_id); 
00836    my_vec0->addComponent(nvar[1], nvindx[1], nwgt_id); 
00837 
00838    Pointer< SAMRAIVectorReal3<double> > my_vec1 = 
00839       new SAMRAIVectorReal3<double>("my_vec1", hierarchy, 0, 1);
00840    my_vec1->addComponent(cvar[1], cvindx[1], cwgt_id);
00841    my_vec1->addComponent(fvar[1], fvindx[1], fwgt_id);
00842    my_vec1->addComponent(nvar[2], nvindx[2], nwgt_id);
00843    my_vec1->addComponent(nvar[3], nvindx[3], nwgt_id);
00844 
00845    my_vec0->allocateVectorData();
00846    my_vec1->allocateVectorData();
00847 
00848 
00849    // Print out control volume data and compute integrals...
00850  
00851    plog << "cell control volume data" << endl;
00852    cell_ops->printData(cwgt_id, plog);
00853    plog << "face control volume data" << endl;
00854    face_ops->printData(fwgt_id, plog);
00855    plog << "node control volume data" << endl;
00856    node_ops->printData(nwgt_id, plog);
00857 
00858    double norm;
00859    //pout << "sum of each control volume is " << endl;
00860 
00861    norm = cell_ops->sumControlVolumes(cvindx[0], cwgt_id);
00862    if (!tbox_Utilities::deq(norm,(double)0.5)) {
00863       plog << "FAILED - Test #1, norm != 0.5\n";
00864    }
00865    //pout << "Component 0 : " << norm << " = 0.5?" << endl;
00866 
00867    norm = face_ops->sumControlVolumes(fvindx[0], fwgt_id);
00868    if (!tbox_Utilities::deq(norm,(double)0.75)) {
00869       plog << "FAILED - Test #2, norm != 0.75\n";
00870    }
00871    //pout << "Component 1 : " << norm << " = 0.75?" << endl;
00872 
00873    norm = node_ops->sumControlVolumes(nvindx[0], nwgt_id);
00874    if (!tbox_Utilities::deq(norm,(double)0.25)) {
00875       plog << "FAILED - Test #3, norm != 0.25\n";
00876    }
00877    //pout << "Component 2 : " << norm << " = 0.25?" << endl;
00878 
00879    norm = node_ops->sumControlVolumes(nvindx[1], nwgt_id);
00880    if (!tbox_Utilities::deq(norm,(double)0.25)) {
00881       plog << "FAILED - Test #4, norm != 0.25\n";
00882    }
00883    //pout << "Component 3 : " << norm << " = 0.25?\n" << endl;
00884 
00885    // Simple tests of SAMRAI vector operations
00886 
00887    // Construct SAMRAI vector wrappers to test operations via PETSc calls
00888    Vec pvec0 = PETSc_SAMRAIVectorReal3<double>::createPETScVector(my_vec0);
00889    Vec pvec1 = PETSc_SAMRAIVectorReal3<double>::createPETScVector(my_vec1);
00890 
00891    double zero = 0.0; 
00892    double half = 0.5; 
00893    double one = 1.0; 
00894    double two = 2.0; 
00895    double three = 3.0; 
00896    double four = 4.0; 
00897    double twelve = 12.0; 
00898 
00899    // my_vec0 = 2.0
00900    my_vec0->setToScalar(2.0);
00901    VecView(pvec0, ((PetscViewer)NULL));
00902 
00903    double my_norm;
00904    double p_norm;
00905    double l1_norm;
00906    my_norm = my_vec0->L1Norm();
00907    //pout << "L1-norm of my_vec0 is " << norm << " = 6.0?\n" << endl;
00908    VecNorm(pvec0, NORM_1, &p_norm);
00909    //pout << "L1-norm of pvec0 is " << norm << " = 6.0?\n" << endl;
00910    if (!tbox_Utilities::deq(my_norm, p_norm)) {
00911       plog << "FAILED - Test #5, L1-norm calculation\n";
00912    }
00913    l1_norm = my_norm;
00914 
00915    double l2_norm;
00916    my_norm = my_vec0->L2Norm();
00917    //pout << "L2-norm of my_vec0 is " << norm << " = 3.4641016?\n" << endl;
00918    VecNorm(pvec0, NORM_2, &p_norm);
00919    //pout << "L2-norm of pvec0 is " << norm << " = 3.4641016?\n" << endl;
00920    if (!tbox_Utilities::deq(my_norm, p_norm)) {
00921       plog << "FAILED - Test #6, L2-norm calculation\n";
00922    }
00923    l2_norm = my_norm;
00924 
00925    double both_norms[2];
00926    VecNorm(pvec0, NORM_1_AND_2, both_norms);
00927    if (!tbox_Utilities::deq(both_norms[0], l1_norm)) {
00928       plog << "FAILED - Test #7, both norms calculation, L1-norm\n";
00929    }
00930    if (!tbox_Utilities::deq(both_norms[1], l2_norm)) {
00931       plog << "FAILED - Test #8, both norms calculation, L2-norm\n";
00932    }
00933    //pout << "Both norms of pvec0: " << both_norms[0] << " and " 
00934    //                                << both_norms[1] << "\n" << endl;
00935  
00936    // Set fine data in my_vec0 = 3.0
00937    cell_ops->resetLevels(1,1);
00938    face_ops->resetLevels(1,1);
00939    node_ops->resetLevels(1,1);
00940    cell_ops->setToScalar(cvindx[0], 3.0);
00941    face_ops->setToScalar(fvindx[0], 3.0);
00942    node_ops->setToScalar(nvindx[0], 3.0);
00943    node_ops->setToScalar(nvindx[1], 3.0);
00944 
00945    plog << "CHECK my_vec0" << endl;
00946    my_vec0->print(plog); 
00947 
00948    double my_min_val = my_vec0->min();
00949  
00950    int dummy1;
00951    double p_min_val;
00952    VecMin(pvec0, &dummy1, &p_min_val);
00953    double min_val;
00954    VecMin(pvec0, &dummy1, &min_val);
00955    plog << "min of pvec0 is " << min_val << " = 2.0?\n" << endl; 
00956    if (!tbox_Utilities::deq(my_min_val, p_min_val)) {
00957       plog << "FAILED - Test #9, min val calculation\n";
00958    }
00959 
00960    // my_vec1 = 1/my_vec0
00961    my_vec1->reciprocal(my_vec0);
00962 
00963    double my_max_val = my_vec1->max();
00964 
00965    double p_max_val;
00966    VecMax(pvec1, &dummy1, &p_max_val);
00967    if (!tbox_Utilities::deq(my_max_val, p_max_val)) {
00968       plog << "FAILED - Test #10, reciprocal max val calculation\n";
00969    }
00970 
00971    // Manipulate patch data on vector and test norms
00972 
00973    // Set some bogus values on Level in my_vec1 that should be masked out
00974    // in ensuing vector norm calculations
00975 
00976    for (PatchLevel3::Iterator ip(hierarchy->getPatchLevel(0)); ip; ip++) {
00977       patch = hierarchy->getPatchLevel(0)->getPatch(ip());
00978 
00979       cdata = patch->getPatchData(cvindx[1]);
00980       Index3 cindex0(2,2,2);
00981       Index3 cindex1(5,3,2);
00982       Index3 cindex2(4,2,2);
00983       Index3 cindex3(6,3,2);
00984       if (patch->getBox().contains(cindex0)) {
00985          (*cdata)(CellIndex3(cindex0), 0) = 100.0;
00986       }
00987       if (patch->getBox().contains(cindex1)) {
00988          (*cdata)(CellIndex3(cindex1), 0) = -1000.0;
00989       }
00990       if (patch->getBox().contains(cindex2)) {
00991          (*cdata)(CellIndex3(cindex2), 1) = 1100.0;
00992       }
00993       if (patch->getBox().contains(cindex3)) {
00994          (*cdata)(CellIndex3(cindex3), 1) = -10.0;
00995       }
00996 
00997       fdata = patch->getPatchData(fvindx[1]);
00998       Index3 findex0(2,2,2);
00999       Index3 findex1(5,3,2);
01000       if (patch->getBox().contains(findex0)) {
01001          (*fdata)
01002             (FaceIndex3(findex0, FaceIndex3::X, FaceIndex3::Lower)) = 200.0;
01003       }
01004       if (patch->getBox().contains(findex1)) {
01005          (*fdata)
01006             (FaceIndex3(findex1,FaceIndex3::Y,FaceIndex3::Upper)) = -2000.0;
01007       }
01008 
01009       Index3 nindex0(2,2,2);
01010       Index3 nindex1(5,3,2);
01011       if (patch->getBox().contains(nindex0)) {
01012          ndata = patch->getPatchData(nvindx[2]);
01013          (*ndata)(NodeIndex3(nindex0, NodeIndex3::LLL)) = 300.0;
01014          ndata = patch->getPatchData(nvindx[3]);
01015          (*ndata)(NodeIndex3(nindex0, NodeIndex3::LUL)) = 30.0;
01016       }
01017       if (patch->getBox().contains(nindex1)) {
01018          ndata = patch->getPatchData(nvindx[2]);
01019          (*ndata)(NodeIndex3(nindex1, NodeIndex3::UUL)) = -300.0;
01020          ndata = patch->getPatchData(nvindx[3]);
01021          (*ndata)(NodeIndex3(nindex1, NodeIndex3::ULL)) = -3300.0;
01022       }
01023    }
01024 
01025    plog << "my_vec1 = 0.5 (& bogus values) on L0, = 0.3333 on L1?" << endl; 
01026    my_vec1->print(plog);
01027 
01028    double max_val = my_vec1->max();
01029    if (!tbox_Utilities::deq(max_val, (double)1100.0)) {
01030       plog << "FAILED - Test #11, max bogus value\n";
01031    }
01032 
01033    min_val = my_vec1->min();
01034    if (!tbox_Utilities::deq(min_val, (double)-3300.0)) {
01035       plog << "FAILED - Test #12, min bogus value\n";
01036    }
01037 
01038    my_norm = my_vec1->L2Norm();
01039    VecNorm(pvec1, NORM_2, &p_norm);
01040    if (!tbox_Utilities::deq(my_norm, p_norm)) {
01041       plog << "FAILED - Test #13, L2-norm calculation\n";
01042    }
01043 
01044    double my_dot = my_vec1->dot(my_vec1);
01045 
01046    double p_dot;
01047    VecDot(pvec1, pvec1, &p_dot);
01048    if (!tbox_Utilities::deq(my_dot, p_dot)) {
01049       plog << "FAILED - Test #14, dot product calculation\n";
01050    }
01051 
01052    VecTDot(pvec1, pvec1, &p_dot);
01053    if (!tbox_Utilities::deq(my_dot, p_dot)) {
01054       plog << "FAILED - Test #15, T-dot product calculation\n";
01055    }
01056 
01057    my_norm = my_vec1->maxNorm();
01058    VecNorm(pvec1, NORM_INFINITY, &p_norm);
01059    if (!tbox_Utilities::deq(my_norm, p_norm)) {
01060       plog << "FAILED - Test #16, max norm calculation\n";
01061    }
01062 
01063    VecSet(&twelve, pvec0);
01064    norm = my_vec1->weightedL2Norm(my_vec0);
01065    if (!tbox_Utilities::deq(norm, (double)7.6393717)) {
01066       plog << "FAILED - Test #17, weighted L2 norm calculation\n";
01067    }
01068  
01069    norm = my_vec0->RMSNorm();
01070    if (!tbox_Utilities::deq(norm, (double)12.0)) {
01071       plog << "FAILED - Test #18, RMS norm calculation\n";
01072    }
01073 
01074    // Vector test routines
01075    my_vec0->setToScalar(-1.0);
01076    my_vec0->compareToScalar(my_vec0, 0.4);
01077    plog << "my_vec0 = 1.0 on L0 (-1.0 in covered region), = 0.0 pn L1?" << endl;
01078    my_vec0->print(plog);
01079 
01080    int test = my_vec0->testReciprocal(my_vec1);
01081    if (test != 1) {
01082       plog << "Failed - Test #19, reciprocal\n";
01083    }
01084 
01085    plog << "my_vec0 = 2.0 on L0 (-1.0 in covered region), = 3.0 pn L1?" << endl;
01086    my_vec0->print(plog); 
01087 
01088    // NOTE: -1's on face and node components on level 1 are due to fact
01089    //       that these entries are redundant and are ignored in the
01090    //       test calculation.  Thus, they should be ignored in the
01091    //       operations that follow.
01092 
01093    // Duplicate vectors
01094    Pointer< SAMRAIVectorReal3<double> > my_vec2 = 
01095       my_vec0->cloneVector("my_vec2");
01096    my_vec2->allocateVectorData();
01097 
01098    my_vec2->setRandomValues(1.0, 0.0); 
01099 
01100    Vec pvec2 = PETSc_SAMRAIVectorReal3<double>::createPETScVector(my_vec2);
01101 
01102    plog << "\n\nPRINTING VARIABLE DATABASE before adding new vector" << endl;
01103    variable_db->printClassData(plog);
01104 
01105    Vec pvec3;
01106    VecDuplicate(pvec2, &pvec3);
01107 
01108    VecCopy(pvec2, pvec3); 
01109 
01110    Pointer< SAMRAIVectorReal3<double> > sam_vec3 =
01111       PETSc_SAMRAIVectorReal3<double>::getSAMRAIVector(pvec3);
01112 
01113    plog << "\nVariables and data components in new vector...";
01114    int ncomp = sam_vec3->getNumberOfComponents();
01115    for (int ic = 0; ic < ncomp; ic++) {
01116       plog << "\n   Comp id, variable, data id = "
01117            << ic << ", "
01118            << sam_vec3->getComponentVariable(ic)->getName() << ", "
01119            << sam_vec3->getComponentDescriptorIndex(ic);
01120    }
01121 
01122    plog << "\n\nPRINTING VARIABLE DATABASE after adding new vector" << endl;
01123    variable_db->printClassData(plog);
01124 
01125    plog << "pvec3 = Random....?" << endl;
01126    VecView(pvec3, ((PetscViewer)NULL));
01127 
01128    VecSwap(pvec0, pvec3);
01129    plog << "After swapping pvec0 and pvec3, pvec0 = Random....?" << endl;
01130    VecView(pvec0, ((PetscViewer)NULL)); 
01131    plog << "pvec3 = 2.0 on L0 (-1.0 in covered region), = 3.0 pn L1?" << endl;
01132    VecView(pvec3, ((PetscViewer)NULL)); 
01133 
01134    VecAXPY(&four, pvec3, pvec0);
01135    plog << "pvec0 = pvec0 + 4.0 * pvec3 = Random + 8.0 on L0 (-3.0 - Random in covered region), = 12.0 + Random on L1?" << endl;
01136    VecView(pvec0, ((PetscViewer)NULL));
01137 
01138    VecScale(&half, pvec3);
01139    plog << "pvec3 = 1.0 on L0 (-0.5 in covered region), = 1.5 pn L1?" << endl;
01140    VecView(pvec3, ((PetscViewer)NULL)); 
01141 
01142    VecSet(&one, pvec0);
01143    VecSet(&two, pvec1);
01144    VecSet(&three, pvec2);
01145 
01146    VecAXPBY(&three, &half, pvec1, pvec0);
01147    plog << "pvec0 = 3 * 2 + 0.5 * 1 = 6.5?" << endl;
01148    VecView(pvec0, ((PetscViewer)NULL));
01149 
01150    VecAYPX(&twelve, pvec0, pvec1);
01151    plog << "pvec1 = 6.5 + 12 * 2 = 30.5?" << endl;
01152    VecView(pvec1, ((PetscViewer)NULL));
01153 
01154    VecWAXPY(&zero, pvec0, pvec0, pvec0);
01155    plog << "pvec0 = 0 * 6.5 + 6.5 = 6.5?" << endl;
01156    VecView(pvec0, ((PetscViewer)NULL));
01157   
01158    // No more tests....Destroy vectors and data... 
01159    
01160    VecDestroy(pvec3);
01161 
01162    plog << "\n\nPRINTING VARIABLE DATABASE after freeing new vector" << endl;
01163    variable_db->printClassData(plog);
01164    
01165    // Destroy PETSc vector wrappers
01166    PETSc_SAMRAIVectorReal3<double>::destroyPETScVector(pvec0);
01167    PETSc_SAMRAIVectorReal3<double>::destroyPETScVector(pvec1);
01168    PETSc_SAMRAIVectorReal3<double>::destroyPETScVector(pvec2);
01169 
01170    // Deallocate vector data and control volumes
01171    my_vec0->freeVectorComponents();
01172    my_vec1->freeVectorComponents();
01173    my_vec2->freeVectorComponents();
01174 
01175    for (ln = 0; ln < 2; ln++) {
01176       hierarchy->getPatchLevel(ln)->deallocatePatchData(cwgt_id);
01177       hierarchy->getPatchLevel(ln)->deallocatePatchData(fwgt_id);
01178       hierarchy->getPatchLevel(ln)->deallocatePatchData(nwgt_id);
01179    }
01180 
01181    for (iv = 0; iv < NCELL_VARS; iv++) {
01182       cvar[iv].setNull();
01183    }
01184    for (iv = 0; iv < NFACE_VARS; iv++) {
01185       fvar[iv].setNull();
01186    }
01187    for (iv = 0; iv < NNODE_VARS; iv++) {
01188       nvar[iv].setNull();
01189    }
01190    cwgt.setNull();
01191    fwgt.setNull();
01192    nwgt.setNull();
01193    cell_ops.setNull();
01194    face_ops.setNull();
01195    node_ops.setNull();
01196 
01197    geometry.setNull();
01198    hierarchy.setNull();
01199 
01200    PetscFinalize();
01201 #endif
01202 
01203    SAMRAIManager::shutdown();
01204    tbox_MPI::finalize();
01205  
01206    return(0); 
01207 }

Generated on Wed Apr 17 12:51:45 2002 for samtut by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001