1
0
mirror of https://github.com/TREX-CoE/qmc-lttc.git synced 2025-01-03 01:56:20 +01:00
This commit is contained in:
scemama 2021-01-25 23:23:42 +00:00
parent 29c5ebf07c
commit 46ca82707e

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head> <head>
<!-- 2021-01-25 Mon 22:54 --> <!-- 2021-01-25 Mon 23:23 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Quantum Monte Carlo</title> <title>Quantum Monte Carlo</title>
@ -257,128 +257,135 @@ for the JavaScript code in this tag.
<h2>Table of Contents</h2> <h2>Table of Contents</h2>
<div id="text-table-of-contents"> <div id="text-table-of-contents">
<ul> <ul>
<li><a href="#orgf7a78e4">1. Introduction</a></li> <li><a href="#orga35005a">1. Introduction</a></li>
<li><a href="#org5696f8b">2. Numerical evaluation of the energy</a> <li><a href="#org99b226a">2. Numerical evaluation of the energy</a>
<ul> <ul>
<li><a href="#org05580cd">2.1. Local energy</a> <li><a href="#orgb54c6e8">2.1. Local energy</a>
<ul> <ul>
<li><a href="#org23947c1">2.1.1. Exercise 1</a></li> <li><a href="#orgd1fb793">2.1.1. Exercise 1</a></li>
<li><a href="#orgd624a8b">2.1.2. Exercise 2</a> <li><a href="#org3860cee">2.1.2. Exercise 2</a>
<ul> <ul>
<li><a href="#org1661138">2.1.2.1. Python</a></li> <li><a href="#orgc1f4406">2.1.2.1. Python</a></li>
<li><a href="#org50c3aad">2.1.2.2. Python</a></li> <li><a href="#orgec28d8a">2.1.2.2. Python</a></li>
<li><a href="#org3f11dde">2.1.2.3. Fortran</a></li> <li><a href="#org7eaea85">2.1.2.3. Fortran</a></li>
<li><a href="#org92d265e">2.1.2.4. Fortran</a></li> <li><a href="#orgc042d6f">2.1.2.4. Fortran</a></li>
</ul> </ul>
</li> </li>
<li><a href="#orgc68ea75">2.1.3. Exercise 3</a> <li><a href="#orga7e8e23">2.1.3. Exercise 3</a>
<ul> <ul>
<li><a href="#orgaa63204">2.1.3.1. Python</a></li> <li><a href="#orgc8636eb">2.1.3.1. Python</a></li>
<li><a href="#orge262e44">2.1.3.2. Python</a></li> <li><a href="#org4aa281b">2.1.3.2. Python</a></li>
<li><a href="#org0ab4bfb">2.1.3.3. Fortran</a></li> <li><a href="#org35818d2">2.1.3.3. Fortran</a></li>
<li><a href="#org9a6c1fb">2.1.3.4. Fortran</a></li> <li><a href="#org6f79896">2.1.3.4. Fortran</a></li>
</ul> </ul>
</li> </li>
<li><a href="#org547c9c4">2.1.4. Exercise 4</a> <li><a href="#org7169dad">2.1.4. Exercise 4</a>
<ul> <ul>
<li><a href="#org74c97bf">2.1.4.1. Python</a></li> <li><a href="#org49311f6">2.1.4.1. Python</a></li>
<li><a href="#orgcc44043">2.1.4.2. Python</a></li> <li><a href="#org64701c8">2.1.4.2. Python</a></li>
<li><a href="#orgce2c2e5">2.1.4.3. Fortran</a></li> <li><a href="#orgcf1f8bb">2.1.4.3. Fortran</a></li>
<li><a href="#org941820f">2.1.4.4. Fortran</a></li> <li><a href="#orga709c70">2.1.4.4. Fortran</a></li>
</ul> </ul>
</li> </li>
<li><a href="#orgbdaff18">2.1.5. Exercise 5</a> <li><a href="#orgabff35a">2.1.5. Exercise 5</a>
<ul> <ul>
<li><a href="#org159140e">2.1.5.1. Python</a></li> <li><a href="#org7d1aba4">2.1.5.1. Python</a></li>
<li><a href="#org1e4cde2">2.1.5.2. Python</a></li> <li><a href="#orgb2b4bad">2.1.5.2. Python</a></li>
<li><a href="#org02d18b8">2.1.5.3. Fortran</a></li> <li><a href="#org6e7a546">2.1.5.3. Fortran</a></li>
<li><a href="#org63ad259">2.1.5.4. Fortran</a></li> <li><a href="#org53213b5">2.1.5.4. Fortran</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#orgdd79233">2.2. Plot of the local energy along the \(x\) axis</a> <li><a href="#orgbeab5ec">2.2. Plot of the local energy along the \(x\) axis</a>
<ul> <ul>
<li><a href="#orgd250551">2.2.1. Exercise</a> <li><a href="#org3510925">2.2.1. Exercise</a>
<ul> <ul>
<li><a href="#orgb5fae5f">2.2.1.1. Python</a></li> <li><a href="#orge574bc5">2.2.1.1. Python</a></li>
<li><a href="#orgb2f1970">2.2.1.2. Python</a></li> <li><a href="#org580bac9">2.2.1.2. Python</a></li>
<li><a href="#orga11ec40">2.2.1.3. Fortran</a></li> <li><a href="#org03b17a4">2.2.1.3. Fortran</a></li>
<li><a href="#org6eafd17">2.2.1.4. Fortran</a></li> <li><a href="#org9a6dc16">2.2.1.4. Fortran</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#org554689a">2.3. Numerical estimation of the energy</a> <li><a href="#orgbf0209f">2.3. Numerical estimation of the energy</a>
<ul> <ul>
<li><a href="#org6369add">2.3.1. Exercise</a> <li><a href="#org3958454">2.3.1. Exercise</a>
<ul> <ul>
<li><a href="#orgf3840f2">2.3.1.1. Python</a></li> <li><a href="#org30bade1">2.3.1.1. Python</a></li>
<li><a href="#orgf5e3ecd">2.3.1.2. Python</a></li> <li><a href="#org77b7b0a">2.3.1.2. Python</a></li>
<li><a href="#org826f9f4">2.3.1.3. Fortran</a></li> <li><a href="#orga93a5dd">2.3.1.3. Fortran</a></li>
<li><a href="#org97c81ba">2.3.1.4. Fortran</a></li> <li><a href="#org6dd2871">2.3.1.4. Fortran</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#org4eb04ef">2.4. Variance of the local energy</a> <li><a href="#orgeedbee0">2.4. Variance of the local energy</a>
<ul> <ul>
<li><a href="#org9443a40">2.4.1. Exercise (optional)</a></li> <li><a href="#org4acda64">2.4.1. Exercise (optional)</a></li>
<li><a href="#org5106671">2.4.2. Exercise</a> <li><a href="#org6854abf">2.4.2. Exercise</a>
<ul> <ul>
<li><a href="#org5767c40">2.4.2.1. Python</a></li> <li><a href="#org0d826af">2.4.2.1. Python</a></li>
<li><a href="#org32c72a0">2.4.2.2. Python</a></li> <li><a href="#org576fa85">2.4.2.2. Python</a></li>
<li><a href="#org1b3f7f4">2.4.2.3. Fortran</a></li> <li><a href="#org307c660">2.4.2.3. Fortran</a></li>
<li><a href="#org7f15713">2.4.2.4. Fortran</a></li> <li><a href="#org119dad1">2.4.2.4. Fortran</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#org6414cd7">3. <span class="todo TODO">TODO</span> Variational Monte Carlo</a> <li><a href="#org0c2fa9b">3. Variational Monte Carlo</a>
<ul> <ul>
<li><a href="#org76f4f47">3.1. <span class="todo TODO">TODO</span> Computation of the statistical error</a> <li><a href="#org4e85021">3.1. Computation of the statistical error</a>
<ul> <ul>
<li><a href="#orgc801982">3.1.1. Exercise</a></li> <li><a href="#orga3687ff">3.1.1. Exercise</a>
</ul>
</li>
<li><a href="#org8b118ec">3.2. <span class="todo TODO">TODO</span> Uniform sampling in the box</a>
<ul> <ul>
<li><a href="#org925cb8e">3.2.1. Exercise</a></li> <li><a href="#org568b394">3.1.1.1. Python</a></li>
</ul> <li><a href="#org3d69b65">3.1.1.2. Python</a></li>
</li> <li><a href="#org314b0e7">3.1.1.3. Fortran</a></li>
<li><a href="#org8c24125">3.3. <span class="todo TODO">TODO</span> Metropolis sampling with \(\Psi^2\)</a> <li><a href="#org0f8bdcf">3.1.1.4. Fortran</a></li>
<ul>
<li><a href="#org99bc8b5">3.3.1. Exercise</a></li>
</ul>
</li>
<li><a href="#org85cb077">3.4. <span class="todo TODO">TODO</span> Gaussian random number generator</a></li>
<li><a href="#org3f7062f">3.5. <span class="todo TODO">TODO</span> Generalized Metropolis algorithm</a>
<ul>
<li><a href="#orgc5b23ac">3.5.1. Exercise 1</a></li>
<li><a href="#org876a231">3.5.2. Exercise 2</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#org86be009">4. <span class="todo TODO">TODO</span> Diffusion Monte Carlo</a> <li><a href="#orgb0930a1">3.2. <span class="todo TODO">TODO</span> Uniform sampling in the box</a>
<ul> <ul>
<li><a href="#orgbbfe631">4.1. <span class="todo TODO">TODO</span> Hydrogen atom</a> <li><a href="#org1ecf130">3.2.1. Exercise</a></li>
<ul>
<li><a href="#org574137c">4.1.1. Exercise</a></li>
</ul> </ul>
</li> </li>
<li><a href="#orgdb34f3d">4.2. <span class="todo TODO">TODO</span> Dihydrogen</a></li> <li><a href="#org5d0adc4">3.3. <span class="todo TODO">TODO</span> Metropolis sampling with \(\Psi^2\)</a>
<ul>
<li><a href="#orgb3a648e">3.3.1. Exercise</a></li>
</ul> </ul>
</li> </li>
<li><a href="#orgc3ba7b8">5. <span class="todo TODO">TODO</span> <code>[0/1]</code> Last things to do</a></li> <li><a href="#orgb5348ef">3.4. <span class="todo TODO">TODO</span> Gaussian random number generator</a></li>
<li><a href="#org932bae5">3.5. <span class="todo TODO">TODO</span> Generalized Metropolis algorithm</a>
<ul>
<li><a href="#org460f3fe">3.5.1. Exercise 1</a></li>
<li><a href="#orgd39a7d7">3.5.2. Exercise 2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orgaf5996c">4. <span class="todo TODO">TODO</span> Diffusion Monte Carlo</a>
<ul>
<li><a href="#org12ab3c5">4.1. <span class="todo TODO">TODO</span> Hydrogen atom</a>
<ul>
<li><a href="#org3b3e8ae">4.1.1. Exercise</a></li>
</ul>
</li>
<li><a href="#orgf0f2402">4.2. <span class="todo TODO">TODO</span> Dihydrogen</a></li>
</ul>
</li>
<li><a href="#org1c017d7">5. <span class="todo TODO">TODO</span> <code>[0/1]</code> Last things to do</a></li>
</ul> </ul>
</div> </div>
</div> </div>
<div id="outline-container-orgf7a78e4" class="outline-2"> <div id="outline-container-orga35005a" class="outline-2">
<h2 id="orgf7a78e4"><span class="section-number-2">1</span> Introduction</h2> <h2 id="orga35005a"><span class="section-number-2">1</span> Introduction</h2>
<div class="outline-text-2" id="text-1"> <div class="outline-text-2" id="text-1">
<p> <p>
We propose different exercises to understand quantum Monte Carlo (QMC) We propose different exercises to understand quantum Monte Carlo (QMC)
@ -413,8 +420,8 @@ coordinates, etc).
</div> </div>
<div id="outline-container-org5696f8b" class="outline-2"> <div id="outline-container-org99b226a" class="outline-2">
<h2 id="org5696f8b"><span class="section-number-2">2</span> Numerical evaluation of the energy</h2> <h2 id="org99b226a"><span class="section-number-2">2</span> Numerical evaluation of the energy</h2>
<div class="outline-text-2" id="text-2"> <div class="outline-text-2" id="text-2">
<p> <p>
In this section we consider the Hydrogen atom with the following In this section we consider the Hydrogen atom with the following
@ -487,18 +494,36 @@ E & = & \frac{\langle \Psi| \hat{H} | \Psi\rangle}{\langle \Psi |\Psi \rangle}
\end{eqnarray*} \end{eqnarray*}
</div> </div>
<div id="outline-container-org05580cd" class="outline-3"> <div id="outline-container-orgb54c6e8" class="outline-3">
<h3 id="org05580cd"><span class="section-number-3">2.1</span> Local energy</h3> <h3 id="orgb54c6e8"><span class="section-number-3">2.1</span> Local energy</h3>
<div class="outline-text-3" id="text-2-1"> <div class="outline-text-3" id="text-2-1">
<p> <p>
Write all the functions of this section in a single file : Write all the functions of this section in a single file :
<code>hydrogen.py</code> if you use Python, or <code>hydrogen.f90</code> is you use <code>hydrogen.py</code> if you use Python, or <code>hydrogen.f90</code> is you use
Fortran. Fortran.
</p> </p>
<div class="note">
<ul class="org-ul">
<li>When computing a square root in \(\mathbb{R}\), <b>always</b> make sure
that the argument of the square root is non-negative.</li>
<li>When you divide, <b>always</b> make sure that you will not divide by zero</li>
</ul>
<p>
If a <i>floating-point exception</i> can occur, you should make a test
to catch the error.
</p>
</div> </div>
<div id="outline-container-org23947c1" class="outline-4"> <p>
<h4 id="org23947c1"><span class="section-number-4">2.1.1</span> Exercise 1</h4> #+end<sub>note</sub>
</p>
</div>
<div id="outline-container-orgd1fb793" class="outline-4">
<h4 id="orgd1fb793"><span class="section-number-4">2.1.1</span> Exercise 1</h4>
<div class="outline-text-4" id="text-2-1-1"> <div class="outline-text-4" id="text-2-1-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -509,8 +534,8 @@ Find the theoretical value of \(a\) for which \(\Psi\) is an eigenfunction of \(
</div> </div>
</div> </div>
<div id="outline-container-orgd624a8b" class="outline-4"> <div id="outline-container-org3860cee" class="outline-4">
<h4 id="orgd624a8b"><span class="section-number-4">2.1.2</span> Exercise 2</h4> <h4 id="org3860cee"><span class="section-number-4">2.1.2</span> Exercise 2</h4>
<div class="outline-text-4" id="text-2-1-2"> <div class="outline-text-4" id="text-2-1-2">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -529,8 +554,8 @@ and returns the potential.
</p> </p>
</div> </div>
<div id="outline-container-org1661138" class="outline-5"> <div id="outline-container-orgc1f4406" class="outline-5">
<h5 id="org1661138"><span class="section-number-5">2.1.2.1</span> Python</h5> <h5 id="orgc1f4406"><span class="section-number-5">2.1.2.1</span> Python</h5>
<div class="outline-text-5" id="text-2-1-2-1"> <div class="outline-text-5" id="text-2-1-2-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -542,21 +567,23 @@ and returns the potential.
</div> </div>
</div> </div>
<div id="outline-container-org50c3aad" class="outline-5"> <div id="outline-container-orgec28d8a" class="outline-5">
<h5 id="org50c3aad"><span class="section-number-5">2.1.2.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="orgec28d8a"><span class="section-number-5">2.1.2.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-2-2"> <div class="outline-text-5" id="text-2-1-2-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">potential</span>(r): <span style="color: #a020f0;">def</span> <span style="color: #0000ff;">potential</span>(r):
<span style="color: #a020f0;">return</span> -1. / np.sqrt(np.dot(r,r)) <span style="color: #a0522d;">distance</span> = np.sqrt(np.dot(r,r))
<span style="color: #a020f0;">assert</span> (distance &gt; 0)
<span style="color: #a020f0;">return</span> -1. / distance
</pre> </pre>
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org3f11dde" class="outline-5"> <div id="outline-container-org7eaea85" class="outline-5">
<h5 id="org3f11dde"><span class="section-number-5">2.1.2.3</span> Fortran</h5> <h5 id="org7eaea85"><span class="section-number-5">2.1.2.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-1-2-3"> <div class="outline-text-5" id="text-2-1-2-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">potential</span><span style="color: #000000; background-color: #ffffff;">(r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">potential</span><span style="color: #000000; background-color: #ffffff;">(r)</span>
@ -569,14 +596,20 @@ and returns the potential.
</div> </div>
</div> </div>
<div id="outline-container-org92d265e" class="outline-5"> <div id="outline-container-orgc042d6f" class="outline-5">
<h5 id="org92d265e"><span class="section-number-5">2.1.2.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="orgc042d6f"><span class="section-number-5">2.1.2.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-2-4"> <div class="outline-text-5" id="text-2-1-2-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">potential</span><span style="color: #000000; background-color: #ffffff;">(r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">potential</span><span style="color: #000000; background-color: #ffffff;">(r)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span> <span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> r(3)</span> <span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> r(3)</span>
potential = -1.d0 / dsqrt( r(1)*r(1) + r(2)*r(2) + r(3)*r(3) ) <span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> distance</span>
distance = dsqrt( r(1)*r(1) + r(2)*r(2) + r(3)*r(3) )
<span style="color: #a020f0;">if</span> (distance &gt; 0.d0) <span style="color: #a020f0;">then</span>
potential = -1.d0 / dsqrt( r(1)*r(1) + r(2)*r(2) + r(3)*r(3) )
<span style="color: #a020f0;">else</span>
<span style="color: #a020f0;">stop</span> <span style="color: #8b2252;">'potential at r=0.d0 diverges'</span>
<span style="color: #a020f0;">end if</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">potential</span> <span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">potential</span>
</pre> </pre>
</div> </div>
@ -584,8 +617,8 @@ and returns the potential.
</div> </div>
</div> </div>
<div id="outline-container-orgc68ea75" class="outline-4"> <div id="outline-container-orga7e8e23" class="outline-4">
<h4 id="orgc68ea75"><span class="section-number-4">2.1.3</span> Exercise 3</h4> <h4 id="orga7e8e23"><span class="section-number-4">2.1.3</span> Exercise 3</h4>
<div class="outline-text-4" id="text-2-1-3"> <div class="outline-text-4" id="text-2-1-3">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -597,9 +630,8 @@ input arguments, and returns a scalar.
</div> </div>
</div> </div>
<div id="outline-container-orgc8636eb" class="outline-5">
<div id="outline-container-orgaa63204" class="outline-5"> <h5 id="orgc8636eb"><span class="section-number-5">2.1.3.1</span> Python</h5>
<h5 id="orgaa63204"><span class="section-number-5">2.1.3.1</span> Python</h5>
<div class="outline-text-5" id="text-2-1-3-1"> <div class="outline-text-5" id="text-2-1-3-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">psi</span>(a, r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">psi</span>(a, r):
@ -609,8 +641,8 @@ input arguments, and returns a scalar.
</div> </div>
</div> </div>
<div id="outline-container-orge262e44" class="outline-5"> <div id="outline-container-org4aa281b" class="outline-5">
<h5 id="orge262e44"><span class="section-number-5">2.1.3.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org4aa281b"><span class="section-number-5">2.1.3.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-3-2"> <div class="outline-text-5" id="text-2-1-3-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">psi</span>(a, r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">psi</span>(a, r):
@ -620,8 +652,8 @@ input arguments, and returns a scalar.
</div> </div>
</div> </div>
<div id="outline-container-org0ab4bfb" class="outline-5"> <div id="outline-container-org35818d2" class="outline-5">
<h5 id="org0ab4bfb"><span class="section-number-5">2.1.3.3</span> Fortran</h5> <h5 id="org35818d2"><span class="section-number-5">2.1.3.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-1-3-3"> <div class="outline-text-5" id="text-2-1-3-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">psi</span><span style="color: #000000; background-color: #ffffff;">(a, r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">psi</span><span style="color: #000000; background-color: #ffffff;">(a, r)</span>
@ -634,8 +666,8 @@ input arguments, and returns a scalar.
</div> </div>
</div> </div>
<div id="outline-container-org9a6c1fb" class="outline-5"> <div id="outline-container-org6f79896" class="outline-5">
<h5 id="org9a6c1fb"><span class="section-number-5">2.1.3.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org6f79896"><span class="section-number-5">2.1.3.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-3-4"> <div class="outline-text-5" id="text-2-1-3-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">psi</span><span style="color: #000000; background-color: #ffffff;">(a, r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">psi</span><span style="color: #000000; background-color: #ffffff;">(a, r)</span>
@ -649,8 +681,8 @@ input arguments, and returns a scalar.
</div> </div>
</div> </div>
<div id="outline-container-org547c9c4" class="outline-4"> <div id="outline-container-org7169dad" class="outline-4">
<h4 id="org547c9c4"><span class="section-number-4">2.1.4</span> Exercise 4</h4> <h4 id="org7169dad"><span class="section-number-4">2.1.4</span> Exercise 4</h4>
<div class="outline-text-4" id="text-2-1-4"> <div class="outline-text-4" id="text-2-1-4">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -708,8 +740,8 @@ So the local kinetic energy is
</p> </p>
</div> </div>
<div id="outline-container-org74c97bf" class="outline-5"> <div id="outline-container-org49311f6" class="outline-5">
<h5 id="org74c97bf"><span class="section-number-5">2.1.4.1</span> Python</h5> <h5 id="org49311f6"><span class="section-number-5">2.1.4.1</span> Python</h5>
<div class="outline-text-5" id="text-2-1-4-1"> <div class="outline-text-5" id="text-2-1-4-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">kinetic</span>(a,r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">kinetic</span>(a,r):
@ -719,19 +751,21 @@ So the local kinetic energy is
</div> </div>
</div> </div>
<div id="outline-container-orgcc44043" class="outline-5"> <div id="outline-container-org64701c8" class="outline-5">
<h5 id="orgcc44043"><span class="section-number-5">2.1.4.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org64701c8"><span class="section-number-5">2.1.4.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-4-2"> <div class="outline-text-5" id="text-2-1-4-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">kinetic</span>(a,r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">kinetic</span>(a,r):
<span style="color: #a020f0;">return</span> -0.5 * (a**2 - (2.*a)/np.sqrt(np.dot(r,r))) <span style="color: #a0522d;">distance</span> = np.sqrt(np.dot(r,r))
<span style="color: #a020f0;">assert</span> (distance &gt; 0.)
<span style="color: #a020f0;">return</span> -0.5 * (a**2 - (2.*a)/distance)
</pre> </pre>
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-orgce2c2e5" class="outline-5"> <div id="outline-container-orgcf1f8bb" class="outline-5">
<h5 id="orgce2c2e5"><span class="section-number-5">2.1.4.3</span> Fortran</h5> <h5 id="orgcf1f8bb"><span class="section-number-5">2.1.4.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-1-4-3"> <div class="outline-text-5" id="text-2-1-4-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">kinetic</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">kinetic</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span>
@ -744,15 +778,20 @@ So the local kinetic energy is
</div> </div>
</div> </div>
<div id="outline-container-org941820f" class="outline-5"> <div id="outline-container-orga709c70" class="outline-5">
<h5 id="org941820f"><span class="section-number-5">2.1.4.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="orga709c70"><span class="section-number-5">2.1.4.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-4-4"> <div class="outline-text-5" id="text-2-1-4-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">kinetic</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">kinetic</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span> <span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> a, r(3)</span> <span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> a, r(3)</span>
kinetic = -0.5d0 * (a*a - (2.d0*a) / <span style="color: #a020f0;">&amp;</span> <span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> distance</span>
dsqrt( r(1)*r(1) + r(2)*r(2) + r(3)*r(3) ) ) distance = dsqrt( r(1)*r(1) + r(2)*r(2) + r(3)*r(3) )
<span style="color: #a020f0;">if</span> (distance &gt; 0.d0) <span style="color: #a020f0;">then</span>
kinetic = -0.5d0 * (a*a - (2.d0*a) / distance)
<span style="color: #a020f0;">else</span>
<span style="color: #a020f0;">stop</span> <span style="color: #8b2252;">'kinetic energy diverges at r=0'</span>
<span style="color: #a020f0;">end if</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">kinetic</span> <span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">kinetic</span>
</pre> </pre>
</div> </div>
@ -760,8 +799,8 @@ So the local kinetic energy is
</div> </div>
</div> </div>
<div id="outline-container-orgbdaff18" class="outline-4"> <div id="outline-container-orgabff35a" class="outline-4">
<h4 id="orgbdaff18"><span class="section-number-4">2.1.5</span> Exercise 5</h4> <h4 id="orgabff35a"><span class="section-number-4">2.1.5</span> Exercise 5</h4>
<div class="outline-text-4" id="text-2-1-5"> <div class="outline-text-4" id="text-2-1-5">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -781,8 +820,8 @@ local kinetic energy.
</div> </div>
<div id="outline-container-org159140e" class="outline-5"> <div id="outline-container-org7d1aba4" class="outline-5">
<h5 id="org159140e"><span class="section-number-5">2.1.5.1</span> Python</h5> <h5 id="org7d1aba4"><span class="section-number-5">2.1.5.1</span> Python</h5>
<div class="outline-text-5" id="text-2-1-5-1"> <div class="outline-text-5" id="text-2-1-5-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">e_loc</span>(a,r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">e_loc</span>(a,r):
@ -792,8 +831,8 @@ local kinetic energy.
</div> </div>
</div> </div>
<div id="outline-container-org1e4cde2" class="outline-5"> <div id="outline-container-orgb2b4bad" class="outline-5">
<h5 id="org1e4cde2"><span class="section-number-5">2.1.5.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="orgb2b4bad"><span class="section-number-5">2.1.5.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-5-2"> <div class="outline-text-5" id="text-2-1-5-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">e_loc</span>(a,r): <pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">e_loc</span>(a,r):
@ -803,8 +842,8 @@ local kinetic energy.
</div> </div>
</div> </div>
<div id="outline-container-org02d18b8" class="outline-5"> <div id="outline-container-org6e7a546" class="outline-5">
<h5 id="org02d18b8"><span class="section-number-5">2.1.5.3</span> Fortran</h5> <h5 id="org6e7a546"><span class="section-number-5">2.1.5.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-1-5-3"> <div class="outline-text-5" id="text-2-1-5-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">e_loc</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">e_loc</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span>
@ -817,8 +856,8 @@ local kinetic energy.
</div> </div>
</div> </div>
<div id="outline-container-org63ad259" class="outline-5"> <div id="outline-container-org53213b5" class="outline-5">
<h5 id="org63ad259"><span class="section-number-5">2.1.5.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org53213b5"><span class="section-number-5">2.1.5.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-1-5-4"> <div class="outline-text-5" id="text-2-1-5-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">e_loc</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span> <pre class="src src-f90"><span style="color: #228b22;">double precision </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">e_loc</span><span style="color: #000000; background-color: #ffffff;">(a,r)</span>
@ -834,13 +873,20 @@ local kinetic energy.
</div> </div>
</div> </div>
<div id="outline-container-orgdd79233" class="outline-3"> <div id="outline-container-orgbeab5ec" class="outline-3">
<h3 id="orgdd79233"><span class="section-number-3">2.2</span> Plot of the local energy along the \(x\) axis</h3> <h3 id="orgbeab5ec"><span class="section-number-3">2.2</span> Plot of the local energy along the \(x\) axis</h3>
<div class="outline-text-3" id="text-2-2"> <div class="outline-text-3" id="text-2-2">
<div class="note">
<p>
The potential and the kinetic energy both diverge at \(r=0\), so we
choose a grid which does not contain the origin.
</p>
</div>
</div> </div>
<div id="outline-container-orgd250551" class="outline-4"> <div id="outline-container-org3510925" class="outline-4">
<h4 id="orgd250551"><span class="section-number-4">2.2.1</span> Exercise</h4> <h4 id="org3510925"><span class="section-number-4">2.2.1</span> Exercise</h4>
<div class="outline-text-4" id="text-2-2-1"> <div class="outline-text-4" id="text-2-2-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -854,8 +900,8 @@ Gnuplot to plot the files.
</div> </div>
</div> </div>
<div id="outline-container-orgb5fae5f" class="outline-5"> <div id="outline-container-orge574bc5" class="outline-5">
<h5 id="orgb5fae5f"><span class="section-number-5">2.2.1.1</span> Python</h5> <h5 id="orge574bc5"><span class="section-number-5">2.2.1.1</span> Python</h5>
<div class="outline-text-5" id="text-2-2-1-1"> <div class="outline-text-5" id="text-2-2-1-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -876,8 +922,8 @@ plt.savefig(<span style="color: #8b2252;">"plot_py.png"</span>)
</div> </div>
</div> </div>
<div id="outline-container-orgb2f1970" class="outline-5"> <div id="outline-container-org580bac9" class="outline-5">
<h5 id="orgb2f1970"><span class="section-number-5">2.2.1.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org580bac9"><span class="section-number-5">2.2.1.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-2-1-2"> <div class="outline-text-5" id="text-2-2-1-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -906,8 +952,8 @@ plt.savefig(<span style="color: #8b2252;">"plot_py.png"</span>)
</div> </div>
</div> </div>
<div id="outline-container-orga11ec40" class="outline-5"> <div id="outline-container-org03b17a4" class="outline-5">
<h5 id="orga11ec40"><span class="section-number-5">2.2.1.3</span> Fortran</h5> <h5 id="org03b17a4"><span class="section-number-5">2.2.1.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-2-1-3"> <div class="outline-text-5" id="text-2-2-1-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">plot</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">plot</span>
@ -957,8 +1003,8 @@ plot './data' index 0 using 1:2 with lines title 'a=0.1', \
</div> </div>
</div> </div>
<div id="outline-container-org6eafd17" class="outline-5"> <div id="outline-container-org9a6dc16" class="outline-5">
<h5 id="org6eafd17"><span class="section-number-5">2.2.1.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org9a6dc16"><span class="section-number-5">2.2.1.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-2-1-4"> <div class="outline-text-5" id="text-2-2-1-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">plot</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">plot</span>
@ -1029,8 +1075,8 @@ plot './data' index 0 using 1:2 with lines title 'a=0.1', \
</div> </div>
</div> </div>
<div id="outline-container-org554689a" class="outline-3"> <div id="outline-container-orgbf0209f" class="outline-3">
<h3 id="org554689a"><span class="section-number-3">2.3</span> Numerical estimation of the energy</h3> <h3 id="orgbf0209f"><span class="section-number-3">2.3</span> Numerical estimation of the energy</h3>
<div class="outline-text-3" id="text-2-3"> <div class="outline-text-3" id="text-2-3">
<p> <p>
If the space is discretized in small volume elements \(\mathbf{r}_i\) If the space is discretized in small volume elements \(\mathbf{r}_i\)
@ -1060,8 +1106,8 @@ The energy is biased because:
</div> </div>
<div id="outline-container-org6369add" class="outline-4"> <div id="outline-container-org3958454" class="outline-4">
<h4 id="org6369add"><span class="section-number-4">2.3.1</span> Exercise</h4> <h4 id="org3958454"><span class="section-number-4">2.3.1</span> Exercise</h4>
<div class="outline-text-4" id="text-2-3-1"> <div class="outline-text-4" id="text-2-3-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1073,8 +1119,8 @@ Compute a numerical estimate of the energy in a grid of
</div> </div>
</div> </div>
<div id="outline-container-orgf3840f2" class="outline-5"> <div id="outline-container-org30bade1" class="outline-5">
<h5 id="orgf3840f2"><span class="section-number-5">2.3.1.1</span> Python</h5> <h5 id="org30bade1"><span class="section-number-5">2.3.1.1</span> Python</h5>
<div class="outline-text-5" id="text-2-3-1-1"> <div class="outline-text-5" id="text-2-3-1-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -1094,8 +1140,8 @@ Compute a numerical estimate of the energy in a grid of
</div> </div>
</div> </div>
<div id="outline-container-orgf5e3ecd" class="outline-5"> <div id="outline-container-org77b7b0a" class="outline-5">
<h5 id="orgf5e3ecd"><span class="section-number-5">2.3.1.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org77b7b0a"><span class="section-number-5">2.3.1.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-3-1-2"> <div class="outline-text-5" id="text-2-3-1-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -1127,8 +1173,8 @@ Compute a numerical estimate of the energy in a grid of
</div> </div>
</div> </div>
<div id="outline-container-org826f9f4" class="outline-5"> <div id="outline-container-orga93a5dd" class="outline-5">
<h5 id="org826f9f4"><span class="section-number-5">2.3.1.3</span> Fortran</h5> <h5 id="orga93a5dd"><span class="section-number-5">2.3.1.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-3-1-3"> <div class="outline-text-5" id="text-2-3-1-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">energy_hydrogen</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">energy_hydrogen</span>
@ -1165,8 +1211,8 @@ To compile the Fortran and run it:
</div> </div>
</div> </div>
<div id="outline-container-org97c81ba" class="outline-5"> <div id="outline-container-org6dd2871" class="outline-5">
<h5 id="org97c81ba"><span class="section-number-5">2.3.1.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org6dd2871"><span class="section-number-5">2.3.1.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-3-1-4"> <div class="outline-text-5" id="text-2-3-1-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">energy_hydrogen</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">energy_hydrogen</span>
@ -1234,8 +1280,8 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002
</div> </div>
</div> </div>
<div id="outline-container-org4eb04ef" class="outline-3"> <div id="outline-container-orgeedbee0" class="outline-3">
<h3 id="org4eb04ef"><span class="section-number-3">2.4</span> Variance of the local energy</h3> <h3 id="orgeedbee0"><span class="section-number-3">2.4</span> Variance of the local energy</h3>
<div class="outline-text-3" id="text-2-4"> <div class="outline-text-3" id="text-2-4">
<p> <p>
The variance of the local energy is a functional of \(\Psi\) The variance of the local energy is a functional of \(\Psi\)
@ -1262,8 +1308,8 @@ energy can be used as a measure of the quality of a wave function.
</p> </p>
</div> </div>
<div id="outline-container-org9443a40" class="outline-4"> <div id="outline-container-org4acda64" class="outline-4">
<h4 id="org9443a40"><span class="section-number-4">2.4.1</span> Exercise (optional)</h4> <h4 id="org4acda64"><span class="section-number-4">2.4.1</span> Exercise (optional)</h4>
<div class="outline-text-4" id="text-2-4-1"> <div class="outline-text-4" id="text-2-4-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1275,8 +1321,8 @@ Prove that :
</div> </div>
</div> </div>
<div id="outline-container-org5106671" class="outline-4"> <div id="outline-container-org6854abf" class="outline-4">
<h4 id="org5106671"><span class="section-number-4">2.4.2</span> Exercise</h4> <h4 id="org6854abf"><span class="section-number-4">2.4.2</span> Exercise</h4>
<div class="outline-text-4" id="text-2-4-2"> <div class="outline-text-4" id="text-2-4-2">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1290,8 +1336,8 @@ in a grid of \(50\times50\times50\) points in the range
</div> </div>
</div> </div>
<div id="outline-container-org5767c40" class="outline-5"> <div id="outline-container-org0d826af" class="outline-5">
<h5 id="org5767c40"><span class="section-number-5">2.4.2.1</span> Python</h5> <h5 id="org0d826af"><span class="section-number-5">2.4.2.1</span> Python</h5>
<div class="outline-text-5" id="text-2-4-2-1"> <div class="outline-text-5" id="text-2-4-2-1">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -1310,8 +1356,8 @@ in a grid of \(50\times50\times50\) points in the range
</div> </div>
</div> </div>
<div id="outline-container-org32c72a0" class="outline-5"> <div id="outline-container-org576fa85" class="outline-5">
<h5 id="org32c72a0"><span class="section-number-5">2.4.2.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org576fa85"><span class="section-number-5">2.4.2.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-4-2-2"> <div class="outline-text-5" id="text-2-4-2-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np <pre class="src src-python"><span style="color: #a020f0;">import</span> numpy <span style="color: #a020f0;">as</span> np
@ -1347,8 +1393,8 @@ in a grid of \(50\times50\times50\) points in the range
</div> </div>
</div> </div>
<div id="outline-container-org1b3f7f4" class="outline-5"> <div id="outline-container-org307c660" class="outline-5">
<h5 id="org1b3f7f4"><span class="section-number-5">2.4.2.3</span> Fortran</h5> <h5 id="org307c660"><span class="section-number-5">2.4.2.3</span> Fortran</h5>
<div class="outline-text-5" id="text-2-4-2-3"> <div class="outline-text-5" id="text-2-4-2-3">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">variance_hydrogen</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">variance_hydrogen</span>
@ -1390,8 +1436,8 @@ To compile and run:
</div> </div>
</div> </div>
<div id="outline-container-org7f15713" class="outline-5"> <div id="outline-container-org119dad1" class="outline-5">
<h5 id="org7f15713"><span class="section-number-5">2.4.2.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5> <h5 id="org119dad1"><span class="section-number-5">2.4.2.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-2-4-2-4"> <div class="outline-text-5" id="text-2-4-2-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">variance_hydrogen</span> <pre class="src src-f90"><span style="color: #a020f0;">program</span> <span style="color: #0000ff;">variance_hydrogen</span>
@ -1467,8 +1513,8 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002 s2 = 1.806881
</div> </div>
<div id="outline-container-org6414cd7" class="outline-2"> <div id="outline-container-org0c2fa9b" class="outline-2">
<h2 id="org6414cd7"><span class="section-number-2">3</span> <span class="todo TODO">TODO</span> Variational Monte Carlo</h2> <h2 id="org0c2fa9b"><span class="section-number-2">3</span> Variational Monte Carlo</h2>
<div class="outline-text-2" id="text-3"> <div class="outline-text-2" id="text-3">
<p> <p>
Numerical integration with deterministic methods is very efficient Numerical integration with deterministic methods is very efficient
@ -1484,14 +1530,14 @@ interval.
</p> </p>
</div> </div>
<div id="outline-container-org76f4f47" class="outline-3"> <div id="outline-container-org4e85021" class="outline-3">
<h3 id="org76f4f47"><span class="section-number-3">3.1</span> <span class="todo TODO">TODO</span> Computation of the statistical error</h3> <h3 id="org4e85021"><span class="section-number-3">3.1</span> Computation of the statistical error</h3>
<div class="outline-text-3" id="text-3-1"> <div class="outline-text-3" id="text-3-1">
<p> <p>
To compute the statistical error, you need to perform \(M\) To compute the statistical error, you need to perform \(M\)
independent Monte Carlo calculations. You will obtain \(M\) different independent Monte Carlo calculations. You will obtain \(M\) different
estimates of the energy, which are expected to have a Gaussian estimates of the energy, which are expected to have a Gaussian
distribution by the central limit theorem. distribution according to the <a href="https://en.wikipedia.org/wiki/Central_limit_theorem">Central Limit Theorem</a>.
</p> </p>
<p> <p>
@ -1525,8 +1571,8 @@ And the confidence interval is given by
</p> </p>
</div> </div>
<div id="outline-container-orgc801982" class="outline-4"> <div id="outline-container-orga3687ff" class="outline-4">
<h4 id="orgc801982"><span class="section-number-4">3.1.1</span> Exercise</h4> <h4 id="orga3687ff"><span class="section-number-4">3.1.1</span> Exercise</h4>
<div class="outline-text-4" id="text-3-1-1"> <div class="outline-text-4" id="text-3-1-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1534,25 +1580,61 @@ Write a function returning the average and statistical error of an
input array. input array.
</p> </p>
</div>
</div> </div>
<p> <div id="outline-container-org568b394" class="outline-5">
<b>Python</b> <h5 id="org568b394"><span class="section-number-5">3.1.1.1</span> Python</h5>
</p> <div class="outline-text-5" id="text-3-1-1-1">
<div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">from</span> math <span style="color: #a020f0;">import</span> sqrt
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">ave_error</span>(arr):
#<span style="color: #b22222;">TODO</span>
<span style="color: #a020f0;">return</span> (average, error)
</pre>
</div>
</div>
</div>
<div id="outline-container-org3d69b65" class="outline-5">
<h5 id="org3d69b65"><span class="section-number-5">3.1.1.2</span> Python&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-3-1-1-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-python"><span style="color: #a020f0;">from</span> math <span style="color: #a020f0;">import</span> sqrt <pre class="src src-python"><span style="color: #a020f0;">from</span> math <span style="color: #a020f0;">import</span> sqrt
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">ave_error</span>(arr): <span style="color: #a020f0;">def</span> <span style="color: #0000ff;">ave_error</span>(arr):
<span style="color: #a0522d;">M</span> = <span style="color: #483d8b;">len</span>(arr) <span style="color: #a0522d;">M</span> = <span style="color: #483d8b;">len</span>(arr)
<span style="color: #a020f0;">assert</span> (M&gt;1) <span style="color: #a020f0;">assert</span>(M&gt;0)
<span style="color: #a0522d;">average</span> = <span style="color: #483d8b;">sum</span>(arr)/M <span style="color: #a020f0;">if</span> M == 1:
<span style="color: #a0522d;">variance</span> = 1./(M-1) * <span style="color: #483d8b;">sum</span>( [ (x - average)**2 <span style="color: #a020f0;">for</span> x <span style="color: #a020f0;">in</span> arr ] ) <span style="color: #a020f0;">return</span> (arr[0], 0.)
<span style="color: #a020f0;">return</span> (average, sqrt(variance/M)) <span style="color: #a020f0;">else</span>:
<span style="color: #a0522d;">average</span> = <span style="color: #483d8b;">sum</span>(arr)/M
<span style="color: #a0522d;">variance</span> = 1./(M-1) * <span style="color: #483d8b;">sum</span>( [ (x - average)**2 <span style="color: #a020f0;">for</span> x <span style="color: #a020f0;">in</span> arr ] )
<span style="color: #a0522d;">error</span> = sqrt(variance/M)
<span style="color: #a020f0;">return</span> (average, error)
</pre> </pre>
</div> </div>
</div>
</div>
<p> <div id="outline-container-org314b0e7" class="outline-5">
<b>Fortran</b> <h5 id="org314b0e7"><span class="section-number-5">3.1.1.3</span> Fortran</h5>
</p> <div class="outline-text-5" id="text-3-1-1-3">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">ave_error</span>(x,n,ave,err)
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> n </span>
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> x(n) </span>
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> ave, err</span>
! <span style="color: #b22222;">TODO</span>
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">ave_error</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org0f8bdcf" class="outline-5">
<h5 id="org0f8bdcf"><span class="section-number-5">3.1.1.4</span> Fortran&#xa0;&#xa0;&#xa0;<span class="tag"><span class="solution">solution</span></span></h5>
<div class="outline-text-5" id="text-3-1-1-4">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">ave_error</span>(x,n,ave,err) <pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">ave_error</span>(x,n,ave,err)
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span> <span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
@ -1560,7 +1642,9 @@ input array.
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> x(n) </span> <span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> x(n) </span>
<span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> ave, err</span> <span style="color: #228b22;">double precision</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> ave, err</span>
<span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> variance</span> <span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> variance</span>
<span style="color: #a020f0;">if</span> (n == 1) <span style="color: #a020f0;">then</span> <span style="color: #a020f0;">if</span> (n &lt; 1) <span style="color: #a020f0;">then</span>
<span style="color: #a020f0;">stop</span> <span style="color: #8b2252;">'n&lt;1 in ave_error'</span>
<span style="color: #a020f0;">else if</span> (n == 1) <span style="color: #a020f0;">then</span>
ave = x(1) ave = x(1)
err = 0.d0 err = 0.d0
<span style="color: #a020f0;">else</span> <span style="color: #a020f0;">else</span>
@ -1574,9 +1658,10 @@ input array.
</div> </div>
</div> </div>
</div> </div>
</div>
<div id="outline-container-org8b118ec" class="outline-3"> <div id="outline-container-orgb0930a1" class="outline-3">
<h3 id="org8b118ec"><span class="section-number-3">3.2</span> <span class="todo TODO">TODO</span> Uniform sampling in the box</h3> <h3 id="orgb0930a1"><span class="section-number-3">3.2</span> <span class="todo TODO">TODO</span> Uniform sampling in the box</h3>
<div class="outline-text-3" id="text-3-2"> <div class="outline-text-3" id="text-3-2">
<p> <p>
We will now do our first Monte Carlo calculation to compute the We will now do our first Monte Carlo calculation to compute the
@ -1610,8 +1695,8 @@ statistical error.
</p> </p>
</div> </div>
<div id="outline-container-org925cb8e" class="outline-4"> <div id="outline-container-org1ecf130" class="outline-4">
<h4 id="org925cb8e"><span class="section-number-4">3.2.1</span> Exercise</h4> <h4 id="org1ecf130"><span class="section-number-4">3.2.1</span> Exercise</h4>
<div class="outline-text-4" id="text-3-2-1"> <div class="outline-text-4" id="text-3-2-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1721,8 +1806,8 @@ E = -0.49588321986667677 +/- 7.1758863546737969E-004
</div> </div>
</div> </div>
<div id="outline-container-org8c24125" class="outline-3"> <div id="outline-container-org5d0adc4" class="outline-3">
<h3 id="org8c24125"><span class="section-number-3">3.3</span> <span class="todo TODO">TODO</span> Metropolis sampling with \(\Psi^2\)</h3> <h3 id="org5d0adc4"><span class="section-number-3">3.3</span> <span class="todo TODO">TODO</span> Metropolis sampling with \(\Psi^2\)</h3>
<div class="outline-text-3" id="text-3-3"> <div class="outline-text-3" id="text-3-3">
<p> <p>
We will now use the square of the wave function to sample random We will now use the square of the wave function to sample random
@ -1809,8 +1894,8 @@ step such that the acceptance rate is close to 0.5 is a good compromise.
</div> </div>
<div id="outline-container-org99bc8b5" class="outline-4"> <div id="outline-container-orgb3a648e" class="outline-4">
<h4 id="org99bc8b5"><span class="section-number-4">3.3.1</span> Exercise</h4> <h4 id="orgb3a648e"><span class="section-number-4">3.3.1</span> Exercise</h4>
<div class="outline-text-4" id="text-3-3-1"> <div class="outline-text-4" id="text-3-3-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -1940,8 +2025,8 @@ A = 0.51737800000000000 +/- 4.1827406733181444E-004
</div> </div>
</div> </div>
<div id="outline-container-org85cb077" class="outline-3"> <div id="outline-container-orgb5348ef" class="outline-3">
<h3 id="org85cb077"><span class="section-number-3">3.4</span> <span class="todo TODO">TODO</span> Gaussian random number generator</h3> <h3 id="orgb5348ef"><span class="section-number-3">3.4</span> <span class="todo TODO">TODO</span> Gaussian random number generator</h3>
<div class="outline-text-3" id="text-3-4"> <div class="outline-text-3" id="text-3-4">
<p> <p>
To obtain Gaussian-distributed random numbers, you can apply the To obtain Gaussian-distributed random numbers, you can apply the
@ -1995,8 +2080,8 @@ following sections.
</div> </div>
</div> </div>
<div id="outline-container-org3f7062f" class="outline-3"> <div id="outline-container-org932bae5" class="outline-3">
<h3 id="org3f7062f"><span class="section-number-3">3.5</span> <span class="todo TODO">TODO</span> Generalized Metropolis algorithm</h3> <h3 id="org932bae5"><span class="section-number-3">3.5</span> <span class="todo TODO">TODO</span> Generalized Metropolis algorithm</h3>
<div class="outline-text-3" id="text-3-5"> <div class="outline-text-3" id="text-3-5">
<p> <p>
One can use more efficient numerical schemes to move the electrons. One can use more efficient numerical schemes to move the electrons.
@ -2095,8 +2180,8 @@ The transition probability becomes:
</div> </div>
<div id="outline-container-orgc5b23ac" class="outline-4"> <div id="outline-container-org460f3fe" class="outline-4">
<h4 id="orgc5b23ac"><span class="section-number-4">3.5.1</span> Exercise 1</h4> <h4 id="org460f3fe"><span class="section-number-4">3.5.1</span> Exercise 1</h4>
<div class="outline-text-4" id="text-3-5-1"> <div class="outline-text-4" id="text-3-5-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -2132,8 +2217,8 @@ Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\P
</div> </div>
</div> </div>
<div id="outline-container-org876a231" class="outline-4"> <div id="outline-container-orgd39a7d7" class="outline-4">
<h4 id="org876a231"><span class="section-number-4">3.5.2</span> Exercise 2</h4> <h4 id="orgd39a7d7"><span class="section-number-4">3.5.2</span> Exercise 2</h4>
<div class="outline-text-4" id="text-3-5-2"> <div class="outline-text-4" id="text-3-5-2">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -2285,17 +2370,17 @@ A = 0.78861366666666655 +/- 3.5096729498002445E-004
</div> </div>
</div> </div>
<div id="outline-container-org86be009" class="outline-2"> <div id="outline-container-orgaf5996c" class="outline-2">
<h2 id="org86be009"><span class="section-number-2">4</span> <span class="todo TODO">TODO</span> Diffusion Monte Carlo</h2> <h2 id="orgaf5996c"><span class="section-number-2">4</span> <span class="todo TODO">TODO</span> Diffusion Monte Carlo</h2>
<div class="outline-text-2" id="text-4"> <div class="outline-text-2" id="text-4">
</div> </div>
<div id="outline-container-orgbbfe631" class="outline-3"> <div id="outline-container-org12ab3c5" class="outline-3">
<h3 id="orgbbfe631"><span class="section-number-3">4.1</span> <span class="todo TODO">TODO</span> Hydrogen atom</h3> <h3 id="org12ab3c5"><span class="section-number-3">4.1</span> <span class="todo TODO">TODO</span> Hydrogen atom</h3>
<div class="outline-text-3" id="text-4-1"> <div class="outline-text-3" id="text-4-1">
</div> </div>
<div id="outline-container-org574137c" class="outline-4"> <div id="outline-container-org3b3e8ae" class="outline-4">
<h4 id="org574137c"><span class="section-number-4">4.1.1</span> Exercise</h4> <h4 id="org3b3e8ae"><span class="section-number-4">4.1.1</span> Exercise</h4>
<div class="outline-text-4" id="text-4-1-1"> <div class="outline-text-4" id="text-4-1-1">
<div class="exercise"> <div class="exercise">
<p> <p>
@ -2453,8 +2538,8 @@ A = 0.78861366666666655 +/- 3.5096729498002445E-004
</div> </div>
<div id="outline-container-orgdb34f3d" class="outline-3"> <div id="outline-container-orgf0f2402" class="outline-3">
<h3 id="orgdb34f3d"><span class="section-number-3">4.2</span> <span class="todo TODO">TODO</span> Dihydrogen</h3> <h3 id="orgf0f2402"><span class="section-number-3">4.2</span> <span class="todo TODO">TODO</span> Dihydrogen</h3>
<div class="outline-text-3" id="text-4-2"> <div class="outline-text-3" id="text-4-2">
<p> <p>
We will now consider the H<sub>2</sub> molecule in a minimal basis composed of the We will now consider the H<sub>2</sub> molecule in a minimal basis composed of the
@ -2475,8 +2560,8 @@ the nuclei.
</div> </div>
<div id="outline-container-orgc3ba7b8" class="outline-2"> <div id="outline-container-org1c017d7" class="outline-2">
<h2 id="orgc3ba7b8"><span class="section-number-2">5</span> <span class="todo TODO">TODO</span> <code>[0/1]</code> Last things to do</h2> <h2 id="org1c017d7"><span class="section-number-2">5</span> <span class="todo TODO">TODO</span> <code>[0/1]</code> Last things to do</h2>
<div class="outline-text-2" id="text-5"> <div class="outline-text-2" id="text-5">
<ul class="org-ul"> <ul class="org-ul">
<li class="off"><code>[&#xa0;]</code> Prepare 4 questions for the exam: multiple-choice questions <li class="off"><code>[&#xa0;]</code> Prepare 4 questions for the exam: multiple-choice questions
@ -2491,7 +2576,7 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u.</li>
</div> </div>
<div id="postamble" class="status"> <div id="postamble" class="status">
<p class="author">Author: Anthony Scemama, Claudia Filippi</p> <p class="author">Author: Anthony Scemama, Claudia Filippi</p>
<p class="date">Created: 2021-01-25 Mon 22:54</p> <p class="date">Created: 2021-01-25 Mon 23:23</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div> </div>
</body> </body>