Skip to content

Commit

Permalink
#859 Added time from start of simulation option
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobStoren committed Nov 22, 2016
1 parent 3a0e7d0 commit 5d04ac1
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 45 deletions.
27 changes: 15 additions & 12 deletions ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ bool RifReaderEclipseSummary::open(const std::string& headerFileName, const std:
eclSmSpec = ecl_sum_get_smspec(ecl_sum);
assert(eclSmSpec != NULL);

assert(ecl_sum != NULL);

for ( int time_index = 0; time_index < timeStepCount(); time_index++ )
{
time_t sim_time = ecl_sum_iget_sim_time(ecl_sum, time_index);
m_timeSteps.push_back(sim_time);
}

return true;
}

Expand Down Expand Up @@ -241,13 +249,15 @@ const std::vector<RifEclipseSummaryAddress>& RifReaderEclipseSummary::allResultA
bool RifReaderEclipseSummary::values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values)
{
assert(ecl_sum != NULL);

int variableIndex = indexFromAddress(resultAddress);

if ( variableIndex < 0 ) return false;

values->clear();
int tsCount = timeStepCount();
values->reserve(timeStepCount());

int variableIndex = indexFromAddress(resultAddress);

if(variableIndex < 0) return false;

const smspec_node_type * ertSumVarNode = ecl_smspec_iget_node(eclSmSpec, variableIndex);
int paramsIndex = smspec_node_get_params_index(ertSumVarNode);
Expand All @@ -274,18 +284,11 @@ int RifReaderEclipseSummary::timeStepCount() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<time_t> RifReaderEclipseSummary::timeSteps() const
const std::vector<time_t>& RifReaderEclipseSummary::timeSteps() const
{
assert(ecl_sum != NULL);

std::vector<time_t> steps;
for (int time_index = 0; time_index < timeStepCount(); time_index++)
{
time_t sim_time = ecl_sum_iget_sim_time(ecl_sum , time_index);
steps.push_back(sim_time);
}

return steps;
return m_timeSteps;
}

//--------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion ApplicationCode/FileInterface/RifReaderEclipseSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RifReaderEclipseSummary : public cvf::Object

bool hasAddress(const RifEclipseSummaryAddress& resultAddress);
const std::vector<RifEclipseSummaryAddress>& allResultAddresses();
std::vector<time_t> timeSteps() const;
const std::vector<time_t>& timeSteps() const;

bool values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values);
std::string unitName(const RifEclipseSummaryAddress& resultAddress);
Expand All @@ -66,6 +66,7 @@ class RifReaderEclipseSummary : public cvf::Object

ecl_sum_type* ecl_sum;
const ecl_smspec_type * eclSmSpec;
std::vector<time_t> m_timeSteps;

std::vector<RifEclipseSummaryAddress> m_allResultAddresses;
std::map<RifEclipseSummaryAddress, int> m_resultAddressToErtNodeIdx;
Expand Down
55 changes: 47 additions & 8 deletions ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "cafPdmUiTreeOrdering.h"

#include "qwt_date.h"
#include "RimSummaryTimeAxisProperties.h"


