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

MeshComponents.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 // Find connected components in a mesh by using the dual graph
00007 //
00008 
00009 // Define only if Zoltan is enabled
00010 #if defined (ALBANY_LCM) && defined(ALBANY_ZOLTAN)
00011 
00012 #include <iomanip>
00013 #include <Teuchos_CommandLineProcessor.hpp>
00014 
00015 #include <LCMPartition.h>
00016 
00017 int main(int ac, char* av[])
00018 {
00019   //
00020   // Create a command line processor and parse command line options
00021   //
00022   Teuchos::GlobalMPISession mpiSession(&ac, &av);
00023   Teuchos::CommandLineProcessor
00024   command_line_processor;
00025 
00026   command_line_processor.setDocString(
00027       "Computation of connected components of an Exodus mesh.\n");
00028 
00029   std::string input_file = "input.e";
00030   command_line_processor.setOption(
00031       "input",
00032       &input_file,
00033       "Input File Name");
00034 
00035   std::string output_file = "output.e";
00036   command_line_processor.setOption(
00037       "output",
00038       &output_file,
00039       "Output File Name");
00040 
00041   // Throw a warning and not error for unrecognized options
00042   command_line_processor.recogniseAllOptions(true);
00043 
00044   // Don't throw exceptions for errors
00045   command_line_processor.throwExceptions(false);
00046 
00047   // Parse command line
00048   Teuchos::CommandLineProcessor::EParseCommandLineReturn
00049   parse_return = command_line_processor.parse(ac, av);
00050 
00051   if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00052     return 0;
00053   }
00054 
00055   if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00056     return 1;
00057   }
00058 
00059   //
00060   // Read mesh
00061   //
00062   LCM::ConnectivityArray
00063   connectivity_array(input_file, output_file);
00064 
00065   //
00066   // Create dual graph
00067   //
00068   LCM::DualGraph dual_graph(connectivity_array);
00069 
00070   //
00071   // Compute connected components
00072   //
00073   std::vector<int>
00074   components;
00075 
00076   const int
00077   number_components = dual_graph.GetConnectedComponents(components);
00078 
00079   // Get abstract discretization from connectivity array and convert
00080   // to stk discretization to use stk-specific methods.
00081   Albany::AbstractDiscretization &
00082   discretization = connectivity_array.GetDiscretization();
00083 
00084   Albany::STKDiscretization &
00085   stk_discretization = static_cast<Albany::STKDiscretization &>(discretization);
00086 
00087   // Get MDArray which is memeopru in stk for "Partition" element variable
00088   Albany::MDArray
00089   stk_component =
00090       stk_discretization.getStateArrays().elemStateArrays[0]["Partition"];
00091 
00092   //
00093   // Output components
00094   //
00095 
00096   // Assumption: numbering of elements is contiguous.
00097   for (std::vector<int>::size_type element = 0;
00098       element < components.size();
00099       ++element) {
00100     const int component = components[element];
00101 
00102     // set component number in stk field memory
00103     stk_component[element] = component;
00104 
00105   }
00106 
00107   // Need solution for output call
00108   Teuchos::RCP<Epetra_Vector>
00109   solution_field = stk_discretization.getSolutionField();
00110 
00111   // second arg to output is (pseudo)time
00112 //  stk_discretization.outputToExodus(*solution_field, 1.0);
00113   stk_discretization.writeSolution(*solution_field, 1.0);
00114 
00115   const int
00116   number_elements = connectivity_array.GetNumberElements();
00117 
00118   std::cout << std::endl;
00119   std::cout << "==========================================";
00120   std::cout << std::endl;
00121   std::cout << "Number of Elements        : " << number_elements << std::endl;
00122   std::cout << std::endl;
00123   std::cout << "Number of Mesh Components : " << number_components << std::endl;
00124   std::cout << "------------------------------------------";
00125   std::cout << std::endl;
00126   std::cout << "Element Component";
00127   std::cout << std::endl;
00128   std::cout << "------------------------------------------";
00129   std::cout << std::endl;
00130 
00131   for (std::vector<int>::size_type element = 0;
00132       element < components.size();
00133       ++element) {
00134     std::cout << std::setw(8) << element;
00135     std::cout << std::setw(8) << components[element] << std::endl;
00136   }
00137 
00138   std::cout << "==========================================";
00139   std::cout << std::endl;
00140 
00141   return 0;
00142 
00143 }
00144 
00145 #else // #if defined (ALBANY_LCM) && defined(ALBANY_ZOLTAN)
00146 
00147 // Zoltan not defined, do nothing
00148 int main(int ac, char* av[])
00149 {
00150   return 0;
00151 }
00152 
00153 #endif // #if defined (ALBANY_ZOLTAN)

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