-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTutorial01.html
546 lines (542 loc) · 65 KB
/
Tutorial01.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<!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.10.0"/>
<title>G+Smo: Tutorial 01: Hello G+Smo</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>
<script type="text/javascript" src="cookie.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 */
$(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.10.0 -->
<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 */
$(function(){initNavTree('Tutorial01.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">Tutorial 01: Hello G+Smo</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>In this tutorial you will get to know the structure of the library, some main tools which are available as well as how to write your first program.</p>
<h1><a class="anchor" id="Folder01"></a>
Code repository</h1>
<h2><a class="anchor" id="Obtaining01"></a>
Obtaining and compiling</h2>
<p>The source code can be obtained via Subversion or Git. See the section <a href="https://github.com/gismo/gismo/wiki/Downloads" target="_parent">Downloads</a> of the wiki for downloading information.</p>
<p>The configuration/compilation is based on the CMake build management system. A C++ compiler should be available in the system. See the section <a href="https://github.com/gismo/gismo/wiki/Compiling" target="_parent">Compiling</a> of the wiki for information on compilation.</p>
<h2><a class="anchor" id="Source01"></a>
The source folder</h2>
<p>The source folder contains the following sub-folders:</p>
<ul>
<li><p class="startli"><b>src</b> </p>
<p class="startli">In this folder we have the source files of the library. Code is partitioned into modules, which correspond to folders inside src. Here is a list of these folders/modules:</p><ul>
<li><p class="startli"><a class="el" href="group__Core.html">gsCore</a></p>
<p class="startli">Contains several general objects that are useful for the rest of the modules. Most importantly it contains abstract classes such as <a class="el" href="classgismo_1_1gsFunction.html" title="A function from a n-dimensional domain to an m-dimensional image.">gsFunction</a> and <a class="el" href="classgismo_1_1gsBasis.html" title="A basis represents a family of scalar basis functions defined over a common parameter domain.">gsBasis</a> which represent functions and sets of bases on a parametric domain. Continue here.</p>
</li>
<li><p class="startli"><a class="el" href="group__Matrix.html">gsMatrix</a></p>
<p class="startli">Contains classes for matrices, vectors, and sparse matrices. These objects are derived from the <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> linear algebra library.</p>
</li>
<li><p class="startli"><a class="el" href="group__Nurbs.html">gsNurbs</a></p>
<p class="startli">Contains classes for knot-vectors, univariate B-splines, tensor-product B-splines as well as NURBS and tensor-product NURBS classes.</p>
</li>
<li><p class="startli"><a class="el" href="group__HSplines.html">gsHSplines</a></p>
<p class="startli">Contains classes for hierarchical B-spline basis, as well as truncated hierarchical B-spline basis. These are based on a tree-structure which holds the domain information. It also contains adaptive fitting algorithms using hierarchical splines.</p>
</li>
<li><p class="startli"><a class="el" href="group__Modeling.html">gsModeling</a></p>
<p class="startli">Contains classes related to modeling with geometric objects. The main functionality is currently fitting and boundary-represented solids.</p>
</li>
<li><p class="startli"><a class="el" href="group__Pde.html">gsPde</a></p>
<p class="startli">Contains classes which represent boundary value problems of partial differential equations. This includes the PDE definitions, boundary conditions and point loads.</p>
</li>
<li><p class="startli"><a class="el" href="group__Assembler.html">gsAssembler</a></p>
<p class="startli">Contains classes which allow us to generate (assemble) the matrices and right-hand side(s) of a boundary value problem by means of (Gauss) quadrature. Also, it contains classes which allow us to compute the norms or semi-norms of the difference of two functions, error estimators and related utilities.</p>
</li>
<li><p class="startli"><a class="el" href="group__Solver.html">gsSolver</a></p>
<p class="startli">Contains iterative linear solvers which complement the ones from the <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> library, such as GMRES. It also contains multigrid solvers and preconditioners.</p>
</li>
<li><p class="startli"><a class="el" href="group__IO.html">gsIO</a></p>
<p class="startli">Contains utilities related to data input and output. This includes helpers for adding command line arguments to executables, reading data from files and writing data to the disk. It implements the XML file format of G+Smo. Finally, there are functions which generate Paraview files for visualization.</p>
</li>
<li><p class="startli"><a class="el" href="group__Tensor.html">gsTensor</a></p>
<p class="startli">Contains classes and function to manipulate tensor-structured objects.</p>
</li>
<li><p class="startli"><a class="el" href="group__Utils.html">gsUtils</a></p>
<p class="startli">Contains several utilities that are needed by other modules. This includes combinatorics utilities, point grid generators and iterators, utilities for measuring the CPU time, and a data structure for triangular meshes.</p>
</li>
</ul>
</li>
<li><p class="startli"><b>examples</b> </p>
<p class="startli">Contains source code for <a class="el" href="Examples.html">the examples</a>, small programs and tutorials. Each of these files has extension .cpp and produces an executable upon compilation.</p>
</li>
<li><p class="startli"><b>filedata</b> </p>
<p class="startli">Contains some example data files in the XML format the G+Smo can read and write.</p>
</li>
<li><p class="startli"><b>optional</b> </p>
<p class="startli">Optional additional modules that can be compiled along G+Smo, typically extending functionality, sometimes also requiring external packages, which may be automatically downloaded. For instance, the Parasolid module requires the Parasolid library, and IpOpt module requires the IpOpt optimization library. The OpenNurbs module is used to read and write the Rhino3D 3DM file format, but it does not require any external package, since the source code of the OpenNurbs library is already in /external.</p>
</li>
<li><p class="startli"><b>plugins</b> </p>
<p class="startli">The plugins are typically dynamic libraries which wrap G+Smo for linking with external software and for exporting functionality to third party software. A plugin is available for the Axel geometric modeller (INRIA).</p>
</li>
<li><p class="startli"><b>cmake</b> </p>
<p class="startli">Contains Cmake configuration script files which are required for compilation.</p>
</li>
<li><p class="startli"><b>doc</b> </p>
<p class="startli">Contains files related to Doxygen documentation pages.</p>
</li>
</ul>
<h2><a class="anchor" id="BuildFolder01"></a>
The build (compilation) folder</h2>
<p>The build folder has the following subfolders and files:</p>
<ul>
<li><p class="startli"><b>lib</b> </p>
<p class="startli">In this folder the G+Smo library is created. On MS Windows the dynamic library will be called gismo.dll, while on linux libgismo.so and on OSX libgismo.dylib. The static libraries are gismo_static.lib and libgismo_static.a, respectively. When typing "make -j2 gismo" in the root build folder the dynamic library is created. If you need a static library then "make -j2 gismo_static" will do the trick.</p>
</li>
<li><p class="startli"><b>bin</b> </p>
<p class="startli">Inside this folder all the compiled executable files will be created upon compilation. In particular, each .cpp file in the <em>examples</em> folder corresponds to the file in this folder, with the same name. On MS Windows, the file will have extension .exe, while on Linux they will be marked as executable files. If this folder is empty, then type "make -j2 examples" in the root build folder to trigger the compilation.</p>
<p class="startli">On a command line, you can compile (and execute) specific examples, for instance to execute the executable coming from examples/gsView.cpp it suffices to issue inside the build folder: </p><div class="fragment"><div class="line">$ make gsView</div>
<div class="line">[100%] Building CXX <span class="keywordtype">object</span> stable/examples/CMakeFiles/gsView.dir/gsView.cpp.o</div>
<div class="line">[100%] Linking CXX executable ../../bin/gsView</div>
<div class="line">[100%] Built target gsView</div>
<div class="line">$ ./bin/gsView</div>
<div class="line">Hi, <a class="code hl_function" href="namespacegismo.html#ab72442c3b5aeef49b3c60f6e9df77110">give</a> me a file (eg: .xml) and I will try to draw it!</div>
<div class="line">Type ./bin/gsView -h, to get the list of command line options.</div>
<div class="line">$</div>
<div class="ttc" id="anamespacegismo_html_ab72442c3b5aeef49b3c60f6e9df77110"><div class="ttname"><a href="namespacegismo.html#ab72442c3b5aeef49b3c60f6e9df77110">gismo::give</a></div><div class="ttdeci">S give(S &x)</div><div class="ttdef"><b>Definition</b> gsMemory.h:266</div></div>
</div><!-- fragment --><p> Note that on Linux you need to provide correctly the path (starting with dot-slash-bin), in order to execute a file. Similarly on Windows you should execute (eg. from a command line) the file <em>gsView.exe</em> </p>
</li>
<li><p class="startli"><b>doc</b> </p>
<p class="startli">This folder contains files related to Doxygen documentation. In particular, if Doxygen is available on the system, and inside the root build folder we execute: </p><div class="fragment"><div class="line">$ make doc</div>
<div class="line">[100%] Generating API documentation with Doxygen</div>
<div class="line">[100%] Built target doc</div>
<div class="line">$ firefox doc/html/index.html</div>
</div><!-- fragment --><p> then the resulting main Doxygen page will be created in <b>doc/html/index.html</b> and can be opened with a web-browser.</p>
</li>
<li><p class="startli"><b>CMakeFiles</b> </p>
<p class="startli">This folder contains files related to the CMake configuration. Similarly several files (eg. with extension .cmake) which are found in the root folder are related to CMake. Most important of the latter files is the CMakeCache.txt file which keeps all the needed paths (eg. the path to the source folder) and all compilation flags and options.</p>
</li>
<li><p class="startli"><b>src</b>, <b>examples</b>, <b>external</b>, <b>optional</b> </p>
<p class="startli">These folders are named as the corresponding folders in the source folder, and contain the compiled object files. All files in these folders are temporary, and their goal is to allow one to re-compile the library fast when there are only a few changes in the source files (while all the other object files are unchanged). Most of the time we do not need to care about or work in these folders.</p>
</li>
</ul>
<h2><a class="anchor" id="build1"></a>
Build types</h2>
<p>There are a number of options which parametrize the compilation process. The default options should work most of the time. For a list of the available options have a look at <a href="https://github.com/gismo/gismo/wiki/Compiling#configuration-options" target="_parent">this wiki page</a>.</p>
<p>The most important setting is setting the build type. As common to the <a href="https://cmake.org/" target="_blank">CMake</a> build management system, there are three basic build types:</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">Build type </th><th class="markdownTableHeadNone">Characteristics </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone"><code>Debug</code> </td><td class="markdownTableBodyNone">No optimizations, NDEBUG not defined </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone"><code>RelWithDebInfo</code> </td><td class="markdownTableBodyNone">Optimized code, but NDEBUG <b>defined</b> </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone"><code>Release</code> </td><td class="markdownTableBodyNone">The macro NDEBUG is defined, fully optimized </td></tr>
</table>
<p>The default build type (if not specified with the CMAKE_BUILD_TYPE setting) is Release. Contrarily to the default setting of CMake, in G+Smo the macro NDEBUG <b>is</b> defined in this setting. Therefore in RelWithDebInfo mode you still get a fairly good checking level, with the cost that the performance is reduced.</p>
<p>The Debug mode is often too slow. However, as a last resort for chasing bugs this mode should be tried. Several times RelWithDebInfo inlines functions, and causes the debug information to point to the wrong line in the code.</p>
<p>The Release mode is the fully optimized, production code.</p>
<h1><a class="anchor" id="get01"></a>
Getting started</h1>
<p>A toy program using the library looks as follows. </p><div class="fragment"><div class="line"><span class="preprocessor"># include <<a class="code" href="gismo_8h.html">gismo.h</a>></span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code hl_namespace" href="namespacegismo.html">gismo</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argc</a>, <span class="keywordtype">char</span>* <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argv</a>[])</div>
<div class="line">{</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Hello G+Smo.\n"</span>;</div>
<div class="line"> </div>
<div class="line"> real_t <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">a</a> = 2.0; <span class="comment">// a real number, ie. double</span></div>
<div class="line"> </div>
<div class="line"> index_t b = 3; <span class="comment">// an integer, ie. int</span></div>
<div class="line"> </div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#afef28a292b09ce4b06f94e6ed3b8abb4">GISMO_ASSERT</a>( <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">a</a>*b == 6, <span class="stringliteral">"This is an error, 2*3 should be 6."</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="aclassgismo_1_1gsTHBSplineBasis_html"><div class="ttname"><a href="classgismo_1_1gsTHBSplineBasis.html">gismo::gsTHBSplineBasis</a></div><div class="ttdoc">Truncated hierarchical B-spline basis.</div><div class="ttdef"><b>Definition</b> gsTHBSplineBasis.h:36</div></div>
<div class="ttc" id="agismo_8h_html"><div class="ttname"><a href="gismo_8h.html">gismo.h</a></div><div class="ttdoc">Main header to be included by clients using the G+Smo library.</div></div>
<div class="ttc" id="agsDebug_8h_html_af6177e1e282640c3cb9175565f84a432"><div class="ttname"><a href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a></div><div class="ttdeci">#define gsInfo</div><div class="ttdef"><b>Definition</b> gsDebug.h:43</div></div>
<div class="ttc" id="agsDebug_8h_html_afef28a292b09ce4b06f94e6ed3b8abb4"><div class="ttname"><a href="gsDebug_8h.html#afef28a292b09ce4b06f94e6ed3b8abb4">GISMO_ASSERT</a></div><div class="ttdeci">#define GISMO_ASSERT(cond, message)</div><div class="ttdef"><b>Definition</b> gsDebug.h:89</div></div>
<div class="ttc" id="anamespacegismo_html"><div class="ttname"><a href="namespacegismo.html">gismo</a></div><div class="ttdoc">The G+Smo namespace, containing all definitions for the library.</div></div>
</div><!-- fragment --><p> All the objects of the library are found inside the <em>gismo</em> namespace.</p>
<h2><a class="anchor" id="str01"></a>
Streaming text messages</h2>
<p>There are pre-defined streams that should be preferred:</p>
<ul>
<li><b>gsInfo</b> This stream is an alias for <code>std::cout</code> and should be preferred over it.</li>
<li><b>gsWarn</b> This stream prints the word "Warning" before your message, and should be used to warn of any important events.</li>
<li><b>gsDebug</b> The messages are prefixed by GISMO_DEBUG and appear in Debug/RelWithDebInfo but not in release mode (controlled by the macro NDEBUG).</li>
<li><b>gsDebugVar</b>(<em>var</em>) Streams the variable <em>var</em>, and the line and file of the code which emitted the message. This macro is used for easy printing and inspecting the contents of a variable.</li>
</ul>
<p>Note that the end-of-line character <code>"\n"</code> should be preferred over <code>std::endl</code> .</p>
<h2><a class="anchor" id="deb01"></a>
Assertion macros</h2>
<p>In Debug/RelWithDebInfo the assertions of the type are executed: </p><div class="fragment"><div class="line"><a class="code hl_define" href="gsDebug_8h.html#afef28a292b09ce4b06f94e6ed3b8abb4">GISMO_ASSERT</a>( <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">condition</a>, <span class="stringliteral">"Message if failed"</span>)</div>
</div><!-- fragment --><p> In Release Mode these commands are striped out of the code. An assertion which executes even in release mode is the following: </p><div class="fragment"><div class="line"><a class="code hl_define" href="gsDebug_8h.html#ad244d2129e4089c7772855461057e0fb">GISMO_ENSURE</a>( <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">condition</a>, <span class="stringliteral">"Message if failed"</span>)</div>
<div class="ttc" id="agsDebug_8h_html_ad244d2129e4089c7772855461057e0fb"><div class="ttname"><a href="gsDebug_8h.html#ad244d2129e4089c7772855461057e0fb">GISMO_ENSURE</a></div><div class="ttdeci">#define GISMO_ENSURE(cond, message)</div><div class="ttdef"><b>Definition</b> gsDebug.h:102</div></div>
</div><!-- fragment --><p> Also, the following emits an runtime error exception (without check condition): </p><div class="fragment"><div class="line"><a class="code hl_define" href="gsDebug_8h.html#a70e3438ba5da4ec4bd4541d17cf7a79a">GISMO_ERROR</a>(<span class="stringliteral">"You reached a line in the code which indicated a serious error"</span>)</div>
<div class="ttc" id="agsDebug_8h_html_a70e3438ba5da4ec4bd4541d17cf7a79a"><div class="ttname"><a href="gsDebug_8h.html#a70e3438ba5da4ec4bd4541d17cf7a79a">GISMO_ERROR</a></div><div class="ttdeci">#define GISMO_ERROR(message)</div><div class="ttdef"><b>Definition</b> gsDebug.h:118</div></div>
</div><!-- fragment --><h2><a class="anchor" id="art1"></a>
Arithmetic types</h2>
<p>Common arithmetic types are defined by macros in G+Smo, and should be preferred:</p><ul>
<li><b>real_t</b> This type defaults to <em>double</em> </li>
<li><b>index_t</b> This is the number type used for all matrix and vector indices and sizes (eg. number of rows).</li>
<li><b>size_t</b> This is the type used in the standard library, eg. for the size of an std::vector.</li>
</ul>
<p>Note that index_t and size_t might be different types, therefore care should be taken when comparing their value.</p>
<p>Many template classes (for instance matrices) have a default first argument which is in most cases <b>real_t</b>.</p>
<h1><a class="anchor" id="io01"></a>
Basic input and output</h1>
<h2><a class="anchor" id="cmd01"></a>
Command line arguments</h2>
<p>A handy class called <a class="el" href="classgismo_1_1gsCmdLine.html" title="Class for command-line argument parsing.">gsCmdLine</a> for adding command line options to your programs. Adding options to a program makes it more friendly to the users, while allowing you to execute many different scenarios without having to change the source code and re-compile the source file.</p>
<p>Command-line arguments are useful to avoid re-compiling your code every time a small parameter is altered, as well as to make your program easily accessible by others. In G+Smo there is an easy way to add command-line arguments, which come automatically with a small help message and error checking, see <a class="el" href="commandLineArg_example.html">commandLineArg_example.cpp</a>.</p>
<p>In the file <a class="el" href="gsView.html">gsView.cpp</a> for instance, we find the following code for parsing the command line:</p>
<div class="fragment"><div class="line"> <a class="code hl_class" href="classgismo_1_1gsCmdLine.html">gsCmdLine</a> cmd(<span class="stringliteral">"Hi, give me a file (eg: .xml) and I will try to draw it!"</span>);</div>
<div class="line"> </div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"geometry"</span>, <span class="stringliteral">"Try to find and plot a geometry contained in the file"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">get_geo</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"mesh"</span> , <span class="stringliteral">"Try to find and plot a mesh contained in the file"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">get_mesh</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"basis"</span> , <span class="stringliteral">"Try to find and plot a basis contained in the file"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">get_basis</a>);</div>
<div class="line"> cmd.addInt (<span class="stringliteral">"s"</span>, <span class="stringliteral">"samples"</span>, <span class="stringliteral">"Number of samples to use for viewing"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">numSamples</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"element"</span> , <span class="stringliteral">"Plot the element mesh (when applicable)"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">plot_mesh</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"controlNet"</span>, <span class="stringliteral">"Plot the control net (when applicable)"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">plot_net</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"pid"</span> , <span class="stringliteral">"Plot the ID of each patch and boudanries as color"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">plot_patchid</a>);</div>
<div class="line"> cmd.addPlainString(<span class="stringliteral">"filename"</span>, <span class="stringliteral">"File containing data to draw (.xml or third-party)"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fn</a>);</div>
<div class="line"> cmd.addString(<span class="stringliteral">"o"</span>, <span class="stringliteral">"oname"</span>, <span class="stringliteral">"Filename to use for the ParaView output"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pname</a>);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">try</span> { cmd.getValues(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argc</a>,<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argv</a>); } <span class="keywordflow">catch</span> (<span class="keywordtype">int</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">rv</a>) { <span class="keywordflow">return</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">rv</a>; }</div>
</div><!-- fragment --><p>The last argument of each "add" command is, as expected, a boolean (for the addSwitch), or an integer (for the addInt). The <a class="el" href="classgismo_1_1gsCmdLine.html#a25029e87405c0c54d376659803bbe939" title="Parses the command line based on the specified parameters.">gsCmdLine::getValues</a> command parses all the user's input and updates the variables with new values. Therefore, after this command, the value of all the variables can be different. If an argument is not provided by the user, then the value of the variable does not change.</p>
<p>After compiling the program we can issue: </p><div class="fragment"><div class="line"><a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">$</a> ./<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">bin</a>/gsView -<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">h</a></div>
</div><!-- fragment --><p> and we obtain a list of the arguments together with the short explanation that we provided in the definition of the argument. Note that all arguments are checked automatically during parsing, eg. duplicate arguments and other subtle errors are detected.</p>
<p>Combined with reading the input data from files, this feature allows you eg. to write code which works for any input file which contains data that G+Smo can read, merely by adding a command line argument which accepts a string describing a filename.</p>
<h2><a class="anchor" id="xml01"></a>
The XML file format</h2>
<p>The native format for data input, output and data exchange is XML. In G+Smo we define a number of tags that are used to read and write respective objects (classes). Typically, the data in an XML tree which represent, for instance, a B-spline, follow the logic of the classes in the code. As a first example the file square.xml is:</p>
<div class="fragment"><div class="line"><?<span class="keyword">xml</span> <span class="keyword">version</span>=<span class="stringliteral">"1.0"</span> <span class="keyword">encoding</span>=<span class="stringliteral">"UTF-8"</span>?></div>
<div class="line"><<span class="keywordtype">xml</span>></div>
<div class="line"> <<span class="keywordtype">Geometry</span> <span class="keyword">type</span>=<span class="stringliteral">"TensorBSpline2"</span> <span class="keyword">id</span>=<span class="stringliteral">"1"</span>></div>
<div class="line"> <<span class="keywordtype">Basis</span> <span class="keyword">type</span>=<span class="stringliteral">"TensorBSplineBasis2"</span>></div>
<div class="line"> <<span class="keywordtype">Basis</span> <span class="keyword">type</span>=<span class="stringliteral">"BSplineBasis"</span> <span class="keyword">index</span>=<span class="stringliteral">"0"</span>></div>
<div class="line"> <<span class="keywordtype">KnotVector</span> <span class="keyword">degree</span>=<span class="stringliteral">"1"</span>>0.00000 0.00000 1.00000 1.00000</<span class="keywordtype">KnotVector</span>></div>
<div class="line"> </<span class="keywordtype">Basis</span>></div>
<div class="line"> <<span class="keywordtype">Basis</span> <span class="keyword">type</span>=<span class="stringliteral">"BSplineBasis"</span> <span class="keyword">index</span>=<span class="stringliteral">"1"</span>></div>
<div class="line"> <<span class="keywordtype">KnotVector</span> <span class="keyword">degree</span>=<span class="stringliteral">"1"</span>>0.00000 0.00000 1.00000 1.00000</<span class="keywordtype">KnotVector</span>></div>
<div class="line"> </<span class="keywordtype">Basis</span>></div>
<div class="line"> </<span class="keywordtype">Basis</span>></div>
<div class="line"> <<span class="keywordtype">coefs</span> <span class="keyword">geoDim</span>=<span class="stringliteral">"2"</span>>0 0 1 0 0 1 1 1 </<span class="keywordtype">coefs</span>></div>
<div class="line"> </<span class="keywordtype">Geometry</span>></div>
<div class="line"></<span class="keywordtype">xml</span>></div>
<div class="line"> </div>
</div><!-- fragment --><p>The space between the numbers and line breaks do not matter. The plain text files can become big in size, when the data is a lot. For this reason, a compressed XML format is also supported, which can also be read/written directly.</p>
<p>All the tags in the XML tree of a G+Smo XML file must be contained inside the <b><<code>xml</code> ></b> tag. Arbitrary data can be contained inside an XML file, as long as they are valid XML files. If you write (a small) XML file yourself, you can validate it for instance <a href="http://www.w3schools.com/xml/xml_validator.asp" target="_blank">this page</a> to make sure that there are no errors. In any case, invalid files will not be read properly by G+Smo and errors will be emitted. Each object in a G+Smo XML is also expected to have a unique ID attribute, which can be used for identifiing the specific data in the file.</p>
<p>The XML file format is extensible. As soon as objects/classes are created, a new tag for reading or writing the data can be added in the XML manager.</p>
<h2><a class="anchor" id="read01"></a>
Reading files</h2>
<p>To read a file in your program the recommended solution is to first define an input argument for your program which will be a string holding the name of the filename. For instance</p>
<div class="fragment"><div class="line"> std::string input(<span class="stringliteral">"curves3d/bspline3d_curve_01.xml"</span>);</div>
<div class="line"> std::string <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">output</a>(<span class="stringliteral">""</span>);</div>
<div class="line"> <span class="keywordtype">bool</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">bezier</a>=<span class="keyword">false</span>; </div>
<div class="line"> </div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsCmdLine.html">gsCmdLine</a> cmd(<span class="stringliteral">"Tutorial Input Output"</span>);</div>
<div class="line"> cmd.addPlainString(<span class="stringliteral">"filename"</span>, <span class="stringliteral">"G+Smo input geometry file."</span>, input);</div>
<div class="line"> cmd.addString(<span class="stringliteral">"o"</span>, <span class="stringliteral">"output"</span>, <span class="stringliteral">"Name of the output file"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">output</a>);</div>
<div class="line"> cmd.addSwitch(<span class="stringliteral">"b"</span>,<span class="stringliteral">"bezier"</span>, <span class="stringliteral">"Output using Bezier elements"</span>, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">bezier</a>);</div>
<div class="line"> <span class="keywordflow">try</span> { cmd.getValues(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argc</a>,<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">argv</a>); } <span class="keywordflow">catch</span> (<span class="keywordtype">int</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">rv</a>) { <span class="keywordflow">return</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">rv</a>; }</div>
</div><!-- fragment --><p>In the above code note the default value of the input string: The macro GISMO_DATA_DIR always points to the <em>filedata</em> folder inside the <a class="el" href="#Source01">source folder</a>. Using this macro allows you to make sure that your default argument will work on any system which will compile the library. Using an absolute path such as <em>/home/myname/gismo/filedata/square</em>.xml will directly make your program to fail when used in a different system. Therefore the GISMO_DATA_DIR macro is highly recommended.</p>
<p>The main class which allows you to read data from the file is the <a class="el" href="classgismo_1_1gsFileData.html" title="This class represents an XML data tree which can be read from or written to a (file) stream.">gsFileData</a> object. In the following we read a polymorphic <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a> object from the file:</p>
<div class="fragment"><div class="line"> <span class="keywordflow">if</span> (!gsFileManager::fileExists(input))</div>
<div class="line"> {</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#a855d5a33a1f52e7519abe44f5ddf45f0">gsWarn</a> << <span class="stringliteral">"The file cannot be found!\n"</span>;</div>
<div class="line"> <span class="keywordflow">return</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">EXIT_FAILURE</a>;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Read file \""</span> << input << <span class="stringliteral">"\"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsFileData<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fileData</a>(input);</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_typedef" href="classgismo_1_1gsGeometry.html#a662205e4593e51aa058cfd6d71f98c08">gsGeometry<>::uPtr</a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>;</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fileData</a>.has< <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsGeometry<></a> >())</div>
<div class="line"> {</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a> = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fileData</a>.getFirst< <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsGeometry<></a> >();</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> {</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#a855d5a33a1f52e7519abe44f5ddf45f0">gsWarn</a> << <span class="stringliteral">"Input file doesn't have a geometry.\n"</span>;</div>
<div class="line"> <span class="keywordflow">return</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">EXIT_FAILURE</a>;</div>
<div class="line"> }</div>
</div><!-- fragment --><p>When creating the <a class="el" href="classgismo_1_1gsFileData.html" title="This class represents an XML data tree which can be read from or written to a (file) stream.">gsFileData</a> object, all the XML data in the file are loading into memory as an XML tree. This XML tree can contain many different objects. In the above, the <a class="el" href="classgismo_1_1gsFileData.html#af2403acf5250d85d474308c1b84253f8" title="Returns true if an Object exists in the filedata.">gsFileData::has</a> helper searches the tree for the existence of a <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a> tag. This tag corresponds to a polymorphic geometry object (which can be a polynomial curve, surface or volume or a rational NURBS patch, or a different type of geometry/patch). In the case that a <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a> object is found, a pointer is allocated and returned to the user. As the name of the get function suggests, the returned object is the first object which was encountered in the XML tree.</p>
<p>To see what is the <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a> data that have been obtained, we can stream it to gsInfo:</p>
<div class="fragment"></div><!-- fragment --><p>You can have better control of which data is read from the file by reading using the ID of the tag. For instance, the following:</p>
<div class="fragment"><div class="line"> <span class="comment">// Surface fitting</span></div>
<div class="line"> <span class="comment">// Expected input is a file with matrices with:</span></div>
<div class="line"> <span class="comment">// id 0: u,v -- parametric coordinates, size 2 x N</span></div>
<div class="line"> <span class="comment">// id 1: x,y,z -- corresponding mapped values, size 3 x N</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsFileData<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fd_in</a>(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fn</a>);</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> uv, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">xyz</a>;</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fd_in</a>.getId<<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> >(0, uv );</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">fd_in</a>.getId<<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> >(1, <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">xyz</a>);</div>
</div><!-- fragment --><p>reads two matrices from an XML tree, that correspond to parameters and values for a fitting problem. The <em>uv</em> matrix is fetched from the file as the matrix inside the file with id=0, and then the <em>xyz</em> matrix is fetched again by its id=1. this way there is no ambiguity which object is being read from the tree (as long as we use unique ids).</p>
<p>Another command which appears in the above example is the <em>safe</em> function. This macro takes a pointer to a matrix (which is the returned type of getId, and produces a smart pointer. The smart pointer is then transferred to uv/xyz matrices. This is an emulation of the move semantics of C++11, which we do not use yet, for the sake of compatibility.</p>
<dl class="todo"><dt><b><a class="el" href="todo.html#_todo000024">Todo</a></b></dt><dd>Update this paragraph</dd></dl>
<h2><a class="anchor" id="write01"></a>
Writing files</h2>
<p>Similarly to reading XML data, we are able to create XML tree data and save them as a file in the disk:</p>
<div class="fragment"><div class="line"> <span class="comment">// writing a G+Smo .xml file</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsFileData<></a> fd;</div>
<div class="line"> fd << *<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>;</div>
<div class="line"> <span class="comment">// output is a string. The extention .xml is added automatically</span></div>
<div class="line"> fd.save(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">output</a>);</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Wrote G+Smo file: "</span> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">output</a> << <span class="stringliteral">".xml \n"</span>;</div>
</div><!-- fragment --><p>the << operator translates the object into an XML tag. Then the save command creates a file with all the contents of the <em>fd</em> XML tree. Since we only pushed one object in the tree up to now, only one <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a> tag will be found in the resulting file.</p>
<p>Apart from the native XML format of the library, a number of third party formats can be imported or exported. One such useful format is Rhino's 3DM file format (note: the gsOpennurbs submodule must be enabled). Also, the Siemens' NX (Parasolid) file format is supported, if the Parasolid library is available in the system (note: GISMO_WITH_PSOLID compilation parameter). Other formats include the GeoPDE (Matlab/octave) text format, the GoTools format and OBJ, OFF and STL mesh files. The IGES file format is under development.</p>
<h1><a class="anchor" id="la01"></a>
Matrices and linear algebra</h1>
<p>The matrices in G+Smo are obtained from the Eigen linear algebra library.</p>
<p>All the functionality of <a class="elRef" href="http://eigen.tuxfamily.org/dox/classEigen_1_1Matrix.html">Eigen::Matrix</a> is available in the (inherited) class <a class="el" href="classgismo_1_1gsMatrix.html" title="A matrix with arbitrary coefficient type and fixed or dynamic size.">gsMatrix</a>. The <a class="el" href="linearAlgebra_example.html">linearAlgebra_example.cpp</a> contains starting examples for using matrices.</p>
<p>The sparse matrix class is <a class="el" href="classgismo_1_1gsSparseMatrix.html" title="Sparse matrix class, based on gsEigen::SparseMatrix.">gsSparseMatrix</a> and is derived from <a class="elRef" href="http://eigen.tuxfamily.org/dox/classEigen_1_1SparseMatrix.html">Eigen::SparseMatrix</a> class. Several sparse linear solvers are available, demonstrated in <a class="el" href="sparseSolvers_example.html">sparseSolvers_example.cpp</a>. The main information about the matrix manipulations can be found in the <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> documentation pages. We link to the most important chapters:</p>
<ul>
<li><a class="elRef" href="http://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__chapter.html">Dense matrix and array manipulation</a></li>
<li><a class="elRef" href="http://eigen.tuxfamily.org/dox/group__DenseLinearSolvers__chapter.html">Dense linear problems and decompositions</a></li>
<li><a class="elRef" href="http://eigen.tuxfamily.org/dox/group__Sparse__chapter.html">Sparse linear algebra</a></li>
</ul>
<p>The quick reference pages give a summary of the functionality:</p>
<ul>
<li><a class="elRef" href="http://eigen.tuxfamily.org/dox/group__QuickRefPage.html">Quick reference guide</a> (for dense matrices)</li>
<li><a class="elRef" href="http://eigen.tuxfamily.org/dox/group__SparseQuickRefPage.html">Quick reference guide for sparse matrices</a></li>
</ul>
<p>There is also a list with the <a href="http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt">correspondance to Matlab functions</a>. However, note that some operations of Matlab are not mirrored (yet) with functionality in <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a>. For example, a <em>reshape</em> function does not exist. The Topic <a class="elRef" href="http://eigen.tuxfamily.org/dox/group__TopicAliasing.html">Aliasing</a> is also important to learn how to avoid bugs and write more efficient code.</p>
<dl class="section note"><dt>Note</dt><dd>You do not need to care about headers and inclusion of <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> files. By default the Core, Dense and Sparse packages are included in in G+Smo.</dd></dl>
<p>All the information and functionality in the above pages apply to the <a class="el" href="classgismo_1_1gsMatrix.html" title="A matrix with arbitrary coefficient type and fixed or dynamic size.">gsMatrix</a>, <a class="el" href="classgismo_1_1gsVector.html" title="A vector with arbitrary coefficient type and fixed or dynamic size.">gsVector</a> and <a class="el" href="classgismo_1_1gsSparseMatrix.html" title="Sparse matrix class, based on gsEigen::SparseMatrix.">gsSparseMatrix</a>, <a class="el" href="classgismo_1_1gsSparseVector.html" title="Sparse vector class, based on gsEigen::SparseVector.">gsSparseVector</a> classes. For certain functionalities, which we need to extend or adapt in G+Smo, for example for the sparse liner solver classes, there are more objects defined which correspond to <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> objects. In general, we try to avoid the direct use of the <em><a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a></em> namespace inside the library, whenever possible.</p>
<p>The sources of the <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> linear algebra library are included in the code repository of G+Smo, for your convenience.</p>
<p>Matrix operations of <a class="elRef" href="http://eigen.tuxfamily.org/dox/namespaceEigen.html">Eigen</a> should be preferred over using for loops or manual functions. One reason for this is the clarity of the code, the reduction of lines of code and last but not least the fact that the provided operations are vectorized therefore they are more efficient than manual coding.</p>
<p>As a simple example, consider that you would like to multiply each row of a matrix by a number. Here are some equivalent ways to do this:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <<a class="code" href="gismo_8h.html">gismo.h</a>></span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code hl_namespace" href="namespacegismo.html">gismo</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>**)</div>
<div class="line">{</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Task: multiply the rows of M by the corresponding scalars in v</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsVector<></a> v(4);</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> M(4,6);</div>
<div class="line"> v.setRandom();</div>
<div class="line"> M.setRandom();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Manually</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> R1(4,6);</div>
<div class="line"> <span class="keywordflow">for</span> (index_t i = 0; i<4; ++i) <span class="comment">// for all rows</span></div>
<div class="line"> <span class="keywordflow">for</span> (index_t <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">j</a> = 0; <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">j</a><6; ++<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">j</a>) <span class="comment">// for all columns</span></div>
<div class="line"> R1(i,<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">j</a>) = M(i,<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">j</a>) * v[i];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Using row-blocks</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R2</a>(4,6);</div>
<div class="line"> <span class="keywordflow">for</span> (index_t i = 0; i<4; ++i) <span class="comment">// for all rows</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R2</a>.row(i).noalias() = M.row(i) * v[i]; <span class="comment">// matrix x scalar</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Using only one line</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R3</a>;</div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R3</a>.noalias() = v.asDiagonal() * M; <span class="comment">// matrix x matrix</span></div>
<div class="line"> </div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"v is: \n"</span> << v << <span class="stringliteral">"\n\n"</span>;</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"M is: \n"</span> << M << <span class="stringliteral">"\n\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"R1 is: \n"</span> << R1 << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"R2 is: \n"</span> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R2</a> << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"R3 is: \n"</span> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">R3</a> << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p> Output: </p><pre class="fragment">v is:
0.68
-0.211
0.566
0.597
M is:
0.823 -0.444 -0.27 0.271 -0.967 -0.687
-0.605 0.108 0.0268 0.435 -0.514 -0.198
-0.33 -0.0452 0.904 -0.717 -0.726 -0.74
0.536 0.258 0.832 0.214 0.608 -0.782
R1 is:
0.56 -0.302 -0.184 0.185 -0.658 -0.467
0.128 -0.0228 -0.00566 -0.0918 0.109 0.0418
-0.187 -0.0256 0.512 -0.406 -0.411 -0.419
0.32 0.154 0.497 0.128 0.363 -0.467
R2 is:
0.56 -0.302 -0.184 0.185 -0.658 -0.467
0.128 -0.0228 -0.00566 -0.0918 0.109 0.0418
-0.187 -0.0256 0.512 -0.406 -0.411 -0.419
0.32 0.154 0.497 0.128 0.363 -0.467
R3 is:
0.56 -0.302 -0.184 0.185 -0.658 -0.467
0.128 -0.0228 -0.00566 -0.0918 0.109 0.0418
-0.187 -0.0256 0.512 -0.406 -0.411 -0.419
0.32 0.154 0.497 0.128 0.363 -0.467
</pre><p>From these 3 versions, the last one is preferred, since we know well from linear algebra that left multiplication by a diagonal matrix corresponds to multiplying the rows by the diagonal elements. Note that v.asDiagonal() does not make a copy of the vector <em>v</em>, but only returns an expression of the <em>v</em> as a diagonal matrix. Also note the noalias() function to avoid <a class="elRef" href="http://eigen.tuxfamily.org/dox/group__TopicAliasing.html">Aliasing</a>, eg. an un-needed temporary copy of <em>R3</em>.</p>
<h1><a class="anchor" id="main01"></a>
Functions and bases</h1>
<p>One of the most basic objects in G+Smo are the ones representing functions. There are several implementations of functions, or sets of functions. They all derive by a common class, <a class="el" href="classgismo_1_1gsFunctionSet.html" title="Interface for the set of functions defined on a domain (the total number of functions in the set equa...">gsFunctionSet</a>. The main descendants of <a class="el" href="classgismo_1_1gsFunctionSet.html" title="Interface for the set of functions defined on a domain (the total number of functions in the set equa...">gsFunctionSet</a> are two:</p>
<h2><a class="anchor" id="Function01"></a>
gsFunction</h2>
<p>This class represents a (abstract) functions of several variables, possibly vector-valued. The function is defined over an (arbitrary) square domain, referred to as its support. One characteristic of the function is that in principle it takes non-zero values <em>throughout</em> its support.</p>
<p>The main attributes of functions (and bases) are the dimension of the parameter domain and the target domain, as well as their support. The main functionality is the ability to evaluate the function and its derivatives at given points inside the support.</p>
<p>One instance of function is the <a class="el" href="classgismo_1_1gsFunctionExpr.html" title="Class defining a multivariate (real or vector) function given by a string mathematical expression.">gsFunctionExpr</a>. This class can be defined by a string containing the mathematical formula of a function. It makes it very easy ad efficient to define and work with complicated mathematical function with minimal effort.</p>
<h2><a class="anchor" id="Basis01"></a>
gsBasis</h2>
<p>This class represent an (abstract) function basis, that is, a set of basis functions. The functions are usually local, that is, they take non-zero value only at a small portion of the support of the basis. See <a class="el" href="basis_example.html">basis_example.cpp</a></p>
<h2><a class="anchor" id="Geometry01"></a>
gsGeometry</h2>
<p>One more instance of a function (derived from <a class="el" href="classgismo_1_1gsFunction.html" title="A function from a n-dimensional domain to an m-dimensional image.">gsFunction</a>) is the <a class="el" href="classgismo_1_1gsGeometry.html" title="Abstract base class representing a geometry map.">gsGeometry</a>. This class is essentially a function defined by a coefficient vector and a <a class="el" href="classgismo_1_1gsBasis.html" title="A basis represents a family of scalar basis functions defined over a common parameter domain.">gsBasis</a>. For example a NURBS patch will fall in this category.</p>
<p>Printing the geometry: </p><div class="fragment"><div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"The file contains: \n"</span> << *<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a> << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// G+Smo geometries contains basis and coefficients</span></div>
<div class="line"> <span class="keyword">const</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsBasis<></a>& basis = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>-><a class="code hl_function" href="classgismo_1_1gsFunctionSet.html#ae883268587612dd29669e46ad726c6cc">basis</a>();</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"\nBasis: \n"</span> << basis << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keyword">const</span> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a>& coefs = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>->coefs();</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"\nCoefficients: \n"</span> << coefs << <span class="stringliteral">"\n"</span> << <span class="stringliteral">"\n"</span>;</div>
</div><!-- fragment --><p>Printing the main properties: </p><div class="fragment"><div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Dimension of the parameter space: "</span> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>->parDim() << <span class="stringliteral">"\n"</span></div>
<div class="line"> << <span class="stringliteral">"Dimension of the geometry: "</span> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>->geoDim() << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// support of the geometry, this is the same as gsBasis::support</span></div>
<div class="line"> <span class="comment">// (dim x 2 matrix, the parametric domain)</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> support = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>-><a class="code hl_function" href="classgismo_1_1gsHTensorBasis.html#ac58c425b016eb6633317c4634f26edc2">support</a>();</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Support: \n"</span></div>
<div class="line"> << support << <span class="stringliteral">"\n"</span> << <span class="stringliteral">"\n"</span>;</div>
</div><!-- fragment --><p>Computing values and derivatives: </p><div class="fragment"><div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> u = 0.3 * support.col(0) + 0.7 * support.col(1);</div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"u "</span> << size(u) << <span class="stringliteral">": \n"</span> << u << <span class="stringliteral">"\n"</span> << <span class="stringliteral">"\n"</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// geoDim x 1 matrix</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> value = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>-><a class="code hl_function" href="classgismo_1_1gsFunctionSet.html#a4b9e91ddf533514f29bfe4d15cb24b65">eval</a>(u);</div>
<div class="line"> <span class="comment">// geoDim * parDim x 1 matrix (columns represent gradients)</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der1</a> = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>-><a class="code hl_function" href="classgismo_1_1gsFunctionSet.html#a8bef99878bdde33c1a5c6f889b8c0776">deriv</a>(u);</div>
<div class="line"> <span class="comment">// [geoDim * (parDim + parDim * (parDim - 1) / 2)] x 1 matrix</span></div>
<div class="line"> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">gsMatrix<></a> <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der2</a> = <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">pGeom</a>-><a class="code hl_function" href="classgismo_1_1gsFunctionSet.html#adf7250a84da63b52a48783e2d24df638">deriv2</a>(u);</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_define" href="gsDebug_8h.html#af6177e1e282640c3cb9175565f84a432">gsInfo</a> << <span class="stringliteral">"Value at u "</span> << size(value) << <span class="stringliteral">": \n"</span></div>
<div class="line"> << value</div>
<div class="line"> << <span class="stringliteral">"\n\nDerivative at u "</span> << size(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der1</a>) << <span class="stringliteral">": \n"</span></div>
<div class="line"> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der1</a></div>
<div class="line"> << <span class="stringliteral">"\n\nSecond derivative at u "</span> << size(<a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der2</a>) << <span class="stringliteral">": \n"</span></div>
<div class="line"> << <a class="code hl_class" href="classgismo_1_1gsTHBSplineBasis.html">der2</a></div>
<div class="line"> << <span class="stringliteral">"\n"</span> << <span class="stringliteral">"\n"</span>;</div>
</div><!-- fragment --> </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 Feb 10 2025 09:21:44 for G+Smo by Doxygen v1.10.0 </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>