BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Input_Section.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_INPUT_SECTION_HPP
13#define BELFEM_CL_INPUT_SECTION_HPP
14
15#include "typedefs.hpp"
16#include "stringtools.hpp"
17#include "cl_Cell.hpp"
18#include "cl_Map.hpp"
19#include "cl_Vector.hpp"
20
21namespace belfem
22{
23 namespace input
24 {
25
26//------------------------------------------------------------------------------
33 class Section
34 {
35 const Section * mParent ;
36 const int mLevel ;
37 const Cell< string > & mBuffer ;
38 const string mType ;
39 const string mLabel ;
40 const string mKey ;
41 const index_t mStartFlag ;
42 const index_t mEndFlag ;
43 Cell < Section * > mData ;
44
45
46 Map< string, Section * > mSections ;
48 Map< string, real > mRealKeys ;
49 Map< string, value > mValueKeys ;
50
51 Cell< string > mKeyLabels ;
52
53//------------------------------------------------------------------------------
54 public:
55//------------------------------------------------------------------------------
56
57 Section(
58 const Section * aParent,
59 const Cell< string > & aBuffer,
60 const string & aKey,
61 const index_t aStartFlag,
62 const index_t aEndFlag
63 );
64
65//------------------------------------------------------------------------------
66
67 ~Section() ;
68
69//------------------------------------------------------------------------------
70
74 const string &
75 type() const;
76
77//------------------------------------------------------------------------------
78
82 const string &
83 label() const;
84
85//------------------------------------------------------------------------------
86
87 const string &
88 key() const;
89
90//------------------------------------------------------------------------------
91
95 bool
96 section_exists( const string & aType ) const;
97
98//------------------------------------------------------------------------------
99
103 bool
104 section_exists( const string & aType, const string & aLabel ) const;
105
106//------------------------------------------------------------------------------
107
111 bool
112 key_exists( const string & aKey ) const;
113
114//------------------------------------------------------------------------------
115
119 bool
120 key_is_real( const string & aKey ) const;
121
122//------------------------------------------------------------------------------
123
127 const string &
128 get_string( const string & aKey ) const;
129
130//------------------------------------------------------------------------------
131
135 bool
136 get_bool( const string & aKey ) const;
137
138//------------------------------------------------------------------------------
139
143 real
144 get_real( const string & aKey ) const;
145
146//------------------------------------------------------------------------------
147
151 value
152 get_value( const string & aKey , const string & aUnit ) const;
153
154//------------------------------------------------------------------------------
155
159 void
160 get_value( const index_t aIndex, string & aKey, value & aValue ) const ;
161
162//------------------------------------------------------------------------------
163
167 string
168 get_units( const string & aKey ) const;
169
170//------------------------------------------------------------------------------
171
175 int
176 get_int( const string & aKey ) const;
177
178//------------------------------------------------------------------------------
179
180 void
181 get_ids( const string & aKey, Vector< id_t > & aIDs ) const ;
182
183//------------------------------------------------------------------------------
184
185 void
186 get_intersection_list( const string & aKey, Vector< id_t > & aIDs1, Vector< id_t > & aIDs2 ) const ;
187
188//------------------------------------------------------------------------------
189
190 std::pair< id_t, id_t >
191 get_intersection_ids( const string & aKey ) const ;
192
193//------------------------------------------------------------------------------
194
195 void
196 get_ids( const string & aKey, const string & aTape, Vector< id_t > & aIDs ) const ;
197
198//------------------------------------------------------------------------------
199
200 void
201 get_id_groups( const string & aKey, Cell<Cell< id_t >> & aIDs ) const ;
202
203//------------------------------------------------------------------------------
204
205 void
206 get_reals( const string & aKey, Vector< real > & aReals ) const ;
207
208//------------------------------------------------------------------------------
209
213 const Section *
214 section( const string & aType ) const ;
215
216//------------------------------------------------------------------------------
217
221 const Section *
222 section( const string & aType, const string & aLabel ) const ;
223
224//------------------------------------------------------------------------------
225
229 const Section *
230 section( const index_t aIndex ) const ;
231
232//------------------------------------------------------------------------------
233
237 index_t
238 num_sections() const ;
239
240//------------------------------------------------------------------------------
241
245 index_t
246 num_keys() const ;
247
248//------------------------------------------------------------------------------
249
253 const string &
254 key( const index_t aIndex ) const ;
255
256//------------------------------------------------------------------------------
257
261 int
262 level() const ;
263
264//------------------------------------------------------------------------------
265
269 const Section *
270 parent() const ;
271
272//------------------------------------------------------------------------------
273
277 string
278 tree() const ;
279
280//------------------------------------------------------------------------------
281
285 index_t
286 start() const ;
287
288//------------------------------------------------------------------------------
289
293 index_t
294 end() const ;
295
296//------------------------------------------------------------------------------
297
298 void
299 ids_from_string( const string & aString, Vector< id_t > & aIDs ) const ;
300
301//------------------------------------------------------------------------------
302
303 const Cell< string > &
304 buffer() const ;
305
306//------------------------------------------------------------------------------
307 private:
308//------------------------------------------------------------------------------
309
310 void
311 create_children();
312
313//------------------------------------------------------------------------------
314
315 void
316 create_key( const string & aLine );
317
318//------------------------------------------------------------------------------
319
320 string
321 error_section_not_exisits( const string & aSection ) const ;
322
323//------------------------------------------------------------------------------
324
325 string
326 error_key_not_exists( const string & aKey ) const ;
327
328//------------------------------------------------------------------------------
329
330 string
331 error_key_not_real( const string & aKey ) const ;
332
333//------------------------------------------------------------------------------
334
335 string
336 get_type( const string & aLine ) const ;
337
338 string
339 get_label( const string & aLine ) const ;
340
341//------------------------------------------------------------------------------
342 };
343
344
345
346//------------------------------------------------------------------------------
347
348 inline index_t
350 {
351 return mData.size() ;
352 }
353
354//------------------------------------------------------------------------------
355
356 inline index_t
358 {
359 return mKeyLabels.size() ;
360 }
361
362//------------------------------------------------------------------------------
363
364 inline const string &
365 Section::key( const index_t aIndex ) const
366 {
367 return mKeyLabels( aIndex );
368 }
369
370//------------------------------------------------------------------------------
371
372 inline const Section *
373 Section::section( const index_t aIndex ) const
374 {
375 return mData( aIndex );
376 }
377
378//------------------------------------------------------------------------------
379
380 inline index_t
382 {
383 return mStartFlag ;
384 }
385
386//------------------------------------------------------------------------------
387
388 inline index_t
390 {
391 return mEndFlag ;
392 }
393
394//------------------------------------------------------------------------------
395
396 inline bool
397 Section::section_exists( const string & aSection ) const
398 {
399 // section types are lowercased when the file is parsed
400 // ( get_type ), exactly as key names are, so the lookup must
401 // lowercase its argument too. Keys have always done this; the
402 // section lookups did not, which made 'Defect' miss a 'defect'
403 // that the parser had already folded to lower case
404 return mSections.key_exists( string_to_lower( aSection ) );
405 }
406
407//------------------------------------------------------------------------------
408
409 inline bool
410 Section::section_exists( const string & aType, const string & aLabel ) const
411 {
412 // both halves are lowercased at parse ( get_type / get_label )
413 string tSection = string_to_lower( aType ) + ":"
414 + string_to_lower( aLabel ) ;
415 return mSections.key_exists( tSection );
416 }
417
418//------------------------------------------------------------------------------
419
420 inline const Cell< string > &
422 {
423 return mBuffer ;
424 }
425
426//------------------------------------------------------------------------------
427 }
428}
429
430#endif //BELFEM_CL_INPUT_SECTION_HPP
Hash map (unordered key-value).
Definition cl_Map.hpp:75
One hierarchical section of a configuration file.
Definition cl_Input_Section.hpp:34
Section(const Section *aParent, const Cell< string > &aBuffer, const string &aKey, const index_t aStartFlag, const index_t aEndFlag)
Definition cl_Input_Section.cpp:21
void get_reals(const string &aKey, Vector< real > &aReals) const
Definition cl_Input_Section.cpp:748
int get_int(const string &aKey) const
get the int value of a key
Definition cl_Input_Section.cpp:374
index_t end() const
end flag in buffer
Definition cl_Input_Section.hpp:389
string tree() const
returns the tree of this section
Definition cl_Input_Section.cpp:421
const string & type() const
return the type of this Section
Definition cl_Input_Section.cpp:218
bool key_exists(const string &aKey) const
check if a key exists
Definition cl_Input_Section.cpp:250
const string & label() const
return the name of this Section
Definition cl_Input_Section.cpp:226
void ids_from_string(const string &aString, Vector< id_t > &aIDs) const
Definition cl_Input_Section.cpp:588
int level() const
the level of this section
Definition cl_Input_Section.cpp:242
bool key_is_real(const string &aKey) const
check if a key is real
Definition cl_Input_Section.cpp:258
const string & key() const
Definition cl_Input_Section.cpp:234
void get_intersection_list(const string &aKey, Vector< id_t > &aIDs1, Vector< id_t > &aIDs2) const
Definition cl_Input_Section.cpp:520
const Section * parent() const
the parent of this section
Definition cl_Input_Section.cpp:413
string get_units(const string &aKey) const
get the units of a key
Definition cl_Input_Section.cpp:353
real get_real(const string &aKey) const
get the real value of a key
Definition cl_Input_Section.cpp:291
bool section_exists(const string &aType) const
tell if a section exists
Definition cl_Input_Section.hpp:397
index_t num_sections() const
number of sections
Definition cl_Input_Section.hpp:349
const Section * section(const string &aType) const
return a subsection by type string (requires empty label)
Definition cl_Input_Section.cpp:382
index_t num_keys() const
number of keys
Definition cl_Input_Section.hpp:357
bool get_bool(const string &aKey) const
get the bool value of a key
Definition cl_Input_Section.cpp:283
void get_id_groups(const string &aKey, Cell< Cell< id_t > > &aIDs) const
Definition cl_Input_Section.cpp:663
value get_value(const string &aKey, const string &aUnit) const
get the real value of a key with unit
Definition cl_Input_Section.cpp:313
const string & get_string(const string &aKey) const
get the value of a key
Definition cl_Input_Section.cpp:266
index_t start() const
start flag in buffer
Definition cl_Input_Section.hpp:381
void get_ids(const string &aKey, Vector< id_t > &aIDs) const
Definition cl_Input_Section.cpp:512
const Cell< string > & buffer() const
Definition cl_Input_Section.hpp:421
std::pair< id_t, id_t > get_intersection_ids(const string &aKey) const
Definition cl_Input_Section.cpp:535
Definition cl_Input_Section.cpp:20
USER GUIDES:
Definition cl_Capacitor.cpp:16
std::pair< real, unit > value
Definition typedefs.hpp:74
std::string string_to_lower(const std::string &aString)
convert the string to lower case
Definition stringtools.cpp:267
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36