本文整理汇总了C++中SolutionPtr::addSolution方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::addSolution方法的具体用法?C++ SolutionPtr::addSolution怎么用?C++ SolutionPtr::addSolution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::addSolution方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
////////////////////////////////////////////////////////////////////
// CREATE SOLUTION OBJECT
////////////////////////////////////////////////////////////////////
Teuchos::RCP<Solution> solution = Teuchos::rcp(new Solution(mesh, inflowBC, rhs, ip));
mesh->registerSolution(solution); solution->setCubatureEnrichmentDegree(10);
////////////////////////////////////////////////////////////////////
// HESSIAN BIT + CHECKS ON GRADIENT + HESSIAN
////////////////////////////////////////////////////////////////////
VarFactory hessianVars = varFactory.getBubnovFactory(VarFactory::BUBNOV_TRIAL);
VarPtr du = hessianVars.test(u->ID());
// BFPtr hessianBF = Teuchos::rcp( new BF(hessianVars) ); // initialize bilinear form
FunctionPtr du_current = Teuchos::rcp( new PreviousSolutionFunction(solution, u) );
FunctionPtr fnhat = Teuchos::rcp(new PreviousSolutionFunction(solution,fn));
LinearTermPtr residual = Teuchos::rcp(new LinearTerm);// residual
residual->addTerm(fnhat*v,true);
residual->addTerm( - (e1 * (u_prev_squared_div2) + e2 * (u_prev)) * v->grad(),true);
LinearTermPtr Bdu = Teuchos::rcp(new LinearTerm);// residual
Bdu->addTerm( - du_current*(beta*v->grad()));
Teuchos::RCP<RieszRep> riesz = Teuchos::rcp(new RieszRep(mesh, ip, residual));
Teuchos::RCP<RieszRep> duRiesz = Teuchos::rcp(new RieszRep(mesh, ip, Bdu));
riesz->computeRieszRep();
FunctionPtr e_v = Teuchos::rcp(new RepFunction(v,riesz));
e_v->writeValuesToMATLABFile(mesh, "e_v.m");
FunctionPtr posErrPart = Teuchos::rcp(new PositivePart(e_v->dx()));
// hessianBF->addTerm(e_v->dx()*u,du);
// hessianBF->addTerm(posErrPart*u,du);
// Teuchos::RCP<NullFilter> nullFilter = Teuchos::rcp(new NullFilter);
// Teuchos::RCP<HessianFilter> hessianFilter = Teuchos::rcp(new HessianFilter(hessianBF));
Teuchos::RCP< LineSearchStep > LS_Step = Teuchos::rcp(new LineSearchStep(riesz));
double NL_residual = 9e99;
for (int i = 0;i<numSteps;i++){
// write matrix to file and then resollve without hessian
/*
solution->setFilter(hessianFilter);
stringstream oss;
oss << "hessianMatrix" << i << ".dat";
solution->setWriteMatrixToFile(true,oss.str());
solution->solve(false);
solution->setFilter(nullFilter);
oss.str(""); // clear
oss << "stiffnessMatrix" << i << ".dat";
solution->setWriteMatrixToFile(false,oss.str());
*/
solution->solve(false); // do one solve to initialize things...
double stepLength = 1.0;
stepLength = LS_Step->stepSize(backgroundFlow,solution, NL_residual);
// solution->setWriteMatrixToFile(true,"stiffness.dat");
backgroundFlow->addSolution(solution,stepLength);
NL_residual = LS_Step->getNLResidual();
if (rank==0){
cout << "NL residual after adding = " << NL_residual << " with step size " << stepLength << endl;
}
double fd_gradient;
for (int dofIndex = 0;dofIndex<mesh->numGlobalDofs();dofIndex++){
TestingUtilities::initializeSolnCoeffs(solnPerturbation);
TestingUtilities::setSolnCoeffForGlobalDofIndex(solnPerturbation,1.0,dofIndex);
fd_gradient = FiniteDifferenceUtilities::finiteDifferenceGradient(mesh, riesz, backgroundFlow, dofIndex);
// CHECK GRADIENT
LinearTermPtr b_u = bf->testFunctional(solnPerturbation);
map<int,FunctionPtr> NL_err_rep_map;
NL_err_rep_map[v->ID()] = Teuchos::rcp(new RepFunction(v,riesz));
FunctionPtr gradient = b_u->evaluate(NL_err_rep_map, TestingUtilities::isFluxOrTraceDof(mesh,dofIndex)); // use boundary part only if flux or trace
double grad;
if (TestingUtilities::isFluxOrTraceDof(mesh,dofIndex)){
grad = gradient->integralOfJump(mesh,10);
}else{
grad = gradient->integrate(mesh,10);
}
double fdgrad = fd_gradient;
double diff = grad-fdgrad;
if (abs(diff)>1e-6 && i>0){
cout << "Found difference of " << diff << ", " << " with fd val = " << fdgrad << " and gradient = " << grad << " in dof " << dofIndex << ", isTraceDof = " << TestingUtilities::isFluxOrTraceDof(mesh,dofIndex) << endl;
}
}
}
VTKExporter exporter(solution, mesh, varFactory);
if (rank==0){
exporter.exportSolution("qopt");
cout << endl;
}
return 0;
}
示例2: 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;
}
示例3: main
//.........这里部分代码省略.........
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
IPPtr ip = Teuchos::rcp(new IP);
if (norm == 0)
{
ip = bf->graphNorm();
}
else if (norm == 1)
{
// ip = bf->l2Norm();
}
//////////////////// CREATE BCs ///////////////////////
Teuchos::RCP<BCEasy> bc = Teuchos::rcp( new BCEasy );
// Teuchos::RCP<PenaltyConstraints> pc = Teuchos::rcp( new PenaltyConstraints );
SpatialFilterPtr left = Teuchos::rcp( new ConstantXBoundary(-0.5) );
SpatialFilterPtr right = Teuchos::rcp( new ConstantXBoundary(1) );
SpatialFilterPtr top = Teuchos::rcp( new ConstantYBoundary(-0.5) );
SpatialFilterPtr bottom = Teuchos::rcp( new ConstantYBoundary(1.5) );
bc->addDirichlet(u1hat, left, u1Exact);
bc->addDirichlet(u2hat, left, u2Exact);
bc->addDirichlet(u1hat, right, u1Exact);
bc->addDirichlet(u2hat, right, u2Exact);
bc->addDirichlet(u1hat, top, u1Exact);
bc->addDirichlet(u2hat, top, u2Exact);
bc->addDirichlet(u1hat, bottom, u1Exact);
bc->addDirichlet(u2hat, bottom, u2Exact);
// zero mean constraint on pressure
bc->addZeroMeanConstraint(p);
// pc->addConstraint(u1hat*u2hat-t1hat == zero, top);
// pc->addConstraint(u2hat*u2hat-t2hat == zero, top);
Teuchos::RCP<Solution> solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
// solution->setFilter(pc);
// if (enforceLocalConservation) {
// solution->lagrangeConstraints()->addConstraint(u1hat->times_normal_x() + u2hat->times_normal_y() == zero);
// }
// ==================== Register Solutions ==========================
mesh->registerSolution(solution);
mesh->registerSolution(backgroundFlow);
// Teuchos::RCP< RefinementHistory > refHistory = Teuchos::rcp( new RefinementHistory );
// mesh->registerObserver(refHistory);
//////////////////// SOLVE & REFINE ///////////////////////
double energyThreshold = 0.2; // for mesh refinements
RefinementStrategy refinementStrategy( solution, energyThreshold );
VTKExporter exporter(backgroundFlow, mesh, varFactory);
stringstream outfile;
outfile << "kovasznay" << "_" << 0;
exporter.exportSolution(outfile.str());
double nonlinearRelativeEnergyTolerance = 1e-5; // used to determine convergence of the nonlinear solution
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
double L2Update = 1e10;
int iterCount = 0;
while (L2Update > nonlinearRelativeEnergyTolerance && iterCount < maxNewtonIterations)
{
solution->solve(false);
double u1L2Update = solution->L2NormOfSolutionGlobal(u1->ID());
double u2L2Update = solution->L2NormOfSolutionGlobal(u2->ID());
L2Update = sqrt(u1L2Update*u1L2Update + u2L2Update*u2L2Update);
// Check local conservation
if (commRank == 0)
{
cout << "L2 Norm of Update = " << L2Update << endl;
// if (saveFile.length() > 0) {
// std::ostringstream oss;
// oss << string(saveFile) << refIndex ;
// cout << "on refinement " << refIndex << " saving mesh file to " << oss.str() << endl;
// refHistory->saveToFile(oss.str());
// }
}
// line search algorithm
double alpha = 1.0;
backgroundFlow->addSolution(solution, alpha);
iterCount++;
}
if (commRank == 0)
{
stringstream outfile;
outfile << "kovasznay" << "_" << refIndex+1;
exporter.exportSolution(outfile.str());
}
if (refIndex < numRefs)
refinementStrategy.refine(commRank==0); // print to console on commRank 0
}
return 0;
}
示例4: 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);
示例5: main
//.........这里部分代码省略.........
// cout << "after replay, num elems = " << numElems << " and min side length = " << minSideLength << endl;
// }
// }
for (int i = 0; i < uniformRefinements; i++)
refinementStrategy.hRefineUniformly(mesh);
double nonlinearRelativeEnergyTolerance = 1e-5; // used to determine convergence of the nonlinear solution
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
double L2Update = 1e10;
int iterCount = 0;
while (L2Update > nonlinearRelativeEnergyTolerance && iterCount < maxNewtonIterations)
{
solution->solve(false);
double u1L2Update = solution->L2NormOfSolutionGlobal(u1->ID());
double u2L2Update = solution->L2NormOfSolutionGlobal(u2->ID());
L2Update = sqrt(u1L2Update*u1L2Update + u2L2Update*u2L2Update);
double energy_error = solution->energyErrorTotal();
// Check local conservation
if (commRank == 0)
{
FunctionPtr n = Function::normal();
FunctionPtr u1_prev = Function::solution(u1hat, solution);
FunctionPtr u2_prev = Function::solution(u2hat, solution);
FunctionPtr flux = u1_prev*n->x() + u2_prev*n->y();
Teuchos::Tuple<double, 3> fluxImbalances = checkConservation(flux, zero, mesh);
// cout << "Mass flux: Largest Local = " << fluxImbalances[0]
// << ", Global = " << fluxImbalances[1] << ", Sum Abs = " << fluxImbalances[2] << endl;
errOut << mesh->numGlobalDofs() << " " << energy_error << " "
<< fluxImbalances[0] << " " << fluxImbalances[1] << " " << fluxImbalances[2] << endl;
double massFlux0 = computeFluxOverElementSides(u1_prev, mesh, cellFace0);
double massFlux1 = computeFluxOverElementSides(u1_prev, mesh, cellFace1);
double massFlux2 = computeFluxOverElementSides(u1_prev, mesh, cellFace2);
double massFlux3 = computeFluxOverElementSides(u1_prev, mesh, cellFace3);
double massFlux4 = computeFluxOverElementSides(u1_prev, mesh, cellFace4);
fluxOut << massFlux0 << " " << massFlux1 << " " << massFlux2 << " " << massFlux3 << " " << massFlux4 << " " << endl;
cout << "Total mass flux = " << massFlux0 << " " << massFlux1 << " " << massFlux2 << " " << massFlux3 << " " << massFlux4 << " " << endl;
// if (saveFile.length() > 0) {
// std::ostringstream oss;
// oss << string(saveFile) << refIndex ;
// cout << "on refinement " << refIndex << " saving mesh file to " << oss.str() << endl;
// refHistory->saveToFile(oss.str());
// }
}
// line search algorithm
double alpha = 1.0;
// bool useLineSearch = false;
// int posEnrich = 5; // amount of enriching of grid points on which to ensure positivity
// if (useLineSearch){ // to enforce positivity of density rho
// double lineSearchFactor = .5; double eps = .001; // arbitrary
// FunctionPtr rhoTemp = Function::solution(rho,backgroundFlow) + alpha*Function::solution(rho,solution) - Function::constant(eps);
// FunctionPtr eTemp = Function::solution(e,backgroundFlow) + alpha*Function::solution(e,solution) - Function::constant(eps);
// bool rhoIsPositive = rhoTemp->isPositive(mesh,posEnrich);
// bool eIsPositive = eTemp->isPositive(mesh,posEnrich);
// int iter = 0; int maxIter = 20;
// while (!(rhoIsPositive && eIsPositive) && iter < maxIter){
// alpha = alpha*lineSearchFactor;
// rhoTemp = Function::solution(rho,backgroundFlow) + alpha*Function::solution(rho,solution);
// eTemp = Function::solution(e,backgroundFlow) + alpha*Function::solution(e,solution);
// rhoIsPositive = rhoTemp->isPositive(mesh,posEnrich);
// eIsPositive = eTemp->isPositive(mesh,posEnrich);
// iter++;
// }
// if (commRank==0 && alpha < 1.0){
// cout << "line search factor alpha = " << alpha << endl;
// }
// }
backgroundFlow->addSolution(solution, alpha, false, true);
iterCount++;
// if (commRank == 0)
// cout << "L2 Norm of Update = " << L2Update << endl;
}
if (commRank == 0)
cout << endl;
if (commRank == 0)
{
stringstream outfile;
outfile << "stokeshemker" << uniformRefinements << "_" << refIndex;
exporter.exportSolution(outfile.str());
}
if (refIndex < numRefs)
refinementStrategy.refine(commRank==0); // print to console on commRank 0
}
if (commRank == 0)
{
errOut.close();
fluxOut.close();
}
return 0;
}
示例6: 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;
}
示例7: main
//.........这里部分代码省略.........
mesh->registerSolution(solution);
////////////////////////////////////////////////////////////////////
// WARNING: UNFINISHED HESSIAN BIT
////////////////////////////////////////////////////////////////////
VarFactory hessianVars = varFactory.getBubnovFactory(VarFactory::BUBNOV_TRIAL);
VarPtr du = hessianVars.test(u->ID());
BFPtr hessianBF = Teuchos::rcp( new BF(hessianVars) ); // initialize bilinear form
// FunctionPtr e_v = Function::constant(1.0); // dummy error rep function for now - should do nothing
FunctionPtr u_current = Teuchos::rcp( new PreviousSolutionFunction(solution, u) );
FunctionPtr sig1_prev = Teuchos::rcp( new PreviousSolutionFunction(solution, sigma1) );
FunctionPtr sig2_prev = Teuchos::rcp( new PreviousSolutionFunction(solution, sigma2) );
FunctionPtr sig_prev = (e1*sig1_prev + e2*sig2_prev);
FunctionPtr fnhat = Teuchos::rcp(new PreviousSolutionFunction(solution,beta_n_u_minus_sigma_hat));
FunctionPtr uhat_prev = Teuchos::rcp(new PreviousSolutionFunction(solution,uhat));
LinearTermPtr residual = Teuchos::rcp(new LinearTerm);// residual
residual->addTerm(fnhat*v - (e1 * (u_prev_squared_div2 - sig1_prev) + e2 * (u_prev - sig2_prev)) * v->grad());
residual->addTerm((1/epsilon)*sig_prev * tau + u_prev * tau->div() - uhat_prev*tau->dot_normal());
LinearTermPtr Bdu = Teuchos::rcp(new LinearTerm);// residual
Bdu->addTerm( u_current*tau->div() - u_current*(beta*v->grad()));
Teuchos::RCP<RieszRep> riesz = Teuchos::rcp(new RieszRep(mesh, ip, residual));
Teuchos::RCP<RieszRep> duRiesz = Teuchos::rcp(new RieszRep(mesh, ip, Bdu));
riesz->computeRieszRep();
FunctionPtr e_v = Teuchos::rcp(new RepFunction(v,riesz));
e_v->writeValuesToMATLABFile(mesh, "e_v.m");
FunctionPtr posErrPart = Teuchos::rcp(new PositivePart(e_v->dx()));
hessianBF->addTerm(e_v->dx()*u,du);
// hessianBF->addTerm(posErrPart*u,du);
Teuchos::RCP<HessianFilter> hessianFilter = Teuchos::rcp(new HessianFilter(hessianBF));
if (useHessian)
{
solution->setWriteMatrixToFile(true,"hessianStiffness.dat");
}
else
{
solution->setWriteMatrixToFile(true,"stiffness.dat");
}
Teuchos::RCP< LineSearchStep > LS_Step = Teuchos::rcp(new LineSearchStep(riesz));
ofstream out;
out.open("Burgers.txt");
double NL_residual = 9e99;
for (int i = 0; i<numSteps; i++)
{
solution->solve(false); // do one solve to initialize things...
double stepLength = 1.0;
stepLength = LS_Step->stepSize(backgroundFlow,solution, NL_residual);
if (useHessian)
{
solution->setFilter(hessianFilter);
}
backgroundFlow->addSolution(solution,stepLength);
NL_residual = LS_Step->getNLResidual();
if (rank==0)
{
cout << "NL residual after adding = " << NL_residual << " with step size " << stepLength << endl;
out << NL_residual << endl; // saves initial NL error
}
}
out.close();
////////////////////////////////////////////////////////////////////
// DEFINE REFINEMENT STRATEGY
////////////////////////////////////////////////////////////////////
Teuchos::RCP<RefinementStrategy> refinementStrategy;
refinementStrategy = Teuchos::rcp(new RefinementStrategy(solution,energyThreshold));
int numRefs = 0;
Teuchos::RCP<NonlinearStepSize> stepSize = Teuchos::rcp(new NonlinearStepSize(nonlinearStepSize));
Teuchos::RCP<NonlinearSolveStrategy> solveStrategy;
solveStrategy = Teuchos::rcp( new NonlinearSolveStrategy(backgroundFlow, solution, stepSize,
nonlinearRelativeEnergyTolerance));
////////////////////////////////////////////////////////////////////
// SOLVE
////////////////////////////////////////////////////////////////////
for (int refIndex=0; refIndex<numRefs; refIndex++)
{
solveStrategy->solve(rank==0); // print to console on rank 0
refinementStrategy->refine(rank==0); // print to console on rank 0
}
// solveStrategy->solve(rank==0);
if (rank==0)
{
backgroundFlow->writeToVTK("Burgers.vtu",min(H1Order+1,4));
solution->writeFluxesToFile(uhat->ID(), "burgers.dat");
cout << "wrote solution files" << endl;
}
return 0;
}
示例8: main
//.........这里部分代码省略.........
////////////////////////////////////////////////////////////////////
// CREATE SOLUTION OBJECT
////////////////////////////////////////////////////////////////////
Teuchos::RCP<Solution> solution = Teuchos::rcp(new Solution(mesh, inflowBC, rhs, ip));
mesh->registerSolution(solution);
if (enforceLocalConservation)
{
FunctionPtr zero = Teuchos::rcp( new ConstantScalarFunction(0.0) );
solution->lagrangeConstraints()->addConstraint(fhat == zero);
}
////////////////////////////////////////////////////////////////////
// DEFINE REFINEMENT STRATEGY
////////////////////////////////////////////////////////////////////
Teuchos::RCP<RefinementStrategy> refinementStrategy;
refinementStrategy = Teuchos::rcp(new RefinementStrategy(solution,energyThreshold));
////////////////////////////////////////////////////////////////////
// SOLVE
////////////////////////////////////////////////////////////////////
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
double L2Update = 1e7;
int iterCount = 0;
while (L2Update > nonlinearRelativeEnergyTolerance && iterCount < maxNewtonIterations)
{
solution->solve();
L2Update = solution->L2NormOfSolutionGlobal(u->ID());
cout << "L2 Norm of Update = " << L2Update << endl;
// backgroundFlow->clear();
backgroundFlow->addSolution(solution, newtonStepSize);
iterCount++;
}
cout << endl;
// check conservation
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 massFlux = Teuchos::rcp( new PreviousSolutionFunction(solution, fhat) );
LinearTermPtr massFluxTerm = massFlux * testOne;
Teuchos::RCP<shards::CellTopology> quadTopoPtr = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >() ));
DofOrderingFactory dofOrderingFactory(fakeBF);
int fakeTestOrder = H1Order;
DofOrderingPtr testOrdering = dofOrderingFactory.testOrdering(fakeTestOrder, *quadTopoPtr);
int testOneIndex = testOrdering->getDofIndex(testOne->ID(),0);
vector< ElementTypePtr > elemTypes = mesh->elementTypes(); // global element types
map<int, double> massFluxIntegral; // cellID -> integral
double maxMassFluxIntegral = 0.0;
double totalMassFlux = 0.0;
double totalAbsMassFlux = 0.0;
for (vector< ElementTypePtr >::iterator elemTypeIt = elemTypes.begin(); elemTypeIt != elemTypes.end(); elemTypeIt++)
{
ElementTypePtr elemType = *elemTypeIt;
vector< ElementPtr > elems = mesh->elementsOfTypeGlobal(elemType);
vector<int> cellIDs;
for (int i=0; i<elems.size(); i++)
{
cellIDs.push_back(elems[i]->cellID());
}