fix a few review comments

This commit is contained in:
Andreas Lauser 2018-10-30 15:50:36 +01:00
parent 339c76bcac
commit 46b52448aa
3 changed files with 72 additions and 61 deletions

View File

@ -65,7 +65,7 @@ namespace Opm
AquiferCarterTracy( const AquiferCT::AQUCT_data& aquct_data, AquiferCarterTracy( const AquiferCT::AQUCT_data& aquct_data,
const Aquancon::AquanconOutput& connection, const Aquancon::AquanconOutput& connection,
const Simulator& ebosSimulator) const Simulator& ebosSimulator)
: simulator_ (ebosSimulator) : ebos_simulator_ (ebosSimulator)
, aquct_data_ (aquct_data) , aquct_data_ (aquct_data)
, connection_(connection) , connection_(connection)
{} {}
@ -77,22 +77,22 @@ namespace Opm
void beginTimeStep() void beginTimeStep()
{ {
ElementContext elemCtx(simulator_); ElementContext elemCtx(ebos_simulator_);
auto elemIt = simulator_.gridView().template begin<0>(); auto elemIt = ebos_simulator_.gridView().template begin<0>();
const auto& elemEndIt = simulator_.gridView().template end<0>(); const auto& elemEndIt = ebos_simulator_.gridView().template end<0>();
for (; elemIt != elemEndIt; ++elemIt) { for (; elemIt != elemEndIt; ++elemIt) {
const auto& elem = *elemIt; const auto& elem = *elemIt;
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
int cellIdx = elemCtx.globalSpaceIndex(0, 0); int cellIdx = elemCtx.globalSpaceIndex(0, 0);
int connIdx = cellToConnectionIdx_[cellIdx]; int idx = cellToConnectionIdx_[cellIdx];
if (connIdx < 0) if (idx < 0)
continue; continue;
elemCtx.updateIntensiveQuantities(0); elemCtx.updateIntensiveQuantities(0);
const auto& iq = elemCtx.intensiveQuantities(0, 0); const auto& iq = elemCtx.intensiveQuantities(0, 0);
pressure_previous_[connIdx] = Opm::getValue(iq.fluidState().pressure(waterPhaseIdx)); pressure_previous_[idx] = Opm::getValue(iq.fluidState().pressure(waterPhaseIdx));
} }
} }
@ -101,35 +101,34 @@ namespace Opm
{ {
unsigned cellIdx = context.globalSpaceIndex(spaceIdx, timeIdx); unsigned cellIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
int connIdx = cellToConnectionIdx_[cellIdx]; int idx = cellToConnectionIdx_[cellIdx];
if (connIdx < 0) if (idx < 0)
return; return;
// We are dereferencing the value of IntensiveQuantities because cachedIntensiveQuantities return a const pointer to // We are dereferencing the value of IntensiveQuantities because cachedIntensiveQuantities return a const pointer to
// IntensiveQuantities of that particular cell_id // IntensiveQuantities of that particular cell_id
const IntensiveQuantities intQuants = context.intensiveQuantities(spaceIdx, timeIdx); const IntensiveQuantities intQuants = context.intensiveQuantities(spaceIdx, timeIdx);
// This is the pressure at td + dt // This is the pressure at td + dt
updateCellPressure(pressure_current_,connIdx,intQuants); updateCellPressure(pressure_current_,idx,intQuants);
updateCellDensity(connIdx,intQuants); updateCellDensity(idx,intQuants);
calculateInflowRate(connIdx, context.simulator()); calculateInflowRate(idx, context.simulator());
rates[BlackoilIndices::conti0EqIdx + FluidSystem::waterCompIdx] += rates[BlackoilIndices::conti0EqIdx + FluidSystem::waterCompIdx] +=
Qai_[connIdx]/context.dofVolume(spaceIdx, timeIdx); Qai_[idx]/context.dofVolume(spaceIdx, timeIdx);
} }
void endTimeStep() void endTimeStep()
{ {
for (const auto& Qai: Qai_) { for (const auto& Qai: Qai_) {
totalWaterFlux_ += Qai*simulator_.timeStepSize(); W_flux_ += Qai*ebos_simulator_.timeStepSize();
} }
} }
private: private:
const Simulator& simulator_; const Simulator& ebos_simulator_;
// Grid variables // Grid variables
std::vector<size_t> connectionToCellIdx_; std::vector<size_t> cell_idx_;
std::vector<Scalar> faceArea_connected_; std::vector<Scalar> faceArea_connected_;
// Quantities at each grid id // Quantities at each grid id
@ -140,8 +139,6 @@ namespace Opm
std::vector<Eval> rhow_; std::vector<Eval> rhow_;
std::vector<Scalar> alphai_; std::vector<Scalar> alphai_;
std::vector<Eval> aquiferWaterInflux_;
// Variables constants // Variables constants
const AquiferCT::AQUCT_data aquct_data_; const AquiferCT::AQUCT_data aquct_data_;
@ -150,11 +147,11 @@ namespace Opm
Scalar Tc_; // Time constant Scalar Tc_; // Time constant
Scalar pa0_; // initial aquifer pressure Scalar pa0_; // initial aquifer pressure
Eval totalWaterFlux_; Eval W_flux_;
Scalar gravity_() const Scalar gravity_() const
{ return simulator_.problem().gravity()[2]; } { return ebos_simulator_.problem().gravity()[2]; }
inline void getInfluenceTableValues(Scalar& pitd, Scalar& pitd_prime, const Scalar& td) inline void getInfluenceTableValues(Scalar& pitd, Scalar& pitd_prime, const Scalar& td)
{ {
@ -166,7 +163,7 @@ namespace Opm
inline void initQuantities(const Aquancon::AquanconOutput& connection) inline void initQuantities(const Aquancon::AquanconOutput& connection)
{ {
// We reset the cumulative flux at the start of any simulation, so, W_flux = 0 // We reset the cumulative flux at the start of any simulation, so, W_flux = 0
totalWaterFlux_ = 0.; W_flux_ = 0.;
// We next get our connections to the aquifer and initialize these quantities using the initialize_connections function // We next get our connections to the aquifer and initialize these quantities using the initialize_connections function
initializeConnections(connection); initializeConnections(connection);
@ -175,10 +172,9 @@ namespace Opm
calculateAquiferConstants(); calculateAquiferConstants();
aquiferWaterInflux_.resize(connectionToCellIdx_.size()); pressure_previous_.resize(cell_idx_.size(), 0.);
pressure_previous_.resize(connectionToCellIdx_.size(), 0.); pressure_current_.resize(cell_idx_.size(), 0.);
pressure_current_.resize(connectionToCellIdx_.size(), 0.); Qai_.resize(cell_idx_.size(), 0.0);
Qai_.resize(connectionToCellIdx_.size(), 0.0);
} }
inline void updateCellPressure(std::vector<Eval>& pressure_water, const int idx, const IntensiveQuantities& intQuants) inline void updateCellPressure(std::vector<Eval>& pressure_water, const int idx, const IntensiveQuantities& intQuants)
@ -213,7 +209,7 @@ namespace Opm
Scalar PItdprime = 0.; Scalar PItdprime = 0.;
Scalar PItd = 0.; Scalar PItd = 0.;
getInfluenceTableValues(PItd, PItdprime, td_plus_dt); getInfluenceTableValues(PItd, PItdprime, td_plus_dt);
a = 1.0/Tc_ * ( (beta_ * dpai(idx)) - (totalWaterFlux_.value() * PItdprime) ) / ( PItd - td*PItdprime ); a = 1.0/Tc_ * ( (beta_ * dpai(idx)) - (W_flux_.value() * PItdprime) ) / ( PItd - td*PItdprime );
b = beta_ / (Tc_ * ( PItd - td*PItdprime)); b = beta_ / (Tc_ * ( PItd - td*PItdprime));
} }
@ -242,22 +238,22 @@ namespace Opm
// This function is used to initialize and calculate the alpha_i for each grid connection to the aquifer // This function is used to initialize and calculate the alpha_i for each grid connection to the aquifer
inline void initializeConnections(const Aquancon::AquanconOutput& connection) inline void initializeConnections(const Aquancon::AquanconOutput& connection)
{ {
const auto& eclState = simulator_.vanguard().eclState(); const auto& eclState = ebos_simulator_.vanguard().eclState();
const auto& ugrid = simulator_.vanguard().grid(); const auto& ugrid = ebos_simulator_.vanguard().grid();
const auto& grid = eclState.getInputGrid(); const auto& grid = eclState.getInputGrid();
connectionToCellIdx_ = connection.global_index; cell_idx_ = connection.global_index;
auto globalCellIdx = ugrid.globalCell(); auto globalCellIdx = ugrid.globalCell();
assert( connectionToCellIdx_ == connection.global_index); assert( cell_idx_ == connection.global_index);
assert( (connectionToCellIdx_.size() == connection.influx_coeff.size()) ); assert( (cell_idx_.size() == connection.influx_coeff.size()) );
assert( (connection.influx_coeff.size() == connection.influx_multiplier.size()) ); assert( (connection.influx_coeff.size() == connection.influx_multiplier.size()) );
assert( (connection.influx_multiplier.size() == connection.reservoir_face_dir.size()) ); assert( (connection.influx_multiplier.size() == connection.reservoir_face_dir.size()) );
// We hack the cell depth values for now. We can actually get it from elementcontext pos // We hack the cell depth values for now. We can actually get it from elementcontext pos
cell_depth_.resize(connectionToCellIdx_.size(), aquct_data_.d0); cell_depth_.resize(cell_idx_.size(), aquct_data_.d0);
alphai_.resize(connectionToCellIdx_.size(), 1.0); alphai_.resize(cell_idx_.size(), 1.0);
faceArea_connected_.resize(connectionToCellIdx_.size(),0.0); faceArea_connected_.resize(cell_idx_.size(),0.0);
Scalar faceArea; Scalar faceArea;
auto cell2Faces = Opm::UgGridHelpers::cell2Faces(ugrid); auto cell2Faces = Opm::UgGridHelpers::cell2Faces(ugrid);
@ -268,12 +264,12 @@ namespace Opm
// denom_face_areas is the sum of the areas connected to an aquifer // denom_face_areas is the sum of the areas connected to an aquifer
Scalar denom_face_areas = 0.; Scalar denom_face_areas = 0.;
cellToConnectionIdx_.resize(simulator_.gridView().size(/*codim=*/0), -1); cellToConnectionIdx_.resize(ebos_simulator_.gridView().size(/*codim=*/0), -1);
for (size_t idx = 0; idx < connectionToCellIdx_.size(); ++idx) for (size_t idx = 0; idx < cell_idx_.size(); ++idx)
{ {
cellToConnectionIdx_[connectionToCellIdx_[idx]] = idx; cellToConnectionIdx_[cell_idx_[idx]] = idx;
auto cellFacesRange = cell2Faces[connectionToCellIdx_.at(idx)]; auto cellFacesRange = cell2Faces[cell_idx_.at(idx)];
for(auto cellFaceIter = cellFacesRange.begin(); cellFaceIter != cellFacesRange.end(); ++cellFaceIter) for(auto cellFaceIter = cellFacesRange.begin(); cellFaceIter != cellFacesRange.end(); ++cellFaceIter)
{ {
// The index of the face in the compressed grid // The index of the face in the compressed grid
@ -309,11 +305,11 @@ namespace Opm
denom_face_areas += ( connection.influx_multiplier.at(idx) * faceArea_connected_.at(idx) ); denom_face_areas += ( connection.influx_multiplier.at(idx) * faceArea_connected_.at(idx) );
} }
} }
auto cellCenter = grid.getCellCenter(connectionToCellIdx_.at(idx)); auto cellCenter = grid.getCellCenter(cell_idx_.at(idx));
cell_depth_.at(idx) = cellCenter[2]; cell_depth_.at(idx) = cellCenter[2];
} }
for (size_t idx = 0; idx < connectionToCellIdx_.size(); ++idx) for (size_t idx = 0; idx < cell_idx_.size(); ++idx)
{ {
alphai_.at(idx) = ( connection.influx_multiplier.at(idx) * faceArea_connected_.at(idx) )/denom_face_areas; alphai_.at(idx) = ( connection.influx_multiplier.at(idx) * faceArea_connected_.at(idx) )/denom_face_areas;
} }
@ -324,7 +320,7 @@ namespace Opm
int pvttableIdx = aquct_data_.pvttableID - 1; int pvttableIdx = aquct_data_.pvttableID - 1;
rhow_.resize(connectionToCellIdx_.size(),0.); rhow_.resize(cell_idx_.size(),0.);
if (aquct_data_.p0 < 1.0) if (aquct_data_.p0 < 1.0)
{ {
@ -337,8 +333,8 @@ namespace Opm
// use the thermodynamic state of the first active cell as a // use the thermodynamic state of the first active cell as a
// reference. there might be better ways to do this... // reference. there might be better ways to do this...
ElementContext elemCtx(simulator_); ElementContext elemCtx(ebos_simulator_);
const auto& elem = *simulator_.gridView().template begin</*codim=*/0>(); const auto& elem = *ebos_simulator_.gridView().template begin</*codim=*/0>();
elemCtx.updateAll(elem); elemCtx.updateAll(elem);
const auto& iq0 = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0); const auto& iq0 = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
@ -364,8 +360,8 @@ namespace Opm
std::vector<Scalar> pw_aquifer; std::vector<Scalar> pw_aquifer;
Scalar water_pressure_reservoir; Scalar water_pressure_reservoir;
ElementContext elemCtx(simulator_); ElementContext elemCtx(ebos_simulator_);
const auto& gridView = simulator_.gridView(); const auto& gridView = ebos_simulator_.gridView();
auto elemIt = gridView.template begin</*codim=*/0>(); auto elemIt = gridView.template begin</*codim=*/0>();
const auto& elemEndIt = gridView.template end</*codim=*/0>(); const auto& elemEndIt = gridView.template end</*codim=*/0>();
for (; elemIt != elemEndIt; ++elemIt) { for (; elemIt != elemEndIt; ++elemIt) {
@ -373,8 +369,8 @@ namespace Opm
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
size_t cellIdx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0); size_t cellIdx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
int connIdx = cellToConnectionIdx_[cellIdx]; int idx = cellToConnectionIdx_[cellIdx];
if (connIdx < 0) if (idx < 0)
continue; continue;
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
@ -382,8 +378,8 @@ namespace Opm
const auto& fs = iq0.fluidState(); const auto& fs = iq0.fluidState();
water_pressure_reservoir = fs.pressure(waterPhaseIdx).value(); water_pressure_reservoir = fs.pressure(waterPhaseIdx).value();
rhow_[connIdx] = fs.density(waterPhaseIdx); rhow_[idx] = fs.density(waterPhaseIdx);
pw_aquifer.push_back( (water_pressure_reservoir - rhow_[connIdx].value()*gravity_()*(cell_depth_[connIdx] - aquct_data_.d0))*alphai_[connIdx] ); pw_aquifer.push_back( (water_pressure_reservoir - rhow_[idx].value()*gravity_()*(cell_depth_[idx] - aquct_data_.d0))*alphai_[idx] );
} }
// We take the average of the calculated equilibrium pressures. // We take the average of the calculated equilibrium pressures.

