From ec52431bb56fc74eaac8f3c566063741d5f16f5c Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 11 Dec 2024 16:40:04 -0600 Subject: [PATCH] refactor: remove assemblyLaunch duplicates in poromechanics solvers (#3488) --- .../multiphysics/MultiphasePoromechanics.cpp | 74 +++++++++---------- .../multiphysics/MultiphasePoromechanics.hpp | 58 --------------- .../multiphysics/PoromechanicsSolver.hpp | 39 ++++++++++ .../multiphysics/SinglePhasePoromechanics.cpp | 60 +++++++-------- .../multiphysics/SinglePhasePoromechanics.hpp | 55 -------------- 5 files changed, 106 insertions(+), 180 deletions(-) diff --git a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp index 29b47efd16..dc3875a88e 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp @@ -141,39 +141,39 @@ void MultiphasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assembleElementBa if( this->m_isThermal ) { poromechanicsMaxForce = - assemblyLaunch< constitutive::PorousSolidBase, - thermalPoromechanicsKernels::ThermalMultiphasePoromechanicsKernelFactory >( mesh, - dofManager, - regionNames, - Base::viewKeyStruct::porousMaterialNamesString(), - localMatrix, - localRhs, - dt, - flowDofKey, - this->flowSolver()->numFluidComponents(), - this->flowSolver()->numFluidPhases(), - this->flowSolver()->useTotalMassEquation(), - this->m_performStressInitialization, - FlowSolverBase::viewKeyStruct::fluidNamesString() ); + this->template assemblyLaunch< constitutive::PorousSolidBase, + thermalPoromechanicsKernels::ThermalMultiphasePoromechanicsKernelFactory >( mesh, + dofManager, + regionNames, + Base::viewKeyStruct::porousMaterialNamesString(), + localMatrix, + localRhs, + dt, + flowDofKey, + this->flowSolver()->numFluidComponents(), + this->flowSolver()->numFluidPhases(), + this->flowSolver()->useTotalMassEquation(), + this->m_performStressInitialization, + FlowSolverBase::viewKeyStruct::fluidNamesString() ); } else { poromechanicsMaxForce = - assemblyLaunch< constitutive::PorousSolidBase, - poromechanicsKernels::MultiphasePoromechanicsKernelFactory >( mesh, - dofManager, - regionNames, - Base::viewKeyStruct::porousMaterialNamesString(), - localMatrix, - localRhs, - dt, - flowDofKey, - this->flowSolver()->numFluidComponents(), - this->flowSolver()->numFluidPhases(), - this->flowSolver()->useSimpleAccumulation(), - this->flowSolver()->useTotalMassEquation(), - this->m_performStressInitialization, - FlowSolverBase::viewKeyStruct::fluidNamesString() ); + this->template assemblyLaunch< constitutive::PorousSolidBase, + poromechanicsKernels::MultiphasePoromechanicsKernelFactory >( mesh, + dofManager, + regionNames, + Base::viewKeyStruct::porousMaterialNamesString(), + localMatrix, + localRhs, + dt, + flowDofKey, + this->flowSolver()->numFluidComponents(), + this->flowSolver()->numFluidPhases(), + this->flowSolver()->useSimpleAccumulation(), + this->flowSolver()->useTotalMassEquation(), + this->m_performStressInitialization, + FlowSolverBase::viewKeyStruct::fluidNamesString() ); } } ); @@ -203,14 +203,14 @@ void MultiphasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assembleElementBa } mechanicsMaxForce = - assemblyLaunch< constitutive::SolidBase, - solidMechanicsLagrangianFEMKernels::QuasiStaticFactory >( mesh, - dofManager, - filteredRegionNames.toViewConst(), - SolidMechanicsLagrangianFEM::viewKeyStruct::solidMaterialNamesString(), - localMatrix, - localRhs, - dt ); + this->template assemblyLaunch< constitutive::SolidBase, + solidMechanicsLagrangianFEMKernels::QuasiStaticFactory >( mesh, + dofManager, + filteredRegionNames.toViewConst(), + SolidMechanicsLagrangianFEM::viewKeyStruct::solidMaterialNamesString(), + localMatrix, + localRhs, + dt ); } ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.hpp b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.hpp index 55dbd18053..89d46b554b 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.hpp @@ -107,72 +107,14 @@ class MultiphasePoromechanics : public PoromechanicsSolver< FLOW_SOLVER, MECHANI virtual void initializePostInitialConditionsPreSubGroups() override; - - -private: - /** * @brief Helper function to recompute the bulk density * @param[in] subRegion the element subRegion */ virtual void updateBulkDensity( ElementSubRegionBase & subRegion ) override; - template< typename CONSTITUTIVE_BASE, - typename KERNEL_WRAPPER, - typename ... PARAMS > - real64 assemblyLaunch( MeshLevel & mesh, - DofManager const & dofManager, - arrayView1d< string const > const & regionNames, - string const & materialNamesString, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - real64 const dt, - PARAMS && ... params ); - - }; -template< typename FLOW_SOLVER, typename MECHANICS_SOLVER > -template< typename CONSTITUTIVE_BASE, - typename KERNEL_WRAPPER, - typename ... PARAMS > -real64 MultiphasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assemblyLaunch( MeshLevel & mesh, - DofManager const & dofManager, - arrayView1d< string const > const & regionNames, - string const & materialNamesString, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - real64 const dt, - PARAMS && ... params ) -{ - GEOS_MARK_FUNCTION; - - NodeManager const & nodeManager = mesh.getNodeManager(); - - string const dofKey = dofManager.getKey( fields::solidMechanics::totalDisplacement::key() ); - arrayView1d< globalIndex const > const & dofNumber = nodeManager.getReference< globalIndex_array >( dofKey ); - - real64 const gravityVectorData[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( PhysicsSolverBase::gravityVector() ); - - KERNEL_WRAPPER kernelWrapper( dofNumber, - dofManager.rankOffset(), - localMatrix, - localRhs, - dt, - gravityVectorData, - std::forward< PARAMS >( params )... ); - - return finiteElement:: - regionBasedKernelApplication< parallelDevicePolicy< >, - CONSTITUTIVE_BASE, - CellElementSubRegion >( mesh, - regionNames, - this->solidMechanicsSolver()->getDiscretizationName(), - materialNamesString, - kernelWrapper ); -} - - } /* namespace geos */ #endif /* GEOS_PHYSICSSOLVERS_MULTIPHYSICS_MULTIPHASEPOROMECHANICS_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp index fb5d63043c..62a772e027 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp @@ -395,6 +395,45 @@ class PoromechanicsSolver : public CoupledSolver< FLOW_SOLVER, MECHANICS_SOLVER protected: + template< typename CONSTITUTIVE_BASE, + typename KERNEL_WRAPPER, + typename ... PARAMS > + real64 assemblyLaunch( MeshLevel & mesh, + DofManager const & dofManager, + arrayView1d< string const > const & regionNames, + string const & materialNamesString, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + real64 const dt, + PARAMS && ... params ) + { + GEOS_MARK_FUNCTION; + + NodeManager const & nodeManager = mesh.getNodeManager(); + + string const dofKey = dofManager.getKey( fields::solidMechanics::totalDisplacement::key() ); + arrayView1d< globalIndex const > const & dofNumber = nodeManager.getReference< globalIndex_array >( dofKey ); + + real64 const gravityVectorData[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( PhysicsSolverBase::gravityVector() ); + + KERNEL_WRAPPER kernelWrapper( dofNumber, + dofManager.rankOffset(), + localMatrix, + localRhs, + dt, + gravityVectorData, + std::forward< PARAMS >( params )... ); + + return finiteElement:: + regionBasedKernelApplication< parallelDevicePolicy< >, + CONSTITUTIVE_BASE, + CellElementSubRegion >( mesh, + regionNames, + this->solidMechanicsSolver()->getDiscretizationName(), + materialNamesString, + kernelWrapper ); + } + /* Implementation of Nonlinear Acceleration (Aitken) of averageMeanTotalStressIncrement */ void recordAverageMeanTotalStressIncrement( DomainPartition & domain, diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp index 3d04a90004..b28c0d0b9a 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp @@ -194,32 +194,32 @@ void SinglePhasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assembleElementB if( this->m_isThermal ) { poromechanicsMaxForce = - assemblyLaunch< constitutive::PorousSolidBase, - thermalPoromechanicsKernels::ThermalSinglePhasePoromechanicsKernelFactory >( mesh, - dofManager, - regionNames, - viewKeyStruct::porousMaterialNamesString(), - localMatrix, - localRhs, - dt, - flowDofKey, - this->m_performStressInitialization, - FlowSolverBase::viewKeyStruct::fluidNamesString() ); + this->template assemblyLaunch< constitutive::PorousSolidBase, + thermalPoromechanicsKernels::ThermalSinglePhasePoromechanicsKernelFactory >( mesh, + dofManager, + regionNames, + viewKeyStruct::porousMaterialNamesString(), + localMatrix, + localRhs, + dt, + flowDofKey, + this->m_performStressInitialization, + FlowSolverBase::viewKeyStruct::fluidNamesString() ); } else { poromechanicsMaxForce = - assemblyLaunch< constitutive::PorousSolidBase, - poromechanicsKernels::SinglePhasePoromechanicsKernelFactory >( mesh, - dofManager, - regionNames, - viewKeyStruct::porousMaterialNamesString(), - localMatrix, - localRhs, - dt, - flowDofKey, - this->m_performStressInitialization, - FlowSolverBase::viewKeyStruct::fluidNamesString() ); + this->template assemblyLaunch< constitutive::PorousSolidBase, + poromechanicsKernels::SinglePhasePoromechanicsKernelFactory >( mesh, + dofManager, + regionNames, + viewKeyStruct::porousMaterialNamesString(), + localMatrix, + localRhs, + dt, + flowDofKey, + this->m_performStressInitialization, + FlowSolverBase::viewKeyStruct::fluidNamesString() ); } } ); @@ -248,14 +248,14 @@ void SinglePhasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assembleElementB } mechanicsMaxForce = - assemblyLaunch< constitutive::SolidBase, - solidMechanicsLagrangianFEMKernels::QuasiStaticFactory >( mesh, - dofManager, - filteredRegionNames.toViewConst(), - SolidMechanicsLagrangianFEM::viewKeyStruct::solidMaterialNamesString(), - localMatrix, - localRhs, - dt ); + this->template assemblyLaunch< constitutive::SolidBase, + solidMechanicsLagrangianFEMKernels::QuasiStaticFactory >( mesh, + dofManager, + filteredRegionNames.toViewConst(), + SolidMechanicsLagrangianFEM::viewKeyStruct::solidMaterialNamesString(), + localMatrix, + localRhs, + dt ); } ); this->solidMechanicsSolver()->applyContactConstraint( dofManager, domain, localMatrix, localRhs ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp index 35d11acb11..4b9dfbf742 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp @@ -118,20 +118,6 @@ class SinglePhasePoromechanics : public PoromechanicsSolver< FLOW_SOLVER, MECHAN virtual void initializePostInitialConditionsPreSubGroups() override; - template< typename CONSTITUTIVE_BASE, - typename KERNEL_WRAPPER, - typename ... PARAMS > - real64 assemblyLaunch( MeshLevel & mesh, - DofManager const & dofManager, - arrayView1d< string const > const & regionNames, - string const & materialNamesString, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - real64 const dt, - PARAMS && ... params ); - -private: - /** * @brief Helper function to recompute the bulk density * @param[in] subRegion the element subRegion @@ -142,47 +128,6 @@ class SinglePhasePoromechanics : public PoromechanicsSolver< FLOW_SOLVER, MECHAN }; -template< typename FLOW_SOLVER, typename MECHANICS_SOLVER > -template< typename CONSTITUTIVE_BASE, - typename KERNEL_WRAPPER, - typename ... PARAMS > -real64 SinglePhasePoromechanics< FLOW_SOLVER, MECHANICS_SOLVER >::assemblyLaunch( MeshLevel & mesh, - DofManager const & dofManager, - arrayView1d< string const > const & regionNames, - string const & materialNamesString, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - real64 const dt, - PARAMS && ... params ) -{ - GEOS_MARK_FUNCTION; - - NodeManager const & nodeManager = mesh.getNodeManager(); - - string const dofKey = dofManager.getKey( fields::solidMechanics::totalDisplacement::key() ); - arrayView1d< globalIndex const > const & dofNumber = nodeManager.getReference< globalIndex_array >( dofKey ); - - real64 const gravityVectorData[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( PhysicsSolverBase::gravityVector() ); - - KERNEL_WRAPPER kernelWrapper( dofNumber, - dofManager.rankOffset(), - localMatrix, - localRhs, - dt, - gravityVectorData, - std::forward< PARAMS >( params )... ); - - return finiteElement:: - regionBasedKernelApplication< parallelDevicePolicy< >, - CONSTITUTIVE_BASE, - CellElementSubRegion >( mesh, - regionNames, - this->solidMechanicsSolver()->getDiscretizationName(), - materialNamesString, - kernelWrapper ); -} - - } /* namespace geos */ #endif /* GEOS_PHYSICSSOLVERS_MULTIPHYSICS_SINGLEPHASEPOROMECHANICS_HPP_ */