Use BCConfig when setting up boundary conditions

This commit is contained in:
Joakim Hove 2020-01-25 09:40:50 +01:00
parent c9ef6ac843
commit bc718bafc8

View File

@ -2996,13 +2996,13 @@ private:
nonTrivialBoundaryConditions_ = false; nonTrivialBoundaryConditions_ = false;
const auto& simulator = this->simulator(); const auto& simulator = this->simulator();
const auto& vanguard = simulator.vanguard(); const auto& vanguard = simulator.vanguard();
const auto& bcconfig = vanguard.eclState().getSimulationConfig().bcconfig();
if (vanguard.deck().hasKeyword("BC")) { if (bcconfig.size() > 0) {
nonTrivialBoundaryConditions_ = true; nonTrivialBoundaryConditions_ = true;
size_t numCartDof = vanguard.cartesianSize(); size_t numCartDof = vanguard.cartesianSize();
unsigned numElems = vanguard.gridView().size(/*codim=*/0); unsigned numElems = vanguard.gridView().size(/*codim=*/0);
std::vector<int> cartesianToCompressedElemIdx(numCartDof); std::vector<int> cartesianToCompressedElemIdx(numCartDof, -1);
for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx) for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx)
cartesianToCompressedElemIdx[vanguard.cartesianIndex(elemIdx)] = elemIdx; cartesianToCompressedElemIdx[vanguard.cartesianIndex(elemIdx)] = elemIdx;
@ -3020,115 +3020,114 @@ private:
freebcZ_.resize(numElems, false); freebcZ_.resize(numElems, false);
freebcZMinus_.resize(numElems, false); freebcZMinus_.resize(numElems, false);
const auto& bcs = vanguard.deck().getKeywordList("BC"); for (const auto& bcface : bcconfig) {
for (size_t listIdx = 0; listIdx < bcs.size(); ++listIdx) { const auto& type = bcface.bctype;
const auto& bc = *bcs[listIdx]; if (type == BCType::RATE) {
int compIdx;
for (size_t record = 0; record < bc.size(); ++record) { switch (bcface.component) {
case BCComponent::OIL:
std::string type = bc.getRecord(record).getItem("TYPE").getTrimmedString(0);
std::string compName = bc.getRecord(record).getItem("COMPONENT").getTrimmedString(0);
int compIdx = -999;
if (compName == "OIL")
compIdx = oilCompIdx; compIdx = oilCompIdx;
else if (compName == "GAS") break;
case BCComponent::GAS:
compIdx = gasCompIdx; compIdx = gasCompIdx;
else if (compName == "WATER") break;
case BCComponent::WATER:
compIdx = waterCompIdx; compIdx = waterCompIdx;
else if (compName == "SOLVENT") break;
{ case BCComponent::SOLVENT:
if (!enableSolvent) if (!enableSolvent)
throw std::logic_error("solvent is disabled and you're trying to add solvent to BC"); throw std::logic_error("solvent is disabled and you're trying to add solvent to BC");
compIdx = Indices::solventSaturationIdx; compIdx = Indices::solventSaturationIdx;
} break;
else if (compName == "POLYMER") case BCComponent::POLYMER:
{
if (!enablePolymer) if (!enablePolymer)
throw std::logic_error("polymer is disabled and you're trying to add polymer to BC"); throw std::logic_error("polymer is disabled and you're trying to add polymer to BC");
compIdx = Indices::polymerConcentrationIdx; compIdx = Indices::polymerConcentrationIdx;
} break;
else if (compName == "NONE") case BCComponent::NONE:
{ if (type == BCType::RATE)
if ( type == "RATE")
throw std::logic_error("you need to specify the component when RATE type is set in BC"); throw std::logic_error("you need to specify the component when RATE type is set in BC");
break;
} }
else
throw std::logic_error("invalid component name for BC");
int i1 = bc.getRecord(record).getItem("I1").template get< int >(0) - 1; std::vector<RateVector>* data = nullptr;
int i2 = bc.getRecord(record).getItem("I2").template get< int >(0) - 1; switch (bcface.dir) {
int j1 = bc.getRecord(record).getItem("J1").template get< int >(0) - 1; case FaceDir::XMinus:
int j2 = bc.getRecord(record).getItem("J2").template get< int >(0) - 1; data = &massratebcXMinus_;
int k1 = bc.getRecord(record).getItem("K1").template get< int >(0) - 1; break;
int k2 = bc.getRecord(record).getItem("K2").template get< int >(0) - 1; case FaceDir::XPlus:
std::string direction = bc.getRecord(record).getItem("DIRECTION").getTrimmedString(0); data = &massratebcX_;
break;
case FaceDir::YMinus:
data = &massratebcYMinus_;
break;
case FaceDir::YPlus:
data = &massratebcY_;
break;
case FaceDir::ZMinus:
data = &massratebcZMinus_;
break;
case FaceDir::ZPlus:
data = &massratebcZ_;
break;
}
if (type == "RATE") { const Evaluation rate = bcface.rate;
assert(compIdx >= 0); for (int i = bcface.i1; i <= bcface.i2; ++i) {
std::vector<RateVector>* data = 0; for (int j = bcface.j1; j <= bcface.j2; ++j) {
if (direction == "X-") for (int k = bcface.k1; k <= bcface.k2; ++k) {
data = &massratebcXMinus_; std::array<int, 3> tmp = {i,j,k};
else if (direction == "X") auto elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
data = &massratebcX_; if (elemIdx >= 0)
else if (direction == "Y-")
data = &massratebcYMinus_;
else if (direction == "Y")
data = &massratebcY_;
else if (direction == "Z-")
data = &massratebcZMinus_;
else if (direction == "Z")
data = &massratebcZ_;
else
throw std::logic_error("invalid direction for BC");
const Evaluation rate = bc.getRecord(record).getItem("RATE").getSIDouble(0);
for (int i = i1; i <= i2; ++i) {
for (int j = j1; j <= j2; ++j) {
for (int k = k1; k <= k2; ++k) {
std::array<int, 3> tmp = {i,j,k};
size_t elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
(*data)[elemIdx][compIdx] = rate; (*data)[elemIdx][compIdx] = rate;
}
} }
} }
} else if (type == "FREE") {
std::vector<bool>* data = 0;
if (direction == "X-")
data = &freebcXMinus_;
else if (direction == "X")
data = &freebcX_;
else if (direction == "Y-")
data = &freebcYMinus_;
else if (direction == "Y")
data = &freebcY_;
else if (direction == "Z-")
data = &freebcZMinus_;
else if (direction == "Z")
data = &freebcZ_;
else
throw std::logic_error("invalid direction for BC");
for (int i = i1; i <= i2; ++i) {
for (int j = j1; j <= j2; ++j) {
for (int k = k1; k <= k2; ++k) {
std::array<int, 3> tmp = {i,j,k};
size_t elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
(*data)[elemIdx] = true;
}
}
}
// TODO: either the real initial solution needs to be computed or read from the restart file
const auto& eclState = simulator.vanguard().eclState();
const auto& initconfig = eclState.getInitConfig();
if (initconfig.restartRequested()) {
throw std::logic_error("restart is not compatible with using free boundary conditions");
}
} else {
throw std::logic_error("invalid type for BC. Use FREE or RATE");
} }
} else if (type == BCType::FREE) {
std::vector<bool>* data = nullptr;
switch (bcface.dir) {
case FaceDir::XMinus:
data = &freebcXMinus_;
break;
case FaceDir::XPlus:
data = &freebcX_;
break;
case FaceDir::YMinus:
data = &freebcYMinus_;
break;
case FaceDir::YPlus:
data = &freebcY_;
break;
case FaceDir::ZMinus:
data = &freebcZMinus_;
break;
case FaceDir::ZPlus:
data = &freebcZ_;
break;
}
for (int i = bcface.i1; i <= bcface.i2; ++i) {
for (int j = bcface.j1; j <= bcface.j2; ++j) {
for (int k = bcface.k1; k <= bcface.k2; ++k) {
std::array<int, 3> tmp = {i,j,k};
auto elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
if (elemIdx >= 0)
(*data)[elemIdx] = true;
}
}
}
// TODO: either the real initial solution needs to be computed or read from the restart file
const auto& eclState = simulator.vanguard().eclState();
const auto& initconfig = eclState.getInitConfig();
if (initconfig.restartRequested()) {
throw std::logic_error("restart is not compatible with using free boundary conditions");
}
} else {
throw std::logic_error("invalid type for BC. Use FREE or RATE");
} }
} }
} }