Skip to content

Commit

Permalink
fix elastic seismos bug (#2849)
Browse files Browse the repository at this point in the history
The rewrite of #2729 introduced a bug in the elastic solver, where the derived class had members shadowing the parent class variables.
The cleanup was done in #2557 but was somehow missed when cherry-picking commits to create #2729.
This PR:
- fixes elastic solver bug (member variables shadowing), reported by @shenchengyi, reproducer using `inputFiles/wavePropagation/elas3D_DAS_smoke.xml`: empty seismos time and sampled value;
- make `initTrace` consistent with `writeSeismoTrace` i.e. don't touch the file if `outputSeismoTrace` is unset;
- remove redundant / unused `ElasticWaveEquationSEM::getNumNodesPerElem`;
- code style consistency across `wavePropagation` solvers files (e.g. use `e` for element);
- use `pow(..., n)` patterns for clarity.
  • Loading branch information
tbeltzun authored and ouassimkh committed Feb 16, 2024
1 parent 1692a75 commit ece2ae9
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 128 deletions.
2 changes: 1 addition & 1 deletion integratedTests
Submodule integratedTests updated 33 files
+ tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_01/0to200_restart_000000201.root
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_01/0to200_restart_000000201/rank_0000000.hdf5
+ tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201.root
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000000.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000001.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000002.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000003.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000004.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000005.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000006.hdf5
+2 −2 tests/allTests/wavePropagation/baselines/elas3D_Q3_abc_fs_smoke_08/0to200_restart_000000201/rank_0000007.hdf5
+ tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_01/0to200_restart_000000201.root
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_01/0to200_restart_000000201/rank_0000000.hdf5
+ tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201.root
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000000.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000001.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000002.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000003.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000004.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000005.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000006.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_fs_smoke_08/0to200_restart_000000201/rank_0000007.hdf5
+ tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_01/0to200_restart_000000201.root
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_01/0to200_restart_000000201/rank_0000000.hdf5
+ tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201.root
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000000.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000001.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000002.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000003.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000004.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000005.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000006.hdf5
+1 −1 tests/allTests/wavePropagation/baselines/elas3D_abc_smoke_08/0to200_restart_000000201/rank_0000007.hdf5
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,13 @@ void AcousticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLev
{
using FE_TYPE = TYPEOFREF( finiteElement );

constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
localIndex const numFacesPerElem = elementSubRegion.numFacesPerElement();

acousticFirstOrderWaveEquationSEMKernels::
PrecomputeSourceAndReceiverKernel::
launch< EXEC_POLICY, FE_TYPE >
( elementSubRegion.size(),
regionIndex,
numNodesPerElem,
numFacesPerElem,
X,
elemGhostRank,
Expand Down Expand Up @@ -343,7 +341,7 @@ void AcousticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGro
} );
} );

WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_receiverConstants.size( 0 ), m_receiverIsLocal );
WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_outputSeismoTrace, m_receiverConstants.size( 0 ), m_receiverIsLocal );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct PrecomputeSourceAndReceiverKernel
* @tparam EXEC_POLICY execution policy
* @tparam FE_TYPE finite element type
* @param[in] size the number of cells in the subRegion
* @param[in] numNodesPerElem number of nodes per element
* @param[in] numFacesPerElem number of faces per element
* @param[in] nodeCoords coordinates of the nodes
* @param[in] elemGhostRank rank of the ghost element
Expand Down Expand Up @@ -68,7 +67,6 @@ struct PrecomputeSourceAndReceiverKernel
static void
launch( localIndex const size,
localIndex const regionIndex,
localIndex const numNodesPerElem,
localIndex const numFacesPerElem,
arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords,
arrayView1d< integer const > const elemGhostRank,
Expand All @@ -95,6 +93,7 @@ struct PrecomputeSourceAndReceiverKernel
real32 const timeSourceDelay,
localIndex const rickerOrder )
{
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;

forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
Expand Down Expand Up @@ -133,7 +132,7 @@ struct PrecomputeSourceAndReceiverKernel
sourceIsAccessible[isrc] = 1;
sourceElem[isrc] = k;
sourceRegion[isrc] = regionIndex;
real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -181,7 +180,7 @@ struct PrecomputeSourceAndReceiverKernel
rcvElem[ircv] = k;
receiverRegion[ircv] = regionIndex;

real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -227,26 +226,26 @@ struct MassMatrixKernel
arrayView1d< real32 > const mass )

