Commit c60401e1 authored by Marc R.'s avatar Marc R.

MStructuredGrid: getTop/BottomDataVolumePressure() now cache their results;...

MStructuredGrid: getTop/BottomDataVolumePressure() now cache their results; the methods are called in the render method of the HSec actor are recomputation caused considerable performance loss in particular for aux-p grids
parent d2f30322
......@@ -1314,8 +1314,8 @@ void MNWPHorizontalSectionActor::renderToCurrentContext(MSceneViewGLWidget *scen
// fields to there data volume pressure since this is zero and thus
// surface fields won't be drawn anymore.
if (var->grid->getLevelType() != MVerticalLevelType::SURFACE_2D
&& (var->grid->getBottomDataVolumePressure() < slicePosition_hPa
|| var->grid->getTopDataVolumePressure() > slicePosition_hPa))
&& (var->grid->getBottomDataVolumePressure_hPa() < slicePosition_hPa
|| var->grid->getTopDataVolumePressure_hPa() > slicePosition_hPa))
{
continue;
}
......@@ -1341,9 +1341,9 @@ void MNWPHorizontalSectionActor::renderToCurrentContext(MSceneViewGLWidget *scen
// If the slice position is outside the model grid domain of the
// 2nd variable, there is nothing to render.
if ((varDiff->grid->getBottomDataVolumePressure()
if ((varDiff->grid->getBottomDataVolumePressure_hPa()
< slicePosition_hPa)
|| (varDiff->grid->getTopDataVolumePressure()
|| (varDiff->grid->getTopDataVolumePressure_hPa()
> slicePosition_hPa))
{
continue;
......@@ -2454,8 +2454,8 @@ void MNWPHorizontalSectionActor::renderVectorGlyphs(
// Don't render vector glyphs if horizontal slice position is outside the
// data domain (assuming longitudial/latitudial are on the same grid).
if (varLatitudinal->grid->getLevelType() != SURFACE_2D &&
(varLatitudinal->grid->getBottomDataVolumePressure() < slicePosition_hPa
|| varLatitudinal->grid->getTopDataVolumePressure() > slicePosition_hPa))
(varLatitudinal->grid->getBottomDataVolumePressure_hPa() < slicePosition_hPa
|| varLatitudinal->grid->getTopDataVolumePressure_hPa() > slicePosition_hPa))
{
return;
}
......@@ -2867,8 +2867,8 @@ void MNWPHorizontalSectionActor::renderContourLabels(
// to there data volume pressure since this is zero and thus surface
// fields won't be drawn anymore.
if (var->grid->getLevelType() != MVerticalLevelType::SURFACE_2D
&& (var->grid->getBottomDataVolumePressure() < slicePosition_hPa
|| var->grid->getTopDataVolumePressure() > slicePosition_hPa))
&& (var->grid->getBottomDataVolumePressure_hPa() < slicePosition_hPa
|| var->grid->getTopDataVolumePressure_hPa() > slicePosition_hPa))
{
return;
}
......
......@@ -444,13 +444,13 @@ MIndex3D MStructuredGrid::maxNeighbouringGridPoint(QVector3D vec3_lonLatP)
QVector3D MStructuredGrid::getNorthWestTopDataVolumeCorner_lonlatp()
{
return QVector3D(lons[0], lats[0], getTopDataVolumePressure());
return QVector3D(lons[0], lats[0], getTopDataVolumePressure_hPa());
}
QVector3D MStructuredGrid::getSouthEastBottomDataVolumeCorner_lonlatp()
{
return QVector3D(lons[nlons-1], lats[nlats-1], getBottomDataVolumePressure());
return QVector3D(lons[nlons-1], lats[nlats-1], getBottomDataVolumePressure_hPa());
}
......@@ -1489,7 +1489,9 @@ MLonLatHybridSigmaPressureGrid::MLonLatHybridSigmaPressureGrid(
bk(new double[nlevs]),
aki_hPa(nullptr),
bki(nullptr),
surfacePressure(nullptr)
surfacePressure(nullptr),
cachedTopDataVolumePressure_hPa(M_MISSING_VALUE),
cachedBottomDataVolumePressure_hPa(M_MISSING_VALUE)
{
akbkID = getID() + "hyb";
}
......@@ -1909,17 +1911,36 @@ float MLonLatHybridSigmaPressureGrid::getTopInterfacePressure(
}
float MLonLatHybridSigmaPressureGrid::getTopDataVolumePressure()
float MLonLatHybridSigmaPressureGrid::getTopDataVolumePressure_hPa(
bool useCachedValue)
{
float psfc_min = surfacePressure->min() / 100.;
return (ak_hPa[0] + bk[0] * psfc_min);
if (cachedTopDataVolumePressure_hPa == M_MISSING_VALUE || !useCachedValue)
{
// Update cached value upon first call or if explicity requested by
// caller.
float psfc_min = surfacePressure->min() / 100.;
cachedTopDataVolumePressure_hPa = (ak_hPa[0] + bk[0] * psfc_min);
}
// Return cached value.
return cachedTopDataVolumePressure_hPa;
}
float MLonLatHybridSigmaPressureGrid::getBottomDataVolumePressure()
float MLonLatHybridSigmaPressureGrid::getBottomDataVolumePressure_hPa(
bool useCachedValue)
{
float psfc_max = surfacePressure->max() / 100.;
return (ak_hPa[nlevs-1] + bk[nlevs-1] * psfc_max);
if (cachedBottomDataVolumePressure_hPa == M_MISSING_VALUE || !useCachedValue)
{
// Update cached value upon first call or if explicity requested by
// caller.
float psfc_max = surfacePressure->max() / 100.;
cachedBottomDataVolumePressure_hPa =
(ak_hPa[nlevs-1] + bk[nlevs-1] * psfc_max);
}
// Return cached value.
return cachedBottomDataVolumePressure_hPa;
}
......@@ -2024,7 +2045,9 @@ MLonLatAuxiliaryPressureGrid::MLonLatAuxiliaryPressureGrid(
bool reverseLevels)
: MStructuredGrid(AUXILIARY_PRESSURE_3D, nlevs, nlats, nlons),
auxPressureField_hPa(nullptr),
reverseLevels(reverseLevels)
reverseLevels(reverseLevels),
cachedTopDataVolumePressure_hPa(M_MISSING_VALUE),
cachedBottomDataVolumePressure_hPa(M_MISSING_VALUE)
{}
......@@ -2170,15 +2193,33 @@ float MLonLatAuxiliaryPressureGrid::getTopInterfacePressure(
}
float MLonLatAuxiliaryPressureGrid::getTopDataVolumePressure()
float MLonLatAuxiliaryPressureGrid::getTopDataVolumePressure_hPa(
bool useCachedValue)
{
return auxPressureField_hPa->min();
if (cachedTopDataVolumePressure_hPa == M_MISSING_VALUE || !useCachedValue)
{
// Update cached value upon first call or if explicity requested by
// caller.
cachedTopDataVolumePressure_hPa = auxPressureField_hPa->min();
}
// Return cached value.
return cachedTopDataVolumePressure_hPa;
}
float MLonLatAuxiliaryPressureGrid::getBottomDataVolumePressure()
float MLonLatAuxiliaryPressureGrid::getBottomDataVolumePressure_hPa(
bool useCachedValue)
{
return auxPressureField_hPa->max();
if (cachedBottomDataVolumePressure_hPa == M_MISSING_VALUE || !useCachedValue)
{
// Update cached value upon first call or if explicity requested by
// caller.
cachedBottomDataVolumePressure_hPa = auxPressureField_hPa->max();
}
// Return cached value.
return cachedBottomDataVolumePressure_hPa;
}
......
......@@ -321,9 +321,23 @@ public:
QVector3D getSouthEastBottomDataVolumeCorner_lonlatp();
virtual float getTopDataVolumePressure() { return 0.; }
/**
Returns the topmost pressure elevation of the data volume. If
@p useCachedValue is set to @p true (default), the value is computed
once and reused (i.e., the vertical levels are assumed to be static).
If you change the vertical levels and need to update this value,
set @p useCachedValue to @p false.
*/
virtual float getTopDataVolumePressure_hPa(bool useCachedValue=true)
{ Q_UNUSED(useCachedValue); return 0.; }
virtual float getBottomDataVolumePressure() { return 0.; }
/**
Returns the bottommost pressure elevation of the data volume.
See @see getTopDataVolumePressure_hPa() for the meaning of the
@p useCachedValue parameter.
*/
virtual float getBottomDataVolumePressure_hPa(bool useCachedValue=true)
{ Q_UNUSED(useCachedValue); return 0.; }
bool gridIsCyclicInLongitude();
......@@ -608,9 +622,11 @@ public:
float getTopInterfacePressure(
unsigned int k, unsigned int j, unsigned int i);
float getTopDataVolumePressure() override { return exp(levels[0]); }
float getTopDataVolumePressure_hPa(bool useCachedValue=true) override
{ Q_UNUSED(useCachedValue); return exp(levels[0]); }
float getBottomDataVolumePressure() override { return exp(levels[nlevs-1]); }
float getBottomDataVolumePressure_hPa(bool useCachedValue=true) override
{ Q_UNUSED(useCachedValue); return exp(levels[nlevs-1]); }
protected:
......@@ -646,9 +662,11 @@ public:
float getTopInterfacePressure(
unsigned int k, unsigned int j, unsigned int i);
float getTopDataVolumePressure() override { return levels[0]; }
float getTopDataVolumePressure_hPa(bool useCachedValue=true) override
{ Q_UNUSED(useCachedValue); return levels[0]; }
float getBottomDataVolumePressure() override { return levels[nlevs-1]; }
float getBottomDataVolumePressure_hPa(bool useCachedValue=true) override
{ Q_UNUSED(useCachedValue); return levels[nlevs-1]; }
protected:
......@@ -727,9 +745,9 @@ public:
float getTopInterfacePressure(
unsigned int k, unsigned int j, unsigned int i);
float getTopDataVolumePressure() override;
float getTopDataVolumePressure_hPa(bool useCachedValue=true) override;
float getBottomDataVolumePressure() override;
float getBottomDataVolumePressure_hPa(bool useCachedValue=true) override;
void dumpGridData(unsigned int maxValues=50);
......@@ -764,6 +782,8 @@ protected:
private:
QString pressureTexCoordID;
double cachedTopDataVolumePressure_hPa;
double cachedBottomDataVolumePressure_hPa;
};
......@@ -791,9 +811,9 @@ public:
float getTopInterfacePressure(
unsigned int k, unsigned int j, unsigned int i);
float getTopDataVolumePressure() override;
float getTopDataVolumePressure_hPa(bool useCachedValue=true) override;
float getBottomDataVolumePressure() override;
float getBottomDataVolumePressure_hPa(bool useCachedValue=true) override;
/**
Returns the reverseLevels-Flag.
......@@ -815,6 +835,10 @@ protected:
MLonLatAuxiliaryPressureGrid *auxPressureField_hPa;
bool reverseLevels;
private:
double cachedTopDataVolumePressure_hPa;
double cachedBottomDataVolumePressure_hPa;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment