Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Shuai Lu
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__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_USER_DATA__
34 : #define __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_USER_DATA__
35 :
36 : #include "common/common.h"
37 :
38 : #include "lib_disc/spatial_disc/user_data/std_user_data.h"
39 : #include "lib_grid/global_attachments.h"
40 : #include "lib_grid/grid_objects/grid_dim_traits.h"
41 :
42 :
43 : namespace ug{
44 :
45 : template <int WDim, typename TData = number>
46 : class GlobAttachmentElementUserData
47 : : public StdUserData<GlobAttachmentElementUserData<WDim, TData>, TData, WDim>
48 :
49 : {
50 : static const int dim = WDim;
51 : typedef TData data_type;
52 : typedef typename grid_dim_traits<dim>::grid_base_object elem_type;
53 : typedef Attachment<data_type> attachment_type;
54 :
55 : private:
56 : std::string m_attachment_name;
57 : SmartPtr<Grid> m_spGrid;
58 : attachment_type m_att;
59 : Grid::AttachmentAccessor<elem_type, attachment_type> m_aatt;
60 :
61 : /// Evalutation of the attachment in one element
62 : inline void eval_on_elem
63 : (
64 : elem_type * elem, ///< the element to evaluate on
65 : const size_t nip, ///< number of the values to write
66 : data_type vValue [] ///< array for the values
67 : ) const
68 : {
69 0 : for (size_t ip = 0; ip < nip; ++ip)
70 0 : vValue[ip] = m_aatt [elem];
71 : }
72 :
73 : public:
74 :
75 : /// constructor
76 0 : GlobAttachmentElementUserData(SmartPtr<Grid> grid, const char* name)
77 0 : : m_attachment_name(name), m_spGrid(grid)
78 : {
79 0 : if (! GlobalAttachments::is_declared (m_attachment_name))
80 0 : UG_THROW ("GlobAttachmentElementUserData: No global attachment '" << m_attachment_name << "' found.");
81 0 : m_att = GlobalAttachments::attachment<attachment_type> (m_attachment_name);
82 0 : m_aatt.access (*grid, m_att);
83 0 : };
84 :
85 : // UserData interface
86 :
87 0 : virtual bool continuous () const
88 : {
89 0 : return false;
90 : }
91 :
92 0 : virtual bool requires_grid_fct () const
93 : {
94 0 : return true;
95 : }
96 :
97 : // StdUserData interface
98 : template <int refDim>
99 : inline void evaluate
100 : (
101 : data_type vValue[],
102 : const MathVector<dim> vGlobIP[],
103 : number time, int si,
104 : GridObject* elem,
105 : const MathVector<dim> vCornerCoords[],
106 : const MathVector<refDim> vLocIP[],
107 : const size_t nip,
108 : LocalVector* u,
109 : const MathMatrix<refDim, dim>* vJT = NULL
110 : ) const
111 : {
112 : UG_ASSERT (refDim == dim, "GlobAttachmentElementUserData: Dimensionality of the element should be equal to the world dimensionality.");
113 :
114 : eval_on_elem ((elem_type *) elem, nip, vValue);
115 : }
116 :
117 : // StdUserData interface
118 :
119 0 : virtual void compute
120 : (
121 : LocalVector* u,
122 : GridObject* elem,
123 : const MathVector<dim> vCornerCoords[],
124 : bool bDeriv = false
125 : )
126 : {
127 : UG_ASSERT (elem->base_object_id() == dim, "GlobAttachmentElementUserData: Dimensionality of the element should be equal to the world dimensionality.");
128 :
129 0 : for (size_t s = 0; s < this->num_series (); ++s)
130 : eval_on_elem ((elem_type *) elem, this->num_ip (s), this->values (s));
131 0 : }
132 :
133 0 : virtual void compute
134 : (
135 : LocalVectorTimeSeries* u,
136 : GridObject* elem,
137 : const MathVector<dim> vCornerCoords[],
138 : bool bDeriv = false
139 : )
140 : {
141 : UG_ASSERT (elem->base_object_id() == dim, "GlobAttachmentElementUserData: Dimensionality of the element should be equal to the world dimensionality.");
142 :
143 0 : for (size_t s = 0; s < this->num_series (); ++s)
144 : eval_on_elem ((elem_type *) elem, this->num_ip (s), this->values (s));
145 0 : }
146 :
147 0 : virtual void operator () ///< cannot be implemented here
148 : (
149 : data_type& value,
150 : const MathVector<dim>& globIP,
151 : number time, int si
152 : ) const
153 : {
154 0 : UG_THROW("GlobAttachmentElementUserData: Element required"
155 : " for evaluation, but not passed. Cannot evaluate.");
156 : }
157 :
158 0 : virtual void operator () ///< cannot be implemented here
159 : (
160 : data_type vValue[],
161 : const MathVector<dim> vGlobIP[],
162 : number time, int si,
163 : const size_t nip
164 : ) const
165 : {
166 0 : UG_THROW("GlobAttachmentElementUserData: Element required"
167 : " for evaluation, but not passed. Cannot evaluate.");
168 : }
169 : };
170 :
171 :
172 : } // end namespace ug
173 :
174 : #endif /* __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION_USER_DATA__ */
|