Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cleaning of filter cake in a more intuitive way #5627

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions opm/simulators/wells/BlackoilWellModelGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,20 +1821,21 @@ void BlackoilWellModelGeneric<Scalar>::initInjMult()

template<class Scalar>
void BlackoilWellModelGeneric<Scalar>::
updateFiltrationParticleVolume(const double dt,
const std::size_t water_index)
updateFiltrationModelsPostStep(const double dt,
const std::size_t water_index,
DeferredLogger& deferred_logger)
{
for (auto& well : this->well_container_generic_) {
if (well->isInjector()) {
const Scalar conc = well->wellEcl().evalFilterConc(this->summaryState_);
if (conc > 0.) {
auto fc = this->filter_cake_
// Update filter cake build-ups (external to the wellbore)
auto retval = this->filter_cake_
.emplace(std::piecewise_construct,
std::forward_as_tuple(well->name()),
std::tuple{});

fc.first->second.updateFiltrationParticleVolume(*well, dt, conc, water_index,
this->wellState());
auto& fc = retval.first->second;
fc.updatePostStep(*well, this->wellState(), dt, conc, water_index, deferred_logger);
}
}
}
Expand All @@ -1853,19 +1854,20 @@ updateInjMult(DeferredLogger& deferred_logger)

template<class Scalar>
void BlackoilWellModelGeneric<Scalar>::
updateInjFCMult(DeferredLogger& deferred_logger)
updateFiltrationModelsPreStep(DeferredLogger& deferred_logger)
{
for (auto& well : this->well_container_generic_) {
if (well->isInjector()) {
const auto it = filter_cake_.find(well->name());
if (it != filter_cake_.end()) {
it->second.updateInjFCMult(*well, this->wellState(), deferred_logger);
it->second.updatePreStep(*well, deferred_logger);
well->updateFilterCakeMultipliers(it->second.multipliers());
}
}
}
}


template class BlackoilWellModelGeneric<double>;

#if FLOW_INSTANTIATE_FLOAT
Expand Down
7 changes: 5 additions & 2 deletions opm/simulators/wells/BlackoilWellModelGeneric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,11 @@ class BlackoilWellModelGeneric
void updateInjMult(DeferredLogger& deferred_logger);
void updateInjFCMult(DeferredLogger& deferred_logger);

void updateFiltrationParticleVolume(const double dt,
const std::size_t water_index);
void updateFiltrationModelsPostStep(const double dt,
const std::size_t water_index,
DeferredLogger& deferred_logger);

void updateFiltrationModelsPreStep(DeferredLogger& deferred_logger);

// create the well container
virtual void createWellContainer(const int time_step) = 0;
Expand Down
6 changes: 3 additions & 3 deletions opm/simulators/wells/BlackoilWellModel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ namespace Opm {
well->setGuideRate(&this->guideRate_);
}

this->updateInjFCMult(local_deferredLogger);
this->updateFiltrationModelsPreStep(local_deferredLogger);

// Close completions due to economic reasons
for (auto& well : well_container_) {
Expand Down Expand Up @@ -708,10 +708,10 @@ namespace Opm {
}

if (Indices::waterEnabled) {
this->updateFiltrationParticleVolume(dt, FluidSystem::waterPhaseIdx);
this->updateFiltrationModelsPostStep(dt, FluidSystem::waterPhaseIdx, local_deferredLogger);
}

// at the end of the time step, updating the inj_multiplier saved in WellState for later use
// WINJMULT: At the end of the time step, update the inj_multiplier saved in WellState for later use
this->updateInjMult(local_deferredLogger);

// report well switching
Expand Down
225 changes: 147 additions & 78 deletions opm/simulators/wells/WellFilterCake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,109 +37,178 @@ namespace Opm {

template<class Scalar>
void WellFilterCake<Scalar>::
updateFiltrationParticleVolume(const WellInterfaceGeneric<Scalar>& well,
const double dt,
const Scalar conc,
const std::size_t water_index,
WellState<Scalar>& well_state)
updatePostStep(const WellInterfaceGeneric<Scalar>& well,
WellState<Scalar>& well_state,
const double dt,
const Scalar conc,
const std::size_t water_index,
DeferredLogger& deferred_logger)
{
if (!well.isInjector()) {
if (! well.isInjector() || well.wellEcl().injectorType() != InjectorType::WATER)
return;
}

if (filtration_particle_volume_.empty()) {
const auto& ws = well_state.well(well.indexOfWell());
filtration_particle_volume_.assign(ws.perf_data.size(), 0.); // initializing to be zero
}

const auto injectorType = well.wellEcl().injectorType();
if (injectorType != InjectorType::WATER) {
return;
assert (conc > 0.);
auto& ws = well_state.well(well.indexOfWell());
const auto nperf = ws.perf_data.size();
if (skin_factor_.empty()) {
skin_factor_.assign(nperf, 0.);
thickness_.assign(nperf, 0.);
}

auto& ws = well_state.well(well.indexOfWell());
ws.filtrate_conc = conc;

if (conc == 0.) {
return;
}
updateSkinFactorsAndMultipliers(well, well_state, dt, water_index, deferred_logger);
}

const auto& connection_rates = ws.perf_data.phase_rates;
template<class Scalar>
void WellFilterCake<Scalar>::
updatePreStep(const WellInterfaceGeneric<Scalar>& well, DeferredLogger& deferred_logger)
{
// Apply cleaning and reset any filter cake cleaning multipliers (even if the well is producing at this time)
applyCleaning(well, deferred_logger);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to move the update of inj_fc_multiplier_ here. Because of possibly changed well setup and possibly cleaned filtration cake and skin factors, we update inj_fc_multiplier_ here will make sure that we utilize the most updated skin factors.

Copy link
Member Author

@vkip vkip Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point, inj_fc_multiplier_ must be updated here.

}

const std::size_t np = well_state.numPhases();
for (int perf = 0; perf < well.numPerfs(); ++perf) {
// not considering the production water
const Scalar water_rates = std::max(Scalar{0.}, connection_rates[perf * np + water_index]);
const Scalar filtrate_rate = water_rates * conc;
filtration_particle_volume_[perf] += filtrate_rate * dt;
ws.perf_data.filtrate_data.rates[perf] = filtrate_rate;
ws.perf_data.filtrate_data.total[perf] = filtration_particle_volume_[perf];
template<class Scalar>
void WellFilterCake<Scalar>::
applyCleaning(const WellInterfaceGeneric<Scalar>& well,
DeferredLogger& deferred_logger)
{
const auto& connections = well.wellEcl().getConnections();
const auto nperf = well.numPerfs();
for (int perf = 0; perf < nperf; ++perf) {
const auto perf_ecl_index = well.perforationData()[perf].ecl_index;
const auto& connection = connections[perf_ecl_index];
if (!connection.filterCakeActive())
continue;

const auto& filter_cake = connection.getFilterCake();
const Scalar factor = filter_cake.sf_multiplier;
if (factor == 1.0)
continue;

filter_cake.sf_multiplier = 1.0;
skin_factor_[perf] *= factor;
updateMultiplier(connection, perf);
const Scalar rw = connection.getFilterCakeRadius();
switch (filter_cake.geometry) {
case FilterCake::FilterCakeGeometry::LINEAR: {
// Previous thickness adjusted to give correct cleaning multiplier at start of time step
thickness_[perf] *= factor;
break;
}
case FilterCake::FilterCakeGeometry::RADIAL: {
Scalar rc_prev = std::sqrt(rw * rw + 2. * rw * thickness_[perf]);
// Previous thickness and rc adjusted to give correct cleaning multiplier at start of time step
rc_prev = rw*std::exp(factor*std::log(rc_prev/rw));
thickness_[perf] = (rc_prev * rc_prev - rw * rw) / (2. * rw);
break;
}
default:
const auto geometry =
FilterCake::filterCakeGeometryToString(filter_cake.geometry);
OPM_DEFLOG_THROW(std::runtime_error,
fmt::format(" Invalid filtration cake geometry type ({}) for well {}",
geometry, well.name()),
deferred_logger);
}
}
}


template<class Scalar>
void WellFilterCake<Scalar>::
updateInjFCMult(const WellInterfaceGeneric<Scalar>& well,
WellState<Scalar>& well_state,
DeferredLogger& deferred_logger)
updateSkinFactorsAndMultipliers(const WellInterfaceGeneric<Scalar>& well,
WellState<Scalar>& well_state,
const double dt,
const std::size_t water_index,
DeferredLogger& deferred_logger)
{
if (inj_fc_multiplier_.empty()) {
inj_fc_multiplier_.resize(well.numPerfs(), 1.0);
}
const auto nperf = well.numPerfs();
inj_fc_multiplier_.assign(nperf, 1.0);

assert(well.isInjector());

const auto& connections = well.wellEcl().getConnections();
auto& ws = well_state.well(well.indexOfWell());
auto& perf_data = ws.perf_data;
assert (nperf == static_cast<int>(perf_data.size()));

for (int perf = 0; perf < well.numPerfs(); ++perf) {
const auto& connection_rates = perf_data.phase_rates;
const auto conc = ws.filtrate_conc;
const std::size_t np = well_state.numPhases();

for (int perf = 0; perf < nperf; ++perf) {
const auto perf_ecl_index = well.perforationData()[perf].ecl_index;
const auto& connections = well.wellEcl().getConnections();
const auto& connection = connections[perf_ecl_index];
if (well.isInjector() && connection.filterCakeActive()) {
const auto& filter_cake = connection.getFilterCake();
const Scalar area = connection.getFilterCakeArea();
const Scalar poro = filter_cake.poro;
const Scalar perm = filter_cake.perm;
const Scalar rw = connection.getFilterCakeRadius();
const Scalar K = connection.Kh() / connection.connectionLength();
const Scalar factor = filter_cake.sf_multiplier;
// the thickness of the filtration cake
const Scalar thickness = filtration_particle_volume_[perf] / (area * (1. - poro));
auto& filtrate_data = perf_data.filtrate_data;
filtrate_data.thickness[perf] = thickness;
filtrate_data.poro[perf] = poro;
filtrate_data.perm[perf] = perm;
filtrate_data.radius[perf] = connection.getFilterCakeRadius();
filtrate_data.area_of_flow[perf] = connection.getFilterCakeArea();

Scalar skin_factor = 0.;
switch (filter_cake.geometry) {
case FilterCake::FilterCakeGeometry::LINEAR: {
skin_factor = thickness / rw * K / perm * factor;
break;
}
case FilterCake::FilterCakeGeometry::RADIAL: {
const Scalar rc = std::sqrt(rw * rw + 2. * rw * thickness);
skin_factor = K / perm * std::log(rc / rw) * factor;
break;
}
default:
const auto geometry =
FilterCake::filterCakeGeometryToString(filter_cake.geometry);
OPM_DEFLOG_THROW(std::runtime_error,
fmt::format(" Invalid filtration cake geometry type ({}) for well {}",
geometry, well.name()),
deferred_logger);
}
filtrate_data.skin_factor[perf] = skin_factor;
if (!connection.filterCakeActive())
continue;

const auto denom = connection.ctfProperties().peaceman_denom;
const auto denom2 = denom + skin_factor;
inj_fc_multiplier_[perf] = denom / denom2;
} else {
inj_fc_multiplier_[perf] = 1.0;
// not considering the production water
const Scalar water_rates = std::max(Scalar{0.}, connection_rates[perf * np + water_index]);
const Scalar filtrate_rate = water_rates * conc;
const Scalar filtrate_particle_volume = filtrate_rate * dt;
auto& filtrate_data = perf_data.filtrate_data;
filtrate_data.rates[perf] = filtrate_rate;
filtrate_data.total[perf] += filtrate_particle_volume;

const auto& filter_cake = connection.getFilterCake();
const Scalar area = connection.getFilterCakeArea();
const Scalar poro = filter_cake.poro;
const Scalar perm = filter_cake.perm;
const Scalar rw = connection.getFilterCakeRadius();
const Scalar K = connection.Kh() / connection.connectionLength();
// The thickness of the filtration cake due to particle deposition at current time step
const Scalar delta_thickness = filtrate_particle_volume / (area * (1. - poro));

filtrate_data.poro[perf] = poro;
filtrate_data.perm[perf] = perm;
filtrate_data.radius[perf] = connection.getFilterCakeRadius();
filtrate_data.area_of_flow[perf] = connection.getFilterCakeArea();

Scalar delta_skin_factor = 0.;
Scalar thickness = 0.;
switch (filter_cake.geometry) {
case FilterCake::FilterCakeGeometry::LINEAR: {
thickness = thickness_[perf] + delta_thickness;
filtrate_data.thickness[perf] = thickness;
delta_skin_factor = delta_thickness / rw * K / perm;
break;
}
case FilterCake::FilterCakeGeometry::RADIAL: {
const auto prev_thickness = thickness_[perf];
Scalar rc_prev = std::sqrt(rw * rw + 2. * rw * prev_thickness);
thickness = prev_thickness + delta_thickness;

const Scalar rc = std::sqrt(rw * rw + 2. * rw * thickness);
filtrate_data.thickness[perf] = rc - rw;
delta_skin_factor = K / perm * std::log(rc / rc_prev);
break;
}
default:
const auto geometry =
FilterCake::filterCakeGeometryToString(filter_cake.geometry);
OPM_DEFLOG_THROW(std::runtime_error,
fmt::format(" Invalid filtration cake geometry type ({}) for well {}",
geometry, well.name()),
deferred_logger);
}
skin_factor_[perf] += delta_skin_factor;
filtrate_data.skin_factor[perf] = skin_factor_[perf];
thickness_[perf] = thickness;

updateMultiplier(connection, perf);
}
}

template<class Scalar> template <class Conn>
void WellFilterCake<Scalar>::
updateMultiplier(const Conn& connection, const int perf)
{
const auto denom = connection.ctfProperties().peaceman_denom;
const auto denom2 = denom + skin_factor_[perf];
inj_fc_multiplier_[perf] = denom / denom2;
}

template class WellFilterCake<double>;

#if FLOW_INSTANTIATE_FLOAT
Expand Down
Loading