Line data Source code
1 : /*
2 : * Copyright (c) 2013-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 "neumann_boundary_base.h"
34 : #include "lib_disc/common/groups_util.h"
35 : #include "lib_disc/spatial_disc/user_data/const_user_data.h"
36 :
37 : #ifdef UG_FOR_LUA
38 : #include "bindings/lua/lua_user_data.h"
39 : #endif
40 :
41 : namespace ug{
42 : ////////////////////////////////////////////////////////////////////////////////
43 : // Constructor
44 : ////////////////////////////////////////////////////////////////////////////////
45 :
46 : template<typename TDomain>
47 0 : NeumannBoundaryBase<TDomain>::NeumannBoundaryBase(const char* function)
48 0 : :IElemDisc<TDomain>(function, "")
49 : {
50 0 : if(this->num_fct() != 1)
51 0 : UG_THROW("NeumannBoundaryBase: needed exactly one function.");
52 0 : }
53 :
54 : ////////////////////////////////////////////////////////////////////////////////
55 : // User Data
56 : ////////////////////////////////////////////////////////////////////////////////
57 :
58 : template<typename TDomain>
59 0 : void NeumannBoundaryBase<TDomain>::
60 : update_subset_groups(Data& userData)
61 : {
62 : // create Function Group and Subset Group
63 0 : FunctionGroup functionGroup;
64 :
65 : // convert strings
66 : try{
67 0 : userData.InnerSSGrp = this->approx_space()->subset_grp_by_name(userData.InnerSubsetNames.c_str());
68 0 : }UG_CATCH_THROW("NeumannBoundaryBase:"
69 : " Subsets '"<<userData.InnerSubsetNames<<"' not"
70 : " all contained in ApproximationSpace.");
71 : try{
72 0 : userData.BndSSGrp = this->approx_space()->subset_grp_by_name(userData.BndSubsetNames.c_str());
73 0 : }UG_CATCH_THROW("NeumannBoundaryBase:"
74 : " Subsets '"<<userData.BndSubsetNames<<"' not"
75 : " all contained in ApproximationSpace.");
76 0 : }
77 :
78 : template<typename TDomain>
79 0 : void NeumannBoundaryBase<TDomain>::
80 : add_inner_subsets(const char* InnerSubsets)
81 : {
82 0 : std::vector<std::string> vSubsets = this->symb_subsets();
83 0 : std::vector<std::string> vNew = TokenizeTrimString(InnerSubsets);
84 0 : for(size_t i = 0; i < vNew.size(); ++i)
85 0 : if(std::find(vSubsets.begin(), vSubsets.end(), vNew[i]) == vSubsets.end())
86 0 : vSubsets.push_back(vNew[i]);
87 0 : this->set_subsets(vSubsets);
88 :
89 0 : }
90 :
91 : template<typename TDomain>
92 0 : void NeumannBoundaryBase<TDomain>::
93 : add(SmartPtr<CplUserData<number, dim> > data, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
94 : {
95 : std::string bnd;
96 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
97 0 : if(i > 0) bnd.append(",");
98 : bnd.append(BndSubsets[i]);
99 : }
100 : std::string inner;
101 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
102 0 : if(i > 0) inner.append(",");
103 : inner.append(InnerSubsets[i]);
104 : }
105 :
106 0 : add(data, bnd.c_str(), inner.c_str());
107 0 : }
108 :
109 : template<typename TDomain>
110 0 : void NeumannBoundaryBase<TDomain>::
111 : add(SmartPtr<CplUserData<number, dim, bool> > data, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
112 : {
113 : std::string bnd;
114 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
115 0 : if(i > 0) bnd.append(",");
116 : bnd.append(BndSubsets[i]);
117 : }
118 : std::string inner;
119 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
120 0 : if(i > 0) inner.append(",");
121 : inner.append(InnerSubsets[i]);
122 : }
123 :
124 0 : add(data, bnd.c_str(), inner.c_str());
125 0 : }
126 :
127 : template<typename TDomain>
128 0 : void NeumannBoundaryBase<TDomain>::
129 : add(SmartPtr<CplUserData<MathVector<dim>, dim> > data, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
130 : {
131 : std::string bnd;
132 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
133 0 : if(i > 0) bnd.append(",");
134 : bnd.append(BndSubsets[i]);
135 : }
136 : std::string inner;
137 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
138 0 : if(i > 0) inner.append(",");
139 : inner.append(InnerSubsets[i]);
140 : }
141 :
142 0 : add(data, bnd.c_str(), inner.c_str());
143 0 : }
144 :
145 : template<typename TDomain>
146 0 : void NeumannBoundaryBase<TDomain>::
147 : add(number val, const char* function, const char* subsets)
148 : {
149 0 : SmartPtr<CplUserData<number, dim> > sp = make_sp(new ConstUserNumber<dim>(val));
150 0 : add(sp, function, subsets);
151 0 : }
152 :
153 : template<typename TDomain>
154 0 : void NeumannBoundaryBase<TDomain>::
155 : add(number val, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
156 : {
157 : std::string bnd;
158 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
159 0 : if(i > 0) bnd.append(",");
160 : bnd.append(BndSubsets[i]);
161 : }
162 : std::string inner;
163 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
164 0 : if(i > 0) inner.append(",");
165 : inner.append(InnerSubsets[i]);
166 : }
167 :
168 0 : add(val, bnd.c_str(), inner.c_str());
169 0 : }
170 :
171 : template<typename TDomain>
172 0 : void NeumannBoundaryBase<TDomain>::
173 : add(const std::vector<number>& val, const char* function, const char* subsets)
174 : {
175 0 : SmartPtr<CplUserData<MathVector<dim>, dim> > sp = make_sp(new ConstUserVector<dim>(val));
176 0 : add(sp, function, subsets);
177 0 : }
178 :
179 : template<typename TDomain>
180 0 : void NeumannBoundaryBase<TDomain>::
181 : add(const std::vector<number>& val, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
182 : {
183 : std::string bnd;
184 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
185 0 : if(i > 0) bnd.append(",");
186 : bnd.append(BndSubsets[i]);
187 : }
188 : std::string inner;
189 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
190 0 : if(i > 0) inner.append(",");
191 : inner.append(InnerSubsets[i]);
192 : }
193 :
194 0 : add(val, bnd.c_str(), inner.c_str());
195 0 : }
196 :
197 :
198 : #ifdef UG_FOR_LUA
199 : template <typename TDomain>
200 0 : void NeumannBoundaryBase<TDomain>::
201 : add(const char* name, const char* function, const char* subsets)
202 : {
203 0 : if(LuaUserData<number, dim>::check_callback_returns(name)){
204 0 : SmartPtr<CplUserData<number, dim> > sp =
205 : LuaUserDataFactory<number, dim>::create(name);
206 0 : add(sp, function, subsets);
207 : return;
208 : }
209 0 : if(LuaUserData<number, dim, bool>::check_callback_returns(name)){
210 0 : SmartPtr<CplUserData<number, dim, bool> > sp =
211 : LuaUserDataFactory<number, dim, bool>::create(name);
212 0 : add(sp, function, subsets);
213 : return;
214 : }
215 0 : if(LuaUserData<MathVector<dim>, dim>::check_callback_returns(name)){
216 0 : SmartPtr<CplUserData<MathVector<dim>, dim> > sp =
217 : LuaUserDataFactory<MathVector<dim>, dim>::create(name);
218 0 : add(sp, function, subsets);
219 : return;
220 : }
221 :
222 : // no match found
223 0 : if(!CheckLuaCallbackName(name))
224 0 : UG_THROW("NeumannBoundaryBase: Lua-Callback with name '"<<name<<
225 : "' does not exist.");
226 :
227 : // name exists but wrong signature
228 0 : UG_THROW("NeumannBoundaryBase: Cannot find matching callback "
229 : "signature. Use one of:\n"
230 : "a) Number - Callback\n"
231 : << (LuaUserData<number, dim>::signature()) << "\n" <<
232 : "b) Conditional Number - Callback\n"
233 : << (LuaUserData<number, dim, bool>::signature()) << "\n" <<
234 : "c) "<<dim<<"d Vector - Callback\n"
235 : << (LuaUserData<MathVector<dim>, dim>::signature()));
236 : }
237 :
238 : template <typename TDomain>
239 0 : void NeumannBoundaryBase<TDomain>::
240 : add(const char* name, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
241 : {
242 : std::string bnd;
243 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
244 0 : if(i > 0) bnd.append(",");
245 : bnd.append(BndSubsets[i]);
246 : }
247 : std::string inner;
248 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
249 0 : if(i > 0) inner.append(",");
250 : inner.append(InnerSubsets[i]);
251 : }
252 0 : add(name, bnd.c_str(), inner.c_str());
253 0 : }
254 :
255 : template <typename TDomain>
256 0 : void NeumannBoundaryBase<TDomain>::
257 : add(LuaFunctionHandle fct, const char* function, const char* subsets)
258 : {
259 0 : if(LuaUserData<number, dim>::check_callback_returns(fct)){
260 0 : SmartPtr<CplUserData<number, dim> > sp =
261 0 : make_sp(new LuaUserData<number, dim>(fct));
262 0 : add(sp, function, subsets);
263 : return;
264 : }
265 0 : if(LuaUserData<number, dim, bool>::check_callback_returns(fct)){
266 0 : SmartPtr<CplUserData<number, dim, bool> > sp =
267 0 : make_sp(new LuaUserData<number, dim, bool>(fct));
268 0 : add(sp, function, subsets);
269 : return;
270 : }
271 0 : if(LuaUserData<MathVector<dim>, dim>::check_callback_returns(fct)){
272 0 : SmartPtr<CplUserData<MathVector<dim>, dim> > sp =
273 0 : make_sp(new LuaUserData<MathVector<dim>, dim>(fct));
274 0 : add(sp, function, subsets);
275 : return;
276 : }
277 :
278 : // name exists but wrong signature
279 0 : UG_THROW("NeumannBoundaryBase: Cannot find matching callback "
280 : "signature. Use one of:\n"
281 : "a) Number - Callback\n"
282 : << (LuaUserData<number, dim>::signature()) << "\n" <<
283 : "b) Conditional Number - Callback\n"
284 : << (LuaUserData<number, dim, bool>::signature()) << "\n" <<
285 : "c) "<<dim<<"d Vector - Callback\n"
286 : << (LuaUserData<MathVector<dim>, dim>::signature()));
287 : }
288 :
289 : template <typename TDomain>
290 0 : void NeumannBoundaryBase<TDomain>::
291 : add(LuaFunctionHandle fct, const std::vector<std::string>& BndSubsets, const std::vector<std::string>& InnerSubsets)
292 : {
293 : std::string bnd;
294 0 : for(size_t i = 0; i < BndSubsets.size(); ++i){
295 0 : if(i > 0) bnd.append(",");
296 : bnd.append(BndSubsets[i]);
297 : }
298 : std::string inner;
299 0 : for(size_t i = 0; i < InnerSubsets.size(); ++i){
300 0 : if(i > 0) inner.append(",");
301 : inner.append(InnerSubsets[i]);
302 : }
303 0 : add(fct, bnd.c_str(), inner.c_str());
304 0 : }
305 :
306 : #endif
307 :
308 : ////////////////////////////////////////////////////////////////////////////////
309 : // explicit template instantiations
310 : ////////////////////////////////////////////////////////////////////////////////
311 :
312 : #ifdef UG_DIM_1
313 : template class NeumannBoundaryBase<Domain1d>;
314 : #endif
315 : #ifdef UG_DIM_2
316 : template class NeumannBoundaryBase<Domain2d>;
317 : #endif
318 : #ifdef UG_DIM_3
319 : template class NeumannBoundaryBase<Domain3d>;
320 : #endif
321 :
322 : } // namespace ug
323 :
|