本文整理汇总了C++中SolutionPtr::L2NormOfSolutionGlobal方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::L2NormOfSolutionGlobal方法的具体用法?C++ SolutionPtr::L2NormOfSolutionGlobal怎么用?C++ SolutionPtr::L2NormOfSolutionGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::L2NormOfSolutionGlobal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
////////////////////////////////////////////////////////////////////
// INITIALIZE FLOW FUNCTIONS
////////////////////////////////////////////////////////////////////
BCPtr nullBC = Teuchos::rcp((BC*)NULL);
RHSPtr nullRHS = Teuchos::rcp((RHS*)NULL);
IPPtr nullIP = Teuchos::rcp((IP*)NULL);
SolutionPtr prevTimeFlow = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
SolutionPtr flowResidual = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
FunctionPtr u_prev_time = Teuchos::rcp( new PreviousSolutionFunction(prevTimeFlow, u) );
//////////////////// DEFINE BILINEAR FORM ///////////////////////
Teuchos::RCP<RHSEasy> rhs = Teuchos::rcp( new RHSEasy );
FunctionPtr invDt = Teuchos::rcp(new ScalarParamFunction(1.0/dt));
// v terms:
confusionBF->addTerm( beta * u, - v->grad() );
confusionBF->addTerm( beta_n_u_hat, v);
confusionBF->addTerm( u, invDt*v );
rhs->addTerm( u_prev_time * invDt * v );
//////////////////// SPECIFY RHS ///////////////////////
FunctionPtr f = Teuchos::rcp( new ConstantScalarFunction(0.0) );
rhs->addTerm( f * v ); // obviously, with f = 0 adding this term is not necessary!
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = confusionBF->graphNorm();
// IPPtr ip = Teuchos::rcp(new IP);
// ip->addTerm(v);
// ip->addTerm(invDt*v - beta*v->grad());
//////////////////// CREATE BCs ///////////////////////
Teuchos::RCP<BCEasy> bc = Teuchos::rcp( new BCEasy );
SpatialFilterPtr inflowBoundary = Teuchos::rcp( new InflowSquareBoundary(beta) );
FunctionPtr u0 = Teuchos::rcp( new ConstantScalarFunction(0) );
FunctionPtr n = Teuchos::rcp( new UnitNormalFunction );
bc->addDirichlet(beta_n_u_hat, inflowBoundary, beta*n*u0);
Teuchos::RCP<Solution> solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
// ==================== Register Solutions ==========================
mesh->registerSolution(solution);
mesh->registerSolution(prevTimeFlow);
mesh->registerSolution(flowResidual);
// ==================== SET INITIAL GUESS ==========================
FunctionPtr u_init = Teuchos::rcp(new InitialCondition());
map<int, Teuchos::RCP<Function> > functionMap;
functionMap[u->ID()] = u_init;
prevTimeFlow->projectOntoMesh(functionMap);
//////////////////// SOLVE & REFINE ///////////////////////
// if (enforceLocalConservation) {
// // FunctionPtr parity = Teuchos::rcp<Function>( new SideParityFunction );
// // LinearTermPtr conservedQuantity = Teuchos::rcp<LinearTerm>( new LinearTerm(parity, beta_n_u_minus_sigma_n) );
// LinearTermPtr conservedQuantity = Teuchos::rcp<LinearTerm>( new LinearTerm(1.0, beta_n_u_minus_sigma_n) );
// LinearTermPtr sourcePart = Teuchos::rcp<LinearTerm>( new LinearTerm(invDt, u) );
// conservedQuantity->addTerm(sourcePart, true);
// solution->lagrangeConstraints()->addConstraint(conservedQuantity == u_prev_time * invDt);
// }
int timestepCount = 0;
double time_tol = 1e-8;
double L2_time_residual = 1e9;
while((L2_time_residual > time_tol) && (timestepCount < numTimeSteps))
{
solution->solve(false);
// Subtract solutions to get residual
flowResidual->setSolution(solution);
flowResidual->addSolution(prevTimeFlow, -1.0);
L2_time_residual = flowResidual->L2NormOfSolutionGlobal(u->ID());
if (rank == 0)
{
cout << endl << "Timestep: " << timestepCount << ", dt = " << dt << ", Time residual = " << L2_time_residual << endl;
stringstream outfile;
outfile << "rotatingCylinder_" << timestepCount;
solution->writeToVTK(outfile.str(), 5);
// Check local conservation
FunctionPtr flux = Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_hat) );
FunctionPtr source = Teuchos::rcp( new PreviousSolutionFunction(flowResidual, u) );
source = invDt * source;
Teuchos::Tuple<double, 3> fluxImbalances = checkConservation(flux, source, varFactory, mesh);
cout << "Mass flux: Largest Local = " << fluxImbalances[0]
<< ", Global = " << fluxImbalances[1] << ", Sum Abs = " << fluxImbalances[2] << endl;
}
prevTimeFlow->setSolution(solution); // reset previous time solution to current time sol
timestepCount++;
}
return 0;
}
示例2: main
//.........这里部分代码省略.........
else
{
FunctionPtr zero = Teuchos::rcp( new ConstantScalarFunction(0.0) );
solution->lagrangeConstraints()->addConstraint(beta_n_u_minus_sigma_n == zero);
}
}
// ==================== Register Solutions ==========================
mesh->registerSolution(solution);
mesh->registerSolution(prevTimeFlow); // u_t(i-1)
mesh->registerSolution(flowResidual); // u_t(i-1)
double energyThreshold = 0.25; // for mesh refinements
Teuchos::RCP<RefinementStrategy> refinementStrategy;
refinementStrategy = Teuchos::rcp(new RefinementStrategy(solution,energyThreshold));
////////////////////////////////////////////////////////////////////
// PSEUDO-TIME SOLVE STRATEGY
////////////////////////////////////////////////////////////////////
double time_tol = 1e-8;
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
double L2_time_residual = 1e7;
int timestepCount = 0;
if (!transient)
numTimeSteps = 1;
while((L2_time_residual > time_tol) && (timestepCount < numTimeSteps))
{
solution->solve(false);
// subtract solutions to get residual
flowResidual->setSolution(solution); // reset previous time solution to current time sol
flowResidual->addSolution(prevTimeFlow, -1.0);
double L2u = flowResidual->L2NormOfSolutionGlobal(u->ID());
double L2sigma1 = flowResidual->L2NormOfSolutionGlobal(sigma1->ID());
double L2sigma2 = flowResidual->L2NormOfSolutionGlobal(sigma2->ID());
L2_time_residual = sqrt(L2u*L2u + L2sigma1*L2sigma1 + L2sigma2*L2sigma2);
cout << endl << "Timestep: " << timestepCount << ", dt = " << dt << ", Time residual = " << L2_time_residual << endl;
if (rank == 0)
{
stringstream outfile;
if (transient)
outfile << "TransientConfusion_" << refIndex << "_" << timestepCount;
else
outfile << "TransientConfusion_" << refIndex;
solution->writeToVTK(outfile.str(), 5);
}
//////////////////////////////////////////////////////////////////////////
// Check conservation by testing against one
//////////////////////////////////////////////////////////////////////////
VarPtr testOne = varFactory.testVar("1", CONSTANT_SCALAR);
// Create a fake bilinear form for the testing
BFPtr fakeBF = Teuchos::rcp( new BF(varFactory) );
// Define our mass flux
FunctionPtr flux_current_time = Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_minus_sigma_n) );
FunctionPtr delta_u = Teuchos::rcp( new PreviousSolutionFunction(flowResidual, u) );
LinearTermPtr surfaceFlux = -1.0 * flux_current_time * testOne;
LinearTermPtr volumeChange = invDt * delta_u * testOne;
LinearTermPtr massFluxTerm;
if (transient)
{
massFluxTerm = volumeChange;
// massFluxTerm->addTerm(surfaceFlux);
}
示例3: 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;
}
示例4: main
//.........这里部分代码省略.........
Teuchos::RCP<Solution> solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
// ==================== Register Solutions ==========================
mesh->registerSolution(solution);
mesh->registerSolution(prevTimeFlow);
mesh->registerSolution(flowResidual);
// ==================== SET INITIAL GUESS ==========================
double u_free = 0.0;
map<int, Teuchos::RCP<Function> > functionMap;
// functionMap[u->ID()] = Teuchos::rcp( new ConInletBC
functionMap[u->ID()] = Teuchos::rcp( new InletBC );
prevTimeFlow->projectOntoMesh(functionMap);
//////////////////// SOLVE & REFINE ///////////////////////
if (enforceLocalConservation)
{
if (steady)
{
FunctionPtr zero = Teuchos::rcp( new ConstantScalarFunction(0.0) );
solution->lagrangeConstraints()->addConstraint(beta_n_u_hat == zero);
}
else
{
// FunctionPtr parity = Teuchos::rcp<Function>( new SideParityFunction );
// LinearTermPtr conservedQuantity = Teuchos::rcp<LinearTerm>( new LinearTerm(parity, beta_n_u_minus_sigma_n) );
LinearTermPtr conservedQuantity = Teuchos::rcp<LinearTerm>( new LinearTerm(1.0, beta_n_u_hat) );
LinearTermPtr sourcePart = Teuchos::rcp<LinearTerm>( new LinearTerm(invDt, u) );
conservedQuantity->addTerm(sourcePart, true);
solution->lagrangeConstraints()->addConstraint(conservedQuantity == u_prev_time * invDt);
}
}
double energyThreshold = 0.2; // for mesh refinements
RefinementStrategy refinementStrategy( solution, energyThreshold );
VTKExporter exporter(solution, mesh, varFactory);
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
if (steady)
{
solution->solve(false);
if (commRank == 0)
{
stringstream outfile;
outfile << "Convection_" << refIndex;
exporter.exportSolution(outfile.str());
// Check local conservation
FunctionPtr flux = Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_hat) );
FunctionPtr zero = Teuchos::rcp( new ConstantScalarFunction(0.0) );
Teuchos::Tuple<double, 3> fluxImbalances = checkConservation(flux, zero, varFactory, mesh);
cout << "Mass flux: Largest Local = " << fluxImbalances[0]
<< ", Global = " << fluxImbalances[1] << ", Sum Abs = " << fluxImbalances[2] << endl;
}
}
else
{
int timestepCount = 0;
double time_tol = 1e-8;
double L2_time_residual = 1e9;
// cout << L2_time_residual <<" "<< time_tol << timestepCount << numTimeSteps << endl;
while((L2_time_residual > time_tol) && (timestepCount < numTimeSteps))
{
solution->solve(false);
// Subtract solutions to get residual
flowResidual->setSolution(solution);
flowResidual->addSolution(prevTimeFlow, -1.0);
L2_time_residual = flowResidual->L2NormOfSolutionGlobal(u->ID());
if (commRank == 0)
{
cout << endl << "Timestep: " << timestepCount << ", dt = " << dt << ", Time residual = " << L2_time_residual << endl;
stringstream outfile;
outfile << "TransientConvection_" << refIndex << "-" << timestepCount;
exporter.exportSolution(outfile.str());
// Check local conservation
FunctionPtr flux = Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_hat) );
FunctionPtr source = Teuchos::rcp( new PreviousSolutionFunction(flowResidual, u) );
source = -invDt * source;
Teuchos::Tuple<double, 3> fluxImbalances = checkConservation(flux, source, varFactory, mesh);
cout << "Mass flux: Largest Local = " << fluxImbalances[0]
<< ", Global = " << fluxImbalances[1] << ", Sum Abs = " << fluxImbalances[2] << endl;
}
prevTimeFlow->setSolution(solution); // reset previous time solution to current time sol
timestepCount++;
}
}
if (refIndex < numRefs)
refinementStrategy.refine(commRank==0); // print to console on commRank 0
}
return 0;
}