{
forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k )
forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const e )
{

constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
constexpr localIndex numQuadraturePointsPerElem = FE_TYPE::numQuadraturePoints;

real32 const invC2 = 1.0 / ( density[k] * velocity[k] * velocity[k] );
real32 const invC2 = 1.0 / ( density[e] * pow( velocity[e], 2 ) );
real64 xLocal[ numNodesPerElem ][ 3 ];
for( localIndex a = 0; a < numNodesPerElem; ++a )
{
for( localIndex i = 0; i < 3; ++i )
{
xLocal[a][i] = nodeCoords( elemsToNodes( k, a ), i );
xLocal[a][i] = nodeCoords( elemsToNodes( e, a ), i );
}
}

for( localIndex q = 0; q < numQuadraturePointsPerElem; ++q )
{
real32 const localIncrement = invC2 * m_finiteElement.computeMassTerm( q, xLocal );
RAJA::atomicAdd< ATOMIC_POLICY >( &mass[elemsToNodes[k][q]], localIncrement );
RAJA::atomicAdd< ATOMIC_POLICY >( &mass[elemsToNodes( e, q )], localIncrement );
}
} ); // end loop over element
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ void AcousticVTIWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLevel & me
{
using FE_TYPE = TYPEOFREF( finiteElement );

constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
localIndex const numFacesPerElem = elementSubRegion.numFacesPerElement();

acousticVTIWaveEquationSEMKernels::
PrecomputeSourceAndReceiverKernel::
launch< EXEC_POLICY, FE_TYPE >
( elementSubRegion.size(),
numNodesPerElem,
numFacesPerElem,
X32,
elemGhostRank,
Expand Down Expand Up @@ -314,7 +312,7 @@ void AcousticVTIWaveEquationSEM::initializePostInitialConditionsPreSubGroups()
} );
} );

WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_receiverConstants.size( 0 ), m_receiverIsLocal );
WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_outputSeismoTrace, m_receiverConstants.size( 0 ), m_receiverIsLocal );
}

void AcousticVTIWaveEquationSEM::precomputeSurfaceFieldIndicator( DomainPartition & domain )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct PrecomputeSourceAndReceiverKernel
* @tparam EXEC_POLICY execution policy
* @tparam FE_TYPE finite element type
* @param[in] size the number of cells in the subRegion
* @param[in] numNodesPerElem number of nodes per element
* @param[in] numFacesPerElem number of faces per element
* @param[in] nodeCoords coordinates of the nodes
* @param[in] elemGhostRank the ghost ranks
Expand All @@ -64,7 +63,6 @@ struct PrecomputeSourceAndReceiverKernel
template< typename EXEC_POLICY, typename FE_TYPE >
static void
launch( localIndex const size,
localIndex const numNodesPerElem,
localIndex const numFacesPerElem,
arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords,
arrayView1d< integer const > const elemGhostRank,
Expand All @@ -87,6 +85,7 @@ struct PrecomputeSourceAndReceiverKernel
real32 const timeSourceDelay,
localIndex const rickerOrder )
{
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;

forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
Expand Down Expand Up @@ -123,7 +122,7 @@ struct PrecomputeSourceAndReceiverKernel
coordsOnRefElem );

sourceIsAccessible[isrc] = 1;
real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -170,7 +169,7 @@ struct PrecomputeSourceAndReceiverKernel

receiverIsLocal[ircv] = 1;

real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -220,7 +219,7 @@ struct MassMatrixKernel
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
constexpr localIndex numQuadraturePointsPerElem = FE_TYPE::numQuadraturePoints;

real32 const invC2 = 1.0 / ( velocity[e] * velocity[e] );
real32 const invC2 = 1.0 / pow( velocity[e], 2 );
real64 xLocal[ numNodesPerElem ][ 3 ];
for( localIndex a = 0; a < numNodesPerElem; ++a )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void AcousticWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLevel & mesh,
{
using FE_TYPE = TYPEOFREF( finiteElement );

constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
localIndex const numFacesPerElem = elementSubRegion.numFacesPerElement();

{
Expand All @@ -181,7 +180,6 @@ void AcousticWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLevel & mesh,
PrecomputeSourceAndReceiverKernel::
launch< EXEC_POLICY, FE_TYPE >
( elementSubRegion.size(),
numNodesPerElem,
numFacesPerElem,
X32,
elemGhostRank,
Expand Down Expand Up @@ -323,7 +321,7 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups()
} );
} );

WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_receiverConstants.size( 0 ), m_receiverIsLocal );
WaveSolverUtils::initTrace( "seismoTraceReceiver", getName(), m_outputSeismoTrace, m_receiverConstants.size( 0 ), m_receiverIsLocal );
}


Expand Down Expand Up @@ -853,7 +851,7 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n,

EventManager const & event = getGroupByPath< EventManager >( "/Problem/Events" );
real64 const & maxTime = event.getReference< real64 >( EventManager::viewKeyStruct::maxTimeString() );
int const maxCycle = int(round( maxTime/dt ));
int const maxCycle = int(round( maxTime / dt ));

