1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-10-02 06:21:07 +02:00
qmckl/index.html
2020-12-03 18:00:55 +00:00

2865 lines
134 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2020-12-03 Thu 18:00 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>QMCkl source code documentation</title>
<meta name="generator" content="Org mode" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"></script>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2019 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="content">
<h1 class="title">QMCkl source code documentation</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org335b8ad">1. Introduction</a>
<ul>
<li><a href="#org975c069">1.1. Language used</a></li>
<li><a href="#orgd9a3d74">1.2. Source code editing</a></li>
<li><a href="#org7fa05fe">1.3. Writing in Fortran</a></li>
<li><a href="#org1b3441f">1.4. Coding style</a></li>
<li><a href="#org37ab598">1.5. Design of the library</a>
<ul>
<li><a href="#org040bea0">1.5.1. Naming conventions</a></li>
<li><a href="#orgd24dcc0">1.5.2. Application programming interface</a></li>
<li><a href="#org4fbc31d">1.5.3. Global state</a></li>
<li><a href="#orgb33c82b">1.5.4. Low-level functions</a></li>
<li><a href="#org7636c25">1.5.5. High-level functions</a></li>
<li><a href="#org503220e">1.5.6. Numerical precision</a></li>
</ul>
</li>
<li><a href="#org240c3cd">1.6. Algorithms</a></li>
<li><a href="#org43d8314">1.7. Rules for the API</a></li>
</ul>
</li>
<li><a href="#orgf6cb0a7">2. Documentation</a>
<ul>
<li><a href="#orgbb43cd1">2.1. <code>qmckl.h</code> header file</a>
<ul>
<li><a href="#org482c5f0">2.1.1. Constants</a></li>
</ul>
</li>
<li><a href="#orgb3794b5">2.2. Memory management</a>
<ul>
<li><a href="#org1501ebd">2.2.1. <code>qmckl_malloc</code></a></li>
<li><a href="#orga7d25af">2.2.2. <code>qmckl_free</code></a></li>
</ul>
</li>
<li><a href="#orgb4bf6c5">2.3. Context</a>
<ul>
<li><a href="#orgdd38676">2.3.1. Context</a></li>
<li><a href="#org354ee46">2.3.2. Basis set</a></li>
<li><a href="#orgcc5fd18">2.3.3. Precision</a></li>
</ul>
</li>
<li><a href="#orga3e42f5">2.4. Computation of distances</a>
<ul>
<li><a href="#orgcab1734">2.4.1. Squared distance</a></li>
</ul>
</li>
<li><a href="#org031a382">2.5. Atomic Orbitals</a>
<ul>
<li><a href="#org8371761">2.5.1. Polynomials</a></li>
<li><a href="#org859d9a6">2.5.2. Gaussian basis functions</a></li>
<li><a href="#org00a5e37">2.5.3. <span class="todo TODO">TODO</span> Slater basis functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org3732fa8">3. Acknowledgments</a></li>
</ul>
</div>
</div>
<div id="outline-container-org335b8ad" class="outline-2">
<h2 id="org335b8ad"><span class="section-number-2">1</span> Introduction</h2>
<div class="outline-text-2" id="text-1">
<p>
The ultimate goal of QMCkl is to provide a high-performance
implementation of the main kernels of QMC. In this particular
repository, we focus on the definition of the API and the tests, and
on a <i>pedagogical</i> presentation of the algorithms. We expect the
HPC experts to use this repository as a reference for re-writing
optimized libraries.
</p>
<p>
Literate programming is particularly adapted in this context.
Source files are written in <a href="https://karl-voit.at/2017/09/23/orgmode-as-markup-only/">org-mode</a> format, to provide useful
comments and LaTex formulas close to the code. There exists multiple
possibilities to convert org-mode files into different formats such
as HTML or pdf. For a tutorial on literate programming with
org-mode, follow <a href="http://www.howardism.org/Technical/Emacs/literate-programming-tutorial.html">this link</a>.
</p>
<p>
The code is extracted from the org files using Emacs as a
command-line tool in the <code>Makefile</code>, and then the produced files are
compiled.
</p>
</div>
<div id="outline-container-org975c069" class="outline-3">
<h3 id="org975c069"><span class="section-number-3">1.1</span> Language used</h3>
<div class="outline-text-3" id="text-1-1">
<p>
Fortran is one of the most common languages used by the community,
and is simple enough to make the algorithms readable. Hence we
propose in this pedagogical implementation of QMCkl to use Fortran
to express the algorithms. For specific internal functions where
the C language is more natural, C is used.
</p>
<p>
As Fortran modules generate compiler-dependent files, the use of
modules is restricted to the internal use of the library, otherwise
the compliance with C is violated.
</p>
<p>
The external dependencies should be kept as small as possible, so
external libraries should be used <i>only</i> if their used is strongly
justified.
</p>
</div>
</div>
<div id="outline-container-orgd9a3d74" class="outline-3">
<h3 id="orgd9a3d74"><span class="section-number-3">1.2</span> Source code editing</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Any text editor can be used to edit org-mode files. For a better
user experience Emacs is recommended. For users hating Emacs, it
is good to know that Emacs can behave like Vim when switched into
``Evil'' mode. There also exists <a href="https://www.spacemacs.org">Spacemacs</a> which helps the
transition for Vim users.
</p>
<p>
For users with a preference for Jupyter notebooks, the following
script can convert jupyter notebooks to org-mode files:
</p>
<div class="org-src-container">
<pre class="src src-sh">#<span style="color: #b22222;">!/bin/</span><span style="color: #a020f0;">bash</span>
# <span style="color: #b22222;">$ nb_to_org.sh notebook.ipynb</span>
# <span style="color: #b22222;">produces the org-mode file notebook.org</span>
<span style="color: #483d8b;">set</span> -e
<span style="color: #a0522d;">nb</span>=$(basename $<span style="color: #a0522d;">1</span> .ipynb)
jupyter nbconvert --to markdown ${<span style="color: #a0522d;">nb</span>}.ipynb --output ${<span style="color: #a0522d;">nb</span>}.md
pandoc ${<span style="color: #a0522d;">nb</span>}.md -o ${<span style="color: #a0522d;">nb</span>}.org
rm ${<span style="color: #a0522d;">nb</span>}.md
</pre>
</div>
<p>
And pandoc can convert multiple markdown formats into org-mode.
</p>
</div>
</div>
<div id="outline-container-org7fa05fe" class="outline-3">
<h3 id="org7fa05fe"><span class="section-number-3">1.3</span> Writing in Fortran</h3>
<div class="outline-text-3" id="text-1-3">
<p>
The Fortran source files should provide a C interface using
<code>iso_c_binding</code>. The name of the Fortran source files should end
with <code>_f.f90</code> to be properly handled by the Makefile. The names of
the functions defined in fortran should be the same as those
exposed in the API suffixed by <code>_f</code>. Fortran interface files
should also be written in the <code>qmckl_f.f90</code> file.
</p>
<p>
For more guidelines on using Fortran to generate a C interface, see
<a href="http://fortranwiki.org/fortran/show/Generating+C+Interfaces">this link</a>.
</p>
</div>
</div>
<div id="outline-container-org1b3441f" class="outline-3">
<h3 id="org1b3441f"><span class="section-number-3">1.4</span> Coding style</h3>
<div class="outline-text-3" id="text-1-4">
<p>
To improve readability, we maintain a consistent coding style in
the library.
</p>
<ul class="org-ul">
<li>For C source files, we will use <span class="underline"><span class="underline">(decide on a coding style)</span></span></li>
<li>For Fortran source files, we will use <span class="underline"><span class="underline">(decide on a coding
style)</span></span></li>
</ul>
<p>
Coding style can be automatically checked with <a href="https://clang.llvm.org/docs/ClangFormat.html">clang-format</a>.
</p>
</div>
</div>
<div id="outline-container-org37ab598" class="outline-3">
<h3 id="org37ab598"><span class="section-number-3">1.5</span> Design of the library</h3>
<div class="outline-text-3" id="text-1-5">
<p>
The proposed API should allow the library to:
</p>
<ul class="org-ul">
<li>deal with memory transfers between CPU and accelerators</li>
<li>use different levels of floating-point precision</li>
</ul>
<p>
We chose a multi-layered design with low-level and high-level
functions (see below).
</p>
</div>
<div id="outline-container-org040bea0" class="outline-4">
<h4 id="org040bea0"><span class="section-number-4">1.5.1</span> Naming conventions</h4>
<div class="outline-text-4" id="text-1-5-1">
<p>
Use <code>qmckl_</code> as a prefix for all exported functions and variables.
All exported header files should have a filename with the prefix
<code>qmckl_</code>.
</p>
<p>
If the name of the org-mode file is <code>xxx.org</code>, the name of the
produced C files should be <code>xxx.c</code> and <code>xxx.h</code> and the name of the
produced Fortran files should be <code>xxx.f90</code>
</p>
<p>
Arrays are in uppercase and scalars are in lowercase.
</p>
<p>
In the names of the variables and functions, only the singular
form is allowed.
</p>
</div>
</div>
<div id="outline-container-orgd24dcc0" class="outline-4">
<h4 id="orgd24dcc0"><span class="section-number-4">1.5.2</span> Application programming interface</h4>
<div class="outline-text-4" id="text-1-5-2">
<p>
The application programming interface (API) is designed to be
compatible with the C programming language (not C++), to ensure
that the library will be easily usable in <i>any</i> language. This
implies that only the following data types are allowed in the API:
</p>
<ul class="org-ul">
<li>32-bit and 64-bit floats and arrays (<code>real</code> and <code>double</code>)</li>
<li>32-bit and 64-bit integers and arrays (<code>int32_t</code> and <code>int64_t</code>)</li>
<li>Pointers should be represented as 64-bit integers (even on
32-bit architectures)</li>
<li>ASCII strings are represented as a pointers to a character
arrays and terminated by a zero character (C convention).</li>
</ul>
<p>
Complex numbers can be represented by an array of 2 floats.
</p>
<p>
To facilitate the use in other languages than C, we provide some
bindings in other languages in other repositories.
</p>
</div>
</div>
<div id="outline-container-org4fbc31d" class="outline-4">
<h4 id="org4fbc31d"><span class="section-number-4">1.5.3</span> Global state</h4>
<div class="outline-text-4" id="text-1-5-3">
<p>
Global variables should be avoided in the library, because it is
possible that one single program needs to use multiple instances
of the library. To solve this problem we propose to use a pointer
to a <code>context</code> variable, built by the library with the
<code>qmckl_context_create</code> function. The <code>context</code> contains the global
state of the library, and is used as the first argument of many
QMCkl functions.
</p>
<p>
The internal structure of the context is not specified, to give a
maximum of freedom to the different implementations. Modifying
the state is done by setters and getters, prefixed by
<code>qmckl_context_set_</code> an <code>qmckl_context_get_</code>. When a context
variable is modified by a setter, a copy of the old data structure
is made and updated, and the pointer to the new data structure is
returned, such that the old contexts can still be accessed. It is
also possible to modify the state in an impure fashion, using the
<code>qmckl_context_update_</code> functions. The context and its old
versions can be destroyed with <code>qmckl_context_destroy</code>.
</p>
</div>
</div>
<div id="outline-container-orgb33c82b" class="outline-4">
<h4 id="orgb33c82b"><span class="section-number-4">1.5.4</span> Low-level functions</h4>
<div class="outline-text-4" id="text-1-5-4">
<p>
Low-level functions are very simple functions which are leaves of
the function call tree (they don't call any other QMCkl function).
</p>
<p>
These functions are <i>pure</i>, and unaware of the QMCkl
<code>context</code>. They are not allowed to allocate/deallocate memory, and
if they need temporary memory it should be provided in input.
</p>
</div>
</div>
<div id="outline-container-org7636c25" class="outline-4">
<h4 id="org7636c25"><span class="section-number-4">1.5.5</span> High-level functions</h4>
<div class="outline-text-4" id="text-1-5-5">
<p>
High-level functions are at the top of the function call tree.
They are able to choose which lower-level function to call
depending on the required precision, and do the corresponding type
conversions. These functions are also responsible for allocating
temporary storage, to simplify the use of accelerators.
</p>
<p>
The high-level functions should be pure, unless the introduction
of non-purity is justified. All the side effects should be made in
the <code>context</code> variable.
</p>
</div>
</div>
<div id="outline-container-org503220e" class="outline-4">
<h4 id="org503220e"><span class="section-number-4">1.5.6</span> Numerical precision</h4>
<div class="outline-text-4" id="text-1-5-6">
<p>
The number of bits of precision required for a function should be
given as an input of low-level computational functions. This input
will be used to define the values of the different thresholds that
might be used to avoid computing unnecessary noise. High-level
functions will use the precision specified in the <code>context</code>
variable.
</p>
</div>
</div>
</div>
<div id="outline-container-org240c3cd" class="outline-3">
<h3 id="org240c3cd"><span class="section-number-3">1.6</span> Algorithms</h3>
<div class="outline-text-3" id="text-1-6">
<p>
Reducing the scaling of an algorithm usually implies also reducing
its arithmetic complexity (number of flops per byte). Therefore,
for small sizes \(\mathcal{O}(N^3)\) and \(\mathcal{O}(N^2)\)
algorithms are better adapted than linear scaling algorithms. As
QMCkl is a general purpose library, multiple algorithms should be
implemented adapted to different problem sizes.
</p>
</div>
</div>
<div id="outline-container-org43d8314" class="outline-3">
<h3 id="org43d8314"><span class="section-number-3">1.7</span> Rules for the API</h3>
<div class="outline-text-3" id="text-1-7">
<ul class="org-ul">
<li><code>stdint</code> should be used for integers (<code>int32_t</code>, <code>int64_t</code>)</li>
<li>integers used for counting should always be <code>int64_t</code></li>
<li>floats should be by default <code>double</code>, unless explicitly mentioned</li>
<li>pointers are converted to <code>int64_t</code> to increase portability</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-orgf6cb0a7" class="outline-2">
<h2 id="orgf6cb0a7"><span class="section-number-2">2</span> Documentation</h2>
<div class="outline-text-2" id="text-2">
</div>
<div id="outline-container-orgbb43cd1" class="outline-3">
<h3 id="orgbb43cd1"><span class="section-number-3">2.1</span> <code>qmckl.h</code> header file</h3>
<div class="outline-text-3" id="text-2-1">
<p>
This file produces the <code>qmckl.h</code> header file, which is to be included
when qmckl functions are used.
</p>
<p>
We also create here the <code>qmckl_f.f90</code> which is the Fortran interface file.
</p>
</div>
<div id="outline-container-org482c5f0" class="outline-4">
<h4 id="org482c5f0"><span class="section-number-4">2.1.1</span> Constants</h4>
<div class="outline-text-4" id="text-2-1-1">
</div>
<ol class="org-ol">
<li><a id="org14c012b"></a>Success/failure<br />
<div class="outline-text-5" id="text-2-1-1-1">
<p>
These are the codes returned by the functions to indicate success
or failure. All such functions should have as a return type <code>qmckl_exit_code</code>.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_SUCCESS</span> 0
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_FAILURE</span> 1
<span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int32_t</span> <span style="color: #228b22;">qmckl_exit_code</span>;
<span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int64_t</span> <span style="color: #228b22;">qmckl_context</span> ;
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_SUCCESS = 0</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_FAILURE = 0</span>
</pre>
</div>
</div>
</li>
<li><a id="orgbe1cb71"></a>Precision-related constants<br />
<div class="outline-text-5" id="text-2-1-1-2">
<p>
Controlling numerical precision enables optimizations. Here, the
default parameters determining the target numerical precision and
range are defined.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_DEFAULT_PRECISION</span> 53
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_DEFAULT_RANGE</span> 11
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_DEFAULT_PRECISION = 53</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_DEFAULT_RANGE = 11</span>
</pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div id="outline-container-orgb3794b5" class="outline-3">
<h3 id="orgb3794b5"><span class="section-number-3">2.2</span> Memory management</h3>
<div class="outline-text-3" id="text-2-2">
<p>
We override the allocation functions to enable the possibility of
optimized libraries to fine-tune the memory allocation.
</p>
<p>
2 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_memory.c</code></li>
<li>a test file : <code>test_qmckl_memory.c</code></li>
</ul>
</div>
<div id="outline-container-org1501ebd" class="outline-4">
<h4 id="org1501ebd"><span class="section-number-4">2.2.1</span> <code>qmckl_malloc</code></h4>
<div class="outline-text-4" id="text-2-2-1">
<p>
Memory allocation function, letting the library choose how the
memory will be allocated, and a pointer is returned to the user.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">void</span>* <span style="color: #0000ff;">qmckl_malloc</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">ctx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>);
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">type (c_ptr) </span><span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_malloc</span> <span style="color: #000000; background-color: #ffffff;">(context, size) bind(C)</span>
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> size</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_malloc</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org59a2956"></a>Source<br />
<div class="outline-text-5" id="text-2-2-1-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">void</span>* <span style="color: #0000ff;">qmckl_malloc</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">ctx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>) {
<span style="color: #a020f0;">if</span> (ctx == (<span style="color: #228b22;">qmckl_context</span>) 0) {
/* <span style="color: #b22222;">Avoids unused parameter error </span>*/
<span style="color: #a020f0;">return</span> malloc( (<span style="color: #228b22;">size_t</span>) size );
}
<span style="color: #a020f0;">return</span> malloc( (<span style="color: #228b22;">size_t</span>) size );
}
</pre>
</div>
</div>
</li>
</ol>
</div>
<div id="outline-container-orga7d25af" class="outline-4">
<h4 id="orga7d25af"><span class="section-number-4">2.2.2</span> <code>qmckl_free</code></h4>
<div class="outline-text-4" id="text-2-2-2">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">void</span> <span style="color: #0000ff;">qmckl_free</span>(<span style="color: #228b22;">void</span> *<span style="color: #a0522d;">ptr</span>);
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">qmckl_free</span> (ptr) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">type (c_ptr)</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> :: <span style="color: #a0522d;">ptr</span>
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">qmckl_free</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgcd777db"></a>Source<br />
<div class="outline-text-5" id="text-2-2-2-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">void</span> <span style="color: #0000ff;">qmckl_free</span>(<span style="color: #228b22;">void</span> *<span style="color: #a0522d;">ptr</span>) {
free(ptr);
}
</pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div id="outline-container-orgb4bf6c5" class="outline-3">
<h3 id="orgb4bf6c5"><span class="section-number-3">2.3</span> Context</h3>
<div class="outline-text-3" id="text-2-3">
<p>
This file is written in C because it is more natural to express the
context in C than in Fortran.
</p>
<p>
2 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_context.c</code></li>
<li>a test file : <code>test_qmckl_context.c</code></li>
</ul>
</div>
<div id="outline-container-orgdd38676" class="outline-4">
<h4 id="orgdd38676"><span class="section-number-4">2.3.1</span> Context</h4>
<div class="outline-text-4" id="text-2-3-1">
<p>
The context variable is a handle for the state of the library, and
is stored in the following data structure, which can't be seen
outside of the library. To simplify compatibility with other
languages, the pointer to the internal data structure is converted
into a 64-bit signed integer, defined in the <code>qmckl_context</code> type.
A value of 0 for the context is equivalent to a <code>NULL</code> pointer.
</p>
<div class="org-src-container">
<pre class="src src-C">
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgb38c7b4"></a>Basis set data structure<br />
<div class="outline-text-5" id="text-2-3-1-1">
<p>
Data structure for the info related to the atomic orbitals
basis set.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_ao_basis_struct</span> {
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span>;
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_center</span>;
<span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">shell_ang_mom</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">shell_factor</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">exponent</span> ;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">coefficient</span> ;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_prim_num</span>;
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>;
} <span style="color: #228b22;">qmckl_ao_basis_struct</span>;
</pre>
</div>
</div>
</li>
<li><a id="org2f75436"></a>Source<br />
<div class="outline-text-5" id="text-2-3-1-2">
<p>
The tag is used internally to check if the memory domain pointed
by a pointer is a valid context.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_context_struct</span> {
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_context_struct</span> * <span style="color: #a0522d;">prev</span>;
/* <span style="color: #b22222;">Molecular system </span>*/
// <span style="color: #b22222;">struct qmckl_nucleus_struct * nucleus; </span>
// <span style="color: #b22222;">struct qmckl_electron_struct * electron;</span>
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_ao_basis_struct</span> * <span style="color: #a0522d;">ao_basis</span>;
// <span style="color: #b22222;">struct qmckl_mo_struct * mo;</span>
// <span style="color: #b22222;">struct qmckl_determinant_struct * det;</span>
/* <span style="color: #b22222;">Numerical precision </span>*/
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">tag</span>;
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">precision</span>;
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">range</span>;
} <span style="color: #228b22;">qmckl_context_struct</span>;
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">VALID_TAG</span> 0xBEEFFACE
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">INVALID_TAG</span> 0xDEADBEEF
</pre>
</div>
</div>
</li>
<li><a id="orgaee32b5"></a><code>qmckl_context_check</code><br />
<div class="outline-text-5" id="text-2-3-1-3">
<p>
Checks if the domain pointed by the pointer is a valid context.
Returns the input <code>qmckl_context</code> if the context is valid, 0
otherwise.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) ;
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org7eca44b"></a>Source<br />
<div class="outline-text-6" id="text-2-3-1-3-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">if</span> (context == (<span style="color: #228b22;">qmckl_context</span>) 0) <span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span> * <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx-&gt;tag != VALID_TAG) <span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
<span style="color: #a020f0;">return</span> context;
}
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org949aa80"></a><code>qmckl_context_create</code><br />
<div class="outline-text-5" id="text-2-3-1-4">
<p>
To create a new context, use <code>qmckl_context_create()</code>.
</p>
<ul class="org-ul">
<li>On success, returns a pointer to a context using the <code>qmckl_context</code> type</li>
<li><p>
Returns <code>0</code> upon failure to allocate the internal data structure
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_create</span>();
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="orgaeebce9"></a>Source<br />
<div class="outline-text-6" id="text-2-3-1-4-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_create</span>() {
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">context</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) qmckl_malloc ((<span style="color: #228b22;">qmckl_context</span>) 0, <span style="color: #a020f0;">sizeof</span>(qmckl_context_struct));
<span style="color: #a020f0;">if</span> (context == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
context-&gt;prev = <span style="color: #008b8b;">NULL</span>;
context-&gt;ao_basis = <span style="color: #008b8b;">NULL</span>;
context-&gt;precision = QMCKL_DEFAULT_PRECISION;
context-&gt;range = QMCKL_DEFAULT_RANGE;
context-&gt;tag = VALID_TAG;
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) context;
}
</pre>
</div>
</div>
</li>
<li><a id="org3b55931"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-1-4-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_create</span>() <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_create</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org4ed37de"></a><code>qmckl_context_copy</code><br />
<div class="outline-text-5" id="text-2-3-1-5">
<p>
This function makes a shallow copy of the current context.
</p>
<ul class="org-ul">
<li>Copying the 0-valued context returns 0</li>
<li>On success, returns a pointer to the new context using the <code>qmckl_context</code> type</li>
<li><p>
Returns 0 upon failure to allocate the internal data structure
for the new context
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_copy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="org0b33fb3"></a>Source<br />
<div class="outline-text-6" id="text-2-3-1-5-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_copy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">old_context</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">new_context</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_context_struct</span>));
<span style="color: #a020f0;">if</span> (new_context == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
new_context-&gt;prev = old_context;
new_context-&gt;ao_basis = old_context-&gt;ao_basis;
new_context-&gt;precision = old_context-&gt;precision;
new_context-&gt;range = old_context-&gt;range;
new_context-&gt;tag = VALID_TAG;
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="orgaad248e"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-1-5-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_copy</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_copy</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org80da7b3"></a><code>qmckl_context_previous</code><br />
<div class="outline-text-5" id="text-2-3-1-6">
<p>
Returns the previous context
</p>
<ul class="org-ul">
<li>On success, returns the ancestor of the current context</li>
<li>Returns 0 for the initial context</li>
<li><p>
Returns 0 for the 0-valued context
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_previous</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="orgbc3ad1a"></a>Source<br />
<div class="outline-text-6" id="text-2-3-1-6-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_previous</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #a020f0;">return</span> qmckl_context_check((<span style="color: #228b22;">qmckl_context</span>) ctx-&gt;prev);
}
</pre>
</div>
</div>
</li>
<li><a id="org304605b"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-1-6-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_previous</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_previous</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org1bc8a39"></a><code>qmckl_context_destroy</code><br />
<div class="outline-text-5" id="text-2-3-1-7">
<p>
Destroys the current context, leaving the ancestors untouched.
</p>
<ul class="org-ul">
<li>Succeeds if the current context is properly destroyed</li>
<li>Fails otherwise</li>
<li>Fails if the 0-valued context is given in argument</li>
<li>Fails if the the pointer is not a valid context</li>
</ul>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_destroy</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgd8f8704"></a>Source<br />
<div class="outline-text-6" id="text-2-3-1-7-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_destroy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;tag = INVALID_TAG;
qmckl_free(ctx);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org1a7b794"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-1-7-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_destroy</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_destroy</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-org354ee46" class="outline-4">
<h4 id="org354ee46"><span class="section-number-4">2.3.2</span> Basis set</h4>
<div class="outline-text-4" id="text-2-3-2">
<p>
For H<sub>2</sub> with the following basis set,
</p>
<pre class="example">
HYDROGEN
S 5
1 3.387000E+01 6.068000E-03
2 5.095000E+00 4.530800E-02
3 1.159000E+00 2.028220E-01
4 3.258000E-01 5.039030E-01
5 1.027000E-01 3.834210E-01
S 1
1 3.258000E-01 1.000000E+00
S 1
1 1.027000E-01 1.000000E+00
P 1
1 1.407000E+00 1.000000E+00
P 1
1 3.880000E-01 1.000000E+00
D 1
1 1.057000E+00 1.0000000
</pre>
<p>
we have:
</p>
<pre class="example">
type = 'G'
shell_num = 12
prim_num = 20
SHELL_CENTER = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
SHELL_ANG_MOM = ['S', 'S', 'S', 'P', 'P', 'D', 'S', 'S', 'S', 'P', 'P', 'D']
SHELL_PRIM_NUM = [5, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1]
prim_index = [1, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20]
EXPONENT = [ 33.87, 5.095, 1.159, 0.3258, 0.1027, 0.3258, 0.1027,
1.407, 0.388, 1.057, 33.87, 5.095, 1.159, 0.3258, 0.1027,
0.3258, 0.1027, 1.407, 0.388, 1.057]
COEFFICIENT = [ 0.006068, 0.045308, 0.202822, 0.503903, 0.383421,
1.0, 1.0, 1.0, 1.0, 1.0, 0.006068, 0.045308, 0.202822,
0.503903, 0.383421, 1.0, 1.0, 1.0, 1.0, 1.0]
</pre>
</div>
<ol class="org-ol">
<li><a id="org76121f7"></a><code>qmckl_context_update_ao_basis</code><br />
<div class="outline-text-5" id="text-2-3-2-1">
<p>
Updates the data describing the AO basis set into the context.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org18a8eae"></a>Source<br />
<div class="outline-text-6" id="text-2-3-2-1-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">i</span>;
/* <span style="color: #b22222;">Check input </span>*/
<span style="color: #a020f0;">if</span> (type != <span style="color: #8b2252;">'G'</span> &amp;&amp; type != <span style="color: #8b2252;">'S'</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (shell_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt; shell_num) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
<span style="color: #a020f0;">if</span> (SHELL_CENTER[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_NUM[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_ANG_MOM[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_INDEX[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
<span style="color: #a020f0;">if</span> (EXPONENT[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_ao_basis_struct</span>* <span style="color: #a0522d;">basis</span> = (<span style="color: #228b22;">qmckl_ao_basis_struct</span>*) malloc (<span style="color: #a020f0;">sizeof</span>(qmckl_ao_basis_struct));
<span style="color: #a020f0;">if</span> (basis == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
/* <span style="color: #b22222;">Memory allocations </span>*/
basis-&gt;shell_center = (<span style="color: #228b22;">int64_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_center == <span style="color: #008b8b;">NULL</span>) {
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_ang_mom = (<span style="color: #228b22;">int32_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int32_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_ang_mom == <span style="color: #008b8b;">NULL</span>) {
free(basis-&gt;shell_center);
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_prim_num= (<span style="color: #228b22;">int64_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_prim_num == <span style="color: #008b8b;">NULL</span>) {
free(basis-&gt;shell_ang_mom);
free(basis-&gt;shell_center);
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_factor = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_factor == <span style="color: #008b8b;">NULL</span>) {
free(basis-&gt;shell_prim_num);
free(basis-&gt;shell_ang_mom);
free(basis-&gt;shell_center);
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;exponent = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;exponent == <span style="color: #008b8b;">NULL</span>) {
free(basis-&gt;shell_factor);
free(basis-&gt;shell_prim_num);
free(basis-&gt;shell_ang_mom);
free(basis-&gt;shell_center);
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;coefficient = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;coefficient == <span style="color: #008b8b;">NULL</span>) {
free(basis-&gt;exponent);
free(basis-&gt;shell_factor);
free(basis-&gt;shell_prim_num);
free(basis-&gt;shell_ang_mom);
free(basis-&gt;shell_center);
free(basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
/* <span style="color: #b22222;">Assign data </span>*/
basis-&gt;type = type;
basis-&gt;shell_num = shell_num;
basis-&gt;prim_num = prim_num;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
basis-&gt;shell_center [i] = SHELL_CENTER [i];
basis-&gt;shell_ang_mom [i] = SHELL_ANG_MOM [i];
basis-&gt;shell_prim_num[i] = SHELL_PRIM_NUM[i];
basis-&gt;shell_factor [i] = SHELL_FACTOR [i];
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
basis-&gt;exponent [i] = EXPONENT[i];
basis-&gt;coefficient[i] = COEFFICIENT[i];
}
ctx-&gt;ao_basis = basis;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org78a3ca6"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-2-1-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>)<span style="color: #a0522d;"> function qmckl_context_update_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> shell_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> prim_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_CENTER(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_NUM(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
<li><a id="orgd644733"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
<li><a id="org0b9f000"></a><code>qmckl_context_set_ao_basis</code><br />
<div class="outline-text-5" id="text-2-3-2-2">
<p>
Sets the data describing the AO basis set into the context.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgeab5ed0"></a>Source<br />
<div class="outline-text-6" id="text-2-3-2-2-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_ao_basis(context, type, shell_num, prim_num,
SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR,
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT,
COEFFICIENT
) == QMCKL_FAILURE)
<span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="org311906a"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-2-2-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>)<span style="color: #a0522d;"> function qmckl_context_set_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> shell_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> prim_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_CENTER(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_NUM(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_set_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
<li><a id="org612d721"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-orgcc5fd18" class="outline-4">
<h4 id="orgcc5fd18"><span class="section-number-4">2.3.3</span> Precision</h4>
<div class="outline-text-4" id="text-2-3-3">
<p>
The following functions set and get the expected required
precision and range. <code>precision</code> should be an integer between 2
and 53, and <code>range</code> should be an integer between 2 and 11.
</p>
<p>
The setter functions functions return a new context as a 64-bit
integer. The getter functions return the value, as a 32-bit
integer. The update functions return <code>QMCKL_SUCCESS</code> or
<code>QMCKL_FAILURE</code>.
</p>
</div>
<ol class="org-ol">
<li><a id="org931d529"></a><code>qmckl_context_update_precision</code><br />
<div class="outline-text-5" id="text-2-3-3-1">
<p>
Modifies the parameter for the numerical precision in a given context.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgdddbfb5"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-1-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>) {
<span style="color: #a020f0;">if</span> (precision &lt; 2) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (precision &gt; 53) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;precision = precision;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org05e8ba0"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-1-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>(context, precision) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> precision</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org17bf1b7"></a><code>qmckl_context_update_range</code><br />
<div class="outline-text-5" id="text-2-3-3-2">
<p>
Modifies the parameter for the numerical range in a given context.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org0fa958f"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-2-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>) {
<span style="color: #a020f0;">if</span> (range &lt; 2) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (range &gt; 11) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;range = range;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="orgca10a74"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-2-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_update_range</span>(context, range) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> range</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgdf9f2e5"></a><code>qmckl_context_set_precision</code><br />
<div class="outline-text-5" id="text-2-3-3-3">
<p>
Returns a copy of the context with a different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org073d783"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-3-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>) {
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_precision(context, precision) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="orgba2a2d6"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-3-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_set_precision</span>(context, precision) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> precision</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_set_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org9675601"></a><code>qmckl_context_set_range</code><br />
<div class="outline-text-5" id="text-2-3-3-4">
<p>
Returns a copy of the context with a different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org3796bbf"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-4-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>) {
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_range(context, range) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="org2f5dda8"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-4-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_set_range</span>(context, range) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> range</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_set_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgb2f9fb6"></a><code>qmckl_context_get_precision</code><br />
<div class="outline-text-5" id="text-2-3-3-5">
<p>
Returns the value of the numerical precision in the context
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int32_t</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgc1ce9d6"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-5-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> ctx-&gt;precision;
}
</pre>
</div>
</div>
</li>
<li><a id="orgae083be"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-5-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgabec8a4"></a><code>qmckl_context_get_range</code><br />
<div class="outline-text-5" id="text-2-3-3-6">
<p>
Returns the value of the numerical range in the context
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int32_t</span> <span style="color: #0000ff;">qmckl_context_get_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgc38a64d"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-6-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> ctx-&gt;range;
}
</pre>
</div>
</div>
</li>
<li><a id="orga8de72f"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-6-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_get_range</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgaec57a3"></a><code>qmckl_context_get_epsilon</code><br />
<div class="outline-text-5" id="text-2-3-3-7">
<p>
Returns \(\epsilon = 2^{1-n}\) where <code>n</code> is the precision
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org9ee7432"></a>Source<br />
<div class="outline-text-6" id="text-2-3-3-7-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> pow(2.0,(<span style="color: #228b22;">double</span>) 1-ctx-&gt;precision);
}
</pre>
</div>
</div>
</li>
<li><a id="org9493397"></a>Fortran interface<br />
<div class="outline-text-6" id="text-2-3-3-7-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">real</span> (<span style="color: #008b8b;">c_double</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
</div>
<div id="outline-container-orga3e42f5" class="outline-3">
<h3 id="orga3e42f5"><span class="section-number-3">2.4</span> Computation of distances</h3>
<div class="outline-text-3" id="text-2-4">
<p>
Function for the computation of distances between particles.
</p>
<p>
3 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_distance.f90</code></li>
<li>a C test file : <code>test_qmckl_distance.c</code></li>
<li>a Fortran test file : <code>test_qmckl_distance_f.f90</code></li>
</ul>
</div>
<div id="outline-container-orgcab1734" class="outline-4">
<h4 id="orgcab1734"><span class="section-number-4">2.4.1</span> Squared distance</h4>
<div class="outline-text-4" id="text-2-4-1">
</div>
<ol class="org-ol">
<li><a id="org2945678"></a><code>qmckl_distance_sq</code><br />
<div class="outline-text-5" id="text-2-4-1-1">
<p>
Computes the matrix of the squared distances between all pairs of
points in two sets, one point within each set:
\[
C_{ij} = \sum_{k=1}^3 (A_{k,i}-B_{k,j})^2
\]
</p>
</div>
<ol class="org-ol">
<li><a id="orga756bfd"></a>Arguments<br />
<div class="outline-text-6" id="text-2-4-1-1-1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>transa</code></td>
<td class="org-left">input</td>
<td class="org-left">Array <code>A</code> is <code>N</code>: Normal, <code>T</code>: Transposed</td>
</tr>
<tr>
<td class="org-left"><code>transb</code></td>
<td class="org-left">input</td>
<td class="org-left">Array <code>B</code> is <code>N</code>: Normal, <code>T</code>: Transposed</td>
</tr>
<tr>
<td class="org-left"><code>m</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of points in the first set</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of points in the second set</td>
</tr>
<tr>
<td class="org-left"><code>A(lda,3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the \(m \times 3\) matrix \(A\)</td>
</tr>
<tr>
<td class="org-left"><code>lda</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>A</code></td>
</tr>
<tr>
<td class="org-left"><code>B(ldb,3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the \(n \times 3\) matrix \(B\)</td>
</tr>
<tr>
<td class="org-left"><code>ldb</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>B</code></td>
</tr>
<tr>
<td class="org-left"><code>C(ldc,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Array containing the \(m \times n\) matrix \(C\)</td>
</tr>
<tr>
<td class="org-left"><code>ldc</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>C</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org36f2947"></a>Requirements<br />
<div class="outline-text-6" id="text-2-4-1-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>m</code> &gt; 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>lda</code> &gt;= 3 if <code>transa</code> is <code>N</code></li>
<li><code>lda</code> &gt;= m if <code>transa</code> is <code>T</code></li>
<li><code>ldb</code> &gt;= 3 if <code>transb</code> is <code>N</code></li>
<li><code>ldb</code> &gt;= n if <code>transb</code> is <code>T</code></li>
<li><code>ldc</code> &gt;= m</li>
<li><code>A</code> is allocated with at least \(3 \times m \times 8\) bytes</li>
<li><code>B</code> is allocated with at least \(3 \times n \times 8\) bytes</li>
<li><code>C</code> is allocated with at least \(m \times n \times 8\) bytes</li>
</ul>
</div>
</li>
<li><a id="orgfd638fe"></a>Performance<br />
<div class="outline-text-6" id="text-2-4-1-1-3">
<p>
This function might be more efficient when <code>A</code> and <code>B</code> are
transposed.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_distance_sq</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">transa</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">transb</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">m</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">A</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">lda</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">B</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldb</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">C</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldc</span>);
</pre>
</div>
</div>
</li>
<li><a id="org3cbdca8"></a>Source<br />
<div class="outline-text-6" id="text-2-4-1-1-4">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">qmckl_distance_sq_f</span><span style="color: #000000; background-color: #ffffff;">(context, transa, transb, m, n, A, LDA, B, LDB, C, LDC) result(info)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">character</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> transa, transb</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> m, n</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> lda</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> A(lda,*)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldb</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> B(ldb,*)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldc</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> C(ldc,*)</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> x, y, z</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> transab</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (m &lt;= 0_8) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (n &lt;= 0_8) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transa == <span style="color: #8b2252;">'N'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'n'</span>) <span style="color: #a020f0;">then</span>
transab = 0
<span style="color: #a020f0;">else if</span> (transa == <span style="color: #8b2252;">'T'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'t'</span>) <span style="color: #a020f0;">then</span>
transab = 1
<span style="color: #a020f0;">else</span>
transab = -100
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transb == <span style="color: #8b2252;">'N'</span> <span style="color: #a020f0;">.or.</span> transb == <span style="color: #8b2252;">'n'</span>) <span style="color: #a020f0;">then</span>
<span style="color: #a020f0;">continue</span>
<span style="color: #a020f0;">else if</span> (transa == <span style="color: #8b2252;">'T'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'t'</span>) <span style="color: #a020f0;">then</span>
transab = transab + 2
<span style="color: #a020f0;">else</span>
transab = -100
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transab &lt; 0) <span style="color: #a020f0;">then</span>
info = -4
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,1) == 0 <span style="color: #a020f0;">.and.</span> LDA &lt; 3) <span style="color: #a020f0;">then</span>
info = -5
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,1) == 1 <span style="color: #a020f0;">.and.</span> LDA &lt; m) <span style="color: #a020f0;">then</span>
info = -6
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,2) == 0 <span style="color: #a020f0;">.and.</span> LDA &lt; 3) <span style="color: #a020f0;">then</span>
info = -6
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,2) == 2 <span style="color: #a020f0;">.and.</span> LDA &lt; m) <span style="color: #a020f0;">then</span>
info = -7
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">select case</span> (transab)
<span style="color: #a020f0;">case</span>(0)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(1,i) - B(1,j)
y = A(2,i) - B(2,j)
z = A(3,i) - B(3,j)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(1)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(i,1) - B(1,j)
y = A(i,2) - B(2,j)
z = A(i,3) - B(3,j)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(2)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(1,i) - B(j,1)
y = A(2,i) - B(j,2)
z = A(3,i) - B(j,3)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(3)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(i,1) - B(j,1)
y = A(i,2) - B(j,2)
z = A(i,3) - B(j,3)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end select</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_distance_sq_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
</div>
<div id="outline-container-org031a382" class="outline-3">
<h3 id="org031a382"><span class="section-number-3">2.5</span> Atomic Orbitals</h3>
<div class="outline-text-3" id="text-2-5">
<p>
This files contains all the routines for the computation of the
values, gradients and Laplacian of the atomic basis functions.
</p>
<p>
3 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_ao.f90</code></li>
<li>a C test file : <code>test_qmckl_ao.c</code></li>
<li>a Fortran test file : <code>test_qmckl_ao_f.f90</code></li>
</ul>
</div>
<div id="outline-container-org8371761" class="outline-4">
<h4 id="org8371761"><span class="section-number-4">2.5.1</span> Polynomials</h4>
<div class="outline-text-4" id="text-2-5-1">
<p>
\[
P_l(\mathbf{r},\mathbf{R}_i) = (x-X_i)^a (y-Y_i)^b (z-Z_i)^c
\]
</p>
\begin{eqnarray*}
\frac{\partial }{\partial x} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & a (x-X_i)^{a-1} (y-Y_i)^b (z-Z_i)^c \\
\frac{\partial }{\partial y} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & b (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c \\
\frac{\partial }{\partial z} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & c (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1} \\
\end{eqnarray*}
\begin{eqnarray*}
\left( \frac{\partial }{\partial x^2} +
\frac{\partial }{\partial y^2} +
\frac{\partial }{\partial z^2} \right) P_l
\left(\mathbf{r},\mathbf{R}_i \right) & = &
a(a-1) (x-X_i)^{a-2} (y-Y_i)^b (z-Z_i)^c + \\
&& b(b-1) (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c + \\
&& c(c-1) (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1}
\end{eqnarray*}
</div>
<ol class="org-ol">
<li><a id="org241ea72"></a><code>qmckl_ao_power</code><br />
<div class="outline-text-5" id="text-2-5-1-1">
<p>
Computes all the powers of the <code>n</code> input data up to the given
maximum value given in input for each of the \(n\) points:
</p>
<p>
\[ P_{ij} = X_j^i \]
</p>
</div>
<ol class="org-ol">
<li><a id="org378ed91"></a>Arguments<br />
<div class="outline-text-6" id="text-2-5-1-1-1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of values</td>
</tr>
<tr>
<td class="org-left"><code>X(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the input values</td>
</tr>
<tr>
<td class="org-left"><code>LMAX(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the maximum power for each value</td>
</tr>
<tr>
<td class="org-left"><code>P(LDP,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Array containing all the powers of <code>X</code></td>
</tr>
<tr>
<td class="org-left"><code>LDP</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>P</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org10cd8ef"></a>Requirements<br />
<div class="outline-text-6" id="text-2-5-1-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>X</code> is allocated with at least \(n \times 8\) bytes</li>
<li><code>LMAX</code> is allocated with at least \(n \times 4\) bytes</li>
<li><code>P</code> is allocated with at least \(n \times \max_i \text{LMAX}_i \times 8\) bytes</li>
<li><code>LDP</code> &gt;= \(\max_i\) <code>LMAX[i]</code></li>
</ul>
</div>
</li>
<li><a id="org2448618"></a>Header<br />
<div class="outline-text-6" id="text-2-5-1-1-3">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_power</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> *<span style="color: #a0522d;">LMAX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">P</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">LDP</span>);
</pre>
</div>
</div>
</li>
<li><a id="org91eb46a"></a>Source<br />
<div class="outline-text-6" id="text-2-5-1-1-4">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">qmckl_ao_power_f</span><span style="color: #000000; background-color: #ffffff;">(context, n, X, LMAX, P, ldp) result(info)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(n)</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> LMAX(n)</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> P(ldp,n)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldp</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (LDP &lt; <span style="color: #a020f0;">MAXVAL</span>(LMAX)) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> j=1,n
P(1,j) = X(j)
<span style="color: #a020f0;">do</span> i=2,LMAX(j)
P(i,j) = P(i-1,j) * X(j)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_power_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org5b60793"></a><code>qmckl_ao_polynomial_vgl</code><br />
<div class="outline-text-5" id="text-2-5-1-2">
<p>
Computes the values, gradients and Laplacians at a given point of
all polynomials with an angular momentum up to <code>lmax</code>.
</p>
</div>
<ol class="org-ol">
<li><a id="org4f2dc8b"></a>Arguments<br />
<div class="outline-text-6" id="text-2-5-1-2-1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>X(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the coordinates of the points</td>
</tr>
<tr>
<td class="org-left"><code>R(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the x,y,z coordinates of the center</td>
</tr>
<tr>
<td class="org-left"><code>lmax</code></td>
<td class="org-left">input</td>
<td class="org-left">Maximum angular momentum</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">output</td>
<td class="org-left">Number of computed polynomials</td>
</tr>
<tr>
<td class="org-left"><code>L(ldl,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Contains a,b,c for all <code>n</code> results</td>
</tr>
<tr>
<td class="org-left"><code>ldl</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of <code>L</code></td>
</tr>
<tr>
<td class="org-left"><code>VGL(ldv,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Value, gradients and Laplacian of the polynomials</td>
</tr>
<tr>
<td class="org-left"><code>ldv</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>VGL</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org7fd5a2b"></a>Requirements<br />
<div class="outline-text-6" id="text-2-5-1-2-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>lmax</code> &gt;= 0</li>
<li><code>ldl</code> &gt;= 3</li>
<li><code>ldv</code> &gt;= 5</li>
<li><code>X</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>R</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>n</code> &gt;= <code>(lmax+1)(lmax+2)(lmax+3)/6</code></li>
<li><code>L</code> is allocated with at least \(3 \times n \times 4\) bytes</li>
<li><code>VGL</code> is allocated with at least \(5 \times n \times 8\) bytes</li>
<li>On output, <code>n</code> should be equal to <code>(lmax+1)(lmax+2)(lmax+3)/6</code></li>
<li>On output, the powers are given in the following order (l=a+b+c):
<ul class="org-ul">
<li>Increase values of <code>l</code></li>
<li>Within a given value of <code>l</code>, alphabetical order of the
string made by a*"x" + b*"y" + c*"z" (in Python notation).
For example, with a=0, b=2 and c=1 the string is "yyz"</li>
</ul></li>
</ul>
</div>
</li>
<li><a id="orgbc83356"></a>Error codes<br />
<div class="outline-text-6" id="text-2-5-1-2-3">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-right">-1</td>
<td class="org-left">Null context</td>
</tr>
<tr>
<td class="org-right">-2</td>
<td class="org-left">Inconsistent <code>ldl</code></td>
</tr>
<tr>
<td class="org-right">-3</td>
<td class="org-left">Inconsistent <code>ldv</code></td>
</tr>
<tr>
<td class="org-right">-4</td>
<td class="org-left">Inconsistent <code>lmax</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org9c9875e"></a>Header<br />
<div class="outline-text-6" id="text-2-5-1-2-4">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_polynomial_vgl</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">R</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">lmax</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> *<span style="color: #a0522d;">L</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldl</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">VGL</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldv</span>);
</pre>
</div>
</div>
</li>
<li><a id="orgcc63e8f"></a>Source<br />
<div class="outline-text-6" id="text-2-5-1-2-5">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">qmckl_ao_polynomial_vgl_f</span><span style="color: #000000; background-color: #ffffff;">(context, X, R, lmax, n, L, ldl, VGL, ldv) result(info)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(3), R(3)</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> lmax</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> L(ldl,(lmax+1)*(lmax+2)*(lmax+3)/6)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldl</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> VGL(ldv,(lmax+1)*(lmax+2)*(lmax+3)/6)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldv</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> a,b,c,d</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> Y(3)</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> lmax_array(3)</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> pows(-2:lmax,3)</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">external</span> ::<span style="color: #a0522d;"> qmckl_ao_power_f</span>
<span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> xy, yz, xz</span>
<span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> da, db, dc, dd</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldl &lt; 3) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldv &lt; 5) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (lmax &lt;= 0) <span style="color: #a020f0;">then</span>
info = -4
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> i=1,3
Y(i) = X(i) - R(i)
<span style="color: #a020f0;">end do</span>
lmax_array(1:3) = lmax
<span style="color: #a020f0;">if</span> (lmax == 0) <span style="color: #a020f0;">then</span>
VGL(1,1) = 1.d0
vgL(2:5,1) = 0.d0
l(1:3,1) = 0
n=1
<span style="color: #a020f0;">else if</span> (lmax &gt; 0) <span style="color: #a020f0;">then</span>
pows(-2:0,1:3) = 1.d0
<span style="color: #a020f0;">do</span> i=1,lmax
pows(i,1) = pows(i-1,1) * Y(1)
pows(i,2) = pows(i-1,2) * Y(2)
pows(i,3) = pows(i-1,3) * Y(3)
<span style="color: #a020f0;">end do</span>
VGL(1:5,1:4) = 0.d0
l(1:3,1:4) = 0
VGL(1,1) = 1.d0
vgl(1:5,2:4) = 0.d0
l(1,2) = 1
vgl(1,2) = pows(1,1)
vgL(2,2) = 1.d0
l(2,3) = 1
vgl(1,3) = pows(1,2)
vgL(3,3) = 1.d0
l(3,4) = 1
vgl(1,4) = pows(1,3)
vgL(4,4) = 1.d0
n=4
<span style="color: #a020f0;">endif</span>
! <span style="color: #b22222;">l&gt;=2</span>
dd = 2.d0
<span style="color: #a020f0;">do</span> d=2,lmax
da = dd
<span style="color: #a020f0;">do</span> a=d,0,-1
db = dd-da
<span style="color: #a020f0;">do</span> b=d-a,0,-1
c = d - a - b
dc = dd - da - db
n = n+1
l(1,n) = a
l(2,n) = b
l(3,n) = c
xy = pows(a,1) * pows(b,2)
yz = pows(b,2) * pows(c,3)
xz = pows(a,1) * pows(c,3)
vgl(1,n) = xy * pows(c,3)
xy = dc * xy
xz = db * xz
yz = da * yz
vgl(2,n) = pows(a-1,1) * yz
vgl(3,n) = pows(b-1,2) * xz
vgl(4,n) = pows(c-1,3) * xy
vgl(5,n) = <span style="color: #a020f0;">&amp;</span>
(da-1.d0) * pows(a-2,1) * yz + <span style="color: #a020f0;">&amp;</span>
(db-1.d0) * pows(b-2,2) * xz + <span style="color: #a020f0;">&amp;</span>
(dc-1.d0) * pows(c-2,3) * xy
db = db - 1.d0
<span style="color: #a020f0;">end do</span>
da = da - 1.d0
<span style="color: #a020f0;">end do</span>
dd = dd + 1.d0
<span style="color: #a020f0;">end do</span>
info = 0
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_polynomial_vgl_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-org859d9a6" class="outline-4">
<h4 id="org859d9a6"><span class="section-number-4">2.5.2</span> Gaussian basis functions</h4>
<div class="outline-text-4" id="text-2-5-2">
</div>
<ol class="org-ol">
<li><a id="orgd8c71e4"></a><code>qmckl_ao_gaussian_vgl</code><br />
<div class="outline-text-5" id="text-2-5-2-1">
<p>
Computes the values, gradients and Laplacians at a given point of
<code>n</code> Gaussian functions centered at the same point:
</p>
<p>
\[ v_i = exp(-a_i |X-R|^2) \]
\[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \]
\[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \]
\[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \]
\[ \Delta v_i = a_i (4 |X-R|^2 a_i - 6) v_i \]
</p>
</div>
<ol class="org-ol">
<li><a id="orga0de829"></a>Arguments<br />
<div class="outline-text-6" id="text-2-5-2-1-1">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>X(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the coordinates of the points</td>
</tr>
<tr>
<td class="org-left"><code>R(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the x,y,z coordinates of the center</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of computed gaussians</td>
</tr>
<tr>
<td class="org-left"><code>A(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Exponents of the Gaussians</td>
</tr>
<tr>
<td class="org-left"><code>VGL(ldv,5)</code></td>
<td class="org-left">output</td>
<td class="org-left">Value, gradients and Laplacian of the Gaussians</td>
</tr>
<tr>
<td class="org-left"><code>ldv</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>VGL</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="orge2f3715"></a>Requirements<br />
<div class="outline-text-6" id="text-2-5-2-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>ldv</code> &gt;= 5</li>
<li><code>A(i)</code> &gt; 0 for all <code>i</code></li>
<li><code>X</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>R</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>A</code> is allocated with at least \(n \times 8\) bytes</li>
<li><code>VGL</code> is allocated with at least \(n \times 5 \times 8\) bytes</li>
</ul>
</div>
</li>
<li><a id="org125eaac"></a>Header<br />
<div class="outline-text-6" id="text-2-5-2-1-3">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_gaussian_vgl</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">R</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">n</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">A</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">VGL</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldv</span>);
</pre>
</div>
</div>
</li>
<li><a id="org846db81"></a>Source<br />
<div class="outline-text-6" id="text-2-5-2-1-4">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">qmckl_ao_gaussian_vgl_f</span><span style="color: #000000; background-color: #ffffff;">(context, X, R, n, A, VGL, ldv) result(info)</span>
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(3), R(3)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> A(n)</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> VGL(ldv,5)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldv</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> Y(3), r2, t, u, v</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (n &lt;= 0) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldv &lt; n) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> i=1,3
Y(i) = X(i) - R(i)
<span style="color: #a020f0;">end do</span>
r2 = Y(1)*Y(1) + Y(2)*Y(2) + Y(3)*Y(3)
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,1) = dexp(-A(i) * r2)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,5) = A(i) * VGL(i,1)
<span style="color: #a020f0;">end do</span>
t = -2.d0 * ( X(1) - R(1) )
u = -2.d0 * ( X(2) - R(2) )
v = -2.d0 * ( X(3) - R(3) )
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,2) = t * VGL(i,5)
VGL(i,3) = u * VGL(i,5)
VGL(i,4) = v * VGL(i,5)
<span style="color: #a020f0;">end do</span>
t = 4.d0 * r2
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,5) = (t * A(i) - 6.d0) * VGL(i,5)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_gaussian_vgl_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-org00a5e37" class="outline-4">
<h4 id="org00a5e37"><span class="section-number-4">2.5.3</span> <span class="todo TODO">TODO</span> Slater basis functions</h4>
</div>
</div>
</div>
<div id="outline-container-org3732fa8" class="outline-2">
<h2 id="org3732fa8"><span class="section-number-2">3</span> Acknowledgments</h2>
<div class="outline-text-2" id="text-3">
<p>
<img src="https://trex-coe.eu/sites/default/files/inline-images/euflag.jpg" alt="euflag.jpg" />
<a href="https://trex-coe.eu">TREX: Targeting Real Chemical Accuracy at the Exascale</a> project has received funding from the European Unions Horizon 2020 - Research and Innovation program - under grant agreement no. 952165. The content of this document does not represent the opinion of the European Union, and the European Union is not responsible for any use that might be made of such content.
</p>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Created: 2020-12-03 Thu 18:00</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>