svZeroDSolver
Loading...
Searching...
No Matches
ParameterHolder.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/**
5 * @file ParameterHolder.h
6 * @brief Common base for chamber sub-components configured from input
7 * parameters
8 */
9
10#ifndef SVZERODSOLVER_MODEL_PARAMETERHOLDER_HPP_
11#define SVZERODSOLVER_MODEL_PARAMETERHOLDER_HPP_
12
13#include <map>
14#include <string>
15#include <utility>
16#include <vector>
17
18#include "Parameter.h"
19
20/**
21 * @brief Base class for chamber sub-components (activation functions,
22 * materials, active stress models) that are configured from scalar/vector
23 * input parameters read from the JSON input file.
24 */
26 public:
27 /**
28 * @brief Properties of the input parameters for this component
29 * [(name, InputParameter), ...]
30 */
31 const std::vector<std::pair<std::string, InputParameter>>
33
34 /**
35 * @brief Construct a ParameterHolder
36 *
37 * @param props Parameter name/spec pairs for this component, used to
38 * initialize params_/params_vec_ with default values
39 */
40 explicit ParameterHolder(
41 const std::vector<std::pair<std::string, InputParameter>>& props);
42
43 virtual ~ParameterHolder() = default;
44
45 /**
46 * @brief Set a scalar parameter value by name.
47 *
48 * Calling function must validate the parameter name and value.
49 *
50 * @param name Parameter name
51 * @param value Parameter value
52 */
53 void set_param(const std::string& name, double value);
54
55 /**
56 * @brief Set a vector-valued parameter value by name.
57 *
58 * Calling function must validate the parameter name and value.
59 *
60 * @param name Parameter name
61 * @param value Parameter value
62 */
63 void set_param_vector(const std::string& name,
64 const std::vector<double>& value);
65
66 /**
67 * @brief Called once after all parameters have been read from the input
68 * file (e.g. by the loader).
69 *
70 * Default no-op; subclasses override to validate the parameters they were
71 * given or precompute derived values (e.g. normalization constants).
72 */
73 virtual void finalize() {}
74
75 protected:
76 /**
77 * @brief Map of scalar parameter names to their values
78 */
79 std::map<std::string, double> params_;
80
81 /**
82 * @brief Map of vector-valued parameter names to their values
83 */
84 std::map<std::string, std::vector<double>> params_vec_;
85};
86
87#endif // SVZERODSOLVER_MODEL_PARAMETERHOLDER_HPP_
model::Parameter source file
virtual void finalize()
Called once after all parameters have been read from the input file (e.g. by the loader).
Definition ParameterHolder.h:73
std::map< std::string, double > params_
Map of scalar parameter names to their values.
Definition ParameterHolder.h:79
std::map< std::string, std::vector< double > > params_vec_
Map of vector-valued parameter names to their values.
Definition ParameterHolder.h:84
ParameterHolder(const std::vector< std::pair< std::string, InputParameter > > &props)
Construct a ParameterHolder.
Definition ParameterHolder.cpp:5
const std::vector< std::pair< std::string, InputParameter > > input_param_properties
Properties of the input parameters for this component [(name, InputParameter), ......
Definition ParameterHolder.h:32
void set_param(const std::string &name, double value)
Set a scalar parameter value by name.
Definition ParameterHolder.cpp:15
void set_param_vector(const std::string &name, const std::vector< double > &value)
Set a vector-valued parameter value by name.
Definition ParameterHolder.cpp:19