Line data Source code
1 : /*
2 : * Copyright (c) 2016: 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 : #ifndef __H__UG_grid_function_coordinate_util
34 : #define __H__UG_grid_function_coordinate_util
35 :
36 : #include "common/common.h"
37 : #include "common/util/smart_pointer.h"
38 :
39 : #include "lib_grid/tools/subset_group.h"
40 :
41 : #include "lib_disc/domain_util.h"
42 : #include "lib_disc/common/groups_util.h"
43 : #include "lib_disc/local_finite_element/local_finite_element_provider.h"
44 : #include "lib_disc/reference_element/reference_mapping.h"
45 :
46 : namespace ug{
47 :
48 : template <typename TGridFunction>
49 0 : void AddFunctionValuesToGridCoordinatesP1(
50 : SmartPtr<TGridFunction> spGridFct,
51 : size_t fct,
52 : size_t coordInd,
53 : const SubsetGroup& ssGrp,
54 : number timestep)
55 : {
56 : // check if fast P1 interpolation may be used
57 0 : UG_COND_THROW(
58 : spGridFct->local_finite_element_id(fct).type() != LFEID::LAGRANGE
59 : || spGridFct->local_finite_element_id(fct).order() != 1,
60 : "Fast P1 interpolation may only be used for Lagrange P1 functions.");
61 :
62 : // domain type and position_type
63 : typedef typename TGridFunction::domain_type domain_type;
64 :
65 : // get position accessor
66 : typename domain_type::position_accessor_type& aaPos
67 0 : = spGridFct->domain()->position_accessor();
68 :
69 : std::vector<DoFIndex> ind;
70 : typename TGridFunction::template dim_traits<0>::const_iterator iterEnd, iter;
71 :
72 0 : for(size_t i = 0; i < ssGrp.size(); ++i)
73 : {
74 : // get subset index
75 : const int si = ssGrp[i];
76 : // skip if function is not defined in subset
77 0 : if(!spGridFct->is_def_in_subset(fct, si)) continue;
78 : // iterate over all elements
79 0 : iterEnd = spGridFct->template end<Vertex>(si);
80 0 : iter = spGridFct->template begin<Vertex>(si);
81 0 : for(; iter != iterEnd; ++iter)
82 : {
83 : // get element
84 : Vertex* vrt = *iter;
85 :
86 : // get multiindices of element
87 : spGridFct->dof_indices(vrt, fct, ind);
88 :
89 : // loop all dofs
90 0 : for(size_t i = 0; i < ind.size(); ++i)
91 : {
92 : // set value#
93 0 : aaPos[vrt][coordInd] += DoFRef(*spGridFct, ind[i]) * timestep;
94 : }
95 : }
96 : }
97 0 : }
98 :
99 : template <typename TGridFunction>
100 0 : void AddFunctionValuesToGridCoordinatesP1(
101 : SmartPtr<TGridFunction> spGridFct,
102 : const char* cmp,
103 : size_t coordInd)
104 : {
105 0 : AddFunctionValuesToGridCoordinatesP1(spGridFct, cmp, coordInd, 1.0);
106 0 : }
107 :
108 :
109 : template <typename TGridFunction>
110 0 : void AddFunctionValuesToGridCoordinatesP1(
111 : SmartPtr<TGridFunction> spGridFct,
112 : const char* cmp,
113 : size_t coordInd,
114 : number timestep)
115 : {
116 : // get function id of name
117 : const size_t fct = spGridFct->fct_id_by_name(cmp);
118 :
119 : // check that function found
120 0 : if(fct > spGridFct->num_fct())
121 0 : UG_THROW("Interpolate: Name of component '"<<cmp<<"' not found.");
122 :
123 : const bool bAllowManyfoldInterpolation =
124 : (spGridFct->local_finite_element_id(fct).type() == LFEID::LAGRANGE);
125 :
126 : // create subset group
127 0 : SubsetGroup ssGrp(spGridFct->domain()->subset_handler());
128 : // add all subsets and remove lower dim subsets afterwards
129 0 : ssGrp.add_all();
130 0 : if(!bAllowManyfoldInterpolation)
131 0 : RemoveLowerDimSubsets(ssGrp);
132 :
133 0 : AddFunctionValuesToGridCoordinatesP1(spGridFct, fct, coordInd, ssGrp, timestep);
134 0 : }
135 :
136 : }// end of namespace
137 :
138 : #endif //__H__UG_grid_function_coordinate_util
|