Merge pull request #5406 from GitPaean/only_trans

only allocate trans_ for globalTrans_
This commit is contained in:
Bård Skaflestad 2024-06-06 21:50:11 +02:00 committed by GitHub
commit e3bf48541f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 17 deletions

View File

@ -190,7 +190,8 @@ public:
getPropValue<TypeTag, getPropValue<TypeTag,
Properties::EnableDispersion>()); Properties::EnableDispersion>());
// Re-ordering for ALUGrid // Re-ordering for ALUGrid
globalTrans_->update(false, [&](unsigned int i) { return gridEquilIdxToGridIdx(i);}); globalTrans_->update(false, TransmissibilityType::TransUpdateQuantities::Trans,
[&](unsigned int i) { return gridEquilIdxToGridIdx(i);});
} }
} }
@ -351,6 +352,10 @@ protected:
std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_; std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_;
std::unique_ptr<EquilCartesianIndexMapper> equilCartesianIndexMapper_; std::unique_ptr<EquilCartesianIndexMapper> equilCartesianIndexMapper_;
std::unique_ptr<Factory> factory_; std::unique_ptr<Factory> factory_;
// \Note: this globalTrans_ is used for domain decomposition and INIT file output.
// It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
// diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
// during parallel running.
std::unique_ptr<TransmissibilityType> globalTrans_; std::unique_ptr<TransmissibilityType> globalTrans_;
int mpiRank; int mpiRank;
}; };

View File

@ -285,7 +285,7 @@ protected:
getPropValue<TypeTag, Properties::EnableEnergy>(), getPropValue<TypeTag, Properties::EnableEnergy>(),
getPropValue<TypeTag, Properties::EnableDiffusion>(), getPropValue<TypeTag, Properties::EnableDiffusion>(),
getPropValue<TypeTag, Properties::EnableDispersion>())); getPropValue<TypeTag, Properties::EnableDispersion>()));
globalTrans_->update(false); globalTrans_->update(false, TransmissibilityType::TransUpdateQuantities::Trans);
} }
double getTransmissibility(unsigned I, unsigned J) const override double getTransmissibility(unsigned I, unsigned J) const override
@ -306,6 +306,10 @@ protected:
this->doFilterConnections_(this->schedule()); this->doFilterConnections_(this->schedule());
} }
// \Note: this globalTrans_ is used for domain decomposition and INIT file output.
// It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
// diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
// during parallel running.
std::unique_ptr<TransmissibilityType> globalTrans_; std::unique_ptr<TransmissibilityType> globalTrans_;
}; };

View File

