Skip to content

Commit e22089f

Browse files
committed
fixing binary restart
1 parent a9682ac commit e22089f

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

SU2_CFD/include/output/COutput.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class COutput {
242242
/*----------------------------- Volume output ----------------------------*/
243243

244244
CParallelDataSorter* volumeDataSorter; //!< Volume data sorter
245+
CParallelDataSorter* volumeDataSorterCompact; //!< Volume data sorter
245246
CParallelDataSorter* surfaceDataSorter; //!< Surface data sorter
246247

247248
vector<string> volumeFieldNames; //!< Vector containing the volume field names
@@ -260,10 +261,12 @@ class COutput {
260261
/*! \brief The name of the field, i.e. the name that is printed in the file header.*/
261262
string fieldName;
262263
/*! \brief This value identifies the position of the values of this field at each node in the ::Local_Data array. */
263-
short offset;
264+
short offset;
265+
/*! \brief This offset is used for the compact formulation. */
266+
short offsetCompact;
264267
/*! \brief The group this field belongs to. */
265268
string outputGroup;
266-
/*! \brief String containing the description of the field */
269+
/*! \brief String containing the description of the field. */
267270
string description;
268271
/*! \brief Default constructor. */
269272
VolumeOutputField () {}
@@ -278,15 +281,15 @@ class COutput {
278281
/*! \brief Vector that contains the keys of the ::volumeOutput_Map in the order of their insertion. */
279282
std::vector<string> volumeOutput_List;
280283

281-
/*! \brief Vector to cache the positions of the field in the data array */
284+
/*! \brief Vector to cache the positions of the field in the data array. */
282285
std::vector<short> fieldIndexCache;
283-
/*! \brief Current value of the cache index */
286+
/*! \brief Current value of the cache index. */
284287
unsigned short cachePosition;
285288
/*! \brief Boolean to store whether the field index cache should be build. */
286289
bool buildFieldIndexCache;
287-
/*! \brief Vector to cache the positions of the field in the data array */
290+
/*! \brief Vector to cache the positions of the field in the data array. */
288291
std::vector<short> fieldGetIndexCache;
289-
/*! \brief Current value of the cache index */
292+
/*! \brief Current value of the cache index. */
290293
unsigned short curGetFieldIndex;
291294

292295
/*! \brief Requested volume field names in the config file. */

SU2_CFD/src/output/COutput.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ COutput::COutput(const CConfig *config, unsigned short ndim, bool fem_output):
179179
curTimeIter = 0;
180180

181181
volumeDataSorter = nullptr;
182+
volumeDataSorterCompact = nullptr;
182183
surfaceDataSorter = nullptr;
183184

184185
headerNeeded = false;
@@ -195,6 +196,7 @@ COutput::~COutput() {
195196
delete fileWritingTable;
196197
delete historyFileTable;
197198
delete volumeDataSorter;
199+
delete volumeDataSorterCompact;
198200
delete surfaceDataSorter;
199201

200202
}
@@ -343,6 +345,9 @@ void COutput::AllocateDataSorters(CConfig *config, CGeometry *geometry){
343345
if (volumeDataSorter == nullptr)
344346
volumeDataSorter = new CFEMDataSorter(config, geometry, volumeFieldNames);
345347

348+
if (volumeDataSorterCompact == nullptr)
349+
volumeDataSorterCompact = new CFEMDataSorter(config, geometry, requiredVolumeFieldNames);
350+
346351
if (surfaceDataSorter == nullptr)
347352
surfaceDataSorter = new CSurfaceFEMDataSorter(config, geometry,
348353
dynamic_cast<CFEMDataSorter*>(volumeDataSorter));
@@ -352,6 +357,9 @@ void COutput::AllocateDataSorters(CConfig *config, CGeometry *geometry){
352357
if (volumeDataSorter == nullptr)
353358
volumeDataSorter = new CFVMDataSorter(config, geometry, volumeFieldNames);
354359

360+
if (volumeDataSorterCompact == nullptr)
361+
volumeDataSorterCompact = new CFVMDataSorter(config, geometry, requiredVolumeFieldNames);
362+
355363
if (surfaceDataSorter == nullptr)
356364
surfaceDataSorter = new CSurfaceFVMDataSorter(config, geometry,
357365
dynamic_cast<CFVMDataSorter*>(volumeDataSorter));
@@ -461,12 +469,15 @@ void COutput::WriteToFile(CConfig *config, CGeometry *geometry, OUTPUT_TYPE form
461469

462470
/*--- If we have compact restarts, we use only the required fields. ---*/
463471
if (config->GetWrt_Restart_Compact())
464-
volumeDataSorter->SetRequiredFieldNames(requiredVolumeFieldNames);
472+
volumeDataSorterCompact->SetRequiredFieldNames(requiredVolumeFieldNames);
465473
else
466474
volumeDataSorter->SetRequiredFieldNames(volumeDataSorter->GetFieldNames());
467475

468476
LogOutputFiles("SU2 binary restart");
469-
fileWriter = new CSU2BinaryFileWriter(volumeDataSorter);
477+
if (config->GetWrt_Restart_Compact())
478+
fileWriter = new CSU2BinaryFileWriter(volumeDataSorterCompact);
479+
else
480+
fileWriter = new CSU2BinaryFileWriter(volumeDataSorter);
470481

471482
break;
472483

@@ -846,6 +857,7 @@ bool COutput::SetResultFiles(CGeometry *geometry, CConfig *config, CSolver** sol
846857
/*--- Partition and sort the data --- */
847858

848859
volumeDataSorter->SortOutputData();
860+
volumeDataSorterCompact->SortOutputData();
849861

850862
if (rank == MASTER_NODE && !isFileWrite) {
851863
fileWritingTable->SetAlign(PrintingToolbox::CTablePrinter::CENTER);
@@ -1554,24 +1566,32 @@ void COutput::PreprocessVolumeOutput(CConfig *config){
15541566
* object gets an offset so that we know where to find the data in the Local_Data() array.
15551567
* Note that the default offset is -1. An index !=-1 defines this field as part of the output. ---*/
15561568

1569+
unsigned short nVolumeFieldsCompact = 0;
1570+
15571571
for (size_t iField_Output = 0; iField_Output < volumeOutput_List.size(); iField_Output++) {
15581572

15591573
const string &fieldReference = volumeOutput_List[iField_Output];
1560-
15611574
if (volumeOutput_Map.count(fieldReference) > 0) {
1562-
15631575
VolumeOutputField &Field = volumeOutput_Map.at(fieldReference);
1576+
15641577
/*--- Loop through all fields specified in the config ---*/
1578+
15651579
for (size_t iReqField = 0; iReqField < restartVolumeFields.size(); iReqField++) {
15661580

1581+
// minimum required fields for restarts
15671582
RequiredField = restartVolumeFields[iReqField];
1583+
15681584
if (((RequiredField == Field.outputGroup) || (RequiredField == fieldReference)) && (Field.offset == -1)) {
1585+
Field.offsetCompact = nVolumeFieldsCompact;
15691586
requiredVolumeFieldNames.push_back(Field.fieldName);
1587+
nVolumeFieldsCompact++;
15701588
}
15711589
}
15721590
}
15731591
}
15741592

1593+
//volumeDataSorter->SetRequiredFieldNames(requiredVolumeFieldNames);
1594+
15751595
unsigned short nVolumeFields = 0;
15761596

15771597
for (size_t iField_Output = 0; iField_Output < volumeOutput_List.size(); iField_Output++) {
@@ -1716,16 +1736,25 @@ void COutput::LoadDataIntoSorter(CConfig* config, CGeometry* geometry, CSolver**
17161736

17171737
void COutput::SetVolumeOutputValue(const string& name, unsigned long iPoint, su2double value){
17181738

1719-
if (buildFieldIndexCache){
1739+
const vector<string> reqFieldNames = requiredVolumeFieldNames;
1740+
string fieldname = volumeOutput_Map.at(name).fieldName;
1741+
bool contains = std::any_of(requiredVolumeFieldNames.begin(), requiredVolumeFieldNames.end(),
1742+
[fieldname](string n) { return n == fieldname; });
1743+
if (buildFieldIndexCache) {
17201744

17211745
/*--- Build up the offset cache to speed up subsequent
17221746
* calls of this routine since the order of calls is
17231747
* the same for every value of iPoint --- */
17241748

1725-
if (volumeOutput_Map.count(name) > 0){
1749+
if (volumeOutput_Map.count(name) > 0) {
17261750
const short Offset = volumeOutput_Map.at(name).offset;
17271751
fieldIndexCache.push_back(Offset);
17281752
if (Offset != -1){
1753+
// note that the compact fields are a subset of the full fields
1754+
if (contains == true) {
1755+
const short OffsetCompact = volumeOutput_Map.at(name).offsetCompact;
1756+
volumeDataSorterCompact->SetUnsortedData(iPoint, OffsetCompact, value);
1757+
}
17291758
volumeDataSorter->SetUnsortedData(iPoint, Offset, value);
17301759
}
17311760
} else {
@@ -1734,9 +1763,12 @@ void COutput::SetVolumeOutputValue(const string& name, unsigned long iPoint, su2
17341763
} else {
17351764

17361765
/*--- Use the offset cache for the access ---*/
1737-
17381766
const short Offset = fieldIndexCache[cachePosition++];
1739-
if (Offset != -1){
1767+
if (Offset != -1) {
1768+
if (contains == true) {
1769+
const short OffsetCompact = volumeOutput_Map.at(name).offsetCompact;
1770+
volumeDataSorterCompact->SetUnsortedData(iPoint, OffsetCompact, value);
1771+
}
17401772
volumeDataSorter->SetUnsortedData(iPoint, Offset, value);
17411773
}
17421774
if (cachePosition == fieldIndexCache.size()){

0 commit comments

Comments
 (0)