35#ifndef OPM_UPSCALERBASE_IMPL_HEADER
36#define OPM_UPSCALERBASE_IMPL_HEADER
47 template <
class Traits>
51 residual_tolerance_(1e-8),
53 linsolver_prolongate_factor_(1.0),
54 linsolver_verbosity_(0),
56 linsolver_smooth_steps_(1),
59 , grid_(MPI_COMM_SELF)
67 template <
class Traits>
77 template <
class Traits>
85 int bct = param.get<
int>(
"boundary_condition_type");
92 twodim_hack_ = param.getDefault(
"2d_hack", twodim_hack_);
93 residual_tolerance_ = param.getDefault(
"residual_tolerance", residual_tolerance_);
94 linsolver_verbosity_ = param.getDefault(
"linsolver_verbosity", linsolver_verbosity_);
95 linsolver_type_ = param.getDefault(
"linsolver_type", linsolver_type_);
96 linsolver_maxit_ = param.getDefault(
"linsolver_max_iterations", linsolver_maxit_);
97 linsolver_prolongate_factor_ = param.getDefault(
"linsolver_prolongate_factor", linsolver_prolongate_factor_);
98 linsolver_smooth_steps_ = param.getDefault(
"linsolver_smooth_steps", linsolver_smooth_steps_);
99 gravity_ = param.getDefault(
"gravity", gravity_);
104 Opm::ParameterGroup temp_param = param;
105 if (bctype_ == Linear || bctype_ == Periodic) {
106 if (!temp_param.has(
"use_unique_boundary_ids")) {
107 temp_param.insertParameter(
"use_unique_boundary_ids",
"true");
109 if (!temp_param.has(
"clip_z")) {
110 temp_param.insertParameter(
"clip_z",
"true");
113 if (bctype_ == Periodic) {
114 if (!temp_param.has(
"periodic_extension")) {
115 temp_param.insertParameter(
"periodic_extension",
"true");
120 ginterf_.init(grid_);
126 template <
class Traits>
130 std::cout <<
"==================== Unused parameters: ====================\n";
131 param.displayUsage();
132 std::cout <<
"================================================================\n";
138 template <
class Traits>
141 double perm_threshold,
142 double residual_tolerance,
143 int linsolver_verbosity,
147 double linsolver_prolongate_factor,
148 int linsolver_smooth_steps,
149 const double gravity)
152 residual_tolerance_ = residual_tolerance;
153 linsolver_verbosity_ = linsolver_verbosity;
154 linsolver_type_ = linsolver_type;
155 linsolver_maxit_ = linsolver_maxit;
156 linsolver_prolongate_factor_ = linsolver_prolongate_factor;
157 linsolver_smooth_steps_ = linsolver_smooth_steps;
158 twodim_hack_ = twodim_hack;
163 bool periodic_ext = (bctype_ == Periodic);
164 bool turn_normals =
false;
165 bool clip_z = (bctype_ == Linear || bctype_ == Periodic);
166 bool unique_bids = (bctype_ == Linear || bctype_ == Periodic);
167 std::string rock_list(
"no_list");
169 periodic_ext, turn_normals, clip_z, unique_bids,
170 perm_threshold, rock_list,
171 useJ<ResProp>(), 1.0, 0.0,
173 ginterf_.init(grid_);
179 template <
class Traits>
189 template <
class Traits>
193 if ((type == Periodic && bctype_ != Periodic)
194 || (type != Periodic && bctype_ == Periodic)) {
195 OPM_THROW(std::runtime_error,
"Cannot switch to or from Periodic boundary condition, "
196 "periodic must be set in init() params.");
199 if (type == Periodic || type == Linear) {
200 grid_.setUniqueBoundaryIds(
true);
202 grid_.setUniqueBoundaryIds(
false);
210 template <
class Traits>
214 res_prop_.permeabilityModifiable(cell_index) = k;
220 template <
class Traits>
225 return upscaleEffectivePerm(fluid);
231 template <
class Traits>
232 template <
class Flu
idInterface>
236 int num_cells = ginterf_.numberOfCells();
238 std::vector<double> src(num_cells, 0.0);
240 std::vector<double> sat(num_cells, 1.0);
242 Dune::FieldVector<double, 3> gravity(0.0);
243 gravity[2] = gravity_;
246 for (
int pdd = 0; pdd < Dimension; ++pdd) {
252 flow_solver_.init(ginterf_, res_prop_, gravity, bcond_);
256 bool same_matrix = (bctype_ != Fixed) && (pdd != 0);
257 flow_solver_.solve(fluid, sat, bcond_, src, residual_tolerance_,
258 linsolver_verbosity_,
259 linsolver_type_, same_matrix,
260 linsolver_maxit_, linsolver_prolongate_factor_,
261 linsolver_smooth_steps_);
262 double max_mod = flow_solver_.postProcessFluxes();
263 std::cout <<
"Max mod = " << max_mod << std::endl;
266 double Q[Dimension] = { 0 };
269 Q[pdd] = computeAverageVelocity(flow_solver_.getSolution(), pdd, pdd);
273 for (
int i = 0; i < Dimension; ++i) {
274 Q[i] = computeAverageVelocity(flow_solver_.getSolution(), i, pdd);
278 OPM_THROW(std::runtime_error,
"Unknown boundary type: " + std::to_string(bctype_));
280 double delta = computeDelta(pdd);
281 for (
int i = 0; i < Dimension; ++i) {
282 upscaled_K(i, pdd) = Q[i] * delta;
291 template <
class Traits>
292 template <
class FlowSol>
295 const int pdrop_dir)
const
297 double side1_flux = 0.0;
298 double side2_flux = 0.0;
299 double side1_area = 0.0;
300 double side2_area = 0.0;
302 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
303 for (
FaceIter f = c->facebegin(); f != c->faceend(); ++f) {
305 int canon_bid = bcond_.getCanonicalBoundaryId(f->boundaryId());
306 if ((canon_bid - 1)/2 == flow_dir) {
307 double flux = flow_solution.outflux(f);
308 double area = f->area();
309 double norm_comp = f->normal()[flow_dir];
311 if (canon_bid - 1 == 2*flow_dir) {
312 if (flow_dir == pdrop_dir && flux > 0.0) {
314 std::cerr <<
"Flow may be in wrong direction at bid: " << f->boundaryId()<<
" (canonical: "<<canon_bid
315 <<
") Magnitude: " << std::fabs(flux) << std::endl;
319 side1_flux += flux*norm_comp;
322 assert(canon_bid - 1 == 2*flow_dir + 1);
323 if (flow_dir == pdrop_dir && flux < 0.0) {
325 std::cerr <<
"Flow may be in wrong direction at bid: " << f->boundaryId()
326 <<
" Magnitude: " << std::fabs(flux) << std::endl;
330 side2_flux += flux*norm_comp;
338 return 0.5*(side1_flux/side1_area + side2_flux/side2_area);
344 template <
class Traits>
347 double side1_pos = 0.0;
348 double side2_pos = 0.0;
349 double side1_area = 0.0;
350 double side2_area = 0.0;
351 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
352 for (
FaceIter f = c->facebegin(); f != c->faceend(); ++f) {
354 int canon_bid = bcond_.getCanonicalBoundaryId(f->boundaryId());
355 if ((canon_bid - 1)/2 == flow_dir) {
356 double area = f->area();
357 double pos_comp = f->centroid()[flow_dir];
358 if (canon_bid - 1 == 2*flow_dir) {
359 side1_pos += area*pos_comp;
362 side2_pos += area*pos_comp;
370 return side2_pos/side2_area - side1_pos/side1_area;
376 template <
class Traits>
379 double total_vol = 0.0;
380 double total_pore_vol = 0.0;
381 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
382 total_vol += c->volume();
383 total_pore_vol += c->volume()*res_prop_.porosity(c->index());
385 return total_pore_vol/total_vol;
389 template <
class Traits>
392 double total_net_vol = 0.0;
393 double total_pore_vol = 0.0;
394 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
395 total_net_vol += c->volume()*res_prop_.ntg(c->index());
396 total_pore_vol += c->volume()*res_prop_.porosity(c->index())*res_prop_.ntg(c->index());
398 if (total_net_vol>0.0)
return total_pore_vol/total_net_vol;
402 template <
class Traits>
405 double total_vol = 0.0;
406 double total_net_vol = 0.0;
407 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
408 total_vol += c->volume();
409 total_net_vol += c->volume()*res_prop_.ntg(c->index());
411 return total_net_vol/total_vol;
414 template <
class Traits>
417 double total_swcr = 0.0;
418 double total_pore_vol = 0.0;
420 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
421 total_swcr += c->volume()*res_prop_.porosity(c->index())*res_prop_.ntg(c->index())*res_prop_.swcr(c->index());
422 total_pore_vol += c->volume()*res_prop_.porosity(c->index())*res_prop_.ntg(c->index());
426 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
427 total_swcr += c->volume()*res_prop_.porosity(c->index())*res_prop_.swcr(c->index());
428 total_pore_vol += c->volume()*res_prop_.porosity(c->index());
431 return total_swcr/total_pore_vol;
434 template <
class Traits>
437 double total_sowcr = 0.0;
438 double total_pore_vol = 0.0;
440 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
441 total_sowcr += c->volume()*res_prop_.porosity(c->index())*res_prop_.ntg(c->index())*res_prop_.sowcr(c->index());
442 total_pore_vol += c->volume()*res_prop_.porosity(c->index())*res_prop_.ntg(c->index());
446 for (
CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) {
447 total_sowcr += c->volume()*res_prop_.porosity(c->index())*res_prop_.sowcr(c->index());
448 total_pore_vol += c->volume()*res_prop_.porosity(c->index());
451 return total_sowcr/total_pore_vol;
Definition: GridInterfaceEuler.hpp:368
Intersection (face) iterator for solver-near grid interface.
Definition: GridInterfaceEuler.hpp:241
Definition: ReservoirPropertyTracerFluid.hpp:40
double computeDelta(const int flow_dir) const
Definition: UpscalerBase_impl.hpp:345
permtensor_t upscaleSinglePhase()
Definition: UpscalerBase_impl.hpp:222
void setPermeability(const int cell_index, const permtensor_t &k)
Definition: UpscalerBase_impl.hpp:212
double computeAverageVelocity(const FlowSol &flow_solution, const int flow_dir, const int pdrop_dir) const
Definition: UpscalerBase_impl.hpp:293
double upscalePorosity() const
Definition: UpscalerBase_impl.hpp:377
ResProp::MutablePermTensor permtensor_t
A type for the upscaled permeability.
Definition: UpscalerBase.hpp:66
const GridType & grid() const
Access the grid.
Definition: UpscalerBase_impl.hpp:181
double upscaleNTG() const
Definition: UpscalerBase_impl.hpp:403
virtual void initFinal(const Opm::ParameterGroup ¶m)
Definition: UpscalerBase_impl.hpp:127
BoundaryConditionType
Definition: UpscalerBase.hpp:68
permtensor_t upscaleEffectivePerm(const FluidInterface &fluid)
Definition: UpscalerBase_impl.hpp:234
Dune::CpGrid GridType
Definition: UpscalerBase.hpp:60
double upscaleSOWCR(const bool NTG) const
Definition: UpscalerBase_impl.hpp:435
virtual void initImpl(const Opm::ParameterGroup ¶m)
Definition: UpscalerBase_impl.hpp:78
void init(const Opm::ParameterGroup ¶m)
Initializes the upscaler from parameters.
Definition: UpscalerBase_impl.hpp:68
void setBoundaryConditionType(BoundaryConditionType type)
Definition: UpscalerBase_impl.hpp:191
double upscaleNetPorosity() const
Definition: UpscalerBase_impl.hpp:390
double upscaleSWCR(const bool NTG) const
Definition: UpscalerBase_impl.hpp:415
UpscalerBase()
Default constructor.
Definition: UpscalerBase_impl.hpp:48
if(loadcase > -1)
Definition: elasticity_upscale_impl.hpp:448
auto deck
Definition: elasticity_upscale_impl.hpp:590
Definition: ImplicitAssembly.hpp:43
void setupGridAndPropsEclipse(const Opm::Deck &deck, bool periodic_extension, bool turn_normals, bool clip_z, bool unique_bids, double perm_threshold, const std::string &rock_list, bool use_jfunction_scaling, double sigma, double theta, Dune::CpGrid &grid, ResProp< 3 > &res_prop)
Definition: setupGridAndProps.hpp:152
void setupUpscalingConditions(const GridInterface &g, int bct, int pddir, double pdrop, double bdy_sat, bool twodim_hack, BCs &bcs)
Definition: setupBoundaryConditions.hpp:99
void setupGridAndProps(const Opm::ParameterGroup ¶m, Dune::CpGrid &grid, ResProp< 3 > &res_prop)
Definition: setupGridAndProps.hpp:71