Chi-Tech
devman_A3_UnknownMan.h
Go to the documentation of this file.
1/**\page DevManUKMan The chi_math::UnknownManager
2## Table of contents
3- \ref devmanA3_sec0
4- \ref devmanA3_sec1
5- \ref devmanA3_sec2
6- \ref devmanA3_sec3
7- \ref devmanA3_sec4
8
9
10\section devmanA3_sec0 Introduction
11As a developer you might come across code such as
12\code
13imap[i] = sdm.MapDOF(cell, i);
14\endcode
15or its more elaborate cousin
16\code
17const int64_t imap = m_sdm.MapDOF(cell,i,m_uk_man,0,g);
18\endcode
19
20The two function calls, `MapDOF` with 2 arguments and `MapDOF` with 5 arguments,
21are both methods of the base-class `chi_math::SpatialDiscretization`.
22
23The two overloaded methods, `chi_math::SpatialDiscretization::MapDOF` return the
24global index of a degree-of-freedom (DOF). The counterparts to `MapDOF` are the
25`MapDOFLocal` methods that provide the local index of a DOF.
26
27These functions are called with either 2 arguments
28- A cell reference
29- A cell-node local-index
30
31or with 5 arguments
32- A cell reference
33- A cell-node local-index
34- An unknown-manager (`chi_math::UnknownManager`)
35- An unknown id
36- A component id
37
38\section devmanA3_sec1 1 Cells vs Vertices vs Nodes vs Degree-of-Freedom (DOF)
39These comparisons are conceptually simple. The geometry of a cell is described
40by its vertices (see Figure 1 below). The mesh cannot be completely defined
41without the vertices, therefore, cells always go hand-in-hand with vertices.
42
43A spatial discretization (e.g., Finite Volume, PWL, Lagrange Q1, Lagrange Q2)
44places nodes on the mesh that may or may not coincide with some of the vertices.
45For example, the Finite Volume spatial discretization places a single node for
46each cell, at the cell's centroid (hence no coincidence with any vertex), whilst
47a Lagrange Q2 spatial discretization has some of its nodes on the vertices while
48other are not (see Figure 1 below).
49
50\image html UkManVertsNodes.png "Figure 1: Cells, vertices and nodes." width=600px
51
52Where degrees-of-freedom differ from nodes is that each node can be stacked with
53a number of unknowns, e.g., one might have to solve a number of physical
54variables in a multiphysics simulation involving 2D velocity, \f$ u_x \f$ and
55\f$ u_y \f$, a three energy group flux, \f$ \phi_0, \ \phi_1, \ \phi_2 \f$, and
56pressure, \f$ p \f$. One can stack these variables in any form, for example:
57- Unknown 0, a 6 component vector containing
58\f$ u_x, \ u_y, \ \phi_0, \ \phi_1, \ \phi_2 \f$, and \f$ p \f$
59
60or more elegantly
61- Unknown 0, a 2 component vector containing \f$ u_x \f$ and \f$ u_y \f$
62- Unknown 1, a 3 component vector containing \f$ \phi_0, \ \phi_1, \ \phi_2 \f$
63- Unknown 2, a single scalar (1 component) containing just \f$ p \f$
64
65The latter essentially means that each node can have a number of unknowns stacked
66onto it as shown in Figure 2 below.
67
68\image html UkManNodeDOFs.png "Figure 2: Unknowns/DOFs stacked onto a node" width=300px
69
70The individual components of the unknowns are unique for every node and are
71called the degrees-of-freedom (DOFs).
72
73\section devmanA3_sec2 2 One DOF per node
74All the spatial discretizations have a default unknown-manager, defined during
75initialization, called `UNITARY_UNKNOWN_MANAGER`. This allows the spatial
76discretization to map indices as shown in Figure 3 below
77
78\image html UkMan-OneDOFPN.png "Figure 3: Mapping One DOF per Node" width=800px
79
80\section devmanA3_sec3 3 Multiple DOFs Nodal ordering
81With multiple unknowns like the 2D velocity, multigroup flux, and pressure
82example above we can create an unknown manager with this structure as follows
83\code
84chi_math::UnknownManager uk_man;
85uk_man.AddUnknown(chi_math::UnknownType::VECTOR_2); //u_x, u_y
86uk_man.AddUnknown(chi_math::UnknownType::VECTOR_N, 3); //phi_0 to phi_2
87uk_man.AddUnknown(chi_math::UnknownType::SCALAR); //pressure
88\endcode
89
90Using this unknown manager to map DOFs is then done as shown below in Figure 4.
91
92\image html UkMan-NODAL.png "Figure 4: Mapping with a nodal ordering" width=800px
93
94Notice here that the ordering is per-node, i.e., for each node the DOFs all the
95DOFs are stacked into a vector before moving to a new node. This is the default
96ordering in ChiTech.
97
98\section devmanA3_sec4 4 Multiple DOFs Block ordering
99To create a Block-ordered vector mapping the only modification needed is in the
100constructor of the unknown manager:
101\code
102chi_math::UnknownManager uk_man(chi_math::UnknownStorageType::BLOCK);
103uk_man.AddUnknown(chi_math::UnknownType::VECTOR_2); //u_x, u_y
104uk_man.AddUnknown(chi_math::UnknownType::VECTOR_N, 3); //phi_0 to phi_2
105uk_man.AddUnknown(chi_math::UnknownType::SCALAR); //pressure
106\endcode
107
108Now that we specified that we should use `chi_math::UnknownStorageType::BLOCK`
109the unknown manager maps as shown in Figure 5 below
110
111\image html UkMan-Block.png "Figure 5: Mapping with a block ordering" width=800px
112
113Block ordering is likely desireable if one wishes to apply block-solves.
114 */