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

Test2_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 2 of barycentric subdivision. Input file has to be specified.
00007 // Checks that the final output file contains the subdivision.
00008 // Restricted to simplicial complexes.
00009 //
00010 
00011 #include "time.h"
00012 
00013 #include "topology/Topology.h"
00014 #include "topology/Topology_Utils.h"
00015 
00016 typedef stk::mesh::Entity Entity;
00017 
00018 /*
00019  * Returns a vector with the number of entities of the current
00020  * mesh. e.g. vector's element 0 returns the number of entities of rank 0.
00021  * The vector's element 1 returns the number of entities of rank 1, and so on.
00022  */
00023 std::vector<int>
00024 return_number_entities(LCM::Topology & topology_);
00025 
00026 //
00027 // Checks if the subdivision was done correctly
00028 //
00029 std::string
00030 verify_subdivision(const std::vector<int> & former_num_entities,
00031     const std::vector<int> & final_num_entities);
00032 
00033 int main(int ac, char* av[])
00034 {
00035 
00036   //
00037   // Create a command line processor and parse command line options
00038   //
00039   Teuchos::CommandLineProcessor command_line_processor;
00040 
00041   command_line_processor.setDocString("Test of barycentric subdivision.\n"
00042       "Reads in a mesh and applies the barycentric subdivision algorithm.\n"
00043       "Restricted to simplicial complexes.\n");
00044 
00045   std::string input_file = "input.e";
00046   command_line_processor.setOption("input", &input_file, "Input File Name");
00047 
00048   std::string output_file = "output.exo";
00049   command_line_processor.setOption("output", &output_file, "Output File Name");
00050 
00051   // Throw a warning and not error for unrecognized options
00052   command_line_processor.recogniseAllOptions(true);
00053 
00054   // Don't throw exceptions for errors
00055   command_line_processor.throwExceptions(false);
00056 
00057   // Parse command line
00058   Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
00059       command_line_processor.parse(ac, av);
00060 
00061   if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00062     return 0;
00063   }
00064 
00065   if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00066     return 1;
00067   }
00068 
00069   //
00070   // Read the mesh
00071   //
00072   // Copied from Partition.cc
00073   Teuchos::GlobalMPISession mpiSession(&ac, &av);
00074   LCM::Topology topology(input_file, output_file);
00075 
00076  // Print element connectivity before the mesh topology is modified
00077   std::cout << "***********************" << std::endl;
00078   std::cout << "Before mesh subdivision" << std::endl;
00079   std::cout << "***********************" << std::endl;
00080   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00081   //Request the number of entities of the input mesh
00082   std::vector<int> vector_initial_entities = return_number_entities(topology);
00083   // Start the mesh update process
00084   // Prepares mesh for barycentric subdivision
00085   topology.removeNodeRelations();
00086 
00087   //
00088   // Here starts the barycentric subdivision.
00089   //
00090   //Carry out barycentric subdivision on the mesh
00091   topology.barycentricSubdivision();
00092   std::cout << "*************************" << std::endl;
00093   std::cout << "After element subdivision" << std::endl;
00094   std::cout << "*************************" << std::endl;
00095 
00096   // Recreates connectivity in stk mesh expected by Albany_STKDiscretization
00097   // Must be called each time at conclusion of mesh modification
00098 
00099   topology.restoreElementToNodeConnectivity();
00100   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00101 
00102   //
00103   // Generate the output (exodus) file
00104   //
00105   Teuchos::RCP<Albany::AbstractDiscretization> discretization_ptr =
00106       topology.getDiscretization();
00107   Albany::STKDiscretization & stk_discretization =
00108       static_cast<Albany::STKDiscretization &>(*discretization_ptr);
00109   Teuchos::RCP<Epetra_Vector> solution_field =
00110       stk_discretization.getSolutionField();
00111 
00112   // Write final mesh to exodus file
00113   // second arg to output is (pseudo)time
00114   stk_discretization.writeSolution(*solution_field, 1.0);
00115 
00116   //
00117   // Read the output mesh after the subdivision and check that it is correct
00118   //
00119   std::cout << "*************************************" << std::endl;
00120   std::cout << "Checking final mesh after subdivision" << std::endl;
00121   std::cout << "*************************************" << std::endl;
00122   std::string no_use_file = "output.exo";
00123   LCM::Topology topology2(output_file, no_use_file);
00124   std::vector<int> vector_final_entities = return_number_entities(topology2);
00125   std::cout <<verify_subdivision(vector_initial_entities,
00126           vector_final_entities)<<std::endl;
00127 
00128   return 0;
00129 }
00130 /*
00131  * Returns a vector with the number of entities of the current
00132  * mesh. e.g. vector's element 0 returns the number of entities of rank 0.
00133  * The vector's element 1 returns the number of entities of rank 1, and so on.
00134  */
00135 std::vector<int>
00136 return_number_entities(LCM::Topology & topology_){
00137   //Vector with output info
00138   std::vector<int> output_vector;
00139   //Push back number of nodes
00140   stk::mesh::BulkData* bulkData_ = topology_.getBulkData();
00141   std::vector<Entity*> initial_entities_D0 = topology_.getEntitiesByRank(
00142       *(bulkData_), 0);
00143   output_vector.push_back(initial_entities_D0.size());
00144   //Push back number of edges
00145   std::vector<Entity*> initial_entities_D1 = topology_.getEntitiesByRank(
00146       *(bulkData_), 1);
00147   output_vector.push_back(initial_entities_D1.size());
00148   //Push back number of faces
00149   std::vector<Entity*> initial_entities_D2 = topology_.getEntitiesByRank(
00150       *(bulkData_), 2);
00151   output_vector.push_back(initial_entities_D2.size());
00152   //Push back number of elements
00153   std::vector<Entity*> initial_entities_D3 = topology_.getEntitiesByRank(
00154       *(bulkData_), 3);
00155   output_vector.push_back(initial_entities_D3.size());
00156 
00157   return output_vector;
00158 }
00159 //
00160 // Checks if the subdivision was done correctly
00161 //
00162 std::string
00163 verify_subdivision(const std::vector<int> & former_num_entities,
00164     const std::vector<int> & final_num_entities){
00165   //Verify the number of nodes
00166   int final_number_nodes =  former_num_entities[0]+ former_num_entities[1]+ former_num_entities[2]+
00167       former_num_entities[3];
00168   TEUCHOS_TEST_FOR_EXCEPTION( final_number_nodes != final_num_entities[0], std::logic_error,
00169       "The number of nodes after subdivision is incorrect\n");
00170   //Verify the number of edges
00171   int final_number_edges = (former_num_entities[1]*2)+(former_num_entities[2]*6)+
00172       (14*former_num_entities[3]);
00173   TEUCHOS_TEST_FOR_EXCEPTION( final_number_edges != final_num_entities[1], std::logic_error,
00174       "The number of edges after subdivision is incorrect\n");
00175   //Verify the number of faces
00176   int final_number_faces = (former_num_entities[2]*6)+(36* former_num_entities[3]);
00177   TEUCHOS_TEST_FOR_EXCEPTION( final_number_faces != final_num_entities[2], std::logic_error,
00178       "The number of faces after subdivision is incorrect\n");
00179   //Verify the number of elements
00180   int final_number_elements = 24* former_num_entities[3];
00181   TEUCHOS_TEST_FOR_EXCEPTION( final_number_elements != final_num_entities[3], std::logic_error,
00182       "The number of elements after subdivision is incorrect\n");
00183   //If all the subdivision is done correctly, the following message will be displayed
00184   return std::string("SUBDIVISION TEST 2: PASSED");
00185 }

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