BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
logarithmic_potential.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * BubbleProfiler is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
19 #include "error.hpp"
20 #include "math_wrappers.hpp"
21 
22 namespace BubbleProfiler {
23 
25  const Eigen::VectorXd& coords) const
26 {
27  if (coords.size() != 1) {
28  throw Setup_error("Logarithmic_potential::partial: "
29  "number of coordinates must be one");
30  }
31  return this->operator()(coords(0));
32 }
33 
35  const Eigen::VectorXd& coords, int i) const
36 {
37  if (coords.size() != 1) {
38  throw Setup_error("Logarithmic_potential::partial: "
39  "number of coordinates must be one");
40  }
41 
42  if (i != 0) {
43  throw Out_of_bounds_error(
44  i, "Logarithmic_potential::partial: invalid field index "
45  + std::to_string(i));
46  }
47 
48  return first_deriv(coords(0));
49 }
50 
52  const Eigen::VectorXd& coords, int i, int j) const
53 {
54  if (coords.size() != 1) {
55  throw Setup_error("Logarithmic_potential::partial: "
56  "number of coordinates must be one");
57  }
58 
59  if (i != 0) {
60  throw Out_of_bounds_error(
61  i, "Logarithmic_potential::partial: invalid field index "
62  + std::to_string(i));
63  }
64 
65  if (j != 0) {
66  throw Out_of_bounds_error(
67  j, "Logarithmic_potential::partial: invalid field index "
68  + std::to_string(j));
69  }
70 
71  return second_deriv(coords(0));
72 }
73 
74 double Logarithmic_potential::operator()(double coords) const
75 {
76  const double phip = scale * coords + origin;
77 
78  if (Abs(phip) < std::numeric_limits<double>::min()) {
79  return 0.;
80  }
81 
82  return 0.5 * m * m * phip * phip * (1. - Log(phip * phip / (w * w)));
83 }
84 
85 double Logarithmic_potential::first_deriv(double coords) const
86 {
87  const double phip = scale * coords + origin;
88 
89  if (Abs(phip) < std::numeric_limits<double>::min()) {
90  return 0.;
91  }
92 
93  return -m * m * phip * Log(phip * phip / (w * w));
94 }
95 
96 double Logarithmic_potential::second_deriv(double coords) const
97 {
98  const double phip = scale * coords + origin;
99 
100  if (Abs(phip) < std::numeric_limits<double>::min()) {
101  return 0.;
102  }
103 
104  return -m * m * (2. + Log(phip * phip / (w * w)));
105 }
106 
108 {
109  return -origin / scale;
110 }
111 
113 {
114  const double phip = Abs(w);
115 
116  return (phip - origin) / scale;
117 }
118 
120 {
121  const double phip = w * Exp(-0.5 * m * m * r *r + 2.);
122  return (phip - origin) / scale;
123 }
124 
126  const Eigen::VectorXd& rho_values) const
127 {
128  const auto n_grid_points = rho_values.size();
129  Eigen::MatrixXd field_profile(Eigen::MatrixXd::Zero(n_grid_points, 1));
130  for (int i = 0; i < n_grid_points; ++i) {
131  field_profile(i, 0) = get_bounce_solution_at(rho_values(i));
132  }
133 
134  return Field_profiles(rho_values, field_profile);
135 }
136 
138 {
139  return 0.5 * Pi * Pi * Exp(4.) * w * w / (m * m);
140 }
141 
142 } // namespace BubbleProfiler
T Abs(T x) noexcept
virtual double operator()(const Eigen::VectorXd &) const override
Evaluate potential at point.
T Exp(T x) noexcept
T Log(T x) noexcept
virtual double partial(const Eigen::VectorXd &, int) const override
Partial derivative WRT coordinate i at a point.
Exception indicating out of bounds access error.
Definition: error.hpp:75
Field_profiles get_profile(const Eigen::VectorXd &) const
Exception indicating general setup error.
Definition: error.hpp:32
Discretized set of field profiles.