<!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.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>rk2_integrator.f90 Source File</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/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" />
</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="projectlogo"><img alt="Logo" src="MAOOAM_small.png"/></td>
    <td style="padding-left: 0.5em;">
    <div id="projectbrief">A Modular Arbitrary-Order Ocean-Atmosphere Model</div>
    </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></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">rk2_integrator.f90</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">! rk2_integrator.f90</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">!</span><span class="comment"></span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">!&gt;  Module containing the second-order Runge-Kutta (RK2) integration routines.</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">!</span><span class="comment"></span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">!&gt; @copyright                                                               </span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment">!&gt; 2015-2020 Lesley De Cruz &amp; Jonathan Demaeyer.</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">!&gt; See LICENSE.txt for license information.                                  </span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">!</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment">!---------------------------------------------------------------------------!</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment">!</span><span class="comment"></span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment">!&gt;  @remark</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment">!&gt;  This module actually contains the Heun algorithm routines.</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment">!                                                                           </span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment">!---------------------------------------------------------------------------</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="namespacerk2__integrator.html">   17</a></span>&#160;<span class="keyword">MODULE</span> <a class="code" href="namespacerk2__integrator.html">rk2_integrator</a></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;  <span class="keywordtype">USE </span><a class="code" href="namespacemodel__def.html">model_def</a></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;  <span class="keywordtype">USE </span><a class="code" href="namespaceintegrator__def.html">integrator_def</a></div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  <span class="keywordtype">IMPLICIT NONE</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;  <span class="keywordtype">PRIVATE</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment">  !&gt; Class for the Heun (RK2) integrator object.</span></div><div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="structrk2__integrator_1_1rk2integrator.html">   25</a></span>&#160;  <span class="keyword">TYPE</span>, <span class="keyword">EXTENDS</span>(<a class="code" href="structintegrator__def_1_1integrator.html">integrator</a>), <span class="keywordtype">PUBLIC</span> :: <a class="code" href="structrk2__integrator_1_1rk2integrator.html">rk2integrator</a></div><div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="structrk2__integrator_1_1rk2integrator.html#abbcdfd65bf66491ba32a5df23a7241f7">   26</a></span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">DIMENSION(:)</span>, <span class="keywordtype">ALLOCATABLE</span> :: buf_y1<span class="comment"> !&lt; Buffer to hold the intermediate position (Heun algorithm)</span></div><div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="structrk2__integrator_1_1rk2integrator.html#a4b17658557f59d011a0fa185966d1c13">   27</a></span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">DIMENSION(:)</span>, <span class="keywordtype">ALLOCATABLE</span> :: buf_f0<span class="comment"> !&lt; Buffer to hold tendencies at the initial position</span></div><div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="structrk2__integrator_1_1rk2integrator.html#a2daeb0252fa03949b85cff88f3d1c8ce">   28</a></span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">DIMENSION(:)</span>, <span class="keywordtype">ALLOCATABLE</span> :: buf_f1<span class="comment"> !&lt; Buffer to hold tendencies at the intermediate position</span></div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;  <span class="keyword">CONTAINS</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordtype">PROCEDURE</span> :: init</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="keywordtype">PROCEDURE</span> :: step</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    <span class="keywordtype">PROCEDURE</span> :: clean</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="keyword">  END TYPE </span><a class="code" href="structrk2__integrator_1_1rk2integrator.html">rk2integrator</a></div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="keyword">CONTAINS</span></div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;  <span class="comment"></span></div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="comment">  !&gt; Routine to initialise the integration buffers.</span></div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="comment">  !&gt; @param[in,out] integr Integrator object to initialize.</span></div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="comment">  !&gt; @param[in] imodel Model object to initialize the integrator with.</span></div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="keyword">  SUBROUTINE </span>init(integr, imodel)</div><div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="namespacerk2__integrator.html#a1b91e270c5963d316f19ae12ffe35f79">   41</a></span>&#160;    <span class="keywordtype">CLASS</span>(<a class="code" href="structrk2__integrator_1_1rk2integrator.html">rk2integrator</a>), <span class="keywordtype">INTENT(INOUT)</span> :: integr</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="keywordtype">CLASS</span>(<a class="code" href="structmodel__def_1_1model.html">model</a>), <span class="keywordtype">INTENT(IN)</span>, <span class="keywordtype">TARGET</span> :: imodel</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <span class="keywordtype">INTEGER</span> :: AllocStat</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="keywordflow">IF</span> (.NOT.imodel%initialized) <span class="keywordflow">THEN</span></div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;      print*, <span class="stringliteral">&#39;Model not yet initialized, impossible to associate an integrator to an empty model!&#39;</span></div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      <span class="keywordflow">RETURN</span></div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keywordflow">    END IF</span></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    integr%pmodel =&gt; imodel</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    integr%dt =&gt; imodel%model_configuration%integration%dt</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    integr%ndim =&gt; imodel%model_configuration%modes%ndim</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    <span class="keyword">ALLOCATE</span>(integr%buf_y1(0:integr%ndim) ,<a class="code" href="namespacestat.html">stat</a>=allocstat)</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keywordflow">IF</span> (allocstat /= 0) <span class="keywordflow">THEN</span></div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;      print*, <span class="stringliteral">&quot;*** rk2integrator%init: Problem with allocation! ***&quot;</span></div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      stop <span class="stringliteral">&quot;Exiting ...&quot;</span></div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<span class="keywordflow">    END IF</span></div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keyword">ALLOCATE</span>(integr%buf_f0(0:integr%ndim) ,<a class="code" href="namespacestat.html">stat</a>=allocstat)</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="keywordflow">IF</span> (allocstat /= 0) <span class="keywordflow">THEN</span></div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      print*, <span class="stringliteral">&quot;*** rk2integrator%init: Problem with allocation! ***&quot;</span></div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;      stop <span class="stringliteral">&quot;Exiting ...&quot;</span></div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="keywordflow">    END IF</span></div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keyword">ALLOCATE</span>(integr%buf_f1(0:integr%ndim) ,<a class="code" href="namespacestat.html">stat</a>=allocstat)</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keywordflow">IF</span> (allocstat /= 0) <span class="keywordflow">THEN</span></div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;      print*, <span class="stringliteral">&quot;*** rk2integrator%init: Problem with allocation! ***&quot;</span></div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;      stop <span class="stringliteral">&quot;Exiting ...&quot;</span></div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;<span class="keywordflow">    END IF</span></div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;<span class="keyword">  END SUBROUTINE </span>init</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="comment">  !&gt; Routine to perform an integration step (Heun algorithm). The incremented time is returned.</span></div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<span class="comment">  !&gt; @param[in,out] integr Integrator object to perform the step with.</span></div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="comment">  !&gt; @param[in] y Initial point.</span></div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;<span class="comment">  !&gt; @param[in] t Actual integration time</span></div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;<span class="comment">  !&gt; @param[out] res Final point after the step.</span></div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;<span class="keyword">  SUBROUTINE </span>step(integr, y,t,res)</div><div class="line"><a name="l00077"></a><span class="lineno"><a class="line" href="namespacerk2__integrator.html#af90ce8bcd52238459d1367d39f898b12">   77</a></span>&#160;    <span class="keywordtype">CLASS</span>(<a class="code" href="structrk2__integrator_1_1rk2integrator.html">rk2integrator</a>), <span class="keywordtype">INTENT(INOUT)</span> :: integr</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">DIMENSION(0:integr%ndim)</span>, <span class="keywordtype">INTENT(IN)</span> :: y</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">INTENT(INOUT)</span> :: t</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;    <span class="keywordtype">REAL(KIND=8)</span>, <span class="keywordtype">DIMENSION(0:integr%ndim)</span>, <span class="keywordtype">INTENT(OUT)</span> :: res</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    </div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    <span class="keyword">CALL </span>integr%pmodel%tendencies(t,y,integr%buf_f0)</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    integr%buf_y1 = y+integr%dt*integr%buf_f0</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keyword">CALL </span>integr%pmodel%tendencies(t+integr%dt,integr%buf_y1,integr%buf_f1)</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    res=y+0.5*(integr%buf_f0+integr%buf_f1)*integr%dt</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    t=t+integr%dt</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="keyword">  END SUBROUTINE </span>step</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;<span class="comment">  !&gt; Routine to clean the integrator</span></div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment">  !&gt; @param[in,out] integr Integrator object to clean.</span></div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="keyword">  SUBROUTINE </span>clean(integr)</div><div class="line"><a name="l00092"></a><span class="lineno"><a class="line" href="namespacerk2__integrator.html#a4425dabc7bb2f6f999479c3ab64ab06e">   92</a></span>&#160;      <span class="keywordtype">CLASS</span>(<a class="code" href="structrk2__integrator_1_1rk2integrator.html">rk2integrator</a>), <span class="keywordtype">INTENT(INOUT)</span> :: integr</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;      <span class="keywordflow">IF</span> (<span class="keyword">allocated</span>(integr%buf_y1)) <span class="keyword">DEALLOCATE</span>(integr%buf_y1)</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;      <span class="keywordflow">IF</span> (<span class="keyword">allocated</span>(integr%buf_f1)) <span class="keyword">DEALLOCATE</span>(integr%buf_f1)</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;      <span class="keywordflow">IF</span> (<span class="keyword">allocated</span>(integr%buf_f0)) <span class="keyword">DEALLOCATE</span>(integr%buf_f0)</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;<span class="keyword">  END SUBROUTINE </span>clean</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;<span class="keyword">END MODULE </span><a class="code" href="namespacerk2__integrator.html">rk2_integrator</a></div><div class="ttc" id="namespacestat_html"><div class="ttname"><a href="namespacestat.html">stat</a></div><div class="ttdoc">Statistics accumulators. </div><div class="ttdef"><b>Definition:</b> <a href="stat_8f90_source.html#l00014">stat.f90:14</a></div></div>
