Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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 "local_dof_set.h"
34 : #include "lib_disc/reference_element/reference_element_util.h"
35 :
36 : namespace ug{
37 :
38 : ////////////////////////////////////////////////////////////////////////////////
39 : // LocalDoFSet
40 : ////////////////////////////////////////////////////////////////////////////////
41 :
42 0 : int LocalDoFSet::dim() const {
43 0 : return ReferenceElementDimension(roid());
44 : }
45 :
46 0 : size_t LocalDoFSet::num_sh() const
47 : {
48 : size_t sum = 0;
49 0 : for(int i = 0; i < NUM_REFERENCE_OBJECTS; ++i)
50 0 : sum += num_dof((ReferenceObjectID)i);
51 0 : return sum;
52 : }
53 :
54 0 : size_t LocalDoFSet::num_dof(int d, size_t id) const
55 : {
56 0 : static const ReferenceElement& rRefElem = ReferenceElementProvider::get(roid());
57 0 : return num_dof(rRefElem.roid(d, id));
58 : }
59 :
60 0 : bool LocalDoFSet::operator==(const LocalDoFSet& v) const
61 : {
62 0 : if(roid() != v.roid()) return false;
63 0 : if(dim() != v.dim()) return false;
64 :
65 0 : if(num_dof() != v.num_dof()) return false;
66 :
67 0 : for(int r = 0; r < NUM_REFERENCE_OBJECTS; ++r){
68 : const ReferenceObjectID roid = (ReferenceObjectID)r;
69 0 : if(num_dof(roid) != v.num_dof(roid)) return false;
70 : }
71 :
72 0 : for(size_t dof = 0; dof < num_dof(); ++dof)
73 0 : if(local_dof(dof) != v.local_dof(dof)) return false;
74 :
75 : return true;
76 : }
77 :
78 : ////////////////////////////////////////////////////////////////////////////////
79 : // DimLocalDoFSet
80 : ////////////////////////////////////////////////////////////////////////////////
81 :
82 : template <int TDim>
83 0 : DimLocalDoFSet<TDim>::DimLocalDoFSet(){
84 0 : }
85 :
86 : template <int TDim>
87 0 : bool DimLocalDoFSet<TDim>::operator==(const DimLocalDoFSet<TDim>& v) const
88 : {
89 0 : if(*dynamic_cast<const LocalDoFSet*>(this) != *dynamic_cast<const LocalDoFSet*>(&v))
90 : return false;
91 :
92 0 : if(exact_position_available() != v.exact_position_available()) return false;
93 :
94 0 : for(size_t dof = 0; dof < num_dof(); ++dof){
95 : MathVector<TDim> pos, vpos;
96 0 : position(dof, pos);
97 0 : v.position(dof, vpos);
98 :
99 0 : if(VecDistance(pos, vpos) > 1e-9) return false;
100 : }
101 :
102 : return true;
103 : }
104 :
105 : template class DimLocalDoFSet<0>;
106 : template class DimLocalDoFSet<1>;
107 : template class DimLocalDoFSet<2>;
108 : template class DimLocalDoFSet<3>;
109 :
110 : ////////////////////////////////////////////////////////////////////////////////
111 : // CommonLocalDoFSet
112 : ////////////////////////////////////////////////////////////////////////////////
113 :
114 0 : void CommonLocalDoFSet::clear()
115 : {
116 : // set all dofs to not specified
117 0 : for(int i = 0; i < NUM_REFERENCE_OBJECTS; ++i)
118 0 : m_vNumDoF[i] = NOT_SPECIFIED;
119 0 : }
120 :
121 : /// add a local dof set to the intersection
122 0 : void CommonLocalDoFSet::add(const LocalDoFSet& set)
123 : {
124 : const ReferenceElement& rRefElem =
125 0 : ReferenceElementProvider::get(set.roid());
126 :
127 0 : for(int i = 0; i < NUM_REFERENCE_OBJECTS; ++i)
128 : {
129 : // get roid
130 : const ReferenceObjectID roid = (ReferenceObjectID) i;
131 :
132 : // do not override values of same dimension
133 0 : if(ReferenceElementDimension(roid) == set.dim()
134 0 : && roid != set.roid()) continue;
135 :
136 : // check that roid contained in element type
137 0 : if(ReferenceElementDimension(roid) <= set.dim() &&
138 0 : rRefElem.num(roid) == 0) continue;
139 :
140 : // check if already value set and iff the same
141 0 : if(m_vNumDoF[i] != NOT_SPECIFIED)
142 0 : if(m_vNumDoF[i] != (int)set.num_dof(roid))
143 0 : UG_THROW("LocalDoFSetIntersection::add: Adding DoF-Spezification "
144 : "for "<<roid<<" as Subelement of Space for "<<set.roid()<<
145 : ": Values does not match ("<<m_vNumDoF[i]<<" <-> "
146 : << set.num_dof(roid)<<").");
147 :
148 : // set value if not already set
149 0 : m_vNumDoF[i] = set.num_dof(roid);
150 : }
151 0 : }
152 :
153 0 : std::ostream& operator<<(std::ostream& out, const LocalDoF& v)
154 : {
155 0 : out <<"("<<v.dim()<<","<<v.id()<<","<<v.offset()<<")";
156 0 : return out;
157 : }
158 :
159 0 : std::ostream& operator<<(std::ostream& out, const CommonLocalDoFSet& v)
160 : {
161 0 : for(int i = 0; i < NUM_REFERENCE_OBJECTS; ++i)
162 : {
163 : ReferenceObjectID roid = (ReferenceObjectID) i;
164 :
165 0 : out << std::setw(14) << roid << ": ";
166 0 : if(v.num_dof(roid) == CommonLocalDoFSet::NOT_SPECIFIED)
167 0 : out << "(not specified)";
168 : else
169 0 : out << v.num_dof(roid);
170 0 : out << "\n";
171 : }
172 0 : return out;
173 : }
174 :
175 0 : std::ostream& operator<<(std::ostream& out, const LocalDoFSet& v)
176 : {
177 0 : for(int i = 0; i < NUM_REFERENCE_OBJECTS; ++i)
178 : {
179 : ReferenceObjectID roid = (ReferenceObjectID) i;
180 0 : out << std::setw(14) << roid << ": " << v.num_dof(roid) << "\n";
181 : }
182 0 : return out;
183 : }
184 :
185 : template <int dim>
186 0 : std::ostream& operator<<(std::ostream& out, const DimLocalDoFSet<dim>& v)
187 : {
188 0 : out << *dynamic_cast<const LocalDoFSet*>(&v);
189 :
190 0 : for(size_t dof = 0; dof < v.num_dof(); ++dof){
191 0 : out << "DoF "<<std::setw(3)<<dof<<": ";
192 0 : MathVector<dim> pos; v.position(dof, pos);
193 0 : out << v.local_dof(dof) << ", " << pos << "\n";
194 : }
195 0 : return out;
196 : }
197 :
198 : template std::ostream& operator<<(std::ostream& out, const DimLocalDoFSet<0>& v);
199 : template std::ostream& operator<<(std::ostream& out, const DimLocalDoFSet<1>& v);
200 : template std::ostream& operator<<(std::ostream& out, const DimLocalDoFSet<2>& v);
201 : template std::ostream& operator<<(std::ostream& out, const DimLocalDoFSet<3>& v);
202 :
203 : } // end namespace ug
|