本文整理汇总了C++中IPPtr::addTerm方法的典型用法代码示例。如果您正苦于以下问题:C++ IPPtr::addTerm方法的具体用法?C++ IPPtr::addTerm怎么用?C++ IPPtr::addTerm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPPtr
的用法示例。
在下文中一共展示了IPPtr::addTerm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
BCPtr nullBC = Teuchos::rcp((BC*)NULL);
RHSPtr nullRHS = Teuchos::rcp((RHS*)NULL);
IPPtr nullIP = Teuchos::rcp((IP*)NULL);
SolutionPtr backgroundFlow = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
vector<double> e1(2); // (1,0)
e1[0] = 1;
vector<double> e2(2); // (0,1)
e2[1] = 1;
FunctionPtr u1_prev = Function::solution(u1, backgroundFlow);
FunctionPtr u2_prev = Function::solution(u2, backgroundFlow);
// FunctionPtr sigma11_prev = Function::solution(sigma11, backgroundFlow);
// FunctionPtr sigma12_prev = Function::solution(sigma12, backgroundFlow);
// FunctionPtr sigma22_prev = Function::solution(sigma22, backgroundFlow);
FunctionPtr zero = Teuchos::rcp( new ConstantScalarFunction(0.0) );
FunctionPtr one = Teuchos::rcp( new ConstantScalarFunction(1.0) );
FunctionPtr u1Exact = Teuchos::rcp( new ExactU1(lambda) );
FunctionPtr u2Exact = Teuchos::rcp( new ExactU2(lambda) );
// ==================== SET INITIAL GUESS ==========================
map<int, Teuchos::RCP<Function> > functionMap;
// functionMap[u1->ID()] = u1Exact;
// functionMap[u2->ID()] = u2Exact;
functionMap[u1->ID()] = zero;
functionMap[u2->ID()] = zero;
backgroundFlow->projectOntoMesh(functionMap);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
// stress equation
bf->addTerm( 1./nu*sigma11, tau11 );
bf->addTerm( 1./nu*sigma12, tau12 );
bf->addTerm( 1./nu*sigma12, tau12 );
bf->addTerm( 1./nu*sigma22, tau22 );
bf->addTerm( -0.5/nu*sigma11, tau11 );
bf->addTerm( -0.5/nu*sigma22, tau11 );
bf->addTerm( -0.5/nu*sigma11, tau22 );
bf->addTerm( -0.5/nu*sigma22, tau22 );
bf->addTerm( 2*u1, tau11->dx() );
bf->addTerm( 2*u1, tau12->dy() );
bf->addTerm( 2*u2, tau12->dx() );
bf->addTerm( 2*u2, tau22->dy() );
bf->addTerm( -2*u1hat, tau11->times_normal_x() );
bf->addTerm( -2*u1hat, tau12->times_normal_y() );
bf->addTerm( -2*u2hat, tau12->times_normal_x() );
bf->addTerm( -2*u2hat, tau22->times_normal_y() );
// momentum equation
bf->addTerm( -2.*u1_prev*u1, v1->dx() );
bf->addTerm( -u2_prev*u1, v1->dy() );
bf->addTerm( -u1_prev*u2, v1->dy() );
bf->addTerm( -u2_prev*u1, v2->dx() );
bf->addTerm( -u1_prev*u2, v2->dx() );
bf->addTerm( -2.*u2_prev*u2, v2->dy() );
bf->addTerm( sigma11, v1->dx() );
bf->addTerm( sigma12, v1->dy() );
bf->addTerm( sigma12, v2->dx() );
bf->addTerm( sigma22, v2->dy() );
bf->addTerm( t1hat, v1);
bf->addTerm( t2hat, v2);
//////////////////// SPECIFY RHS ///////////////////////
RHSPtr rhs = RHS::rhs();
示例2: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
choice::MpiArgs args( argc, argv );
#else
choice::Args args( argc, argv );
#endif
int rank = Teuchos::GlobalMPISession::getRank();
int numProcs = Teuchos::GlobalMPISession::getNProc();
int nCells = args.Input<int>("--nCells", "num cells",2);
int numSteps = args.Input<int>("--numSteps", "num NR steps",20);
int polyOrder = 0;
// define our manufactured solution or problem bilinear form:
bool useTriangles = false;
int pToAdd = 1;
args.Process();
int H1Order = polyOrder + 1;
////////////////////////////////////////////////////////////////////
// DEFINE VARIABLES
////////////////////////////////////////////////////////////////////
// new-style bilinear form definition
VarFactory varFactory;
VarPtr fn = varFactory.fluxVar("\\widehat{\\beta_n_u}");
VarPtr u = varFactory.fieldVar("u");
VarPtr v = varFactory.testVar("v",HGRAD);
BFPtr bf = Teuchos::rcp( new BF(varFactory) ); // initialize bilinear form
////////////////////////////////////////////////////////////////////
// CREATE MESH
////////////////////////////////////////////////////////////////////
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(nCells , bf, H1Order, H1Order+pToAdd);
////////////////////////////////////////////////////////////////////
// INITIALIZE BACKGROUND FLOW FUNCTIONS
////////////////////////////////////////////////////////////////////
BCPtr nullBC = Teuchos::rcp((BC*)NULL); RHSPtr nullRHS = Teuchos::rcp((RHS*)NULL); IPPtr nullIP = Teuchos::rcp((IP*)NULL);
SolutionPtr backgroundFlow = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
SolutionPtr solnPerturbation = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
vector<double> e1(2),e2(2);
e1[0] = 1; e2[1] = 1;
FunctionPtr u_prev = Teuchos::rcp( new PreviousSolutionFunction(backgroundFlow, u) );
FunctionPtr beta = e1 * u_prev + Teuchos::rcp( new ConstantVectorFunction( e2 ) );
////////////////////////////////////////////////////////////////////
// DEFINE BILINEAR FORM
////////////////////////////////////////////////////////////////////
// v:
bf->addTerm( -u, beta * v->grad());
bf->addTerm( fn, v);
////////////////////////////////////////////////////////////////////
// DEFINE RHS
////////////////////////////////////////////////////////////////////
Teuchos::RCP<RHSEasy> rhs = Teuchos::rcp( new RHSEasy );
FunctionPtr u_prev_squared_div2 = 0.5 * u_prev * u_prev;
rhs->addTerm((e1 * u_prev_squared_div2 + e2 * u_prev) * v->grad());
// ==================== SET INITIAL GUESS ==========================
mesh->registerSolution(backgroundFlow);
FunctionPtr zero = Function::constant(0.0);
FunctionPtr u0 = Teuchos::rcp( new U0 );
FunctionPtr n = Teuchos::rcp( new UnitNormalFunction );
// FunctionPtr parity = Teuchos::rcp(new SideParityFunction);
FunctionPtr u0_squared_div_2 = 0.5 * u0 * u0;
map<int, Teuchos::RCP<Function> > functionMap;
functionMap[u->ID()] = u0;
// functionMap[fn->ID()] = -(e1 * u0_squared_div_2 + e2 * u0) * n * parity;
backgroundFlow->projectOntoMesh(functionMap);
// ==================== END SET INITIAL GUESS ==========================
////////////////////////////////////////////////////////////////////
// DEFINE INNER PRODUCT
////////////////////////////////////////////////////////////////////
IPPtr ip = Teuchos::rcp( new IP );
ip->addTerm( v );
ip->addTerm(v->grad());
// ip->addTerm( beta * v->grad() ); // omitting term to make IP non-dependent on u
////////////////////////////////////////////////////////////////////
//.........这里部分代码省略.........
示例3: testRieszInversion
// tests Riesz inversion by integration by parts
bool LinearTermTests::testRieszInversion()
{
bool success = true;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr tau = varFactory->testVar("\\tau", HDIV);
VarPtr v = varFactory->testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory->traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory->fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory->fieldVar("u");
VarPtr sigma1 = varFactory->fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory->fieldVar("\\sigma_2");
vector<double> beta;
beta.push_back(1.0);
beta.push_back(0.0);
double eps = .01;
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// tau terms:
confusionBF->addTerm(sigma1 / eps, tau->x());
confusionBF->addTerm(sigma2 / eps, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(uhat, -tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( -u, beta * v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
//////////////////// BUILD MESH ///////////////////////
// define nodes for mesh
int H1Order = 1;
int pToAdd = 1;
FieldContainer<double> quadPoints(4,2);
quadPoints(0,0) = 0.0; // x1
quadPoints(0,1) = 0.0; // y1
quadPoints(1,0) = 1.0;
quadPoints(1,1) = 0.0;
quadPoints(2,0) = 1.0;
quadPoints(2,1) = 1.0;
quadPoints(3,0) = 0.0;
quadPoints(3,1) = 1.0;
int nCells = 1;
int horizontalCells = nCells, verticalCells = nCells;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> myMesh = MeshFactory::buildQuadMesh(quadPoints, horizontalCells, verticalCells,
confusionBF, H1Order, H1Order+pToAdd);
ElementTypePtr elemType = myMesh->getElement(0)->elementType();
BasisCachePtr basisCache = Teuchos::rcp(new BasisCache(elemType, myMesh));
vector<GlobalIndexType> cellIDs;
vector<ElementPtr> elems = myMesh->activeElements();
vector<ElementPtr>::iterator elemIt;
for (elemIt=elems.begin(); elemIt!=elems.end(); elemIt++)
{
int cellID = (*elemIt)->cellID();
cellIDs.push_back(cellID);
}
bool createSideCacheToo = true;
basisCache->setPhysicalCellNodes(myMesh->physicalCellNodesGlobal(elemType), cellIDs, createSideCacheToo);
LinearTermPtr integrand = Teuchos::rcp(new LinearTerm);// residual
LinearTermPtr integrandIBP = Teuchos::rcp(new LinearTerm);// residual
vector<double> e1(2); // (1,0)
vector<double> e2(2); // (0,1)
e1[0] = 1;
e2[1] = 1;
FunctionPtr n = Function::normal();
FunctionPtr X = Function::xn(1);
FunctionPtr Y = Function::yn(1);
FunctionPtr testFxn1 = X;
FunctionPtr testFxn2 = Y;
FunctionPtr divTestFxn = testFxn1->dx() + testFxn2->dy();
FunctionPtr vectorTest = testFxn1*e1 + testFxn2*e2;
integrand->addTerm(divTestFxn*v);
integrandIBP->addTerm(vectorTest*n*v - vectorTest*v->grad()); // boundary term
IPPtr sobolevIP = Teuchos::rcp(new IP);
sobolevIP->addTerm(v);
sobolevIP->addTerm(tau);
Teuchos::RCP<RieszRep> riesz = Teuchos::rcp(new RieszRep(myMesh, sobolevIP, integrand));
// riesz->setPrintOption(true);
riesz->computeRieszRep();
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
int rank=mpiSession.getRank();
int numProcs=mpiSession.getNProc();
#else
int rank = 0;
int numProcs = 1;
#endif
int polyOrder = 3;
int pToAdd = 2; // for tests
// define our manufactured solution or problem bilinear form:
double epsilon = 1e-2;
bool useTriangles = false;
FieldContainer<double> quadPoints(4,2);
quadPoints(0,0) = 0.0; // x1
quadPoints(0,1) = 0.0; // y1
quadPoints(1,0) = 1.0;
quadPoints(1,1) = 0.0;
quadPoints(2,0) = 1.0;
quadPoints(2,1) = 1.0;
quadPoints(3,0) = 0.0;
quadPoints(3,1) = 1.0;
int H1Order = polyOrder + 1;
int horizontalCells = 1, verticalCells = 1;
double energyThreshold = 0.2; // for mesh refinements
double nonlinearStepSize = 0.5;
double nonlinearRelativeEnergyTolerance = 0.015; // used to determine convergence of the nonlinear solution
////////////////////////////////////////////////////////////////////
// SET UP PROBLEM
////////////////////////////////////////////////////////////////////
Teuchos::RCP<BurgersBilinearForm> oldBurgersBF = Teuchos::rcp(new BurgersBilinearForm(epsilon));
// new-style bilinear form definition
VarFactory varFactory;
VarPtr uhat = varFactory.traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_hat = varFactory.fluxVar("\\widehat{\\beta_n u - \\sigma_n}");
VarPtr u = varFactory.fieldVar("u");
VarPtr sigma1 = varFactory.fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory.fieldVar("\\sigma_2");
VarPtr tau = varFactory.testVar("\\tau",HDIV);
VarPtr v = varFactory.testVar("v",HGRAD);
BFPtr bf = Teuchos::rcp( new BF(varFactory) );
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = Mesh::buildQuadMesh(quadPoints, horizontalCells, verticalCells, bf, H1Order, H1Order+pToAdd, useTriangles);
mesh->setPartitionPolicy(Teuchos::rcp(new ZoltanMeshPartitionPolicy("HSFC")));
Teuchos::RCP<Solution> backgroundFlow = Teuchos::rcp(new Solution(mesh, Teuchos::rcp((BC*)NULL) , Teuchos::rcp((RHS*)NULL), Teuchos::rcp((DPGInnerProduct*)NULL))); // create null solution
oldBurgersBF->setBackgroundFlow(backgroundFlow);
// tau parts:
// 1/eps (sigma, tau)_K + (u, div tau)_K - (u_hat, tau_n)_dK
bf->addTerm(sigma1 / epsilon, tau->x());
bf->addTerm(sigma2 / epsilon, tau->y());
bf->addTerm(u, tau->div());
bf->addTerm( - uhat, tau->dot_normal() );
vector<double> e1(2); // (1,0)
e1[0] = 1;
vector<double> e2(2); // (0,1)
e2[1] = 1;
FunctionPtr u_prev = Teuchos::rcp( new PreviousSolutionFunction(backgroundFlow, u) );
FunctionPtr beta = e1 * u_prev + Teuchos::rcp( new ConstantVectorFunction( e2 ) );
// v:
// (sigma, grad v)_K - (sigma_hat_n, v)_dK - (u, beta dot grad v) + (u_hat * n dot beta, v)_dK
bf->addTerm( sigma1, v->dx() );
bf->addTerm( sigma2, v->dy() );
bf->addTerm( -u, beta * v->grad());
bf->addTerm( beta_n_u_minus_sigma_hat, v);
// ==================== SET INITIAL GUESS ==========================
mesh->registerSolution(backgroundFlow);
map<int, Teuchos::RCP<AbstractFunction> > functionMap;
functionMap[BurgersBilinearForm::U] = Teuchos::rcp(new InitialGuess());
functionMap[BurgersBilinearForm::SIGMA_1] = Teuchos::rcp(new ZeroFunction());
functionMap[BurgersBilinearForm::SIGMA_2] = Teuchos::rcp(new ZeroFunction());
backgroundFlow->projectOntoMesh(functionMap);
// ==================== END SET INITIAL GUESS ==========================
// compare stiffness matrices for first linear step:
int trialOrder = 1;
pToAdd = 0;
int testOrder = trialOrder + pToAdd;
CellTopoPtr quadTopoPtr = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >() ));
DofOrderingFactory dofOrderingFactory(bf);
DofOrderingPtr testOrdering = dofOrderingFactory.testOrdering(testOrder, *quadTopoPtr);
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
choice::MpiArgs args( argc, argv );
#else
choice::Args args( argc, argv );
#endif
int rank = Teuchos::GlobalMPISession::getRank();
int numProcs = Teuchos::GlobalMPISession::getNProc();
int nCells = args.Input<int>("--nCells", "num cells",2);
int numRefs = args.Input<int>("--numRefs","num adaptive refinements",0);
int numPreRefs = args.Input<int>("--numPreRefs","num preemptive adaptive refinements",0);
int order = args.Input<int>("--order","order of approximation",2);
double eps = args.Input<double>("--epsilon","diffusion parameter",1e-2);
double energyThreshold = args.Input<double>("-energyThreshold","energy thresh for adaptivity", .5);
double rampHeight = args.Input<double>("--rampHeight","ramp height at x = 2", 0.0);
double ipSwitch = args.Input<double>("--ipSwitch","point at which to switch to graph norm", 0.0); // default to 0 to remain on robust norm
bool useAnisotropy = args.Input<bool>("--useAnisotropy","aniso flag ", false);
int H1Order = order+1;
int pToAdd = args.Input<int>("--pToAdd","test space enrichment", 2);
FunctionPtr zero = Function::constant(0.0);
FunctionPtr one = Function::constant(1.0);
FunctionPtr n = Teuchos::rcp( new UnitNormalFunction );
vector<double> e1,e2;
e1.push_back(1.0);e1.push_back(0.0);
e2.push_back(0.0);e2.push_back(1.0);
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactory varFactory;
VarPtr tau = varFactory.testVar("\\tau", HDIV);
VarPtr v = varFactory.testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory.traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory.fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory.fieldVar("u");
VarPtr sigma1 = varFactory.fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory.fieldVar("\\sigma_2");
vector<double> beta;
beta.push_back(1.0);
beta.push_back(0.0);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// tau terms:
confusionBF->addTerm(sigma1 / eps, tau->x());
confusionBF->addTerm(sigma2 / eps, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(uhat, -tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( -u, beta * v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
// first order term with magnitude alpha
double alpha = 0.0;
// confusionBF->addTerm(alpha * u, v);
//////////////////// BUILD MESH ///////////////////////
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(nCells,confusionBF, H1Order, H1Order+pToAdd);
mesh->setPartitionPolicy(Teuchos::rcp(new ZoltanMeshPartitionPolicy("HSFC")));
MeshInfo meshInfo(mesh); // gets info like cell measure, etc
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
IPPtr ip = Teuchos::rcp(new IP);
/*
// robust test norm
FunctionPtr C_h = Teuchos::rcp( new EpsilonScaling(eps) );
FunctionPtr invH = Teuchos::rcp(new InvHScaling);
FunctionPtr invSqrtH = Teuchos::rcp(new InvSqrtHScaling);
FunctionPtr sqrtH = Teuchos::rcp(new SqrtHScaling);
FunctionPtr hSwitch = Teuchos::rcp(new HSwitch(ipSwitch,mesh));
ip->addTerm(hSwitch*sqrt(eps) * v->grad() );
ip->addTerm(hSwitch*beta * v->grad() );
ip->addTerm(hSwitch*tau->div() );
// graph norm
ip->addTerm( (one-hSwitch)*((1.0/eps) * tau + v->grad()));
ip->addTerm( (one-hSwitch)*(beta * v->grad() - tau->div()));
// regularizing terms
ip->addTerm(C_h/sqrt(eps) * tau );
ip->addTerm(invSqrtH*v);
*/
// robust test norm
IPPtr robIP = Teuchos::rcp(new IP);
//.........这里部分代码省略.........
示例6: main
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
choice::MpiArgs args( argc, argv );
#else
choice::Args args( argc, argv );
#endif
int commRank = Teuchos::GlobalMPISession::getRank();
int numProcs = Teuchos::GlobalMPISession::getNProc();
// Required arguments
double epsilon = args.Input<double>("--epsilon", "diffusion parameter");
int numRefs = args.Input<int>("--numRefs", "number of refinement steps");
bool enforceLocalConservation = args.Input<bool>("--conserve", "enforce local conservation");
int norm = args.Input<int>("--norm", "0 = graph\n 1 = robust\n 2 = modified robust");
// Optional arguments (have defaults)
bool zeroL2 = args.Input("--zeroL2", "take L2 term on v in robust norm to zero", false);
args.Process();
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactory varFactory;
VarPtr tau = varFactory.testVar("\\tau", HDIV);
VarPtr v = varFactory.testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory.traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory.fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory.fieldVar("u");
VarPtr sigma = varFactory.fieldVar("sigma", VECTOR_L2);
vector<double> beta;
beta.push_back(1.0);
beta.push_back(0.0);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr bf = Teuchos::rcp( new BF(varFactory) );
// tau terms:
bf->addTerm(sigma / epsilon, tau);
bf->addTerm(u, tau->div());
bf->addTerm(-uhat, tau->dot_normal());
// v terms:
bf->addTerm( sigma, v->grad() );
bf->addTerm( beta * u, - v->grad() );
bf->addTerm( beta_n_u_minus_sigma_n, v);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
IPPtr ip = Teuchos::rcp(new IP);
if (norm == 0)
{
ip = bf->graphNorm();
FunctionPtr h2_scaling = Teuchos::rcp( new ZeroMeanScaling );
ip->addZeroMeanTerm( h2_scaling*v );
}
// Robust norm
else if (norm == 1)
{
// robust test norm
FunctionPtr ip_scaling = Teuchos::rcp( new EpsilonScaling(epsilon) );
FunctionPtr h2_scaling = Teuchos::rcp( new ZeroMeanScaling );
if (!zeroL2)
ip->addTerm( v );
ip->addTerm( sqrt(epsilon) * v->grad() );
// Weight these two terms for inflow
ip->addTerm( beta * v->grad() );
ip->addTerm( tau->div() );
ip->addTerm( ip_scaling/sqrt(epsilon) * tau );
if (zeroL2)
ip->addZeroMeanTerm( h2_scaling*v );
}
// Modified robust norm
else if (norm == 2)
{
// robust test norm
FunctionPtr ip_scaling = Teuchos::rcp( new EpsilonScaling(epsilon) );
FunctionPtr h2_scaling = Teuchos::rcp( new ZeroMeanScaling );
// FunctionPtr ip_weight = Teuchos::rcp( new IPWeight() );
if (!zeroL2)
ip->addTerm( v );
ip->addTerm( sqrt(epsilon) * v->grad() );
ip->addTerm( beta * v->grad() );
ip->addTerm( tau->div() - beta*v->grad() );
ip->addTerm( ip_scaling/sqrt(epsilon) * tau );
if (zeroL2)
ip->addZeroMeanTerm( h2_scaling*v );
}
// // robust test norm
// IPPtr robIP = Teuchos::rcp(new IP);
// FunctionPtr ip_scaling = Teuchos::rcp( new EpsilonScaling(epsilon) );
// if (!enforceLocalConservation)
// robIP->addTerm( ip_scaling * v );
// robIP->addTerm( sqrt(epsilon) * v->grad() );
// // Weight these two terms for inflow
// FunctionPtr ip_weight = Teuchos::rcp( new IPWeight() );
// robIP->addTerm( ip_weight * beta * v->grad() );
// robIP->addTerm( ip_weight * tau->div() );
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[]) {
// Process command line arguments
if (argc > 1)
numRefs = atof(argv[1]);
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
int rank=mpiSession.getRank();
int numProcs=mpiSession.getNProc();
#else
int rank = 0;
int numProcs = 1;
#endif
FunctionPtr beta = Teuchos::rcp(new Beta());
////////////////////////////////////////////////////////////////////
// DEFINE VARIABLES
////////////////////////////////////////////////////////////////////
// test variables
VarFactory varFactory;
VarPtr tau = varFactory.testVar("\\tau", HDIV);
VarPtr v = varFactory.testVar("v", HGRAD);
// trial variables
VarPtr uhat = varFactory.traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory.fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory.fieldVar("u");
VarPtr sigma1 = varFactory.fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory.fieldVar("\\sigma_2");
////////////////////////////////////////////////////////////////////
// CREATE MESH
////////////////////////////////////////////////////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
FieldContainer<double> meshBoundary(4,2);
meshBoundary(0,0) = 0.0; // x1
meshBoundary(0,1) = -2.0; // y1
meshBoundary(1,0) = 4.0;
meshBoundary(1,1) = -2.0;
meshBoundary(2,0) = 4.0;
meshBoundary(2,1) = 2.0;
meshBoundary(3,0) = 0.0;
meshBoundary(3,1) = 2.0;
int horizontalCells = 4, verticalCells = 4;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = Mesh::buildQuadMesh(meshBoundary, horizontalCells, verticalCells,
confusionBF, H1Order, H1Order+pToAdd, false);
////////////////////////////////////////////////////////////////////
// INITIALIZE BACKGROUND 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) );
// ==================== SET INITIAL GUESS ==========================
double u_free = 0.0;
double sigma1_free = 0.0;
double sigma2_free = 0.0;
map<int, Teuchos::RCP<Function> > functionMap;
functionMap[u->ID()] = Teuchos::rcp( new ConstantScalarFunction(u_free) );
functionMap[sigma1->ID()] = Teuchos::rcp( new ConstantScalarFunction(sigma1_free) );
functionMap[sigma2->ID()] = Teuchos::rcp( new ConstantScalarFunction(sigma2_free) );
prevTimeFlow->projectOntoMesh(functionMap);
// ==================== END SET INITIAL GUESS ==========================
////////////////////////////////////////////////////////////////////
// DEFINE BILINEAR FORM
////////////////////////////////////////////////////////////////////
// tau terms:
confusionBF->addTerm(sigma1 / epsilon, tau->x());
confusionBF->addTerm(sigma2 / epsilon, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(-uhat, tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( beta * u, - v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
////////////////////////////////////////////////////////////////////
// TIMESTEPPING TERMS
////////////////////////////////////////////////////////////////////
Teuchos::RCP<RHSEasy> rhs = Teuchos::rcp( new RHSEasy );
double dt = 0.25;
FunctionPtr invDt = Teuchos::rcp(new ScalarParamFunction(1.0/dt));
//.........这里部分代码省略.........
示例8: testIntegrateDiscontinuousFunction
// tests whether a mixed type LT
bool ScratchPadTests::testIntegrateDiscontinuousFunction()
{
bool success = true;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr v = varFactory->testVar("v", HGRAD);
vector<double> beta;
beta.push_back(1.0);
beta.push_back(1.0);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = Teuchos::rcp(new IP);
ip->addTerm(v);
ip->addTerm(beta*v->grad());
// for projections
IPPtr ipL2 = Teuchos::rcp(new IP);
ipL2->addTerm(v);
// define trial variables
VarPtr beta_n_u = varFactory->fluxVar("\\widehat{\\beta \\cdot n }");
VarPtr u = varFactory->fieldVar("u");
//////////////////// BUILD MESH ///////////////////////
BFPtr convectionBF = Teuchos::rcp( new BF(varFactory) );
// v terms:
convectionBF->addTerm( -u, beta * v->grad() );
convectionBF->addTerm( beta_n_u, v);
// define nodes for mesh
int order = 1;
int H1Order = order+1;
int pToAdd = 1;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(2, 1, convectionBF, H1Order, H1Order+pToAdd);
//////////////////// integrate discontinuous function - cellIDFunction ///////////////////////
// FunctionPtr cellIDFxn = Teuchos::rcp(new CellIDFunction); // should be 0 on cellID 0, 1 on cellID 1
set<int> cellIDs;
cellIDs.insert(1); // 0 on cell 0, 1 on cell 1
FunctionPtr indicator = Teuchos::rcp(new IndicatorFunction(cellIDs)); // should be 0 on cellID 0, 1 on cellID 1
double jumpWeight = 13.3; // some random number
FunctionPtr edgeRestrictionFxn = Teuchos::rcp(new EdgeFunction);
FunctionPtr X = Function::xn(1);
LinearTermPtr integrandLT = Function::constant(1.0)*v + Function::constant(jumpWeight)*X*edgeRestrictionFxn*v;
// make riesz representation function to more closely emulate the error rep
LinearTermPtr indicatorLT = Teuchos::rcp(new LinearTerm);// residual
indicatorLT->addTerm(indicator*v);
Teuchos::RCP<RieszRep> riesz = Teuchos::rcp(new RieszRep(mesh, ipL2, indicatorLT));
riesz->computeRieszRep();
map<int,FunctionPtr> vmap;
vmap[v->ID()] = RieszRep::repFunction(v,riesz); // SHOULD BE L2 projection = same thing!!!
FunctionPtr volumeIntegrand = integrandLT->evaluate(vmap,false);
FunctionPtr edgeRestrictedIntegrand = integrandLT->evaluate(vmap,true);
double edgeRestrictedValue = volumeIntegrand->integrate(mesh,10) + edgeRestrictedIntegrand->integrate(mesh,10);
double expectedValue = .5 + .5*jumpWeight;
double diff = abs(expectedValue-edgeRestrictedValue);
if (abs(diff)>1e-11)
{
success = false;
cout << "Failed testIntegrateDiscontinuousFunction() with expectedValue = " << expectedValue << " and actual value = " << edgeRestrictedValue << endl;
}
return success;
}
示例9: testGalerkinOrthogonality
bool ScratchPadTests::testGalerkinOrthogonality()
{
double tol = 1e-11;
bool success = true;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr v = varFactory->testVar("v", HGRAD);
vector<double> beta;
beta.push_back(1.0);
beta.push_back(1.0);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = Teuchos::rcp(new IP);
ip->addTerm(v);
ip->addTerm(beta*v->grad());
// define trial variables
VarPtr beta_n_u = varFactory->fluxVar("\\widehat{\\beta \\cdot n }");
VarPtr u = varFactory->fieldVar("u");
//////////////////// BUILD MESH ///////////////////////
BFPtr convectionBF = Teuchos::rcp( new BF(varFactory) );
FunctionPtr n = Function::normal();
// v terms:
convectionBF->addTerm( -u, beta * v->grad() );
convectionBF->addTerm( beta_n_u, v);
// define nodes for mesh
int order = 2;
int H1Order = order+1;
int pToAdd = 1;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(4, convectionBF, H1Order, H1Order+pToAdd);
//////////////////// SOLVE ///////////////////////
RHSPtr rhs = RHS::rhs();
BCPtr bc = BC::bc();
SpatialFilterPtr inflowBoundary = Teuchos::rcp( new InflowSquareBoundary );
SpatialFilterPtr outflowBoundary = Teuchos::rcp( new NegatedSpatialFilter(inflowBoundary) );
FunctionPtr uIn;
uIn = Teuchos::rcp(new Uinflow); // uses a discontinuous piecewise-constant basis function on left and bottom sides of square
bc->addDirichlet(beta_n_u, inflowBoundary, beta*n*uIn);
Teuchos::RCP<Solution> solution;
solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
solution->solve(false);
FunctionPtr uFxn = Function::solution(u, solution);
FunctionPtr fnhatFxn = Function::solution(beta_n_u,solution);
// make residual for riesz representation function
LinearTermPtr residual = Teuchos::rcp(new LinearTerm);// residual
FunctionPtr parity = Function::sideParity();
residual->addTerm(-fnhatFxn*v + (beta*uFxn)*v->grad());
Teuchos::RCP<RieszRep> riesz = Teuchos::rcp(new RieszRep(mesh, ip, residual));
riesz->computeRieszRep();
map<int,FunctionPtr> err_rep_map;
err_rep_map[v->ID()] = RieszRep::repFunction(v,riesz);
//////////////////// GET BOUNDARY CONDITION DATA ///////////////////////
FieldContainer<GlobalIndexType> bcGlobalIndices;
FieldContainer<double> bcGlobalValues;
mesh->boundary().bcsToImpose(bcGlobalIndices,bcGlobalValues,*(solution->bc()), NULL);
set<int> bcInds;
for (int i=0; i<bcGlobalIndices.dimension(0); i++)
{
bcInds.insert(bcGlobalIndices(i));
}
//////////////////// CHECK GALERKIN ORTHOGONALITY ///////////////////////
BCPtr nullBC;
RHSPtr nullRHS;
IPPtr nullIP;
SolutionPtr solnPerturbation = Teuchos::rcp(new Solution(mesh, nullBC, nullRHS, nullIP) );
map< int, vector<DofInfo> > infoMap = constructGlobalDofToLocalDofInfoMap(mesh);
for (map< int, vector<DofInfo> >::iterator mapIt = infoMap.begin();
mapIt != infoMap.end(); mapIt++)
{
int dofIndex = mapIt->first;
vector< DofInfo > dofInfoVector = mapIt->second; // all the local dofs that map to dofIndex
// create perturbation in direction du
solnPerturbation->clear(); // clear all solns
// set each corresponding local dof to 1.0
for (vector< DofInfo >::iterator dofInfoIt = dofInfoVector.begin();
dofInfoIt != dofInfoVector.end(); dofInfoIt++)
{
//.........这里部分代码省略.........
示例10: testResidualMemoryError
bool ScratchPadTests::testResidualMemoryError()
{
int rank = Teuchos::GlobalMPISession::getRank();
double tol = 1e-11;
bool success = true;
int nCells = 2;
double eps = 1e-2;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr tau = varFactory->testVar("\\tau", HDIV);
VarPtr v = varFactory->testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory->traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory->fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory->fieldVar("u");
VarPtr sigma1 = varFactory->fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory->fieldVar("\\sigma_2");
vector<double> beta;
beta.push_back(1.0);
beta.push_back(0.0);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// tau terms:
confusionBF->addTerm(sigma1 / eps, tau->x());
confusionBF->addTerm(sigma2 / eps, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(uhat, -tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( -u, beta * v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr robIP = Teuchos::rcp(new IP);
robIP->addTerm(tau);
robIP->addTerm(tau->div());
robIP->addTerm(v->grad());
robIP->addTerm(v);
//////////////////// SPECIFY RHS ///////////////////////
FunctionPtr zero = Function::constant(0.0);
FunctionPtr one = Function::constant(1.0);
RHSPtr rhs = RHS::rhs();
FunctionPtr f = zero;
// FunctionPtr f = one;
rhs->addTerm( f * v ); // obviously, with f = 0 adding this term is not necessary!
//////////////////// CREATE BCs ///////////////////////
BCPtr bc = BC::bc();
SpatialFilterPtr inflowBoundary = Teuchos::rcp( new LRInflowSquareBoundary );
SpatialFilterPtr outflowBoundary = Teuchos::rcp( new LROutflowSquareBoundary);
FunctionPtr n = Function::normal();
vector<double> e1,e2;
e1.push_back(1.0);
e1.push_back(0.0);
e2.push_back(0.0);
e2.push_back(1.0);
bc->addDirichlet(beta_n_u_minus_sigma_n, inflowBoundary, beta*n*one);
bc->addDirichlet(uhat, outflowBoundary, zero);
//////////////////// BUILD MESH ///////////////////////
// define nodes for mesh
int order = 2;
int H1Order = order+1;
int pToAdd = 2;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(nCells,confusionBF, H1Order, H1Order+pToAdd);
// mesh->setPartitionPolicy(Teuchos::rcp(new ZoltanMeshPartitionPolicy("HSFC")));
//////////////////// SOLVE & REFINE ///////////////////////
Teuchos::RCP<Solution> solution;
solution = Teuchos::rcp( new Solution(mesh, bc, rhs, robIP) );
solution->solve(false);
mesh->registerSolution(solution);
double energyErr1 = solution->energyErrorTotal();
LinearTermPtr residual = rhs->linearTermCopy();
residual->addTerm(-confusionBF->testFunctional(solution));
RieszRepPtr rieszResidual = Teuchos::rcp(new RieszRep(mesh, robIP, residual));
rieszResidual->computeRieszRep();
FunctionPtr e_v = RieszRep::repFunction(v,rieszResidual);
//.........这里部分代码省略.........
示例11: testLinearTermEvaluationConsistency
// tests whether a mixed type LT
bool ScratchPadTests::testLinearTermEvaluationConsistency()
{
bool success = true;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr v = varFactory->testVar("v", HGRAD);
vector<double> beta;
beta.push_back(1.0);
beta.push_back(1.0);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = Teuchos::rcp(new IP);
ip->addTerm(v);
ip->addTerm(beta*v->grad());
// define trial variables
VarPtr beta_n_u = varFactory->fluxVar("\\widehat{\\beta \\cdot n }");
VarPtr u = varFactory->fieldVar("u");
//////////////////// BUILD MESH ///////////////////////
BFPtr convectionBF = Teuchos::rcp( new BF(varFactory) );
// v terms:
convectionBF->addTerm( -u, beta * v->grad() );
convectionBF->addTerm( beta_n_u, v);
// define nodes for mesh
int order = 1;
int H1Order = order+1;
int pToAdd = 1;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(1, convectionBF, H1Order, H1Order+pToAdd);
//////////////////// get fake residual ///////////////////////
LinearTermPtr lt = Teuchos::rcp(new LinearTerm);
FunctionPtr edgeFxn = Teuchos::rcp(new EdgeFunction);
FunctionPtr Xsq = Function::xn(2);
FunctionPtr Ysq = Function::yn(2);
FunctionPtr XYsq = Xsq*Ysq;
lt->addTerm(edgeFxn*v + (beta*XYsq)*v->grad());
Teuchos::RCP<RieszRep> ltRiesz = Teuchos::rcp(new RieszRep(mesh, ip, lt));
ltRiesz->computeRieszRep();
FunctionPtr repFxn = RieszRep::repFunction(v,ltRiesz);
map<int,FunctionPtr> rep_map;
rep_map[v->ID()] = repFxn;
FunctionPtr edgeLt = lt->evaluate(rep_map, true) ;
FunctionPtr elemLt = lt->evaluate(rep_map, false);
double edgeVal = edgeLt->integrate(mesh,10);
double elemVal = elemLt->integrate(mesh,10);
LinearTermPtr edgeOnlyLt = Teuchos::rcp(new LinearTerm);// residual
edgeOnlyLt->addTerm(edgeFxn*v);
FunctionPtr edgeOnly = edgeOnlyLt->evaluate(rep_map,true);
double edgeOnlyVal = edgeOnly->integrate(mesh,10);
double diff = edgeOnlyVal-edgeVal;
if (abs(diff)>1e-11)
{
success = false;
cout << "Failed testLinearTermEvaluationConsistency() with diff = " << diff << endl;
}
return success;
}
示例12: testLTResidual
// tests to make sure the energy error calculated thru direct integration works for vector valued test functions too
bool ScratchPadTests::testLTResidual()
{
double tol = 1e-11;
int rank = Teuchos::GlobalMPISession::getRank();
bool success = true;
int nCells = 2;
double eps = .1;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr tau = varFactory->testVar("\\tau", HDIV);
VarPtr v = varFactory->testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory->traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory->fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory->fieldVar("u");
VarPtr sigma1 = varFactory->fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory->fieldVar("\\sigma_2");
vector<double> beta;
beta.push_back(1.0);
beta.push_back(0.0);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// tau terms:
confusionBF->addTerm(sigma1 / eps, tau->x());
confusionBF->addTerm(sigma2 / eps, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(uhat, -tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( -u, beta * v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = Teuchos::rcp(new IP);
// choose the mesh-independent norm even though it may have boundary layers
ip->addTerm(v->grad());
ip->addTerm(v);
ip->addTerm(tau);
ip->addTerm(tau->div());
//////////////////// SPECIFY RHS AND HELPFUL FUNCTIONS ///////////////////////
FunctionPtr n = Function::normal();
vector<double> e1,e2;
e1.push_back(1.0);
e1.push_back(0.0);
e2.push_back(0.0);
e2.push_back(1.0);
FunctionPtr one = Function::constant(1.0);
FunctionPtr zero = Function::constant(0.0);
RHSPtr rhs = RHS::rhs();
FunctionPtr f = one; // if this is set to zero instead, we pass the test (a clue?)
rhs->addTerm( f * v );
//////////////////// CREATE BCs ///////////////////////
BCPtr bc = BC::bc();
SpatialFilterPtr squareBoundary = Teuchos::rcp( new SquareBoundary );
bc->addDirichlet(uhat, squareBoundary, one);
//////////////////// BUILD MESH ///////////////////////
// define nodes for mesh
int order = 2;
int H1Order = order+1;
int pToAdd = 2;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(nCells,confusionBF, H1Order, H1Order+pToAdd);
//////////////////// SOLVE & REFINE ///////////////////////
Teuchos::RCP<Solution> solution;
solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
solution->solve(false);
double energyError = solution->energyErrorTotal();
LinearTermPtr residual = rhs->linearTermCopy();
residual->addTerm(-confusionBF->testFunctional(solution),true);
// FunctionPtr uh = Function::solution(uhat,solution);
// FunctionPtr fn = Function::solution(beta_n_u_minus_sigma_n,solution);
// FunctionPtr uF = Function::solution(u,solution);
// FunctionPtr sigma = e1*Function::solution(sigma1,solution)+e2*Function::solution(sigma2,solution);
// residual->addTerm(- (fn*v - uh*tau->dot_normal()));
//.........这里部分代码省略.........
示例13: testLTResidualSimple
// tests residual computation on simple convection
bool ScratchPadTests::testLTResidualSimple()
{
double tol = 1e-11;
int rank = Teuchos::GlobalMPISession::getRank();
bool success = true;
int nCells = 2;
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactoryPtr varFactory = VarFactory::varFactory();
VarPtr v = varFactory->testVar("v", HGRAD);
// define trial variables
VarPtr beta_n_u = varFactory->fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u = varFactory->fieldVar("u");
vector<double> beta;
beta.push_back(1.0);
beta.push_back(1.0);
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// v terms:
confusionBF->addTerm( -u, beta * v->grad() );
confusionBF->addTerm( beta_n_u, v);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// robust test norm
IPPtr ip = Teuchos::rcp(new IP);
// choose the mesh-independent norm even though it may have BLs
ip->addTerm(v->grad());
ip->addTerm(v);
//////////////////// SPECIFY RHS AND HELPFUL FUNCTIONS ///////////////////////
FunctionPtr n = Function::normal();
vector<double> e1,e2;
e1.push_back(1.0);
e1.push_back(0.0);
e2.push_back(0.0);
e2.push_back(1.0);
FunctionPtr one = Function::constant(1.0);
FunctionPtr zero = Function::constant(0.0);
RHSPtr rhs = RHS::rhs();
FunctionPtr f = one;
rhs->addTerm( f * v );
//////////////////// CREATE BCs ///////////////////////
BCPtr bc = BC::bc();
SpatialFilterPtr boundary = Teuchos::rcp( new InflowSquareBoundary );
FunctionPtr u_in = Teuchos::rcp(new Uinflow);
bc->addDirichlet(beta_n_u, boundary, beta*n*u_in);
//////////////////// BUILD MESH ///////////////////////
// define nodes for mesh
int order = 2;
int H1Order = order+1;
int pToAdd = 2;
// create a pointer to a new mesh:
Teuchos::RCP<Mesh> mesh = MeshUtilities::buildUnitQuadMesh(nCells,confusionBF, H1Order, H1Order+pToAdd);
//////////////////// SOLVE & REFINE ///////////////////////
int cubEnrich = 0;
Teuchos::RCP<Solution> solution;
solution = Teuchos::rcp( new Solution(mesh, bc, rhs, ip) );
solution->solve(false);
double energyError = solution->energyErrorTotal();
LinearTermPtr residual = rhs->linearTermCopy();
residual->addTerm(-confusionBF->testFunctional(solution),true);
Teuchos::RCP<RieszRep> rieszResidual = Teuchos::rcp(new RieszRep(mesh, ip, residual));
rieszResidual->computeRieszRep(cubEnrich);
double energyErrorLT = rieszResidual->getNorm();
bool testVsTest = true;
FunctionPtr e_v = RieszRep::repFunction(v,rieszResidual);
map<int,FunctionPtr> errFxns;
errFxns[v->ID()] = e_v;
FunctionPtr err = (ip->evaluate(errFxns,false))->evaluate(errFxns,false); // don't need boundary terms unless they're in IP
double energyErrorIntegrated = sqrt(err->integrate(mesh,cubEnrich,testVsTest));
// check that energy error computed thru Solution and through rieszRep are the same
success = abs(energyError-energyErrorLT) < tol;
if (success==false)
{
if (rank==0)
cout << "Failed testLTResidualSimple; energy error = " << energyError << ", while linearTerm error is computed to be " << energyErrorLT << endl;
return success;
}
//.........这里部分代码省略.........
示例14: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); // initialize MPI
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
int numElements = 3;
vector<vector<double>> domainDim(3,vector<double>{0.0,1.0}); // first index: spaceDim; second: 0/1 for x0, x1, etc.
int polyOrder = 2, delta_k = 1;
int spaceDim = 2;
cmdp.setOption("numElements", &numElements );
cmdp.setOption("polyOrder", &polyOrder );
cmdp.setOption("delta_k", &delta_k );
cmdp.setOption("x0", &domainDim[0][0] );
cmdp.setOption("x1", &domainDim[0][1] );
cmdp.setOption("y0", &domainDim[1][0] );
cmdp.setOption("y1", &domainDim[1][1] );
cmdp.setOption("z0", &domainDim[2][0] );
cmdp.setOption("z1", &domainDim[2][1] );
cmdp.setOption("spaceDim", &spaceDim);
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
vector<double> x0(spaceDim);
vector<double> domainSize(spaceDim);
vector<int> elementCounts(spaceDim);
for (int d=0; d<spaceDim; d++)
{
x0[d] = domainDim[d][0];
domainSize[d] = domainDim[d][1] - x0[d];
elementCounts[d] = numElements;
}
bool conformingTraces = true; // no difference for primal/continuous formulations
PoissonFormulation formCG(spaceDim, conformingTraces, PoissonFormulation::CONTINUOUS_GALERKIN);
VarPtr q = formCG.q();
VarPtr phi = formCG.phi();
BFPtr bf = formCG.bf();
MeshPtr bubnovMesh = MeshFactory::rectilinearMesh(bf, domainSize, elementCounts, polyOrder, 0, x0);
// Right now, hanging nodes don't work with continuous field variables
// there is a GDAMinimumRule test demonstrating the failure, SolvePoisson2DContinuousGalerkinHangingNode.
// make a mesh with hanging nodes (when spaceDim > 1)
// {
// set<GlobalIndexType> cellsToRefine = {0};
// bubnovMesh->hRefine(cellsToRefine);
// }
RHSPtr rhs = RHS::rhs();
rhs->addTerm(1.0 * q); // unit forcing
IPPtr ip = Teuchos::null; // will give Bubnov-Galerkin
BCPtr bc = BC::bc();
bc->addDirichlet(phi, SpatialFilter::allSpace(), Function::zero());
SolutionPtr solution = Solution::solution(bf, bubnovMesh, bc, rhs, ip);
solution->solve();
HDF5Exporter exporter(bubnovMesh, "PoissonContinuousGalerkin");
exporter.exportSolution(solution);
/**** Sort-of-primal experiment ****/
// an experiment: try doing "primal" DPG with IBP to the boundary
// ip = IP::ip();
// ip->addTerm(q->grad());
// ip->addTerm(q);
//
// solution = Solution::solution(bf, bubnovMesh, bc, rhs, ip);
// solution->solve();
//
// HDF5Exporter primalNoFluxExporter(bubnovMesh, "PoissonPrimalNoFlux");
// primalNoFluxExporter.exportSolution(solution);
//*** Primal Formulation ***//
PoissonFormulation form(spaceDim, conformingTraces, PoissonFormulation::PRIMAL);
q = form.q();
phi = form.phi();
bf = form.bf();
bc = BC::bc();
bc->addDirichlet(phi, SpatialFilter::allSpace(), Function::zero());
rhs = RHS::rhs();
rhs->addTerm(1.0 * q); // unit forcing
MeshPtr primalMesh = MeshFactory::rectilinearMesh(bf, domainSize, elementCounts, polyOrder, delta_k, x0);
ip = IP::ip();
ip->addTerm(q->grad());
ip->addTerm(q);
// Right now, hanging nodes don't work with continuous field variables
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
int rank=mpiSession.getRank();
int numProcs=mpiSession.getNProc();
#else
int rank = 0;
int numProcs = 1;
#endif
bool useCompliantGraphNorm = false;
bool enforceOneIrregularity = true;
bool writeStiffnessMatrices = false;
bool writeWorstCaseGramMatrices = false;
int numRefs = 10;
// problem parameters:
double eps = 1e-8;
vector<double> beta_const;
beta_const.push_back(2.0);
beta_const.push_back(1.0);
int k = 2, delta_k = 2;
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
cmdp.setOption("polyOrder",&k,"polynomial order for field variable u");
cmdp.setOption("delta_k", &delta_k, "test space polynomial order enrichment");
cmdp.setOption("numRefs",&numRefs,"number of refinements");
cmdp.setOption("eps", &eps, "epsilon");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
int H1Order = k + 1;
if (rank==0) {
string normChoice = useCompliantGraphNorm ? "unit-compliant graph norm" : "standard graph norm";
cout << "Using " << normChoice << "." << endl;
cout << "eps = " << eps << endl;
cout << "numRefs = " << numRefs << endl;
cout << "p = " << k << endl;
}
//////////////////// DECLARE VARIABLES ///////////////////////
// define test variables
VarFactory varFactory;
VarPtr tau = varFactory.testVar("\\tau", HDIV);
VarPtr v = varFactory.testVar("v", HGRAD);
// define trial variables
VarPtr uhat = varFactory.traceVar("\\widehat{u}");
VarPtr beta_n_u_minus_sigma_n = varFactory.fluxVar("\\widehat{\\beta \\cdot n u - \\sigma_{n}}");
VarPtr u;
if (useCompliantGraphNorm) {
u = varFactory.fieldVar("u",HGRAD);
} else {
u = varFactory.fieldVar("u");
}
VarPtr sigma1 = varFactory.fieldVar("\\sigma_1");
VarPtr sigma2 = varFactory.fieldVar("\\sigma_2");
//////////////////// DEFINE BILINEAR FORM ///////////////////////
BFPtr confusionBF = Teuchos::rcp( new BF(varFactory) );
// tau terms:
confusionBF->addTerm(sigma1 / eps, tau->x());
confusionBF->addTerm(sigma2 / eps, tau->y());
confusionBF->addTerm(u, tau->div());
confusionBF->addTerm(-uhat, tau->dot_normal());
// v terms:
confusionBF->addTerm( sigma1, v->dx() );
confusionBF->addTerm( sigma2, v->dy() );
confusionBF->addTerm( beta_const * u, - v->grad() );
confusionBF->addTerm( beta_n_u_minus_sigma_n, v);
//////////////////// DEFINE INNER PRODUCT(S) ///////////////////////
// mathematician's norm
IPPtr mathIP = Teuchos::rcp(new IP());
mathIP->addTerm(tau);
mathIP->addTerm(tau->div());
mathIP->addTerm(v);
mathIP->addTerm(v->grad());
// quasi-optimal norm
IPPtr qoptIP = Teuchos::rcp(new IP);
if (!useCompliantGraphNorm) {
qoptIP->addTerm( tau / eps + v->grad() );
qoptIP->addTerm( beta_const * v->grad() - tau->div() );
qoptIP->addTerm( v );
} else {
FunctionPtr h = Teuchos::rcp( new hFunction );
//.........这里部分代码省略.........