28#include <dune/grid/common/gridenums.hh>
30#include <dune/common/dynmatrix.hh>
31#include <dune/common/dynvector.hh>
33#include <opm/grid/utility/ElementChunks.hpp>
35#include <opm/common/utility/SymmTensor.hpp>
36#include <opm/common/utility/VoigtArray.hpp>
37#include <opm/material/common/MathToolbox.hpp>
46#include <unordered_map>
56template <
class TypeTag>
71 enum { dimWorld = GridView::dimensionworld };
72 enum { historySize = getPropValue<TypeTag, Properties::SolutionHistorySizeTPSA>() };
73 enum { numEq = getPropValue<TypeTag, Properties::NumEqTPSA>() };
75 enum { disp0Idx = Indices::disp0Idx };
76 enum { rot0Idx = Indices::rot0Idx };
77 enum { solidPres0Idx = Indices::solidPres0Idx };
79 using MaterialState = MaterialStateTPSA<Evaluation>;
81 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
82 using SymTensor = SymmTensor<Scalar>;
83 using PotForceVector = Dune::BlockVector<Scalar>;
146 return std::equal(this->blockVector_.begin(), this->blockVector_.end(),
155 template<
class Serializer>
171 : linearizer_(std::make_unique<Linearizer>())
172 , newtonMethod_(simulator)
173 , simulator_(simulator)
174 , element_chunks_(simulator.gridView(),
Dune::Partitions::all,
ThreadManager::maxThreads())
177 eqWeights_.resize(numEq, 1.0);
181 const std::size_t numDof = simulator_.model().numGridDof();
182 for (
unsigned timeIdx = 0; timeIdx < historySize; ++timeIdx) {
183 solution_[timeIdx] = std::make_unique<TpsaBlockVectorWrapper>(
"solution", numDof);
187 mechPotPresForce_.resize(numDof);
188 mechPotTempForce_.resize(numDof);
197 linearizer_->init(simulator_);
234 auto ghostSync = GhostSyncHandle(
solution(0),
235 simulator_.model().dofMapper());
237 simulator_.gridView().communicate(ghostSync,
238 Dune::InteriorBorder_All_Interface,
239 Dune::ForwardCommunication);
252 const auto& elementMapper = simulator_.model().elementMapper();
254#pragma omp parallel for
256 for (std::size_t ci = 0; ci < element_chunks_.size(); ++ci) {
257 const auto& chunk = element_chunks_[ci];
258 for (
const auto& elem : chunk) {
259 const unsigned globalIdx = elementMapper.index(elem);
260 auto& currSol =
solution(0)[globalIdx];
261 setMaterialState_(globalIdx, 0, currSol);
296 return newtonMethod_;
306 return newtonMethod_;
315 const SolutionVector&
solution(
unsigned timeIdx)
const
317 return solution_[timeIdx]->blockVector();
328 return solution_[timeIdx]->blockVector();
337 return simulator_.model().numGridDof();
357 return simulator_.model().dofTotalVolume(globalIdx);
369 return eqWeights_[eqIdx];
380 eqWeights_[eqIdx] = value;
410 const MaterialState&
materialState(
const unsigned globalIdx,
unsigned )
const
412 return materialState_[globalIdx];
424 DimVector
disp(
const unsigned globalIdx,
const bool )
const
427 for (std::size_t i = 0; i < 3; ++i) {
428 d[i] = decay<Scalar>(materialState_[globalIdx].displacement(i));
442 for (std::size_t i = 0; i < 3; ++i) {
443 rot[i] = decay<Scalar>(materialState_[globalIdx].
rotation(i));
456 return decay<Scalar>(materialState_[globalIdx].
solidPressure());
467 return stress(globalIdx,
false);
496 SymTensor linStressTensor =
stress(globalIdx,
false);
498 for (
const auto& dirIdx : SymTensor::diag_indices) {
499 linStressTensor[dirIdx] -= potForce;
501 return -1.0 * linStressTensor;
514 SymTensor
stress(
const unsigned globalIdx,
const bool )
const
516 SymTensor stressOutput;
517 const auto& stressInfo = linearizer_->getStressInfo();
518 if (!stressInfo.empty()) {
519 const auto& stressInfoGlobI = stressInfo[globalIdx];
524 std::unordered_multimap<int, std::size_t> faceIdMap;
525 std::size_t mapSize = 0;
526 for (std::size_t sInfoIdx = 0; sInfoIdx < stressInfoGlobI.size(); ++sInfoIdx) {
527 const auto faceId = stressInfoGlobI[sInfoIdx].faceId;
531 if (faceId < 0 || stressInfoGlobI[sInfoIdx].faceArea == 0.0) {
534 if (!faceIdMap.contains(faceId)) {
537 faceIdMap.insert({faceId, sInfoIdx});
545 Dune::DynamicMatrix<Scalar> mat(3 * mapSize, 6);
546 Dune::DynamicVector<Scalar> rhs(3 * mapSize);
547 std::size_t rowIdx = 0;
548 for (
auto it = faceIdMap.begin(); it != faceIdMap.end();) {
549 auto [first, last] = faceIdMap.equal_range(it->first);
552 Scalar sumFaceArea = 0.0;
553 for (
auto inner = first; inner != last; ++inner) {
554 const auto sInfoIdx = inner->second;
555 const auto& faceStressInfo = stressInfoGlobI[sInfoIdx];
558 if (inner == first) {
559 const auto& fNormal = faceStressInfo.faceNormal;
560 mat[3*rowIdx][0] = fNormal[0];
561 mat[3*rowIdx][3] = fNormal[1];
562 mat[3*rowIdx][4] = fNormal[2];
564 mat[3*rowIdx + 1][1] = fNormal[1];
565 mat[3*rowIdx + 1][3] = fNormal[0];
566 mat[3*rowIdx + 1][5] = fNormal[2];
568 mat[3*rowIdx + 2][2] = fNormal[2];
569 mat[3*rowIdx + 2][4] = fNormal[0];
570 mat[3*rowIdx + 2][5] = fNormal[1];
574 const auto& fTraction = faceStressInfo.traction;
575 rhs[3*rowIdx] += fTraction[0];
576 rhs[3*rowIdx + 1] += fTraction[1];
577 rhs[3*rowIdx + 2] += fTraction[2];
580 sumFaceArea += faceStressInfo.faceArea;
583 rhs[3*rowIdx] /= sumFaceArea;
584 rhs[3*rowIdx + 1] /= sumFaceArea;
585 rhs[3*rowIdx + 2] /= sumFaceArea;
598 stressOutput[VoigtIndex::XX] =
stress[0];
599 stressOutput[VoigtIndex::YY] =
stress[1];
600 stressOutput[VoigtIndex::ZZ] =
stress[2];
601 stressOutput[VoigtIndex::YZ] =
stress[5];
602 stressOutput[VoigtIndex::XZ] =
stress[4];
603 stressOutput[VoigtIndex::XY] =
stress[3];
617 std::array<DimVector, 6>
traction(
const unsigned globalIdx)
const
619 std::array<DimVector, 6> tractionOutput{};
620 const auto& stressInfo = linearizer_->getStressInfo();
621 if (stressInfo.empty()) {
622 return tractionOutput;
627 std::array<Scalar, 6> sumFaceArea{};
628 for (
const auto& faceStressInfo : stressInfo[globalIdx]) {
629 const auto faceId = faceStressInfo.faceId;
632 if (faceId < 0 || faceStressInfo.faceArea == 0.0) {
636 tractionOutput[faceId] += faceStressInfo.traction;
637 sumFaceArea[faceId] += faceStressInfo.faceArea;
640 for (std::size_t faceId = 0; faceId < 6; ++faceId) {
641 if (sumFaceArea[faceId] > 0.0) {
642 tractionOutput[faceId] /= sumFaceArea[faceId];
646 return tractionOutput;
656 SymTensor
strain(
const unsigned globalIdx,
const bool )
const
659 auto stressDev = this->
linstress(globalIdx);
660 Scalar traceStress = 1.0 / 3.0 * stressDev.trace();
661 stressDev[VoigtIndex::XX] -= traceStress;
662 stressDev[VoigtIndex::YY] -= traceStress;
663 stressDev[VoigtIndex::ZZ] -= traceStress;
666 auto& problem = simulator_.problem();
667 const auto sMod = problem.shearModulus(globalIdx);
668 SymTensor strainDev = 1.0 / (2.0 * sMod) * stressDev;
671 const auto lameParam = problem.lame(globalIdx);
672 Scalar strainVolTerm = traceStress / (3.0 * lameParam + 2 * sMod);
675 strainVol[VoigtIndex::XX] = strainVolTerm;
676 strainVol[VoigtIndex::YY] = strainVolTerm;
677 strainVol[VoigtIndex::ZZ] = strainVolTerm;
680 SymTensor strainOutput = strainDev + strainVol;
705 return mechPotPresForce_[globalIdx];
716 mechPotPresForce_[globalIdx] = val;
727 return mechPotTempForce_[globalIdx];
738 mechPotTempForce_[globalIdx] = val;
752 const std::size_t numDof = simulator_.model().numGridDof();
753 materialState_.resize(numDof);
769 void setMaterialState_(
const unsigned globalIdx,
const unsigned , PrimaryVariables& values)
771 auto& dofMaterialState = materialState_[globalIdx];
772 for (
unsigned dirIdx = 0; dirIdx < 3; ++dirIdx) {
773 dofMaterialState.setDisplacement(dirIdx, values.makeEvaluation(disp0Idx + dirIdx, 0));
774 dofMaterialState.setRotation(dirIdx, values.makeEvaluation(rot0Idx + dirIdx, 0));
776 dofMaterialState.setSolidPressure(values.makeEvaluation(solidPres0Idx, 0));
779 std::unique_ptr<Linearizer> linearizer_;
780 NewtonMethod newtonMethod_;
781 Simulator& simulator_;
782 ElementChunks<GridView, Dune::Partitions::All> element_chunks_;
784 std::array<std::unique_ptr<TpsaBlockVectorWrapper>, historySize> solution_;
785 std::vector<Scalar> eqWeights_;
786 std::vector<MaterialState> materialState_;
787 PotForceVector mechPotPresForce_;
788 PotForceVector mechPotTempForce_;
Data handle for parallel communication which can be used to set the values values of ghost and overla...
Definition: gridcommhandles.hh:109
Linear least squares calculations and properties.
Definition: linearleastsquares.hpp:45
const Vector & x() const
Read-only vector of calculated coefficient vector.
Definition: linearleastsquares.hpp:76
void solve()
Solve linear least squares system.
Definition: linearleastsquares.hpp:66
static void registerParameters()
Register all run-time parameters for the Newton method.
Definition: newtonmethod.hh:134
Simplifies multi-threaded capabilities.
Definition: threadmanager.hpp:36
Small block vector wrapper class for model solutions.
Definition: tpsamodel.hpp:90
bool operator==(const TpsaBlockVectorWrapper &wrapper) const
Check if incoming block vector is the same as current.
Definition: tpsamodel.hpp:144
static TpsaBlockVectorWrapper serializationTestObject()
Test function for serialization.
Definition: tpsamodel.hpp:112
TpsaBlockVectorWrapper()=default
Default constructor.
TpsaBlockVectorWrapper(const std::string &, const std::size_t size)
Constructor.
Definition: tpsamodel.hpp:100
void serializeOp(Serializer &serializer)
Serializing operation.
Definition: tpsamodel.hpp:156
const SolutionVector & blockVector() const
Get const reference of block vector.
Definition: tpsamodel.hpp:135
SolutionVector & blockVector()
Get reference of block vector.
Definition: tpsamodel.hpp:127
SolutionVector blockVector_
Definition: tpsamodel.hpp:92
TPSA geomechanics model.
Definition: tpsamodel.hpp:58
SymTensor delstress(const unsigned globalIdx) const
Output stress tensor without fracture contribution.
Definition: tpsamodel.hpp:465
NewtonMethod & newtonMethod()
Return the Newton method.
Definition: tpsamodel.hpp:304
std::size_t numAuxiliaryDof() const
Return number of auxillary degrees of freedom.
Definition: tpsamodel.hpp:396
SymTensor stress(const unsigned globalIdx, const bool) const
Output stress tensor.
Definition: tpsamodel.hpp:514
SymTensor strain(const unsigned globalIdx, const bool) const
Output strain tensor.
Definition: tpsamodel.hpp:656
void setMechPotentialTempForce(unsigned globalIdx, Scalar val)
Sets potential temperature force.
Definition: tpsamodel.hpp:736
DimVector disp(const unsigned globalIdx, const bool) const
Output displacement vector.
Definition: tpsamodel.hpp:424
void finishInit()
Initialize TPSA model.
Definition: tpsamodel.hpp:194
void setEqWeight(unsigned eqIdx, Scalar value)
Set weights for equation.
Definition: tpsamodel.hpp:378
std::size_t numGridDof() const
Return number of degrees of freedom in the grid from the Flow model.
Definition: tpsamodel.hpp:335
const Linearizer & linearizer() const
Return the linearizer.
Definition: tpsamodel.hpp:274
const NewtonMethod & newtonMethod() const
Return the Newton method.
Definition: tpsamodel.hpp:294
std::size_t numAuxiliaryModules() const
Return number of auxillary modules.
Definition: tpsamodel.hpp:387
void updateMaterialState(const unsigned)
Update material state for all cells.
Definition: tpsamodel.hpp:249
Scalar mechPotentialPressForce(unsigned globalIdx) const
Output potential pressure forces.
Definition: tpsamodel.hpp:703
Scalar mechPotentialTempForce(unsigned globalIdx) const
Output potential temparature forces.
Definition: tpsamodel.hpp:725
SymTensor linstress(const unsigned globalIdx) const
Output linear stress tensor.
Definition: tpsamodel.hpp:492
const SolutionVector & solution(unsigned timeIdx) const
Get reference to history solution vector.
Definition: tpsamodel.hpp:315
const MaterialState & materialState(const unsigned globalIdx, unsigned) const
Return current material state.
Definition: tpsamodel.hpp:410
Scalar dofTotalVolume(unsigned globalIdx) const
Return the total grid volume from the Flow model.
Definition: tpsamodel.hpp:355
void resizeMaterialState_()
Resize material state vector.
Definition: tpsamodel.hpp:750
static void registerParameters()
Register runtime parameters.
Definition: tpsamodel.hpp:206
void setMechPotentialPressForce(unsigned globalIdx, Scalar val)
Sets potential pressure force.
Definition: tpsamodel.hpp:714
Scalar eqWeight(unsigned, unsigned eqIdx) const
Return equation weights.
Definition: tpsamodel.hpp:367
TpsaModel(Simulator &simulator)
Constructor.
Definition: tpsamodel.hpp:170
std::array< DimVector, 6 > traction(const unsigned globalIdx) const
Output traction vector for each of the 6 face directions.
Definition: tpsamodel.hpp:617
SolutionVector & solution(unsigned timeIdx)
Get reference to history solution vector.
Definition: tpsamodel.hpp:326
void prepareTPSA()
Prepare TPSA model for coupled Flow-TPSA scheme.
Definition: tpsamodel.hpp:215
Scalar solidPressure(const unsigned globalIdx) const
Output solid pressure.
Definition: tpsamodel.hpp:454
SymTensor fractureStress(const unsigned) const
Output fracture stress tensor.
Definition: tpsamodel.hpp:478
std::size_t numTotalDof() const
Return the total number of degrees of freedom.
Definition: tpsamodel.hpp:344
Linearizer & linearizer()
Return the linearizer.
Definition: tpsamodel.hpp:284
void syncOverlap()
Sync primary variables in overlapping cells.
Definition: tpsamodel.hpp:226
DimVector rotation(const unsigned globalIdx) const
Output rotation vector.
Definition: tpsamodel.hpp:439
Scalar mechPotentialForce(unsigned globalIdx) const
Output total potential forces.
Definition: tpsamodel.hpp:692
Definition: fvbaseprimaryvariables.hh:161
Definition: blackoilbioeffectsmodules.hh:45
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
The Opm property system, traits with inheritance.