ug4
Loading...
Searching...
No Matches
projection_linker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Dmitry Logashenko
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/*
34 * A linker that projects a given vector to the manifold of given elements.
35 */
36#ifndef __H__UG__LIB_DISC__SPATIAL_DISC__PROJECT_LINKER__
37#define __H__UG__LIB_DISC__SPATIAL_DISC__PROJECT_LINKER__
38
39/* ug4 headers */
40#include "common/common.h"
41
43#include "linker.h"
44
45namespace ug {
46
50template <int dim>
52: public StdDataLinker<ProjectionLinker<dim>, MathVector<dim>, dim>
53{
56
57public:
58
61 (
62 SmartPtr<CplUserData<MathVector<dim>, dim> > spVector
63 )
64 {
65 this->set_num_input (1);
66 m_spVector = spVector;
67 m_spDVector = spVector.template cast_dynamic<DependentUserData<MathVector<dim>, dim> > ();
68 this->set_input (0, spVector, spVector);
69 }
70
73 (
74 MathVector<dim> vector
75 )
76 {
77 this->set_num_input (1);
79 m_spDVector = m_spVector.template cast_dynamic<DependentUserData<MathVector<dim>, dim> > ();
81 }
82
84 virtual bool requires_grid_fct() const {return true;}
85
87 inline void evaluate
88 (
89 MathVector<dim>& value,
90 const MathVector<dim>& glob_ip,
92 int si
93 ) const
94 {
95 UG_THROW ("ProjectionLinker: Cannot evaluate without any specification of the element!");
96 }
97
99 template <int refDim>
100 inline void evaluate
101 (
102 MathVector<dim> vValue[],
103 const MathVector<dim> vGlobIP[],
104 number time,
105 int si,
106 GridObject* elem,
107 const MathVector<dim> vCornerCoords[],
108 const MathVector<refDim> vLocIP[],
109 const size_t nip,
110 LocalVector* u,
111 const MathMatrix<refDim, dim>* vJT = NULL
112 ) const
113 {
114 // 1. Get the vectors themselves
115 (*m_spVector) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
116
117 // 2. Prepare the data of the element
118 const ReferenceObjectID roid = elem->reference_object_id ();
119 DimReferenceMapping<refDim, dim>& rMapping = ReferenceMappingProvider::get<refDim, dim> (roid);
120 rMapping.update (vCornerCoords);
121
122 // 3. At every integration point
123 for (size_t i = 0; i < nip; i++)
124 {
125 // 3a. Get the Jacobian
127 rMapping.jacobian (J, vLocIP[i]);
128 // 3b. Project the vector to the subspace spanned by the columns of the Jacobian
129 OrthogProjectVec (vValue[i], J);
130 }
131 }
132
134 template <int refDim>
136 (
137 MathVector<dim> vValue[],
138 const MathVector<dim> vGlobIP[],
139 number time,
140 int si,
141 GridObject* elem,
142 const MathVector<dim> vCornerCoords[],
143 const MathVector<refDim> vLocIP[],
144 const size_t nip,
145 LocalVector* u,
146 bool bDeriv,
147 int s,
148 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
149 const MathMatrix<refDim, dim>* vJT = NULL
150 ) const
151 {
152 // 1. Get the vectors themselves
153 const MathVector<dim>* vVector = m_spVector->values (s);
154
155 // 2a. Prepare the data of the element
156 const ReferenceObjectID roid = elem->reference_object_id ();
157 DimReferenceMapping<refDim, dim>& rMapping = ReferenceMappingProvider::get<refDim, dim> (roid);
158 rMapping.update (vCornerCoords);
159
160 // 2b. Check if we should compute the derivatives
161 if (this->zero_derivative ())
162 bDeriv = false;
163 else
164 this->set_zero (vvvDeriv, nip);
165
166 // 3. At every integration point
167 for (size_t i = 0; i < nip; i++)
168 {
169 // 3a. Get the Jacobian
171 rMapping.jacobian (J, vLocIP[i]);
172 // 3b. Project the vector to the subspace spanned by the columns of the Jacobian
173 vValue[i] = vVector[i];
174 OrthogProjectVec (vValue[i], J);
175 // 3c. Project the derivatives in the same way
176 if (! bDeriv) continue;
177 for (size_t fct = 0; fct < m_spDVector->num_fct(); fct++)
178 {
179 const MathVector<dim>* vDVector = m_spDVector->deriv (s, i, fct);
180 const size_t c_fct = this->input_common_fct (0, fct);
181 for (size_t sh = 0; sh < this->num_sh (c_fct); sh++)
182 {
183 vvvDeriv[i][c_fct][sh] = vDVector [sh];
184 OrthogProjectVec (vvvDeriv[i][c_fct][sh], J);
185 }
186 }
187 }
188 }
189
190private:
191
195};
196
197} // end namespace ug
198
199#endif // __H__UG__LIB_DISC__SPATIAL_DISC__PROJECT_LINKER__
200
201/* End of File */
parameterString s
Definition smart_pointer.h:108
constant vector user data
Definition const_user_data.h:187
Type based UserData.
Definition user_data.h:501
const TData * values(size_t s) const
returns all values for a series
Definition user_data.h:516
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition user_data.h:512
virtual base class for reference mappings
Definition reference_mapping_provider.h:53
virtual void update(const MathVector< worldDim > *vCornerCoord)=0
refresh mapping for new set of corners
virtual void jacobian(MathMatrix< worldDim, dim > &J, const MathVector< dim > &locPos) const =0
returns jacobian
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition grid_base_objects.h:157
virtual ReferenceObjectID reference_object_id() const =0
number time() const
get the current evaluation time
Definition user_data.h:285
Definition local_algebra.h:198
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Vector with N entries.
Definition math_vector.h:97
Definition projection_linker.h:53
StdDataLinker< ProjectionLinker< dim >, MathVector< dim >, dim > base_type
Base class type.
Definition projection_linker.h:55
void evaluate(MathVector< dim > vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Computation only of the projection.
Definition projection_linker.h:101
void evaluate(MathVector< dim > &value, const MathVector< dim > &glob_ip, number time, int si) const
Evaluation with no element is impossible.
Definition projection_linker.h:88
ProjectionLinker(SmartPtr< CplUserData< MathVector< dim >, dim > > spVector)
Constructor.
Definition projection_linker.h:61
SmartPtr< DependentUserData< MathVector< dim >, dim > > m_spDVector
Definition projection_linker.h:194
void eval_and_deriv(MathVector< dim > vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, bool bDeriv, int s, std::vector< std::vector< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Computation of the projection and its derivatives.
Definition projection_linker.h:136
SmartPtr< CplUserData< MathVector< dim >, dim > > m_spVector
data to project
Definition projection_linker.h:193
virtual bool requires_grid_fct() const
Returns true because without a grid function, we do not get the element to project to!
Definition projection_linker.h:84
ProjectionLinker(MathVector< dim > vector)
Constructor.
Definition projection_linker.h:73
combines several UserDatas to a new UserData of a specified type
Definition linker.h:54
void set_num_input(size_t num)
sets the number of inputs
Definition linker.h:107
size_t input_common_fct(size_t i, size_t fct) const
returns the number in the common FctGrp for a fct of an input
Definition linker.h:153
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
sets an input
Definition linker.h:114
virtual bool zero_derivative() const
returns if derivative is zero
Definition linker_impl.h:179
#define UG_THROW(msg)
Definition error.h:57
double number
Definition types.h:124
void OrthogProjectVec(vector_t &v, const matrix_t &A)
Orthogonal projection.
Definition math_matrix_vector_functions_common_impl.hpp:251
the ug namespace
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition grid_base_objects.h:74
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836