View File

@ -36,29 +36,34 @@ namespace Opm {
/// Class for handling the blackoil well model. /// Class for handling the blackoil well model.
template<typename TypeTag> template<typename TypeTag>
class BlackoilAquiferModel : public Ewoms::EclBaseAquiferModel<TypeTag> class BlackoilAquiferModel
{ {
typedef Ewoms::EclBaseAquiferModel<TypeTag> ParentType;
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator; typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector; typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
public: public:
explicit BlackoilAquiferModel(Simulator& ebosSimulator); explicit BlackoilAquiferModel(Simulator& simulator);
void initialSolutionApplied() void initialSolutionApplied()
{ {
for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) {
aquifer->initialSolutionApplied(); aquifer->initialSolutionApplied();
}
} }
void beginEpisode()
{ }
void beginTimeStep() void beginTimeStep()
{ {
for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) {
aquifer->beginTimeStep(); aquifer->beginTimeStep();
}
} }
void beginIteration()
{ }
// add the water rate due to aquifers to the source term. // add the water rate due to aquifers to the source term.
template <class Context> template <class Context>
void addToSource(RateVector& rates, void addToSource(RateVector& rates,
@ -66,16 +71,24 @@ namespace Opm {
unsigned spaceIdx, unsigned spaceIdx,
unsigned timeIdx) const unsigned timeIdx) const
{ {
for (auto& aquifer: aquifers_) for (auto& aquifer: aquifers_) {
aquifer.addToSource(rates, context, spaceIdx, timeIdx); aquifer.addToSource(rates, context, spaceIdx, timeIdx);
}
} }
void endIteration()
{ }
void endTimeStep() void endTimeStep()
{ {
for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) for (auto aquifer = aquifers_.begin(); aquifer != aquifers_.end(); ++aquifer) {
aquifer->endTimeStep(); aquifer->endTimeStep();
}
} }
void endEpisode()
{ }
protected: protected:
// --------- Types --------- // --------- Types ---------
typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext; typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
@ -87,6 +100,8 @@ namespace Opm {
// long term // long term
mutable std::vector<AquiferType> aquifers_; mutable std::vector<AquiferType> aquifers_;
Simulator& simulator_;
// This initialization function is used to connect the parser objects with the ones needed by AquiferCarterTracy // This initialization function is used to connect the parser objects with the ones needed by AquiferCarterTracy
void init(); void init();

View File

@ -3,8 +3,8 @@ namespace Opm {
template<typename TypeTag> template<typename TypeTag>
BlackoilAquiferModel<TypeTag>:: BlackoilAquiferModel<TypeTag>::
BlackoilAquiferModel(Simulator& ebosSimulator) BlackoilAquiferModel(Simulator& simulator)
: ParentType(ebosSimulator) : simulator_(simulator)
{ {
init(); init();
} }