BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
generalized_fubini_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  double m_)
26  : u(u_), v(v_), m(m_)
27 {
28  if (u <= 0.) {
29  throw Setup_error("Generalized_fubini_potential: u must be positive");
30  }
31  if (v <= 0.) {
32  throw Setup_error("Generalized_fubini_potential: v must be positive");
33  }
34  if (m <= 1.) {
35  throw Setup_error(
36  "Generalized_fubini_potential: m must be greater than 1");
37  }
38 }
39 
41  const Eigen::VectorXd& coords) const
42 {
43  if (coords.size() != 1) {
44  throw Setup_error("Generalized_fubini_potential::partial: "
45  "number of coordinates must be one");
46  }
47 
48  return operator()(coords(0));
49 }
50 
52  const Eigen::VectorXd& coords, int i) const
53 {
54  if (coords.size() != 1) {
55  throw Setup_error("Generalized_fubini_potential::partial: "
56  "number of coordinates must be one");
57  }
58 
59  if (i != 0) {
60  throw Out_of_bounds_error(
61  i, "Generalized_fubini_potential::partial: invalid field index "
62  + std::to_string(i));
63  }
64 
65  return first_deriv(coords(0));
66 }
67 
69  const Eigen::VectorXd& coords, int i, int j) const
70 {
71  if (coords.size() != 1) {
72  throw Setup_error("Generalized_fubini_potential::partial: "
73  "number of coordinates must be one");
74  }
75 
76  if (i != 0) {
77  throw Out_of_bounds_error(
78  i, "Generalized_fubini_potential::partial: invalid field index "
79  + std::to_string(i));
80  }
81 
82  if (j != 0) {
83  throw Out_of_bounds_error(
84  j, "Generalized_fubini_potential::partial: invalid field index "
85  + std::to_string(j));
86  }
87 
88  return second_deriv(coords(0));
89 }
90 
91 double Generalized_fubini_potential::operator()(double coords) const
92 {
93  const double phip = Abs(scale * coords + origin);
94 
95  const auto pow1 = 2. + 1. / m;
96  const auto pow2 = 2. + 2. / m;
97 
98  return (4. * u * m * m * (m - 1.) * std::pow(phip, pow1)) /
99  (2. * m + 1) - 2. * u * v * m * m * std::pow(phip, pow2);
100 }
101 
102 double Generalized_fubini_potential::first_deriv(double coords) const
103 {
104  const double phip = Abs(scale * coords + origin);
105 
106  const auto pow1 = 1. + 1. / m;
107  const auto pow2 = 1. + 2. / m;
108 
109  return 4. * u * m * (m - 1.) * std::pow(phip, pow1)
110  - 4. * u * v * m * (m + 1.) * std::pow(phip, pow2);
111 }
112 
114 {
115  const double phip = Abs(scale * coords + origin);
116 
117  const auto pow1 = 1. / m;
118  const auto pow2 = 2. / m;
119 
120  return 4. * u * (m * m - 1.) * std::pow(phip, pow1)
121  - 4. * u * v * (m * m + 3. * m + 2.) * std::pow(phip, pow2);
122 }
123 
125 {
126  return -origin / scale;
127 }
128 
130 {
131  const double phip = std::pow(m - 1., m) / std::pow(v * (m + 1.), m);
132 
133  return (phip - origin) / scale;
134 }
135 
137 {
138  const double phip = 1. / std::pow(u * r * r + v, m);
139  return (phip - origin) / scale;
140 }
141 
143  const Eigen::VectorXd& rho_values) const
144 {
145  const auto n_grid_points = rho_values.size();
146  Eigen::MatrixXd field_profile(Eigen::MatrixXd::Zero(n_grid_points, 1));
147  for (int i = 0; i < n_grid_points; ++i) {
148  field_profile(i, 0) = get_bounce_solution_at(rho_values(i));
149  }
150 
151  return Field_profiles(rho_values, field_profile);
152 }
153 
155 {
156  return m * Pi * Pi / ((4. * m * m - 1.) * u * std::pow(v, 2. * m - 1.));
157 }
158 
159 } // namespace BubbleProfiler
T Abs(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
virtual double operator()(const Eigen::VectorXd &) const override
Evaluate potential at point.
Exception indicating general setup error.
Definition: error.hpp:32
Discretized set of field profiles.
Field_profiles get_profile(const Eigen::VectorXd &) const