mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #1762 from totto82/refactorBC
Refactor the boundary conditions code
This commit is contained in:
commit
888050613c
@ -363,7 +363,7 @@ protected:
|
|||||||
{
|
{
|
||||||
const auto& problem = elemCtx.problem();
|
const auto& problem = elemCtx.problem();
|
||||||
|
|
||||||
bool enableBoundaryMassFlux = problem.hasFreeBoundaryConditions();
|
bool enableBoundaryMassFlux = problem.nonTrivialBoundaryConditions();
|
||||||
if (!enableBoundaryMassFlux)
|
if (!enableBoundaryMassFlux)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1363,7 +1363,7 @@ public:
|
|||||||
values.setThermalFlow(context, spaceIdx, timeIdx, initialFluidStates_[globalDofIdx]);
|
values.setThermalFlow(context, spaceIdx, timeIdx, initialFluidStates_[globalDofIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFreeBoundaryConditions()) {
|
if (nonTrivialBoundaryConditions()) {
|
||||||
unsigned indexInInside = context.intersection(spaceIdx).indexInInside();
|
unsigned indexInInside = context.intersection(spaceIdx).indexInInside();
|
||||||
unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
|
unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
|
||||||
unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
|
unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
|
||||||
@ -1618,8 +1618,8 @@ public:
|
|||||||
return (oilVaporizationControl.getType() == Opm::OilVaporizationEnum::VAPPARS);
|
return (oilVaporizationControl.getType() == Opm::OilVaporizationEnum::VAPPARS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasFreeBoundaryConditions() const
|
bool nonTrivialBoundaryConditions() const
|
||||||
{ return hasFreeBoundaryConditions_; }
|
{ return nonTrivialBoundaryConditions_; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Propose the size of the next time step to the simulator.
|
* \brief Propose the size of the next time step to the simulator.
|
||||||
@ -2549,18 +2549,11 @@ private:
|
|||||||
|
|
||||||
void readBoundaryConditions_()
|
void readBoundaryConditions_()
|
||||||
{
|
{
|
||||||
hasFreeBoundaryConditions_ = false;
|
nonTrivialBoundaryConditions_ = false;
|
||||||
readBoundaryConditionKeyword_("FREEBCX", freebcX_);
|
|
||||||
readBoundaryConditionKeyword_("FREEBCX-", freebcXMinus_);
|
|
||||||
readBoundaryConditionKeyword_("FREEBCY", freebcY_);
|
|
||||||
readBoundaryConditionKeyword_("FREEBCY-", freebcYMinus_);
|
|
||||||
readBoundaryConditionKeyword_("FREEBCZ", freebcZ_);
|
|
||||||
readBoundaryConditionKeyword_("FREEBCZ-", freebcZMinus_);
|
|
||||||
|
|
||||||
const auto& vanguard = this->simulator().vanguard();
|
const auto& vanguard = this->simulator().vanguard();
|
||||||
|
|
||||||
if (vanguard.deck().hasKeyword("BCRATE")) {
|
if (vanguard.deck().hasKeyword("BC")) {
|
||||||
hasFreeBoundaryConditions_ = 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);
|
||||||
@ -2574,14 +2567,21 @@ private:
|
|||||||
massratebcY_.resize(numElems, 0.0);
|
massratebcY_.resize(numElems, 0.0);
|
||||||
massratebcZMinus_.resize(numElems, 0.0);
|
massratebcZMinus_.resize(numElems, 0.0);
|
||||||
massratebcZ_.resize(numElems, 0.0);
|
massratebcZ_.resize(numElems, 0.0);
|
||||||
|
freebcX_.resize(numElems, false);
|
||||||
|
freebcXMinus_.resize(numElems, false);
|
||||||
|
freebcY_.resize(numElems, false);
|
||||||
|
freebcYMinus_.resize(numElems, false);
|
||||||
|
freebcZ_.resize(numElems, false);
|
||||||
|
freebcZMinus_.resize(numElems, false);
|
||||||
|
|
||||||
const auto& ratebcs = vanguard.deck().getKeywordList("BCRATE");
|
const auto& bcs = vanguard.deck().getKeywordList("BC");
|
||||||
for (size_t listIdx = 0; listIdx < ratebcs.size(); ++listIdx) {
|
for (size_t listIdx = 0; listIdx < bcs.size(); ++listIdx) {
|
||||||
const auto& ratebc = *ratebcs[listIdx];
|
const auto& bc = *bcs[listIdx];
|
||||||
|
|
||||||
for (size_t record = 0; record < ratebc.size(); ++record) {
|
for (size_t record = 0; record < bc.size(); ++record) {
|
||||||
|
|
||||||
std::string compName = ratebc.getRecord(record).getItem("COMPONENT").getTrimmedString(0);
|
std::string type = bc.getRecord(record).getItem("TYPE").getTrimmedString(0);
|
||||||
|
std::string compName = bc.getRecord(record).getItem("COMPONENT").getTrimmedString(0);
|
||||||
int compIdx = -999;
|
int compIdx = -999;
|
||||||
|
|
||||||
if (compName == "OIL")
|
if (compName == "OIL")
|
||||||
@ -2593,77 +2593,95 @@ private:
|
|||||||
else if (compName == "SOLVENT")
|
else if (compName == "SOLVENT")
|
||||||
{
|
{
|
||||||
if (!enableSolvent)
|
if (!enableSolvent)
|
||||||
throw std::logic_error("solvent is disabled and you're trying to add solvent to BCRATE");
|
throw std::logic_error("solvent is disabled and you're trying to add solvent to BC");
|
||||||
|
|
||||||
compIdx = Indices::solventSaturationIdx;
|
compIdx = Indices::solventSaturationIdx;
|
||||||
}
|
}
|
||||||
else if (compName == "POLYMER")
|
else if (compName == "POLYMER")
|
||||||
{
|
{
|
||||||
if (!enablePolymer)
|
if (!enablePolymer)
|
||||||
throw std::logic_error("polymer is disabled and you're trying to add polymer to BCRATE");
|
throw std::logic_error("polymer is disabled and you're trying to add polymer to BC");
|
||||||
|
|
||||||
compIdx = Indices::polymerConcentrationIdx;
|
compIdx = Indices::polymerConcentrationIdx;
|
||||||
}
|
}
|
||||||
|
else if (compName == "NONE")
|
||||||
|
{
|
||||||
|
if ( type == "RATE")
|
||||||
|
throw std::logic_error("you need to specify the component when RATE type is set in BC");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw std::logic_error("invalid component name for BCRATE");
|
throw std::logic_error("invalid component name for BC");
|
||||||
assert(compIdx >= 0);
|
|
||||||
|
|
||||||
std::string direction = ratebc.getRecord(record).getItem("DIRECTION").getTrimmedString(0);
|
int i1 = bc.getRecord(record).getItem("I1").template get< int >(0) - 1;
|
||||||
std::vector<RateVector>* data = 0;
|
int i2 = bc.getRecord(record).getItem("I2").template get< int >(0) - 1;
|
||||||
if (direction == "X-")
|
int j1 = bc.getRecord(record).getItem("J1").template get< int >(0) - 1;
|
||||||
data = &massratebcXMinus_;
|
int j2 = bc.getRecord(record).getItem("J2").template get< int >(0) - 1;
|
||||||
else if (direction == "X")
|
int k1 = bc.getRecord(record).getItem("K1").template get< int >(0) - 1;
|
||||||
data = &massratebcX_;
|
int k2 = bc.getRecord(record).getItem("K2").template get< int >(0) - 1;
|
||||||
else if (direction == "Y-")
|
std::string direction = bc.getRecord(record).getItem("DIRECTION").getTrimmedString(0);
|
||||||
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 BCRATE");
|
|
||||||
|
|
||||||
int i1 = ratebc.getRecord(record).getItem("I1").template get< int >(0) - 1;
|
if (type == "RATE") {
|
||||||
int i2 = ratebc.getRecord(record).getItem("I2").template get< int >(0) - 1;
|
assert(compIdx >= 0);
|
||||||
int j1 = ratebc.getRecord(record).getItem("J1").template get< int >(0) - 1;
|
std::vector<RateVector>* data = 0;
|
||||||
int j2 = ratebc.getRecord(record).getItem("J2").template get< int >(0) - 1;
|
if (direction == "X-")
|
||||||
int k1 = ratebc.getRecord(record).getItem("K1").template get< int >(0) - 1;
|
data = &massratebcXMinus_;
|
||||||
int k2 = ratebc.getRecord(record).getItem("K2").template get< int >(0) - 1;
|
else if (direction == "X")
|
||||||
const Evaluation rate = ratebc.getRecord(record).getItem("RATE").getSIDouble(0);
|
data = &massratebcX_;
|
||||||
for (int i = i1; i <= i2; ++i) {
|
else if (direction == "Y-")
|
||||||
for (int j = j1; j <= j2; ++j) {
|
data = &massratebcYMinus_;
|
||||||
for (int k = k1; k <= k2; ++k) {
|
else if (direction == "Y")
|
||||||
std::array<int, 3> tmp = {i,j,k};
|
data = &massratebcY_;
|
||||||
size_t elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
|
else if (direction == "Z-")
|
||||||
(*data)[elemIdx][compIdx] = rate;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw std::logic_error("invalid type for BC. Use FREE or RATE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readBoundaryConditionKeyword_(const std::string& name, std::vector<bool>& compressedData)
|
|
||||||
{
|
|
||||||
const auto& eclProps = this->simulator().vanguard().eclState().get3DProperties();
|
|
||||||
const auto& vanguard = this->simulator().vanguard();
|
|
||||||
|
|
||||||
unsigned numElems = vanguard.gridView().size(/*codim=*/0);
|
|
||||||
compressedData.resize(numElems, false);
|
|
||||||
|
|
||||||
if (eclProps.hasDeckDoubleGridProperty(name)) {
|
|
||||||
const std::vector<double>& data = eclProps.getDoubleGridProperty(name).getData();
|
|
||||||
for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx) {
|
|
||||||
unsigned cartElemIdx = vanguard.cartesianIndex(elemIdx);
|
|
||||||
compressedData[elemIdx] = (data[cartElemIdx] > 0);
|
|
||||||
}
|
|
||||||
hasFreeBoundaryConditions_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this method applies the runtime constraints specified via the deck and/or command
|
// this method applies the runtime constraints specified via the deck and/or command
|
||||||
// line parameters for the size of the next time step size.
|
// line parameters for the size of the next time step size.
|
||||||
Scalar limitNextTimeStepSize_(Scalar dtNext) const
|
Scalar limitNextTimeStepSize_(Scalar dtNext) const
|
||||||
@ -2754,7 +2772,7 @@ private:
|
|||||||
PffGridVector<GridView, Stencil, PffDofData_, DofMapper> pffDofData_;
|
PffGridVector<GridView, Stencil, PffDofData_, DofMapper> pffDofData_;
|
||||||
TracerModel tracerModel_;
|
TracerModel tracerModel_;
|
||||||
|
|
||||||
bool hasFreeBoundaryConditions_;
|
bool nonTrivialBoundaryConditions_;
|
||||||
std::vector<bool> freebcX_;
|
std::vector<bool> freebcX_;
|
||||||
std::vector<bool> freebcXMinus_;
|
std::vector<bool> freebcXMinus_;
|
||||||
std::vector<bool> freebcY_;
|
std::vector<bool> freebcY_;
|
||||||
|
Loading…
Reference in New Issue
Block a user