CAF_PDM_SOURCE_INIT(RimSummaryAddress, "SummaryAddress");
Expand Down Expand Up @@ -246,16 +247,33 @@ std::string RimSummaryCurve::unitName()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimSummaryCurve::yPlotValues() const
std::vector<double> RimSummaryCurve::yValues() const
{
std::vector<QDateTime> dateTimes;
std::vector<double> values;

this->curveData(&dateTimes, &values);
RifReaderEclipseSummary* reader = summaryReader();

if ( !reader ) return values;

RifEclipseSummaryAddress addr = m_curveVariable()->address();
reader->values(addr, &values);

return values;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<time_t>& RimSummaryCurve::timeSteps() const
{
static std::vector<time_t> emptyVector;
RifReaderEclipseSummary* reader = summaryReader();

if ( !reader ) return emptyVector;

return reader->timeSteps();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -379,20 +397,40 @@ void RimSummaryCurve::onLoadDataAndUpdate()

if (isCurveVisible())
{
std::vector<QDateTime> dateTimes;
std::vector<double> values;
std::vector<time_t> dateTimes = this->timeSteps();
std::vector<double> values = this->yValues();

RimSummaryPlot* plot = nullptr;
firstAncestorOrThisOfType(plot);
bool isLogCurve = plot->isLogarithmicScaleEnabled(this->yAxis());

if(this->curveData(&dateTimes, &values))
if ( dateTimes.size())
{
m_qwtPlotCurve->setSamplesFromDateAndValues(dateTimes, values, isLogCurve);
if ( plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
{
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
}
else
{
double timeScale = plot->timeAxisProperties()->fromTimeTToDisplayUnitScale();

std::vector<double> times;
if ( dateTimes.size() )
{
time_t startDate = dateTimes[0];
for ( time_t& date: dateTimes )
{
times.push_back(timeScale*(date - startDate));
}
}

m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
}

}
else
{
m_qwtPlotCurve->setSamplesFromDateAndValues(std::vector<QDateTime>(), std::vector<double>(), isLogCurve);
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
}

updateZoomInParentPlot();
Expand Down Expand Up @@ -540,3 +578,4 @@ bool RimSummaryCurve::curveData(std::vector<QDateTime>* timeSteps, std::vector<d
RifEclipseSummaryAddress addr = m_curveVariable()->address();
return reader->values(addr, values);
}

3 changes: 2 additions & 1 deletion ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class RimSummaryCurve : public RimPlotCurve
void setSummaryAddress(const RifEclipseSummaryAddress& address);
std::string unitName();

std::vector<double> yPlotValues() const;
std::vector<double> yValues() const;
const std::vector<time_t>& timeSteps() const;

void setYAxis(RimDefines::PlotAxis plotAxis);
RimDefines::PlotAxis yAxis() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void RimSummaryPlotYAxisRangeCalculator::computeYRange(double* min, double* max)
{
if (curve->isCurveVisible())
{
RigStatisticsCalculator::posNegClosestToZero(curve->yPlotValues(), pos, neg);
RigStatisticsCalculator::posNegClosestToZero(curve->yValues(), pos, neg);
}
}

Expand Down
51 changes: 51 additions & 0 deletions ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ bool RimSummaryPlot::isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) co
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryTimeAxisProperties* RimSummaryPlot::timeAxisProperties()
{
return m_timeAxisProperties();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -163,6 +171,40 @@ void RimSummaryPlot::selectAxisInPropertyEditor(int axis)
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
time_t RimSummaryPlot::firstTimeStepOfFirstCurve()
{
RimSummaryCurve * firstCurve = nullptr;

for (RimSummaryCurveFilter* curveFilter : m_curveFilters )
{
if (curveFilter)
{
std::vector<RimSummaryCurve *> curves = curveFilter->curves();
int i = 0;
while (firstCurve == nullptr)
{
firstCurve = curves[i];
i++;
}

if (firstCurve) break;
}
}

int i = 0;
while (firstCurve == nullptr)
{
firstCurve = m_curves[i];
++i;
}

if (firstCurve) return firstCurve->timeSteps()[0];
else return time_t(0);
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -276,6 +318,15 @@ void RimSummaryPlot::updateTimeAxis()
return;
}

if (m_timeAxisProperties->timeMode() == RimSummaryTimeAxisProperties::DATE)
{
m_qwtPlot->useDateBasedTimeAxis();
}
else
{
m_qwtPlot->useTimeBasedTimeAxis();
}

m_qwtPlot->enableAxis(QwtPlot::xBottom, true);

{
Expand Down
3 changes: 3 additions & 0 deletions ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class RimSummaryPlot : public RimViewWindow

bool isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) const;

RimSummaryTimeAxisProperties* timeAxisProperties();
time_t firstTimeStepOfFirstCurve();

void selectAxisInPropertyEditor(int axis);

virtual QWidget* viewWidget() override;
Expand Down
Loading

0 comments on commit 5d04ac1

Please sign in to comment.