ug4
grid_function_coordinate_util.h
Go to the documentation of this file.
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"
38 
40 
41 #include "lib_disc/domain_util.h"
45 
46 namespace ug{
47 
48 template <typename TGridFunction>
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
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  = spGridFct->domain()->position_accessor();
68 
69  std::vector<DoFIndex> ind;
70  typename TGridFunction::template dim_traits<0>::const_iterator iterEnd, iter;
71 
72  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  if(!spGridFct->is_def_in_subset(fct, si)) continue;
78  // iterate over all elements
79  iterEnd = spGridFct->template end<Vertex>(si);
80  iter = spGridFct->template begin<Vertex>(si);
81  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  for(size_t i = 0; i < ind.size(); ++i)
91  {
92  // set value#
93  aaPos[vrt][coordInd] += DoFRef(*spGridFct, ind[i]) * timestep;
94  }
95  }
96  }
97 }
98 
99 template <typename TGridFunction>
101  SmartPtr<TGridFunction> spGridFct,
102  const char* cmp,
103  size_t coordInd)
104 {
105  AddFunctionValuesToGridCoordinatesP1(spGridFct, cmp, coordInd, 1.0);
106 }
107 
108 
109 template <typename TGridFunction>
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  if(fct > spGridFct->num_fct())
121  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  SubsetGroup ssGrp(spGridFct->domain()->subset_handler());
128  // add all subsets and remove lower dim subsets afterwards
129  ssGrp.add_all();
130  if(!bAllowManyfoldInterpolation)
131  RemoveLowerDimSubsets(ssGrp);
132 
133  AddFunctionValuesToGridCoordinatesP1(spGridFct, fct, coordInd, ssGrp, timestep);
134 }
135 
136 }// end of namespace
137 
138 #endif //__H__UG_grid_function_coordinate_util
@ LAGRANGE
Definition: local_finite_element_id.h:104
Group of subsets.
Definition: subset_group.h:51
size_t size() const
number of subsets in this group
Definition: subset_group.h:122
void add_all()
select all subsets of underlying subset handler
Definition: subset_group.cpp:133
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
#define UG_THROW(msg)
Definition: error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
the ug namespace
void AddFunctionValuesToGridCoordinatesP1(SmartPtr< TGridFunction > spGridFct, size_t fct, size_t coordInd, const SubsetGroup &ssGrp, number timestep)
Definition: grid_function_coordinate_util.h:49
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition: multi_index.h:276
void RemoveLowerDimSubsets(SubsetGroup &subsetGroup)
Definition: subset_group.cpp:315