-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_8cpp-example.html
101 lines (99 loc) · 23.1 KB
/
action_8cpp-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>BubbleProfiler: action.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">BubbleProfiler
 <span id="projectnumber">0.3.0</span>
</div>
<div id="projectbrief">by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">action.cpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * This file is part of BubbleProfiler.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * BubbleProfiler is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment"> * (at your option) any later version.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * BubbleProfiler is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include "<a class="code" href="error_8hpp.html">error.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="logging__manager_8hpp.html">logging_manager.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="restricted__quartic__potential_8hpp.html">restricted_quartic_potential.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="shooting_8hpp.html">shooting.hpp</a>"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <iostream></span></div><div class="line"><span class="preprocessor">#include <string></span></div><div class="line"><span class="preprocessor">#include <vector></span></div><div class="line"></div><div class="line"><span class="keyword">namespace </span><a class="code" href="namespaceBubbleProfiler.html">BubbleProfiler</a> {</div><div class="line"></div><div class="line"><span class="keyword">struct </span>Action_options {</div><div class="line"> <span class="keywordtype">double</span> <a name="a0"></a><a class="code" href="structBubbleProfiler_1_1Action__options.html#af602ea1ac3c1fc49977fbf87ed18a510">E</a>{1.};</div><div class="line"> <span class="keywordtype">double</span> <a name="a1"></a><a class="code" href="structBubbleProfiler_1_1Action__options.html#aac608e57171e32ee20cd854e1fe1bd77">alpha</a>{0.6};</div><div class="line"> <span class="keywordtype">int</span> <a name="a2"></a><a class="code" href="structBubbleProfiler_1_1Action__options.html#a1eaabbb6631736a782468314df58564a">dim</a>{4};</div><div class="line"> <span class="keywordtype">bool</span> <a name="a3"></a><a class="code" href="structBubbleProfiler_1_1Action__options.html#abdf6acac8384e7604ce403c904722ea8">verbose</a>{<span class="keyword">false</span>};</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="namespaceBubbleProfiler.html#acab5942407649d2603764aab33a22df1">print_usage</a>()</div><div class="line">{</div><div class="line"> std::cout <<</div><div class="line"> <span class="stringliteral">"Usage: quartic [OPTION] <E> <alpha> <dim>\n\n"</span></div><div class="line"> <span class="stringliteral">"Calculate action for one-dimensional quartic potential\n"</span></div><div class="line"> <span class="stringliteral">"parameterized by E and alpha.\n\n"</span></div><div class="line"> <span class="stringliteral">"Example: quartic 1.0 0.6 3\n\n"</span></div><div class="line"> <span class="stringliteral">"Options:\n"</span></div><div class="line"> <span class="stringliteral">" -h, --help print this help message\n"</span></div><div class="line"> <span class="stringliteral">" -v, --verbose produce verbose output"</span></div><div class="line"> << std::endl;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> <a name="a5"></a><a class="code" href="namespaceBubbleProfiler.html#a2e73ba2498dd7c9c1f2a0bff88ea2e50">starts_with</a>(<span class="keyword">const</span> std::string& option, <span class="keyword">const</span> std::string& prefix)</div><div class="line">{</div><div class="line"> <span class="keywordflow">return</span> !option.compare(0, prefix.size(), prefix);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> <a name="a6"></a><a class="code" href="namespaceBubbleProfiler.html#a58adee7dfbf3d9200ee173ee6bc0da73">parse_positional_args</a>(<span class="keyword">const</span> std::vector<std::string>& <a name="a7"></a><a class="code" href="namespacesm__plus__singlet.html#aa88589445a1cabdb3fba211d7a2e507c">args</a>,</div><div class="line"> Action_options& options)</div><div class="line">{</div><div class="line"> <span class="keyword">const</span> <span class="keyword">auto</span> n_positional_args = args.size();</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (n_positional_args == 0) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"value of E must be provided"</span>);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_positional_args == 1) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"value of alpha must be provided"</span>);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_positional_args == 2) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"number of dimensions must be provided"</span>);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_positional_args > 3) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"unrecognized command line argument '"</span></div><div class="line"> + args[3] + <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> options.E = std::stod(args[0]);</div><div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::invalid_argument& e) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"invalid value for E, '"</span> + args[0] + <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> options.alpha = std::stod(args[1]);</div><div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::invalid_argument& e) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"invalid value for alpha, '"</span> + args[1] + <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> options.dim = std::stoi(args[2]);</div><div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::invalid_argument& e) {</div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"invalid number of dimensions '"</span> + args[2] + <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line">Action_options <a name="a8"></a><a class="code" href="namespaceBubbleProfiler.html#af860c8adc0439ab7bc0e316b6e99c9ff">parse_cmd_line_args</a>(<span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>* argv[])</div><div class="line">{</div><div class="line"> Action_options options;</div><div class="line"></div><div class="line"> std::vector<std::string> positional_args;</div><div class="line"> <span class="keywordtype">int</span> i = 1;</div><div class="line"> <span class="keywordflow">while</span> (i < argc) {</div><div class="line"> <span class="keyword">const</span> std::string opt(argv[i++]);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (!<a class="code" href="namespaceBubbleProfiler.html#a2e73ba2498dd7c9c1f2a0bff88ea2e50">starts_with</a>(opt, <span class="stringliteral">"-"</span>)) {</div><div class="line"> positional_args.push_back(opt);</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"-h"</span> || opt == <span class="stringliteral">"--help"</span>) {</div><div class="line"> <a class="code" href="namespaceBubbleProfiler.html#acab5942407649d2603764aab33a22df1">print_usage</a>();</div><div class="line"> exit(EXIT_SUCCESS);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"-v"</span> || opt == <span class="stringliteral">"--verbose"</span>) {</div><div class="line"> options.verbose = <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">throw</span> Setup_error(</div><div class="line"> <span class="stringliteral">"unrecognized command line argument '"</span> + opt + <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <a class="code" href="namespaceBubbleProfiler.html#a58adee7dfbf3d9200ee173ee6bc0da73">parse_positional_args</a>(positional_args, options);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> options;</div><div class="line">}</div><div class="line"></div><div class="line">} <span class="comment">// namespace BubbleProfiler</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> <a name="a9"></a><a class="code" href="examples_2quartic_2action_8cpp.html#ac0f2228420376f4db7e1274f2b41667c">main</a>(<span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>* argv[])</div><div class="line">{</div><div class="line"> <span class="keyword">using namespace </span><a class="code" href="namespaceBubbleProfiler.html">BubbleProfiler</a>;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (argc == 1) {</div><div class="line"> std::cerr << <span class="stringliteral">"Usage: quartic [OPTION] <E> <alpha> <dim>\n"</span></div><div class="line"> << <span class="stringliteral">"Try 'quartic --help' for more information."</span></div><div class="line"> << std::endl;</div><div class="line"> <span class="keywordflow">return</span> EXIT_FAILURE;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordtype">int</span> exit_code = 0;</div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> <a name="_a10"></a><a class="code" href="structBubbleProfiler_1_1Action__options.html">Action_options</a> options = <a class="code" href="namespaceBubbleProfiler.html#af860c8adc0439ab7bc0e316b6e99c9ff">parse_cmd_line_args</a>(argc, argv);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (options.verbose) {</div><div class="line"> <a name="a11"></a><a class="code" href="classBubbleProfiler_1_1logging_1_1Logging__manager.html#a4ad98c9694717326fce88694e9e3e938">logging::Logging_manager::get_manager</a>().<a name="a12"></a><a class="code" href="classBubbleProfiler_1_1logging_1_1Logging__manager.html#ac1995ad9677e0a54bf07ae9d668f3f7f">set_minimum_log_level</a>(</div><div class="line"> <a name="a13"></a><a class="code" href="namespaceBubbleProfiler_1_1logging.html#ab9e7a962f5b8891f8306783be2218661add4ec0ac4e58f7c32a01244ae91150b1">logging::Log_level::Trace</a>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <a name="_a14"></a><a class="code" href="classBubbleProfiler_1_1Restricted__quartic__potential.html">Restricted_quartic_potential</a> potential(options.alpha, options.E);</div><div class="line"> <span class="keyword">const</span> <span class="keywordtype">double</span> false_min = potential.<a name="a15"></a><a class="code" href="classBubbleProfiler_1_1Restricted__quartic__potential.html#a55cc202cde7e78501e1e3d9ed7e51f15">get_local_minimum_location</a>();</div><div class="line"> <span class="keyword">const</span> <span class="keywordtype">double</span> barrier = potential.<a name="a16"></a><a class="code" href="classBubbleProfiler_1_1Restricted__quartic__potential.html#a1c87c6611fa0135f137e2baf82aa3191">get_local_maximum_location</a>();</div><div class="line"> <span class="keyword">const</span> <span class="keywordtype">double</span> true_min = potential.<a name="a17"></a><a class="code" href="classBubbleProfiler_1_1Restricted__quartic__potential.html#a9d09626ac721294bdb727c2f3e6a21c7">get_global_minimum_location</a>();</div><div class="line"></div><div class="line"> <a name="_a18"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html">Shooting</a> profiler;</div><div class="line"> profiler.<a name="a19"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a8e396b6d55d42d65afbf0849ba1e2f32">set_bisection_precision_bits</a>(5);</div><div class="line"> profiler.<a name="a20"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a15936562006cfb15ce162b985ff6d519">set_action_arrived_rel</a>(1.e-3);</div><div class="line"> profiler.<a name="a21"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a35ea27b47459b03dbd2afd47611fa1e9">set_shooting_abs_tol</a>(1.e-4);</div><div class="line"> profiler.<a name="a22"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a4af6700d859441c2087fdda8b2700c63">set_shooting_rel_tol</a>(1.e-4);</div><div class="line"> profiler.<a name="a23"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a30f04f398a6824c53ad7f7f0b3e34422">set_action_abs_tol</a>(1.e-6);</div><div class="line"> profiler.<a name="a24"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#add9634cc38eea75a97d2cf51d6fe75c9">set_action_rel_tol</a>(1.e-6);</div><div class="line"> profiler.<a name="a25"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a7a05b626fc9f26d7fa7d34338286262e">set_drho_frac</a>(1.e-3);</div><div class="line"> profiler.<a name="a26"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#abe407a60f2ff0b4bd8c69c986ca70cb5">set_bisect_lambda_max</a>(5);</div><div class="line"> profiler.<a name="a27"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a140a6864d3a176438019aab7b0a4b020">set_max_iterations</a>(100000);</div><div class="line"> profiler.<a name="a28"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a914d800cd0a29a233ce0ea160c7ad69e">set_max_periods</a>(1.e2);</div><div class="line"> profiler.<a name="a29"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a80ccc709faee71a87dc686bc6e4d6f5c">set_f_y_max</a>(1.e6);</div><div class="line"> profiler.<a name="a30"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#ad34fdbff21f2d4d893f70b6486f147a4">set_f_y_min</a>(1.e-3);</div><div class="line"> profiler.<a name="a31"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a59a10600ad4db2c63de03418a58ea29a">set_y_max</a>(1.e1);</div><div class="line"></div><div class="line"> profiler.<a name="a32"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a96b0bd77c13e35a4ebb1aa18cf99bb34">solve</a>(potential, false_min, true_min, barrier,</div><div class="line"> options.dim, Shooting::Solver_options::Compute_action);</div><div class="line"></div><div class="line"> std::cout << <span class="stringliteral">"# E = "</span> << options.E</div><div class="line"> << <span class="stringliteral">", alpha = "</span> << options.alpha</div><div class="line"> << <span class="stringliteral">", dim = "</span> << options.dim</div><div class="line"> << <span class="stringliteral">", action = "</span> << profiler.<a name="a33"></a><a class="code" href="classBubbleProfiler_1_1Shooting.html#a43bf8d89a2296ebf139ea2f81cc60c44">get_euclidean_action</a>()</div><div class="line"> << std::endl;</div><div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a34"></a><a class="code" href="classBubbleProfiler_1_1Error.html">Error</a>& e) {</div><div class="line"> std::cerr << <span class="stringliteral">"Error: "</span> << e.what() << std::endl;</div><div class="line"> exit_code = EXIT_FAILURE;</div><div class="line"> } <span class="keywordflow">catch</span> (...) {</div><div class="line"> std::cerr << <span class="stringliteral">"Error: unrecognized error occurred."</span></div><div class="line"> << std::endl;</div><div class="line"> exit_code = EXIT_FAILURE;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> exit_code;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Jan 2 2019 13:08:19 for BubbleProfiler by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>