Line data Source code
1 : /*
2 : * Copyright (c) 2021 - : G-CSC, Goethe University Frankfurt
3 : * Author: Arne Naegel
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 : * User data of a subset indicator (1 in the subset, 0 everywhere else)
35 : */
36 : #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__LINE_USER_DATA__
37 : #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__LINE_USER_DATA__
38 :
39 : #include <vector>
40 :
41 : // ug4 headers
42 : #include "common/common.h"
43 : #include "common/math/ugmath.h"
44 : #include "lib_disc/spatial_disc/user_data/std_user_data.h"
45 :
46 : namespace ug {
47 :
48 : /// User data for the orientation of a line element
49 : template <typename TDomain>
50 : class EdgeOrientation
51 : : public StdUserData<EdgeOrientation<TDomain>, MathVector<TDomain::dim>, TDomain::dim>
52 : {
53 : public:
54 : /// World dimension
55 : static const int dim = TDomain::dim;
56 :
57 : /// Return type
58 : typedef MathVector<dim> return_type;
59 :
60 : /// Type of domain
61 : typedef StdUserData<EdgeOrientation<TDomain>, MathVector<TDomain::dim>, TDomain::dim, void> base_type;
62 : typedef CplUserData<MathVector<TDomain::dim>, TDomain::dim> cpl_user_data;
63 :
64 :
65 :
66 : public:
67 :
68 : /// Constructor
69 0 : EdgeOrientation(SmartPtr<TDomain> domain) : m_spDomain(domain)
70 0 : {}
71 :
72 : /// Indicator functions are discontinuous
73 0 : virtual bool continuous () const {return false;}
74 :
75 : /// Returns true to get the grid element in the evaluation routine
76 0 : virtual bool requires_grid_fct () const {return true;}
77 :
78 : /// This function should not be used
79 0 : void operator() (return_type & vValue, const MathVector<dim> & globIP, number time, int si) const
80 0 : { UG_THROW("SubsetIndicatorUserData: Element required for evaluation, but not passed. Cannot evaluate."); }
81 :
82 : /// This function should not be used
83 0 : void operator() (return_type vValue [], const MathVector<dim> vGlobIP [], number time, int si, const size_t nip) const
84 0 : { UG_THROW("SubsetIndicatorUserData: Element required for evaluation, but not passed. Cannot evaluate."); }
85 :
86 :
87 0 : inline void elem_evaluate(return_type &delta, GridObject * elem) const
88 : {
89 : auto& aaPos = m_spDomain->position_accessor();
90 0 : EdgeVertices *e = dynamic_cast<EdgeVertices*> (elem);
91 : UG_ASSERT(e != NULL, "ERROR: No edge! ");
92 :
93 0 : VecSubtract(delta, aaPos[e->vertex(1)], aaPos[e->vertex(0)]); // v = e_1 - e_0
94 : delta /= VecLength(delta); // normalize
95 0 : }
96 :
97 :
98 :
99 : /// Evaluator
100 : template <int refDim>
101 : inline void evaluate
102 : (
103 : return_type vValue [],
104 : const MathVector<dim> vGlobIP [],
105 : number time,
106 : int si,
107 : GridObject * elem,
108 : const MathVector<dim> vCornerCoords [],
109 : const MathVector<refDim> vLocIP [],
110 : const size_t nip,
111 : LocalVector * u,
112 : const MathMatrix<refDim, dim> * vJT = NULL
113 : ) const
114 : {
115 :
116 : MathVector<dim> delta;
117 0 : elem_evaluate(delta, elem);
118 :
119 0 : for (size_t i = 0; i < nip; i++)
120 : {
121 0 : vValue[i] = delta;
122 : }
123 :
124 : };
125 :
126 : /// implement as a UserData
127 0 : virtual void compute(LocalVector* u, GridObject* elem,
128 : const MathVector<dim> vCornerCoords[], bool bDeriv = false)
129 : {
130 0 : for(size_t s = 0; s < this->num_series(); ++s)
131 0 : for(size_t ip = 0; ip < this->num_ip(s); ++ip)
132 0 : elem_evaluate(this->value(s,ip), elem);
133 0 : }
134 :
135 : /// implement as a UserData
136 0 : virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
137 : const MathVector<dim> vCornerCoords[], bool bDeriv = false)
138 : {
139 0 : for(size_t s = 0; s < this->num_series(); ++s)
140 0 : for(size_t ip = 0; ip < this->num_ip(s); ++ip)
141 0 : elem_evaluate(this->value(s,ip), elem);
142 0 : }
143 :
144 :
145 : protected:
146 : SmartPtr<TDomain> m_spDomain;
147 : };
148 :
149 : } // end namespace ug
150 :
151 : #endif // __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__LINE_USER_DATA__
152 :
153 : /* End of File */
|