Skip to content

Commit 7d2d1b8

Browse files
committed
#13875 ElementPropertyReader: Fix MODULUS scaling bug and remove duplicated code
The range-based loop used the outer column index 'i' as the element index, causing only one slot to be written while all others remained zero. Extracted scaleColumnIfModulus() helper to remove duplication between both branches.
1 parent 2b2a010 commit 7d2d1b8

1 file changed

Lines changed: 25 additions & 33 deletions

File tree

ApplicationLibCode/FileInterface/RifElementPropertyReader.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/////////////////////////////////////////////////////////////////////////////////
1818

1919
#include "RifElementPropertyReader.h"
20+
#include "RiaEclipseUnitTools.h"
2021
#include "RiaLogging.h"
2122

2223
#include "cvfAssert.h"
@@ -85,6 +86,21 @@ std::vector<std::string> RifElementPropertyReader::scalarElementFields() const
8586
return fields;
8687
}
8788

89+
//--------------------------------------------------------------------------------------------------
90+
///
91+
//--------------------------------------------------------------------------------------------------
92+
static void scaleColumnIfModulus( const std::string& fieldName, std::vector<float>& data )
93+
{
94+
if ( fieldName == "MODULUS" )
95+
{
96+
const float paToGPa = static_cast<float>( 1.0 / RiaEclipseUnitTools::gigaPascalToPascal( 1.0 ) );
97+
for ( float& v : data )
98+
{
99+
v *= paToGPa;
100+
}
101+
}
102+
}
103+
88104
//--------------------------------------------------------------------------------------------------
89105
///
90106
//--------------------------------------------------------------------------------------------------
@@ -114,23 +130,9 @@ std::map<std::string, std::vector<float>> RifElementPropertyReader::readAllEleme
114130
for ( size_t i = 0; i < table.data.size(); i++ )
115131
{
116132
const std::string& currentFieldFromFile = m_fieldsMetaData[fieldName].dataColumns[i].toStdString();
117-
118-
if ( currentFieldFromFile == "MODULUS" )
119-
{
120-
const std::vector<float>& currentColumn = table.data[i];
121-
std::vector<float> tempResult( currentColumn.size(), 0 );
122-
123-
for ( float resultItem : currentColumn )
124-
{
125-
tempResult[i] = resultItem * 0.000000001;
126-
}
127-
128-
fieldAndData[currentFieldFromFile].swap( tempResult );
129-
}
130-
else
131-
{
132-
fieldAndData[currentFieldFromFile] = table.data[i];
133-
}
133+
std::vector<float> columnData = table.data[i];
134+
scaleColumnIfModulus( currentFieldFromFile, columnData );
135+
fieldAndData[currentFieldFromFile] = std::move( columnData );
134136
}
135137
}
136138
else if ( elementIdsFromFile.size() > m_elementIdxToId.size() && elementIdsFromFile.size() > m_elementIdToIdx.size() )
@@ -150,7 +152,7 @@ std::map<std::string, std::vector<float>> RifElementPropertyReader::readAllEleme
150152

151153
for ( int elementId : elementIdsFromFile )
152154
{
153-
std::unordered_map<int /*elm ID*/, int /*elm idx*/>::const_iterator it = m_elementIdToIdx.find( elementId );
155+
auto it = m_elementIdToIdx.find( elementId );
154156
if ( it == m_elementIdToIdx.end() )
155157
{
156158
RifElementPropertyReader::outputWarningAboutWrongFileData();
@@ -162,27 +164,17 @@ std::map<std::string, std::vector<float>> RifElementPropertyReader::readAllEleme
162164

163165
for ( size_t i = 0; i < table.data.size(); i++ )
164166
{
165-
std::string currentFieldFromFile = m_fieldsMetaData[fieldName].dataColumns[i].toStdString();
166-
167-
const std::vector<float>& currentColumn = table.data[i];
167+
std::string currentFieldFromFile = m_fieldsMetaData[fieldName].dataColumns[i].toStdString();
168+
const std::vector<float>& currentColumn = table.data[i];
168169

169170
std::vector<float> tempResult( m_elementIdToIdx.size(), HUGE_VAL );
170171

171-
if ( currentFieldFromFile == "MODULUS" )
172-
{
173-
for ( size_t j = 0; j < currentColumn.size(); j++ )
174-
{
175-
tempResult[fileIdxToElementIdx[j]] = currentColumn[j] * 0.000000001;
176-
}
177-
}
178-
else
172+
for ( size_t j = 0; j < currentColumn.size(); j++ )
179173
{
180-
for ( size_t j = 0; j < currentColumn.size(); j++ )
181-
{
182-
tempResult[fileIdxToElementIdx[j]] = currentColumn[j];
183-
}
174+
tempResult[fileIdxToElementIdx[j]] = currentColumn[j];
184175
}
185176

177+
scaleColumnIfModulus( currentFieldFromFile, tempResult );
186178
fieldAndData[currentFieldFromFile].swap( tempResult );
187179
}
188180
}

0 commit comments

Comments
 (0)