25 #ifndef TPSA_MODEL_HPP 26 #define TPSA_MODEL_HPP 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/material/common/MathToolbox.hpp> 38 #include <opm/models/tpsa/tpsabaseproperties.hpp> 39 #include <opm/models/utils/linearleastsquares.hpp> 44 #include <unordered_map> 54 template <
class TypeTag>
69 enum { dimWorld = GridView::dimensionworld };
70 enum { historySize = getPropValue<TypeTag, Properties::SolutionHistorySizeTPSA>() };
71 enum { numEq = getPropValue<TypeTag, Properties::NumEqTPSA>() };
73 enum { disp0Idx = Indices::disp0Idx };
74 enum { rot0Idx = Indices::rot0Idx };
75 enum { solidPres0Idx = Indices::solidPres0Idx };
77 using MaterialState = MaterialStateTPSA<Evaluation>;
79 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
80 using SymTensor = Dune::FieldVector<Scalar, 6>;
89 SolutionVector blockVector_;
112 result.blockVector_[0] = 1.0;
113 result.blockVector_[1] = 2.0;
114 result.blockVector_[2] = 3.0;
125 {
return blockVector_; }
133 {
return blockVector_; }
143 return std::equal(this->blockVector_.begin(), this->blockVector_.end(),
144 wrapper.blockVector_.begin(), wrapper.blockVector_.end());
152 template<
class Serializer>
155 serializer(blockVector_);
168 : linearizer_(std::make_unique<Linearizer>())
169 , newtonMethod_(simulator)
170 , simulator_(simulator)
171 , element_chunks_(simulator.gridView(),
Dune::Partitions::all,
ThreadManager::maxThreads())
174 eqWeights_.resize(numEq, 1.0);
178 const std::size_t numDof = simulator_.model().numGridDof();
179 for (
unsigned timeIdx = 0; timeIdx < historySize; ++timeIdx) {
180 solution_[timeIdx] = std::make_unique<TpsaBlockVectorWrapper>(
"solution", numDof);
190 linearizer_->init(simulator_);
227 auto ghostSync = GhostSyncHandle(
solution(0),
228 simulator_.model().dofMapper());
230 simulator_.gridView().communicate(ghostSync,
231 Dune::InteriorBorder_All_Interface,
232 Dune::ForwardCommunication);
245 const auto& elementMapper = simulator_.model().elementMapper();
247 #pragma omp parallel for 249 for (
const auto& chunk : element_chunks_) {
250 for (
const auto& elem : chunk) {
251 const unsigned globalIdx = elementMapper.index(elem);
252 auto& currSol =
solution(0)[globalIdx];
253 setMaterialState_(globalIdx, 0, currSol);
288 return newtonMethod_;
298 return newtonMethod_;
307 const SolutionVector&
solution(
unsigned timeIdx)
const 309 return solution_[timeIdx]->blockVector();
320 return solution_[timeIdx]->blockVector();
329 return simulator_.model().numGridDof();
349 return simulator_.model().dofTotalVolume(globalIdx);
361 return eqWeights_[eqIdx];
372 eqWeights_[eqIdx] = value;
402 const MaterialState&
materialState(
const unsigned globalIdx,
unsigned )
const 404 return materialState_[globalIdx];
416 DimVector
disp(
const unsigned globalIdx,
const bool )
const 419 for (std::size_t i = 0; i < 3; ++i) {
420 d[i] = decay<Scalar>(materialState_[globalIdx].displacement(i));
477 SymTensor
stress(
const unsigned globalIdx,
const bool )
const 479 SymTensor stressOutput;
480 const auto& stressInfo = linearizer_->getStressInfo();
481 if (!stressInfo.empty()) {
482 const auto& stressInfoGlobI = stressInfo[globalIdx];
487 std::unordered_multimap<int, std::size_t> faceIdMap;
488 std::size_t mapSize = 0;
489 for (std::size_t sInfoIdx = 0; sInfoIdx < stressInfoGlobI.size(); ++sInfoIdx) {
490 const auto faceId = stressInfoGlobI[sInfoIdx].faceId;
494 if (faceId < 0 || stressInfoGlobI[sInfoIdx].faceArea == 0.0) {
497 if (!faceIdMap.contains(faceId)) {
500 faceIdMap.insert({faceId, sInfoIdx});
508 Dune::DynamicMatrix<Scalar> mat(3 * mapSize, 6);
509 Dune::DynamicVector<Scalar> rhs(3 * mapSize);
510 std::size_t rowIdx = 0;
511 for (
auto it = faceIdMap.begin(); it != faceIdMap.end();) {
512 auto [first, last] = faceIdMap.equal_range(it->first);
515 Scalar sumFaceArea = 0.0;
516 for (
auto inner = first; inner != last; ++inner) {
517 const auto sInfoIdx = inner->second;
518 const auto& faceStressInfo = stressInfoGlobI[sInfoIdx];
521 if (inner == first) {
522 const auto& fNormal = faceStressInfo.faceNormal;
523 mat[3*rowIdx][0] = fNormal[0];
524 mat[3*rowIdx][3] = fNormal[1];
525 mat[3*rowIdx][4] = fNormal[2];
527 mat[3*rowIdx + 1][1] = fNormal[1];
528 mat[3*rowIdx + 1][3] = fNormal[0];
529 mat[3*rowIdx + 1][5] = fNormal[2];
531 mat[3*rowIdx + 2][2] = fNormal[2];
532 mat[3*rowIdx + 2][4] = fNormal[0];
533 mat[3*rowIdx + 2][5] = fNormal[1];
537 const auto& fTraction = faceStressInfo.traction;
538 rhs[3*rowIdx] += fTraction[0];
539 rhs[3*rowIdx + 1] += fTraction[1];
540 rhs[3*rowIdx + 2] += fTraction[2];
543 sumFaceArea += faceStressInfo.faceArea;
546 rhs[3*rowIdx] /= sumFaceArea;
547 rhs[3*rowIdx + 1] /= sumFaceArea;
548 rhs[3*rowIdx + 2] /= sumFaceArea;
561 stressOutput[0] =
stress[0];
562 stressOutput[1] =
stress[1];
563 stressOutput[2] =
stress[2];
564 stressOutput[3] =
stress[5];
565 stressOutput[4] =
stress[4];
566 stressOutput[5] =
stress[3];
580 SymTensor
strain(
const unsigned ,
const bool )
const 636 const std::size_t numDof = simulator_.model().numGridDof();
637 materialState_.resize(numDof);
653 void setMaterialState_(
const unsigned globalIdx,
const unsigned , PrimaryVariables& values)
655 auto& dofMaterialState = materialState_[globalIdx];
656 for (
unsigned dirIdx = 0; dirIdx < 3; ++dirIdx) {
657 dofMaterialState.setDisplacement(dirIdx, values.makeEvaluation(disp0Idx + dirIdx, 0));
658 dofMaterialState.setRotation(dirIdx, values.makeEvaluation(rot0Idx + dirIdx, 0));
660 dofMaterialState.setSolidPressure(values.makeEvaluation(solidPres0Idx, 0));
663 std::unique_ptr<Linearizer> linearizer_;
664 NewtonMethod newtonMethod_;
665 Simulator& simulator_;
666 ElementChunks<GridView, Dune::Partitions::All> element_chunks_;
668 std::array<std::unique_ptr<TpsaBlockVectorWrapper>, historySize> solution_;
669 std::vector<Scalar> eqWeights_;
670 std::vector<MaterialState> materialState_;
Data handle for parallel communication which can be used to set the values values of ghost and overla...
Definition: gridcommhandles.hh:105
Simplifies multi-threaded capabilities.
Definition: threadmanager.hpp:35
static void registerParameters()
Register all run-time parameters for the Newton method.
Definition: newtonmethod.hh:135
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
std::size_t numGridDof() const
Return number of degrees of freedom in the grid from the Flow model.
Definition: tpsamodel.hpp:327
const SolutionVector & solution(unsigned timeIdx) const
Get reference to history solution vector.
Definition: tpsamodel.hpp:307
Linear least squares calculations and properties.
Definition: linearleastsquares.hpp:44
Scalar mechPotentialTempForce(unsigned) const
Output potential temparature forces.
Definition: tpsamodel.hpp:620
const NewtonMethod & newtonMethod() const
Return the Newton method.
Definition: tpsamodel.hpp:286
void resizeMaterialState_()
Resize material state vector.
Definition: tpsamodel.hpp:634
Definition: fvbaseprimaryvariables.hh:161
Scalar eqWeight(unsigned, unsigned eqIdx) const
Return equation weights.
Definition: tpsamodel.hpp:359
Scalar mechPotentialForce(unsigned) const
Output potential forces.
Definition: tpsamodel.hpp:594
std::size_t numAuxiliaryModules() const
Return number of auxillary modules.
Definition: tpsamodel.hpp:379
bool operator==(const TpsaBlockVectorWrapper &wrapper) const
Check if incoming block vector is the same as current.
Definition: tpsamodel.hpp:141
Small block vector wrapper class for model solutions.
Definition: tpsamodel.hpp:86
void setEqWeight(unsigned eqIdx, Scalar value)
Set weights for equation.
Definition: tpsamodel.hpp:370
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
SolutionVector & blockVector()
Get reference of block vector.
Definition: tpsamodel.hpp:124
static TpsaBlockVectorWrapper serializationTestObject()
Test function for serialization.
Definition: tpsamodel.hpp:109
const SolutionVector & blockVector() const
Get const reference of block vector.
Definition: tpsamodel.hpp:132
TpsaModel(Simulator &simulator)
Constructor.
Definition: tpsamodel.hpp:167
std::size_t numAuxiliaryDof() const
Return number of auxillary degrees of freedom.
Definition: tpsamodel.hpp:388
TpsaBlockVectorWrapper()=default
Default constructor.
void updateMaterialState(const unsigned)
Update material state for all cells.
Definition: tpsamodel.hpp:242
const Linearizer & linearizer() const
Return the linearizer.
Definition: tpsamodel.hpp:266
void solve()
Solve linear least squares system.
Definition: linearleastsquares.hpp:66
SymTensor delstress(const unsigned) const
Output (del?)stress tensor.
Definition: tpsamodel.hpp:433
const Vector & x() const
Read-only vector of calculated coefficient vector.
Definition: linearleastsquares.hpp:76
SymTensor stress(const unsigned globalIdx, const bool) const
Output stress tensor.
Definition: tpsamodel.hpp:477
SolutionVector & solution(unsigned timeIdx)
Get reference to history solution vector.
Definition: tpsamodel.hpp:318
SymTensor strain(const unsigned, const bool) const
Output strain tensor.
Definition: tpsamodel.hpp:580
NewtonMethod & newtonMethod()
Return the Newton method.
Definition: tpsamodel.hpp:296
void syncOverlap()
Sync primary variables in overlapping cells.
Definition: tpsamodel.hpp:219
void finishInit()
Initialize TPSA model.
Definition: tpsamodel.hpp:187
SymTensor fractureStress(const unsigned) const
Output fracture stress tensor.
Definition: tpsamodel.hpp:447
The Opm property system, traits with inheritance.
std::size_t numTotalDof() const
Return the total number of degrees of freedom.
Definition: tpsamodel.hpp:336
Simplifies multi-threaded capabilities.
DimVector disp(const unsigned globalIdx, const bool) const
Output displacement vector.
Definition: tpsamodel.hpp:416
void prepareTPSA()
Prepare TPSA model for coupled Flow-TPSA scheme.
Definition: tpsamodel.hpp:208
Scalar mechPotentialPressForce(unsigned) const
Output potential pressure forces.
Definition: tpsamodel.hpp:607
SymTensor linstress(const unsigned) const
Output linear stress tensor.
Definition: tpsamodel.hpp:461
TpsaBlockVectorWrapper(const std::string &, const std::size_t size)
Constructor.
Definition: tpsamodel.hpp:97
const MaterialState & materialState(const unsigned globalIdx, unsigned) const
Return current material state.
Definition: tpsamodel.hpp:402
void serializeOp(Serializer &serializer)
Serializing operation.
Definition: tpsamodel.hpp:153
Linearizer & linearizer()
Return the linearizer.
Definition: tpsamodel.hpp:276
TPSA geomechanics model.
Definition: tpsamodel.hpp:55
static void registerParameters()
Register runtime parameters.
Definition: tpsamodel.hpp:199
Scalar dofTotalVolume(unsigned globalIdx) const
Return the total grid volume from the Flow model.
Definition: tpsamodel.hpp:347