Line data Source code
1 : /*
2 : * Copyright (c) 2019: G-CSC, Goethe University Frankfurt
3 : * Author: Dmitry Logashenko / Michael Lampe
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 : * Singular (point and line) sources and sinks in ConvectionDiffusion.
35 : */
36 : #ifndef __H__UG__PLUGINS__CD__SINGULAR_SOURCES_AND_SINKS__
37 : #define __H__UG__PLUGINS__CD__SINGULAR_SOURCES_AND_SINKS__
38 :
39 : #include <vector>
40 :
41 : // ug4 headers
42 : #include "lib_disc/spatial_disc/disc_util/fv1_sss.h"
43 : #include "lib_disc/spatial_disc/user_data/user_data.h"
44 :
45 : #ifdef UG_FOR_LUA
46 : #include "bindings/lua/lua_user_data.h"
47 : #endif
48 :
49 : namespace ug {
50 : namespace ConvectionDiffusionPlugin {
51 :
52 : /// class for data for all the CD plugin sources and sinks
53 : template <int dim>
54 0 : class cd_sss_data
55 : {
56 : public:
57 : typedef SmartPtr<CplUserData<number, dim> > user_data_type;
58 : /** the data for the source/sink:
59 : * [0]: total contaminant flux through the point
60 : */
61 : protected:
62 : //MathVector<1> m_values;
63 : number m_values;
64 :
65 : user_data_type m_spData; ///< an alternative method to specify the data
66 :
67 : public:
68 :
69 : /// class construction (there must exist a 'dummy' constructor!)
70 0 : cd_sss_data () {m_values = 0;}
71 :
72 : /// returns the flux
73 0 : number flux () {return m_values ;}
74 :
75 : /// computes the data from the user data object
76 : void compute
77 : (
78 : const MathVector<dim>& x, ///< point where to evaluate
79 : number time, ///< time argument for the evaluation
80 : int si ///< subset where to evaluate
81 : )
82 : {
83 0 : if (m_spData.valid ())
84 0 : (* m_spData) (m_values, x, time, si);
85 : }
86 :
87 : /// sets the data
88 0 : void set (number flux)
89 : {
90 0 : m_values = flux;
91 0 : m_spData = SPNULL;
92 0 : }
93 :
94 : /// sets the data by an object
95 0 : void set (user_data_type spData)
96 : {
97 0 : m_spData = spData;
98 0 : }
99 :
100 : #ifdef UG_FOR_LUA
101 : /// set as a LUA function
102 0 : void set (LuaFunctionHandle func)
103 0 : { m_spData = make_sp (new LuaUserData<number, dim> (func)); }
104 : #endif
105 :
106 : };
107 :
108 : /** Class for markers of the point sources and sinks
109 : *
110 : * Note that there the point sinks are only used for full-dimensional subdomains.
111 : */
112 : class point_sss_marker
113 : {
114 : GridObject * m_elem; ///< grid element for the source/sink (not to take it into account twice)
115 : size_t m_co; ///< corner of the element (not to take it into account twice inside of the element)
116 :
117 : public:
118 :
119 : /// class constructor
120 0 : point_sss_marker () : m_elem (NULL), m_co (0) {};
121 :
122 : /// resets the mark
123 0 : void init () {m_elem = NULL; m_co = 0;}
124 :
125 : /// check and set the element mark
126 : bool marked_for (GridObject * elem, size_t co)
127 : {
128 0 : if (m_elem == NULL)
129 : {
130 0 : m_elem = elem; m_co = co;
131 0 : return true;
132 : }
133 0 : return m_elem == elem && m_co == co;
134 : }
135 : };
136 :
137 : /** Class for markers of the line sources and sinks
138 : *
139 : * Note that for fractures, line sources/sinks are point sources/sinks.
140 : * For full-dimensional subdomains, there is up to now no special markers.
141 : */
142 0 : class line_sss_marker
143 : {
144 : // All the members are used in the fractures only!
145 :
146 : /// a special structure to identify the element and its corner in a fracture
147 : struct t_fract_elem
148 : {
149 : IVertexGroup * fract_face;
150 : size_t fract_co;
151 :
152 0 : t_fract_elem (IVertexGroup * face, size_t co) : fract_face (face), fract_co (co) {};
153 : };
154 :
155 : /// array keeping the elements from different(!) fractures
156 : std::vector<t_fract_elem> m_intersections;
157 :
158 : public:
159 :
160 : /// class constructor
161 : line_sss_marker () {};
162 :
163 : /// reset the mark
164 : void init () {m_intersections.clear ();}
165 :
166 : /// check and set the element mark (use it only for fractures!)
167 0 : bool marked_for (IVertexGroup * elem, size_t co)
168 : {
169 : // is the fracture already processed?
170 0 : for (size_t i = 0; i < m_intersections.size (); i++)
171 : {
172 : // check if we have already registered this mark
173 : t_fract_elem& intersection = m_intersections[i];
174 0 : if (intersection.fract_face == elem)
175 0 : return intersection.fract_co == co;
176 :
177 : // check if a different corner is meant (i.e. this is the same fracture)
178 0 : Vertex * vrt = elem->vertex (co);
179 0 : for (size_t j = 0; j < intersection.fract_face->num_vertices (); j++)
180 0 : if (vrt == intersection.fract_face->vertex (j))
181 : return false; // in this fracture, we use a different corner
182 : }
183 : // no, register this fracture, too
184 0 : m_intersections.push_back (t_fract_elem (elem, co));
185 0 : return true;
186 : }
187 : };
188 :
189 0 : template <int dim> class cd_point_sss_data : public cd_sss_data<dim>, public point_sss_marker {};
190 0 : template <int dim> class cd_line_sss_data : public cd_sss_data<dim>, public line_sss_marker {};
191 : template <int dim>
192 0 : class CDSingularSourcesAndSinks
193 : : public FVSingularSourcesAndSinks<dim, cd_point_sss_data<dim>, cd_line_sss_data<dim> >
194 : {
195 : public:
196 : typedef cd_point_sss_data<dim> user_data_type;
197 : };
198 :
199 : } // namespace ConvectionDiffusionPlugin
200 : } // end namespace ug
201 :
202 : #endif // __H__UG__PLUGINS__CD__SINGULAR_SOURCES_AND_SINKS__
203 :
204 : /* End of File */
|