@ -538,7 +538,8 @@ public:
}; };
// re-compute all quantities which may possibly be affected. // re-compute all quantities which may possibly be affected.
transmissibilities_.update(true, equilGridToGrid); using TransUpdateQuantities = typename Vanguard::TransmissibilityType::TransUpdateQuantities;
transmissibilities_.update(true, TransUpdateQuantities::All, equilGridToGrid);
this->referencePorosity_[1] = this->referencePorosity_[0]; this->referencePorosity_[1] = this->referencePorosity_[0];
updateReferencePorosity_(); updateReferencePorosity_();
updatePffDofData_(); updatePffDofData_();
@ -700,8 +701,9 @@ public:
.applyActions(episodeIdx, simulator.time() + simulator.timeStepSize(), .applyActions(episodeIdx, simulator.time() + simulator.timeStepSize(),
[this](const bool global) [this](const bool global)
{ {
using TransUpdateQuantities = typename Vanguard::TransmissibilityType::TransUpdateQuantities;
this->transmissibilities_ this->transmissibilities_
.update(global, [&vg = this->simulator().vanguard()] .update(global, TransUpdateQuantities::All, [&vg = this->simulator().vanguard()]
(const unsigned int i) (const unsigned int i)
{ {
return vg.gridIdxToEquilGridIdx(i); return vg.gridIdxToEquilGridIdx(i);

View File

@ -128,7 +128,7 @@ public:
*/ */
void finishInit(const std::function<unsigned int(unsigned int)>& map = {}) void finishInit(const std::function<unsigned int(unsigned int)>& map = {})
{ {
this->update(true, map, /*applyNncMultRegT = */ true); this->update(true, TransUpdateQuantities::All, map, /*applyNncMultRegT = */ true);
} }
/*! /*!
@ -138,6 +138,13 @@ public:
* processes. Also, this updates the "thermal half * processes. Also, this updates the "thermal half
* transmissibilities" if energy is enabled. * transmissibilities" if energy is enabled.
* *
* \param[in] trans Indicating whether we only allocate and upate trans_ without considering
* thermalHalfTrans_, diffusivity_, dispersivity_. For many usage, we only need trans_,
* e.g. weights for domain decomposition, INIT file output. It might change following
* further development.
* Trans only update the trans_, which is related to permeability
* All upate rans_, thermalHalfTrans_, diffusivity_ and dispersivity_.
*
* \param[in] map Undocumented. * \param[in] map Undocumented.
* *
* \param[in] applyNncMultRegT Whether or not to apply regional * \param[in] applyNncMultRegT Whether or not to apply regional
@ -147,7 +154,9 @@ public:
* numerical aquifers. Default value: \c false, meaning do not apply * numerical aquifers. Default value: \c false, meaning do not apply
* regional multipliers to explicit NNCs. * regional multipliers to explicit NNCs.
*/ */
void update(bool global, const std::function<unsigned int(unsigned int)>& map = {}, bool applyNncMultRegT = false); enum class TransUpdateQuantities { Trans, All };
void update(bool global, TransUpdateQuantities update_quantities = TransUpdateQuantities::All,
const std::function<unsigned int(unsigned int)>& map = {}, bool applyNncMultRegT = false);
protected: protected:
void updateFromEclState_(bool global); void updateFromEclState_(bool global);

View File

@ -159,8 +159,11 @@ dispersivity(unsigned elemIdx1, unsigned elemIdx2) const
template<class Grid, class GridView, class ElementMapper, class CartesianIndexMapper, class Scalar> template<class Grid, class GridView, class ElementMapper, class CartesianIndexMapper, class Scalar>
void Transmissibility<Grid,GridView,ElementMapper,CartesianIndexMapper,Scalar>:: void Transmissibility<Grid,GridView,ElementMapper,CartesianIndexMapper,Scalar>::
update(bool global, const std::function<unsigned int(unsigned int)>& map, const bool applyNncMultregT) update(bool global, const TransUpdateQuantities update_quantities,
const std::function<unsigned int(unsigned int)>& map, const bool applyNncMultregT)
{ {
// whether only update the permeability related transmissibility
const bool onlyTrans = (update_quantities == TransUpdateQuantities::Trans);
const auto& cartDims = cartMapper_.cartesianDimensions(); const auto& cartDims = cartMapper_.cartesianDimensions();
const auto& transMult = eclState_.getTransMult(); const auto& transMult = eclState_.getTransMult();
const auto& comm = gridView_.comm(); const auto& comm = gridView_.comm();
@ -208,7 +211,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
transBoundary_.clear(); transBoundary_.clear();
// if energy is enabled, let's do the same for the "thermal half transmissibilities" // if energy is enabled, let's do the same for the "thermal half transmissibilities"
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
thermalHalfTrans_.clear(); thermalHalfTrans_.clear();
thermalHalfTrans_.reserve(numElements*6*1.05); thermalHalfTrans_.reserve(numElements*6*1.05);
@ -216,14 +219,14 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// if diffusion is enabled, let's do the same for the "diffusivity" // if diffusion is enabled, let's do the same for the "diffusivity"
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
diffusivity_.clear(); diffusivity_.clear();
diffusivity_.reserve(numElements*3*1.05); diffusivity_.reserve(numElements*3*1.05);
extractPorosity_(); extractPorosity_();
} }
// if dispersion is enabled, let's do the same for the "dispersivity" // if dispersion is enabled, let's do the same for the "dispersivity"
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
dispersivity_.clear(); dispersivity_.clear();
dispersivity_.reserve(numElements*3*1.05); dispersivity_.reserve(numElements*3*1.05);
extractDispersion_(); extractDispersion_();
@ -283,7 +286,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
// for boundary intersections we also need to compute the thermal // for boundary intersections we also need to compute the thermal
// half transmissibilities // half transmissibilities
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
Scalar transBoundaryEnergyIs; Scalar transBoundaryEnergyIs;
computeHalfDiffusivity_(transBoundaryEnergyIs, computeHalfDiffusivity_(transBoundaryEnergyIs,
faceAreaNormal, faceAreaNormal,
@ -334,15 +337,15 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
// *added to* by applyNncToGridTrans_() later. // *added to* by applyNncToGridTrans_() later.
assert(outsideFaceIdx == -1); assert(outsideFaceIdx == -1);
trans_[details::isId(elemIdx, outsideElemIdx)] = 0.0; trans_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
if (enableEnergy_){ if (enableEnergy_ && !onlyTrans){
thermalHalfTrans_[details::directionalIsId(elemIdx, outsideElemIdx)] = 0.0; thermalHalfTrans_[details::directionalIsId(elemIdx, outsideElemIdx)] = 0.0;
thermalHalfTrans_[details::directionalIsId(outsideElemIdx, elemIdx)] = 0.0; thermalHalfTrans_[details::directionalIsId(outsideElemIdx, elemIdx)] = 0.0;
} }
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
diffusivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0; diffusivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
} }
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
dispersivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0; dispersivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
} }
continue; continue;
@ -459,7 +462,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
trans_[details::isId(elemIdx, outsideElemIdx)] = trans; trans_[details::isId(elemIdx, outsideElemIdx)] = trans;
// update the "thermal half transmissibility" for the intersection // update the "thermal half transmissibility" for the intersection
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
Scalar halfDiffusivity1; Scalar halfDiffusivity1;
Scalar halfDiffusivity2; Scalar halfDiffusivity2;
@ -484,7 +487,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// update the "diffusive half transmissibility" for the intersection // update the "diffusive half transmissibility" for the intersection
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
Scalar halfDiffusivity1; Scalar halfDiffusivity1;
Scalar halfDiffusivity2; Scalar halfDiffusivity2;
@ -520,7 +523,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// update the "dispersivity half transmissibility" for the intersection // update the "dispersivity half transmissibility" for the intersection
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
Scalar halfDispersivity1; Scalar halfDispersivity1;
Scalar halfDispersivity2; Scalar halfDispersivity2;