本文整理汇总了C++中SolutionPtr::energyErrorTotal方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::energyErrorTotal方法的具体用法?C++ SolutionPtr::energyErrorTotal怎么用?C++ SolutionPtr::energyErrorTotal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::energyErrorTotal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
gmgSolver->setAztecOutput(AztecOutputLevel);
gmgSolver->setUseConjugateGradient(true);
gmgSolver->gmgOperator()->setSmootherType(GMGOperator::IFPACK_ADDITIVE_SCHWARZ);
gmgSolver->gmgOperator()->setSmootherOverlap(smootherOverlap);
fineSolver = Teuchos::rcp( gmgSolver );
}
else
{
fineSolver = coarseSolver;
}
// if (rank==0) cout << "experimentally starting by solving with MUMPS on the fine mesh.\n";
// solution->solve( Teuchos::rcp( new MumpsSolver) );
solution->solve(fineSolver);
#ifdef HAVE_EPETRAEXT_HDF5
ostringstream dir_name;
dir_name << "poissonCavityFlow_k" << k;
HDF5Exporter exporter(mesh,dir_name.str());
exporter.exportSolution(solution,varFactory,0);
#endif
#ifdef HAVE_AMESOS_MUMPS
if (useMumps) coarseSolver = Teuchos::rcp( new MumpsSolver(512, true) );
#endif
solution->reportTimings();
if (useGMGSolver) gmgSolver->gmgOperator()->reportTimings();
for (int refIndex=0; refIndex < refCount; refIndex++)
{
double energyError = solution->energyErrorTotal();
GlobalIndexType numFluxDofs = mesh->numFluxDofs();
if (rank==0)
{
cout << "Before refinement " << refIndex << ", energy error = " << energyError;
cout << " (using " << numFluxDofs << " trace degrees of freedom)." << endl;
}
bool printToConsole = printRefinementDetails && (rank==0);
refinementStrategy.refine(printToConsole);
if (useStaticCondensation)
{
CondensedDofInterpreter* condensedDofInterpreter = dynamic_cast<CondensedDofInterpreter*>(solution->getDofInterpreter().get());
if (condensedDofInterpreter != NULL)
{
condensedDofInterpreter->reinitialize();
}
}
GlobalIndexType fineDofs = mesh->globalDofCount();
GlobalIndexType coarseDofs = k0Mesh->globalDofCount();
if (rank==0)
{
cout << "After refinement, coarse mesh has " << k0Mesh->numActiveElements() << " elements and " << coarseDofs << " dofs.\n";
cout << " Fine mesh has " << mesh->numActiveElements() << " elements and " << fineDofs << " dofs.\n";
}
if (!use3D)
{
ostringstream fineMeshLocation, coarseMeshLocation;
fineMeshLocation << "poissonFineMesh_k" << k << "_ref" << refIndex;
GnuPlotUtil::writeComputationalMeshSkeleton(fineMeshLocation.str(), mesh, true); // true: label cells
coarseMeshLocation << "poissonCoarseMesh_k" << k << "_ref" << refIndex;
示例2: main
//.........这里部分代码省略.........
// }
for (int refIndex=loadRef; refIndex <= numRefs; refIndex++)
{
double l2Update = 1e10;
int iterCount = 0;
solverTime->start(true);
Teuchos::RCP<GMGSolver> gmgSolver;
if (solverChoice[0] == 'G')
{
// gmgSolver = Teuchos::rcp( new GMGSolver(solutionUpdate, k0Mesh, maxLinearIterations, solverTolerance, Solver::getDirectSolver(true), useStaticCondensation));
bool reuseFactorization = true;
SolverPtr coarseSolver = Solver::getDirectSolver(reuseFactorization);
gmgSolver = Teuchos::rcp(new GMGSolver(solutionUpdate, meshesCoarseToFine, cgMaxIterations, cgTol, multigridStrategy, coarseSolver, useCondensedSolve));
gmgSolver->setUseConjugateGradient(useConjugateGradient);
int azOutput = 20; // print residual every 20 CG iterations
gmgSolver->setAztecOutput(azOutput);
gmgSolver->gmgOperator()->setNarrateOnRankZero(logFineOperator,"finest GMGOperator");
// gmgSolver->setAztecOutput(azOutput);
// if (solverChoice == "GMG-Direct")
// gmgSolver->gmgOperator()->setSchwarzFactorizationType(GMGOperator::Direct);
// if (solverChoice == "GMG-ILU")
// gmgSolver->gmgOperator()->setSchwarzFactorizationType(GMGOperator::ILU);
// if (solverChoice == "GMG-IC")
// gmgSolver->gmgOperator()->setSchwarzFactorizationType(GMGOperator::IC);
}
while (l2Update > nonlinearTolerance && iterCount < maxNonlinearIterations)
{
if (solverChoice[0] == 'G')
solutionUpdate->solve(gmgSolver);
else
solutionUpdate->condensedSolve(solvers[solverChoice]);
// Compute L2 norm of update
double u1L2Update = solutionUpdate->L2NormOfSolutionGlobal(form->u(1)->ID());
double u2L2Update = solutionUpdate->L2NormOfSolutionGlobal(form->u(2)->ID());
l2Update = sqrt(u1L2Update*u1L2Update + u2L2Update*u2L2Update);
if (commRank == 0)
cout << "Nonlinear Update:\t " << l2Update << endl;
form->updateSolution();
iterCount++;
}
double solveTime = solverTime->stop();
double energyError = solutionUpdate->energyErrorTotal();
double l2Error = 0;
if (computeL2Error)
{
l2Error = problem->computeL2Error(form, solutionBackground);
}
if (commRank == 0)
{
cout << "Refinement: " << refIndex
<< " \tElements: " << mesh->numActiveElements()
<< " \tDOFs: " << mesh->numGlobalDofs()
<< " \tEnergy Error: " << energyError
<< " \tL2 Error: " << l2Error
<< " \tSolve Time: " << solveTime
<< " \tTotal Time: " << totalTimer->totalElapsedTime(true)
// << " \tIteration Count: " << iterationCount
<< endl;
dataFile << refIndex
<< " " << mesh->numActiveElements()
<< " " << mesh->numGlobalDofs()
<< " " << energyError
<< " " << l2Error
<< " " << solveTime
<< " " << totalTimer->totalElapsedTime(true)
// << " " << iterationCount
<< endl;
}
if (exportSolution)
exporter->exportSolution(solutionBackground, refIndex);
if (saveSolution)
{
ostringstream saveFile;
saveFile << saveFilePrefix << "_ref" << refIndex;
form->save(saveFile.str());
}
if (refIndex != numRefs)
{
// k0Mesh = Teuchos::rcp( new Mesh (mesh->getTopology()->deepCopy(), form->bf(), 1, delta_p) );
// meshesCoarseToFine.push_back(k0Mesh);
refStrategy->refine();
meshesCoarseToFine.push_back(mesh);
}
}
dataFile.close();
}
double totalTime = totalTimer->stop();
if (commRank == 0)
cout << "Total time = " << totalTime << endl;
return 0;
}
示例3: main
//.........这里部分代码省略.........
streamIP->addTerm(v_s);
streamIP->addTerm(v_s->div());
SolutionPtr streamSolution = Teuchos::rcp( new Solution( streamMesh, streamBC, streamRHS, streamIP ) );
if (enforceLocalConservation)
{
FunctionPtr zero = Function::zero();
solution->lagrangeConstraints()->addConstraint(u1hat->times_normal_x() + u2hat->times_normal_y()==zero);
solnIncrement->lagrangeConstraints()->addConstraint(u1hat->times_normal_x() + u2hat->times_normal_y()==zero);
}
if (true)
{
FunctionPtr u1_incr = Function::solution(u1, solnIncrement);
FunctionPtr u2_incr = Function::solution(u2, solnIncrement);
FunctionPtr sigma11_incr = Function::solution(sigma11, solnIncrement);
FunctionPtr sigma12_incr = Function::solution(sigma12, solnIncrement);
FunctionPtr sigma21_incr = Function::solution(sigma21, solnIncrement);
FunctionPtr sigma22_incr = Function::solution(sigma22, solnIncrement);
FunctionPtr p_incr = Function::solution(p, solnIncrement);
FunctionPtr l2_incr = u1_incr * u1_incr + u2_incr * u2_incr + p_incr * p_incr
+ sigma11_incr * sigma11_incr + sigma12_incr * sigma12_incr
+ sigma21_incr * sigma21_incr + sigma22_incr * sigma22_incr;
double energyThreshold = 0.20;
Teuchos::RCP< RefinementStrategy > refinementStrategy = Teuchos::rcp( new RefinementStrategy( solnIncrement, energyThreshold ));
for (int i=0; i<ReValues.size(); i++)
{
double Re = ReValues[i];
Re_param->setValue(Re);
if (rank==0) cout << "Solving with Re = " << Re << ":\n";
double energyErrorTotal;
do
{
double incr_norm;
do
{
problem.iterate(useLineSearch);
incr_norm = sqrt(l2_incr->integrate(problem.mesh()));
if (rank==0)
{
cout << "\x1B[2K"; // Erase the entire current line.
cout << "\x1B[0E"; // Move to the beginning of the current line.
cout << "Iteration: " << problem.iterationCount() << "; L^2(incr) = " << incr_norm;
flush(cout);
}
}
while ((incr_norm > minL2Increment ) && (problem.iterationCount() < maxIters));
if (rank==0) cout << endl;
problem.setIterationCount(1); // 1 means reuse background flow (which we must, given that we want continuation in Re...)
energyErrorTotal = solnIncrement->energyErrorTotal(); //solution->energyErrorTotal();
if (energyErrorTotal > energyErrorGoal)
{
refinementStrategy->refine(false);
}
if (rank==0)
{
cout << "Energy error: " << energyErrorTotal << endl;
}
}
while (energyErrorTotal > energyErrorGoal);
}
}
示例4: main
//.........这里部分代码省略.........
VarPtr tau2 = vf->testVar("tau2", HDIV);
VarPtr q = vf->testVar("q", HGRAD);
BFPtr bf = Teuchos::rcp( new BF(vf) );
bf->addTerm(1./mu*sigma1, tau1);
bf->addTerm(1./mu*sigma2, tau2);
bf->addTerm(u1, tau1->div());
bf->addTerm(u2, tau2->div());
bf->addTerm(-u1hat, tau1->dot_normal());
bf->addTerm(-u2hat, tau2->dot_normal());
bf->addTerm(sigma1, v1->grad());
bf->addTerm(sigma2, v2->grad());
bf->addTerm(-p, v1->dx());
bf->addTerm(-p, v2->dy());
bf->addTerm(t1c, v1);
bf->addTerm(t2c, v2);
bf->addTerm(mu*permInv*u1, v1);
bf->addTerm(mu*permInv*u2, v2);
bf->addTerm(-u1, q->dx());
bf->addTerm(-u2, q->dy());
bf->addTerm(u1hat, q->times_normal_x());
bf->addTerm(u2hat, q->times_normal_y());
RHSPtr rhs = RHS::rhs();
BCPtr bc = BC::bc();
SpatialFilterPtr y_equals_one = SpatialFilter::matchingY(1.0);
SpatialFilterPtr y_equals_zero = SpatialFilter::matchingY(0);
SpatialFilterPtr x_equals_one = SpatialFilter::matchingX(1.0);
SpatialFilterPtr x_equals_zero = SpatialFilter::matchingX(0.0);
bc->addDirichlet(u1hat, y_equals_zero, u1_exact);
bc->addDirichlet(u2hat, y_equals_zero, u2_exact);
bc->addDirichlet(u1hat, x_equals_zero, u1_exact);
bc->addDirichlet(u2hat, x_equals_zero, u2_exact);
bc->addDirichlet(u1hat, y_equals_one, u1_exact);
bc->addDirichlet(u2hat, y_equals_one, u2_exact);
bc->addDirichlet(u1hat, x_equals_one, u1_exact);
bc->addDirichlet(u2hat, x_equals_one, u2_exact);
bc->addZeroMeanConstraint(p);
MeshPtr mesh = MeshFactory::quadMesh(bf, k+1, delta_k, 1, 1, 4, 4);
map<string, IPPtr> brinkmanIPs;
brinkmanIPs["Graph"] = bf->graphNorm();
brinkmanIPs["Decoupled"] = Teuchos::rcp(new IP);
brinkmanIPs["Decoupled"]->addTerm(tau1);
brinkmanIPs["Decoupled"]->addTerm(tau2);
brinkmanIPs["Decoupled"]->addTerm(tau1->div());
brinkmanIPs["Decoupled"]->addTerm(tau2->div());
brinkmanIPs["Decoupled"]->addTerm(permInv*v1);
brinkmanIPs["Decoupled"]->addTerm(permInv*v2);
brinkmanIPs["Decoupled"]->addTerm(v1->grad());
brinkmanIPs["Decoupled"]->addTerm(v2->grad());
brinkmanIPs["Decoupled"]->addTerm(q);
brinkmanIPs["Decoupled"]->addTerm(q->grad());
// brinkmanIPs["CoupledRobust"] = Teuchos::rcp(new IP);
// brinkmanIPs["CoupledRobust"]->addTerm(tau->div()-beta*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(Function<double>::min(one/Function<double>::h(),Function<double>::constant(1./sqrt(epsilon)))*tau);
// brinkmanIPs["CoupledRobust"]->addTerm(sqrt(epsilon)*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(beta*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(Function<double>::min(sqrt(epsilon)*one/Function<double>::h(),one)*v);
IPPtr ip = brinkmanIPs[norm];
SolutionPtr soln = TSolution<double>::solution(mesh, bc, rhs, ip);
double threshold = 0.20;
RefinementStrategy refStrategy(soln, threshold);
ostringstream refName;
refName << "brinkman";
HDF5Exporter exporter(mesh,refName.str());
for (int refIndex=0; refIndex <= numRefs; refIndex++)
{
soln->solve(false);
double energyError = soln->energyErrorTotal();
if (commRank == 0)
{
// if (refIndex > 0)
// refStrategy.printRefinementStatistics(refIndex-1);
cout << "Refinement:\t " << refIndex << " \tElements:\t " << mesh->numActiveElements()
<< " \tDOFs:\t " << mesh->numGlobalDofs() << " \tEnergy Error:\t " << energyError << endl;
}
exporter.exportSolution(soln, refIndex);
if (refIndex != numRefs)
refStrategy.refine();
}
return 0;
}
示例5: main
//.........这里部分代码省略.........
// FunctionPtr u_spacetime = Function::solution(u, soln);
// ostringstream dir_name;
// dir_name << "spacetime_slice_convectingCone_k" << k;
// MeshTools::timeSliceExport(dir_name.str(), mesh, u_spacetime, frameTimes[frameOrdinal], "u_slice");
//
// cout << "Exported frame " << frameOrdinal << ", t=" << frameTimes[frameOrdinal] << endl;
// frameOrdinal++;
// }
// }
do
{
soln->solve(solver);
soln->reportTimings();
#ifdef HAVE_EPETRAEXT_HDF5
ostringstream dir_name;
dir_name << "spacetime_convectingCone_k" << k << "_t" << timeSlab;
HDF5Exporter exporter(soln->mesh(),dir_name.str());
exporter.exportSolution(soln, varFactory);
if (rank==0) cout << "Exported HDF solution for time slab to directory " << dir_name.str() << endl;
// string u_name = "u_spacetime";
// exporter.exportFunction(u_spacetime, u_name);
ostringstream file_name;
file_name << dir_name.str();
bool saveSolutionAndMeshForThisSlab = ((timeSlab + 1) % checkPointFrequency == 0); // +1 so that first output is nth, not first
if (saveSolutionAndMeshForThisSlab)
{
dir_name << ".soln";
soln->saveToHDF5(dir_name.str());
if (rank==0) cout << endl << "wrote " << dir_name.str() << endl;
file_name << ".mesh";
soln->mesh()->saveToHDF5(file_name.str());
}
#endif
FunctionPtr u_soln = Function::solution(u, soln);
double solnNorm = u_soln->l2norm(mesh);
double energyError = soln->energyErrorTotal();
relativeEnergyError = energyError / solnNorm;
if (rank==0)
{
cout << "Relative energy error for refinement " << refNumber++ << ": " << relativeEnergyError << endl;
}
if ((relativeEnergyError > refinementTolerance) && (refNumber < maxRefinements))
{
refinementStrategy->refine();
if (rank==0)
{
cout << "After refinement, mesh has " << mesh->getTopology()->activeCellCount() << " active (leaf) cells " << "and " << mesh->globalDofCount() << " degrees of freedom.\n";
}
}
}
while ((relativeEnergyError > refinementTolerance) && (refNumber < maxRefinements));
double t_slab_final = (timeSlab+1) * timeLengthPerSlab;
int frameOrdinal = lastFrameOutputted + 1;
vector<double> timesForSlab;
while (frameTimes[frameOrdinal] < t_slab_final)
{
double t = frameTimes[frameOrdinal];
if (rank==0) cout << "exporting t=" << t << " on slab " << timeSlab << endl;
FunctionPtr sliceFunction = MeshTools::timeSliceFunction(mesh, cellMap, u_spacetime, t);
sliceExporter.exportFunction(sliceFunction, "u_slice", t);
lastFrameOutputted = frameOrdinal++;
}
// set up next mesh/solution:
FunctionPtr q_prev = Function::solution(qHat, soln);
// cout << "Error in setup of q_prev: simple solution doesn't know about the map from the previous time slab to the current one. (TODO: fix this.)\n";
double tn = (timeSlab+1) * timeLengthPerSlab;
origin[2] = tn;
mesh = MeshFactory::rectilinearMesh(bf, dimensions, elementCounts, H1Order, delta_k, origin);
FunctionPtr q_transfer = Teuchos::rcp( new MeshTransferFunction(-q_prev, soln->mesh(), mesh, tn) ); // negate because the normals go in opposite directions
bc = BC::bc();
bc->addDirichlet(qHat, inflowFilter, Function::zero()); // zero BCs enforced at the inflow boundary.
bc->addDirichlet(qHat, SpatialFilter::matchingZ(tn), q_transfer);
// IMPORTANT: now that we are ready to step to next soln, nullify BC. If we do not do this, then we have an RCP chain
// that extends back to the first time slab, effectively a memory leak.
soln->setBC(BC::bc());
soln = Solution::solution(mesh, bc, RHS::rhs(), ip);
soln->setUseCondensedSolve(useCondensedSolve);
}
return 0;
}
示例6: main
//.........这里部分代码省略.........
elementCounts.push_back(numXElems);
}
MeshPtr mesh = MeshFactory::rectilinearMesh(form.bf(), dimensions, elementCounts, k+1, delta_k, x0);
MeshPtr k0Mesh = Teuchos::rcp( new Mesh (mesh->getTopology()->deepCopy(), form.bf(), 1, delta_k) );
mesh->registerObserver(k0Mesh);
// Set up solution
SolutionPtr soln = Solution::solution(form.bf(), mesh, bc, rhs, form.ip(norm));
double threshold = 0.20;
RefinementStrategy refStrategy(soln, threshold);
ostringstream refName;
refName << "confusion" << spaceDim << "D_" << norm << "_" << epsilon << "_k" << k << "_" << solverChoice;
// HDF5Exporter exporter(mesh,refName.str());
Teuchos::RCP<Time> solverTime = Teuchos::TimeMonitor::getNewCounter("Solve Time");
if (commRank == 0)
Solver::printAvailableSolversReport();
map<string, SolverPtr> solvers;
solvers["KLU"] = Solver::getSolver(Solver::KLU, true);
SolverPtr superluSolver = Solver::getSolver(Solver::SuperLUDist, true);
solvers["SuperLU"] = superluSolver;
int maxIters = 2000;
bool useStaticCondensation = false;
int azOutput = 20; // print residual every 20 CG iterations
ofstream dataFile(refName.str()+".txt");
dataFile << "ref\t " << "elements\t " << "dofs\t " << "error\t " << "solvetime\t" << "iterations\t " << endl;
for (int refIndex=0; refIndex <= numRefs; refIndex++)
{
solverTime->start(true);
Teuchos::RCP<GMGSolver> gmgSolver;
if (solverChoice[0] == 'G')
{
gmgSolver = Teuchos::rcp( new GMGSolver(soln, k0Mesh, maxIters, solverTolerance, solvers[coarseSolverChoice], useStaticCondensation));
gmgSolver->setAztecOutput(azOutput);
if (solverChoice == "GMG-Direct")
gmgSolver->gmgOperator().setSchwarzFactorizationType(GMGOperator::Direct);
if (solverChoice == "GMG-ILU")
gmgSolver->gmgOperator().setSchwarzFactorizationType(GMGOperator::ILU);
if (solverChoice == "GMG-IC")
gmgSolver->gmgOperator().setSchwarzFactorizationType(GMGOperator::IC);
soln->solve(gmgSolver);
}
else
soln->condensedSolve(solvers[solverChoice]);
double solveTime = solverTime->stop();
double energyError = soln->energyErrorTotal();
if (commRank == 0)
{
// if (refIndex > 0)
// refStrategy.printRefinementStatistics(refIndex-1);
if (solverChoice[0] == 'G')
{
cout << "Refinement: " << refIndex
<< " \tElements: " << mesh->numActiveElements()
<< " \tDOFs: " << mesh->numGlobalDofs()
<< " \tEnergy Error: " << energyError
<< " \tSolve Time: " << solveTime
<< " \tIteration Count: " << gmgSolver->iterationCount()
<< endl;
dataFile << refIndex
<< " " << mesh->numActiveElements()
<< " " << mesh->numGlobalDofs()
<< " " << energyError
<< " " << solveTime
<< " " << gmgSolver->iterationCount()
<< endl;
}
else
{
cout << "Refinement: " << refIndex
<< " \tElements: " << mesh->numActiveElements()
<< " \tDOFs: " << mesh->numGlobalDofs()
<< " \tEnergy Error: " << energyError
<< " \tSolve Time: " << solveTime
<< endl;
dataFile << refIndex
<< " " << mesh->numActiveElements()
<< " " << mesh->numGlobalDofs()
<< " " << energyError
<< " " << solveTime
<< endl;
}
}
// exporter.exportSolution(soln, refIndex);
if (refIndex != numRefs)
refStrategy.refine();
}
dataFile.close();
return 0;
}