Plugins
Loading...
Searching...
No Matches
ls_analytic_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 * Authors: Christian Wehner, Dmitriy 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
33namespace ug{
34namespace LevelSet{
35
36template<typename TGridFunction>
38{
39 switch(dim)
40 {
41 case 1:
42 v[0] = 1;
43 return 0;
44 case 2:
45 v[0] = -x[1];
46 v[1] = x[0];
47 // v[0] = 1;
48 // v[1] = 0;
49// v[0] = 1;
50 // v[1] = 1;
51 return 0;
52 case 3:
53 v[0] = -x[1];
54 v[1] = x[0];
55 v[2] = 0;
56 return 0;
57 };
58 return true;
59};
60
61template<typename TGridFunction>
63{
64 switch(dim)
65 {
66 case 1:
67 return 1;
68 case 2:
69 return 0;
70 case 3:
71 return 1;
72 };
73 return 1;
74};
75
76template<typename TGridFunction>
78{
79 MathVector<dim> xnew;
80 switch(dim)
81 {
82 case 1:
83 //number v=1;
84 //xnew=x-v*t;
85 //return sin(xnew);
86 return 0;
87 case 2:
88 // return 0;
89 //return x[1];//-t;
90 // number z;
91 // z=min(min(std::abs(x[0]-1),std::abs(x[0]+1)),min(std::abs(x[1]-1),std::abs(x[1]+1)));
92 //z=min(min(std::abs(x[0]),std::abs(1-x[0])),min(std::abs(x[1]),std::abs(1-x[1])));
93 // return z;
94 xnew[0] = x[0]*cos(t)+x[1]*sin(t);
95 xnew[1] = -x[0]*sin(t)+x[1]*cos(t);
96 return sqrt((xnew[0]-0.5)*(xnew[0]-0.5) + xnew[1]*xnew[1]) - 0.5;
97 xnew[0] = x[0] - t;
98 xnew[1] = x[1] - t;
99 return x[0]-t;
100 return sqrt(xnew[0]*xnew[0] + xnew[1]*xnew[1]) - 0.5;
101 // return 2*xnew[0]-xnew[1];
102 case 3:
103 return 0;
104 }
105
106 return -1;
107};
108
109template<typename TGridFunction>
110bool LevelSetAnalytic<TGridFunction>::fill_v_vec(TGridFunction& vel,int component)
111{
112 typedef typename domain_type::position_accessor_type position_accessor_type;
113 typedef typename TGridFunction::template traits<Vertex>::const_iterator VertexConstIterator;
114
115 if (component>dim){
116 UG_THROW("fill_v_vec: component > dim.");
117 }
118
119 position_accessor_type aaPos = vel.domain()->position_accessor();
120 for (int si=0;si<vel.num_subsets();++si)
121 {
122 for(VertexConstIterator iter = vel.template begin<Vertex>(si);
123 iter != vel.template end<Vertex>(si); ++iter)
124 {
125 // get vertex
126 Vertex* vrt = *iter;
127 MathVector<dim> coord;
128 MathVector<dim> vnode;
129 coord = aaPos[vrt];
130
131 // get vector holding all indices on the vertex
132 std::vector<DoFIndex> ind;
133
134 vel.inner_dof_indices(vrt, 0, ind);
135 analytic_velocity(vnode,m_time,coord);
136 DoFRef(vel, ind[0]) = vnode[component];
137 }
138 };
139 return true;
140};
141
142// initialize level set function with analytical solution
143template<typename TGridFunction>
145{
146// get domain of grid function
147 domain_type& domain = *u.domain().get();
148
149// get grid type of domain
150 // typedef typename domain_type::grid_type grid_type;
151
152 typedef typename domain_type::position_accessor_type position_accessor_type;
153
154 // read indices on vertex
155 position_accessor_type aaPos = domain.position_accessor();
156
157 typedef typename TGridFunction::template traits<Vertex>::const_iterator VertexConstIterator;
158 for (int si=0;si<domain.subset_handler()->num_subsets();++si){
159 for(VertexConstIterator iter = u.template begin<Vertex>(si);
160 iter != u.template end<Vertex>(si); ++iter)
161 {
162 // get vertex
163 Vertex* vrt = *iter;
164 MathVector<dim> coord;
165 coord = aaPos[vrt];
166 // get vector holding all indices on the vertex
167 std::vector<DoFIndex> ind;
168 u.inner_dof_indices(vrt, 0, ind);
169 DoFRef(u, ind[0]) = analytic_solution(m_time,coord);
170 }
171 };
172 return true;
173};
174
175} // end namespace LevelSet
176} // end namespace ug
177
178/* End of File */
bool analytic_velocity(MathVector< dim > &, number, MathVector< dim >)
Definition ls_analytic_impl.h:37
TGridFunction::domain_type domain_type
domain type
Definition ls_analytic.h:48
number analytic_source(number, MathVector< dim >)
Definition ls_analytic_impl.h:62
bool init_function(TGridFunction &u)
Definition ls_analytic_impl.h:144
number analytic_solution(number, MathVector< dim >)
Definition ls_analytic_impl.h:77
bool fill_v_vec(TGridFunction &vel, int component)
Definition ls_analytic_impl.h:110
size_t num_subsets() const
#define UG_THROW(msg)
double number
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)