Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: averaging of stress components using quadrature #3279

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
using arrayView2dLayoutStrain = arrayView2d< real64, cells::STRAIN_USD >;
using arrayViewConst2dLayoutStrain = arrayView2d< real64 const, cells::STRAIN_USD >;

using array2dLayoutAvgStress = array2d< real64, cells::STRAIN_PERM >;
using arrayView2dLayoutAvgStress = arrayView2d< real64, cells::STRAIN_USD >;
using arrayViewConst2dLayoutAvgStress = arrayView2d< real64 const, cells::STRAIN_USD >;
ryar9534 marked this conversation as resolved.
Show resolved Hide resolved

using array2dLayoutVelocity = array2d< real64, nodes::VELOCITY_PERM >;
using arrayView2dLayoutVelocity = arrayView2d< real64, nodes::VELOCITY_USD >;
using arrayViewConst2dLayoutVelocity = arrayView2d< real64 const, nodes::VELOCITY_USD >;
Expand Down Expand Up @@ -87,6 +91,14 @@
WRITE_AND_READ,
"Average strain in cell" );

DECLARE_FIELD( averageStress,

Check warning on line 94 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsFields.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsFields.hpp#L94

Added line #L94 was not covered by tests
"averageStress",
array2dLayoutAvgStress,
0,
LEVEL_0,
WRITE_AND_READ,
"Quadrature averaged stress components in cell" );

DECLARE_FIELD( incrementalBubbleDisplacement,
"incrementalBubbleDisplacement",
array2d< real64 >,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
setConstitutiveNamesCallSuper( subRegion );

subRegion.registerField< solidMechanics::strain >( getName() ).reference().resizeDimension< 1 >( 6 );
subRegion.registerField< solidMechanics::averageStress >( getName() ).reference().resizeDimension< 1 >( 6 );

Check warning on line 162 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp#L162

Added line #L162 was not covered by tests
} );

NodeManager & nodes = meshLevel.getNodeManager();
Expand Down Expand Up @@ -944,7 +945,10 @@
SolidBase & constitutiveRelation = getConstitutiveModel< SolidBase >( subRegion, solidMaterialName );
constitutiveRelation.saveConvergedState();

arrayView3d < real64 const, solid::STRESS_USD > const stress = constitutiveRelation.getStress();

Check warning on line 948 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp#L948

Added line #L948 was not covered by tests

solidMechanics::arrayView2dLayoutStrain strain = subRegion.getField< solidMechanics::strain >();
solidMechanics::arrayView2dLayoutAvgStress avgStress = subRegion.getField< solidMechanics::averageStress >();

Check warning on line 951 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp#L951

Added line #L951 was not covered by tests

finiteElement::FiniteElementBase & subRegionFE = subRegion.template getReference< finiteElement::FiniteElementBase >( this->getDiscretizationName());
finiteElement::FiniteElementDispatchHandler< BASE_FE_TYPES >::dispatch3D( subRegionFE, [&] ( auto const finiteElement )
Expand All @@ -957,6 +961,16 @@
finiteElement,
disp,
strain );


AverageStressOverQuadraturePointsKernelFactory::createAndLaunch< CellElementSubRegion, FE_TYPE, parallelDevicePolicy<> >( nodeManager,
mesh.getEdgeManager(),
mesh.getFaceManager(),

Check warning on line 968 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp#L966-L968

Added lines #L966 - L968 were not covered by tests
subRegion,
finiteElement,
stress,
avgStress );

Check warning on line 972 in src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp#L971-L972

Added lines #L971 - L972 were not covered by tests

} );


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,182 @@






