本文整理汇总了C++中opm::time::StopWatch::secsSinceLast方法的典型用法代码示例。如果您正苦于以下问题:C++ StopWatch::secsSinceLast方法的具体用法?C++ StopWatch::secsSinceLast怎么用?C++ StopWatch::secsSinceLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opm::time::StopWatch
的用法示例。
在下文中一共展示了StopWatch::secsSinceLast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newtonSolve
CollOfScalar EquelleRuntimeCUDA::newtonSolve(const ResidualFunctor& rescomp,
const CollOfScalar& u_initialguess)
{
Opm::time::StopWatch clock;
clock.start();
// Set up Newton loop.
// Define the primary variable
CollOfScalar u = CollOfScalar(u_initialguess, true);
if (verbose_ > 2) {
output("Initial u", u);
output(" newtonSolve: norm (initial u)", twoNorm(u));
}
CollOfScalar residual = rescomp(u);
if (verbose_ > 2) {
output("Initial residual", residual);
output(" newtonSolve: norm (initial residual)", twoNorm(residual));
}
int iter = 0;
// Debugging output not specified in Equelle.
if (verbose_ > 1) {
std::cout << " newtonSolve: iter = " << iter << " (max = " << max_iter_
<< "), norm(residual) = " << twoNorm(residual)
<< " (tol = " << abs_res_tol_ << ")" << std::endl;
}
CollOfScalar du;
// Execute newton loop until residual is small or we have used too many iterations.
while ( (twoNorm(residual) > abs_res_tol_) && (iter < max_iter_) ) {
if ( solver_.getSolver() == CPU ) {
du = serialSolveForUpdate(residual);
}
else {
// Solve linear equations for du, apply update.
du = solver_.solve(residual.derivative(),
residual.value(),
verbose_);
}
// du is a constant, hence, u is still a primary variable with an identity
// matrix as its derivative.
u = u - du;
// Recompute residual.
residual = rescomp(u);
if (verbose_ > 2) {
// Debugging output not specified in Equelle.
output("u", u);
output(" newtonSolve: norm(u)", twoNorm(u));
output("residual", residual);
output(" newtonSolve: norm(residual)", twoNorm(residual));
}
++iter;
// Debugging output not specified in Equelle.
if (verbose_ > 1) {
std::cout << " newtonSolve: iter = " << iter << " (max = " << max_iter_
<< "), norm(residual) = " << twoNorm(residual)
<< " (tol = " << abs_res_tol_ << ")" << std::endl;
}
}
if (verbose_ > 0) {
if (twoNorm(residual) > abs_res_tol_) {
std::cout << "Newton solver failed to converge in " << max_iter_ << " iterations" << std::endl;
} else {
std::cout << "Newton solver converged in " << iter << " iterations" << std::endl;
}
}
if (verbose_ > 1) {
std::cout << "Newton solver took: " << clock.secsSinceLast() << " seconds." << std::endl;
}
return CollOfScalar(u.value());
}
示例2: main
int main()
try
{
typedef Opm::AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef Eigen::SparseMatrix<double> S;
Opm::time::StopWatch clock;
clock.start();
const Opm::GridManager gm(3,3);//(50, 50, 10);
const UnstructuredGrid& grid = *gm.c_grid();
using namespace Opm::unit;
using namespace Opm::prefix;
// const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
// { 1000.0, 800.0 },
// { 1.0*centi*Poise, 5.0*centi*Poise },
// 0.2, 100*milli*darcy,
// grid.dimensions, grid.number_of_cells);
// const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
// { 1000.0, 1000.0 },
// { 1.0, 1.0 },
// 1.0, 1.0,
// grid.dimensions, grid.number_of_cells);
const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
{ 1000.0, 1000.0 },
{ 1.0, 30.0 },
1.0, 1.0,
grid.dimensions, grid.number_of_cells);
V htrans(grid.cell_facepos[grid.number_of_cells]);
tpfa_htrans_compute(const_cast<UnstructuredGrid*>(&grid), props.permeability(), htrans.data());
V trans_all(grid.number_of_faces);
// tpfa_trans_compute(const_cast<UnstructuredGrid*>(&grid), htrans.data(), trans_all.data());
const int nc = grid.number_of_cells;
std::vector<int> allcells(nc);
for (int i = 0; i < nc; ++i) {
allcells[i] = i;
}
std::cerr << "Opm core " << clock.secsSinceLast() << std::endl;
// Define neighbourhood-derived operator matrices.
const Opm::HelperOps ops(grid);
const int num_internal = ops.internal_faces.size();
std::cerr << "Topology matrices " << clock.secsSinceLast() << std::endl;
typedef Opm::AutoDiffBlock<double> ADB;
typedef ADB::V V;
// q
V q(nc);
q.setZero();
q[0] = 1.0;
q[nc-1] = -1.0;
// s0 - this is explicit now
typedef Eigen::Array<double, Eigen::Dynamic, 2, Eigen::RowMajor> TwoCol;
TwoCol s0(nc, 2);
s0.leftCols<1>().setZero();
s0.rightCols<1>().setOnes();
// totmob - explicit as well
TwoCol kr(nc, 2);
props.relperm(nc, s0.data(), allcells.data(), kr.data(), 0);
const V krw = kr.leftCols<1>();
const V kro = kr.rightCols<1>();
const double* mu = props.viscosity();
const V totmob = krw/mu[0] + kro/mu[1];
// Moved down here because we need total mobility.
tpfa_eff_trans_compute(const_cast<UnstructuredGrid*>(&grid), totmob.data(),
htrans.data(), trans_all.data());
// Still explicit, and no upwinding!
V mobtransf(num_internal);
for (int fi = 0; fi < num_internal; ++fi) {
mobtransf[fi] = trans_all[ops.internal_faces[fi]];
}
std::cerr << "Property arrays " << clock.secsSinceLast() << std::endl;
// Initial pressure.
V p0(nc,1);
p0.fill(200*Opm::unit::barsa);
// First actual AD usage: defining pressure variable.
const std::vector<int> bpat = { nc };
// Could actually write { nc } instead of bpat below,
// but we prefer a named variable since we will repeat it.
const ADB p = ADB::variable(0, p0, bpat);
const ADB ngradp = ops.ngrad*p;
// We want flux = totmob*trans*(p_i - p_j) for the ij-face.
const ADB flux = mobtransf*ngradp;
const ADB residual = ops.div*flux - q;
std::cerr << "Construct AD residual " << clock.secsSinceLast() << std::endl;
// It's the residual we want to be zero. We know it's linear in p,
// so we just need a single linear solve. Since we have formulated
// ourselves with a residual and jacobian we do this with a single
// Newton step (hopefully easy to extend later):
// p = p0 - J(p0) \ R(p0)
// Where R(p0) and J(p0) are contained in residual.value() and
// residual.derived()[0].
//.........这里部分代码省略.........