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

jacobi_poisson/jpX.C.sed

Go to the documentation of this file.
00001 /*
00002   Id:           $Id: jpX.C.sed,v 1.1.2.2 2002/03/20 00:43:45 gunney Exp $
00003   Copyright:    (c) 1997-2000 The Regents of the University of California
00004   Release:      $Name: v_0_1_7 $
00005   Revision:     $Revision: 1.1.2.2 $
00006   Modified:     $Date: 2002/03/20 00:43:45 $
00007   Description:  Tutorial program for poisson solver using jacobi iteration
00008 */
00009 
00010 #include "SAMRAI_config.h"
00011 
00012 #include <iostream>
00013 #include <string>
00014 
00015 #ifdef HAVE_ISO_HEADERS
00016 #include <fstream>
00017 using namespace std;
00018 #else
00019 #include <fstream.h>
00020 #endif
00021 
00022 #include <printObjectX.h>
00023 #include "JacobiPoissonX.h"
00024 
00025 /*
00026   Headers for basic SAMRAI objects used in this code.
00027 */
00028 #include <tbox_SAMRAIManager.h>
00029 #include <tbox_Array.h>
00030 #include <tbox_Boolean.h>
00031 #include <tbox_Database.h>
00032 #include <tbox_InputManager.h>
00033 #include <tbox_MPI.h>
00034 #include <tbox_PIO.h>
00035 #include <tbox_Pointer.h>
00036 #include <tbox_String.h>
00037 #include <tbox_TimerManager.h>
00038 #include <tbox_Utilities.h>
00039 #include <plot_CartesianVizamraiDataWriter2.h>
00040 
00041 /*
00042   Headers for major algorithm/data structure objects from SAMRAI
00043 */
00044 #include <hier_GridGeometry2.h>
00045 #include <hier_VariableDatabase2.h>
00046 #include <mesh_BergerRigoutsos2.h>
00047 #include <geom_CartesianGridGeometry2.h>
00048 #include <mesh_GriddingAlgorithm2.h>
00049 #include <hier_PatchHierarchy2.h>
00050 #include <mesh_StandardTagAndInitialize2.h>
00051 #include <mesh_UniformLoadBalance2.h>
00052 
00053 #ifndef LACKS_NAMESPACE
00054 using namespace SAMRAI;
00055 #endif
00056 
00057 
00058 
00059 
00067 int main( int argc, char *argv[] )
00068 {
00069   /*
00070     Initialize MPI, SAMRAI, and enable logging.
00071   */
00072 
00073   tbox_MPI::init(&argc, &argv);
00074   tbox_SAMRAIManager::startup();
00075 
00076   string input_filename = "input";
00077   if ( argc > 1 ) input_filename = argv[1];
00078 
00079 
00080   /*
00081     Create input database and parse all data in input file into it.
00082   */
00083 
00084   tbox_Pointer<tbox_Database> input_db = new tbox_InputDatabase("input_db");
00085   tbox_InputManager::getManager()->parseInputFile(input_filename, input_db);
00086 
00087 
00088   /*
00089     Get the Main database part of the input database.
00090     This database contains information relevant to main.
00091   */
00092 
00093   tbox_Pointer<tbox_Database> main_db = input_db->getDatabase("Main");
00094   plog << "Main database:" << endl; main_db->printClassData(plog);
00095 
00096 
00097   /*
00098     Base filename info.
00099   */
00100 
00101   string base_filename = main_db->getStringWithDefault("base_filename", "jp");
00102 
00103 
00104   /*
00105     Log file info.
00106   */
00107 
00108   string log_filename
00109     = main_db->getStringWithDefault("log_filename", base_filename+".log");
00110   tbox_PIO::logOnlyNodeZero(log_filename);
00111 
00112 
00113   /*
00114     Create a patch hierarchy for use later.
00115     This object is a required input for these objects: jacobi_poisson.
00116   */
00117   tbox_Pointer<hier_PatchHierarchy2> patch_hierarchy;
00118   {
00119     /*
00120       Create a grid geometry required for the hier_patchHierarchyX object.
00121     */
00122     tbox_Pointer<geom_CartesianGridGeometryX> grid_geometry =
00123       new geom_CartesianGridGeometryX("CartesianGridGeometry",
00124                                       input_db->getDatabase("CartesianGridGeometry"));
00125     plog << "Grid Geometry:" << endl;
00126     grid_geometry->printClassData(plog);
00127     patch_hierarchy =
00128       new hier_PatchHierarchy2("Patch Hierarchy", grid_geometry);
00129   }
00130   printObjectX( plog, *patch_hierarchy );
00131 
00132 
00133 
00134   /*
00135     Create the problem-specific object implementing the required
00136     SAMRAI virtual functions.
00137     This object is a required input for these objects: hyp_level_integrator.
00138   */
00139   JacobiPoissonX* jacobi_poisson = new JacobiPoissonX(
00140                                  "JacobiPoissonX"
00141                                  , input_db->getDatabase("JacobiPoissonX")
00142                                  );
00143   printObjectX( plog, *patch_hierarchy );
00144 
00145 
00146 
00147 
00148   /*
00149     Create the gridding algorithm used to generate the SAMR grid.
00150   */
00151   tbox_Pointer<mesh_GriddingAlgorithmX> gridding_algorithm;
00152   {
00153     /*
00154       Create the tag-and-initializer, box-generator and load-balancer
00155       object references required by the gridding_algorithm object.
00156     */
00157     tbox_Pointer<mesh_StandardTagAndInitializeX> tag_and_initializer =
00158       new mesh_StandardTagAndInitializeX(
00159           "CellTaggingMethod"
00160         , jacobi_poisson
00161         , input_db->getDatabase("StandardTagAndInitialize")
00162         );
00163     tbox_Pointer<mesh_BergerRigoutsosX> box_generator =
00164       new mesh_BergerRigoutsosX();
00165     tbox_Pointer<mesh_UniformLoadBalanceX> load_balancer =
00166       new mesh_UniformLoadBalanceX(input_db->getDatabase("UniformLoadBalance"));
00167 
00168     gridding_algorithm =
00169       new mesh_GriddingAlgorithmX("Gridding Algorithm",
00170                                   input_db->getDatabase("GriddingAlgorithm"),
00171                                   tag_and_initializer,
00172                                   box_generator,
00173                                   load_balancer);
00174     plog << "Gridding algorithm:" << endl;
00175     gridding_algorithm->printClassData(plog);
00176   }
00177 
00178 
00179 
00180   /*
00181     Make the patch levels.
00182   */
00183   gridding_algorithm->makeCoarsestLevel(patch_hierarchy,0.0);
00184   bool done=false;
00185   for (int lnum = 0;
00186        gridding_algorithm->levelCanBeRefined(lnum) && !done; lnum++) {
00187     plog << "Adding finner levels with lnum = " << lnum << endl;
00188     gridding_algorithm->makeFinerLevel( patch_hierarchy
00189                                         , /* simulation time */ 0.0
00190                                         , /* whether initial time */ true
00191                                         , /* tag buffer size */ 0
00192                                         );
00193     plog << "Just added finner levels with lnum = " << lnum << endl;
00194     done = !(patch_hierarchy->finerLevelExists(lnum));
00195   }
00196 
00197 
00198 
00199   /*
00200     Set up the plotter.
00201   */
00202   tbox_Pointer<plot_CartesianVizamraiDataWriter2> viz_data_writer;
00203   /* Get the output filename. */
00204   string viz_filename
00205     = main_db->getStringWithDefault("viz_filename", base_filename);
00206   int viz_dump_interval
00207     = main_db->getIntegerWithDefault("viz_dump_interval", 0 );
00208   if ( viz_dump_interval ) {
00209     /* Create the vizamrai data writer. */
00210     viz_data_writer = new plot_CartesianVizamraiDataWriter2("Viz Writer");
00211     /* Register variables with plotter. */
00212     jacobi_poisson->registerVariablesWithPlotter(viz_data_writer);
00213     /*
00214       Tell the plotter about the refinement ratios.
00215       This must be done once (and again each time the data changes).
00216     */
00217     for ( int ln=1; ln<gridding_algorithm->getMaxLevels(); ln++ ) {
00218       const hier_IntVectorX &lratio =
00219         gridding_algorithm->getRatioToCoarserLevel(ln);
00220       viz_data_writer->setRatioToCoarserLevel(ln, lratio);
00221     }
00222     /*
00223       Set the finest level to plot (optional).
00224     */
00225     int finest_plot_level
00226       = main_db->getIntegerWithDefault( "finest_plot_level"
00227         , patch_hierarchy->getFinestLevelNumber() );
00228     viz_data_writer->setFinestLevelToPlot(finest_plot_level);
00229   }
00230 
00231 
00232 
00233   /*
00234     After creating all objects and initializing their state,
00235     we print the input database and variable database contents
00236     to the log file.
00237   */
00238   plog << "\nCheck input data and variables before simulation:" << endl;
00239   plog << "Input database..." << endl;
00240   input_db->printClassData(plog);
00241   plog << "\nVariable database..." << endl;
00242   hier_VariableDatabaseX::getDatabase()->printClassData(plog);
00243 
00244 
00245 
00246 
00247   /*
00248     Loop through a fixed number of iterations.
00249   */
00250   pout.setf(ios::scientific);
00251   int number_of_iterations =
00252     main_db->getIntegerWithDefault("number_of_iterations",1);
00253   for ( int itnum=0; itnum<number_of_iterations; ++itnum ) {
00254     pout << "Iteration " << itnum
00255          ;
00256     if ( viz_dump_interval && !(itnum%viz_dump_interval) ) {
00257       /* Write the plot file. */
00258       viz_data_writer->writePlotData( patch_hierarchy , viz_filename , itnum );
00259     }
00260     /* Perform iteration. */
00261     jacobi_poisson->jacobiIteration( patch_hierarchy , 1.0 );
00262     /* Per iteration output */
00263     double l2norm, linorm;
00264     jacobi_poisson->computeError( patch_hierarchy, &l2norm, &linorm );
00265     pout << " l2norm " << l2norm << " linorm " << linorm << endl;
00266   }
00267 
00268 
00269 
00270 
00271   /* Write the final plot file. */
00272   if ( viz_dump_interval )
00273     viz_data_writer->writePlotData( patch_hierarchy , viz_filename
00274                                   , number_of_iterations );
00275 
00276 
00277 
00278   /*
00279     Exit properly by shutting down services in correct order.
00280   */
00281   tbox_SAMRAIManager::shutdown();
00282   tbox_MPI::finalize();
00283 
00284 
00285   return(0);
00286 }

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