#165 Use original days since simulation start when plotting time history curves

This commit is contained in:
Bjørnar Grip Fjær 2017-04-26 09:40:42 +02:00
parent 2c8358e9e9
commit ad4657d610
4 changed files with 103 additions and 18 deletions

View File

@ -294,7 +294,6 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate()
if (isCurveVisible())
{
std::vector<time_t> dateTimes;
std::vector<double> values;
RimEclipseGeometrySelectionItem* eclTopItem = eclipseGeomSelectionItem();
@ -309,39 +308,43 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate()
m_geoMechResultDefinition->loadResult();
}
dateTimes = timeStepValues();
values = yValues();
RimSummaryPlot* plot = nullptr;
firstAncestorOrThisOfType(plot);
bool isLogCurve = plot->isLogarithmicScaleEnabled(this->yAxis());
if (dateTimes.size() > 0 && dateTimes.size() == values.size())
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
{
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
std::vector<time_t> dateTimes = timeStepValues();
if (dateTimes.size() > 0 && dateTimes.size() == values.size())
{
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);
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
}
}
else
{
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
std::vector<double> days = daysSinceSimulationStart();
if (days.size() > 0 && days.size() == values.size())
{
double timeScale = plot->timeAxisProperties()->fromDaysToDisplayUnitScale();
std::vector<double> times;
for (double day : days)
{
times.push_back(timeScale * day);
}
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
}
else
{
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
}
}
updateZoomInParentPlot();
@ -404,6 +407,56 @@ std::vector<time_t> RimGridTimeHistoryCurve::timeStepValues() const
return dateTimes;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RimGridTimeHistoryCurve::daysSinceSimulationStart() const
{
std::vector<double> daysSinceSimulationStart;
RimEclipseGeometrySelectionItem* eclTopItem = eclipseGeomSelectionItem();
if (eclTopItem && eclTopItem->eclipseCase())
{
RimReservoirCellResultsStorage* cellResStorage = m_eclipseResultDefinition->currentGridCellResults();
RigCaseCellResultsData* cellResultsData = cellResStorage->cellResults();
daysSinceSimulationStart = cellResultsData->daysSinceSimulationStart();
}
RimGeoMechGeometrySelectionItem* geoMechTopItem = geoMechGeomSelectionItem();
if (geoMechTopItem && geoMechTopItem->geoMechCase())
{
std::unique_ptr<RiuFemTimeHistoryResultAccessor> timeHistResultAccessor = femTimeHistoryResultAccessor();
if (timeHistResultAccessor)
{
std::vector<double> values = timeHistResultAccessor->timeHistoryValues();
QStringList stepNames = geoMechTopItem->geoMechCase()->timeStepStrings();
std::vector<QDateTime> dates = RimGeoMechCase::dateTimeVectorFromTimeStepStrings(stepNames);
if (dates.size() == values.size())
{
if (!dates.empty()) {
time_t startDate = dates[0].toTime_t();
double secondsToDaysConversion = (24.0 * 60.0 * 60.0);
for (QDateTime dt : dates)
{
double timeDifference = static_cast<double>(dt.toTime_t() - startDate);
daysSinceSimulationStart.push_back(timeDifference / secondsToDaysConversion);
}
}
}
else
{
for (size_t i = 0; i < values.size(); i++)
{
daysSinceSimulationStart.push_back(i);
}
}
}
}
return daysSinceSimulationStart;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -56,6 +56,7 @@ public:
std::vector<double> yValues() const;
std::vector<time_t> timeStepValues() const;
std::vector<double> daysSinceSimulationStart() const;
QString quantityName() const;
QString caseName() const;

View File

@ -278,6 +278,36 @@ double RimSummaryTimeAxisProperties::fromTimeTToDisplayUnitScale()
return scale;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimSummaryTimeAxisProperties::fromDaysToDisplayUnitScale()
{
double scale = 1.0;
switch (m_timeUnit())
{
case SECONDS:
scale = 60.0 * 60.0 * 24.0;
break;
case MINUTES:
scale = 60.0 * 24.0;
break;
case HOURS:
scale = 24.0;
break;
case DAYS:
break;
case YEARS:
scale = 1.0/365.2425;
break;
default:
CVF_ASSERT(false);
break;
}
return scale;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -69,6 +69,7 @@ public:
TimeModeType timeMode() const { return m_timeMode(); }
void setTimeMode(TimeModeType val) { m_timeMode = val; }
double fromTimeTToDisplayUnitScale();
double fromDaysToDisplayUnitScale();
double visibleRangeMin() const;
double visibleRangeMax() const;