16 #include <deal.II/grid/tria.h> 17 #include <deal.II/grid/tria_iterator.h> 18 #include <deal.II/grid/tria_accessor.h> 19 #include <deal.II/grid/manifold_lib.h> 20 #include <deal.II/base/tensor.h> 21 #include <deal.II/lac/vector.h> 24 DEAL_II_NAMESPACE_OPEN
30 template <
int dim,
int spacedim>
36 template <
int dim,
int spacedim>
50 template <
int dim,
int spacedim>
54 Assert(spherical_point[0] >=0.0,
55 ExcMessage(
"Negative radius for given point."));
56 const double rho = spherical_point[0];
57 const double theta = spherical_point[1];
64 p[0] = rho*
cos(theta);
65 p[1] = rho*
sin(theta);
69 const double phi= spherical_point[2];
70 p[0] = rho*
sin(theta)*
cos(phi);
71 p[1] = rho*
sin(theta)*
sin(phi);
72 p[2] = rho*
cos(theta);
81 template <
int dim,
int spacedim>
86 const double rho = R.
norm();
95 p[1] = atan2(R[1],R[0]);
103 const double z = R[2];
104 p[2] = atan2(R[1],R[0]);
107 p[1] = atan2(
sqrt(R[0]*R[0]+R[1]*R[1]),z);
117 template <
int dim,
int spacedim>
121 Assert(spherical_point[0] >= 0.0,
122 ExcMessage(
"Negative radius for given point."));
123 const double rho = spherical_point[0];
124 const double theta = spherical_point[1];
132 DX[0][0] =
cos(theta);
133 DX[0][1] = -rho*
sin(theta);
134 DX[1][0] =
sin(theta);
135 DX[1][1] = rho*
cos(theta);
141 const double phi= spherical_point[2];
142 DX[0][0] =
sin(theta)*
cos(phi);
143 DX[0][1] = rho*
cos(theta)*
cos(phi);
144 DX[0][2] = -rho*
sin(theta)*
sin(phi);
146 DX[1][0] =
sin(theta)*
sin(phi);
147 DX[1][1] = rho*
cos(theta)*
sin(phi);
148 DX[1][2] = rho*
sin(theta)*
cos(phi);
150 DX[2][0] =
cos(theta);
151 DX[2][1] = -rho*
sin(theta);
166 template <
int dim,
int spacedim>
171 template <
int dim,
int spacedim>
176 const double w)
const 178 Assert(w >=0.0 && w <= 1.0,
179 ExcMessage(
"w should be in the range [0.0,1.0]."));
181 const double tol = 1e-10;
183 if ( p1.
distance(p2) < tol || w < tol)
185 else if (w > 1.0 - tol)
195 const double r1 = v1.
norm();
196 const double r2 = v2.
norm();
198 Assert(r1 > tol && r2 > tol,
199 ExcMessage(
"p1 and p2 cannot coincide with the center."));
204 if ((e1 - e2).norm_square() < tol*tol)
208 const double gamma = std::acos(e1*e2);
211 const double sigma = w * gamma;
218 "Probably this means v1==v2 or v2==0."));
230 template <
int dim,
int spacedim>
239 const double r1 = (p1 - center).norm();
240 const double r2 = (p2 - center).norm();
243 ExcMessage(
"p1 cannot coincide with the center."));
246 ExcMessage(
"p2 cannot coincide with the center."));
251 Assert(e1*e2 + 1.0 > 1e-10,
252 ExcMessage(
"p1 and p2 cannot lie on the same diameter and be opposite " 253 "respect to the center."));
259 const double gamma = std::acos(e1*e2);
261 return (r1-r2)*e1 + r1*gamma*tg;
264 template <
int dim,
int spacedim>
272 template <
int dim,
int spacedim>
276 const std::vector<double> &weights)
const 278 const unsigned int n_points = vertices.size();
282 for (
unsigned int i = 0; i<n_points; i++)
285 rho += direction.
norm()*weights[i];
286 candidate += direction*weights[i];
290 candidate /= candidate.
norm();
292 return center+rho*candidate;
299 template <
int dim,
int spacedim>
301 const double tolerance) :
302 direction (
Point<spacedim>::unit_vector(axis)),
303 point_on_axis (
Point<spacedim>()),
310 template <
int dim,
int spacedim>
313 const double tolerance) :
314 direction (direction),
315 point_on_axis (point_on_axis),
324 template <
int dim,
int spacedim>
334 template <
int dim,
int spacedim>
338 const std::vector<double> &weights)
const 341 const Point<spacedim> middle = flat_manifold.get_new_point(surrounding_points,
347 for (
unsigned int i=0; i<surrounding_points.size(); ++i)
349 on_plane = surrounding_points[i]-point_on_axis;
350 on_plane = on_plane - (on_plane*direction) * direction;
351 radius += weights[i]*on_plane.
norm();
358 ((middle-point_on_axis) * direction) * direction;
362 if (vector_from_axis.
norm() <= tolerance * middle.
norm())
367 ((middle-point_on_axis) * direction) * direction +
375 template <
int dim,
int spacedim,
int chartdim>
380 const double tolerance):
382 push_forward_function(&push_forward_function),
383 pull_back_function(&pull_back_function),
384 tolerance(tolerance),
391 template <
int dim,
int spacedim,
int chartdim>
393 (
const std::string push_forward_expression,
394 const std::string pull_back_expression,
397 const std::string chart_vars,
398 const std::string space_vars,
399 const double tolerance,
402 const_map(const_map),
403 tolerance(tolerance),
408 pf->
initialize(chart_vars, push_forward_expression, const_map);
409 pb->
initialize(space_vars, pull_back_expression, const_map);
410 push_forward_function = pf;
411 pull_back_function = pb;
414 template <
int dim,
int spacedim,
int chartdim>
417 if (owns_pointers ==
true)
420 push_forward_function = 0;
424 pull_back_function = 0;
429 template <
int dim,
int spacedim,
int chartdim>
436 for (
unsigned int i=0; i<spacedim; ++i)
442 for (
unsigned int i=0; i<chartdim; ++i)
444 (std::abs(pb[i]-chart_point[i]) < tolerance*chart_point.
norm())) ||
445 (std::abs(pb[i]-chart_point[i]) < tolerance),
446 ExcMessage(
"The push forward is not the inverse of the pull back! Bailing out."));
453 template <
int dim,
int spacedim,
int chartdim>
458 std::vector<Tensor<1, chartdim> > gradients(spacedim);
460 for (
unsigned int i=0; i<spacedim; ++i)
461 for (
unsigned int j=0; j<chartdim; ++j)
462 DF[i][j] = gradients[i][j];
467 template <
int dim,
int spacedim,
int chartdim>
474 for (
unsigned int i=0; i<chartdim; ++i)
488 double phi = atan2(y, x);
489 double theta = atan2(z, std::sqrt(x*x+y*y)-R);
490 double w = std::sqrt(
pow(y-
sin(phi)*R, 2.0)+
pow(x-
cos(phi)*R, 2.0)+z*z)/r;
498 double phi = chart_point(0);
499 double theta = chart_point(1);
500 double w = chart_point(2);
526 double phi = chart_point(0);
527 double theta = chart_point(1);
528 double w = chart_point(2);
530 DX[0][0] = -
sin(phi)*R - r*w*
cos(theta)*
sin(phi);
531 DX[0][1] = -r*w*
sin(theta)*
cos(phi);
532 DX[0][2] = r*
cos(theta)*
cos(phi);
535 DX[1][1] = r*w*
cos(theta);
536 DX[1][2] = r*
sin(theta);
538 DX[2][0] =
cos(phi)*R + r*w*
cos(theta)*
cos(phi);
539 DX[2][1] = -r*w*
sin(theta)*
sin(phi);
540 DX[2][2] = r*
cos(theta)*
sin(phi);
548 #include "manifold_lib.inst" 550 DEAL_II_NAMESPACE_CLOSE
virtual Point< spacedim > get_new_point(const ::Quadrature< spacedim > &quadrature) const 1
#define AssertDimension(dim1, dim2)
FunctionManifold(const Function< chartdim > &push_forward_function, const Function< spacedim > &pull_back_function, const Tensor< 1, chartdim > &periodicity=Tensor< 1, chartdim >(), const double tolerance=1e-10)
static Tensor< 1, spacedim > get_periodicity()
const std::vector< Point< dim > > & get_points() const
const std::vector< double > & get_weights() const
numbers::NumberTraits< Number >::real_type norm() const
TorusManifold(const double R, const double r)
const unsigned int n_components
virtual Point< spacedim > get_new_point(const Quadrature< spacedim > &quad) const 1
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual DerivativeForm< 1, spacedim, spacedim > push_forward_gradient(const Point< spacedim > &chart_point) const
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
CylindricalManifold(const unsigned int axis=0, const double tolerance=1e-10)
PolarManifold(const Point< spacedim > center=Point< spacedim >())
#define Assert(cond, exc)
virtual Point< 3 > pull_back(const Point< 3 > &p) const
VectorizedArray< Number > pow(const ::VectorizedArray< Number > &x, const Number p)
virtual Point< chartdim > pull_back(const Point< spacedim > &space_point) const
virtual Point< spacedim > get_intermediate_point(const Point< spacedim > &p1, const Point< spacedim > &p2, const double w) const
numbers::NumberTraits< Number >::real_type distance(const Point< dim, Number > &p) const
virtual Point< spacedim > push_forward(const Point< chartdim > &chart_point) const
VectorizedArray< Number > sqrt(const ::VectorizedArray< Number > &x)
VectorizedArray< Number > sin(const ::VectorizedArray< Number > &x)
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
virtual DerivativeForm< 1, chartdim, spacedim > push_forward_gradient(const Point< chartdim > &chart_point) const
virtual Point< spacedim > pull_back(const Point< spacedim > &space_point) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, Number > > &gradients) const
static ::ExceptionBase & ExcNotImplemented()
virtual Point< 3 > push_forward(const Point< 3 > &chart_point) const
SphericalManifold(const Point< spacedim > center=Point< spacedim >())
virtual Tensor< 1, spacedim > get_tangent_vector(const Point< spacedim > &x1, const Point< spacedim > &x2) const
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
virtual DerivativeForm< 1, 3, 3 > push_forward_gradient(const Point< 3 > &chart_point) const
VectorizedArray< Number > cos(const ::VectorizedArray< Number > &x)
virtual Point< spacedim > push_forward(const Point< spacedim > &chart_point) const
static ::ExceptionBase & ExcInternalError()