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

NodeUpdate.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 mesh manipulation.
00007 // Separate all elements of a mesh by nodal replacement
00008 //
00009 
00010 #include "topology/Topology.h"
00011 #include "topology/Topology_Utils.h"
00012 
00013 int main(int ac, char* av[])
00014 {
00015 
00016   //
00017   // Create a command line processor and parse command line options
00018   //
00019   Teuchos::CommandLineProcessor
00020     command_line_processor;
00021 
00022   command_line_processor.setDocString(
00023                                       "Test of element separation through nodal insertion.\n"
00024                                       "Remove and replace all nodes in elements.\n");
00025 
00026   std::string input_file = "input.e";
00027   command_line_processor.setOption(
00028                                    "input",
00029                                    &input_file,
00030                                    "Input File Name");
00031 
00032   std::string output_file = "output.e";
00033   command_line_processor.setOption(
00034                                    "output",
00035                                    &output_file,
00036                                    "Output File Name");
00037 
00038   // Throw a warning and not error for unrecognized options
00039   command_line_processor.recogniseAllOptions(true);
00040 
00041   // Don't throw exceptions for errors
00042   command_line_processor.throwExceptions(false);
00043 
00044   // Parse command line
00045   Teuchos::CommandLineProcessor::EParseCommandLineReturn
00046     parse_return = command_line_processor.parse(ac, av);
00047 
00048   if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00049     return 0;
00050   }
00051 
00052   if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00053     return 1;
00054   }
00055 
00056   //
00057   // Read the mesh
00058   //
00059   // Copied from Partition.cc
00060   Teuchos::GlobalMPISession mpiSession(&ac,&av);
00061 
00062   LCM::Topology
00063     topology(input_file,output_file);
00064 
00065   stk::mesh::BulkData&
00066     bulkData = *(topology.getBulkData());
00067 
00068   // Node rank should be 0 and element rank should be equal to the dimension of the
00069   // system (e.g. 2 for 2D meshes and 3 for 3D meshes)
00070   //std::cout << "Node Rank: "<< nodeRank << ", Element Rank: " << getCellRank() << "\n";
00071 
00072   // Print element connectivity before the mesh topology is modified
00073   std::cout << "*************************\n"
00074        << "Before element separation\n"
00075        << "*************************\n";
00076 
00077   // Start the mesh update process
00078   // Will fully separate the elements in the mesh by replacing element nodes
00079   // Get a vector containing the element set of the mesh.
00080   std::vector<stk::mesh::Entity*> element_lst;
00081   stk::mesh::get_entities(bulkData,topology.getCellRank(),element_lst);
00082 
00083   // Modifies mesh for graph algorithm
00084   // Function must be called each time before there are changes to the mesh
00085   topology.removeNodeRelations();
00086 
00087   // Check for failure criterion
00088   std::map<stk::mesh::EntityKey, bool> entity_open;
00089   topology.setEntitiesOpen(entity_open);
00090   std::string gviz_output = LCM::parallelize_string("output") + ".dot";
00091   topology.outputToGraphviz(gviz_output);
00092 
00093   // test the functions of the class
00094   bulkData.modification_begin();
00095 
00096   // begin mesh fracture
00097   std::cout << "begin mesh fracture\n";
00098   topology.splitOpenFaces(entity_open);
00099 
00100   //std::string gviz_output = "output.dot";
00101   //topology.output_to_graphviz(gviz_output,entity_open);
00102 
00103   // Recreates connectivity in stk mesh expected by Albany_STKDiscretization
00104   // Must be called each time at conclusion of mesh modification
00105   topology.restoreElementToNodeConnectivity();
00106 
00107   // End mesh update
00108   bulkData.modification_end();
00109 
00110 
00111   std::cout << "*************************\n"
00112        << "After element separation\n"
00113        << "*************************\n";
00114 
00115   // Need to update the mesh to reflect changes in duplicate_entity routine.
00116   //   Redefine connectivity and coordinate arrays with updated values.
00117   //   Mesh must only have relations between elements and nodes.
00118   Teuchos::RCP<Albany::AbstractDiscretization> discretization_ptr =
00119     topology.getDiscretization();
00120   Albany::STKDiscretization & stk_discretization =
00121     static_cast<Albany::STKDiscretization &>(*discretization_ptr);
00122 
00123   Teuchos::ArrayRCP<double>
00124     coordinates = stk_discretization.getCoordinates();
00125 
00126   // Separate the elements of the mesh to illustrate the
00127   //   disconnected nature of the final mesh
00128 
00129   // Create a vector to hold displacement values for nodes
00130   Teuchos::RCP<const Epetra_Map> dof_map = stk_discretization.getMap();
00131   Epetra_Vector displacement = Epetra_Vector(*(dof_map),true);
00132 
00133   // Add displacement to nodes
00134   stk::mesh::get_entities(bulkData,topology.getCellRank(),element_lst);
00135 
00136   // displacement scale factor
00137   double alpha = 0.5;
00138 
00139   for (int i = 0; i < element_lst.size(); ++i){
00140     std::vector<double> centroid(3);
00141     std::vector<double> disp(3);
00142     stk::mesh::PairIterRelation relations = 
00143       element_lst[i]->relations(LCM::NODE_RANK);
00144     // Get centroid of the element
00145     for (int j = 0; j < relations.size(); ++j){
00146       stk::mesh::Entity & node = *(relations[j].entity());
00147       int id = static_cast<int>(node.identifier());
00148       centroid[0] += coordinates[id*3-3];
00149       centroid[1] += coordinates[id*3-2];
00150       centroid[2] += coordinates[id*3-1];
00151     }
00152     centroid[0] /= relations.size();
00153     centroid[1] /= relations.size();
00154     centroid[2] /= relations.size();
00155 
00156     // Determine displacement
00157     for (int j = 0; j < 3; ++j){
00158       disp[j] = alpha*centroid[j];
00159     }
00160 
00161     // Add displacement to nodes
00162     for (int j = 0; j < relations.size(); ++j){
00163       stk::mesh::Entity & node = *(relations[j].entity());
00164       int id = static_cast<int>(node.identifier());
00165       displacement[id*3-3] += disp[0];
00166       displacement[id*3-2] += disp[1];
00167       displacement[id*3-1] += disp[2];
00168     }
00169   }
00170 
00171   stk_discretization.setResidualField(displacement);
00172 
00173   Teuchos::RCP<Epetra_Vector>
00174     solution_field = stk_discretization.getSolutionField();
00175 
00176   // Write final mesh to exodus file
00177   // second arg to output is (pseudo)time
00178 //  stk_discretization.outputToExodus(*solution_field, 1.0);
00179   stk_discretization.writeSolution(*solution_field, 1.0);
00180 
00181   return 0;
00182 
00183 }

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