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

Test1_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 1 of barycentric subdivision. Input file has to be specified.
00007 // Checks the proper operation of the barycentric_subdivision() function.
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.e";
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   // Print element connectivity before the mesh topology is modified
00076   std::cout << "***********************" << std::endl;
00077   std::cout << "Before mesh subdivision" << std::endl;
00078   std::cout << "***********************" << std::endl;
00079   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00080 
00081   //Request the number of entities of the input mesh
00082   std::vector<int> vector_initial_entities = return_number_entities(topology);
00083 
00084   // Start the mesh update process
00085   // Prepares mesh for barycentric subdivision
00086   topology.removeNodeRelations();
00087 
00088   //
00089   // Here starts the barycentric subdivision.
00090   //
00091   //Carry out barycentric subdivision on the mesh
00092   topology.barycentricSubdivision();
00093   std::cout << "*************************" << std::endl;
00094   std::cout << "After element subdivision" << std::endl;
00095   std::cout << "*************************" << std::endl;
00096   //Request the number of entities of the output mesh after subdivision
00097   std::vector<int> vector_final_entities = return_number_entities(topology);
00098   LCM::display_connectivity(topology.getBulkData(), topology.getCellRank());
00099 
00100   // Checking that the final mesh after subdivision is correct
00101   std::cout << "*************************************" << std::endl;
00102   std::cout << "Checking final mesh after subdivision" << std::endl;
00103   std::cout << "*************************************" << std::endl;
00104   std::cout <<verify_subdivision(vector_initial_entities,
00105       vector_final_entities)<<std::endl;
00106 
00107   return 0;
00108 
00109 }
00110 
00111 /*
00112  * Returns a vector with the number of entities of the current
00113  * mesh. e.g. vector's element 0 returns the number of entities of rank 0.
00114  * The vector's element 1 returns the number of entities of rank 1, and so on.
00115  */
00116 std::vector<int>
00117 return_number_entities(LCM::Topology & topology_){
00118   //Vector with output info
00119   std::vector<int> output_vector;
00120   //Push back number of nodes
00121   stk::mesh::BulkData* bulkData_ = topology_.getBulkData();
00122   std::vector<Entity*> initial_entities_D0 = topology_.getEntitiesByRank(
00123       *(bulkData_), 0);
00124   output_vector.push_back(initial_entities_D0.size());
00125   //Push back number of edges
00126   std::vector<Entity*> initial_entities_D1 = topology_.getEntitiesByRank(
00127       *(bulkData_), 1);
00128   output_vector.push_back(initial_entities_D1.size());
00129   //Push back number of faces
00130   std::vector<Entity*> initial_entities_D2 = topology_.getEntitiesByRank(
00131       *(bulkData_), 2);
00132   output_vector.push_back(initial_entities_D2.size());
00133   //Push back number of elements
00134   std::vector<Entity*> initial_entities_D3 = topology_.getEntitiesByRank(
00135       *(bulkData_), 3);
00136   output_vector.push_back(initial_entities_D3.size());
00137 
00138   return output_vector;
00139 }
00140 //
00141 // Checks if the subdivision was done correctly
00142 //
00143 std::string
00144 verify_subdivision(const std::vector<int> & former_num_entities,
00145       const std::vector<int> & final_num_entities){
00146   //Verify the number of nodes
00147   int final_number_nodes =  former_num_entities[0]+ former_num_entities[1]+ former_num_entities[2]+
00148       former_num_entities[3];
00149   TEUCHOS_TEST_FOR_EXCEPTION( final_number_nodes != final_num_entities[0], std::logic_error,
00150                              "The number of nodes after subdivision is incorrect\n");
00151   //Verify the number of edges
00152   int final_number_edges = (former_num_entities[1]*2)+(former_num_entities[2]*6)+
00153       (14*former_num_entities[3]);
00154   TEUCHOS_TEST_FOR_EXCEPTION( final_number_edges != final_num_entities[1], std::logic_error,
00155                              "The number of edges after subdivision is incorrect\n");
00156   //Verify the number of faces
00157   int final_number_faces = (former_num_entities[2]*6)+(36* former_num_entities[3]);
00158   TEUCHOS_TEST_FOR_EXCEPTION( final_number_faces != final_num_entities[2], std::logic_error,
00159                              "The number of faces after subdivision is incorrect\n");
00160   //Verify the number of elements
00161   int final_number_elements = 24* former_num_entities[3];
00162   TEUCHOS_TEST_FOR_EXCEPTION( final_number_elements != final_num_entities[3], std::logic_error,
00163                                  "The number of elements after subdivision is incorrect\n");
00164   //If all the subdivision is done correctly, the following message will be displayed
00165   return std::string("SUBDIVISION TEST 1: PASSED");
00166 }

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