|
| 1 | +/*---------------------------------------------------------------------------*\ |
| 2 | +OneFLOW - LargeScale Multiphysics Scientific Simulation Environment |
| 3 | +Copyright (C) 2017-2026 He Xin and the OneFLOW contributors. |
| 4 | +------------------------------------------------------------------------------- |
| 5 | +License |
| 6 | +This file is part of OneFLOW. |
| 7 | +
|
| 8 | +OneFLOW is free software: you can redistribute it and/or modify it |
| 9 | +under the terms of the GNU General Public License as published by |
| 10 | +the Free Software Foundation, either version 3 of the License, or |
| 11 | +(at your option) any later version. |
| 12 | +
|
| 13 | +OneFLOW is distributed in the hope that it will be useful, but WITHOUT |
| 14 | +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | +for more details. |
| 17 | +
|
| 18 | +You should have received a copy of the GNU General Public License |
| 19 | +along with OneFLOW. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +
|
| 21 | +\*---------------------------------------------------------------------------*/ |
| 22 | +#pragma once |
| 23 | +#include "NamespaceMacros.h" |
| 24 | +#include "HXDefine.h" |
| 25 | +#include <string> |
| 26 | + |
| 27 | +BeginNameSpace( ONEFLOW ) |
| 28 | + |
| 29 | +class TextFileParser; |
| 30 | + |
| 31 | +// Parse integer token: digit literal, or DataBase variable name. |
| 32 | +int ResolveIntegerValue( const std::string & valueToken ); |
| 33 | + |
| 34 | +// Field name list from inter*.txt style "true, name;" lines. |
| 35 | +class FieldNameList |
| 36 | +{ |
| 37 | +public: |
| 38 | + void Add( const std::string & name ); |
| 39 | + int Size() const; |
| 40 | + const std::string & GetName( int index ) const; |
| 41 | + |
| 42 | +private: |
| 43 | + StringField nameList; |
| 44 | +}; |
| 45 | + |
| 46 | +// Name/value pairs from init.txt style lines. |
| 47 | +class NameValuePair |
| 48 | +{ |
| 49 | +public: |
| 50 | + void Add( const std::string & name, Real value ); |
| 51 | + int Size() const; |
| 52 | + const std::string & GetName( int index ) const; |
| 53 | + Real GetValue( int index ) const; |
| 54 | + |
| 55 | +private: |
| 56 | + StringField nameList; |
| 57 | + RealField valueList; |
| 58 | +}; |
| 59 | + |
| 60 | +// Reader for system/<solver>/alloc/ text: |
| 61 | +// inter*.txt -> ReadFile() -> GetFieldNameList() |
| 62 | +// init.txt -> ReadValueFile() -> GetNameValuePair() |
| 63 | +// Supports true / bool / superbool control lines. |
| 64 | +class FieldConfigReader |
| 65 | +{ |
| 66 | +public: |
| 67 | + const FieldNameList & GetFieldNameList() const; |
| 68 | + const NameValuePair & GetNameValuePair() const; |
| 69 | + |
| 70 | + bool GetBoolValue( const std::string & varName ) const; |
| 71 | + void Add( const std::string & name, bool value ); |
| 72 | + |
| 73 | + void ReadBool( TextFileParser & textFileParser ); |
| 74 | + void ReadSuperBool( TextFileParser & textFileParser ); |
| 75 | + void ReadName( TextFileParser & textFileParser ); |
| 76 | + void ReadNameValue( TextFileParser & textFileParser ); |
| 77 | + |
| 78 | + void ReadFile( const std::string & fileName ); |
| 79 | + void ReadValueFile( const std::string & fileName ); |
| 80 | + |
| 81 | +private: |
| 82 | + StringField boolNameList; |
| 83 | + BoolField boolValueList; |
| 84 | + FieldNameList fieldNameList; |
| 85 | + NameValuePair nameValuePair; |
| 86 | +}; |
| 87 | + |
| 88 | +EndNameSpace |
0 commit comments