/**
* @class AverageStressOverQuadraturePoints
* @tparam SUBREGION_TYPE the subRegion type
* @tparam FE_TYPE the finite element type
*/
template< typename SUBREGION_TYPE,
typename FE_TYPE >
class AverageStressOverQuadraturePoints :
public AverageOverQuadraturePointsBase< SUBREGION_TYPE,
FE_TYPE >
{
public:

/// Alias for the base class;
using Base = AverageOverQuadraturePointsBase< SUBREGION_TYPE,
FE_TYPE >;

using Base::m_elementVolume;
using Base::m_elemsToNodes;
using Base::m_finiteElementSpace;

/**
* @brief Constructor for the class
* @param nodeManager the node manager
* @param edgeManager the edge manager
* @param faceManager the face manager
* @param elementSubRegion the element subRegion
* @param finiteElementSpace the finite element space
* @param stress the stress solution field
* @param avgStress the stress averaged over quadrature points
*/
AverageStressOverQuadraturePoints( NodeManager & nodeManager,

Check warning on line 251 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L251

Added line #L251 was not covered by tests
EdgeManager const & edgeManager,
FaceManager const & faceManager,
SUBREGION_TYPE const & elementSubRegion,
FE_TYPE const & finiteElementSpace,
arrayView3d< real64 const, solid::STRESS_USD > const stress,
fields::solidMechanics::arrayView2dLayoutAvgStress const avgStress ):
Base( nodeManager,
edgeManager,
faceManager,
elementSubRegion,
finiteElementSpace ),
m_stress( stress ),
m_avgStress( avgStress )
{}

Check warning on line 265 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L263-L265

Added lines #L263 - L265 were not covered by tests

/**
* @copydoc finiteElement::KernelBase::StackVariables
*/
struct StackVariables : Base::StackVariables
{ };

/**
* @brief Performs the setup phase for the kernel.
* @param k The element index.
* @param stack The StackVariable object that hold the stack variables.
*/
GEOS_HOST_DEVICE
void setup( localIndex const k,

Check warning on line 279 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L279

Added line #L279 was not covered by tests
StackVariables & stack ) const
{
Base::setup( k, stack );

Check warning on line 282 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L282

Added line #L282 was not covered by tests

for( int icomp = 0; icomp < 6; ++icomp )

Check warning on line 284 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L284

Added line #L284 was not covered by tests
{
m_avgStress[k][icomp] = 0.0;

Check warning on line 286 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L286

Added line #L286 was not covered by tests
}
}

/**
* @brief Increment the average property with the contribution of the property at this quadrature point
* @param k The element index
* @param q The quadrature point index
* @param stack The StackVariables object that hold the stack variables.
*/
GEOS_HOST_DEVICE
void quadraturePointKernel( localIndex const k,

Check warning on line 297 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L297

Added line #L297 was not covered by tests
Copy link
Contributor

@castelletto1 castelletto1 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains two functions quadraturePointKernel once for the strain and one for the stress. In my opinion only one function should exist to perform the averaging of a second order symmetric stress tensor -- and probably of any scalar (rank 0), vector (rank 1), ... . The class AverageOverQuadraturePointsBase should be responsible for this task, and the quantity to be averaged should either provided directly or with a lambda function that evaluates such property.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could generalize it and come up with a single kernel. We could try to make it accept a list of views instead of a specific one. It would also mean that we do all averaging in a single kernel launch which it is indeed better. We could use something similar to the elementViewAccessors and create an array1d of all scalars, one for all vectors and one for all tensors to be averaged and have the averagingKernel only ask for the keys of the fields that need to be averaged.
The strain probably remains a bit of a special case though and i don't know that we do any averaging for other quantities.

Copy link
Contributor

@castelletto1 castelletto1 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long term, such computations should be managed by a numerical quadrature library (i.e. --> Shiva)

localIndex const q,
StackVariables & stack ) const
{
//real64 const weight = FE_TYPE::transformedQuadratureWeight( q, stack.xLocal, stack.feStack ) / m_elementVolume[k];

real64 dNdX[ FE_TYPE::maxSupportPoints ][3];
real64 const detJxW = m_finiteElementSpace.template getGradN< FE_TYPE >( k, q, stack.xLocal, stack.feStack, dNdX );

Check warning on line 304 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L304

Added line #L304 was not covered by tests

for( int icomp = 0; icomp < 6; ++icomp )

Check warning on line 306 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L306

Added line #L306 was not covered by tests
{
m_avgStress[k][icomp] += detJxW*m_stress[k][q][icomp]/m_elementVolume[k];

Check warning on line 308 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L308

Added line #L308 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we divide by the cell element volume (m_elementVolume[k]) to compute the increment to the average value. In AverageOverQuadraturePointsBase the cell element contribution is directly included in the weight definition. Both correct, but it would be nice to be consistent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should divide only once at the end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, I would argue that m_elementVolume[k] should not even be required and computed directly in the quadrature process. For this specific case:

real64 cellVolume{0.0}
for( int icomp = 0; icomp < 6; ++icomp )
{
  m_avgStress[k][icomp] += detJxW*m_stress[k][q][icomp];
  cellVolume += detJxW;
}
m_avgStress[k][icomp] /= cellVolume;

}
}

/**
* @brief Launch the kernel over the elements in the subRegion
* @tparam POLICY the kernel policy
* @tparam KERNEL_TYPE the type of kernel
* @param numElems the number of elements in the subRegion
* @param kernelComponent the kernel component
*/
template< typename POLICY,
typename KERNEL_TYPE >
static void
kernelLaunch( localIndex const numElems,

Check warning on line 322 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L322

Added line #L322 was not covered by tests
KERNEL_TYPE const & kernelComponent )
{
forAll< POLICY >( numElems,
[=] GEOS_HOST_DEVICE ( localIndex const k )

Check warning on line 326 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L325-L326

Added lines #L325 - L326 were not covered by tests
{
typename KERNEL_TYPE::StackVariables stack;

Check warning on line 328 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L328

Added line #L328 was not covered by tests

kernelComponent.setup( k, stack );
for( integer q = 0; q < FE_TYPE::numQuadraturePoints; ++q )

Check warning on line 331 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L330-L331

Added lines #L330 - L331 were not covered by tests
{
kernelComponent.quadraturePointKernel( k, q, stack );

Check warning on line 333 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L333

Added line #L333 was not covered by tests
}
} );
}

protected:

/// The stress solution
arrayView3d< real64 const, solid::STRESS_USD > const m_stress;

/// The average stress
fields::solidMechanics::arrayView2dLayoutAvgStress const m_avgStress;

};



