BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
restricted_quartic_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 
21 namespace BubbleProfiler {
22 
24  : alpha(alpha_)
25 {
26  if (alpha <= 0.5 || alpha >= 0.75) {
27  throw Setup_error(
28  "alpha must be between 0.5 and 0.75");
29  }
30 }
31 
33  double alpha_, double E_)
34  : alpha(alpha_)
35  , E(E_)
36 {
37 
38  if (alpha <= 0.5 || alpha >= 0.75) {
39  throw Setup_error(
40  "alpha must be between 0.5 and 0.75");
41  }
42 
43  if (E <= 0.) {
44  throw Setup_error(
45  "E must be positive");
46  }
47 }
48 
50  const Eigen::VectorXd& coords) const
51 {
52  if (coords.size() != 1) {
53  throw Setup_error("Restricted_quartic_potential::partial: "
54  "number of coordinates must be one");
55  }
56 
57  return operator()(coords(0));
58 }
59 
61  const Eigen::VectorXd& coords, int i) const
62 {
63  if (coords.size() != 1) {
64  throw Setup_error("Restricted_quartic_potential::partial: "
65  "number of coordinates must be one");
66  }
67 
68  if (i != 0) {
69  throw Out_of_bounds_error(
70  i, "Restricted_quartic_potential::partial: invalid field index "
71  + std::to_string(i));
72  }
73 
74  return first_deriv(coords(0));
75 }
76 
77 double Restricted_quartic_potential::partial(const Eigen::VectorXd& coords,
78  int i, int j) const
79 {
80  if (coords.size() != 1) {
81  throw Setup_error("Restricted_quartic_potential::partial: "
82  "number of coordinates must be one");
83  }
84 
85  if (i != 0) {
86  throw Out_of_bounds_error(
87  i, "Restricted_quartic_potential::partial: invalid field index "
88  + std::to_string(i));
89  }
90 
91  if (j != 0) {
92  throw Out_of_bounds_error(
93  j, "Restricted_quartic_potential::partial: invalid field index "
94  + std::to_string(j));
95  }
96 
97  return second_deriv(coords(0));
98 }
99 
100 
101 double Restricted_quartic_potential::operator()(double coords) const
102 {
103  const double phip = scale * coords + origin;
104  return 0.5 * (3. - 4. * alpha) * E * phip * phip
105  - E * phip * phip * phip
106  + alpha * E * phip * phip * phip * phip
107  + offset;
108 }
109 
110 double Restricted_quartic_potential::first_deriv(double coords) const
111 {
112  const double phip = scale * coords + origin;
113  return (3. - 4. * alpha) * E * phip - 3. * E * phip * phip
114  + 4. * alpha * E * phip * phip * phip;
115 }
116 
118 {
119  const double phip = scale * coords + origin;
120  return (3. - 4. * alpha) * E - 6. * E * phip
121  + 12. * alpha * E * phip * phip;
122 }
123 
125 {
126  return 1 - origin;
127 }
128 
130 {
131  return -origin;
132 }
133 
135 {
136  return 0.25 * (3. - 4. * alpha) / alpha - origin;
137 }
138 
139 } // namespace BubbleProfiler
virtual double operator()(const Eigen::VectorXd &) const override
Evaluate potential at point.
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
Exception indicating general setup error.
Definition: error.hpp:32