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

BarycentricSubdivision.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 
00007 // Define only if LCM is enabled
00008 #if defined (ALBANY_LCM)
00009 
00010 #include <stk_mesh/base/FieldData.hpp>
00011 #include "Topology.h"
00012 
00013 // FIXME: need to extract Topology member functions specific to 
00014 // Barycentric subdivision and move into their own header!
00015 
00016 namespace LCM {
00017 
00018   //----------------------------------------------------------------------------
00019   //
00020   // \brief Determine highest id number for each entity rank.
00021   // Used to assign unique ids to newly created entities
00022   //
00023   void 
00024   Topology::setHighestIds()
00025   {
00026     // Get space dimension by querying the STK discretization.
00027     Albany::STKDiscretization &
00028       stk_discretization =
00029       static_cast<Albany::STKDiscretization &>(*discretization_);
00030 
00031     const unsigned int number_dimensions =
00032       stk_discretization.getSTKMeshStruct()->numDim;
00033 
00034     highest_ids_.resize(number_dimensions);
00035 
00036     for (unsigned int rank = 0; rank < number_dimensions; ++rank) {
00037       highest_ids_[rank] = getNumberEntitiesByRank(*getBulkData(), rank);
00038     }
00039 
00040     return;
00041   }
00042 
00043   //----------------------------------------------------------------------------
00044   //
00045   // \brief Adds a new entity of rank 3 to the mesh
00046   //
00047   void
00048   Topology::addElement(EntityRank entity_rank)
00049   {
00050     stk::mesh::PartVector part_vector(1);
00051     part_vector[0] = stk_mesh_struct_->partVec[0];
00052     const unsigned int entity_id = ++highest_ids_[entity_rank];
00053     getBulkData()->declare_entity(entity_rank,
00054                                entity_id, 
00055                                part_vector);
00056 
00057     return;
00058   }
00059 
00060   //----------------------------------------------------------------------------
00061   //
00062   // \brief creates several entities at a time. The information about
00063   // the type of entity and and the amount of entities is contained
00064   // in the input vector called: "requests"
00065   //
00066   void
00067   Topology::addEntities(std::vector<size_t> & requests )
00068   {
00069     stk::mesh::EntityVector newEntity;
00070     getBulkData()->generate_new_entities(requests,newEntity);
00071     return;
00072   }
00073 
00074 
00075   //----------------------------------------------------------------------------
00076   //
00077   // \brief Removes an entity and all its connections
00078   //
00079   void 
00080   Topology::removeEntity(Entity & entity)
00081   {
00082     //Destroy all relations to or from the entity
00083     Entity * entities = &entity;
00084     stk::mesh::PairIterRelation relations = entity.relations();
00085     stk::mesh::PairIterRelation::iterator iterator_entity_relations;
00086 
00087     for(iterator_entity_relations = relations.begin();
00088         iterator_entity_relations != relations.end();++iterator_entity_relations){
00089       EdgeId edgeId = iterator_entity_relations->identifier();
00090       Entity & target = *(iterator_entity_relations->entity());
00091       getBulkData()->destroy_relation(entity, target, edgeId);
00092     }
00093     // remove the entity from stk mesh
00094     bool deleted = getBulkData()->destroy_entity(entities);
00095     assert(deleted);
00096     return;
00097   }
00098 
00099   //----------------------------------------------------------------------------
00100   //
00101   // \brief Adds a relation between two entities
00102   //
00103   void 
00104   Topology::addRelation(Entity & source_entity, Entity & target_entity,
00105                               EdgeId local_relation_id)
00106   {
00107     getBulkData()->declare_relation(source_entity, target_entity,
00108                                 local_relation_id);
00109     return;
00110   }
00111 
00112   //----------------------------------------------------------------------------
00113   //
00114   // \brief Removes the relation between two entities
00115   //
00116   void 
00117   Topology::removeRelation(Entity & source_entity, Entity & target_entity,
00118                            EdgeId local_relation_id)
00119   {
00120     getBulkData()->destroy_relation(source_entity, target_entity,
00121                                 local_relation_id);
00122     return;
00123   }
00124 
00125   //----------------------------------------------------------------------------
00126   //
00127   // \brief Returns a vector with all the actual mesh entities of a
00128   // specific rank
00129   //
00130   std::vector<Entity*> 
00131   Topology::getEntitiesByRank(const stk::mesh::BulkData & mesh, 
00132                               EntityRank entity_rank)
00133   {
00134     std::vector<Entity*> entities;
00135     const std::vector<stk::mesh::Bucket*> & ks = mesh.buckets(entity_rank);
00136     entities.clear();
00137     size_t count = 0;
00138     const std::vector<stk::mesh::Bucket*>::const_iterator ie = ks.end();
00139     std::vector<stk::mesh::Bucket*>::const_iterator ik = ks.begin();
00140 
00141     for (; ik != ie; ++ik) {
00142       count += (*ik)->size();
00143     }
00144     entities.reserve(count);
00145 
00146     ik = ks.begin();
00147     for (; ik != ie; ++ik) {
00148       const stk::mesh::Bucket & k = **ik;
00149       size_t n = k.size();
00150       for (size_t i = 0; i < n; ++i) {
00151         entities.push_back(&k[i]);
00152       }
00153     }
00154     return entities;
00155   }
00156 
00157   //----------------------------------------------------------------------------
00158   //
00159   // \brief This returns the number of entities on the former mesh of
00160   // a given rank
00161   //
00162   std::vector<Entity*>::size_type 
00163   Topology::getNumberEntitiesByRank(const stk::mesh::BulkData & mesh, 
00164                                     EntityRank entity_rank)
00165   {
00166     return mesh.buckets(entity_rank).size();
00167   }
00168 
00169   //----------------------------------------------------------------------------
00170   //
00171   // \brief Gets the local relation id (0,1,2,...) between two entities
00172   //
00173   EdgeId 
00174   Topology::getLocalRelationId(const Entity & source_entity,
00175                                       const Entity & target_entity)
00176   {
00177 
00178     EdgeId local_id;
00179     const stk::mesh::PairIterRelation &source_relations = source_entity.relations();
00180     unsigned int target_entity_identifier = target_entity.identifier();
00181     unsigned int target_entity_entity_rank = target_entity.entity_rank();
00182 
00183     stk::mesh::PairIterRelation::iterator iterator_source_relations;
00184     for (iterator_source_relations = source_relations.begin(); 
00185          iterator_source_relations!=source_relations.end(); 
00186          iterator_source_relations++) {
00187       const Entity *entity = iterator_source_relations->entity();
00188       if (entity->identifier()
00189           == target_entity_identifier
00190           && entity->entity_rank()
00191           == target_entity_entity_rank) {
00192         local_id = iterator_source_relations->identifier();
00193       }
00194     }
00195     return local_id;
00196   }
00197 
00198   //----------------------------------------------------------------------------
00199   //
00200   // \brief Returns the total number of lower rank entities connected
00201   // to a specific entity
00202   //
00203   int 
00204   Topology::getNumberLowerRankEntities(const Entity & entity)
00205   {
00206 
00207     unsigned int count = 0;
00208     const stk::mesh::PairIterRelation &entity_relations = entity.relations();
00209     unsigned int entity_rank=entity.entity_rank();
00210 
00211     stk::mesh::PairIterRelation::iterator iterator_relations;
00212     for(iterator_relations=entity_relations.begin(); 
00213         iterator_relations!=entity_relations.end(); 
00214         iterator_relations++){
00215       if(entity_rank > iterator_relations->entity()->entity_rank()) count++;
00216     }
00217 
00218     return count;
00219   }
00220 
00221   //----------------------------------------------------------------------------
00222   //
00223   // \brief Returns a group of entities connected directly to a given
00224   //  entity. The input rank is the rank of the returned entities.
00225   //
00226   std::vector<Entity*> 
00227   Topology::getDirectlyConnectedEntities(const Entity & entity, 
00228                                          EntityRank entity_rank)
00229   {
00230     std::vector<Entity*> returned_entities;
00231     const stk::mesh::PairIterRelation &entity_relations = entity.relations();
00232     stk::mesh::PairIterRelation::iterator iterator_relations;
00233 
00234     for(iterator_relations=entity_relations.begin();
00235         iterator_relations!=entity_relations.end();
00236         iterator_relations++){
00237       if(iterator_relations->entity_rank() == entity_rank){
00238         returned_entities.push_back(iterator_relations->entity());
00239       }
00240     }
00241     return returned_entities;
00242   }
00243 
00244   //----------------------------------------------------------------------------
00245   //
00246   // \brief Checks if an entity exists inside a specific
00247   // vector. returns "true" if the entity exists in the vector of entities
00248   //
00249   bool
00250   Topology::findEntityInVector(std::vector<Entity*> & entities,
00251                                Entity * entity)
00252   {
00253     std::vector<Entity*>::iterator iterator_entities;
00254     bool is_in_vector(false);
00255     for (iterator_entities = entities.begin();
00256          iterator_entities != entities.end(); 
00257          ++iterator_entities) {
00258       if (*iterator_entities == entity) {
00259         is_in_vector = true;
00260         break;
00261       }
00262     }
00263     return is_in_vector;
00264   }
00265 
00266   //----------------------------------------------------------------------------
00267   //
00268   //  \brief Returns a group of entities connected indirectly to a
00269   //  given entity.  e.g. of returns: nodes that belong to a face
00270   //  segments or nodes that belong to an element The input rank is
00271   //  the rank of the returned entities.  The input rank must be lower
00272   //  than that of the input entity
00273   //
00274   //
00275   std::vector<Entity*>
00276   Topology::getBoundaryEntities(const Entity & entity,
00277                                 EntityRank entity_rank)
00278   {
00279 
00280     EntityRank given_entity_rank = entity.entity_rank();
00281     //Get entities of  "given_entity_rank -1"
00282     std::vector<std::vector<Entity*> > boundary_entities(given_entity_rank + 1);
00283     boundary_entities[given_entity_rank - 1] = 
00284       getDirectlyConnectedEntities(entity, given_entity_rank - 1);
00285     std::vector<Entity*>::iterator iterator_entities1;
00286     std::vector<Entity*>::iterator iterator_entities2;
00287     std::vector<Entity*> temp_vector1;
00288     for (unsigned int ii = given_entity_rank - 1; ii > entity_rank; ii--) {
00289       for (iterator_entities1 = boundary_entities[ii].begin();
00290            iterator_entities1 != boundary_entities[ii].end();
00291            ++iterator_entities1) {
00292         temp_vector1 = getDirectlyConnectedEntities(*(*iterator_entities1),
00293                                                        ii - 1);
00294         for (iterator_entities2 = temp_vector1.begin();
00295              iterator_entities2 != temp_vector1.end(); ++iterator_entities2) {
00296           // If the entity pointed to by iterator_entities2 is not in boundary_entities[ii - 1],
00297           // add it to the vector
00298           if (!findEntityInVector(boundary_entities[ii - 1],
00299                                     *iterator_entities2) ) {
00300             boundary_entities[ii - 1].push_back(*iterator_entities2);
00301           }
00302         }
00303         temp_vector1.clear();
00304       }
00305     }
00306     return boundary_entities[entity_rank];
00307   }
00308 
00309   //----------------------------------------------------------------------------
00310   //
00311   // \brief Checks if a segment is connected to an input node. Returns "true" if segment is connected to the node.
00312   //
00313   bool
00314   Topology::segmentIsConnected(const Entity & segment,
00315                                    Entity * node)
00316   {
00317     // NOT connected is the default
00318     bool is_connected(false);
00319     std::vector<Entity*> segment_nodes = getBoundaryEntities(segment, 0);
00320     std::vector<Entity*>::iterator Iterator_nodes;
00321     for (Iterator_nodes = segment_nodes.begin();
00322          Iterator_nodes != segment_nodes.end(); ++Iterator_nodes) {
00323       if (*Iterator_nodes == node) {
00324         // segment IS connected
00325         is_connected = true;
00326       }
00327     }
00328     return is_connected;
00329   }
00330 
00331   //----------------------------------------------------------------------------
00332   //
00333   // \brief Finds the adjacent segments to a given segment. The
00334   // adjacent segments are connected to a given common point.  it
00335   // returns adjacent segments
00336   //
00337   std::vector<Entity*>
00338   Topology::findAdjacentSegments(const Entity & segment,
00339                                  Entity * node)
00340   {
00341 
00342     std::vector<Entity*>::iterator Iterator_seg_nodes;
00343     std::vector<Entity*>::iterator Iterator_adj_nodes;
00344     std::vector<Entity*>::iterator Iterator_adj_seg;
00345     std::vector<Entity*> adjacent_segments;
00346     std::vector<Entity*> adjacent_segments_final;
00347 
00348     //Obtain the nodes corresponding to the input segment
00349     std::vector<Entity*> input_segment_nodes = 
00350       getDirectlyConnectedEntities(segment, 0);
00351     //Find the segments connected to "input_segment_nodes"
00352     for (Iterator_adj_nodes = input_segment_nodes.begin();
00353          Iterator_adj_nodes != input_segment_nodes.end();
00354          ++Iterator_adj_nodes) {
00355       adjacent_segments = 
00356         getDirectlyConnectedEntities(*(*Iterator_adj_nodes), 1);
00357       //Which segment is connected to the input node?
00358       for (Iterator_adj_seg = adjacent_segments.begin();
00359            Iterator_adj_seg != adjacent_segments.end(); 
00360            ++Iterator_adj_seg) {
00361         if (segmentIsConnected(*(*Iterator_adj_seg), node)) {
00362           adjacent_segments_final.push_back(*Iterator_adj_seg);
00363         }
00364       }
00365     }
00366     return adjacent_segments_final;
00367   }
00368 
00369   //----------------------------------------------------------------------------
00370   //
00371   // \brief Returns all the 3D entities connected to a given face
00372   //
00373   std::vector<Entity*>
00374   Topology::findCellRelations(const Entity & face)
00375   {
00376     std::vector<Entity*> entities_3d;
00377     const stk::mesh::PairIterRelation & relations = face.relations();
00378     stk::mesh::PairIterRelation::iterator iterator_relations;
00379 
00380     for (iterator_relations = relations.begin();
00381          iterator_relations != relations.end();
00382          ++iterator_relations) {
00383       if (iterator_relations->entity()->entity_rank() == 3) {
00384         entities_3d.push_back(iterator_relations->entity());
00385       }
00386     }
00387     return entities_3d;
00388   }
00389 
00390   //----------------------------------------------------------------------------
00391   //
00392   // \brief Returns all the segments at the boundary of a given
00393   // element. Including those connected between the faces barycenters
00394   // and the faces boundary nodes
00395   //
00396   std::vector<Entity*> Topology::findSegmentsFromElement(const Entity & element)
00397   {
00398     std::vector<Entity*> element_faces;
00399     std::vector<Entity*> element_node;
00400     std::vector<Entity*> node_segments;
00401     std::vector<Entity*> _segments;
00402     std::vector<Entity*> outer_segments;
00403     std::vector<Entity*>::const_iterator iterator_element_faces;
00404     std::vector<Entity*>::const_iterator iterator_node_segments;
00405     std::vector<Entity*>::const_iterator iterator_outer_segments;
00406 
00407     element_faces = getBoundaryEntities(element, 2);
00408     for (iterator_element_faces = element_faces.begin();
00409          iterator_element_faces != element_faces.end();
00410          ++iterator_element_faces) {
00411       element_node = getDirectlyConnectedEntities(*(*iterator_element_faces),
00412                                                      0);
00413       node_segments = getDirectlyConnectedEntities(*(element_node[0]), 1);
00414       for (iterator_node_segments = node_segments.begin();
00415            iterator_node_segments != node_segments.end();
00416            ++iterator_node_segments) {
00417         _segments.push_back(*iterator_node_segments);
00418       }
00419     }
00420     outer_segments = getBoundaryEntities(element, 1);
00421     for (iterator_outer_segments = outer_segments.begin();
00422          iterator_outer_segments != outer_segments.end();
00423          ++iterator_outer_segments) {
00424       _segments.push_back(*iterator_outer_segments);
00425     }
00426     return _segments;
00427   }
00428 
00429 
00430   // FIXME - I don't know what to do with this.  
00431   //----------------------------------------------------------------------------
00432   //
00433   // \brief Returns true if the input faces have two points in common
00434   //
00435   bool 
00436   Topology::facesShareTwoPoints(const Entity & face1, const Entity & face2)
00437   {
00438     std::vector<Entity*> face1_nodes;
00439     std::vector<Entity*> face2_nodes;
00440     std::vector<Entity*> common_nodes;
00441     std::vector<Entity*>::iterator iterator_entity_faces;
00442 
00443     face1_nodes = getBoundaryEntities(face1, 0);
00444     face2_nodes = getBoundaryEntities(face2, 0);
00445     bool num = false;
00446     for(iterator_entity_faces = face2_nodes.begin();
00447         iterator_entity_faces != face2_nodes.end();
00448         ++iterator_entity_faces) {
00449       // If the entity pointed to by iterator_entity_faces is in the vector face1_nodes,
00450       // save the entity in common_nodes
00451       if ( findEntityInVector(face1_nodes, *iterator_entity_faces) ) {
00452         common_nodes.push_back(*iterator_entity_faces);
00453       }
00454     }
00455     if (common_nodes.size() == 2) {
00456       num = true;
00457     }
00458     return num;
00459   }
00460 
00461   //----------------------------------------------------------------------------
00462   //
00463   // \brief returns the adjacent segments from a given face
00464   //
00465   std::vector<Entity*>
00466   Topology::findAdjacentSegmentsFromFace(const std::vector<std::vector<Entity*> > & faces_inside_element, 
00467                                          const Entity & face,
00468                                          const int element_number){
00469     std::vector<Entity*> adjacent_faces;
00470     std::vector<Entity*>::const_iterator iterator_element_internal_faces;
00471     std::vector<Entity*> _element_internal_faces = 
00472       faces_inside_element[element_number];
00473 
00474     for (iterator_element_internal_faces = _element_internal_faces.begin();
00475          iterator_element_internal_faces != _element_internal_faces.end();
00476          ++iterator_element_internal_faces) {
00477       //Save the face the iterator points to if it shares two points with "face"
00478       if ( facesShareTwoPoints(face, *(*iterator_element_internal_faces)) ) {
00479         adjacent_faces.push_back(*iterator_element_internal_faces);
00480       }
00481     }
00482     return adjacent_faces;
00483   }
00484 
00485   //----------------------------------------------------------------------------
00486   //
00487   // \brief Returns a pointer with the coordinates of a given entity
00488   //
00489   double*
00490   Topology::getPointerOfCoordinates(Entity * entity)
00491   {
00492 
00493     Teuchos::RCP<Albany::AbstractDiscretization> discretization_ptr =
00494       getDiscretization();
00495     Albany::STKDiscretization & stk_discretization =
00496       static_cast<Albany::STKDiscretization &>(*discretization_ptr);
00497     //Obtain the stkMeshStruct
00498     Teuchos::RCP<Albany::AbstractSTKMeshStruct> stkMeshStruct =
00499       stk_discretization.getSTKMeshStruct();
00500     //Create the pointer of coordinates
00501     double* pointer_coordinates =
00502       stk::mesh::field_data(*stkMeshStruct->getCoordinatesField(), *entity);
00503 
00504     return pointer_coordinates;
00505   }
00506 
00507   //----------------------------------------------------------------------------
00508   //
00509   // \brief Returns a vector with the corresponding former boundary
00510   // nodes of an input entity of rank 3
00511   //
00512 
00513   std::vector<Entity*> Topology::getFormerElementNodes(const Entity & element,
00514                                                        const std::vector<std::vector<Entity*> > & entities)
00515   {
00516     std::vector<Entity*> vector_nodes_;
00517     std::vector<Entity*> boundary_nodes;
00518     std::vector<Entity*>::iterator iterator_nodes;
00519     vector_nodes_ = entities[element.identifier()];
00520 
00521     for (iterator_nodes = vector_nodes_.begin();
00522          iterator_nodes != vector_nodes_.end();++iterator_nodes){
00523       boundary_nodes.push_back(*iterator_nodes);
00524     }
00525     return boundary_nodes;
00526   }
00527 
00528   //----------------------------------------------------------------------------
00529   //
00530   // \brief Generates the coordinate of a given barycenter "entities"
00531   // is a vector with the entities of rank "0" that belong to the same
00532   // higher rank entity connected to the barycenter(e.g segment, face,
00533   // or element)
00534   //
00535   void
00536   Topology::computeBarycentricCoordinates(const std::vector<Entity*> & entities,
00537                                Entity * barycenter)
00538   {
00539 
00540     //vector of pointers
00541     std::vector<double*> vector_pointers;
00542     std::vector<Entity*>::const_iterator iterator_entities;
00543     //Copy all the fields from entity1 to the new middle node called "barycenter"
00544     getBulkData()->copy_entity_fields(*entities[0], *barycenter);
00545 
00546     //With the barycenter coordinate initialized, take the average between the entities that belong to
00547     //the vector called: "entities"
00548     for (iterator_entities = entities.begin();iterator_entities != entities.end();
00549          ++iterator_entities){
00550       vector_pointers.push_back(getPointerOfCoordinates(*iterator_entities));
00551     }
00552 
00553     //Pointer with coordinates without average
00554     std::vector<double> coordinates_(3);
00555     for (unsigned int ii = 0; ii < vector_pointers.size(); ++ii) {
00556       coordinates_[0] += vector_pointers[ii][0];
00557       coordinates_[1] += vector_pointers[ii][1];
00558       coordinates_[2] += vector_pointers[ii][2];
00559     }
00560 
00561     //Pointer with the barycenter coordinates
00562     double* barycenter_coordinates = getPointerOfCoordinates(barycenter);
00563     barycenter_coordinates[0] = coordinates_[0] / (1.0 * entities.size());
00564     barycenter_coordinates[1] = coordinates_[1] / (1.0 * entities.size());
00565     barycenter_coordinates[2] = coordinates_[2] / (1.0 * entities.size());
00566 
00567     return;
00568   }
00569 
00570   //----------------------------------------------------------------------------
00571   //
00572   // \brief Barycentric subdivision of simplicial meshes
00573   //
00574   void Topology::barycentricSubdivision()
00575   {
00576     // Use to assign unique ids
00577     setHighestIds();
00578 
00579     // Begin mesh update
00580     getBulkData()->modification_begin();
00581 
00582     //--------------------------------------------------------------------------
00583     // I. Divide all the segments of the mesh by half
00584     // initial_entities_0D: Vector with all the entities of rank "0"
00585     // (nodes) required to divide the original mesh segments by half
00586     // initial_entities_1D: Vector that contains all the entities of
00587     // rank "1" (segments) of the original mesh modified1_entities_1D:
00588     // Vector with all the segments required to divide the original
00589     // mesh segments by half initial_entities_3d: vector with all the
00590     // elements of the former mesh Assign coordinates to the new nodes
00591     // needed to divide the segments by half
00592     // -------------------------------------------------------------------------
00593 
00594     //MEASURING TIME
00595     clock_t start1, end1;
00596     double cpu_time_used1;
00597     start1 = clock();
00598 
00599     //Get the segments from the original mesh
00600     std::vector<Entity*>
00601     initial_entities_1D = getEntitiesByRank(*(getBulkData()), 1);
00602     std::vector<Entity*> vector_nodes;
00603 
00604     //Adding nodes to divide segments by half
00605     std::vector<size_t> requests1(getSpaceDimension() + 1, 0);
00606     requests1[0] = initial_entities_1D.size();
00607     std::vector<size_t> requests_step1_1(getSpaceDimension() + 1, 0);
00608     requests_step1_1[0] = initial_entities_1D.size();
00609     addEntities(requests_step1_1);
00610 
00611     std::vector<Entity*>
00612     initial_entities_0D = getEntitiesByRank(*(getBulkData()), 0);
00613 
00614     //vector with all elements from former mesh. This is used in step VI
00615     std::vector<Entity*>
00616     initial_entities_3d = getEntitiesByRank(*(getBulkData()), 3);
00617     //Create a vector of vectors that contains all the former boundary nodes of all the elements of the mesh
00618     std::vector<std::vector<Entity*> >
00619     all_elements_boundary_nodes1(initial_entities_3d.size() + 1);
00620     //temporary vector //check the values inside this vector
00621     for (unsigned int ii = 0; ii < initial_entities_3d.size(); ++ii) {
00622       all_elements_boundary_nodes1[ii + 1] =
00623           getBoundaryEntities(*(initial_entities_3d[ii]), 0);
00624     }
00625 
00626     for (unsigned int ii = 0; ii < initial_entities_1D.size(); ++ii) {
00627       //Create a vector with all the initial nodes connected to a segment
00628       vector_nodes = getDirectlyConnectedEntities(*(initial_entities_1D[ii]),
00629                                                      0);
00630       //Look for all the relations of each segment
00631       stk::mesh::PairIterRelation _relations =
00632         initial_entities_1D[ii]->relations();
00633       for (unsigned int i = 0; i < _relations.size(); ++i) {
00634         if (_relations[i].entity()->entity_rank() == 0
00635             && getLocalRelationId(*(initial_entities_1D[ii]),
00636                                      *(_relations[i].entity())) == 1) {
00637           //Add a blue(local relation) connection. This is only for reference
00638           addRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00639                        2);
00640           //Remove the relation between the former segment and node
00641           removeRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00642                           1);
00643           //Add a relation from the former segment to a new node
00644           addRelation(*(initial_entities_1D[ii]), *(initial_entities_0D[ii]),
00645                        1);
00646         }
00647       }
00648       //Assign coordinates to the new nodes
00649       computeBarycentricCoordinates(vector_nodes, initial_entities_0D[ii]);
00650     }
00651 
00652 
00653     //Adding segments
00654     std::vector<size_t> requests_step1_2(getSpaceDimension() + 1, 0);
00655     requests_step1_2[1] = initial_entities_1D.size();
00656     addEntities(requests_step1_2);
00657     std::vector<Entity*>
00658     modified1_entities_1D = getEntitiesByRank(*(getBulkData()), 1);
00659 
00660     for (unsigned int ii = 0; ii < initial_entities_1D.size(); ++ii) {
00661       //Look for all the relations of each segment
00662       stk::mesh::PairIterRelation _relations =
00663         initial_entities_1D[ii]->relations();
00664       for (unsigned int i = 0; i < _relations.size(); ++i) {
00665         if (_relations[i].entity()->entity_rank() == 0
00666             && getLocalRelationId(*(initial_entities_1D[ii]),
00667                                      *(_relations[i].entity())) == 2) {
00668           //Add a relation between the new segment and a node
00669           addRelation(*(modified1_entities_1D[ii]), *(_relations[i].entity()),
00670                        0);
00671           //Remove this connection. This was only for reference
00672           removeRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00673                           2);
00674           //Add a relation between the new segment and the "middle" node
00675           addRelation(*(modified1_entities_1D[ii]), *(initial_entities_0D[ii]),
00676                        1);
00677         }
00678       }
00679     }
00680 
00681     //Adding the new segments to its corresponding faces
00682     //The segments can be connected to 1 one or more faces
00683     for (unsigned int ii = 0; ii < initial_entities_1D.size(); ++ii) {
00684       stk::mesh::PairIterRelation _relations =
00685         initial_entities_1D[ii]->relations();
00686       for (unsigned int i = 0; i < _relations.size(); ++i) {
00687         if (_relations[i].entity()->entity_rank() == 2) {
00688           addRelation(*(_relations[i].entity()), *(modified1_entities_1D[ii]),
00689                        getNumberLowerRankEntities(*(_relations[i].entity())));
00690         }
00691       }
00692     }
00693 
00694     //Get the former faces from the mesh
00695     std::vector<Entity*>
00696     initial_entities_2D = getEntitiesByRank(*(getBulkData()), 2);
00697     //Calculate the final number of segments per face after the division of the segments
00698     const stk::mesh::PairIterRelation & _relations =
00699       initial_entities_2D[0]->relations();
00700     stk::mesh::PairIterRelation::iterator iterator_Relations_;
00701     std::vector<Entity*> segments;
00702     for (iterator_Relations_ = _relations.begin();
00703          iterator_Relations_ != _relations.end();++iterator_Relations_){
00704       if (iterator_Relations_->entity()->entity_rank() == 1) {
00705         segments.push_back(iterator_Relations_->entity());
00706       }
00707     }
00708 
00709     //Number of segments per face after division by half
00710     unsigned int Num_segments_face = segments.size();
00711 
00712     //MEASURING TIME
00713     end1 = clock();
00714     cpu_time_used1 = ((double) (end1 - start1)) / CLOCKS_PER_SEC;
00715     std::cout << std::endl;
00716     std::cout << "First part takes "
00717               << cpu_time_used1 << " seconds"<<std::endl;
00718     //--------------------------------------------------------------------------
00719     // II.Connect the new center nodes to the center of the face
00720     // mofified1_entities_0D: Vector of nodes that includes all the
00721     // ones up the "node centers of the faces" initial_entities_2D:
00722     // Vector with the faces of the original mesh Add the
00723     // corresponding coordinates to the barycenters of all faces
00724     // --------------------------------------------------------------------------
00725     // MEASURING TIME
00726     clock_t start2, end2;
00727     double cpu_time_used2;
00728     start2 = clock();
00729     //Adding new nodes to the centers of the faces of the original mesh
00730     std::vector<size_t> requests_step2(getSpaceDimension() + 1, 0);
00731     requests_step2[0] = initial_entities_2D.size();
00732     addEntities(requests_step2);
00733 
00734     std::vector<Entity*>
00735     modified1_entities_0D = getEntitiesByRank(*(getBulkData()), 0);
00736 
00737     for (unsigned int ii = 0; ii < initial_entities_2D.size(); ++ii) {
00738       //Connect the node to its corresponding face
00739       addRelation(*(initial_entities_2D[ii]), *(modified1_entities_0D[ii]),
00740                    getNumberLowerRankEntities(*(initial_entities_2D[ii])));
00741     }
00742 
00743     //Add the corresponding coordinates to the barycenters of all faces
00744     std::vector<Entity*> boundary_nodes;
00745     for (unsigned int ii = 0; ii < initial_entities_2D.size(); ++ii) {
00746       boundary_nodes = getBoundaryEntities(*(initial_entities_2D[ii]), 0);
00747       computeBarycentricCoordinates(boundary_nodes, modified1_entities_0D[ii]);
00748     }
00749     //MEASURING TIME
00750     end2 = clock();
00751     cpu_time_used2 = ((double) (end2 - start2)) / CLOCKS_PER_SEC;
00752     std::cout << std::endl;
00753     std::cout << "The second part takes "
00754               << cpu_time_used2 << " seconds"<<std::endl;
00755     //--------------------------------------------------------------------------
00756     // III. For each face start creating new segments that will
00757     // connect the center point of the face with with all the points
00758     // at its boundary modified2_entities_1D: Vector with all the
00759     // segments up the new ones defined in III.
00760     // vector_boundary_points: Vector with all the boundary nodes of
00761     // all faces of the element New_Boundary_segments: Number of new
00762     // segments that connect the centroid of each face with the points
00763     // at the face's boundary
00764     //--------------------------------------------------------------------------
00765 
00766     //MEASURING TIME
00767     clock_t start3, end3;
00768     double cpu_time_used3;
00769     start3 = clock();
00770     // Add the new segments that will connect the center point with the
00771     // points at the boundary
00772     const int New_Boundary_segments =
00773       (getDirectlyConnectedEntities(*initial_entities_2D[0],1).size())*(initial_entities_2D.size());
00774     std::vector<size_t> requests_step3(getSpaceDimension() + 1, 0);
00775     requests_step3[1] = New_Boundary_segments;
00776     addEntities(requests_step3);
00777 
00778     //Vector that contains the latest addition of segments
00779     std::vector<Entity*> modified2_entities_1D = 
00780       getEntitiesByRank(*(getBulkData()), 1);
00781 
00782     //Vector with all the boundary nodes of all faces of the element
00783     std::vector<Entity*>::iterator iterator_entities1;
00784     std::vector<Entity*>::iterator iterator_entities2;
00785     std::vector<Entity*> vector_boundary_points1;
00786     std::vector<Entity*> vector_boundary_points;
00787     for (iterator_entities1 = initial_entities_2D.begin();
00788          iterator_entities1 != initial_entities_2D.end(); ++iterator_entities1) {
00789       //Create a vector with all the "0 rank" boundaries (nodes)
00790       vector_boundary_points1 = getBoundaryEntities(*(*iterator_entities1),
00791                                                       0);
00792       //Push all the vector of boundary points into a single one
00793       for (iterator_entities2 = vector_boundary_points1.begin();
00794            iterator_entities2 != vector_boundary_points1.end();
00795            ++iterator_entities2) {
00796         vector_boundary_points.push_back(*iterator_entities2);
00797       }
00798       vector_boundary_points1.clear();
00799     }
00800 
00801     //Connect the new segments to the corresponding nodes
00802     for (unsigned int ii = 0; ii < Num_segments_face * initial_entities_2D.size();
00803          ++ii) {
00804       //Add a relation between the segments and the center nodes
00805       addRelation(*(modified2_entities_1D[ii]),
00806                    *(modified1_entities_0D[ii / Num_segments_face]), 0);
00807       //Add a relation between the segments and the boundary nodes
00808       addRelation(*(modified2_entities_1D[ii]), *(vector_boundary_points[ii]),
00809                    1);
00810     }
00811 
00812     //Create a vector with all the boundary segments of the elements
00813     // "All_boundary_segments" and "Number_new_triangles_inside_element" used in step VIII.
00814     int Number_new_triangles_inside_element;
00815     std::vector<Entity*> All_boundary_segments;
00816     std::vector<Entity*> element_segments;
00817     std::vector<Entity*>::iterator iterator_elements_;
00818     std::vector<Entity*>::iterator iterator_element_segments;
00819     for (iterator_elements_ = initial_entities_3d.begin();
00820          iterator_elements_ != initial_entities_3d.end(); ++iterator_elements_) {
00821       element_segments = findSegmentsFromElement(*(*iterator_elements_));
00822       Number_new_triangles_inside_element = element_segments.size();
00823       for (iterator_element_segments = element_segments.begin();
00824            iterator_element_segments != element_segments.end();
00825            ++iterator_element_segments) {
00826         All_boundary_segments.push_back(*iterator_element_segments);
00827       }
00828     }
00829     //MEASURING TIME
00830     end3 = clock();
00831     cpu_time_used3 = ((double) (end3 - start3)) / CLOCKS_PER_SEC;
00832     std::cout << std::endl;
00833     std::cout << "The Third part takes "
00834               << cpu_time_used3 << " seconds"<<std::endl;
00835     //--------------------------------------------------------------------------
00836     // IV. Define the new faces at the boundary of the elements
00837     // modified1_entities_2D: Vector that contains all the faces up to
00838     // the new ones at the boundary of the elements
00839     // "all_faces_centroids" and "All_boundary_segments" defined below
00840     // -------------------------------------------------------------------------
00841     // MEASURING TIME
00842     clock_t start4, end4;
00843     double cpu_time_used4;
00844     start4 = clock();
00845     //Add the new faces
00846     std::vector<size_t> requests_step4(getSpaceDimension() + 1, 0);
00847     requests_step4[2] = Num_segments_face * initial_entities_2D.size();
00848     addEntities(requests_step4);
00849 
00850     std::vector<Entity*>
00851     modified1_entities_2D = getEntitiesByRank(*(getBulkData()), 2);
00852 
00853     //iterators
00854     std::vector<Entity*>::iterator iterator_faces;
00855     std::vector<Entity*>::iterator iterator_segments;
00856     std::vector<Entity*>::iterator iterator_nodes;
00857     //vectors
00858     std::vector<Entity*> vector_segments;
00859     std::vector<Entity*> face_centroid;
00860     std::vector<Entity*> all_boundary_segments;
00861     std::vector<Entity*> all_faces_centroids;
00862 
00863     // Put all the boundary segments in a single vector. Likewise, the
00864     // nodes.
00865     for (iterator_faces = initial_entities_2D.begin();
00866          iterator_faces != initial_entities_2D.end(); ++iterator_faces) {
00867       // vector_segments, This vector contains the boundary segments
00868       // that conform a specific face
00869       vector_segments = getDirectlyConnectedEntities(*(*iterator_faces), 1);
00870       face_centroid = getDirectlyConnectedEntities(*(*iterator_faces), 0);
00871       for (iterator_segments = vector_segments.begin();
00872            iterator_segments != vector_segments.end(); ++iterator_segments) {
00873         all_boundary_segments.push_back(*iterator_segments);
00874       }
00875       for (iterator_nodes = face_centroid.begin();
00876            iterator_nodes != face_centroid.end(); ++iterator_nodes) {
00877         all_faces_centroids.push_back(*iterator_nodes);
00878       }
00879     }
00880 
00881     //Add the new faces to its corresponding segments and elements
00882     std::vector<Entity*> adjacent_segments;
00883     std::vector<Entity*> original_face_relations_3D;
00884     std::vector<Entity*> original_face;
00885     std::vector<Entity*>::iterator iterator_entities;
00886     for (unsigned int ii = 0; ii < all_boundary_segments.size(); ++ii) {
00887       adjacent_segments = findAdjacentSegments(*all_boundary_segments[ii],
00888                                                  all_faces_centroids[ii / Num_segments_face]);
00889       addRelation(*(modified1_entities_2D[ii]), *(all_boundary_segments[ii]),
00890                    0);
00891       addRelation(*(modified1_entities_2D[ii]), *(adjacent_segments[0]), 1);
00892       addRelation(*(modified1_entities_2D[ii]), *(adjacent_segments[1]), 2);
00893 
00894       //Add the new face to its corresponding element
00895       original_face = getDirectlyConnectedEntities(
00896                                                       *(all_faces_centroids[ii / Num_segments_face]), 2);
00897 
00898       //find original_face 3D relations (entities)
00899       original_face_relations_3D = findCellRelations(*(original_face[0]));
00900       for (iterator_entities = original_face_relations_3D.begin();
00901            iterator_entities != original_face_relations_3D.end();
00902            iterator_entities++) {
00903         addRelation(*(*iterator_entities), *(modified1_entities_2D[ii]),
00904                      getNumberLowerRankEntities(*(*iterator_entities)));
00905       }
00906     }
00907 
00908     //MEASURING TIME
00909     end4 = clock();
00910     cpu_time_used4 = ((double) (end4 - start4)) / CLOCKS_PER_SEC;
00911     std::cout << std::endl;
00912     std::cout << "The Fourth part takes "
00913               << cpu_time_used4 << " seconds"<<std::endl;
00914 
00915     //--------------------------------------------------------------------------
00916     // V. Delete former mesh faces initial_entities_3d: Vector that
00917     // contains all the former elements of the mesh
00918     // All_boundary_faces:vector with all the boundary faces of all
00919     // elements.  This vector doesn't include the faces inside the
00920     // elements
00921     // --------------------------------------------------------------------------
00922     // MEASURING TIME
00923     clock_t start5, end5;
00924     double cpu_time_used5;
00925     start5 = clock();
00926     // Because "remove_entity" cannot be used to delete the relation
00927     // between faces and elements Remove first the relations between
00928     // elements and faces
00929     std::vector<Entity*>::iterator iterator_entities_3d;
00930     std::vector<Entity*>::iterator iterator_faces_centroids;
00931     for (iterator_faces_centroids = all_faces_centroids.begin();
00932          iterator_faces_centroids != all_faces_centroids.end();++iterator_faces_centroids){
00933       std::vector<Entity*> former_face = getDirectlyConnectedEntities(
00934                                                                          *(*iterator_faces_centroids), 2);
00935       std::vector<Entity*> elements = getDirectlyConnectedEntities(
00936                                                                       *(former_face[0]), 3);
00937       for (iterator_entities_3d = elements.begin();
00938            iterator_entities_3d != elements.end(); ++iterator_entities_3d) {
00939         removeRelation(*(*iterator_entities_3d), *(former_face[0]),
00940                         getLocalRelationId(*(*iterator_entities_3d), *(former_face[0])));
00941       }
00942     }
00943 
00944     //Remove the former mesh faces and all their relations
00945     std::vector<Entity*>::iterator iterator_all_faces_centroids;
00946     for (iterator_all_faces_centroids = all_faces_centroids.begin();
00947          iterator_all_faces_centroids != all_faces_centroids.end();
00948          ++iterator_all_faces_centroids){
00949       std::vector<Entity*> former_face = getDirectlyConnectedEntities(
00950                                                                          *(*iterator_all_faces_centroids), 2);
00951       removeEntity(*(former_face[0]));
00952     }
00953 
00954 
00955     //The following variables will be used in step IX
00956     //Number of faces per element "_faces_element". This number doesn't include any faces inside
00957     //the element.Only the ones at the boundary
00958     std::vector<Entity*> _faces_element;
00959     std::vector<Entity*> All_boundary_faces;
00960     std::vector<Entity*>::iterator iterator_faces_element;
00961     std::vector<Entity*>::iterator iterator_initial_entities_3d;
00962     for (iterator_initial_entities_3d = initial_entities_3d.begin();
00963          iterator_initial_entities_3d != initial_entities_3d.end();++iterator_initial_entities_3d){
00964       _faces_element = getDirectlyConnectedEntities(
00965                                                        *(*iterator_initial_entities_3d), 2);
00966       for (iterator_faces_element = _faces_element.begin();
00967            iterator_faces_element != _faces_element.end();++iterator_faces_element) {
00968         All_boundary_faces.push_back(*iterator_faces_element);
00969       }
00970     }
00971     //MEASURING TIME
00972     end5 = clock();
00973     cpu_time_used5 = ((double) (end5 - start5)) / CLOCKS_PER_SEC;
00974     std::cout << std::endl;
00975     std::cout << "The Fifth part takes "
00976               << cpu_time_used5 << " seconds"<<std::endl;
00977     //--------------------------------------------------------------------------
00978     // VI. Add a point to each element. Each point represents the
00979     // centroid of each element modified2_entities_0D: Vector that
00980     // contains all the nodes up to the centroids of all the elements
00981     // Add the coordinates of all the elements centroids
00982     // -------------------------------------------------------------------------
00983     // MEASURING TIME
00984     clock_t start6, end6;
00985     double cpu_time_used6;
00986     start6 = clock();
00987     //Add a point to each element
00988     std::vector<size_t> requests_step6(getSpaceDimension() + 1, 0);
00989     requests_step6[0] = initial_entities_3d.size();
00990     addEntities(requests_step6);
00991 
00992     std::vector<Entity*>
00993     modified2_entities_0D = getEntitiesByRank(*(getBulkData()), 0);
00994 
00995     //At this point the way the numbers are stored in the vector of nodes has changed
00996     //Thus, create a new vector with the nodes that has all the centroids of the elements
00997     std::vector<Entity*> elements_centroids;
00998     int _start = initial_entities_2D.size();
00999     int _end = initial_entities_2D.size() + initial_entities_3d.size();
01000     for (int ii = _start; ii < _end; ++ii) {
01001       elements_centroids.push_back(modified2_entities_0D[ii]);
01002     }
01003 
01004     //Add the coordinates of all the elements centroids
01005     std::vector<Entity*> boundary_nodes_elements;
01006     for (unsigned int ii = 0; ii < initial_entities_3d.size(); ++ii) {
01007       boundary_nodes_elements = 
01008         getFormerElementNodes(*(initial_entities_3d[ii]), 
01009                                  all_elements_boundary_nodes1);
01010       computeBarycentricCoordinates(boundary_nodes_elements,
01011                                     elements_centroids[ii]);
01012     }
01013 
01014     //Connect each element to the new added nodes
01015     for (unsigned int ii = 0; ii < initial_entities_3d.size(); ++ii) {
01016       //Connect the node to its corresponding element
01017       addRelation(*(initial_entities_3d[ii]), *(elements_centroids[ii]),
01018                    getNumberLowerRankEntities(*(initial_entities_3d[ii])));
01019     }
01020     //MEASURING TIME
01021     end6 = clock();
01022     cpu_time_used6 = ((double) (end6 - start6)) / CLOCKS_PER_SEC;
01023     std::cout << std::endl;
01024     std::cout << "The Sixth part takes "
01025               << cpu_time_used6 << " seconds"<<std::endl;
01026 
01027     //--------------------------------------------------------------------------
01028     // VII. For each element create new segments to connect its center
01029     // point to all the points that compose its boundary
01030     // modified3_entities_1D: Vector that contains all the segments up
01031     // to the new ones defined in step VII.
01032     // -------------------------------------------------------------------------
01033 
01034     //MEASURING TIME
01035     clock_t start7, end7;
01036     double cpu_time_used7;
01037     start7 = clock();
01038     // Add the new segments that will connect the center point with the
01039     // points at the boundary Create a vector with all the boundary
01040     // points of all the former elements of the mesh
01041     std::vector<Entity*> element_boundary_nodes;
01042     std::vector<Entity*> all_elements_boundary_nodes;
01043     std::vector<Entity*>::iterator iterator_Initial_entities_3d;
01044     std::vector<Entity*>::iterator iterator_element_boundary_nodes;
01045 
01046     for (iterator_Initial_entities_3d = initial_entities_3d.begin();
01047          iterator_Initial_entities_3d != initial_entities_3d.end(); ++iterator_Initial_entities_3d){
01048       element_boundary_nodes = getBoundaryEntities(*(*iterator_Initial_entities_3d),0);
01049       for (iterator_element_boundary_nodes = element_boundary_nodes.begin();
01050            iterator_element_boundary_nodes != element_boundary_nodes.end();++iterator_element_boundary_nodes) {
01051         all_elements_boundary_nodes.push_back(*iterator_element_boundary_nodes);
01052       }
01053     }
01054 
01055     //Add the new segments.
01056     std::vector<size_t> requests_step7(getSpaceDimension() + 1, 0);
01057     requests_step7[1] = all_elements_boundary_nodes.size();
01058     addEntities(requests_step7);
01059 
01060 
01061     //Vector that contains the latest addition of segments
01062     std::vector<Entity*>
01063     modified3_entities_1D = getEntitiesByRank(*(getBulkData()), 1);
01064 
01065     // At this point the way the numbers are stored in the vector of
01066     // segments has changed. Thus, create a new vector that contains
01067     // the segments that connect the element centroid with the element
01068     // boundary points
01069     const int Start_ = Num_segments_face * initial_entities_2D.size()
01070       + initial_entities_1D.size();
01071     const int End_ = modified3_entities_1D.size() - initial_entities_1D.size();
01072     std::vector<Entity*> segments_connected_centroid;
01073     for (int ii = Start_; ii < End_; ++ii) {
01074       segments_connected_centroid.push_back(modified3_entities_1D[ii]);
01075     }
01076 
01077     //Connect the new segments to the corresponding nodes
01078     for (unsigned int ii = 0; ii < segments_connected_centroid.size(); ++ii) {
01079       //Add a relation between the segments and the center nodes
01080       addRelation(*(segments_connected_centroid[ii]),
01081                    *(elements_centroids[ii / element_boundary_nodes.size()]), 0);
01082       //Add a relation between the segments and the boundary nodes
01083       addRelation(*(segments_connected_centroid[ii]),
01084                    *(all_elements_boundary_nodes[ii]), 1);
01085     }
01086     //MEASURING TIME
01087     end7 = clock();
01088     cpu_time_used7 = ((double) (end7 - start7)) / CLOCKS_PER_SEC;
01089     std::cout << std::endl;
01090     std::cout << "The Seventh part takes "
01091               << cpu_time_used7 << " seconds"<<std::endl;
01092 
01093     // -------------------------------------------------------------------------
01094     // VIII. Create the new faces inside each element
01095     // modified2_entities_2D: Vector with all the faces up the ones
01096     // that are inside the elements
01097     // -------------------------------------------------------------------------
01098     // MEASURING TIME
01099     clock_t start8, end8;
01100     double cpu_time_used8;
01101     start8 = clock();
01102     //Add the new faces.
01103     std::vector<size_t> requests_step8(getSpaceDimension() + 1, 0);
01104     requests_step8[2] = All_boundary_segments.size();
01105     addEntities(requests_step8);
01106 
01107     std::vector<Entity*>
01108     modified2_entities_2D = getEntitiesByRank(*(getBulkData()), 2);
01109 
01110     //Create a vector of vectors with all the faces inside the element. Each
01111     //row represents an element
01112     std::vector<std::vector<Entity*> > faces_inside_elements(initial_entities_3d.size());
01113 
01114     //Connect  the face to the corresponding segments
01115     std::vector<Entity*> adjacent_segments_inside(2);
01116     for (unsigned int ii = 0; ii < All_boundary_segments.size(); ++ii) {
01117       adjacent_segments_inside = findAdjacentSegments(*(All_boundary_segments[ii]),
01118                                                         elements_centroids[ii / Number_new_triangles_inside_element]);
01119       addRelation(*(modified2_entities_2D[ii]), *(All_boundary_segments[ii]),
01120                    0);
01121       addRelation(*(modified2_entities_2D[ii]), *(adjacent_segments_inside[0]),
01122                    1);
01123       addRelation(*(modified2_entities_2D[ii]), *(adjacent_segments_inside[1]),
01124                    2);
01125       /*
01126        *faces_inside_elements is a vector of vectors that contains
01127        *the faces inside each element. Each row contains the faces of
01128        *one specific element. The first row corresponds to the first
01129        *element, the second one to the second element, and so forth.
01130        */
01131       faces_inside_elements[ii/Number_new_triangles_inside_element].
01132         push_back(modified2_entities_2D[ii]);
01133     }
01134 
01135     //MEASURING TIME
01136     end8 = clock();
01137     cpu_time_used8 = ((double) (end8 - start8)) / CLOCKS_PER_SEC;
01138     std::cout << std::endl;
01139     std::cout << "The Eight part takes "
01140               << cpu_time_used8 << " seconds"<<std::endl;
01141 
01142     //--------------------------------------------------------------------------
01143     // IX. Delete the former elements
01144     //
01145     //--------------------------------------------------------------------------
01146     //MEASURING TIME
01147     clock_t start9, end9;
01148     double cpu_time_used9;
01149     start9 = clock();
01150     //Remove former elements from the mesh
01151     std::vector<Entity*>::iterator iterator_elements_centroids;
01152     for (iterator_elements_centroids = elements_centroids.begin();
01153          iterator_elements_centroids != elements_centroids.end();
01154          ++iterator_elements_centroids){
01155       std::vector<Entity*> former_element = getDirectlyConnectedEntities(
01156                                                                             *(*iterator_elements_centroids), 3);
01157       removeEntity(*(former_element[0]));
01158     }
01159 
01160     //MEASURING TIME
01161     end9 = clock();
01162     cpu_time_used9 = ((double) (end9 - start9)) / CLOCKS_PER_SEC;
01163     std::cout << std::endl;
01164     std::cout << "The Ninth part takes "
01165               << cpu_time_used9 << " seconds"<<std::endl;
01166 
01167     //--------------------------------------------------------------------------
01168     // X. Create the new elements modified1_entities_3d: Vector with
01169     // all the elements required to carry out the barycentric
01170     // subdivision
01171     // -------------------------------------------------------------------------
01172 
01173     const int number_new_elements = _faces_element.size()*initial_entities_3d.size();
01174 
01175     //Add the new elements
01176     for (int ii = 0; ii < number_new_elements; ++ii) {
01177       addElement(3);
01178     }
01179     std::vector<Entity*>
01180     modified1_entities_3d = getEntitiesByRank(*(getBulkData()),3);
01181 
01182     //MEASURING TIME
01183     clock_t start10, end10;
01184     double cpu_time_used10;
01185     start10 = clock();
01186     //Connect the the element with its corresponding faces
01187     std::vector<Entity*> adjacent_faces_inside(3);
01188     for (unsigned int ii = 0; ii < All_boundary_faces.size(); ++ii) {
01189       adjacent_faces_inside  = findAdjacentSegmentsFromFace(faces_inside_elements,
01190                                                              *(All_boundary_faces[ii]),(ii/_faces_element.size()));
01191       addRelation(*(modified1_entities_3d[ii]), *(All_boundary_faces[ii]), 0);
01192       addRelation(*(modified1_entities_3d[ii]), *adjacent_faces_inside[0], 1);
01193       addRelation(*(modified1_entities_3d[ii]), *adjacent_faces_inside[1], 2);
01194       addRelation(*(modified1_entities_3d[ii]), *adjacent_faces_inside[2], 3);
01195     }
01196 
01197     //MEASURING TIME
01198     end10 = clock();
01199     cpu_time_used10 = ((double) (end10 - start10)) / CLOCKS_PER_SEC;
01200     std::cout << std::endl;
01201     std::cout << "The tenth part takes "
01202               << cpu_time_used10 << "seconds"<<std::endl;
01203 
01204 
01205     //--------------------------------------------------------------------------
01206     // XI. Update the vector: connectivity_temp
01207     //--------------------------------------------------------------------------
01208     //MEASURING TIME
01209     clock_t start11, end11;
01210     double cpu_time_used11;
01211     start11 = clock();
01212     //Connectivity matrix
01213     std::vector<std::vector<Entity*> > connectivity_temp(modified1_entities_3d.size());
01214     //Add the new entities to "connectivity_temp"
01215     for (unsigned int ii = 0; ii < modified1_entities_3d.size(); ++ii) {
01216       connectivity_temp[ii] = getBoundaryEntities(*modified1_entities_3d[ii],0);
01217     }
01218     connectivity_temp_.clear();
01219     connectivity_temp_ = connectivity_temp;
01220 
01221     // End mesh update
01222     getBulkData()->modification_end();
01223     //MEASURING TIME
01224     end11 = clock();
01225     cpu_time_used11 = ((double) (end11 - start11)) / CLOCKS_PER_SEC;
01226     std::cout << std::endl;
01227     std::cout << "The Eleventh part takes "
01228               << cpu_time_used11 << " seconds"<<std::endl;
01229 
01230     return;
01231   }
01232 
01233 } // namespace LCM
01234 
01235 #endif // #if defined (ALBANY_LCM)

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