Skip to content

Commit a8c7c69

Browse files
authored
Merge pull request eric2003#176 from eric2003/hexin
Hexin
2 parents a28bb71 + 2403d0d commit a8c7c69

11 files changed

Lines changed: 710 additions & 495 deletions

File tree

‎codes/database/include/DataBase.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ License
3333
#include <string>
3434
#include <set>
3535
#include <map>
36+
#include <stdexcept>
3637

3738
BeginNameSpace( ONEFLOW )
3839

@@ -107,19 +108,36 @@ T * GetDataPointer( const std::string & varName )
107108
{
108109
DataBase * database = ONEFLOW::GetGlobalDataBase();
109110
DataEntry * dataEntry = database->dataPara->GetDataPointer( varName );
111+
112+
// Required lookup: match GetDataValue -- missing name must not
113+
// dereference a null DataEntry.
114+
if ( dataEntry == nullptr )
115+
{
116+
// Short-term: throw instead of exit, so unit tests can catch it
117+
throw std::runtime_error(
118+
"DataBase: cannot find variable \"" + varName + "\"" );
119+
}
120+
110121
DataObject * data = dataEntry->data;
111122
return static_cast< T * >( data->GetVoidPointer() );
112123
}
113124

114125
class PointerWrap;
115126
PointerWrap * GetPointerWrap( DataField * dataField, const std::string & dataObjectName );
116127

128+
// Field storage lookup (optional): returns nullptr if the named field
129+
// is not registered. Callers that require the field must null-check
130+
// or Fatal. Contrast with GetDataValue / GetDataPointer (required).
117131
void * GetFieldPointerVoid( DataBase * database, const std::string & dataObjectName );
118132

119133
template < typename T >
120134
T * GetFieldPointer( DataBase * database, const std::string & dataObjectName );
121135
template < typename T, typename TStorage >
122136
T * GetFieldPointer( TStorage * storage, const std::string & dataObjectName );
137+
138+
// Required field access: dereferences GetFieldPointer. The named field
139+
// must already be registered; otherwise this is undefined behavior.
140+
// Prefer GetFieldPointer + null-check/Fatal when presence is uncertain.
123141
template < typename T >
124142
T & GetFieldReference( DataBase * database, const std::string & dataObjectName );
125143
template < typename T, typename TStorage >
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

‎codes/global/include/FieldAllocator.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ License
2525

2626
BeginNameSpace( ONEFLOW )
2727

28+
// Orchestrates field definition, interface registration, runtime allocation,
29+
// and constant initialization for one solverType.
30+
// Config root: system/<basicString>/alloc/
31+
// inner.txt / face.txt / bc.txt / unsteady.txt -> FieldManager definitions
32+
// inter.txt / interDq.txt / interGrad.txt / interOverset.txt
33+
// -> communication field names
34+
// init.txt -> constant initial values
35+
// Definition is solverType-scoped; allocation is per current Grid/DataStorage.
2836
class FieldAllocator
2937
{
3038
public:

‎codes/global/include/FieldManager.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ class FieldManager
171171
bool interfaceDefinitionsReady;
172172
};
173173

174+
// Per-solverType FieldManager registry.
175+
// AddFieldManager: create empty manager if missing (idempotent).
176+
// GetFieldManager: optional lookup (nullptr if not registered).
177+
// Callers that require a manager after Add must null-check or Fatal.
174178
class FieldManagerRegistry
175179
{
176180
public:
@@ -187,6 +191,4 @@ void DownloadInterfaceValue( UnsGrid * grid, MRField * field2D, const std::strin
187191
void UploadOversetValue( UnsGrid * grid, MRField * field2D, const std::string & name, int nEqu );
188192
void DownloadOversetValue( UnsGrid * grid, MRField * field2D, const std::string & name, int nEqu );
189193

190-
void DownloadInterfaceValue_TEST( UnsGrid * grid, MRField * field2D, const std::string & name, int nEqu );
191-
192194
EndNameSpace

0 commit comments

Comments
 (0)