#4669 Compute stress gradient.

This commit is contained in:
Kristian Bendiksen 2020-01-16 13:54:26 +01:00
parent 50f219412a
commit 17d0bcb49c
5 changed files with 245 additions and 87 deletions

View File

@ -33,9 +33,11 @@ add_library( ${PROJECT_NAME}
RigFemResultAddress.h
RigFemResultPosEnum.h
RimFemResultObserver.h
RimFemResultObserver.cpp
RimGeoMechGeometrySelectionItem.h
RimGeoMechGeometrySelectionItem.cpp
RimFemResultObserver.cpp
RigHexGradientTools.h
RigHexGradientTools.cpp
RimGeoMechGeometrySelectionItem.h
RimGeoMechGeometrySelectionItem.cpp
)
target_include_directories(${PROJECT_NAME}

View File

@ -36,6 +36,7 @@
#include "RigFemPartResults.h"
#include "RigFemScalarResultFrames.h"
#include "RigFormationNames.h"
#include "RigHexGradientTools.h"
#include "RigHexIntersectionTools.h"
#include "RigStatisticsDataCache.h"
#include "RigWbsParameter.h"
@ -45,11 +46,10 @@
#include "RimWellLogPlot.h"
#include "RimWellLogPlotCollection.h"
#include "cafProgressInfo.h"
#include "cvfBoundingBox.h"
#include "cafProgressInfo.h"
#include "cafTensor3.h"
#include "cvfBoundingBox.h"
#include "cvfGeometryTools.h"
#include "cvfMath.h"
@ -1008,6 +1008,10 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateStressGradient(
frameCountProgress.incrementProgress();
const RigFemPart* femPart = m_femParts->part( partIndex );
int elementCount = femPart->elementCount();
const std::vector<cvf::Vec3f>& nodeCoords = femPart->nodes().coordinates;
int frameCount = st11->frameCount();
for ( int fIdx = 0; fIdx < frameCount; ++fIdx )
{
@ -1017,10 +1021,40 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateStressGradient(
size_t valCount = st11Data.size();
dstFrameData.resize( valCount );
#pragma omp parallel for
for ( long vIdx = 0; vIdx < static_cast<long>( valCount ); ++vIdx )
#pragma omp parallel for schedule( dynamic )
for ( int elmIdx = 0; elmIdx < elementCount; ++elmIdx )
{
dstFrameData[vIdx] = st11Data[vIdx];
const int* cornerIndices = femPart->connectivities( elmIdx );
RigElementType elmType = femPart->elementType( elmIdx );
if ( !( elmType == HEX8P || elmType == HEX8 ) ) 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::elmentNodeCount( elmType );
for ( int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx )
{
size_t elmNodResIdx = femPart->elementNodeResultIdx( elmIdx, elmNodIdx );
int nodeIdx = femPart->nodeIdxFromElementNodeResultIdx( elmNodResIdx );
cornerValues[elmNodIdx] = st11Data[nodeIdx];
}
std::array<cvf::Vec3d, 8> gradients = RigHexGradientTools::gradients( hexCorners, cornerValues );
for ( int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx )
{
size_t elmNodResIdx = femPart->elementNodeResultIdx( elmIdx, elmNodIdx );
dstFrameData[elmNodResIdx] = gradients[elmNodIdx].x();
}
}
frameCountProgress.incrementProgress();

View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RigHexGradientTools.h"
#include "../cafHexInterpolator/cafHexInterpolator.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::array<cvf::Vec3d, 8> RigHexGradientTools::gradients( const std::array<cvf::Vec3d, 8>& hexCorners,
const std::array<double, 8>& values )
{
//
std::array<cvf::Vec3d, 8> gradientsUVW;
gradientsUVW[0] = cvf::Vec3d( forwardFD( values, 0, 1 ), forwardFD( values, 0, 3 ), forwardFD( values, 0, 4 ) );
gradientsUVW[1] = cvf::Vec3d( backwardFD( values, 1, 0 ), forwardFD( values, 1, 2 ), forwardFD( values, 1, 5 ) );
gradientsUVW[2] = cvf::Vec3d( backwardFD( values, 2, 3 ), backwardFD( values, 2, 1 ), forwardFD( values, 2, 6 ) );
gradientsUVW[3] = cvf::Vec3d( forwardFD( values, 3, 2 ), backwardFD( values, 3, 0 ), forwardFD( values, 3, 7 ) );
gradientsUVW[4] = cvf::Vec3d( forwardFD( values, 4, 5 ), forwardFD( values, 4, 7 ), backwardFD( values, 4, 0 ) );
gradientsUVW[5] = cvf::Vec3d( backwardFD( values, 5, 4 ), forwardFD( values, 5, 6 ), backwardFD( values, 5, 1 ) );
gradientsUVW[6] = cvf::Vec3d( backwardFD( values, 6, 7 ), backwardFD( values, 6, 5 ), backwardFD( values, 6, 2 ) );
gradientsUVW[7] = cvf::Vec3d( forwardFD( values, 7, 6 ), backwardFD( values, 7, 4 ), backwardFD( values, 7, 3 ) );
std::array<cvf::Vec3d, 8> NC;
NC[0] = {-1, -1, -1};
NC[1] = {1, -1, -1};
NC[2] = {1, 1, -1};
NC[3] = {-1, 1, -1};
NC[4] = {-1, -1, 1};
NC[5] = {1, -1, 1};
NC[6] = {1, 1, 1};
NC[7] = {-1, 1, 1};
std::array<cvf::Vec3d, 8> gradientsXYZ;
for ( int i = 0; i < 8; i++ )
{
bool isInvertPossible = false;
cvf::Mat3d jacobian = caf::HexInterpolator::jacobi( hexCorners, NC[i] );
gradientsXYZ[i] = gradientsUVW[i].getTransformedVector( jacobian.getInverted( &isInvertPossible ) );
}
return gradientsXYZ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigHexGradientTools::forwardFD( const std::array<double, 8>& values, int from, int to )
{
double h = 2.0;
return ( values[to] - values[from] ) / h;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigHexGradientTools::backwardFD( const std::array<double, 8>& values, int from, int to )
{
return forwardFD( values, to, from );
}

View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RigHexGradientTools.h"
#include "cvfVector3.h"
#include <array>
//==================================================================================================
///
//==================================================================================================
class RigHexGradientTools
{
public:
static std::array<cvf::Vec3d, 8> gradients( const std::array<cvf::Vec3d, 8>& hexCorners,
const std::array<double, 8>& values );
private:
// Private to avoid instantiation
RigHexGradientTools();
static double forwardFD( const std::array<double, 8>& values, int from, int to );
static double backwardFD( const std::array<double, 8>& values, int from, int to );
};

View File

@ -220,6 +220,85 @@ public:
return interpolationCoeffs(pointInNormElm);
}
static cvf::Mat3d jacobi(const std::array<cvf::Vec3d, 8>& hexCorners, const cvf::Vec3d & pointInNormalizedElement)
{
const double k_1_8 = 0.125;
double i = pointInNormalizedElement[0];
double j = pointInNormalizedElement[1];
double k = pointInNormalizedElement[2];
double ij = i*j;
double ik = i*k;
double jk = j*k;
double C0_x = hexCorners[0][0]; double C0_y = hexCorners[0][1]; double C0_z = hexCorners[0][2];
double C1_x = hexCorners[1][0]; double C1_y = hexCorners[1][1]; double C1_z = hexCorners[1][2];
double C2_x = hexCorners[2][0]; double C2_y = hexCorners[2][1]; double C2_z = hexCorners[2][2];
double C3_x = hexCorners[3][0]; double C3_y = hexCorners[3][1]; double C3_z = hexCorners[3][2];
double C4_x = hexCorners[4][0]; double C4_y = hexCorners[4][1]; double C4_z = hexCorners[4][2];
double C5_x = hexCorners[5][0]; double C5_y = hexCorners[5][1]; double C5_z = hexCorners[5][2];
double C6_x = hexCorners[6][0]; double C6_y = hexCorners[6][1]; double C6_z = hexCorners[6][2];
double C7_x = hexCorners[7][0]; double C7_y = hexCorners[7][1]; double C7_z = hexCorners[7][2];
double dN0_di = (- 1 + j + k - jk);
double dN1_di = (+ 1 - j - k + jk);
double dN2_di = (+ 1 + j - k - jk);
double dN3_di = (- 1 - j + k + jk);
double dN4_di = (- 1 + j - k + jk);
double dN5_di = (+ 1 - j + k - jk);
double dN6_di = (+ 1 + j + k + jk);
double dN7_di = (- 1 - j - k - jk);
double dN0_dj = (- 1 + i + k - ik);
double dN1_dj = (- 1 - i + k + ik);
double dN2_dj = (+ 1 + i - k - ik);
double dN3_dj = (+ 1 - i - k + ik);
double dN4_dj = (- 1 + i - k + ik);
double dN5_dj = (- 1 - i - k - ik);
double dN6_dj = (+ 1 + i + k + ik);
double dN7_dj = (+ 1 - i + k - ik);
double dN0_dk = (- 1 + i + j - ij);
double dN1_dk = (- 1 - i + j + ij);
double dN2_dk = (- 1 - i - j - ij);
double dN3_dk = (- 1 + i - j + ij);
double dN4_dk = (+ 1 - i - j + ij);
double dN5_dk = (+ 1 + i - j - ij);
double dN6_dk = (+ 1 + i + j + ij);
double dN7_dk = (+ 1 - i + j - ij);
double dx_di = k_1_8 * ( (dN0_di) * C0_x + (dN1_di) * C1_x + (dN2_di) * C2_x + (dN3_di) * C3_x + (dN4_di) * C4_x + (dN5_di) * C5_x + (dN6_di) * C6_x + (dN7_di) * C7_x );
double dx_dj = k_1_8 * ( (dN0_dj) * C0_x + (dN1_dj) * C1_x + (dN2_dj) * C2_x + (dN3_dj) * C3_x + (dN4_dj) * C4_x + (dN5_dj) * C5_x + (dN6_dj) * C6_x + (dN7_dj) * C7_x );
double dx_dk = k_1_8 * ( (dN0_dk) * C0_x + (dN1_dk) * C1_x + (dN2_dk) * C2_x + (dN3_dk) * C3_x + (dN4_dk) * C4_x + (dN5_dk) * C5_x + (dN6_dk) * C6_x + (dN7_dk) * C7_x );
double dy_di = k_1_8 * ( (dN0_di) * C0_y + (dN1_di) * C1_y + (dN2_di) * C2_y + (dN3_di) * C3_y + (dN4_di) * C4_y + (dN5_di) * C5_y + (dN6_di) * C6_y + (dN7_di) * C7_y );
double dy_dj = k_1_8 * ( (dN0_dj) * C0_y + (dN1_dj) * C1_y + (dN2_dj) * C2_y + (dN3_dj) * C3_y + (dN4_dj) * C4_y + (dN5_dj) * C5_y + (dN6_dj) * C6_y + (dN7_dj) * C7_y );
double dy_dk = k_1_8 * ( (dN0_dk) * C0_y + (dN1_dk) * C1_y + (dN2_dk) * C2_y + (dN3_dk) * C3_y + (dN4_dk) * C4_y + (dN5_dk) * C5_y + (dN6_dk) * C6_y + (dN7_dk) * C7_y );
double dz_di = k_1_8 * ( (dN0_di) * C0_z + (dN1_di) * C1_z + (dN2_di) * C2_z + (dN3_di) * C3_z + (dN4_di) * C4_z + (dN5_di) * C5_z + (dN6_di) * C6_z + (dN7_di) * C7_z );
double dz_dj = k_1_8 * ( (dN0_dj) * C0_z + (dN1_dj) * C1_z + (dN2_dj) * C2_z + (dN3_dj) * C3_z + (dN4_dj) * C4_z + (dN5_dj) * C5_z + (dN6_dj) * C6_z + (dN7_dj) * C7_z );
double dz_dk = k_1_8 * ( (dN0_dk) * C0_z + (dN1_dk) * C1_z + (dN2_dk) * C2_z + (dN3_dk) * C3_z + (dN4_dk) * C4_z + (dN5_dk) * C5_z + (dN6_dk) * C6_z + (dN7_dk) * C7_z );
// Do not know which ordering ends up as correct
#if 1 // Use literature jacobi ordering
return cvf::Mat3d(
dx_di, dx_dj, dx_dk,
dy_di, dy_dj, dy_dk,
dz_di, dz_dj, dz_dk
);
#else // use NTNU ordering
return cvf::Mat3d(
dx_di, dy_di, dz_di,
dx_dj, dy_dj, dz_dj,
dx_dk, dy_dk, dz_dk
);
#endif
}
private:
static double interpolateInNormElm( const cvf::Vec3d & pointInNormElm, const std::array<double, 8>& values)
@ -300,83 +379,6 @@ private:
return normPoint;
}
static cvf::Mat3d jacobi(const std::array<cvf::Vec3d, 8>& hexCorners, const cvf::Vec3d & pointInNormalizedElement)
{
const double k_1_8 = 0.125;
double i = pointInNormalizedElement[0];
double j = pointInNormalizedElement[1];
double k = pointInNormalizedElement[2];
double ij = i*j;
double ik = i*k;
double jk = j*k;
double C0_x = hexCorners[0][0]; double C0_y = hexCorners[0][1]; double C0_z = hexCorners[0][2];
double C1_x = hexCorners[1][0]; double C1_y = hexCorners[1][1]; double C1_z = hexCorners[1][2];
double C2_x = hexCorners[2][0]; double C2_y = hexCorners[2][1]; double C2_z = hexCorners[2][2];
double C3_x = hexCorners[3][0]; double C3_y = hexCorners[3][1]; double C3_z = hexCorners[3][2];
double C4_x = hexCorners[4][0]; double C4_y = hexCorners[4][1]; double C4_z = hexCorners[4][2];
double C5_x = hexCorners[5][0]; double C5_y = hexCorners[5][1]; double C5_z = hexCorners[5][2];
double C6_x = hexCorners[6][0]; double C6_y = hexCorners[6][1]; double C6_z = hexCorners[6][2];
double C7_x = hexCorners[7][0]; double C7_y = hexCorners[7][1]; double C7_z = hexCorners[7][2];
double dN0_di = (- 1 + j + k - jk);
double dN1_di = (+ 1 - j - k + jk);
double dN2_di = (+ 1 + j - k - jk);
double dN3_di = (- 1 - j + k + jk);
double dN4_di = (- 1 + j - k + jk);
double dN5_di = (+ 1 - j + k - jk);
double dN6_di = (+ 1 + j + k + jk);
double dN7_di = (- 1 - j - k - jk);
double dN0_dj = (- 1 + i + k - ik);
double dN1_dj = (- 1 - i + k + ik);
double dN2_dj = (+ 1 + i - k - ik);
double dN3_dj = (+ 1 - i - k + ik);
double dN4_dj = (- 1 + i - k + ik);
double dN5_dj = (- 1 - i - k - ik);
double dN6_dj = (+ 1 + i + k + ik);
double dN7_dj = (+ 1 - i + k - ik);
double dN0_dk = (- 1 + i + j - ij);
double dN1_dk = (- 1 - i + j + ij);
double dN2_dk = (- 1 - i - j - ij);
double dN3_dk = (- 1 + i - j + ij);
double dN4_dk = (+ 1 - i - j + ij);
double dN5_dk = (+ 1 + i - j - ij);
double dN6_dk = (+ 1 + i + j + ij);
double dN7_dk = (+ 1 - i + j - ij);
double dx_di = k_1_8 * ( (dN0_di) * C0_x + (dN1_di) * C1_x + (dN2_di) * C2_x + (dN3_di) * C3_x + (dN4_di) * C4_x + (dN5_di) * C5_x + (dN6_di) * C6_x + (dN7_di) * C7_x );
double dx_dj = k_1_8 * ( (dN0_dj) * C0_x + (dN1_dj) * C1_x + (dN2_dj) * C2_x + (dN3_dj) * C3_x + (dN4_dj) * C4_x + (dN5_dj) * C5_x + (dN6_dj) * C6_x + (dN7_dj) * C7_x );
double dx_dk = k_1_8 * ( (dN0_dk) * C0_x + (dN1_dk) * C1_x + (dN2_dk) * C2_x + (dN3_dk) * C3_x + (dN4_dk) * C4_x + (dN5_dk) * C5_x + (dN6_dk) * C6_x + (dN7_dk) * C7_x );
double dy_di = k_1_8 * ( (dN0_di) * C0_y + (dN1_di) * C1_y + (dN2_di) * C2_y + (dN3_di) * C3_y + (dN4_di) * C4_y + (dN5_di) * C5_y + (dN6_di) * C6_y + (dN7_di) * C7_y );
double dy_dj = k_1_8 * ( (dN0_dj) * C0_y + (dN1_dj) * C1_y + (dN2_dj) * C2_y + (dN3_dj) * C3_y + (dN4_dj) * C4_y + (dN5_dj) * C5_y + (dN6_dj) * C6_y + (dN7_dj) * C7_y );
double dy_dk = k_1_8 * ( (dN0_dk) * C0_y + (dN1_dk) * C1_y + (dN2_dk) * C2_y + (dN3_dk) * C3_y + (dN4_dk) * C4_y + (dN5_dk) * C5_y + (dN6_dk) * C6_y + (dN7_dk) * C7_y );
double dz_di = k_1_8 * ( (dN0_di) * C0_z + (dN1_di) * C1_z + (dN2_di) * C2_z + (dN3_di) * C3_z + (dN4_di) * C4_z + (dN5_di) * C5_z + (dN6_di) * C6_z + (dN7_di) * C7_z );
double dz_dj = k_1_8 * ( (dN0_dj) * C0_z + (dN1_dj) * C1_z + (dN2_dj) * C2_z + (dN3_dj) * C3_z + (dN4_dj) * C4_z + (dN5_dj) * C5_z + (dN6_dj) * C6_z + (dN7_dj) * C7_z );
double dz_dk = k_1_8 * ( (dN0_dk) * C0_z + (dN1_dk) * C1_z + (dN2_dk) * C2_z + (dN3_dk) * C3_z + (dN4_dk) * C4_z + (dN5_dk) * C5_z + (dN6_dk) * C6_z + (dN7_dk) * C7_z );
// Do not know which ordering ends up as correct
#if 1 // Use literature jacobi ordering
return cvf::Mat3d(
dx_di, dx_dj, dx_dk,
dy_di, dy_dj, dy_dk,
dz_di, dz_dj, dz_dk
);
#else // use NTNU ordering
return cvf::Mat3d(
dx_di, dy_di, dz_di,
dx_dj, dy_dj, dz_dj,
dx_dk, dy_dk, dz_dk
);
#endif
}
};
}
}