-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeveloper_tutorial.html
1372 lines (1168 loc) · 50.3 KB
/
developer_tutorial.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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Goma Developer Tutorial</title>
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/wortiz.css" id="theme">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/tomorrow-night.css" id="highlight-theme">
<style>
.container{
display: flex;
align-items: center;
}
.col{
flex: 1;
padding: 0.5em;
}
.col img {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.col2{
flex: 2;
padding: 0.5em;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown>
<script type="text/template">
## Developer Tutorial
### Weston Ortiz
</script>
</section>
<section>
<h2>Outline</h2>
</section>
<section>
<h4>Outline</h4>
Our developer tutorial topics
<ul>
<li>Adding an Equation</li>
<li>Types of Boundary Conditions in Goma</li>
<li>Adding a Neumann/Robin Condition</li>
<li>Adding a Material Property</li>
<li>Adding a Viscosity Model</li>
<li>Adding a Species Source</li>
<li>Adding a Post Processing Card</li>
</ul>
</section>
<section>
<h2>Adding an Equation</h2>
</section>
<section style="font-size: 0.7em">
<h4>An example problem for a new equation</h4>
<p>
Due to time constraints we will be looking at adding a simple equation
</p>
<p>
The Poisson Equation:
</p>
\[ \Delta u = g \]
<p>Domain is a unit square from (0,0) to (1,1)</p>
<p>Source is \(g = -10 exp(-((x-0.5)^2+(y-0.5)^2)/0.02) \)
<p>BCs</p>
<ul>
<li>
\( n\cdot \nabla u = f = sin(5x) \) on bottom and top
</li>
<li> Dirichlet \(u = 0\) on left and right</li>
</ul>
<p style="font-size:0.5em">Borrowed from <a href="https://fenicsproject.org/docs/dolfin/1.3.0/python/demo/documented/poisson/python/documentation.html">Fenics Docs Examples</a></p>
</section>
<section>
<h4>A New Equation in Goma</h4>
<p>
Due to time constraints we will be looking at adding a simple equation
</p>
<p>
The Poisson Equation:
</p>
\[ \Delta u = g \]
</section>
<section style="font-size:0.7em">
<h4>Formulation</h4>
<p>
Before we add equations to Goma we want to think about how
we formulate the equations, as an example:
</p>
<p>
The Poisson Equation has two options a single equation
</p>
\[ \Delta u = g \]
<p>
or a mixed form
</p>
\[ \nabla \cdot \omega = g \]
\[ \nabla q = \omega \]
</section>
<section style="font-size:0.7em">
<h4>Choosing a Formulation</h4>
<p> When picking a formulation we might want to consider things like: </p>
<ul>
<li> If a formulation has advantageous boundary conditions </li>
<li> A formulation supports a different solution procedure that is beneficial</li>
</ul>
For simplicity of implementation we will choose the single equation form
\[ \Delta u = g \]
</section>
<section>
<h4>Weighted Residual</h4>
<p>
Equations in Goma are written in a weighted residual form
</p>
<p>
We should do this before we start our implementation so we
understand what boundary conditions might be available and
what we are going to be coding
</p>
</section>
<section>
<h4>Weighted Residual for Poisson</h4>
<p>
First we put our equation in a residual form representing the error. Where \(\bar{u}\) is a new variable
</p>
\[ R(\bar{u},x_i) = \Delta \bar{u} - g \ne 0 \]
<p>
Then we can approximate the equation using a weighting function and
integrating over the domain
</p>
\[ \int_\Omega w(x_i) R(\bar{u},x_i) dV = 0 \]
</section>
<section>
<h4>Weighted Residual for Poisson</h4>
Here we introduce our finite element basis function \(\bar{u} = \sum_j \phi_j u_j\):
\[ \int_\Omega w(x_i) \nabla \cdot \nabla \bar{u} - w(x_i) g \ dV = 0 \]
</section>
<section>
<h4>FEM Weighted Residual for Poisson</h4>
We interpolate our field variable using shape functions \(\bar{u} = \sum_j \phi_i u_i\):
And for Galerkin Finite element we use the same shape functions as weighting functions
\[ \int_\Omega \phi_i \nabla \cdot \nabla \bar{u} - \phi_i g \ dV = 0 \]
<p class="color-maroon">Goma does not support second derivatives using finite element shape functions, instead we integrate by parts</p>
</section>
<section style="font-size:0.6em;">
<h4>FEM Weighted Residual for Poisson</h4>
<div>
<p>
Field variable using shape functions \(\bar{u} = \sum_j \phi_j u_j, \nabla \bar{u} = \sum_j \nabla \phi_j u_j \):
\[ \int_\Omega \phi_i \nabla \cdot \nabla \bar{u} - \phi_i g \ dV = 0 \]
</p>
<p>Use divergence theorem </p>\[\int v (\nabla \cdot u) dV = \int_{dV} v (n \cdot u) d\Gamma - \int \nabla v \cdot u dV\]
We get
\[- \int_\Omega \nabla \phi_i \cdot \nabla \bar{u} - \phi_i g \ dV + \color{rgb(186, 22, 69)}{\int_{d\Omega} \phi_i n \cdot \nabla \bar{u}\ d\Gamma} = 0 \]
</div>
</section>
<section style="font-size:0.8em;">
<h4>FEM weak form for Poisson, Integration by Parts</h4>
<p>Now we have our weak form</p>
\[- \int_\Omega \nabla \phi_i \cdot \nabla \bar{u} - \phi_i g \ dV + \color{rgb(186, 22, 69)}{\int_{d\Omega} n \cdot \nabla \bar{u}\ d\Gamma} = 0 \]
<p>If we omit the boundary term we have a natural boundary condition</p>
\[- \int_\Omega \nabla \phi_i \cdot \nabla \bar{u} - \phi_i g \ dV = 0 \implies \color{rgb(186, 22, 69)}{\int_{d\Omega} \phi_i n \cdot \nabla \bar{u}\ d\Gamma = 0} \]
</section>
<section>
<h4>Steps to add an equation</h4>
<p>Recipe with details available in <code>mm_fill_shell.c</code></p>
<p>Abridged version in these slides</p>
</section>
<section>
<h4>Step 1: Add Macros for Variable/Equation</h4>
<p><code class="color-maroon">rf_fem_const.h</code></p>
<p>Add macros for Poisson variable and equation</p>
<p>Usually we add to the end of the list of equations (might want to search and make sure names are available)</p>
<pre><code data-trim data-noescape class="c">
#define POISSON <num>
...
#define R_POISSON <num>
#define V_LAST <num+1>
</code></pre>
</section>
<section>
<h3>Step 2: Adjust initializer lists</h3>
<div style="font-size: 0.75em;">
<p><code class="color-maroon">mm_names.h</code></p>
<p>Add initializations in <code>EQ_Name</code>, <code>Var_Name</code>, <code>Exo_Var_Names</code>, and <code>Var_Units</code></p>
<p>These are important for I/O such as exodus reading/output and special boundary conditions such as GD_PARAB</p>
<p>Try to be consistent, we will choose:</p>
</div>
<pre><code data-trim data-noescape class="c">
"POISSON" "R_POISSON" "U"
</code></pre>
</section>
<section>
<h4>Step 3: Entries for Field Variables</h4>
<p><code class="color-maroon">mm_as_structs.h</code></p>
Add entries for the following structs:
<pre style="font-size: 0.5em;"><code data-trim data-noescape class="c">
Element_Stiffness_Pointers // pointers into solution vector
Element_Variable_Pointers // pointers into "other" solutions (x_old)
Field_Variables // Values at current iteration u^n / grad u^n
Diet_Field_Variables // Values at other e.g. u^(n-1) / grad u^(n-1)
</code></pre>
<code>esp->u evp->u fv->u fv->grad_u[DIM] fv->d_grad_u_dmesh[DIM][DIM][MDE]</code>
</section>
<section>
<h4>Step 4: Allocate space</h4>
<p>
<code class="color-maroon">mm_as_alloc.c</code>
</p>
<p>
We need to allocate space for
</p>
<pre><code>Element_Stiffness_Pointers</code></pre>
<p>
if the equation is enabled.
</p>
</section>
<section>
<h4>Step 5: Load stiffness pointers</h4>
<p>
<code class="color-maroon">mm_fill_ptrs.c</code>
</p>
<p>
In <code class="color-indigo">load_elem_dofptr()</code> add a new call to <code class="color-indigo">load_varType_Interpolation_ptrs()</code> to populate <code>esp</code>
</p>
</section>
<section>
<h4>Step 6: load_variable</h4>
<p>
<code class="color-maroon">bc_colloc.c</code>
</p>
<p>
In <code class="color-indigo">load_variable()</code> add a case for your new variable
</p>
</section>
<section>
<h4>Step 7a: Equation Specification</h4>
<p>
<code class="color-maroon">mm_input.c</code>
</p>
<p>
In <code class="color-indigo">rd_eq_specs()</code> add <code class="color-indigo">set_eqn()</code> call for your equation
</p>
<p>
In <code class="color-indigo">rd_eq_specs()</code> add <code class="color-indigo">set_var()</code> call for your variable
</p>
These are important for the equation section in goma
<pre style="font-size: 0.5em;"><code data-trim data-noescape class="c">
EQ = momentum1 Q1 U1 Q1 1. 1. 1. 1. 1. 0.
equation var ms adv bnd dif src por
</code></pre>
<p>
We will pick <code class="color-taupe">"poisson"</code> and <code class="color-taupe">"u"</code>
</p>
</section>
<section>
<h4>Step 7b: Equation Specification</h4>
<p>
<code class="color-maroon">mm_input.c</code>
</p>
<p>
Decide on equation term multipliers, for Poisson it probably makes sense to have
<span class="color-green">diffusion</span>, <span class="color-maroon">boundary</span>, and <span class="color-indigo">source</span> as we have 3 terms
</p>
<pre style="font-size: 0.5em;"><code data-trim data-noescape data-line-numbers=2 class="c">
EQ = momentum1 Q1 U1 Q1 1. 1. 1. 1. 1. 0.
EQ = poisson Q1 U Q1 1. 1. 1.
equation var ms adv bnd dif src por
</code></pre>
\[- \int_\Omega \color{rgb(113, 140, 0)}{\nabla \phi_i \cdot \nabla \bar{u}} - \color{rgb(18, 76, 112)}{\phi_i g} \ dV + \int_{d\Omega} \color{rgb(186, 22, 69)}{\phi_i n \cdot \nabla \bar{u}}\ d\Gamma = 0 \]
<p>
</p>
</section>
<section>
<h4>Step 7c: Equation Specification</h4>
<p>
<code class="color-maroon">mm_input.c</code>
</p>
<pre style="font-size: 0.5em;"><code data-trim data-noescape data-line-numbers=2 class="c">
EQ = poisson Q1 U Q1 1. 1. 1.
</code></pre>
<p>
Read in your equation term multipliers in <code class="color-indigo">rd_eq_specs()</code>
</p>
</section>
<section>
<h4>Step 8: Variable String to int</h4>
<p>
<code class="color-maroon">mm_input_util.c</code>
</p>
<p>
Add conversion from variable string to your declared variable in <code class="color-indigo">variable_string_to_int()</code>
</p>
<p>
<pre><code>"POISSON" -> POISSON</code></pre>
</p>
</section>
<section>
<h4>Step 9: Set up pd</h4>
<p>
<code class="color-maroon">mm_prob_def.c</code>
</p>
<p>
Add lines to set member <code class="color-green">e</code> based on etm <code class="color-indigo">setup_pd()</code>
</p>
<p>
These are bitwise or's to enable terms, refer to many examples
</p>
</section>
<section>
<h4>Step 10a: Load Field Variables</h4>
<p>
<code class="color-maroon">mm_fill_terms.c</code>
</p>
<p>
Fill your field variables using <code>esp</code> <code class="color-indigo">load_fv()</code>
</p>
<p>
\[ \bar{u} = \sum_j \phi_j u_j \]
</p>
</section>
<section>
<h4>Step 10b: Load Field Variables</h4>
<p>
<code class="color-maroon">mm_fill_terms.c</code>
</p>
<p>
Fill your gradient field variables using <code>esp</code> <code class="color-indigo">load_fv_grad()</code>
</p>
<p>
\[ \nabla \bar{u} = \sum_j \nabla \phi_j u_j \]
</p>
</section>
<section>
<h4>Step 10c: Load Field Variables</h4>
<p>
<code class="color-maroon">mm_fill_terms.c</code>
</p>
<p>
Fill your mesh derivative field variables using <code>esp</code> <code class="color-indigo">load_fv_mesh_derivs()</code>
</p>
<p>
\[ \frac{\partial}{\partial d}\nabla \bar{u} = \sum_j \frac{\partial}{\partial d}\nabla \phi_j u_j \]
</p>
</section>
<section>
<h4>Step 11: Variable Sensitivity</h4>
<p>
<code class="color-maroon">mm_flux.c</code>
</p>
<p>
Add your new variable to <code class="color-indigo">load_fv_sens()</code>
</p>
</section>
<section>
<h4>Step 12: Interactions</h4>
<p>
<code class="color-maroon">mm_unknown_map.c</code>
</p>
<ol>
<li>
<p>
In <code class="color-indigo">set_interaction_masks()</code> add your new variable to any other variables it will have interactions with
</p>
</li><li>
<p>Add a new case with interactions for your variable
</p>
</li>
<li>
<p>Mesh displacements are almost universally expected unless moving mesh will never be used
</p>
</li>
</ol>
</section>
<section>
<h4>Step 12: Add LSA mesh deriv modifications</h4>
<p>
<code class="color-maroon">ac_stability_util.c</code>
</p>
<p>
In <code class="color-indigo">modify_fv_mesh_derivs_for_LSA_3D_of_2D()</code> add your gradient field variable if you added mesh derivatives for a gradient
</p>
</section>
<section>
<h4>Step 13a: Add a new Assembly function for your equation</h4>
<p>
The majority of assembly functions are in
<code class="color-maroon">mm_fill_terms.c</code>
</p>
<p>
This file is quite bloated and we want to avoid adding to that so lets create new files <code class="color-indigo">src/mm_fill_poisson.c</code> and <code class="color-indigo">include/mm_fill_poisson.h</code>
</p>
</section>
<section>
<h4>Step 13b: Add a new Assembly function for your equation</h4>
<p>
Add the new files to the <code class="color-maroon">Makefile</code>
</p>
</section>
<section>
<h4>Step 13c: Add a new Assembly function for your equation</h4>
<p>
Add a header guard to <code class="color-maroon">mm_fill_poisson.h</code> to ensure the header is only loaded once
</p>
<p>
Add an initial prototype for our assembly
</p>
<pre><code data-trim data-noescape class="c">
#ifndef GOMA_MM_FILL_POISSON
#define GOMA_MM_FILL_POISSON
extern int assemble_poisson(void);
#endif // GOMA_MM_FILL_POISSON
</code></pre>
</section>
<section>
<h4>Step 13d: Add a new Assembly function for your equation</h4>
<p>
Add assembly function in <code class="color-maroon">mm_fill_poisson.c</code>
Include header files as needed
</p>
<pre style="font-size:0.6em;"><code data-trim data-noescape class="c">
#include "goma.h" // catch all would prefer
// to use required headers instead
// but can take a while by hand
#include "mm_as.h" // ei, pd
#include "mm_as_structs.h" // field variables
#include "mm_fill_poisson.h"
int assemble_poisson(void) {
return 0;
}
</code></pre>
</section>
<section>
<h4>Step 13e: Add a new Assembly function for your equation</h4>
<p style="font-size:0.8em">
Add Section for Residual assembly in <code class="color-maroon">mm_fill_poisson.c</code>
</p>
<pre style="font-size:0.6em;"><code data-trim data-noescape class="c">
int assemble_poisson(void) {
if (af->Assemble_Residual) {
}
</code></pre>
\[R_i = R_i -(\nabla \phi_i \cdot \nabla \bar{u} - \phi_i g ) g_{wt} d_{vol} h_3 \ \]
\[g = -10 exp(-((x-0.5)^2+(y-0.5)^2)/0.02) \]
</section>
<section>
<h4>Step 13f: Add a new Assembly function for your equation</h4>
<p style="font-size:0.8em">
Add Section for Jacobian assembly in <code class="color-maroon">mm_fill_poisson.c</code>
</p>
<pre style="font-size:0.6em;"><code data-trim data-noescape class="c">
if (af->Assemble_Jacobian) {
</code></pre>
\[\bar{u} = \sum_j\phi_j u_j,\ \nabla \bar{u} = \sum_j \nabla \phi_j u_j \]
\[R_i = R_i -(\nabla \phi_i \cdot \nabla \bar{u} - \phi_i g ) g_{wt} d_{vol} h_3 \ \]
</section>
<section>
<h4>Step 13g: Add assembly to matrix fill</h4>
<p style="font-size:0.8em">
Add a call to your assembly in <code class="color-maroon">mm_fill.c</code>
</p>
<pre style="font-size:0.6em;"><code data-trim data-noescape class="c">
if( pde[R_POISSON] ) {
err = assemble_poisson();
EH( err, "assemble_poisson");
#ifdef CHECK_FINITE
err = CHECKFINITE("assemble_poisson");
if (err) return -1;
#endif
}
</code></pre>
</section>
<section>
<h4>Testing with GD BCs</h4>
<p>We can actually still test before adding boundary conditions
as we have GD BCs which can act as Dirichlet conditions for us.
</p>
</section>
<section>
<h4>Test 1: Laplace in X direction</h4>
<p> In a 1x1 box we use natural boundary conditions
on top and bottom \(n\cdot \nabla u = 0\)<p>
<pre style="font-size:0.5em;"><code data-trim data-noescape class="c">
# Right SS 2 NS 2
BC = GD_LINEAR SS 2 R_POISSON 0 POISSON 0 -1.0 1.0
# Left SS 4 NS 4
BC = GD_LINEAR SS 4 R_POISSON 0 POISSON 0 -2.0 1.0
...
Number of EQ = -1
# disable source term
EQ = poisson Q1 U Q1 1.0 1.0 0.0
END OF EQ
ms adv bnd dif src por
</code></pre>
</section>
<section>
<h4>Test 1: Laplace in X direction</h4>
<div class="container">
<div class="col">
<img width=60%" data-src="./images/laplace_x.png" />
</div>
</div>
</section>
<section>
<h4>Test 2: Laplace in Y direction</h4>
<p> In a 1x1 box we use natural boundary conditions
on left and right \(n\cdot \nabla u = 0\)<p>
<pre style="font-size:0.5em;"><code data-trim data-noescape class="c">
# Top SS 1 NS 1
BC = GD_LINEAR SS 1 R_POISSON 0 POISSON 0 -1.0 1.0
# Top SS 3 NS 3
BC = GD_LINEAR SS 3 R_POISSON 0 POISSON 0 -2.0 1.0
...
Number of EQ = -1
# disable source term
EQ = poisson Q1 U Q1 1.0 1.0 0.0
END OF EQ
ms adv bnd dif src por
</code></pre>
</section>
<section>
<h4>Test 2: Laplace in Y direction</h4>
<div class="container">
<div class="col">
<img width=60%" data-src="./images/laplace_y.png" />
</div>
</div>
</section>
<section>
<h4>Test 3: Poisson with Dirichlet</h4>
<p> In a 1x1 box we use natural boundary conditions
on top and bottom \(n\cdot \nabla u = 0\)<p>
<pre style="font-size:0.5em;"><code data-trim data-noescape class="c">
# Right SS 2 NS 2
BC = GD_LINEAR SS 2 R_POISSON 0 POISSON 0 -1.0 1.0
# Left SS 4 NS 4
BC = GD_LINEAR SS 4 R_POISSON 0 POISSON 0 -2.0 1.0
...
Number of EQ = -1
# disable source term
EQ = poisson Q1 U Q1 1.0 1.0 1.0
END OF EQ
ms adv bnd dif src por
</code></pre>
</section>
<section>
<h4>Test 3: Poisson with Dirichlet</h4>
<div class="container">
<div class="col">
<img width=40%" data-src="./images/poisson_gd.png" />
</div>
</div>
</section>
<section>
<h4>Step 14: Add Necessary Boundary Conditions</h4>
<p> This will bring us into our next step in the training </p>
<p> We cannot run equations without boundary conditions unless
they are satisfiable with natural boundary conditions</p>
</section>
<section>
<h2>Types of Boundary Conditions in Goma</h2>
</section>
<section>
<h4>Types of Boundary Conditions in Goma</h4>
<p> Goma contains a plethora of boundary conditions </p>
<p>
<ul>
<li>Dirichlet</li>
<li>Neumann</li>
<li>Robin</li>
<li>Many Special cases.</li>
</ul>
</p>
</section>
<section>
<h4>Examples of BCs: Dirichlet</h4>
<p>Dirichlet are usually pretty straight forward, we specify the value at a boundary or point</p>
<p>This will be the first BC we usually implement. Examples include:</p>
<p>
<ul>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#uvw">U,V,W: Momentum</a></li>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#t">T: Energy</a></li>
</ul>
</p>
</section>
<section style="font-size: 0.7em">
<h4>Examples of BCs: Neumann</h4>
<p>Neumann BCs are the second type of BCs and we specify the derivative vs. specifying the value.</p>
<p>These are very common in FEM as we usually have an "integration by parts" where the
boundary term is in the form \(n \cdot \nabla u\)<p>
<p>The natural boundary condition is often a Neumann condition where we are specifying the derivative
to be zero. Examples:</p>
<p>
<ul>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#qside">QSIDE: Energy</a></li>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#yflux-const">YFLUX_CONST: Species</a></li>
</ul>
</p>
</section>
<section>
<h4>Examples of BCs: Robin</h4>
<p>Robin BCs are the third type of BCs and are a combination of Dirichlet and Neumann<p>
<p>Often take a form \(n \cdot \nabla u = h(u - u_{ref})\)<p>
<p>
Examples:
<ul>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#qconv">QCONV: Energy</a></li>
<li><a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#yflux">YFLUX: Species</a></li>
</ul>
</p>
</section>
<section style="font-size: 0.7em">
<h4>Strong vs Weak BCs</h4>
<p>Goma has a notion of <b>Strong</b> and <b>Weak</b> boundary conditions<p>
<p>
<ul>
<li><b>Strong</b>: is applied in a way such that we overwrite contributions
of the equation, e.g. <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#velo-normal">VELO_NORMAL</a>, <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#kinematic">KINEMATIC</a> \[R_i = \int_{d\Omega} \text{BIG_PENALTY} (\phi^j n\cdot v - g) = 0 \]</li>
<li><b>Weak</b>: is instead the more typical BC where we are replacing the natural boundary condition with an integrated BC like Neumann or Robin
\[\int_{d\Omega} \phi_i n \cdot \nabla u = \int_{d\Omega} \phi_i f\] </li>
</ul>
</p>
</section>
<section style="font-size: 0.7em">
<h4>Special Cases</h4>
<p>There are a number of special cases in Goma<p>
<p>
<ul>
<li><b>Embedded</b>: Applied on a diffuse interface (level-set)
e.g. <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#ls-capillary">LS_CAPILLARY</a></li>
<li><b>Collocated</b>: Strong conditions at nodes, often Dirichlet-like, applied using collocation instead of Galerkin approach e.g. <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#gd-parab">GD_PARAB</a>, <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#kinematic-colloc">KINEMATIC_COLLOC</a>, <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#plane">PLANE</a></li>
<li><b>Special</b>: BCs which don't fit in with normal methods, <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#cap-endforce">CAP_ENDFORCE</a></li>
<li><b>Rotated</b>: BCs which require equations like mesh and momentum to be rotated into normal and tangential coordinate systems, <a href="https://docs.gomafem.com/problem_description_file/boundary_conditions.html#velo-normal">VELO_NORMAL</a></li>
</ul>
</p>
</section>
<section>
<h2>Adding a Dirichlet Condition</h2>
</section>
<section>
<h4>Dirichlet Condition: Step 1</h4>
Add new constant to <code class="color-maroon">rf_bc_const.h</code>
<pre><code>#define POISSON_BC <uniq num></code></pre>
</section>
<section>
<h4>Dirichlet Condition: Step 2</h4>
Add BC to Initializer list in <code class="color-maroon">mm_names.h</code>
<pre style="font-size: 0.6em"><code data-trim data-noescape>
{ "POISSON", "POISSON_BC", DIRICHLET, POISSON_BC,
R_POISSON, SCALAR, NO_ROT, {0,...0,1}, SINGLE_PHASE,
DVI_SINGLE_PHASE_DB }</code></pre>
</section>
<section>
<h4>Dirichlet Condition: Step 3</h4>
<p>
Add BC to Dirichlet BC case in <code class="color-maroon">mm_input_bc.c</code>
</p>
<p> You can now use the Dirichlet BC</p>
</section>
<section>
<h4>Test Dirichlet</h4>
<p> We can modify our previous Poisson test to now use Dirichlet instead of GD</p>
<pre style="font-size:0.5em;"><code data-trim data-noescape class="shell">
# Right SS 2 NS 2
#BC = GD_LINEAR SS 2 R_POISSON 0 POISSON 0 -1.0 1.0
BC = POISSON NS 2 1.0
# Left SS 4 NS 4
#BC = GD_LINEAR SS 4 R_POISSON 0 POISSON 0 -2.0 1.0
BC = POISSON NS 4 2.0
</code></pre>
</section>
<section>
<h4>Test Dirichlet</h4>
<div class="col">
<img width=40%" data-src="./images/poisson_gd.png" />
</div>
</section>
<section>
<h2>Adding a Neumann/Robin Condition</h2>
</section>
<section>
<h4>Neumann Condition Step 1</h4>
Add new constant to <code class="color-maroon">rf_bc_const.h</code>
<pre><code>#define POISSON_SIDE_SIN_BC <uniq num></code></pre>
</section>
<section>
<h4>Neumann Condition Step 2</h4>
<p>
Add to Initializer list in <code class="color-maroon">mm_names.h</code>
</p>
<pre><code>#define POISSON_SIDE_SIN_BC <uniq num></code></pre>
<pre style="font-size: 0.6em"><code data-trim data-noescape>
{ "POISSON_SIDE_SIN", "POISSON_SIDE_SIN_BC", WEAK_INT_SURF,
POISSON_SIDE_SIN_BC, R_POISSON, SCALAR, NO_ROT, {0,...0,1},
SINGLE_PHASE, DVI_SINGLE_PHASE_DB }</code></pre>
</section>
<section>
<h4>Neumann Condition Step 3</h4>
<p>
Read input in <code class="color-maroon">mm_input_bc.c</code>
</p>
<p>
We want to read five floats \(\alpha, \beta, \gamma, \omega, \zeta\)
</p>
\[ n\cdot \nabla u = \alpha sin(\beta x + \gamma y + \omega z) + \zeta \]
</section>
<section>
<h4>Neumann Condition Step 4</h4>
<p>
Make a new BC function in <code class="color-maroon">mm_fill_poisson.c</code>
</p>
\[ n\cdot \nabla u = \alpha sin(\beta x + \gamma y + \omega z) + \zeta \]
<pre style="font-size: 0.6em"><code data-trim data-noescape class="c">
void
poisson_side_sin_bc(dbl func[DIM],
dbl d_func[DIM][MAX_VARIABLE_TYPES + MAX_CONC][MDE],
dbl alpha, dbl beta, dbl gamma, dbl omega, dbl zeta) {...}
</code></pre>
</section>
<section>
<h4>Neumann Condition Step 5</h4>
<p>
Add declaration to header <code class="color-maroon">mm_fill_poisson.h</code>
</p>
<pre style="font-size: 0.6em"><code data-trim data-noescape class="c">
void
poisson_side_sin_bc(dbl func[DIM],
dbl d_func[DIM][MAX_VARIABLE_TYPES + MAX_CONC][MDE],
dbl alpha, dbl beta, dbl gamma, dbl omega, dbl zeta);
</code></pre>
</section>
<section>
<h4>Neumann Condition Step 6</h4>
<p>
Add call to switch for BC in <code class="color-maroon">bc_integ.c</code>
</p>
<p>
You can now use your Neumann BC
</p>
</section>
<section>
<h4>Test Neumann condition</h4>
<p>Top and bottom we want \(n \cdot \nabla = sin(5x)\), left and right \(u = 0\)</p>
<pre style="font-size: 0.6em"><code data-trim data-noescape class="c">
# Bottom SS 1 NS 1
BC = POISSON_SIDE_SIN SS 1 1.0 5.0 0.0 0.0 0.0
# Right SS 2 NS 2
BC = POISSON NS 2 0.0
# Top SS 3 NS 3
BC = POISSON_SIDE_SIN SS 3 1.0 5.0 0.0 0.0 0.0
# Left SS 4 NS 4
BC = POISSON NS 4 0.0
</code></pre>
</section>
<section>
<h4>Test Neumann condition</h4>
<div class="col">
<img width=40%" data-src="./images/poisson_full.png" />
</div>
</section>
<section>
<h4>Notes on adding other boundary conditions</h4>
<p>
There are many examples, usually the first thing you should look
for is a near-by example.
</p>
<p>
Adding a <b>Strong</b> condition should be the same as Neumann only
now you are using <b>STRONG_INT_SURF</b> in <code>mm_names.h</code>,
they are still called in <code class="color-indigo">apply_integrated_bc()</code>
</p>
<p>
Other BCs should follow a similar process but may not be added to <code class="color-maroon">bc_integ.c</code>
but <code class="color-maroon">bc_colloc.c</code> or one of the other BC files
</p>
</section>
<section>
<h2>Adding a Material Property</h2>
</section>
<section>
<h4>Adding a Material Property</h4>
<p> Material properties are added so that we do not have to hard code values
in our assemblies.</p>
<p> For our Poisson equation we will add a <code>Poisson Source</code> card
which lets us read in either a constant (which would be useful to set to 0 for Laplace Equation)
and our exponential source term</p>
</section>
<section>
<h4>Step 1: Material Property</h4>
<code class="color-maroon">mm_mp_structs.h</code>
<p>
Add needed values to <code class="color-green">struct Material_Properties</code>
</p>
<pre style="font-size: 0.6em"><code data-trim data-noescape>
dbl poisson_source;
int poissonSourceModel;
int len_u_poisson_source;
dbl *u_poisson_source;
</code></pre>
</section>
<section>
<h4>Step 2: Material Property</h4>
<code class="color-maroon">dp_vif.c</code>
<p>
Add communication of the material properties to the various functions
</p>
<p>There are many examples</p>
<p>If you have an allocation make sure that is communicated and allocated on all processors</p>
</section>
<section>
<h4>Step 3: Material Property</h4>
<code class="color-maroon">mm_mp_const.h</code>
<p>
Add new constant for your model
</p>
<pre style="font-size: 0.6em"><code data-trim data-noescape>
// CONSTANT is 1 so we do not want to use that to differentiate
#define POISSON_EXP 0
</code></pre>
</section>
<section>
<h4>Step 4a: Material Property</h4>
<code class="color-maroon">mm_input_mp.c</code>
<p>Read in your new material property</p>
<p>By default <code class="color-indigo">look_for_mat_prop()</code> will look for CONSTANT
properties so we only need to add special cases</p>
</section>
<section style="font-size: 0.5em">
<h4>Step 4b: Material Property</h4>
<code class="color-maroon">mm_input_mp.c</code>
<p>Source is \(g = \alpha exp(-((x-\beta)^2+(y-\gamma)^2 + (z-\omega)^2))/\zeta) \)
so we want 5 constants \(\alpha,\beta,\gamma,\omega,\zeta\)</p>
<pre ><code data-trim data-noescape>
if ( !strcmp(model_name, "EXP") )
{
poissonSourceModel = POISSON_EXP;
model_read = 1;
mat_ptr->poissonSourceModel = PoissonSourceModel;
num_const = read_constants(imp, &(mat_ptr->u_poisson_source),
NO_SPECIES);
if (num_const != 5) {