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

grid_construction/gcX.C.sed

Go to the documentation of this file.
00001 /*
00002   Id:           $Id: gcX.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:  Main program sketch for grid_construction
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 "GridConstructionX.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 int main( int argc, char *argv[] )
00060 {
00061   /*
00062     Initialize MPI, SAMRAI, and enable logging.
00063   */
00064 
00065   tbox_MPI::init(&argc, &argv);
00066   tbox_SAMRAIManager::startup();
00067 
00068 
00069   string input_filename = "input";
00070   if ( argc > 1 ) input_filename = argv[1];
00071 
00072 
00073   /*
00074     Create input database and parse all data in input file into it.
00075   */
00076 
00077   tbox_Pointer<tbox_Database> input_db = new tbox_InputDatabase("input_db");
00078   tbox_InputManager::getManager()->parseInputFile(input_filename, input_db);
00079 
00080 
00081 
00082   /*
00083     Get the Main database part of the input database.
00084     This database contains information relevant to main.
00085   */
00086 
00087   tbox_Pointer<tbox_Database> main_db = input_db->getDatabase("Main");
00088   plog << "Main database:" << endl; main_db->printClassData(plog);
00089 
00090 
00091   /*
00092     Base filename info.
00093   */
00094 
00095   string base_filename = main_db->getStringWithDefault("base_filename", "jp");
00096 
00097 
00098   /*
00099     Log file info.
00100   */
00101 
00102   string log_filename
00103     = main_db->getStringWithDefault("log_filename", base_filename+".log");
00104   tbox_PIO::logOnlyNodeZero(log_filename);
00105 
00106 
00107 
00108 
00109   /*
00110     Create a patch hierarchy for use later.
00111     This object is a required input for these objects: grid_construction.
00112   */
00113   tbox_Pointer<hier_PatchHierarchy2> patch_hierarchy;
00114   {
00115     /*
00116       Create a grid geometry required for the hier_patchHierarchyX object.
00117     */
00118     tbox_Pointer<geom_CartesianGridGeometryX> grid_geometry =
00119       new geom_CartesianGridGeometryX("CartesianGridGeometry",
00120                                       input_db->getDatabase("CartesianGridGeometry"));
00121     plog << "Grid Geometry:" << endl;
00122     grid_geometry->printClassData(plog);
00123     patch_hierarchy =
00124       new hier_PatchHierarchy2("Patch Hierarchy", grid_geometry);
00125   }
00126   printObjectX( plog, *patch_hierarchy );
00127 
00128 
00129 
00130   /*
00131     Create the problem-specific object implementing the required
00132     SAMRAI virtual functions.
00133     This object is a required input for these objects: hyp_level_integrator.
00134   */
00135   GridConstructionX* grid_construction = new GridConstructionX(
00136                                          "GridConstructionX"
00137                                          , input_db->getDatabase("GridConstructionX")
00138                                          );
00139   printObjectX( plog, *patch_hierarchy );
00140 
00141 
00142 
00143 
00144   /*
00145     Create the gridding algorithm used to generate the SAMR grid.
00146   */
00147   tbox_Pointer<mesh_GriddingAlgorithmX> gridding_algorithm;
00148   {
00149     /*
00150       Create the tag-and-initializer, box-generator and load-balancer
00151       object references required by the gridding_algorithm object.
00152     */
00153     tbox_Pointer<mesh_StandardTagAndInitializeX> tag_and_initializer =
00154       new mesh_StandardTagAndInitializeX(
00155           "CellTaggingMethod"
00156         , grid_construction
00157         , input_db->getDatabase("StandardTagAndInitialize")
00158         );
00159     tbox_Pointer<mesh_BergerRigoutsosX> box_generator =
00160       new mesh_BergerRigoutsosX();
00161     tbox_Pointer<mesh_UniformLoadBalanceX> load_balancer =
00162       new mesh_UniformLoadBalanceX(input_db->getDatabase("UniformLoadBalance"));
00163 
00164     gridding_algorithm =
00165       new mesh_GriddingAlgorithmX("Gridding Algorithm",
00166                                   input_db->getDatabase("GriddingAlgorithm"),
00167                                   tag_and_initializer,
00168                                   box_generator,
00169                                   load_balancer);
00170     plog << "Gridding algorithm:" << endl;
00171     gridding_algorithm->printClassData(plog);
00172   }
00173 
00174 
00175 
00176   /*
00177     Make the patch levels.
00178   */
00179   gridding_algorithm->makeCoarsestLevel(patch_hierarchy,0.0);
00180   bool done=false;
00181   for (int lnum = 0;
00182        gridding_algorithm->levelCanBeRefined(lnum) && !done; lnum++) {
00183     plog << "Adding finner levels with lnum = " << lnum << endl;
00184     gridding_algorithm->makeFinerLevel( patch_hierarchy
00185                                         , /* simulation time */ 0.0
00186                                         , /* whether initial time */ true
00187                                         , /* tag buffer size */ 0
00188                                         );
00189     plog << "Just added finner levels with lnum = " << lnum << endl;
00190     done = !(patch_hierarchy->finerLevelExists(lnum));
00191   }
00192 
00193 
00194 
00195   /*
00196     After creating all objects and initializing their state,
00197     we print the input database and variable database contents
00198     to the log file.
00199   */
00200   plog << "\nCheck input data and variables before simulation:" << endl;
00201   plog << "Input database..." << endl;
00202   input_db->printClassData(plog);
00203   plog << "\nVariable database..." << endl;
00204   hier_VariableDatabaseX::getDatabase()->printClassData(plog);
00205 
00206 
00207 
00208 
00209   /*
00210     Now that hierarchy is constructed, write a plot file.
00211   */
00212   {
00213     /* Get the output filename. */
00214     string viz_filename
00215       = main_db->getStringWithDefault("viz_filename", base_filename);
00216     /* Create the vizamrai data writer. */
00217     tbox_Pointer<plot_CartesianVizamraiDataWriter2> viz_data_writer =
00218       new plot_CartesianVizamraiDataWriter2("Viz Writer");
00219     /* Register variables with plotter. */
00220     grid_construction->registerVariablesWithPlotter(viz_data_writer);
00221     /*
00222       Tell the plotter about the refinement ratios.
00223       This must be done once (and again each time the data changes).
00224     */
00225     for ( int ln=1; ln<gridding_algorithm->getMaxLevels(); ln++ ) {
00226       const hier_IntVectorX &lratio =
00227         gridding_algorithm->getRatioToCoarserLevel(ln);
00228       viz_data_writer->setRatioToCoarserLevel(ln, lratio);
00229     }
00230     /* Write the plot file. */
00231     viz_data_writer->writePlotData( patch_hierarchy , viz_filename );
00232   }
00233 
00234 
00235 
00236   /*
00237     Exit properly by shutting down services in correct order.
00238   */
00239   tbox_SAMRAIManager::shutdown();
00240   tbox_MPI::finalize();
00241 
00242 
00243   return(0);
00244 }

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