if( computeGradient && cycleNumber < maxCycle )
{
Expand Down Expand Up @@ -962,8 +960,8 @@ real64 AcousticWaveEquationSEM::explicitStepInternal( real64 const & time_n,

EventManager const & event = getGroupByPath< EventManager >( "/Problem/Events" );
real64 const & minTime = event.getReference< real64 >( EventManager::viewKeyStruct::minTimeString() );
integer const cycleForSource = int(round( -minTime/dt + cycleNumber ));
//std::cout<<"cycle GEOSX = "<<cycleForSource<<std::endl;
integer const cycleForSource = int(round( -minTime / dt + cycleNumber ));

addSourceToRightHandSide( cycleForSource, rhs );

/// calculate your time integrators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct PrecomputeSourceAndReceiverKernel
* @tparam EXEC_POLICY execution policy
* @tparam FE_TYPE finite element type
* @param[in] size the number of cells in the subRegion
* @param[in] numNodesPerElem number of nodes per element
* @param[in] nodeCoords coordinates of the nodes
* @param[in] elemsToNodes map from element to nodes
* @param[in] elemsToFaces map from element to faces
Expand All @@ -58,7 +57,6 @@ struct PrecomputeSourceAndReceiverKernel
template< typename EXEC_POLICY, typename FE_TYPE >
static void
launch( localIndex const size,
localIndex const numNodesPerElem,
localIndex const numFacesPerElem,
arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords,
arrayView1d< integer const > const elemGhostRank,
Expand All @@ -81,9 +79,11 @@ struct PrecomputeSourceAndReceiverKernel
real32 const timeSourceDelay,
localIndex const rickerOrder )
{
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;

forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k )
{

real64 const center[3] = { elemCenter[k][0],
elemCenter[k][1],
elemCenter[k][2] };
Expand Down Expand Up @@ -117,7 +117,7 @@ struct PrecomputeSourceAndReceiverKernel
coordsOnRefElem );

sourceIsAccessible[isrc] = 1;
real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -164,7 +164,7 @@ struct PrecomputeSourceAndReceiverKernel

receiverIsLocal[ircv] = 1;

real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -216,7 +216,7 @@ struct MassMatrixKernel
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
constexpr localIndex numQuadraturePointsPerElem = FE_TYPE::numQuadraturePoints;

real32 const invC2 = 1.0 / ( density[e] * velocity[e] * velocity[e] );
real32 const invC2 = 1.0 / ( density[e] * pow( velocity[e], 2 ) );
real64 xLocal[ numNodesPerElem ][ 3 ];
for( localIndex a = 0; a < numNodesPerElem; ++a )
{
Expand Down Expand Up @@ -803,9 +803,9 @@ class ExplicitAcousticSEM : public finiteElement::KernelBase< SUBREGION_TYPE,
{
m_finiteElementSpace.template computeStiffnessTerm( q, stack.xLocal, [&] ( int i, int j, real64 val )
{
real32 invDensity = 1./m_density[k];
real32 const localIncrement = invDensity*val*m_p_n[m_elemsToNodes[k][j]];
RAJA::atomicAdd< parallelDeviceAtomic >( &m_stiffnessVector[m_elemsToNodes[k][i]], localIncrement );
real32 invDensity = 1.0 / m_density[k];
real32 const localIncrement = invDensity*val*m_p_n[m_elemsToNodes( k, j )];
RAJA::atomicAdd< parallelDeviceAtomic >( &m_stiffnessVector[m_elemsToNodes( k, i )], localIncrement );
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,13 @@ void ElasticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLeve
{
using FE_TYPE = TYPEOFREF( finiteElement );

constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;
localIndex const numFacesPerElem = elementSubRegion.numFacesPerElement();

elasticFirstOrderWaveEquationSEMKernels::
PrecomputeSourceAndReceiverKernel::
launch< EXEC_POLICY, FE_TYPE >
( elementSubRegion.size(),
regionIndex,
numNodesPerElem,
numFacesPerElem,
X,
elemGhostRank,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct PrecomputeSourceAndReceiverKernel
static void
launch( localIndex const size,
localIndex const regionIndex,
localIndex const numNodesPerElem,
localIndex const numFacesPerElem,
arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords,
arrayView1d< integer const > const elemGhostRank,
Expand All @@ -89,6 +88,7 @@ struct PrecomputeSourceAndReceiverKernel
real32 const timeSourceDelay,
localIndex const rickerOrder )
{
constexpr localIndex numNodesPerElem = FE_TYPE::numNodes;

forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
Expand Down Expand Up @@ -126,7 +126,7 @@ struct PrecomputeSourceAndReceiverKernel
sourceIsAccessible[isrc] = 1;
sourceElem[isrc] = k;
sourceRegion[isrc] = regionIndex;
real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -174,7 +174,7 @@ struct PrecomputeSourceAndReceiverKernel
rcvElem[ircv] = k;
receiverRegion[ircv] = regionIndex;

real64 Ntest[FE_TYPE::numNodes];
real64 Ntest[numNodesPerElem];
FE_TYPE::calcN( coordsOnRefElem, Ntest );

for( localIndex a = 0; a < numNodesPerElem; ++a )
Expand Down Expand Up @@ -377,8 +377,8 @@ struct StressComputation
}
}

mu[k] = density[k] * velocityVs[k] * velocityVs[k];
lambda[k] = density[k] * velocityVp[k] * velocityVp[k] - 2.0*mu[k];
mu[k] = density[k] * pow( velocityVs[k], 2 );
lambda[k] = density[k] * pow( velocityVp[k], 2 ) - 2.0*mu[k];

real32 uelemxx[numNodesPerElem] = {0.0};
real32 uelemyy[numNodesPerElem] = {0.0};
Expand Down
Loading

0 comments on commit ece2ae9

Please sign in to comment.