mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
Migrate all assert macros in ApplicationLibCode to CAF_ASSERT and remove every use of cvfAssert.h. CVF_ASSERT is replaced one to one. CVF_TIGHT_ASSERT is also replaced by CAF_ASSERT, which is semantically exact: CVF_ENABLE_TIGHT_ASSERTS is 1 only under _DEBUG, and that is what CAF_ASSERT now does. The two CVF_FAIL_MSG sites become CAF_ASSERT( false && "message" ), preserving the message with the idiom already used elsewhere in the code base. Counts before and after: CVF_ASSERT 1044 to 0, CVF_TIGHT_ASSERT 66 to 0, CVF_FAIL_MSG 2 to 0, cvfAssert.h references 154 to 0. Include handling: files that included cvfAssert.h directly now include cafAssert.h instead, includes left dead by the migration are removed, and files that were relying on cvfAssert.h transitively get an explicit cafAssert.h. Files that reach cafAssert.h through another caf header are left unchanged; a missing include here is a compile error, not a silently disabled assert. ResultStatisticsCache links only LibCore and therefore had no path to cafAssert.h. Add the cafPdmCore directory as a private include path rather than linking the library, since cafAssert.h is header only. Note that this stops these asserts from firing in Release and RelWithDebInfo, where CVF_ASSERT was previously active.
173 lines
8.2 KiB
C++
173 lines
8.2 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2020- Equinor ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RigFemPartResultCalculatorStressGradients.h"
|
|
|
|
#include "RigFemPart.h"
|
|
#include "RigFemPartCollection.h"
|
|
#include "RigFemPartResultsCollection.h"
|
|
#include "RigFemResultAddress.h"
|
|
#include "RigFemScalarResultFrames.h"
|
|
#include "RigHexGradientTools.h"
|
|
|
|
#include "cafProgressInfo.h"
|
|
|
|
#include <QString>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RigFemPartResultCalculatorStressGradients::RigFemPartResultCalculatorStressGradients( RigFemPartResultsCollection& collection )
|
|
: RigFemPartResultCalculator( collection )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RigFemPartResultCalculatorStressGradients::~RigFemPartResultCalculatorStressGradients()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RigFemPartResultCalculatorStressGradients::isMatching( const RigFemResultAddress& resVarAddr ) const
|
|
{
|
|
if ( resVarAddr.fieldName == "ST" || resVarAddr.fieldName == "SE" )
|
|
{
|
|
const std::vector<std::string> allowedComponentNames = RigFemPartResultsCollection::getStressGradientComponentNames();
|
|
|
|
for ( auto& allowedComponentName : allowedComponentNames )
|
|
{
|
|
if ( resVarAddr.componentName == allowedComponentName )
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RigFemScalarResultFrames* RigFemPartResultCalculatorStressGradients::calculate( int partIndex, const RigFemResultAddress& resVarAddr )
|
|
{
|
|
CAF_ASSERT( resVarAddr.fieldName == "ST" || resVarAddr.fieldName == "SE" );
|
|
|
|
caf::ProgressInfo stepCountProgress( m_resultCollection->timeStepCount() * 2, "" );
|
|
stepCountProgress.setProgressDescription( "Calculating gradient: " +
|
|
QString::fromStdString( resVarAddr.fieldName + ": " + resVarAddr.componentName ) );
|
|
stepCountProgress.setNextProgressIncrement( m_resultCollection->timeStepCount() );
|
|
|
|
QString origFieldName = QString::fromStdString( resVarAddr.fieldName );
|
|
QString origComponentName = QString::fromStdString( resVarAddr.componentName );
|
|
// Split out the direction of the component name: SE-X => SE
|
|
QString componentName = origComponentName.left( origComponentName.lastIndexOf( QChar( '-' ) ) );
|
|
|
|
RigFemScalarResultFrames* inputResultFrames =
|
|
m_resultCollection->findOrLoadScalarResult( partIndex,
|
|
RigFemResultAddress( resVarAddr.resultPosType,
|
|
resVarAddr.fieldName,
|
|
componentName.toStdString() ) );
|
|
|
|
RigFemScalarResultFrames* dataFramesX =
|
|
m_resultCollection->createScalarResult( partIndex,
|
|
RigFemResultAddress( resVarAddr.resultPosType,
|
|
resVarAddr.fieldName,
|
|
componentName.toStdString() + "-X" ) );
|
|
RigFemScalarResultFrames* dataFramesY =
|
|
m_resultCollection->createScalarResult( partIndex,
|
|
RigFemResultAddress( resVarAddr.resultPosType,
|
|
resVarAddr.fieldName,
|
|
componentName.toStdString() + "-Y" ) );
|
|
RigFemScalarResultFrames* dataFramesZ =
|
|
m_resultCollection->createScalarResult( partIndex,
|
|
RigFemResultAddress( resVarAddr.resultPosType,
|
|
resVarAddr.fieldName,
|
|
componentName.toStdString() + "-Z" ) );
|
|
stepCountProgress.incrementProgress();
|
|
|
|
const RigFemPart* femPart = m_resultCollection->parts()->part( partIndex );
|
|
int elementCount = femPart->elementCount();
|
|
const std::vector<cvf::Vec3f>& nodeCoords = femPart->nodes().coordinates;
|
|
|
|
const int timeSteps = inputResultFrames->timeStepCount();
|
|
for ( int stepIdx = 0; stepIdx < timeSteps; stepIdx++ )
|
|
{
|
|
const int frameCount = inputResultFrames->frameCount( stepIdx );
|
|
for ( int fIdx = 0; fIdx < frameCount; fIdx++ )
|
|
{
|
|
const std::vector<float>& inputData = inputResultFrames->frameData( stepIdx, fIdx );
|
|
|
|
std::vector<float>& dstFrameDataX = dataFramesX->frameData( stepIdx, fIdx );
|
|
std::vector<float>& dstFrameDataY = dataFramesY->frameData( stepIdx, fIdx );
|
|
std::vector<float>& dstFrameDataZ = dataFramesZ->frameData( stepIdx, fIdx );
|
|
size_t valCount = inputData.size();
|
|
if ( valCount == 0 ) continue;
|
|
|
|
dstFrameDataX.resize( valCount );
|
|
dstFrameDataY.resize( valCount );
|
|
dstFrameDataZ.resize( valCount );
|
|
|
|
#pragma omp parallel for schedule( dynamic )
|
|
for ( int elmIdx = 0; elmIdx < elementCount; ++elmIdx )
|
|
{
|
|
const int* cornerIndices = femPart->connectivities( elmIdx );
|
|
RigElementType elmType = femPart->elementType( elmIdx );
|
|
|
|
if ( !RigFemTypes::is8NodeElement( elmType ) ) continue;
|
|
|
|
// Find the corner coordinates for element
|
|
std::array<cvf::Vec3d, 8> hexCorners;
|
|
for ( int i = 0; i < 8; i++ )
|
|
{
|
|
hexCorners[i] = cvf::Vec3d( nodeCoords[cornerIndices[i]] );
|
|
}
|
|
|
|
// Find the corresponding corner values for the element
|
|
std::array<double, 8> cornerValues;
|
|
|
|
int elmNodeCount = RigFemTypes::elementNodeCount( elmType );
|
|
for ( int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx )
|
|
{
|
|
size_t elmNodResIdx = femPart->elementNodeResultIdx( elmIdx, elmNodIdx );
|
|
cornerValues[elmNodIdx] = inputData[elmNodResIdx];
|
|
}
|
|
|
|
std::array<cvf::Vec3d, 8> gradients = RigHexGradientTools::gradients( hexCorners, cornerValues );
|
|
|
|
for ( int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx )
|
|
{
|
|
size_t elmNodResIdx = femPart->elementNodeResultIdx( elmIdx, elmNodIdx );
|
|
dstFrameDataX[elmNodResIdx] = gradients[elmNodIdx].x();
|
|
dstFrameDataY[elmNodResIdx] = gradients[elmNodIdx].y();
|
|
dstFrameDataZ[elmNodResIdx] = gradients[elmNodIdx].z();
|
|
}
|
|
}
|
|
}
|
|
stepCountProgress.incrementProgress();
|
|
}
|
|
|
|
RigFemScalarResultFrames* requestedStress = m_resultCollection->findOrLoadScalarResult( partIndex, resVarAddr );
|
|
CAF_ASSERT( requestedStress );
|
|
return requestedStress;
|
|
}
|