int main(int argc, char *argv[]){ double *collideField = NULL; double *streamField = NULL; int *flagField = NULL; int xlength = 0; double tau = 0.0; double velocityWall[3] = {0}; int timesteps = 0; int timestepsPerPlotting = 0; int t = 0; int readParamError = 0; const char *szProblem = "data_CFD_Assignment_02"; readParamError = readParameters(&xlength, &tau, velocityWall, ×teps, ×tepsPerPlotting, argc, argv); if(readParamError != 0) { printf("Please provide only one argument to the program; the path to the input file."); return -1; } /* Initialize pointers according to the D3Q19 discretization scheme */ collideField = malloc(19*(xlength+2)*(xlength+2)*(xlength+2)*sizeof(*collideField)); streamField = malloc(19*(xlength+2)*(xlength+2)*(xlength+2)*sizeof(*streamField)); flagField = malloc((xlength+2)*(xlength+2)*(xlength+2)*sizeof(*flagField)); initialiseFields(collideField, streamField, flagField, xlength); for(t = 0; t < timesteps; t++) { double *swap = NULL; doStreaming(collideField, streamField, flagField, xlength); swap = collideField; collideField = streamField; streamField = swap; doCollision(collideField, flagField, &tau, xlength); treatBoundary(collideField, flagField, velocityWall, xlength); if (t % timestepsPerPlotting == 0) { writeVtkOutput(collideField, flagField, szProblem, t, xlength); } } /* Free heap memory */ free(collideField); free(streamField); free(flagField); return 0; }
/// @brief /// @todo Doc me! void run() { // Initial saturation. std::vector<double> saturation(this->init_saturation_); std::vector<double> saturation_old(saturation); // Gravity. // Dune::FieldVector<double, 3> gravity(0.0); // gravity[2] = -Dune::unit::gravity; // Compute flow field. if (this->gravity_.two_norm() > 0.0) { MESSAGE("Warning: Gravity not handled by flow solver."); } // Solve some steps. for (int i = 0; i < this->simulation_steps_; ++i) { std::cout << "\n\n================ Simulation step number " << i << " ===============" << std::endl; // Flow. this->flow_solver_.solve(this->res_prop_, saturation, this->bcond_, this->injection_rates_psolver_, this->residual_tolerance_, this->linsolver_verbosity_, this->linsolver_type_); // if (i == 0) { // flow_solver_.printSystem("linsys_dump_mimetic"); // } // Transport. this->transport_solver_.transportSolve(saturation, this->stepsize_, this->gravity_, this->flow_solver_.getSolution(), this->injection_rates_); // Output. writeVtkOutput(this->ginterf_, this->res_prop_, this->flow_solver_.getSolution(), saturation, "testsolution-" + boost::lexical_cast<std::string>(i)); writeField(saturation, "saturation-" + boost::lexical_cast<std::string>(i)); // Comparing old to new. int num_cells = saturation.size(); double maxdiff = 0.0; for (int i = 0; i < num_cells; ++i) { maxdiff = std::max(maxdiff, std::fabs(saturation[i] - saturation_old[i])); } std::cout << "Maximum saturation change: " << maxdiff << std::endl; // Copy to old. saturation_old = saturation; } }
inline std::pair<typename SteadyStateUpscaler<Traits>::permtensor_t, typename SteadyStateUpscaler<Traits>::permtensor_t> SteadyStateUpscaler<Traits>:: upscaleSteadyState(const int flow_direction, const std::vector<double>& initial_saturation, const double boundary_saturation, const double pressure_drop, const permtensor_t& upscaled_perm) { static int count = 0; ++count; int num_cells = this->ginterf_.numberOfCells(); // No source or sink. std::vector<double> src(num_cells, 0.0); Opm::SparseVector<double> injection(num_cells); // Gravity. Dune::FieldVector<double, 3> gravity(0.0); if (use_gravity_) { gravity[2] = Opm::unit::gravity; } if (gravity.two_norm() > 0.0) { OPM_MESSAGE("Warning: Gravity is experimental for flow solver."); } // Set up initial saturation profile. std::vector<double> saturation = initial_saturation; // Set up boundary conditions. setupUpscalingConditions(this->ginterf_, this->bctype_, flow_direction, pressure_drop, boundary_saturation, this->twodim_hack_, this->bcond_); // Set up solvers. if (flow_direction == 0) { this->flow_solver_.init(this->ginterf_, this->res_prop_, gravity, this->bcond_); } transport_solver_.initObj(this->ginterf_, this->res_prop_, this->bcond_); // Run pressure solver. this->flow_solver_.solve(this->res_prop_, saturation, this->bcond_, src, this->residual_tolerance_, this->linsolver_verbosity_, this->linsolver_type_, false, this->linsolver_maxit_, this->linsolver_prolongate_factor_, this->linsolver_smooth_steps_); double max_mod = this->flow_solver_.postProcessFluxes(); std::cout << "Max mod = " << max_mod << std::endl; // Do a run till steady state. For now, we just do some pressure and transport steps... std::vector<double> saturation_old = saturation; for (int iter = 0; iter < simulation_steps_; ++iter) { // Run transport solver. transport_solver_.transportSolve(saturation, stepsize_, gravity, this->flow_solver_.getSolution(), injection); // Run pressure solver. this->flow_solver_.solve(this->res_prop_, saturation, this->bcond_, src, this->residual_tolerance_, this->linsolver_verbosity_, this->linsolver_type_, false, this->linsolver_maxit_, this->linsolver_prolongate_factor_, this->linsolver_smooth_steps_); max_mod = this->flow_solver_.postProcessFluxes(); std::cout << "Max mod = " << max_mod << std::endl; // Print in-out flows if requested. if (print_inoutflows_) { std::pair<double, double> w_io, o_io; computeInOutFlows(w_io, o_io, this->flow_solver_.getSolution(), saturation); std::cout << "Pressure step " << iter << "\nWater flow [in] " << w_io.first << " [out] " << w_io.second << "\nOil flow [in] " << o_io.first << " [out] " << o_io.second << std::endl; } // Output. if (output_vtk_) { writeVtkOutput(this->ginterf_, this->res_prop_, this->flow_solver_.getSolution(), saturation, std::string("output-steadystate") + '-' + boost::lexical_cast<std::string>(count) + '-' + boost::lexical_cast<std::string>(flow_direction) + '-' + boost::lexical_cast<std::string>(iter)); } // Comparing old to new. int num_cells = saturation.size(); double maxdiff = 0.0; for (int i = 0; i < num_cells; ++i) { maxdiff = std::max(maxdiff, std::fabs(saturation[i] - saturation_old[i])); } #ifdef VERBOSE std::cout << "Maximum saturation change: " << maxdiff << std::endl; #endif if (maxdiff < sat_change_threshold_) { #ifdef VERBOSE std::cout << "Maximum saturation change is under steady state threshold." << std::endl; #endif break; } // Copy to old. saturation_old = saturation; } // Compute phase mobilities. // First: compute maximal mobilities. typedef typename Super::ResProp::Mobility Mob; Mob m; double m1max = 0; double m2max = 0; for (int c = 0; c < num_cells; ++c) { this->res_prop_.phaseMobility(0, c, saturation[c], m.mob); m1max = maxMobility(m1max, m.mob); this->res_prop_.phaseMobility(1, c, saturation[c], m.mob); m2max = maxMobility(m2max, m.mob); } // Second: set thresholds. const double mob1_abs_thres = relperm_threshold_ / this->res_prop_.viscosityFirstPhase(); const double mob1_rel_thres = m1max / maximum_mobility_contrast_; const double mob1_threshold = std::max(mob1_abs_thres, mob1_rel_thres); const double mob2_abs_thres = relperm_threshold_ / this->res_prop_.viscositySecondPhase(); const double mob2_rel_thres = m2max / maximum_mobility_contrast_; const double mob2_threshold = std::max(mob2_abs_thres, mob2_rel_thres); // Third: extract and threshold. std::vector<Mob> mob1(num_cells); std::vector<Mob> mob2(num_cells); for (int c = 0; c < num_cells; ++c) { this->res_prop_.phaseMobility(0, c, saturation[c], mob1[c].mob); thresholdMobility(mob1[c].mob, mob1_threshold); this->res_prop_.phaseMobility(1, c, saturation[c], mob2[c].mob); thresholdMobility(mob2[c].mob, mob2_threshold); } // Compute upscaled relperm for each phase. ReservoirPropertyFixedMobility<Mob> fluid_first(mob1); permtensor_t eff_Kw = Super::upscaleEffectivePerm(fluid_first); ReservoirPropertyFixedMobility<Mob> fluid_second(mob2); permtensor_t eff_Ko = Super::upscaleEffectivePerm(fluid_second); // Set the steady state saturation fields for eventual outside access. last_saturation_state_.swap(saturation); // Compute the (anisotropic) upscaled mobilities. // eff_Kw := lambda_w*K // => lambda_w = eff_Kw*inv(K); permtensor_t lambda_w(matprod(eff_Kw, inverse3x3(upscaled_perm))); permtensor_t lambda_o(matprod(eff_Ko, inverse3x3(upscaled_perm))); // Compute (anisotropic) upscaled relative permeabilities. // lambda = k_r/mu permtensor_t k_rw(lambda_w); k_rw *= this->res_prop_.viscosityFirstPhase(); permtensor_t k_ro(lambda_o); k_ro *= this->res_prop_.viscositySecondPhase(); return std::make_pair(k_rw, k_ro); }