mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
RimDeltaSummaryEnsemble-Test.cpp and RimSummaryCaseMainCollection-Test.cpp each defined an identical createMockCase() in an anonymous namespace. A unity build concatenates the two translation units, which merges the two anonymous namespaces into one and makes the second definition a redefinition, breaking the build with C2084. Move the factory to RimMockSummaryCase.h, the header both tests already include for the mock case itself, and drop both local copies.
82 lines
2.8 KiB
C++
82 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "RifSummaryReaderInterface.h"
|
|
#include "RigCaseRealizationParameters.h"
|
|
#include "RimSummaryCase.h"
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class RimMockSummaryCase : public RimSummaryCase, public RifSummaryReaderInterface
|
|
{
|
|
public:
|
|
void setName( const QString& name ) { m_name = name; }
|
|
|
|
void addVector( const RifEclipseSummaryAddress& address,
|
|
const std::vector<time_t>& timeSteps,
|
|
const std::vector<double>& values,
|
|
const std::string& unit = "" )
|
|
{
|
|
m_data[address] = { timeSteps, values, unit };
|
|
m_allResultAddresses.insert( address );
|
|
}
|
|
|
|
// RimSummaryCase overrides
|
|
void createSummaryReaderInterface() override {}
|
|
RifSummaryReaderInterface* summaryReader() override { return this; }
|
|
QString caseName() const override { return m_name; }
|
|
|
|
// RifSummaryReaderInterface overrides
|
|
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override
|
|
{
|
|
auto it = m_data.find( resultAddress );
|
|
if ( it != m_data.end() ) return it->second.timeSteps;
|
|
return {};
|
|
}
|
|
|
|
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override
|
|
{
|
|
auto it = m_data.find( resultAddress );
|
|
if ( it != m_data.end() ) return { true, it->second.values };
|
|
return { false, {} };
|
|
}
|
|
|
|
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override
|
|
{
|
|
auto it = m_data.find( resultAddress );
|
|
if ( it != m_data.end() ) return it->second.unit;
|
|
return {};
|
|
}
|
|
|
|
RiaDefines::EclipseUnitSystem unitSystem() const override { return RiaDefines::EclipseUnitSystem::UNITS_METRIC; }
|
|
|
|
size_t keywordCount() const override { return m_allResultAddresses.size(); }
|
|
|
|
private:
|
|
struct VectorData
|
|
{
|
|
std::vector<time_t> timeSteps;
|
|
std::vector<double> values;
|
|
std::string unit;
|
|
};
|
|
|
|
QString m_name = "MockCase";
|
|
std::map<RifEclipseSummaryAddress, VectorData> m_data;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/// A mock case carrying the realization number a delta ensemble matches its source cases on.
|
|
//--------------------------------------------------------------------------------------------------
|
|
inline RimSummaryCase* createMockCase( int realizationNumber )
|
|
{
|
|
auto* summaryCase = new RimMockSummaryCase();
|
|
|
|
auto parameters = std::make_shared<RigCaseRealizationParameters>();
|
|
parameters->setRealizationNumber( realizationNumber );
|
|
summaryCase->setCaseRealizationParameters( parameters );
|
|
|
|
return summaryCase;
|
|
}
|