ug4
Loading...
Searching...
No Matches
gradient_evaluators.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014: 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_DISC__GRADIENT_EVALUATORS__
34#define __H__UG_DISC__GRADIENT_EVALUATORS__
35
36#include "grid_function.h"
42
43namespace ug{
44
47template <class TFunction>
49 public:
50 static const int dim = TFunction::dim;
52 typedef typename TFunction::element_type elem_t;
53
54 GradientEvaluator_LagrangeP1(TFunction* u, size_t fct) :
55 m_pu(u),
56 m_aaPos(u->domain()->position_accessor()),
57 m_fct(fct)
58 {}
59
61 {
62 TFunction& u = *m_pu;
63
64 // reference object type
65 ReferenceObjectID roid = elem->reference_object_id();
66
67 // get trial space
68 const LocalShapeFunctionSet<dim>& lsfs =
69 LocalFiniteElementProvider::get<dim>(roid, LFEID(LFEID::LAGRANGE, dim, 1));
70
71 // create a reference mapping
73 = ReferenceMappingProvider::get<dim, dim>(roid);
74
75 // get local Mid Point
76 vector_t localIP = ReferenceElementCenter<dim>(roid);
77
78 // number of shape functions
79 const size_t numSH = lsfs.num_sh();
80 vLocalGrad.resize(numSH);
81 vGlobalGrad.resize(numSH);
82
83 // evaluate reference gradient at local midpoint
84 lsfs.grads(&vLocalGrad[0], localIP);
85
86 // get corners of element
88
89 // update mapping
90 map.update(&vCorner[0]);
91
92 // compute jacobian
94
95 // compute gradient at mid point by summing contributions of all shape fct
96 vector_t elemGrad;
97 VecSet(elemGrad, 0.0);
98 for(size_t sh = 0 ; sh < numSH; ++sh)
99 {
100 // get global Gradient
102
103 // get vertex
104 Vertex* vert = elem->vertex(sh);
105
106 // get of of vertex
107 std::vector<DoFIndex> ind;
108 u.inner_dof_indices(vert, m_fct, ind);
109
110 // scale global gradient
111 vGlobalGrad[sh] *= DoFRef(u, ind[0]);
112
113 // sum up
114 elemGrad += vGlobalGrad[sh];
115 }
116 return elemGrad;
117 }
118 private:
119 TFunction* m_pu;
120 typename TFunction::domain_type::position_accessor_type m_aaPos;
121 size_t m_fct;
122 // the following members are declared here so that they can be efficiently reused
124 std::vector<vector_t > vLocalGrad;
125 std::vector<vector_t > vGlobalGrad;
126 std::vector<vector_t > vCorner;
127};
128
129}// end of namespace
130#endif
virtual base class for reference mappings
Definition reference_mapping_provider.h:53
virtual number jacobian_transposed_inverse(MathMatrix< worldDim, dim > &JTInv, const MathVector< dim > &locPos) const =0
returns transposed of the inverse of the jacobian and returns sqrt of gram determinante
virtual void update(const MathVector< worldDim > *vCornerCoord)=0
refresh mapping for new set of corners
Definition gradient_evaluators.h:48
GradientEvaluator_LagrangeP1(TFunction *u, size_t fct)
Definition gradient_evaluators.h:54
size_t m_fct
Definition gradient_evaluators.h:121
TFunction::element_type elem_t
Definition gradient_evaluators.h:52
vector_t evaluate(elem_t *elem)
Definition gradient_evaluators.h:60
TFunction::domain_type::position_accessor_type m_aaPos
Definition gradient_evaluators.h:120
static const int dim
Definition gradient_evaluators.h:50
TFunction * m_pu
Definition gradient_evaluators.h:119
std::vector< vector_t > vGlobalGrad
Definition gradient_evaluators.h:125
std::vector< vector_t > vLocalGrad
Definition gradient_evaluators.h:124
MathMatrix< dim, dim > JTInv
Definition gradient_evaluators.h:123
MathVector< dim > vector_t
Definition gradient_evaluators.h:51
std::vector< vector_t > vCorner
Definition gradient_evaluators.h:126
Identifier for Local Finite Elements.
Definition local_finite_element_id.h:98
@ LAGRANGE
Definition local_finite_element_id.h:104
virtual size_t num_sh() const
Definition local_dof_set.cpp:46
virtual base class for local shape function sets
Definition local_shape_function_set.h:70
virtual void grads(grad_type *vGrad, const MathVector< dim > &x) const =0
returns all gradients evaluated at a point
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Vector with N entries.
Definition math_vector.h:97
Base-class for all vertex-types.
Definition grid_base_objects.h:231
void CollectCornerCoordinates(std::vector< typename TAAPos::ValueType > &vCornerCoordsOut, const TElem &elem, const TAAPos &aaPos, bool clearContainer=true)
returns the corner coordinates of a geometric object
Definition domain_util_impl.h:75
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication.
Definition math_matrix_vector_functions_common_impl.hpp:49
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition math_vector_functions_common_impl.hpp:539
the ug namespace
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition grid_base_objects.h:74
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition multi_index.h:276