Line data Source code
1 : /*
2 : * Copyright (c) 2017: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "tkd_util.h"
34 : #include "lib_grid/grid_objects/grid_objects.h"
35 :
36 : using namespace std;
37 :
38 : namespace ug {
39 :
40 0 : void CreateTKDVertices (const TKDInfo& tkdInfo,
41 : Grid& g,
42 : APosition3& aPos,
43 : Vertex** vrtsOut)
44 : {
45 : Grid::VertexAttachmentAccessor<APosition3> aaPos(g, aPos);
46 :
47 : const vector3* coords = tkdInfo.coords();
48 0 : for(size_t i = 0; i < tkdInfo.num_coords(); ++i){
49 0 : Vertex* vrt = *g.create<RegularVertex>();
50 0 : aaPos[vrt] = coords[i];
51 0 : if(vrtsOut)
52 0 : vrtsOut[i] = vrt;
53 : }
54 0 : }
55 :
56 :
57 : /** \param volsOut (optional) Array of size numElements.*/
58 : static
59 0 : void CreateVolumesFromElementIndexList (
60 : Grid& g,
61 : const int* elemIndexList,
62 : int numElements,
63 : Vertex* const* vrts,
64 : Volume** volsOut = NULL)
65 : {
66 0 : VolumeDescriptor vd;
67 :
68 : const int* inds = elemIndexList;
69 :
70 0 : for(int i = 0; i < numElements; ++i){
71 0 : const int elemId = *inds++;
72 0 : const size_t num = (size_t)elemId;
73 0 : vd.set_num_vertices(num);
74 0 : for(size_t j = 0; j < num; ++j){
75 0 : vd.set_vertex(j, vrts[*inds++]);
76 : }
77 :
78 : Volume* vol = NULL;
79 0 : switch(elemId){
80 0 : case 4: vol = *g.create<Tetrahedron>(vd); break;
81 0 : case 5: vol = *g.create<Pyramid>(vd); break;
82 0 : case 6: vol = *g.create<Prism>(vd); break;
83 0 : case 8: vol = *g.create<Hexahedron>(vd); break;
84 0 : default: UG_THROW("Unsupported element index: " << elemId);
85 : }
86 :
87 0 : if(volsOut)
88 0 : volsOut[i] = vol;
89 : }
90 0 : }
91 :
92 :
93 0 : void CreateTKD (const TKDInfo& tkdInfo,
94 : Grid& g,
95 : APosition3& aPos,
96 : Volume** volsOut)
97 : {
98 : Vertex* vrts[TKDInfo::NUM_COORDS];
99 0 : CreateTKDVertices (tkdInfo, g, aPos, vrts);
100 0 : CreateVolumesFromElementIndexList (g, tkdInfo.inner_element_indices(),
101 : TKDInfo::NUM_INNER_ELEMENTS,
102 : vrts,
103 : volsOut);
104 0 : }
105 :
106 :
107 0 : void CreateTKDWithOuterLayer (const TKDInfo& tkdInfo,
108 : Grid& g,
109 : APosition3& aPos,
110 : Volume** volsOut)
111 : {
112 : Vertex* vrts[TKDInfo::NUM_COORDS];
113 0 : CreateTKDVertices (tkdInfo, g, aPos, vrts);
114 0 : CreateVolumesFromElementIndexList (g, tkdInfo.inner_element_indices(),
115 : TKDInfo::NUM_INNER_ELEMENTS,
116 : vrts,
117 : volsOut);
118 0 : CreateVolumesFromElementIndexList (g, tkdInfo.outer_element_indices(),
119 : TKDInfo::NUM_OUTER_ELEMENTS,
120 : vrts,
121 : volsOut ? volsOut + TKDInfo::NUM_INNER_ELEMENTS : 0);
122 0 : }
123 :
124 : }// end of namespace
|