00001
00002
00003
00004
00005
00006
00007
00008 #if defined (ALBANY_LCM)
00009
00010 #include <stk_mesh/base/FieldData.hpp>
00011 #include "Topology.h"
00012
00013
00014
00015
00016 namespace LCM {
00017
00018
00019
00020
00021
00022
00023 void
00024 Topology::setHighestIds()
00025 {
00026
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
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
00063
00064
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
00078
00079 void
00080 Topology::removeEntity(Entity & entity)
00081 {
00082
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
00094 bool deleted = getBulkData()->destroy_entity(entities);
00095 assert(deleted);
00096 return;
00097 }
00098
00099
00100
00101
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
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
00128
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
00160
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
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
00201
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
00224
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
00247
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
00269
00270
00271
00272
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
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
00297
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
00312
00313 bool
00314 Topology::segmentIsConnected(const Entity & segment,
00315 Entity * node)
00316 {
00317
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
00325 is_connected = true;
00326 }
00327 }
00328 return is_connected;
00329 }
00330
00331
00332
00333
00334
00335
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
00349 std::vector<Entity*> input_segment_nodes =
00350 getDirectlyConnectedEntities(segment, 0);
00351
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
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
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
00393
00394
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
00431
00432
00433
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
00450
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
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
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
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
00498 Teuchos::RCP<Albany::AbstractSTKMeshStruct> stkMeshStruct =
00499 stk_discretization.getSTKMeshStruct();
00500
00501 double* pointer_coordinates =
00502 stk::mesh::field_data(*stkMeshStruct->getCoordinatesField(), *entity);
00503
00504 return pointer_coordinates;
00505 }
00506
00507
00508
00509
00510
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
00531
00532
00533
00534
00535 void
00536 Topology::computeBarycentricCoordinates(const std::vector<Entity*> & entities,
00537 Entity * barycenter)
00538 {
00539
00540
00541 std::vector<double*> vector_pointers;
00542 std::vector<Entity*>::const_iterator iterator_entities;
00543
00544 getBulkData()->copy_entity_fields(*entities[0], *barycenter);
00545
00546
00547
00548 for (iterator_entities = entities.begin();iterator_entities != entities.end();
00549 ++iterator_entities){
00550 vector_pointers.push_back(getPointerOfCoordinates(*iterator_entities));
00551 }
00552
00553
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
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
00573
00574 void Topology::barycentricSubdivision()
00575 {
00576
00577 setHighestIds();
00578
00579
00580 getBulkData()->modification_begin();
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 clock_t start1, end1;
00596 double cpu_time_used1;
00597 start1 = clock();
00598
00599
00600 std::vector<Entity*>
00601 initial_entities_1D = getEntitiesByRank(*(getBulkData()), 1);
00602 std::vector<Entity*> vector_nodes;
00603
00604
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
00615 std::vector<Entity*>
00616 initial_entities_3d = getEntitiesByRank(*(getBulkData()), 3);
00617
00618 std::vector<std::vector<Entity*> >
00619 all_elements_boundary_nodes1(initial_entities_3d.size() + 1);
00620
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
00628 vector_nodes = getDirectlyConnectedEntities(*(initial_entities_1D[ii]),
00629 0);
00630
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
00638 addRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00639 2);
00640
00641 removeRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00642 1);
00643
00644 addRelation(*(initial_entities_1D[ii]), *(initial_entities_0D[ii]),
00645 1);
00646 }
00647 }
00648
00649 computeBarycentricCoordinates(vector_nodes, initial_entities_0D[ii]);
00650 }
00651
00652
00653
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
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
00669 addRelation(*(modified1_entities_1D[ii]), *(_relations[i].entity()),
00670 0);
00671
00672 removeRelation(*(initial_entities_1D[ii]), *(_relations[i].entity()),
00673 2);
00674
00675 addRelation(*(modified1_entities_1D[ii]), *(initial_entities_0D[ii]),
00676 1);
00677 }
00678 }
00679 }
00680
00681
00682
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
00695 std::vector<Entity*>
00696 initial_entities_2D = getEntitiesByRank(*(getBulkData()), 2);
00697
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
00710 unsigned int Num_segments_face = segments.size();
00711
00712
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
00720
00721
00722
00723
00724
00725
00726 clock_t start2, end2;
00727 double cpu_time_used2;
00728 start2 = clock();
00729
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
00739 addRelation(*(initial_entities_2D[ii]), *(modified1_entities_0D[ii]),
00740 getNumberLowerRankEntities(*(initial_entities_2D[ii])));
00741 }
00742
00743
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
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
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767 clock_t start3, end3;
00768 double cpu_time_used3;
00769 start3 = clock();
00770
00771
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
00779 std::vector<Entity*> modified2_entities_1D =
00780 getEntitiesByRank(*(getBulkData()), 1);
00781
00782
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
00790 vector_boundary_points1 = getBoundaryEntities(*(*iterator_entities1),
00791 0);
00792
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
00802 for (unsigned int ii = 0; ii < Num_segments_face * initial_entities_2D.size();
00803 ++ii) {
00804
00805 addRelation(*(modified2_entities_1D[ii]),
00806 *(modified1_entities_0D[ii / Num_segments_face]), 0);
00807
00808 addRelation(*(modified2_entities_1D[ii]), *(vector_boundary_points[ii]),
00809 1);
00810 }
00811
00812
00813
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
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
00837
00838
00839
00840
00841
00842 clock_t start4, end4;
00843 double cpu_time_used4;
00844 start4 = clock();
00845
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
00854 std::vector<Entity*>::iterator iterator_faces;
00855 std::vector<Entity*>::iterator iterator_segments;
00856 std::vector<Entity*>::iterator iterator_nodes;
00857
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
00864
00865 for (iterator_faces = initial_entities_2D.begin();
00866 iterator_faces != initial_entities_2D.end(); ++iterator_faces) {
00867
00868
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
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
00895 original_face = getDirectlyConnectedEntities(
00896 *(all_faces_centroids[ii / Num_segments_face]), 2);
00897
00898
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
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
00917
00918
00919
00920
00921
00922
00923 clock_t start5, end5;
00924 double cpu_time_used5;
00925 start5 = clock();
00926
00927
00928
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
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
00956
00957
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
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
00979
00980
00981
00982
00983
00984 clock_t start6, end6;
00985 double cpu_time_used6;
00986 start6 = clock();
00987
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
00996
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
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
01015 for (unsigned int ii = 0; ii < initial_entities_3d.size(); ++ii) {
01016
01017 addRelation(*(initial_entities_3d[ii]), *(elements_centroids[ii]),
01018 getNumberLowerRankEntities(*(initial_entities_3d[ii])));
01019 }
01020
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
01029
01030
01031
01032
01033
01034
01035 clock_t start7, end7;
01036 double cpu_time_used7;
01037 start7 = clock();
01038
01039
01040
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
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
01062 std::vector<Entity*>
01063 modified3_entities_1D = getEntitiesByRank(*(getBulkData()), 1);
01064
01065
01066
01067
01068
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
01078 for (unsigned int ii = 0; ii < segments_connected_centroid.size(); ++ii) {
01079
01080 addRelation(*(segments_connected_centroid[ii]),
01081 *(elements_centroids[ii / element_boundary_nodes.size()]), 0);
01082
01083 addRelation(*(segments_connected_centroid[ii]),
01084 *(all_elements_boundary_nodes[ii]), 1);
01085 }
01086
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
01095
01096
01097
01098
01099 clock_t start8, end8;
01100 double cpu_time_used8;
01101 start8 = clock();
01102
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
01111
01112 std::vector<std::vector<Entity*> > faces_inside_elements(initial_entities_3d.size());
01113
01114
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
01127
01128
01129
01130
01131 faces_inside_elements[ii/Number_new_triangles_inside_element].
01132 push_back(modified2_entities_2D[ii]);
01133 }
01134
01135
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
01144
01145
01146
01147 clock_t start9, end9;
01148 double cpu_time_used9;
01149 start9 = clock();
01150
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
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
01169
01170
01171
01172
01173 const int number_new_elements = _faces_element.size()*initial_entities_3d.size();
01174
01175
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
01183 clock_t start10, end10;
01184 double cpu_time_used10;
01185 start10 = clock();
01186
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
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
01207
01208
01209 clock_t start11, end11;
01210 double cpu_time_used11;
01211 start11 = clock();
01212
01213 std::vector<std::vector<Entity*> > connectivity_temp(modified1_entities_3d.size());
01214
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
01222 getBulkData()->modification_end();
01223
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 }
01234
01235 #endif // #if defined (ALBANY_LCM)