本文整理汇总了C++中SolutionPtr::getStiffnessMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::getStiffnessMatrix方法的具体用法?C++ SolutionPtr::getStiffnessMatrix怎么用?C++ SolutionPtr::getStiffnessMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::getStiffnessMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
double xLeft = 0.0, xRight = 1.0;
int polyOrder = 1, delta_k = 1;
cmdp.setOption("numElements", &numElements );
cmdp.setOption("polyOrder", &polyOrder );
cmdp.setOption("delta_k", &delta_k );
cmdp.setOption("xLeft", &xLeft );
cmdp.setOption("xRight", &xRight );
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
int spaceDim = 1;
bool conformingTraces = true; // conformingTraces argument has no effect in 1D
PoissonFormulation poissonForm(spaceDim, conformingTraces);
MeshPtr mesh = MeshFactory::intervalMesh(poissonForm.bf(), xLeft, xRight, numElements, polyOrder + 1, delta_k); // 1D equispaced
RHSPtr rhs = RHS::rhs(); // zero RHS
IPPtr ip = poissonForm.bf()->graphNorm();
BCPtr bc = BC::bc();
bc->addDirichlet(poissonForm.phi_hat(), SpatialFilter::allSpace(), Function::zero());
SolutionPtr solution = Solution::solution(poissonForm.bf(), mesh, bc, rhs, ip);
solution->solve();
GDAMinimumRule* minRule = dynamic_cast<GDAMinimumRule*>(mesh->globalDofAssignment().get());
// minRule->printGlobalDofInfo();
Teuchos::RCP<Epetra_CrsMatrix> A = solution->getStiffnessMatrix();
EpetraExt::RowMatrixToMatrixMarketFile("A.dat",*A, NULL, NULL, false);
HDF5Exporter exporter(mesh);
return 0;
}
示例2: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpiSession(&argc, &argv, 0);
int spaceDim = 2;
int meshWidth = 2;
bool conformingTraces = true;
int H1Order = 2, delta_k = 3;
double domainWidth = 1.0e-3;
bool diagScaling = false;
double h = domainWidth / meshWidth;
double weight = h / 4.0; // ratio of area of square with sidelength h to its perimeter
double sigma_weight = 1.0; // h / 4.0; // sigma = sigma_weight * u->grad()
Space uHatSpace = conformingTraces ? HGRAD : L2;
VarFactoryPtr vf = VarFactory::varFactory();
// fields
VarPtr u = vf->fieldVar("u");
VarPtr sigma = vf->fieldVar("sigma", VECTOR_L2);
// traces
VarPtr u_hat = vf->traceVar("u_hat", uHatSpace);
VarPtr sigma_n = vf->fluxVar("sigma_n");
// tests
VarPtr v = vf->testVar("v", HGRAD);
VarPtr tau = vf->testVar("tau", HDIV);
BFPtr bf = BF::bf(vf);
// standard BF:
// bf->addTerm(sigma, v->grad());
// bf->addTerm(sigma_n, v);
//
// bf->addTerm(sigma, tau);
// bf->addTerm(u, tau->div());
// bf->addTerm(-u_hat, tau->dot_normal());
// weighted BF:
bf->addTerm(sigma, v->grad());
bf->addTerm(weight * sigma_n, v);
bf->addTerm(sigma, tau);
bf->addTerm(sigma_weight * u, tau->div());
bf->addTerm(- sigma_weight * weight * u_hat, tau->dot_normal());
IPPtr ip = IP::ip();
// standard IP:
ip->addTerm(tau + v->grad());
ip->addTerm(tau->div());
ip->addTerm(v);
ip->addTerm(tau);
// weighted IP:
// ip->addTerm(tau + v->grad());
// ip->addTerm(sigma_weight * tau->div());
// ip->addTerm(max(sigma_weight,1e-3) * v);
// ip->addTerm(sigma_weight * weight * tau);
BCPtr bc = BC::bc();
bc->addDirichlet(u_hat, SpatialFilter::allSpace(), Function::zero());
RHSPtr rhs = RHS::rhs();
rhs->addTerm(1.0 * sigma_weight * v);
vector<double> dimensions(spaceDim,domainWidth);
vector<int> elementCounts(spaceDim,meshWidth);
MeshPtr mesh = MeshFactory::rectilinearMesh(bf, dimensions, elementCounts, H1Order, delta_k);
SolutionPtr soln = Solution::solution(mesh, bc, rhs, ip);
soln->setUseCondensedSolve(true);
soln->initializeLHSVector();
soln->initializeStiffnessAndLoad();
soln->populateStiffnessAndLoad();
Teuchos::RCP<Epetra_RowMatrix> stiffness = soln->getStiffnessMatrix();
double condNumber = conditionNumberLAPACK(*stiffness, diagScaling);
cout << "condest (1-norm): " << condNumber << endl;
return 0;
}