• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Subdivision.cc

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 // Test of barycentric subdivision.
00007 // Reads in a mesh and applies the barycentric subdivision algorithm
00008 // to it. Restricted to simplicial complexes.
00009 //
00010 
00011 #include "time.h"
00012 
00013 #include "topology/Topology.h"
00014 #include "topology/Topology_Utils.h"
00015 
00016 int
00017 main(int ac, char* av[])
00018 {
00019 
00020   //
00021   // Create a command line processor and parse command line options
00022   //
00023   Teuchos::CommandLineProcessor command_line_processor;
00024 
00025   command_line_processor.setDocString("Test of barycentric subdivision.\n"
00026       "Reads in a mesh and applies the barycentric subdivision algorithm.\n"
00027       "Restricted to simplicial complexes.\n");
00028 
00029   std::string input_file = "input.e";
00030   command_line_processor.setOption("input", &input_file, "Input File Name");
00031 
00032   std::string output_file = "output.e";
00033   command_line_processor.setOption("output", &output_file, "Output File Name");
00034 
00035   // Throw a warning and not error for unrecognized options
00036   command_line_processor.recogniseAllOptions(true);
00037 
00038   // Don't throw exceptions for errors
00039   command_line_processor.throwExceptions(false);
00040 
00041   // Parse command line
00042   Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
00043       command_line_processor.parse(ac, av);
00044 
00045   if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00046     return 0;
00047   }
00048 
00049   if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00050     return 1;
00051   }
00052 
00053   //
00054   // Read the mesh
00055   //
00056   // Copied from Partition.cc
00057   Teuchos::GlobalMPISession mpiSession(&ac, &av);
00058 
00059   LCM::Topology topology(input_file, output_file);
00060 
00061   // Node rank should be 0 and element rank should be equal to the dimension of the
00062   //system (e.g. 2 for 2D meshes and 3 for 3D meshes)
00063   //cout << "Node Rank: "<< nodeRank << ", Element Rank: " << elementRank << "\n";
00064 
00065   // Print element connectivity before the mesh topology is modified
00066   std::cout << "***********************" << std::endl;
00067   std::cout << "Before mesh subdivision" << std::endl;
00068   std::cout << "***********************" << std::endl;
00069 
00070   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00071 
00072   // Start the mesh update process
00073   // Prepares mesh for barycentric subdivision
00074   topology.removeNodeRelations();
00075 
00076   // Output graph structure for debugging
00077   std::string gviz_output = LCM::parallelize_string("before") + ".dot";
00078   topology.outputToGraphviz(gviz_output);
00079 
00080   //
00081   // Here starts the barycentric subdivision.
00082   //
00083   //-----------------------------------------------------------------------------------------------------------------------------------
00084   // Generate the output file
00085   //-----------------------------------------------------------------------------------------------------------------------------------
00086 
00087   //Measure the time computing the barycentric subdivision
00088   clock_t start, end;
00089   double cpu_time_used;
00090   start = clock();
00091 
00092   //Carry out barycentric subdivision on the mesh
00093   topology.barycentricSubdivision();
00094 
00095   end = clock();
00096   cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
00097 
00098   std::cout << "*************************" << std::endl;
00099   std::cout << "After element subdivision" << std::endl;
00100   std::cout << "*************************" << std::endl;
00101   gviz_output = LCM::parallelize_string("after") + ".dot";
00102   topology.outputToGraphviz(gviz_output);
00103 
00104   // Recreates connectivity in stk mesh expected by Albany_STKDiscretization
00105   // Must be called each time at conclusion of mesh modification
00106   topology.restoreElementToNodeConnectivity();
00107 
00108   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00109 
00110   std::cout << std::endl;
00111   std::cout << "topology.barycentricSubdivision() takes "
00112       << cpu_time_used << " seconds"<< std::endl;
00113 
00114   Teuchos::RCP<Albany::AbstractDiscretization> discretization_ptr =
00115       topology.getDiscretization();
00116   Albany::STKDiscretization & stk_discretization =
00117       static_cast<Albany::STKDiscretization &>(*discretization_ptr);
00118 
00119   Teuchos::RCP<Epetra_Vector> solution_field =
00120       stk_discretization.getSolutionField();
00121 
00122   // Write final mesh to exodus file
00123   // second arg to output is (pseudo)time
00124 //  stk_discretization.outputToExodus(*solution_field, 1.0);
00125   stk_discretization.writeSolution(*solution_field, 1.0);
00126 
00127   return 0;
00128 
00129 }

Generated on Wed Mar 26 2014 18:36:44 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1