/********************************************************************************** * Copyright 2010 Christoph Pflaum * Department Informatik Lehrstuhl 10 - Systemsimulation * Friedrich-Alexander Universität Erlangen-Nürnberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **********************************************************************************/ #include "../mympi.h" #include "../abbrevi.h" #include "../parameter.h" #include "../math_lib/math_lib.h" #include "../basics/basic.h" #include "elements.h" #include "../grid/parti.h" #include "ug.h" #include "marker.h" #include #include ////////////////////////////////////////////////////////////////// // Object_based_on_ug member functions ////////////////////////////////////////////////////////////////// Object_based_on_ug::Object_based_on_ug(Unstructured_grid* ug) { ug->Add_object(this); } void Object_based_on_ug::Unregister(Unstructured_grid* ug) { ug->Remove_object(this); } ////////////////////////////////////////////////////////////////// // other member functions ////////////////////////////////////////////////////////////////// void Unstructured_grid::Add_object(Object_based_on_ug *obj) { #if 0 std::ios_base::fmtflags f = cout.flags(); cout << "Unstructured_grid::Add_object() obj = 0x" << std::hex << obj << endl; cout.setf(f); //*static_cast(0)=1; #endif all_objects_based_on_ug.push_back(obj); } void Unstructured_grid::Remove_object(Object_based_on_ug *obj) { #if 0 std::ios_base::fmtflags f = cout.flags(); cout << "Unstructured_grid::Remove_object() obj = 0x" << std::hex << obj << endl; cout.setf(f); #endif Object_list::iterator it; it=find(all_objects_based_on_ug.begin(), all_objects_based_on_ug.end(), obj); if(it != all_objects_based_on_ug.end()) all_objects_based_on_ug.erase(it); } Not_constant_direction_marker::Not_constant_direction_marker(Unstructured_grid* grid) { num_hexahedra = grid->Give_number_hexahedra(); not_const_x = new bool[num_hexahedra]; not_const_y = new bool[num_hexahedra]; not_const_z = new bool[num_hexahedra]; for(int i=0;i=num_hexahedra) cout << " error in Constant_direction_marker::Mark_x_as_const_at" << endl; else not_const_x[i] = bb; } void Not_constant_direction_marker::Mark_y_as_not_constant_at(int i, bool bb) { if(i<0 || i>=num_hexahedra) cout << " error in Constant_direction_marker::Mark_y_as_const_at" << endl; else not_const_y[i] = bb; } void Not_constant_direction_marker::Mark_z_as_not_constant_at(int i, bool bb) { if(i<0 || i>=num_hexahedra) cout << " error in Constant_direction_marker::Mark_z_as_const_at" << endl; else not_const_z[i] = bb; } D3vector transform_nothing(double x, double* gd) { return D3vector(0.0,0.0,0.0); } D3vector transform_nothing(double x, double y) { return D3vector(0.0,0.0,0.0); } Unstructured_grid::Unstructured_grid() { #if 0 cout << "Unstructured_grid::Unstructured_grid()" << endl; #endif constructionParameters.resize(0); construction_hexahedron_points_done_yn = false; construction_done_yn = false; periodic = false; pointer_global_data = NULL; size_pointer_global_data = 0; num_points = 0; num_edges = 0; num_quadrangles = 0; num_hexahedra = 0; points = NULL; edges = NULL; quadrangles = NULL; hexahedra = NULL; number_degree_of_freedom = 0; all_points = NULL; typFuerSlice = noWithZTyp; } Unstructured_grid::~Unstructured_grid() { Object_list::iterator iter; for(iter = all_objects_based_on_ug.begin(); iter != all_objects_based_on_ug.end(); ++iter) { #if 0 std::ios_base::fmtflags f = cout.flags(); cout << "Unstructured_grid::~Unstructured_grid() Delete_data() obj = 0x" << std::hex << (*iter) << endl; cout.setf(f); #endif (*iter)->Delete_data(); } all_objects_based_on_ug.clear(); if(points != NULL) delete [] points; points = NULL; if(edges != NULL) delete [] edges; edges = NULL; if(quadrangles != NULL) delete [] quadrangles; quadrangles = NULL; if(hexahedra != NULL) delete [] hexahedra; hexahedra = NULL; delete [] pointer_global_data; delete all_points; delete zordering; if (my_not_constant_directions != NULL) delete my_not_constant_directions; } void Unstructured_grid::Set_number_points(int num_points_) { num_points = num_points_; if(developer_version) if(points!=NULL) cout << " error in Unstructured_grid::Set_number_points !" << endl; points = new Point_el[num_points]; } void Unstructured_grid::Set_coordinate_point(int id, D3vector coord) { if(developer_version) if(points==NULL) cout << " error in Unstructured_grid::Set_coordinate_point " << endl; points[id].Set_coordinate(coord); } void Unstructured_grid::Set_number_hexahedra(int num_hexahedra_) { // Set informations of hexahedra num_hexahedra = num_hexahedra_; if(developer_version) if(hexahedra!=NULL) cout << " error in Unstructured_grid::Set_number_hexahedra !" << endl; hexahedra = new Hexahedron_el[num_hexahedra]; } void Unstructured_grid::Set_hexahedron(int id, int i_WSD, int i_ESD, int i_WND, int i_END, int i_WST, int i_EST, int i_WNT, int i_ENT) { if(developer_version) if(construction_hexahedron_points_done_yn==true) cout << " error in Unstructured_grid::Set_hexahedron !" << endl; // Anwender muss sehr schlau sein beim Anwenden dieser // Funktion, da sonst Orientierung nicht stimmt. // std::cout << // i_WSD << " " << i_ESD // << " " << i_WND << " " << i_END // << " " << i_WST << " " << i_EST // << " " << i_WNT << " " << i_ENT << std::endl; hexahedra[id].Set_id_corner(WSDdir3D,i_WSD); hexahedra[id].Set_id_corner(ESDdir3D,i_ESD); hexahedra[id].Set_id_corner(WNDdir3D,i_WND); hexahedra[id].Set_id_corner(ENDdir3D,i_END); hexahedra[id].Set_id_corner(WSTdir3D,i_WST); hexahedra[id].Set_id_corner(ESTdir3D,i_EST); hexahedra[id].Set_id_corner(WNTdir3D,i_WNT); hexahedra[id].Set_id_corner(ENTdir3D,i_ENT); hexahedra[id].Set_coord(WSDdir3D,points[i_WSD].Give_coordinate()); hexahedra[id].Set_coord(ESDdir3D,points[i_ESD].Give_coordinate()); hexahedra[id].Set_coord(WNDdir3D,points[i_WND].Give_coordinate()); hexahedra[id].Set_coord(ENDdir3D,points[i_END].Give_coordinate()); hexahedra[id].Set_coord(WSTdir3D,points[i_WST].Give_coordinate()); hexahedra[id].Set_coord(ESTdir3D,points[i_EST].Give_coordinate()); hexahedra[id].Set_coord(WNTdir3D,points[i_WNT].Give_coordinate()); hexahedra[id].Set_coord(ENTdir3D,points[i_ENT].Give_coordinate()); } void Unstructured_grid::Set_hexahedron(int id, int i_WSD, int i_ESD, int i_WND, int i_END, int i_WST, int i_EST, int i_WNT, int i_ENT, D3vector coord_WSD, D3vector coord_ESD, D3vector coord_WND, D3vector coord_END, D3vector coord_WST, D3vector coord_EST, D3vector coord_WNT, D3vector coord_ENT) { if(developer_version) if(construction_hexahedron_points_done_yn==true) cout << " error in Unstructured_grid::Set_hexahedron !" << endl; hexahedra[id].Set_id_corner(WSDdir3D,i_WSD); hexahedra[id].Set_id_corner(ESDdir3D,i_ESD); hexahedra[id].Set_id_corner(WNDdir3D,i_WND); hexahedra[id].Set_id_corner(ENDdir3D,i_END); hexahedra[id].Set_id_corner(WSTdir3D,i_WST); hexahedra[id].Set_id_corner(ESTdir3D,i_EST); hexahedra[id].Set_id_corner(WNTdir3D,i_WNT); hexahedra[id].Set_id_corner(ENTdir3D,i_ENT); hexahedra[id].Set_coord(WSDdir3D,coord_WSD); hexahedra[id].Set_coord(ESDdir3D,coord_ESD); hexahedra[id].Set_coord(WNDdir3D,coord_WND); hexahedra[id].Set_coord(ENDdir3D,coord_END); hexahedra[id].Set_coord(WSTdir3D,coord_WST); hexahedra[id].Set_coord(ESTdir3D,coord_EST); hexahedra[id].Set_coord(WNTdir3D,coord_WNT); hexahedra[id].Set_coord(ENTdir3D,coord_ENT); } elementTyp Give_corresponding_el_typ(elementTyp el_typ){ if(el_typ == hexahedronEl) return quadrangleEl; if(el_typ == quadrangleEl) return edgeEl; if(developer_version) if(el_typ != edgeEl) cout << " errror in Give_corresponding_el_typ!" << endl; return pointEl; } void Calculate_corresponding_corners(dir3D_sons corner, dir3D_sons& SED_corner, dir3D_sons& NWD_corner, dir3D_sons& SWT_corner){ if(corner == WSDdir3D){ SED_corner = ESDdir3D; NWD_corner = WNDdir3D; SWT_corner = WSTdir3D; } else if(corner == ESDdir3D){ SED_corner = ENDdir3D; NWD_corner = WSDdir3D; SWT_corner = ESTdir3D; } else if(corner == WNDdir3D){ SED_corner = WSDdir3D; NWD_corner = ENDdir3D; SWT_corner = WNTdir3D; } else if(corner == ENDdir3D){ SED_corner = WNDdir3D; NWD_corner = ESDdir3D; SWT_corner = ENTdir3D; } else if(corner == WSTdir3D){ SED_corner = WNTdir3D; NWD_corner = ESTdir3D; SWT_corner = WSDdir3D; } else if(corner == ESTdir3D){ SED_corner = WSTdir3D; NWD_corner = ENTdir3D; SWT_corner = ESDdir3D; } else if(corner == WNTdir3D){ SED_corner = ENTdir3D; NWD_corner = WSTdir3D; SWT_corner = WNDdir3D; } else{ if(developer_version) if(corner != ENTdir3D) cout << "error in Calculate_corresponding_corners!" << endl; SED_corner = ESTdir3D; NWD_corner = WNTdir3D; SWT_corner = ENDdir3D; } } void Calculate_corresponding_edges(dir3D_sons corner, Edges_cell& SD_edge, Edges_cell& WD_edge, Edges_cell& SW_edge){ if(corner == WSDdir3D){ SD_edge = SDed; WD_edge = WDed; SW_edge = SWed; } else if(corner == ESDdir3D){ SD_edge = EDed; WD_edge = SDed; SW_edge = SEed; } else if(corner == WNDdir3D){ SD_edge = WDed; WD_edge = NDed; SW_edge = NWed; } else if(corner == ENDdir3D){ SD_edge = NDed; WD_edge = EDed; SW_edge = NEed; } else if(corner == WSTdir3D){ SD_edge = WTed; WD_edge = STed; SW_edge = SWed; } else if(corner == ESTdir3D){ SD_edge = STed; WD_edge = ETed; SW_edge = SEed; } else if(corner == WNTdir3D){ SD_edge = NTed; WD_edge = WTed; SW_edge = NWed; } else{ if(developer_version) if(corner != ENTdir3D) cout << "error in Calculate_corresponding_edges!" << endl; SD_edge = ETed; WD_edge = NTed; SW_edge = NEed; } } void Unstructured_grid::construction_hexahedron_points_done() { int num, num_q, ec, fc, c, i, e, q, ed, ismallest, smallest, number_neighbors, number_neighbors_hex, num_hex; int idA, idB, id, id_ed, id_quad, id_edge, id_point, id_corner; int id4[4]; int idt[4]; sorted_quad SQuad; sorted_pair SPair; unsorted_pair USPair; int c_SW, c_SE, c_NW, c_NE; int ed_W, ed_E, ed_S, ed_N; int id_search_quad, id_search_edge; int W_corner, E_corner; elementTyp neighbor_in_typ; int neighbor_in_id, id_global_ND, id_global_ST, id_global_SD, id_global_WD, id_global_SW, id_global_S, id_global_D, id_global_W; Edges_cell ed_cell, SD_edge, WD_edge, SW_edge; dir3D_sons corner, SED_corner, NWD_corner, SWT_corner; construction_hexahedron_points_done_yn = true; // allocate my_constant_directions my_not_constant_directions = new Not_constant_direction_marker(this); // Set informations of hexahedra, count edges and quadrangles and put in Topf for(num=0;numnumber_neighbors_hex) cout << "error1 in construction_hexahedron_points_done!" << endl; } else if(neighbor_in_typ == quadrangleEl){ edges[id_edge].Set_rel_neigh_locstiff(num, -1); edges[id_edge].Set_typ_W_el(num,edgeEl); edges[id_edge].Set_typ_E_el(num,edgeEl); for(e=0;e<4;++e){ id_ed = quadrangles[neighbor_in_id].Give_id_edge((dir2D)e); if(id_ed != id_edge) for(c=0;c<2;++c){ if(edges[id_ed].Give_id_corner((dir1D)c) == W_corner) edges[id_edge].Set_id_W_el(num,id_ed); else if(edges[id_ed].Give_id_corner((dir1D)c) == E_corner) edges[id_edge].Set_id_E_el(num,id_ed); } } } } if(developer_version) if(num_hex!=number_neighbors_hex) cout << "error2 in construction_hexahedron_points_done!" << endl; } //construcht neighbors of corners for(num=0;numnumber_neighbors_hex) cout << "error3 in construction_hexahedron_points_done!" << endl; } else points[id_point].Set_rel_neigh_locstiff(num, -1); } if(developer_version) if(num_hex!=number_neighbors_hex) cout << "error4 in construction_hexahedron_points_done!" << endl; } // set coordinates of quadrangles and edges Set_coordinates_quadrangles(); Set_coordinates_edges(); } // setze Koordinaten der Quadrangles von hexaeder ecken void Unstructured_grid::Set_coordinates_quadrangles() { int idpoint_hex[4]; D3vector coord_hex[4]; dir3D_sons co_hex; int id_quad; int idpoint_quad; for(int num=0;num give_coord_edge() instead of transform_nothing ??? // set transformation function hexahedra[id_hex].transform[i] = edges[hexahedra[id_hex].Give_id_edge((Edges_cell)i)].transform; hexahedra[id_hex].setShiftPointer(edges[hexahedra[id_hex].Give_id_edge((Edges_cell)i)].getShiftPointer()); }; } // III. set all points all_points = new Marker(this); // IV. Zordering zordering = new Zordering(this); //zordering->Print(this); // V. Check, whether FACE or EDGE transform is used to find coordinates. Default is FALSE transformFromQuadrangle = true; //transformFromQuadrangle for (int qu = 0; qu < Give_number_quadrangles(); ++qu) { if( Give_quadrangle(qu)->transform == NULL) { transformFromQuadrangle = false; } } if (transformFromQuadrangle) { edge_to_quad_id.resize(Give_number_edges()); edge_to_quad_dir.resize(Give_number_edges()); edge_to_hex_id.resize(Give_number_edges()); for (int iter = 0 ; iter D3vector if(developer_version){ if(construction_hexahedron_points_done_yn!=true && construction_done_yn==true) cout << " error 1 in Unstructured_grid::Set_transformation_edge !" << endl; if(idL>=idR) cout << " error 2 in Unstructured_grid::Set_transformation_edge !" << endl; } Edge_el* poiE = &edges[topf_edges.Give_id(idL,idR)]; poiE->transform = Transform; poiE->setShiftPointer(shift_of_pointer); } void Unstructured_grid::Set_transformation_edge_from_face(int idL, int idR, D3vector (*transform)(double, double, double *), int shift_of_pointer) { } void Unstructured_grid::Set_transformation_edge_of_hexahedron(int id_hex, Edges_cell ed, D3vector (*Transform)(double, double*)) { // transform must be zero vector at 0,1 // transform: [0,1] -> D3vector if(developer_version){ if(construction_hexahedron_points_done_yn!=true && construction_done_yn==true) cout << " error 1 in Unstructured_grid::Set_transformation_edge_of.. !" << endl; if(id_hex < 0 || id_hex >= num_hexahedra) cout << " error 2 in Unstructured_grid::Set_transformation_edge_of.. !" << endl; } hexahedra[id_hex].transform[(int)ed] = Transform; assert(false); // das wurde noch nie angwendet. Es geht vielleicht hier aber nicht bei compose_grid.h } void Unstructured_grid::Set_transformation_face(int idSW, int idSE, int idNW, int idNE, D3vector (*Transform)(double,double, double*), int shift_of_pointer) { // transform must be zero at (0,0) if(developer_version) if(construction_hexahedron_points_done_yn!=true && construction_done_yn==true) cout << " error in Unstructured_grid::Set_transformation_face !" << endl; // cout << " Unstructured_grid::Set_transformation_face is being implemented ! ..." << endl; Quadrangle_el* quadEL = &quadrangles[topf_quadrangles.Give_id(idSW,idSE,idNW,idNE)]; //cout << "id of quadrangle transform: " << topf_quadrangles.Give_id(idSW,idSE,idNW,idNE) << endl; quadEL->transform = Transform; quadEL->setShiftPointer(shift_of_pointer); //Set_transformation_edge_from_face(); } void Unstructured_grid::Set_transformation_hex(int id_hex, D3vector (*transform_h)(int ,double,double,double)) { if(developer_version) if(construction_hexahedron_points_done_yn!=true && construction_done_yn==true) cout << " error in Unstructured_grid::Set_transformation_hex !" << endl; hexahedra[id_hex].transform_hex = transform_h; assert(false); // das wurde noch nie angwendet. Es geht vielleicht hier aber nicht bei compose_grid.h } void Unstructured_grid::Print() { cout << "Print ug 3D " << endl; cout << "---------------------------" << endl; for(int i=0; i