OOFEM 3.0
Loading...
Searching...
No Matches
parametermanager.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef parametermanager_h
36#define parametermanager_h
37
38#include <unordered_map>
39#include <string>
40#include <tuple>
41#include <vector>
42#include <mutex>
43#include <shared_mutex>
44#include <variant>
45#include <optional>
46
47#include "intarray.h"
48#include "floatarray.h"
49#include "floatmatrix.h"
50
51#include "error.h"
52
53namespace oofem {
54
55
56#define PM_UPDATE_PARAMETER(_val, _pm, _ir, _componentnum, _paramkey, _prio) \
57 { \
58 std::size_t _indx=_paramkey.getIndex(); \
59 const char* _kwd = _paramkey.getName().c_str(); \
60 if ((_prio >= _pm.getPriority(_componentnum, _indx)) && (_ir.hasField(_kwd))) { \
61 _ir.giveField(_val, _kwd); \
62 _pm.setPriority(_componentnum, _indx, _prio); \
63 } \
64 }
65
66#define PM_UPDATE_PARAMETER_AND_REPORT(_val, _pm, _ir, _componentnum, _paramkey, _prio, _flag) \
67 { \
68 std::size_t _indx=_paramkey.getIndex(); \
69 const char* _kwd = _paramkey.getName().c_str(); \
70 if ((_prio >= _pm.getPriority(_componentnum, _indx)) && (_ir.hasField(_kwd))) { \
71 _ir.giveField(_val, _kwd); \
72 _pm.setPriority(_componentnum, _indx, _prio); \
73 _flag=true; \
74 } else { \
75 _flag=false; \
76 } \
77 }
78
79#define PM_UPDATE_TEMP_PARAMETER(_type, _pm, _ir, _componentnum, _paramkey, _prio) \
80 { \
81 std::size_t _indx=_paramkey.getIndex(); \
82 const char* _kwd = _paramkey.getName().c_str(); \
83 if ((_prio >= _pm.getPriority(_componentnum, _indx)) && (_ir.hasField(_kwd))) { \
84 _type _val; \
85 _ir.giveField(_val, _kwd); \
86 _pm.setPriority(_componentnum, _indx, _prio); \
87 _pm.setTemParam(_componentnum, _indx, _val); \
88 } \
89 }
90
91#define PM_CHECK_FLAG_AND_REPORT(_pm, _ir, _componentnum, _paramkey, _prio, _flag) \
92 { \
93 std::size_t _indx=_paramkey.getIndex(); \
94 const char* _kwd = _paramkey.getName().c_str(); \
95 if ((_prio >= _pm.getPriority(_componentnum, _indx)) && (_ir.hasField(_kwd))) { \
96 _pm.setPriority(_componentnum, _indx, _prio); \
97 _flag=true; \
98 } else { \
99 _flag=false; \
100 } \
101 }
102
103#define PM_ELEMENT_ERROR_IFNOTSET(_pm, _componentnum, _paramkey) \
104 { \
105 if (!_pm.checkIfSet(_componentnum, _paramkey.getIndex())) { \
106 OOFEM_ERROR("Element %d: Parameter %s not set", _componentnum, _paramkey.getNameCStr());\
107 }\
108 }
109
110#define PM_DOFMAN_ERROR_IFNOTSET(_pm, _componentnum, _paramkey) \
111 { \
112 if (!_pm.checkIfSet(_componentnum, _paramkey.getIndex())) { \
113 OOFEM_ERROR("DofManager %d: Parameter %s not set", _componentnum, _paramkey.getNameCStr());\
114 }\
115 }
116
129// ParameterManager class to track parameter priorities
131public:
132 using paramValue = std::variant<int, double, std::string, bool, IntArray, FloatArray, FloatMatrix>;
133 void setPriority(size_t componentIndex, size_t paramIndex, int priority) {
134 std::unique_lock lock(mtx);
135 if (componentIndex > priorities.size()) {
136 priorities.resize(componentIndex);
137 }
138 priorities[componentIndex-1][paramIndex] = priority;
139 }
140
141 int getPriority(size_t componentIndex, size_t paramIndex) const {
142 std::shared_lock lock(mtx);
143 int ci1 = componentIndex - 1; // Adjust for 0-based index
144 if (componentIndex <= priorities.size() && priorities[ci1].find(paramIndex) != priorities[ci1].end()) {
145 return priorities[ci1].at(paramIndex);
146 }
147 return -1; // Return -1 if priority is not found
148 }
149
150 void clear() {
151 std::unique_lock lock(mtx);
152 priorities.clear();
153 tempParams.clear();
154 }
155
156 bool checkIfSet(size_t componentIndex, size_t paramIndex) {
157 int ci1 = componentIndex - 1; // Adjust for 0-based index
158 if (componentIndex <= priorities.size()) {
159 return priorities[ci1].find(paramIndex) != priorities[ci1].end();
160 } else {
161 return false; // Return false if componentIndex is out of bounds
162 }
163 }
164
165 void setTemParam(size_t componentIndex, size_t paramIndex, const paramValue &value) {
166 std::unique_lock lock(mtx);
167 if (componentIndex >= tempParams.size()) {
168 tempParams.resize(componentIndex);
169 }
170 tempParams[componentIndex-1][paramIndex] = value;
171 }
172 std::optional<paramValue> getTempParam(size_t componentIndex, size_t paramIndex) const {
173 std::shared_lock lock(mtx);
174 int ci1 = componentIndex - 1; // Adjust for 0-based index
175 auto it = tempParams[ci1].find(paramIndex);
176 if (it != tempParams[ci1].end()) {
177 return it->second;
178 }
179 return std::nullopt; // Return nullopt if parameter is not found
180 }
181 bool hasTempParam(size_t componentIndex, size_t paramIndex) const {
182 std::shared_lock lock(mtx);
183 int ci1 = componentIndex - 1; // Adjust for 0-based index
184 return tempParams[ci1].find(paramIndex) != tempParams[ci1].end();
185 }
186
187private:
188 std::vector<std::unordered_map<size_t, int>> priorities;
189 mutable std::shared_mutex mtx;
190
191 std::vector<std::unordered_map<size_t, paramValue>> tempParams;
192};
193
194
195
196
197} // end namespace oofem
198
199
200#endif // parametermanager_h
std::vector< std::unordered_map< size_t, int > > priorities
bool checkIfSet(size_t componentIndex, size_t paramIndex)
bool hasTempParam(size_t componentIndex, size_t paramIndex) const
std::variant< int, double, std::string, bool, IntArray, FloatArray, FloatMatrix > paramValue
int getPriority(size_t componentIndex, size_t paramIndex) const
void setTemParam(size_t componentIndex, size_t paramIndex, const paramValue &value)
std::vector< std::unordered_map< size_t, paramValue > > tempParams
void setPriority(size_t componentIndex, size_t paramIndex, int priority)
std::optional< paramValue > getTempParam(size_t componentIndex, size_t paramIndex) const

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011