Plugins
Loading...
Searching...
No Matches
level_set_ave_data.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021: 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 * Tools for averaging of variable values in the elements (mainly for plotting)
35 */
36#ifndef __H__UG__PLUGINS__LEVEL_SET_AVE_DATA_H__
37#define __H__UG__PLUGINS__LEVEL_SET_AVE_DATA_H__
38
39#include <vector>
40#include <iostream>
41#include <limits>
42#include <cmath>
43
44#include "common/common.h"
45
56
57namespace ug {
58namespace LevelSet {
59
67template <typename TGridFunction>
69: public StdDependentUserData<LSAveData<TGridFunction>, number, TGridFunction::dim>
70{
71public:
73 typedef TGridFunction gf_type;
74
76 static const int dim = gf_type::dim;
77
80
83
85 typedef typename gf_type::domain_type domain_type;
86
88 typedef typename gf_type::algebra_type algebra_type;
89
92
93public:
94
97 (
98 SmartPtr<gf_type> sp_gf,
99 const char * fct_name
100 )
101 : m_sp_gf (sp_gf)
102 {
103 if ((m_fct = sp_gf->fct_id_by_name (fct_name)) >= sp_gf->num_fct ())
104 UG_THROW ("LSAveData: Function space does not contain any function with name '" << fct_name << "'.");
105
106 if (sp_gf->local_finite_element_id (m_fct) != LFEID(LFEID::LAGRANGE, dim, 1))
107 UG_THROW ("LSAveData: Only vertex-centered grid functions are supported.");
108 }
109
111 virtual ~LSAveData () {}
112
114 void set_extrapolation (SmartPtr<extrapol_type> sp_extrapol) {m_sp_extrapol = sp_extrapol;}
115
117 virtual bool continuous () const {return false;}
118
120 virtual bool requires_grid_fct () const {return true;}
121
123 template <int refDim>
125 (
126 number vValue[],
127 const MathVector<dim> vGlobIP[],
128 number time,
129 int si,
130 GridObject* elem,
131 const MathVector<dim> vCornerCoords[],
132 const MathVector<refDim> vLocIP[],
133 const size_t nip,
134 LocalVector* u,
135 bool bDeriv,
136 int s,
137 std::vector<std::vector<number> > vvvDeriv[],
138 const MathMatrix<refDim, dim>* vJT = NULL
139 )
140 {
141 // reference object id
142 const ReferenceObjectID roid = elem->reference_object_id();
143 const DimReferenceElement<dim>& r_ref_elem = ReferenceElementProvider::get<dim>(roid);
144
145 // check if the element is inside/cut/outside
146 int inside = 1;
147 if(m_sp_extrapol.valid ())
148 {
149 int g_level = m_sp_gf->grid_level().level();
150
151 if (g_level == GridLevel::TOP)
152 g_level = m_sp_gf->approx_space()->num_levels () - 1;
153
154 if ((inside = ((extrapol_type *) m_sp_extrapol.get())->check_elem_lsf
155 (r_ref_elem.num (0), elem, si, g_level, false, vCornerCoords, time)) < 0)
156 {
157 for(size_t ip = 0; ip < nip; ++ip) // element outside
158 vValue[ip] = 0; //TODO: set the interface value
159 return;
160 }
161 }
162
163 // get multiindices of element
164 std::vector<DoFIndex> ind;
165 m_sp_gf->dof_indices (elem, m_fct, ind);
166 if (ind.size () != r_ref_elem.num (0))
167 UG_THROW ("LSAveData: Wrong number of values per element.");
168
169 // average the values
170 size_t n_vals = 0;
171 number sum = 0;
172 for (size_t co = 0; co < ind.size (); co++)
173 {
174 if (inside == 0 && ! m_sp_extrapol->corner_inside (co))
175 continue;
176 sum += DoFRef (*m_sp_gf, ind[co]);
177 n_vals++;
178 }
179 if (n_vals != 0) // if the element is inside
180 sum /= n_vals;
181 else
182 sum = 0; //TODO: set the interface value (this point should be unreachable)
183
184 // return the result
185 for (size_t ip = 0; ip < nip; ip++)
186 vValue[ip] = sum;
187 }
188
189private:
190
192 size_t m_fct;
194};
195
196} // namespace LevelSet
197} // end namespace ug
198
199#endif // __H__UG__PLUGINS__LEVEL_SET_POSITION_H__
200
201/* End of File */
parameterString s
Definition Biogas.lua:2
virtual ReferenceObjectID reference_object_id() const=0
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
Definition level_set_ave_data.h:70
size_t m_fct
the function inside of the grid function
Definition level_set_ave_data.h:192
gf_type::domain_type domain_type
domain type
Definition level_set_ave_data.h:85
void eval_and_deriv(number 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< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL)
Performs the main computations:
Definition level_set_ave_data.h:125
TGridFunction gf_type
type of the grid function
Definition level_set_ave_data.h:73
virtual bool continuous() const
These are element-based data, they are not continuous.
Definition level_set_ave_data.h:117
virtual ~LSAveData()
Destructor.
Definition level_set_ave_data.h:111
gf_type::algebra_type algebra_type
algebra type
Definition level_set_ave_data.h:88
IInterfaceExtrapolation< domain_type, algebra_type > extrapol_type
extrapolation type
Definition level_set_ave_data.h:91
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition level_set_ave_data.h:120
StdDependentUserData< this_type, number, dim > base_type
the base type
Definition level_set_ave_data.h:82
SmartPtr< gf_type > m_sp_gf
the grid function
Definition level_set_ave_data.h:191
LSAveData< gf_type > this_type
this type
Definition level_set_ave_data.h:79
LSAveData(SmartPtr< gf_type > sp_gf, const char *fct_name)
Constructor.
Definition level_set_ave_data.h:97
static const int dim
world dimension
Definition level_set_ave_data.h:76
SmartPtr< extrapol_type > m_sp_extrapol
the extrapolation (if any)
Definition level_set_ave_data.h:193
void set_extrapolation(SmartPtr< extrapol_type > sp_extrapol)
Set the extrapolation (if any)
Definition level_set_ave_data.h:114
size_t num(int dim) const
#define UG_THROW(msg)
double number
ReferenceObjectID
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)