makding the StandardWell and WellInterface templated

with the template parameter TypeTag.
This commit is contained in:
Kai Bao 2017-06-19 14:49:49 +02:00
parent 182bf315f3
commit 1a4ceeec66
7 changed files with 103 additions and 65 deletions

View File

@ -49,8 +49,6 @@ list (APPEND MAIN_SOURCE_FILES
opm/autodiff/VFPInjProperties.cpp opm/autodiff/VFPInjProperties.cpp
opm/autodiff/WellMultiSegment.cpp opm/autodiff/WellMultiSegment.cpp
opm/autodiff/MultisegmentWells.cpp opm/autodiff/MultisegmentWells.cpp
opm/autodiff/WellInterface.cpp
opm/autodiff/StandardWell.cpp
opm/autodiff/MissingFeatures.cpp opm/autodiff/MissingFeatures.cpp
opm/polymer/PolymerState.cpp opm/polymer/PolymerState.cpp
opm/polymer/PolymerBlackoilState.cpp opm/polymer/PolymerBlackoilState.cpp

View File

@ -37,13 +37,15 @@
namespace Opm namespace Opm
{ {
class StandardWell: public WellInterface template<typename TypeTag>
class StandardWell: public WellInterface<TypeTag>
{ {
public: public:
using WellInterface::Simulator; // using WellInterface<TypeTag>::Simulator;
using WellInterface::WellState; // using WellInterface<TypeTag>::WellState;
typedef typename WellInterface<TypeTag>::Simulator Simulator;
typedef typename WellInterface<TypeTag>::WellState WellState;
// the positions of the primary variables for StandardWell // the positions of the primary variables for StandardWell
// there are three primary variables, the second and the third ones are F_w and F_g // there are three primary variables, the second and the third ones are F_w and F_g
// the first one can be total rate (G_t) or bhp, based on the control // the first one can be total rate (G_t) or bhp, based on the control
@ -107,7 +109,22 @@ namespace Opm
EvalWell wellSurfaceVolumeFraction(const int phase) const; EvalWell wellSurfaceVolumeFraction(const int phase) const;
using WellInterface<TypeTag>::phaseUsage;
using WellInterface<TypeTag>::active;
using WellInterface<TypeTag>::numberOfPerforations;
using WellInterface<TypeTag>::indexOfWell;
using WellInterface<TypeTag>::name;
using WellInterface<TypeTag>::wellType;
using WellInterface<TypeTag>::wellControls;
using WellInterface<TypeTag>::compFrac;
using WellInterface<TypeTag>::numberOfPhases;
using WellInterface<TypeTag>::perfDepth;
protected: protected:
using WellInterface<TypeTag>::vfp_properties_;
using WellInterface<TypeTag>::gravity_;
// densities of the fluid in each perforation // densities of the fluid in each perforation
std::vector<double> perf_densities_; std::vector<double> perf_densities_;
// pressure drop between different perforations // pressure drop between different perforations
@ -136,4 +153,6 @@ namespace Opm
} }
#include "StandardWell_impl.hpp"
#endif // OPM_STANDARDWELL_HEADER_INCLUDED #endif // OPM_STANDARDWELL_HEADER_INCLUDED

View File

@ -18,19 +18,15 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>. along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "config.h"
#include <opm/autodiff/StandardWell.hpp>
namespace Opm namespace Opm
{ {
StandardWell:: template<typename TypeTag>
StandardWell<TypeTag>::
StandardWell(const Well* well, const int time_step, const Wells* wells) StandardWell(const Well* well, const int time_step, const Wells* wells)
: WellInterface(well, time_step, wells) : WellInterface<TypeTag>(well, time_step, wells)
, perf_densities_(number_of_perforations_) , perf_densities_(numberOfPerforations())
, perf_pressure_diffs_(number_of_perforations_) , perf_pressure_diffs_(numberOfPerforations())
, well_variables_(numWellEq) // the number of the primary variables , well_variables_(numWellEq) // the number of the primary variables
{ {
dune_B_.setBuildMode( Mat::row_wise ); dune_B_.setBuildMode( Mat::row_wise );
@ -42,8 +38,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<double>& const std::vector<double>&
StandardWell:: StandardWell<TypeTag>::
perfDensities() const perfDensities() const
{ {
return perf_densities_; return perf_densities_;
@ -53,8 +50,9 @@ namespace Opm
template<typename TypeTag>
std::vector<double>& std::vector<double>&
StandardWell:: StandardWell<TypeTag>::
perfDensities() perfDensities()
{ {
return perf_densities_; return perf_densities_;
@ -64,8 +62,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<double>& const std::vector<double>&
StandardWell:: StandardWell<TypeTag>::
perfPressureDiffs() const perfPressureDiffs() const
{ {
return perf_pressure_diffs_; return perf_pressure_diffs_;
@ -75,8 +74,9 @@ namespace Opm
template<typename TypeTag>
std::vector<double>& std::vector<double>&
StandardWell:: StandardWell<TypeTag>::
perfPressureDiffs() perfPressureDiffs()
{ {
return perf_pressure_diffs_; return perf_pressure_diffs_;
@ -86,8 +86,9 @@ namespace Opm
template<typename TypeTag>
void void
StandardWell:: StandardWell<TypeTag>::
assembleWellEq(Simulator& ebos_simulator, assembleWellEq(Simulator& ebos_simulator,
const double dt, const double dt,
WellState& well_state, WellState& well_state,
@ -99,10 +100,11 @@ namespace Opm
void StandardWell:: template<typename TypeTag>
void StandardWell<TypeTag>::
setWellVariables(const WellState& well_state) setWellVariables(const WellState& well_state)
{ {
const int np = number_of_phases_; const int np = numberOfPhases();
const int nw = well_state.bhp().size(); const int nw = well_state.bhp().size();
// TODO: it should be the number of primary variables // TODO: it should be the number of primary variables
// TODO: this is from the old version of StandardWellsDense, it is a coincidence, 3 phases and 3 primary variables // TODO: this is from the old version of StandardWellsDense, it is a coincidence, 3 phases and 3 primary variables
@ -110,7 +112,7 @@ namespace Opm
// TODO: the following code has to be rewritten later for correctness purpose. // TODO: the following code has to be rewritten later for correctness purpose.
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
well_variables_[phase] = 0.0; well_variables_[phase] = 0.0;
well_variables_[phase].setValue(well_state.wellSolutions()[index_of_well_ + nw * phase]); well_variables_[phase].setValue(well_state.wellSolutions()[indexOfWell() + nw * phase]);
well_variables_[phase].setDerivative(numEq + phase, 1.0); well_variables_[phase].setDerivative(numEq + phase, 1.0);
} }
} }
@ -119,11 +121,12 @@ namespace Opm
StandardWell::EvalWell template<typename TypeTag>
StandardWell:: typename StandardWell<TypeTag>::EvalWell
StandardWell<TypeTag>::
getBhp() const getBhp() const
{ {
const WellControls* wc = well_controls_; const WellControls* wc = wellControls();
if (well_controls_get_current_type(wc) == BHP) { if (well_controls_get_current_type(wc) == BHP) {
EvalWell bhp = 0.0; EvalWell bhp = 0.0;
const double target_rate = well_controls_get_current_target(wc); const double target_rate = well_controls_get_current_target(wc);
@ -162,7 +165,7 @@ namespace Opm
// pick the density in the top layer // pick the density in the top layer
const double rho = perf_densities_[0]; const double rho = perf_densities_[0];
// TODO: not sure whether it is always correct // TODO: not sure whether it is always correct
const double well_ref_depth = perf_depth_[0]; const double well_ref_depth = perfDepth()[0];
const double dp = wellhelpers::computeHydrostaticCorrection(well_ref_depth, vfp_ref_depth, rho, gravity_); const double dp = wellhelpers::computeHydrostaticCorrection(well_ref_depth, vfp_ref_depth, rho, gravity_);
bhp -= dp; bhp -= dp;
return bhp; return bhp;
@ -175,19 +178,20 @@ namespace Opm
StandardWell::EvalWell template<typename TypeTag>
StandardWell:: typename StandardWell<TypeTag>::EvalWell
StandardWell<TypeTag>::
getQs(const int phase) const getQs(const int phase) const
{ {
EvalWell qs = 0.0; EvalWell qs = 0.0;
const WellControls* wc = well_controls_; const WellControls* wc = wellControls();
const int np = number_of_phases_; const int np = numberOfPhases();
const double target_rate = well_controls_get_current_target(wc); const double target_rate = well_controls_get_current_target(wc);
// TODO: we need to introduce numComponents() for StandardWell // TODO: we need to introduce numComponents() for StandardWell
// assert(phase < numComponents()); // assert(phase < numComponents());
const auto pu = phase_usage_; const auto pu = phaseUsage();
// TODO: the formulation for the injectors decides it only work with single phase // TODO: the formulation for the injectors decides it only work with single phase
// surface rate injection control. Improvement will be required. // surface rate injection control. Improvement will be required.
@ -315,13 +319,14 @@ namespace Opm
StandardWell::EvalWell template<typename TypeTag>
StandardWell:: typename StandardWell<TypeTag>::EvalWell
StandardWell<TypeTag>::
wellVolumeFractionScaled(const int phase) const wellVolumeFractionScaled(const int phase) const
{ {
// TODO: we should be able to set the g for the well based on the control type // TODO: we should be able to set the g for the well based on the control type
// instead of using explicit code for g all the times // instead of using explicit code for g all the times
const WellControls* wc = well_controls_; const WellControls* wc = wellControls();
if (well_controls_get_current_type(wc) == RESERVOIR_RATE) { if (well_controls_get_current_type(wc) == RESERVOIR_RATE) {
const double* distr = well_controls_get_current_distr(wc); const double* distr = well_controls_get_current_distr(wc);
if (distr[phase] > 0.) { if (distr[phase] > 0.) {
@ -340,8 +345,9 @@ namespace Opm
StandardWell::EvalWell template<typename TypeTag>
StandardWell:: typename StandardWell<TypeTag>::EvalWell
StandardWell<TypeTag>::
wellVolumeFraction(const int phase) const wellVolumeFraction(const int phase) const
{ {
if (phase == Water) { if (phase == Water) {
@ -368,12 +374,13 @@ namespace Opm
StandardWell::EvalWell template<typename TypeTag>
StandardWell:: typename StandardWell<TypeTag>::EvalWell
StandardWell<TypeTag>::
wellSurfaceVolumeFraction(const int phase) const wellSurfaceVolumeFraction(const int phase) const
{ {
EvalWell sum_volume_fraction_scaled = 0.; EvalWell sum_volume_fraction_scaled = 0.;
const int np = number_of_phases_; const int np = numberOfPhases();
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
sum_volume_fraction_scaled += wellVolumeFractionScaled(p); sum_volume_fraction_scaled += wellVolumeFractionScaled(p);
} }

View File

@ -303,9 +303,10 @@ enum WellVariablePositions {
// the name is just temporary // the name is just temporary
// later, might make share_ptr const later. // later, might make share_ptr const later.
// TODO: forget why make it share_ptr instead of unique_ptr // TODO: forget why make it share_ptr instead of unique_ptr
std::vector<std::shared_ptr<WellInterface> > well_container_; std::vector<std::shared_ptr<WellInterface<TypeTag> > > well_container_;
std::vector<std::shared_ptr<WellInterface> > // TODO: forgot why returning a vector here
std::vector<std::shared_ptr<WellInterface<TypeTag> > >
createWellContainer(const std::vector<const Well*>& wells_ecl, createWellContainer(const std::vector<const Well*>& wells_ecl,
const Wells* wells_arg, const Wells* wells_arg,
const int time_step); const int time_step);

View File

@ -148,13 +148,13 @@ namespace Opm {
template<typename TypeTag> template<typename TypeTag>
std::vector<std::shared_ptr<WellInterface> > std::vector<std::shared_ptr<WellInterface<TypeTag> > >
StandardWellsDense<TypeTag>:: StandardWellsDense<TypeTag>::
createWellContainer(const std::vector<const Well*>& wells_ecl, createWellContainer(const std::vector<const Well*>& wells_ecl,
const Wells* wells_arg, const Wells* wells_arg,
const int time_step) const int time_step)
{ {
std::vector<std::shared_ptr<WellInterface> > wells_container; std::vector<std::shared_ptr<WellInterface<TypeTag> > > wells_container;
// There might be no wells in the process // There might be no wells in the process
if (localWellsActive()) { if (localWellsActive()) {
@ -192,7 +192,7 @@ namespace Opm {
// Basically, we are handling all the wells as StandardWell for the moment // Basically, we are handling all the wells as StandardWell for the moment
// TODO: to be changed when we begin introducing MultisegmentWell // TODO: to be changed when we begin introducing MultisegmentWell
wells_container.push_back(std::make_shared<StandardWell>(well_ecl, time_step, wells_arg) ); wells_container.push_back(std::make_shared<StandardWell<TypeTag> >(well_ecl, time_step, wells_arg) );
} }
} }
@ -2228,7 +2228,8 @@ namespace Opm {
typename StandardWellsDense<TypeTag>::EvalWell typename StandardWellsDense<TypeTag>::EvalWell
StandardWellsDense<TypeTag>:: StandardWellsDense<TypeTag>::
getBhp(const int wellIdx) const { getBhp(const int wellIdx) const {
return well_container_(wellIdx)->getBhp(); // return well_container_(wellIdx)->getBhp();
return 0.0; // TODO: for debugging
} }

View File

@ -45,6 +45,7 @@ namespace Opm
class SimulatorFullyImplicitBlackoilEbos; class SimulatorFullyImplicitBlackoilEbos;
template<typename TypeTag>
class WellInterface class WellInterface
{ {
public: public:
@ -161,4 +162,6 @@ namespace Opm
} }
#include "WellInterface_impl.hpp"
#endif // OPM_WELLINTERFACE_HEADER_INCLUDED #endif // OPM_WELLINTERFACE_HEADER_INCLUDED

View File

@ -18,17 +18,13 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>. along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "config.h"
#include <opm/autodiff/WellInterface.hpp>
namespace Opm namespace Opm
{ {
WellInterface:: template<typename TypeTag>
WellInterface<TypeTag>::
WellInterface(const Well* well, const int time_step, const Wells* wells) WellInterface(const Well* well, const int time_step, const Wells* wells)
{ {
@ -94,8 +90,9 @@ namespace Opm
template<typename TypeTag>
void void
WellInterface:: WellInterface<TypeTag>::
init(const PhaseUsage* phase_usage_arg, init(const PhaseUsage* phase_usage_arg,
const std::vector<bool>* active_arg, const std::vector<bool>* active_arg,
const VFPProperties* vfp_properties_arg, const VFPProperties* vfp_properties_arg,
@ -111,8 +108,9 @@ namespace Opm
template<typename TypeTag>
const std::string& const std::string&
WellInterface:: WellInterface<TypeTag>::
name() const name() const
{ {
return name_; return name_;
@ -122,8 +120,9 @@ namespace Opm
template<typename TypeTag>
int int
WellInterface:: WellInterface<TypeTag>::
indexOfWell() const indexOfWell() const
{ {
return index_of_well_; return index_of_well_;
@ -133,8 +132,9 @@ namespace Opm
template<typename TypeTag>
WellType WellType
WellInterface:: WellInterface<TypeTag>::
wellType() const wellType() const
{ {
return well_type_; return well_type_;
@ -144,8 +144,9 @@ namespace Opm
template<typename TypeTag>
int int
WellInterface:: WellInterface<TypeTag>::
numberOfPhases() const numberOfPhases() const
{ {
return number_of_phases_; return number_of_phases_;
@ -154,8 +155,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<double>& const std::vector<double>&
WellInterface:: WellInterface<TypeTag>::
compFrac() const compFrac() const
{ {
return comp_frac_; return comp_frac_;
@ -165,8 +167,9 @@ namespace Opm
template<typename TypeTag>
WellControls* WellControls*
WellInterface:: WellInterface<TypeTag>::
wellControls() const wellControls() const
{ {
return well_controls_; return well_controls_;
@ -176,8 +179,9 @@ namespace Opm
template<typename TypeTag>
int int
WellInterface:: WellInterface<TypeTag>::
numberOfPerforations() const numberOfPerforations() const
{ {
return number_of_perforations_; return number_of_perforations_;
@ -187,8 +191,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<double>& const std::vector<double>&
WellInterface:: WellInterface<TypeTag>::
wellIndex() const wellIndex() const
{ {
return well_index_; return well_index_;
@ -198,8 +203,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<double>& const std::vector<double>&
WellInterface:: WellInterface<TypeTag>::
perfDepth() const perfDepth() const
{ {
return perf_depth_; return perf_depth_;
@ -209,8 +215,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<int>& const std::vector<int>&
WellInterface:: WellInterface<TypeTag>::
wellCells() const wellCells() const
{ {
return well_cell_; return well_cell_;
@ -220,8 +227,9 @@ namespace Opm
template<typename TypeTag>
const std::vector<bool>& const std::vector<bool>&
WellInterface:: WellInterface<TypeTag>::
active() const active() const
{ {
assert(active_); assert(active_);
@ -233,8 +241,9 @@ namespace Opm
template<typename TypeTag>
const PhaseUsage& const PhaseUsage&
WellInterface:: WellInterface<TypeTag>::
phaseUsage() const phaseUsage() const
{ {
assert(phase_usage_); assert(phase_usage_);