/**
* @class AverageStressOverQuadraturePointsKernelFactory
* @brief Class to create and launch the kernel
*/
class AverageStressOverQuadraturePointsKernelFactory
{
public:
ryar9534 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Create a new kernel and launch
* @tparam SUBREGION_TYPE the subRegion type
* @tparam FE_TYPE the finite element type
* @tparam POLICY the kernel policy
* @param nodeManager the node manager
* @param edgeManager the edge manager
* @param faceManager the face manager
* @param elementSubRegion the element subRegion
* @param finiteElementSpace the finite element space
* @param property the property at quadrature points
* @param averageProperty the property averaged over quadrature points
*/
template< typename SUBREGION_TYPE,
typename FE_TYPE,
typename POLICY >
static void
createAndLaunch( NodeManager & nodeManager,

Check warning on line 375 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L375

Added line #L375 was not covered by tests
EdgeManager const & edgeManager,
FaceManager const & faceManager,
SUBREGION_TYPE const & elementSubRegion,
FE_TYPE const & finiteElementSpace,
arrayView3d< real64 const, solid::STRESS_USD > const stress,
fields::solidMechanics::arrayView2dLayoutAvgStress const avgStress )
{
AverageStressOverQuadraturePoints< SUBREGION_TYPE, FE_TYPE >
kernel( nodeManager, edgeManager, faceManager, elementSubRegion, finiteElementSpace,

Check warning on line 384 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L384

Added line #L384 was not covered by tests
stress, avgStress );

AverageStressOverQuadraturePoints< SUBREGION_TYPE, FE_TYPE >::template
kernelLaunch< POLICY >( elementSubRegion.size(), kernel );

Check warning on line 388 in src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/solidMechanics/kernels/StrainHelper.hpp#L388

Added line #L388 was not covered by tests
}
};


}


Expand Down
Loading