<div class="ttc" id="structrk2__integrator_1_1rk2integrator_html"><div class="ttname"><a href="structrk2__integrator_1_1rk2integrator.html">rk2_integrator::rk2integrator</a></div><div class="ttdoc">Class for the Heun (RK2) integrator object. </div><div class="ttdef"><b>Definition:</b> <a href="rk2__integrator_8f90_source.html#l00025">rk2_integrator.f90:25</a></div></div>
<div class="ttc" id="namespaceintegrator__def_html"><div class="ttname"><a href="namespaceintegrator__def.html">integrator_def</a></div><div class="ttdoc">Base class definition for the model&amp;#39;s integrators. </div><div class="ttdef"><b>Definition:</b> <a href="integrator__def_8f90_source.html#l00015">integrator_def.f90:15</a></div></div>
<div class="ttc" id="structmodel__def_1_1model_html"><div class="ttname"><a href="structmodel__def_1_1model.html">model_def::model</a></div><div class="ttdoc">Class to hold the components of a model version. </div><div class="ttdef"><b>Definition:</b> <a href="model__def_8f90_source.html#l00025">model_def.f90:25</a></div></div>
<div class="ttc" id="namespacerk2__integrator_html"><div class="ttname"><a href="namespacerk2__integrator.html">rk2_integrator</a></div><div class="ttdoc">Module containing the second-order Runge-Kutta (RK2) integration routines. </div><div class="ttdef"><b>Definition:</b> <a href="rk2__integrator_8f90_source.html#l00017">rk2_integrator.f90:17</a></div></div>
<div class="ttc" id="structintegrator__def_1_1integrator_html"><div class="ttname"><a href="structintegrator__def_1_1integrator.html">integrator_def::integrator</a></div><div class="ttdoc">Base class to be subclassed to create a new integrator. </div><div class="ttdef"><b>Definition:</b> <a href="integrator__def_8f90_source.html#l00023">integrator_def.f90:23</a></div></div>
<div class="ttc" id="namespacemodel__def_html"><div class="ttname"><a href="namespacemodel__def.html">model_def</a></div><div class="ttdoc">Module to articulate the model classes and define a model version. </div><div class="ttdef"><b>Definition:</b> <a href="model__def_8f90_source.html#l00013">model_def.f90:13</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Jun 26 2020 17:41:24 by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
