Reference documentation for deal.II version 8.5.1
function_lib_cutoff.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/tensor.h>
17 #include <deal.II/base/point.h>
18 #include <deal.II/base/function_lib.h>
19 #include <deal.II/lac/vector.h>
20 
21 #include <cmath>
22 
23 DEAL_II_NAMESPACE_OPEN
24 
25 
26 namespace Functions
27 {
28  template<int dim>
30  const Point<dim> p,
31  const unsigned int n_components,
32  const unsigned int select)
33  :
34  Function<dim> (n_components),
35  center(p),
36  radius(r),
37  selected(select)
38  {}
39 
40 
41  template<int dim>
42  void
44  {
45  center = p;
46  }
47 
48 
49  template<int dim>
50  void
52  {
53  radius = r;
54  }
55 
57 
58  template<int dim>
60  const Point<dim> p,
61  const unsigned int n_components,
62  const unsigned int select)
63  :
64  CutOffFunctionBase<dim> (r, p, n_components, select)
65  {}
66 
67 
68  template<int dim>
69  double
71  const unsigned int component) const
72  {
73  if (this->selected==CutOffFunctionBase<dim>::no_component
74  ||
75  component==this->selected)
76  return ((this->center.distance(p)<this->radius) ? 1. : 0.);
77  return 0.;
78  }
79 
80 
81  template<int dim>
82  void
83  CutOffFunctionLinfty<dim>::value_list (const std::vector<Point<dim> > &points,
84  std::vector<double> &values,
85  const unsigned int component) const
86  {
87  Assert (values.size() == points.size(),
88  ExcDimensionMismatch(values.size(), points.size()));
89  Assert (component < this->n_components,
90  ExcIndexRange(component,0,this->n_components));
91 
92 
93  if (this->selected==CutOffFunctionBase<dim>::no_component
94  ||
95  component==this->selected)
96  for (unsigned int k=0; k<values.size(); ++k)
97  values[k] = (this->center.distance(points[k])<this->radius) ? 1. : 0.;
98  else
99  std::fill (values.begin(), values.end(), 0.);
100  }
101 
102 
103  template<int dim>
104  void
106  const std::vector<Point<dim> > &points,
107  std::vector<Vector<double> > &values) const
108  {
109  Assert (values.size() == points.size(),
110  ExcDimensionMismatch(values.size(), points.size()));
111 
112  for (unsigned int k=0; k<values.size(); ++k)
113  {
114  const double
115  val = (this->center.distance(points[k])<this->radius) ? 1. : 0.;
116  if (this->selected==CutOffFunctionBase<dim>::no_component)
117  values[k] = val;
118  else
119  {
120  values[k] = 0;
121  values[k](this->selected) = val;
122  }
123  }
124  }
125 
126 
127  template<int dim>
129  const Point<dim> p,
130  const unsigned int n_components,
131  const unsigned int select)
132  :
133  CutOffFunctionBase<dim> (r, p, n_components, select)
134  {}
135 
136 
137  template<int dim>
138  double
140  const unsigned int component) const
141  {
142  if (this->selected==CutOffFunctionBase<dim>::no_component
143  ||
144  component==this->selected)
145  {
146  const double d = this->center.distance(p);
147  return ((d<this->radius) ? (this->radius-d) : 0.);
148  }
149  return 0.;
150  }
151 
152 
153  template<int dim>
154  void
155  CutOffFunctionW1<dim>::value_list (const std::vector<Point<dim> > &points,
156  std::vector<double> &values,
157  const unsigned int component) const
158  {
159  Assert (values.size() == points.size(),
160  ExcDimensionMismatch(values.size(), points.size()));
161 
162  if (this->selected==CutOffFunctionBase<dim>::no_component
163  ||
164  component==this->selected)
165  for (unsigned int i=0; i<values.size(); ++i)
166  {
167  const double d = this->center.distance(points[i]);
168  values[i] = ((d<this->radius) ? (this->radius-d) : 0.);
169  }
170  else
171  std::fill (values.begin(), values.end(), 0.);
172  }
173 
174 
175 
176  template<int dim>
177  void
179  const std::vector<Point<dim> > &points,
180  std::vector<Vector<double> > &values) const
181  {
182  Assert (values.size() == points.size(),
183  ExcDimensionMismatch(values.size(), points.size()));
184 
185  for (unsigned int k=0; k<values.size(); ++k)
186  {
187  const double d = this->center.distance(points[k]);
188  const double
189  val = (d<this->radius) ? (this->radius-d) : 0.;
190  if (this->selected==CutOffFunctionBase<dim>::no_component)
191  values[k] = val;
192  else
193  {
194  values[k] = 0;
195  values[k](this->selected) = val;
196  }
197  }
198  }
199 
200 
201  template<int dim>
203  const Point<dim> p,
204  const unsigned int n_components,
205  const unsigned int select)
206  :
207  CutOffFunctionBase<dim> (r, p, n_components, select)
208  {}
209 
210 
211  template<int dim>
212  double
214  const unsigned int component) const
215  {
216  if (this->selected==CutOffFunctionBase<dim>::no_component
217  ||
218  component==this->selected)
219  {
220  const double d = this->center.distance(p);
221  const double r = this->radius;
222  if (d>=r)
223  return 0.;
224  const double e = -r*r/(r*r-d*d);
225  return ((e<-50) ? 0. : numbers::E * exp(e));
226  }
227  return 0.;
228  }
229 
230 
231  template<int dim>
232  void
233  CutOffFunctionCinfty<dim>::value_list (const std::vector<Point<dim> > &points,
234  std::vector<double> &values,
235  const unsigned int component) const
236  {
237  Assert (values.size() == points.size(),
238  ExcDimensionMismatch(values.size(), points.size()));
239 
240  const double r = this->radius;
241 
242  if (this->selected==CutOffFunctionBase<dim>::no_component
243  ||
244  component==this->selected)
245  for (unsigned int i=0; i<values.size(); ++i)
246  {
247  const double d = this->center.distance(points[i]);
248  if (d>=r)
249  {
250  values[i] = 0.;
251  }
252  else
253  {
254  const double e = -r*r/(r*r-d*d);
255  values[i] = (e<-50) ? 0. : numbers::E * exp(e);
256  }
257  }
258  else
259  std::fill (values.begin(), values.end(), 0.);
260  }
261 
262 
263  template<int dim>
264  void
266  const std::vector<Point<dim> > &points,
267  std::vector<Vector<double> > &values) const
268  {
269  Assert (values.size() == points.size(),
270  ExcDimensionMismatch(values.size(), points.size()));
271 
272  for (unsigned int k=0; k<values.size(); ++k)
273  {
274  const double d = this->center.distance(points[k]);
275  const double r = this->radius;
276  double val = 0.;
277  if (d<this->radius)
278  {
279  const double e = -r*r/(r*r-d*d);
280  if (e>-50)
281  val = numbers::E * exp(e);
282  }
283 
284  if (this->selected==CutOffFunctionBase<dim>::no_component)
285  values[k] = val;
286  else
287  {
288  values[k] = 0;
289  values[k](this->selected) = val;
290  }
291  }
292  }
293 
294 
295 
296  template<int dim>
299  const unsigned int) const
300  {
301  const double d = this->center.distance(p);
302  const double r = this->radius;
303  if (d>=r)
304  return Tensor<1,dim>();
305  const double e = -d*d/(r-d)/(r+d);
306  return ((e<-50) ?
307  Point<dim>() :
308  (p-this->center)/d*(-2.0*r*r/pow(-r*r+d*d,2.0)*d*exp(e)));
309  }
310 
311 
312 // explicit instantiations
313  template class CutOffFunctionLinfty <1>;
314  template class CutOffFunctionLinfty <2>;
315  template class CutOffFunctionLinfty <3>;
316 
317  template class CutOffFunctionW1 <1>;
318  template class CutOffFunctionW1 <2>;
319  template class CutOffFunctionW1 <3>;
320 
321  template class CutOffFunctionCinfty <1>;
322  template class CutOffFunctionCinfty <2>;
323  template class CutOffFunctionCinfty <3>;
324 }
325 
326 DEAL_II_NAMESPACE_CLOSE
virtual Tensor< 1, dim > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< double > > &values) const
CutOffFunctionLinfty(const double radius=1., const Point< dim >=Point< dim >(), const unsigned int n_components=1, const unsigned int select=CutOffFunctionBase< dim >::no_component)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< double > > &values) const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
virtual double value(const Point< dim > &p, const unsigned int component=0) const
void new_center(const Point< dim > &p)
#define Assert(cond, exc)
Definition: exceptions.h:313
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static const double E
Definition: numbers.h:69
CutOffFunctionBase(const double radius=1., const Point< dim >=Point< dim >(), const unsigned int n_components=1, const unsigned int select=CutOffFunctionBase< dim >::no_component)
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< double > &values, const unsigned int component=0) const
numbers::NumberTraits< Number >::real_type distance(const Point< dim, Number > &p) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< double > > &values) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< double > &values, const unsigned int component=0) const
virtual double value(const Point< dim > &p, const unsigned int component=0) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< double > &values, const unsigned int component=0) const
CutOffFunctionCinfty(const double radius=1., const Point< dim >=Point< dim >(), const unsigned int n_components=1, const unsigned int select=CutOffFunctionBase< dim >::no_component)
CutOffFunctionW1(const double radius=1., const Point< dim >=Point< dim >(), const unsigned int n_components=1, const unsigned int select=CutOffFunctionBase< dim >::no_component)
virtual double value(const Point< dim > &p, const unsigned int component=0) const