BELFEM 0.9.3
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
177 int
178 get_int( const string & aKey ) const;
179
180//------------------------------------------------------------------------------
181
182 void
183 get_ids( const string & aKey, Vector< id_t > & aIDs ) const ;
184
185//------------------------------------------------------------------------------
186
187 void
188 get_intersection_list( const string & aKey, Vector< id_t > & aIDs1, Vector< id_t > & aIDs2 ) const ;
189
190//------------------------------------------------------------------------------
191
192 std::pair< id_t, id_t >
193 get_intersection_ids( const string & aKey ) const ;
194
195//------------------------------------------------------------------------------
196
197 void
198 get_ids( const string & aKey, const string & aTape, Vector< id_t > & aIDs ) const ;
199
200//------------------------------------------------------------------------------
201
202 void
203 get_id_groups( const string & aKey, Cell<Cell< id_t >> & aIDs ) const ;
204
205//------------------------------------------------------------------------------
206
207 void
208 get_reals( const string & aKey, Vector< real > & aReals ) const ;
209
210//------------------------------------------------------------------------------
211
215 const Section *
216 section( const string & aType ) const ;
217
218//------------------------------------------------------------------------------
219
223 const Section *
224 section( const string & aType, const string & aLabel ) const ;
225
226//------------------------------------------------------------------------------
227
231 const Section *
232 section( const index_t aIndex ) const ;
233
234//------------------------------------------------------------------------------
235
239 index_t
240 num_sections() const ;
241
242//------------------------------------------------------------------------------
243
247 index_t
248 num_keys() const ;
249
250//------------------------------------------------------------------------------
251
255 const string &
256 key( const index_t aIndex ) const ;
257
258//------------------------------------------------------------------------------
259
263 int
264 level() const ;
265
266//------------------------------------------------------------------------------
267
271 const Section *
272 parent() const ;
273
274//------------------------------------------------------------------------------
275
279 string
280 tree() const ;
281
282//------------------------------------------------------------------------------
283
287 index_t
288 start() const ;
289
290//------------------------------------------------------------------------------
291
295 index_t
296 end() const ;
297
298//------------------------------------------------------------------------------
299
300 void
301 ids_from_string( const string & aString, Vector< id_t > & aIDs ) const ;
302
303//------------------------------------------------------------------------------
304
305 const Cell< string > &
306 buffer() const ;
307
308//------------------------------------------------------------------------------
309 private:
310//------------------------------------------------------------------------------
311
312 void
313 create_children();
314
315//------------------------------------------------------------------------------
316
317 void
318 create_key( const string & aLine );
319
320//------------------------------------------------------------------------------
321
322 string
323 error_section_not_exisits( const string & aSection ) const ;
324
325//------------------------------------------------------------------------------
326
327 string
328 error_key_not_exists( const string & aKey ) const ;
329
330//------------------------------------------------------------------------------
331
332 string
333 error_key_not_real( const string & aKey ) const ;
334
335//------------------------------------------------------------------------------
336
337 string
338 get_type( const string & aLine ) const ;
339
340 string
341 get_label( const string & aLine ) const ;
342
343//------------------------------------------------------------------------------
344 };
345
346
347
348//------------------------------------------------------------------------------
349
350 inline index_t
352 {
353 return mData.size() ;
354 }
355
356//------------------------------------------------------------------------------
357
358 inline index_t
360 {
361 return mKeyLabels.size() ;
362 }
363
364//------------------------------------------------------------------------------
365
366 inline const string &
367 Section::key( const index_t aIndex ) const
368 {
369 return mKeyLabels( aIndex );
370 }
371
372//------------------------------------------------------------------------------
373
374 inline const Section *
375 Section::section( const index_t aIndex ) const
376 {
377 return mData( aIndex );
378 }
379
380//------------------------------------------------------------------------------
381
382 inline index_t
384 {
385 return mStartFlag ;
386 }
387
388//------------------------------------------------------------------------------
389
390 inline index_t
392 {
393 return mEndFlag ;
394 }
395
396//------------------------------------------------------------------------------
397
398 inline bool
399 Section::section_exists( const string & aSection ) const
400 {
401 // section types are lowercased when the file is parsed
402 // ( get_type ), exactly as key names are, so the lookup must
403 // lowercase its argument too. Keys have always done this; the
404 // section lookups did not, which made 'Defect' miss a 'defect'
405 // that the parser had already folded to lower case
406 return mSections.key_exists( string_to_lower( aSection ) );
407 }
408
409//------------------------------------------------------------------------------
410
411 inline bool
412 Section::section_exists( const string & aType, const string & aLabel ) const
413 {
414 // both halves are lowercased at parse ( get_type / get_label )
415 string tSection = string_to_lower( aType ) + ":"
416 + string_to_lower( aLabel ) ;
417 return mSections.key_exists( tSection );
418 }
419
420//------------------------------------------------------------------------------
421
422 inline const Cell< string > &
424 {
425 return mBuffer ;
426 }
427
428//------------------------------------------------------------------------------
429 }
430}
431
432#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:24
void get_reals(const string &aKey, Vector< real > &aReals) const
Definition cl_Input_Section.cpp:728
int get_int(const string &aKey) const
get the int value of a key.
Definition cl_Input_Section.cpp:362
index_t end() const
end flag in buffer
Definition cl_Input_Section.hpp:391
string tree() const
returns the tree of this section
Definition cl_Input_Section.cpp:418
const string & type() const
return the type of this Section
Definition cl_Input_Section.cpp:208
bool key_exists(const string &aKey) const
check if a key exists
Definition cl_Input_Section.cpp:240
const string & label() const
return the name of this Section
Definition cl_Input_Section.cpp:216
void ids_from_string(const string &aString, Vector< id_t > &aIDs) const
Definition cl_Input_Section.cpp:578
int level() const
the level of this section
Definition cl_Input_Section.cpp:232
bool key_is_real(const string &aKey) const
check if a key is real
Definition cl_Input_Section.cpp:248
const string & key() const
Definition cl_Input_Section.cpp:224
void get_intersection_list(const string &aKey, Vector< id_t > &aIDs1, Vector< id_t > &aIDs2) const
Definition cl_Input_Section.cpp:516
const Section * parent() const
the parent of this section
Definition cl_Input_Section.cpp:410
string get_units(const string &aKey) const
get the units of a key
Definition cl_Input_Section.cpp:341
real get_real(const string &aKey) const
get the real value of a key
Definition cl_Input_Section.cpp:281
bool section_exists(const string &aType) const
tell if a section exists
Definition cl_Input_Section.hpp:399
index_t num_sections() const
number of sections
Definition cl_Input_Section.hpp:351
const Section * section(const string &aType) const
return a subsection by type string (requires empty label)
Definition cl_Input_Section.cpp:380
index_t num_keys() const
number of keys
Definition cl_Input_Section.hpp:359
bool get_bool(const string &aKey) const
get the bool value of a key
Definition cl_Input_Section.cpp:273
void get_id_groups(const string &aKey, Cell< Cell< id_t > > &aIDs) const
Definition cl_Input_Section.cpp:650
value get_value(const string &aKey, const string &aUnit) const
get the real value of a key with unit
Definition cl_Input_Section.cpp:303
const string & get_string(const string &aKey) const
get the value of a key
Definition cl_Input_Section.cpp:256
index_t start() const
start flag in buffer
Definition cl_Input_Section.hpp:383
void get_ids(const string &aKey, Vector< id_t > &aIDs) const
Definition cl_Input_Section.cpp:508
const Cell< string > & buffer() const
Definition cl_Input_Section.hpp:423
std::pair< id_t, id_t > get_intersection_ids(const string &aKey) const
Definition cl_Input_Section.cpp:531
Definition cl_Input_Section.cpp:23
USER GUIDES:
Definition cl_Capacitor.cpp:16
std::pair< real, unit > value
Definition typedefs.hpp:73
std::string string_to_lower(const std::string &aString)
convert the string to lower case
Definition stringtools.cpp:269
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36