updating AquiferConstantFlux with AQUFLUX

not recreating new instances to avoid unnecessary cost from constructor.
This commit is contained in:
Kai Bao 2023-02-15 23:21:05 +01:00
parent 6fa97874f8
commit 73dc31a7a5
5 changed files with 19 additions and 40 deletions

View File

@ -226,12 +226,6 @@ protected:
return FluidSystem::waterCompIdx;
}
double cumulativeFlux() const
{
return Opm::getValue(this->W_flux_);
}
void initQuantities()
{
// We reset the cumulative flux at the start of any simulation, so, W_flux = 0

View File

@ -37,14 +37,12 @@ public:
static constexpr int numEq = BlackoilIndices::numEq;
using Eval = DenseAd::Evaluation<double, /*size=*/numEq>;
AquiferConstantFlux(const AquiferFlux& aquifer,
AquiferConstantFlux(const SingleAquiferFlux& aquifer,
const std::vector<Aquancon::AquancCell>& connections,
const Simulator& ebos_simulator,
const double init_cumulative_flux = 0.)
const Simulator& ebos_simulator)
: AquiferInterface<TypeTag>(aquifer.id, ebos_simulator)
, connections_(connections)
, aquifer_data_(aquifer)
, cumulative_flux_(init_cumulative_flux)
{
// init_cumulative_flux is the flux volume from previoius running
this->initializeConnections();
@ -53,15 +51,14 @@ public:
virtual ~AquiferConstantFlux() = default;
/* void updateAquifer(const std::shared_ptr<AquiferFlux>& aquifer) {
void updateAquifer(const SingleAquiferFlux& aquifer) {
aquifer_data_ = aquifer;
} */
}
void initFromRestart(const data::Aquifers& /* aquiferSoln */) {
}
void initialSolutionApplied() {
// this->initializeConnections();
}
void beginTimeStep() {
@ -107,32 +104,23 @@ public:
}
const double fw = this->aquifer_data_.flux;
// const double m = this->connections_[idx].influx_coeff;
this->connection_flux_[idx] = fw * this->connections_[idx].effective_facearea;
rates[BlackoilIndices::conti0EqIdx + compIdx_()]
+= this->connection_flux_[idx] / model.dofTotalVolume(cellIdx);
}
// TODO: repeated function from AquiferAnalytical
std::size_t size() const
{
return this->connections_.size();
}
private:
const std::vector<Aquancon::AquancCell> connections_;
AquiferFlux aquifer_data_;
SingleAquiferFlux aquifer_data_;
std::vector<int> cellToConnectionIdx_;
std::vector<Eval> connection_flux_;
double flux_rate_ {};
double cumulative_flux_ = 0.;
void initializeConnections() {
this->cellToConnectionIdx_.resize(this->ebos_simulator_.gridView().size(/*codim=*/0), -1);
const auto& gridView = this->ebos_simulator_.vanguard().gridView();
for (std::size_t idx = 0; idx < this->size(); ++idx) {
for (std::size_t idx = 0; idx < this->connections_.size(); ++idx) {
const auto global_index = this->connections_[idx].global_index;
const int cell_index = this->ebos_simulator_.vanguard().compressedIndex(global_index);
auto elemIt = gridView.template begin</*codim=*/ 0>();
@ -157,11 +145,6 @@ private:
return FluidSystem::waterCompIdx;
}
double cumulativeFlux() const
{
return this->cumulative_flux_;
}
};
}

View File

@ -74,10 +74,6 @@ public:
int aquiferID() const { return this->aquiferID_; }
// TODO: in the future, we might need to save the aquifer state here
// TODO: when other aquifer types are involved
virtual double cumulativeFlux() const = 0;
protected:
bool co2store_() const
{

View File

@ -68,15 +68,20 @@ BlackoilAquiferModel<TypeTag>::beginEpisode()
auto find = std::find_if(begin(this->aquifers), end(this->aquifers), [id](auto& v){ return v->aquiferID() == id; });
if (find == this->aquifers.end()) {
// the aquifer id does not exist in BlackoilAquiferModel yet
const auto& aquinfo = *(elem.second);
const auto& aquinfo = elem.second;
auto aqf = std::make_unique<AquiferConstantFlux<TypeTag>>(aquinfo, connections.getConnections(aquinfo.id), this->simulator_);
this->aquifers.push_back(std::move(aqf));
} else {
const double prev_cumulative_flux = (*find)->cumulativeFlux();
const auto& aquinfo = *(elem.second);
// TODO: it should be improved to be something like to update the related information instead of creating a new one
auto aqf = std::make_unique<AquiferConstantFlux<TypeTag>>(aquinfo, connections.getConnections(aquinfo.id), this->simulator_, prev_cumulative_flux);
*find = std::move(aqf);
const auto& aquinfo = elem.second;
auto aqu = dynamic_cast<AquiferConstantFlux<TypeTag>*> (find->get());
if (!aqu) {
// if the aquifers can return types easily, we might be able to give a better message with type information
const auto msg = fmt::format("Aquifer {} is updated with constant flux aquifer keyword AQUFLUX at report step {},"
" while it might be specified to be a different type of aquifer before this. We do not support the conversion between"
" different types of aquifer.\n", id, report_step);
OPM_THROW(std::runtime_error, msg);
}
aqu->updateAquifer(aquinfo);
}
}
}
@ -194,6 +199,7 @@ BlackoilAquiferModel<TypeTag>::init()
}
for (const auto& [id, aq] : aquifer.aquflux()) {
// make sure not dummy constant flux aquifers
if ( !aq.active ) continue;
if (!connections.hasAquiferConnections(id)) {

View File

@ -268,7 +268,7 @@ namespace {
errorGuard);
}
eclipseState->appendAqufluxSchedule(schedule->getAquiferFluxListEnd());
eclipseState->appendAqufluxSchedule(schedule->getAquiferFluxSchedule());
if (Opm::OpmLog::hasBackend("STDOUT_LOGGER")) {
// loggers might not be set up!