mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Minor refactoring of domain ordering for NLDD.
This commit is contained in:
parent
6f04c31c7c
commit
6945b927ec
@ -696,11 +696,14 @@ private:
|
|||||||
const auto& solution = ebosSimulator.model().solution(0);
|
const auto& solution = ebosSimulator.model().solution(0);
|
||||||
|
|
||||||
std::vector<int> domain_order(domains_.size());
|
std::vector<int> domain_order(domains_.size());
|
||||||
|
std::iota(domain_order.begin(), domain_order.end(), 0);
|
||||||
|
|
||||||
switch (model_.param().local_solve_approach_) {
|
if (model_.param().local_solve_approach_ == DomainSolveApproach::Jacobi) {
|
||||||
case DomainSolveApproach::GaussSeidel: {
|
// Do nothing, 0..n-1 order is fine.
|
||||||
|
return domain_order;
|
||||||
|
} else if (model_.param().local_solve_approach_ == DomainSolveApproach::GaussSeidel) {
|
||||||
// Calculate the measure used to order the domains.
|
// Calculate the measure used to order the domains.
|
||||||
std::vector<std::pair<double, int>> measure_per_domain(domains_.size());
|
std::vector<double> measure_per_domain(domains_.size());
|
||||||
switch (model_.param().local_domain_ordering_) {
|
switch (model_.param().local_domain_ordering_) {
|
||||||
case DomainOrderingMeasure::AveragePressure: {
|
case DomainOrderingMeasure::AveragePressure: {
|
||||||
// Use average pressures to order domains.
|
// Use average pressures to order domains.
|
||||||
@ -710,19 +713,18 @@ private:
|
|||||||
press_sum += solution[c][Indices::pressureSwitchIdx];
|
press_sum += solution[c][Indices::pressureSwitchIdx];
|
||||||
}
|
}
|
||||||
const double avgpress = press_sum / domain.cells.size();
|
const double avgpress = press_sum / domain.cells.size();
|
||||||
measure_per_domain[domain.index] = std::make_pair(avgpress, domain.index);
|
measure_per_domain[domain.index] = avgpress;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DomainOrderingMeasure::MaxPressure: {
|
case DomainOrderingMeasure::MaxPressure: {
|
||||||
// Use max pressures to order domains.
|
// Use max pressures to order domains.
|
||||||
std::vector<std::pair<double, int>> maxpress_per_domain(domains_.size());
|
|
||||||
for (const auto& domain : domains_) {
|
for (const auto& domain : domains_) {
|
||||||
double maxpress = 0.0;
|
double maxpress = 0.0;
|
||||||
for (const int c : domain.cells) {
|
for (const int c : domain.cells) {
|
||||||
maxpress = std::max(maxpress, solution[c][Indices::pressureSwitchIdx]);
|
maxpress = std::max(maxpress, solution[c][Indices::pressureSwitchIdx]);
|
||||||
}
|
}
|
||||||
measure_per_domain[domain.index] = std::make_pair(maxpress, domain.index);
|
measure_per_domain[domain.index] = maxpress;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -730,7 +732,6 @@ private:
|
|||||||
// Use maximum residual to order domains.
|
// Use maximum residual to order domains.
|
||||||
const auto& residual = ebosSimulator.model().linearizer().residual();
|
const auto& residual = ebosSimulator.model().linearizer().residual();
|
||||||
const int num_vars = residual[0].size();
|
const int num_vars = residual[0].size();
|
||||||
std::vector<std::pair<double, int>> maxres_per_domain(domains_.size());
|
|
||||||
for (const auto& domain : domains_) {
|
for (const auto& domain : domains_) {
|
||||||
double maxres = 0.0;
|
double maxres = 0.0;
|
||||||
for (const int c : domain.cells) {
|
for (const int c : domain.cells) {
|
||||||
@ -738,32 +739,20 @@ private:
|
|||||||
maxres = std::max(maxres, std::fabs(residual[c][ii]));
|
maxres = std::max(maxres, std::fabs(residual[c][ii]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
measure_per_domain[domain.index] = std::make_pair(maxres, domain.index);
|
measure_per_domain[domain.index] = maxres;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // end of switch (model_.param().local_domain_ordering_)
|
} // end of switch (model_.param().local_domain_ordering_)
|
||||||
|
|
||||||
|
|
||||||
// Sort by largest measure, keeping index order if equal.
|
// Sort by largest measure, keeping index order if equal.
|
||||||
std::stable_sort(measure_per_domain.begin(), measure_per_domain.end(),
|
const auto& m = measure_per_domain;
|
||||||
[](const auto& m1, const auto& m2){ return m1.first > m2.first; });
|
std::stable_sort(domain_order.begin(), domain_order.end(),
|
||||||
|
[&m](const int i1, const int i2){ return m[i1] > m[i2]; });
|
||||||
// Assign domain order.
|
return domain_order;
|
||||||
for (std::size_t ii = 0; ii < domains_.size(); ++ii) {
|
} else {
|
||||||
domain_order[ii] = measure_per_domain[ii].second;
|
throw std::logic_error("Domain solve approach must be Jacobi or Gauss-Seidel");
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
} // end of case DomainSolveApproach::GaussSeidel
|
|
||||||
|
|
||||||
case DomainSolveApproach::Jacobi:
|
|
||||||
default:
|
|
||||||
std::iota(domain_order.begin(), domain_order.end(), 0);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain_order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GlobalEqVector>
|
template<class GlobalEqVector>
|
||||||
|
Loading…
Reference in New Issue
Block a user