svZeroDSolver
Loading...
Searching...
No Matches
DOFHandler.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the
2// University of California, and others. SPDX-License-Identifier: BSD-3-Clause
3/**
4 * @file DofHandler.h
5 * @brief model::DOFHandler source file
6 */
7#ifndef SVZERODSOLVER_MODEL_DOFHANDLER_HPP_
8#define SVZERODSOLVER_MODEL_DOFHANDLER_HPP_
9
10#include <map>
11#include <string>
12#include <vector>
13
14/**
15 * @brief Degree-of-freedom handler.
16 *
17 * This class handles degrees-of-freedom for model variables and
18 * equations. It assigns each element with row and column indices which it
19 * can use to assemble it's local contributions into the global system.
20 */
22 private:
23 int var_counter{0}; ///< Variable counter
24 int eqn_counter{0}; ///< Equation counter
25
26 public:
27 std::vector<std::string>
28 variables; ///< Variable names corresponding to the variable indices
29 std::map<std::string, int>
30 variable_name_map; ///< Map between variable name and index
31 std::vector<std::string>
32 equations; ///< Equation names corresponding to the equation indices
33 std::vector<std::string>
34 output_variables; ///< Post-processing variables, at the state tail
35
36 /**
37 * @brief Get the number of equations, the size of the solved system
38 *
39 * @return int Number of equations
40 */
41 int get_num_equations() const;
42
43 /**
44 * @brief Get the number of post-processing variables
45 *
46 * @return int Number of post-processing variables
47 */
48 int get_num_output_variables() const;
49
50 /**
51 * @brief Get the number of variables
52 *
53 * @return int Number of variables
54 */
55 int get_num_variables() const;
56
57 /**
58 * @brief Register a new variable at the DOFHandler.
59 *
60 * @param name Name of the variable
61 * @return Global index of the variable
62 */
63 int register_variable(const std::string& name);
64
65 /**
66 * @brief Register a new post-processing variable at the DOFHandler.
67 *
68 * Such a variable is in the state vector and in the output, but has no
69 * equation: no row, no column, never solved for. The owning block computes
70 * it in Block::update_outputs. They occupy the tail of the state vector so
71 * the solved system stays a leading square block, which Model::finalize
72 * arranges with a second registration pass.
73 *
74 * @param name Name of the variable
75 * @return Global index of the variable
76 */
77 int register_output_variable(const std::string& name);
78
79 /**
80 * @brief Get the index of a variable by its name
81 *
82 * @param name Name of the variable
83 * @return int Name of the variable
84 */
85 int get_variable_index(const std::string& name) const;
86
87 /**
88 * @brief Register a new equation at the DOFHandler
89 *
90 * @param name Name of the equation
91 * @return Global index of the equation
92 */
93 int register_equation(const std::string& name);
94
95 /**
96 * @brief Get the index of a variable
97 *
98 * @param name Name of the variable
99 * @return Index of variable with given name
100 */
101 int get_index(const std::string_view& name) const;
102};
103
104#endif // SVZERODSOLVER_MODEL_DOFHANDLER_HPP_
Degree-of-freedom handler.
Definition DOFHandler.h:21
int register_variable(const std::string &name)
Register a new variable at the DOFHandler.
Definition DOFHandler.cpp:16
int get_index(const std::string_view &name) const
Get the index of a variable.
Definition DOFHandler.cpp:41
int get_num_equations() const
Get the number of equations, the size of the solved system.
Definition DOFHandler.cpp:8
std::vector< std::string > variables
Variable names corresponding to the variable indices.
Definition DOFHandler.h:28
int get_num_variables() const
Get the number of variables.
Definition DOFHandler.cpp:10
std::vector< std::string > equations
Equation names corresponding to the equation indices.
Definition DOFHandler.h:32
int get_variable_index(const std::string &name) const
Get the index of a variable by its name.
Definition DOFHandler.cpp:22
int register_equation(const std::string &name)
Register a new equation at the DOFHandler.
Definition DOFHandler.cpp:36
std::vector< std::string > output_variables
Post-processing variables, at the state tail.
Definition DOFHandler.h:34
std::map< std::string, int > variable_name_map
Map between variable name and index.
Definition DOFHandler.h:30
int register_output_variable(const std::string &name)
Register a new post-processing variable at the DOFHandler.
Definition DOFHandler.cpp:31
int get_num_output_variables() const
Get the number of post-processing variables.
Definition DOFHandler.cpp:12