-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPython_cppyy_interface.html
168 lines (166 loc) · 12.2 KB
/
Python_cppyy_interface.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<title>G+Smo: Python via cppyy</title>
<link href="gismodoxy_tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://people.ricam.oeaw.ac.at/gismo/mj/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="gismodoxy.css" rel="stylesheet" type="text/css">
<!-- -->
<!-- <script type="text/javascript"> -->
<!-- </script> -->
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!-- <a name="top"></a> -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="gslogo-doxy.jpg"/></td>
<td style="padding-left: 0.5em;">
<div id="projectname"><a href="index.html"><font style="font-variant:small-caps;">G+S</font><font style="font-variant:small-caps;"
color="#000000">mo</font></a>
 <span id="projectnumber">25.01.0</span>
</div>
<div id="projectbrief">Geometry + Simulation Modules</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
<input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function(){initNavTree('Python_cppyy_interface.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Python via cppyy</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <a href="https://cppyy.readthedocs.io/en/latest/">cppyy</a>-bindings are generated at runtime based on just-in-time compilation. For using G+Smo this is useful, since the bilinear forms are usually assembled using the expression assembler. Since <a class="el" href="classgismo_1_1gsExprAssembler.html">gismo::gsExprAssembler</a> is based on templated expressions, its assembly method can only be compiled once the bilinear form has been defined, which makes precompiled bindings impossible unless we restrict the available bilinear forms. Cppyy's just-in-time compilation solves this problem.</p>
<h3>Configuration</h3>
<p>Configure G+Smo with the options <code>-DGISMO_WITH_CPPYY=On -DCMAKE_CXX_STANDARD=20</code>. This creates the Python package <code>gismo_cppyy</code> in the subdirectory <code>cppyy</code> of your build folder.</p>
<p>Then, build the <code>gismo</code> library as usual.</p>
<p>Run <code>make wheel</code> in order to generate the pip wheel in <code>cppyy/dist</code>. It can be installed with <code>make install-bindings</code> or directly using <code>pip</code>.</p>
<p>The package looks for the G+Smo sources in the source directory and for the shared library in the build directory. This means that these directories need to stay in place.</p>
<h3>Usage</h3>
<p>The bindings can be imported in Python using </p><div class="fragment"><div class="line"><span class="keyword">from</span> gismo_cppyy <span class="keyword">import</span> gismo</div>
</div><!-- fragment --><p> All classes and functions from G+Smo can be found in the <code>gismo</code> namespace, templates are resolved using brackets containing either a string or a Python type. For example, you can access the expression assembler using </p><div class="fragment"><div class="line">A = <a class="code hl_class" href="classgismo_1_1gsExprAssembler.html">gismo.gsExprAssembler</a>[<span class="stringliteral">"real_t"</span>]()</div>
<div class="ttc" id="aclassgismo_1_1gsExprAssembler_html"><div class="ttname"><a href="classgismo_1_1gsExprAssembler.html">gismo::gsExprAssembler</a></div><div class="ttdef"><b>Definition</b> gsExprAssembler.h:33</div></div>
</div><!-- fragment --><p> and, after defining the spaces and variables, assemble the matrix using </p><div class="fragment"><div class="line">A.assemble(gismo.expr.igrad(u, G) * gismo.expr.igrad(u, G).tr() * <a class="code hl_function" href="namespacegismo_1_1expr.html#a37e91c8b6c3efac383e28a3cb2b5f092">gismo.expr.meas</a>(G), u * ff * <a class="code hl_function" href="namespacegismo_1_1expr.html#a37e91c8b6c3efac383e28a3cb2b5f092">gismo.expr.meas</a>(G))</div>
<div class="ttc" id="anamespacegismo_1_1expr_html_a37e91c8b6c3efac383e28a3cb2b5f092"><div class="ttname"><a href="namespacegismo_1_1expr.html#a37e91c8b6c3efac383e28a3cb2b5f092">gismo::expr::meas</a></div><div class="ttdeci">EIGEN_STRONG_INLINE meas_expr< T > meas(const gsGeometryMap< T > &G)</div><div class="ttdoc">The measure of a geometry map.</div><div class="ttdef"><b>Definition</b> gsExpressions.h:4555</div></div>
</div><!-- fragment --><p> just as in C++. Before evaluating the <code>assemble()</code> method, the just-in-time compiler will compile the templated method </p><div class="fragment"><div class="line"><span class="keyword">template</span><<span class="keyword">class</span>... expr> <span class="keywordtype">void</span> assemble(<span class="keyword">const</span> expr &... args);</div>
</div><!-- fragment --><p> of <a class="el" href="classgismo_1_1gsExprAssembler.html">gismo::gsExprAssembler</a> for the employed expressions.</p>
<p>An example for solving the Poisson equation can be found in <code>python_examples/poisson_example_cppyy.py</code>. An additional example for adaptive fitting using THB-splines is in <code>python_examples/fitting_example_cppyy.py</code>.</p>
<h3>Numpy compatibility</h3>
<p>Data can be exchanged with numpy by converting numpy arrays into gismo objects and vice versa. The conversion from gismo objects to numpy arrays is done using the method <code>tonumpy()</code> of <a class="el" href="classgismo_1_1gsVector.html" title="A vector with arbitrary coefficient type and fixed or dynamic size.">gismo.gsVector</a>, <a class="el" href="classgismo_1_1gsMatrix.html" title="A matrix with arbitrary coefficient type and fixed or dynamic size.">gismo.gsMatrix</a> and <a class="el" href="classgismo_1_1gsAsMatrix.html" title="Creates a mapped object or data pointer to a matrix without copying data.">gismo.gsAsMatrix</a>. The class method <code>fromnumpy()</code> of these classes constructs a gismo object from a numpy array.</p>
<p>For example, you can run </p><div class="fragment"><div class="line">>>> <span class="keyword">from</span> gismo_cppyy <span class="keyword">import</span> gismo</div>
<div class="line">>>> <span class="keyword">import</span> numpy <span class="keyword">as</span> np</div>
<div class="line">>>> a = np.array([[1,0],[0,1]], dtype=np.double)</div>
<div class="line">>>> A = <a class="code hl_class" href="classgismo_1_1gsMatrix.html">gismo.gsMatrix</a>[<span class="stringliteral">"double"</span>].fromnumpy(a)</div>
<div class="line">>>> b = A.tonumpy()</div>
<div class="line">>>> B = <a class="code hl_class" href="classgismo_1_1gsAsMatrix.html">gismo.gsAsMatrix</a>[<span class="stringliteral">"double"</span>].fromnumpy(b)</div>
<div class="ttc" id="aclassgismo_1_1gsAsMatrix_html"><div class="ttname"><a href="classgismo_1_1gsAsMatrix.html">gismo::gsAsMatrix</a></div><div class="ttdoc">Creates a mapped object or data pointer to a matrix without copying data.</div><div class="ttdef"><b>Definition</b> gsAsMatrix.h:32</div></div>
<div class="ttc" id="aclassgismo_1_1gsMatrix_html"><div class="ttname"><a href="classgismo_1_1gsMatrix.html">gismo::gsMatrix</a></div><div class="ttdoc">A matrix with arbitrary coefficient type and fixed or dynamic size.</div><div class="ttdef"><b>Definition</b> gsMatrix.h:41</div></div>
</div><!-- fragment --><p>Note that <code><a class="el" href="classgismo_1_1gsMatrix.html" title="A matrix with arbitrary coefficient type and fixed or dynamic size.">gismo.gsMatrix</a>["double"].fromnumpy()</code> copies the underlying data, while <code><a class="el" href="classgismo_1_1gsAsMatrix.html" title="Creates a mapped object or data pointer to a matrix without copying data.">gismo.gsAsMatrix</a>["double"].fromnumpy()</code> does not. <code>tonumpy()</code> never copies the data.</p>
<h3>Further information and examples</h3>
<dl class="todo"><dt><b><a class="el" href="todo.html#_todo000023">Todo:</a></b></dt><dd>@felixfeliz</dd></dl>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Mon Jan 20 2025 09:35:27 for G+Smo by Doxygen v1.9.8 </li>
</ul>
</div>
<!-- Piwik -->
<!--
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://stats.sylphide-consulting.com/piwik/" : "http://stats.sylphide-consulting.com/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 20);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://stats.sylphide-consulting.com/piwik/piwik.php?idsite=20" style="border:0" alt="" /></p></noscript>
-->
<!-- End Piwik Tracking Code -->
</body>
</html>