本文整理汇总了C++中loca::ParameterVector类的典型用法代码示例。如果您正苦于以下问题:C++ ParameterVector类的具体用法?C++ ParameterVector怎么用?C++ ParameterVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParameterVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setParameters
void Problem_Interface::setParameters(const LOCA::ParameterVector& params)
{
problem.setParameters(params.getValue("alpha"),
params.getValue("beta"),
params.getValue("D1"),
params.getValue("D2"));
}
示例2:
// ============================================================================
// Set parameters
void Ginla::Perturbation::Quadrants::
setParameters( const LOCA::ParameterVector & p )
{
TEST_FOR_EXCEPTION ( !p.isParameter ( "Epsilon Quadrant 1" ),
std::logic_error,
"Label \"Epsilon Quadrant 1\" not valid." );
epsilonQuadrant1_ = p.getValue ( "Epsilon Quadrant 1" );
return;
}
示例3:
// ============================================================================
bool
Ginla::MagneticVectorPotential::X::
setParameters( const LOCA::ParameterVector & p )
{
bool valuesChanged = false;
if (p.isParameter( "H0" ))
if ( mu_ != p.getValue ( "H0" ) )
{
mu_ = p.getValue ( "H0" );
valuesChanged = true;
}
return valuesChanged;
}
示例4: resetIsValid
void
LOCA::MultiContinuation::ConstrainedGroup::setParams(
const LOCA::ParameterVector& p)
{
grpPtr->setParams(p);
for (int i=0; i<p.length(); i++)
constraintsPtr->setParam(i, p[i]);
for (int i=0; i<numParams; i++)
xVec->getScalar(i) = p[constraintParamIDs[i]];
resetIsValid();
}
示例5:
// ============================================================================
bool
Ginla::MagneticVectorPotential::ZSquareSymmetric::
setParameters( const LOCA::ParameterVector & p )
{
bool valuesChanged = false;
if (p.isParameter( "H0" ))
if ( mu_ != p.getValue ( "H0" ) )
{
mu_ = p.getValue ( "H0" );
valuesChanged = true;
}
if (p.isParameter( "edge length" ))
if ( edgeLength_ != p.getValue ( "edge length" ) )
{
edgeLength_ = p.getValue ( "edge length" );
valuesChanged = true;
}
return valuesChanged;
}
示例6: main
int main(int argc, char *argv[])
{
int n = 100;
double alpha = 0.0;
double beta = 0.0;
double scale = 1.0;
int maxNewtonIters = 20;
int ierr = 0;
alpha = alpha / scale;
try {
bool verbose = false;
// Check for verbose output
if (argc>1)
if (argv[1][0]=='-' && argv[1][1]=='v')
verbose = true;
// Create parameter list
Teuchos::RCP<Teuchos::ParameterList> paramList =
Teuchos::rcp(new Teuchos::ParameterList);
// Create LOCA sublist
Teuchos::ParameterList& locaParamsList = paramList->sublist("LOCA");
// Create the stepper sublist and set the stepper parameters
Teuchos::ParameterList& stepperList = locaParamsList.sublist("Stepper");
stepperList.set("Continuation Parameter", "alpha");
stepperList.set("Initial Value", alpha);
stepperList.set("Max Value", 5.0/scale);
stepperList.set("Min Value", 0.0/scale);
stepperList.set("Max Steps", 50);
stepperList.set("Max Nonlinear Iterations", maxNewtonIters);
// Create step size sublist
Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size");
stepSizeList.set("Initial Step Size", 0.1/scale);
stepSizeList.set("Min Step Size", 1.0e-3/scale);
stepSizeList.set("Max Step Size", 10.0/scale);
// Create the "Solver" parameters sublist to be used with NOX Solvers
Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
if (verbose)
nlPrintParams.set("Output Information",
NOX::Utils::Error +
NOX::Utils::Details +
NOX::Utils::OuterIteration +
NOX::Utils::InnerIteration +
NOX::Utils::Warning +
NOX::Utils::TestDetails +
NOX::Utils::StepperIteration +
NOX::Utils::StepperDetails +
NOX::Utils::StepperParameters);
else
nlPrintParams.set("Output Information", NOX::Utils::Error);
// Create global data object
Teuchos::RCP<LOCA::GlobalData> globalData =
LOCA::createGlobalData(paramList);
// Set up the problem interface
ChanProblemInterface chan(globalData, n, alpha, beta, scale);
LOCA::ParameterVector p;
p.addParameter("alpha",alpha);
p.addParameter("beta",beta);
p.addParameter("scale",scale);
// Create a group which uses that problem interface. The group will
// be initialized to contain the default initial guess for the
// specified problem.
Teuchos::RCP<LOCA::MultiContinuation::AbstractGroup> grp =
Teuchos::rcp(new LOCA::LAPACK::Group(globalData, chan));
grp->setParams(p);
// Set up the status tests
Teuchos::RCP<NOX::StatusTest::NormF> normF =
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8));
Teuchos::RCP<NOX::StatusTest::MaxIters> maxIters =
Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters));
Teuchos::RCP<NOX::StatusTest::Generic> comboOR =
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR,
normF,
maxIters));
// Create the stepper
LOCA::Stepper stepper(globalData, grp, comboOR, paramList);
// Perform continuation run
LOCA::Abstract::Iterator::IteratorStatus status = stepper.run();
// Check for convergence
if (status != LOCA::Abstract::Iterator::Finished) {
ierr = 1;
if (globalData->locaUtils->isPrintType(NOX::Utils::Error))
globalData->locaUtils->out()
<< "Stepper failed to converge!" << std::endl;
}
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = ixyzt;
// Create the Linear System
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = ixyzt;
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
iReq, iJac, Axyzt,
solnxyzt));
#endif
NOX::Epetra::Vector initialGuess(solnxyzt);
#else
// Use an Epetra Scaling object if desired
Teuchos::RCP<Epetra_Vector> scaleVec =
Teuchos::rcp(new Epetra_Vector(soln));
NOX::Epetra::Scaling scaling;
scaling.addRowSumScaling(NOX::Epetra::Scaling::Left, scaleVec);
Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface;
// Create the Linear System
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
iReq, iJac, A, soln));
//&scaling);
// Create the Group
NOX::Epetra::Vector initialGuess(Teuchos::rcp(&soln,false),
NOX::Epetra::Vector::CreateView,
NOX::DeepCopy);
#endif
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("alpha",0.6);
pVector.addParameter("beta",2.0);
// Create Epetra factory
Teuchos::RCP<LOCA::Abstract::Factory> epetraFactory =
Teuchos::rcp(new LOCA::Epetra::Factory);
// Create global data object
Teuchos::RCP<LOCA::GlobalData> globalData =
LOCA::createGlobalData(paramList, epetraFactory);
Teuchos::RCP<LOCA::Epetra::Group> grp =
Teuchos::rcp(new LOCA::Epetra::Group(globalData, printParams,
iReq, initialGuess, linSys, pVector));
grp->computeF();
// Create the convergence tests
Teuchos::RCP<NOX::StatusTest::NormF> absresid =
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8,
NOX::StatusTest::NormF::Unscaled));
//NOX::StatusTest::NormF relresid(*grp.get(), 1.0e-2);
//NOX::StatusTest::NormUpdate update(1.0e-5);
//NOX::StatusTest::NormWRMS wrms(1.0e-2, 1.0e-8);
//NOX::StatusTest::Combo converged(NOX::StatusTest::Combo::AND);
//converged.addStatusTest(absresid);
//converged.addStatusTest(relresid);
//converged.addStatusTest(wrms);
//converged.addStatusTest(update);
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters =
Teuchos::rcp(new NOX::StatusTest::MaxIters(50));
Teuchos::RCP<NOX::StatusTest::Combo> combo =
示例8: tcubed_test
//.........这里部分代码省略.........
nlPrintParams.set("Output Precision", 4);
if (verbose)
nlPrintParams.set("Output Information",
NOX::Utils::OuterIteration +
NOX::Utils::OuterIterationStatusTest +
NOX::Utils::InnerIteration +
NOX::Utils::Details +
NOX::Utils::LinearSolverDetails +
NOX::Utils::Warning +
NOX::Utils::TestDetails +
NOX::Utils::Error +
NOX::Utils::StepperIteration +
NOX::Utils::StepperDetails +
NOX::Utils::StepperParameters);
else
nlPrintParams.set("Output Information", NOX::Utils::Error);
// Create the "Linear Solver" sublist for Newton's method
Teuchos::ParameterList& dirParams = nlParams.sublist("Direction");
Teuchos::ParameterList& newParams = dirParams.sublist("Newton");
Teuchos::ParameterList& lsParams = newParams.sublist("Linear Solver");
lsParams.set("Aztec Solver", "GMRES");
lsParams.set("Max Iterations", 200);
lsParams.set("Tolerance", 1e-6);
lsParams.set("Output Frequency", 50);
//lsParams.set("Scaling", "None");
//lsParams.set("Scaling", "Row Sum");
lsParams.set("Compute Scaling Manually", false);
//lsParams.set("Preconditioner", "Ifpack");
lsParams.set("Preconditioner", "New Ifpack");
lsParams.set("Ifpack Preconditioner", "ILU");
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("Nonlinear Factor",nonlinear_factor);
pVector.addParameter("Left BC", left_bc);
pVector.addParameter("Right BC", right_bc);
// Create the interface between the test problem and the nonlinear solver
// This is created by the user using inheritance of the abstract base class
Teuchos::RCP<Problem_Interface> interface =
Teuchos::rcp(new Problem_Interface(Problem));
Teuchos::RCP<LOCA::Epetra::Interface::TimeDependent> iReq = interface;
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
// Create the Epetra_RowMatrixfor the Jacobian/Preconditioner
Teuchos::RCP<Epetra_RowMatrix> Amat =
Teuchos::rcp(&Problem.getJacobian(),false);
// Create scaling object
Teuchos::RCP<NOX::Epetra::Scaling> scaling = Teuchos::null;
// scaling = Teuchos::rcp(new NOX::Epetra::Scaling);
// Teuchos::RCP<Epetra_Vector> scalingVector =
// Teuchos::rcp(new Epetra_Vector(soln.Map()));
// //scaling->addRowSumScaling(NOX::Epetra::Scaling::Left, scalingVector);
// scaling->addColSumScaling(NOX::Epetra::Scaling::Right, scalingVector);
// Create transpose scaling object
// Teuchos::RCP<NOX::Epetra::Scaling> trans_scaling = Teuchos::null;
// trans_scaling = Teuchos::rcp(new NOX::Epetra::Scaling);
// Teuchos::RCP<Epetra_Vector> transScalingVector =
// Teuchos::rcp(new Epetra_Vector(soln.Map()));
// trans_scaling->addRowSumScaling(NOX::Epetra::Scaling::Right,
// transScalingVector);
// trans_scaling->addColSumScaling(NOX::Epetra::Scaling::Left,
// transScalingVector);
示例9: testTransposeSolve
int testTransposeSolve(
int NumGlobalElements,
int nRHS,
double reltol,
double abstol,
Epetra_Comm& Comm,
const Teuchos::RCP<LOCA::GlobalData>& globalData,
const Teuchos::RCP<Teuchos::ParameterList>& paramList)
{
int ierr = 0;
double left_bc = 0.0;
double right_bc = 1.0;
double nonlinear_factor = 1.0;
// Create the FiniteElementProblem class. This creates all required
// Epetra objects for the problem and allows calls to the
// function (RHS) and Jacobian evaluation routines.
Tcubed_FiniteElementProblem Problem(NumGlobalElements, Comm);
// Get the vector from the Problem
Epetra_Vector& soln = Problem.getSolution();
// Initialize Solution
soln.PutScalar(0.0);
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("Nonlinear Factor",nonlinear_factor);
pVector.addParameter("Left BC", left_bc);
pVector.addParameter("Right BC", right_bc);
// Create the interface between the test problem and the nonlinear solver
// This is created by the user using inheritance of the abstract base
// class:
Teuchos::RCP<Problem_Interface> interface =
Teuchos::rcp(new Problem_Interface(Problem));
Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface;
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
// Create the Epetra_RowMatrixfor the Jacobian/Preconditioner
Teuchos::RCP<Epetra_RowMatrix> Amat =
Teuchos::rcp(&Problem.getJacobian(),false);
// Get sublists
Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
Teuchos::ParameterList& dirParams = nlParams.sublist("Direction");
Teuchos::ParameterList& newParams = dirParams.sublist("Newton");
Teuchos::ParameterList& lsParams = newParams.sublist("Linear Solver");
// Create the linear systems
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linsys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(nlPrintParams,
lsParams, iReq, iJac,
Amat, soln));
// Create the loca vector
NOX::Epetra::Vector locaSoln(soln);
// Create the Group
Teuchos::RCP<LOCA::Epetra::Group> grp_tp =
Teuchos::rcp(new LOCA::Epetra::Group(globalData, nlPrintParams,
iReq, locaSoln,
linsys, pVector));
// Create the Group
Teuchos::RCP<LOCA::Epetra::Group> grp_lp =
Teuchos::rcp(new LOCA::Epetra::Group(globalData, nlPrintParams,
iReq, locaSoln,
linsys, pVector));
// Create the Group
Teuchos::RCP<LOCA::Epetra::Group> grp_ep =
Teuchos::rcp(new LOCA::Epetra::Group(globalData, nlPrintParams,
iReq, locaSoln,
linsys, pVector));
// Change initial guess to a random vector
Teuchos::RCP<NOX::Abstract::Vector> xnew =
grp_tp->getX().clone();
xnew->random();
grp_tp->setX(*xnew);
grp_lp->setX(*xnew);
grp_ep->setX(*xnew);
// Check some statistics on the solution
Teuchos::RCP<NOX::TestCompare> testCompare =
Teuchos::rcp(new NOX::TestCompare(globalData->locaUtils->out(),
*(globalData->locaUtils)));
// Evaluate blocks
grp_tp->computeF();
grp_lp->computeF();
grp_ep->computeF();
grp_tp->computeJacobian();
grp_lp->computeJacobian();
grp_ep->computeJacobian();
// Set up left- and right-hand sides
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
Teuchos::ParameterList& dirParams = nlParams.sublist("Direction");
Teuchos::ParameterList& newParams = dirParams.sublist("Newton");
Teuchos::ParameterList& lsParams = newParams.sublist("Linear Solver");
lsParams.set("Aztec Solver", "GMRES");
lsParams.set("Max Iterations", 100);
lsParams.set("Tolerance", lstol);
if (verbose)
lsParams.set("Output Frequency", 1);
else
lsParams.set("Output Frequency", 0);
lsParams.set("Scaling", "None");
lsParams.set("Preconditioner", "Ifpack");
//lsParams.set("Preconditioner", "AztecOO");
//lsParams.set("Jacobian Operator", "Matrix-Free");
//lsParams.set("Preconditioner Operator", "Finite Difference");
lsParams.set("Aztec Preconditioner", "ilut");
//lsParams.set("Overlap", 2);
//lsParams.set("Fill Factor", 2.0);
//lsParams.set("Drop Tolerance", 1.0e-12);
lsParams.set("Max Age Of Prec", -2);
// Create the FiniteElementProblem class. This creates all required
// Epetra objects for the problem and allows calls to the
// function (RHS) and Jacobian evaluation routines.
Tcubed_FiniteElementProblem Problem(NumGlobalElements, Comm);
// Get the vector from the Problem
Epetra_Vector& soln = Problem.getSolution();
// Initialize Solution
soln.PutScalar(0.0);
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("Nonlinear Factor",nonlinear_factor);
pVector.addParameter("Left BC", left_bc);
pVector.addParameter("Right BC", right_bc);
// Create the interface between the test problem and the nonlinear solver
// This is created by the user using inheritance of the abstract base
// class:
Teuchos::RCP<Problem_Interface> interface =
Teuchos::rcp(new Problem_Interface(Problem));
Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface;
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
// Create the Epetra_RowMatrixfor the Jacobian/Preconditioner
Teuchos::RCP<Epetra_RowMatrix> Amat =
Teuchos::rcp(&Problem.getJacobian(),false);
// Create the linear systems
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linsys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(nlPrintParams,
lsParams, iReq, iJac,
Amat, soln));
// Create the loca vector
NOX::Epetra::Vector locaSoln(soln);
// Create Epetra factory
Teuchos::RCP<LOCA::Abstract::Factory> epetraFactory =
Teuchos::rcp(new LOCA::Epetra::Factory);
// Create global data object
globalData = LOCA::createGlobalData(paramList, epetraFactory);
示例11: main
int main(int argc, char *argv[])
{
int nConstraints = 10;
int nRHS = 7;
int n = 100;
double alpha = 1.0;
double beta = 0.0;
double gamma = 2.0;
double scale = 1.0;
int ierr = 0;
double reltol = 1.0e-9;
double abstol = 1.0e-9;
alpha = alpha / scale;
try {
bool verbose = false;
// Check for verbose output
if (argc>1)
if (argv[1][0]=='-' && argv[1][1]=='v')
verbose = true;
// Create parameter list
Teuchos::RCP<Teuchos::ParameterList> paramList =
Teuchos::rcp(new Teuchos::ParameterList);
// Create LOCA sublist
Teuchos::ParameterList& locaParamsList = paramList->sublist("LOCA");
// Create the constraints list
Teuchos::ParameterList& constraintsList =
locaParamsList.sublist("Constraints");
constraintsList.set("Bordered Solver Method", "Bordering");
// Create the "Solver" parameters sublist to be used with NOX Solvers
Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
if (verbose)
nlPrintParams.set("Output Information",
NOX::Utils::Error +
NOX::Utils::Details +
NOX::Utils::OuterIteration +
NOX::Utils::InnerIteration +
NOX::Utils::Warning +
NOX::Utils::TestDetails +
NOX::Utils::StepperIteration +
NOX::Utils::StepperDetails);
else
nlPrintParams.set("Output Information", NOX::Utils::Error);
// Create LAPACK factory
Teuchos::RCP<LOCA::Abstract::Factory> lapackFactory =
Teuchos::rcp(new LOCA::LAPACK::Factory);
// Create global data object
globalData = LOCA::createGlobalData(paramList, lapackFactory);
// Create parsed parameter list
parsedParams =
Teuchos::rcp(new LOCA::Parameter::SublistParser(globalData));
parsedParams->parseSublists(paramList);
// Set up the problem interface
ChanProblemInterface chan(globalData, n, alpha, beta, scale);
LOCA::ParameterVector p;
p.addParameter("alpha",alpha);
p.addParameter("beta",beta);
p.addParameter("gamma",gamma);
p.addParameter("scale",scale);
// Create a group which uses that problem interface. The group will
// be initialized to contain the default initial guess for the
// specified problem.
grp = Teuchos::rcp(new LOCA::LAPACK::Group(globalData, chan));
grp->setParams(p);
// Create Jacobian operator
op = Teuchos::rcp(new LOCA::BorderedSolver::JacobianOperator(grp));
// Change initial guess to a random vector
Teuchos::RCP<NOX::Abstract::Vector> xnew = grp->getX().clone();
xnew->random();
grp->setX(*xnew);
// Create the constraints object & constraint param IDs list
constraints = Teuchos::rcp(new LinearConstraint(nConstraints, p, *xnew));
Teuchos::RCP< std::vector<int> > constraintParamIDs =
Teuchos::rcp(new std::vector<int>(1));
(*constraintParamIDs)[0] = p.getIndex("alpha");
// Create bordering solver
bordering
= globalData->locaFactory->createBorderedSolverStrategy(
parsedParams,
parsedParams->getSublist("Constraints"));
// Change strategy to LAPACK Direct Solve
//.........这里部分代码省略.........
示例12: main
int main(int argc, char *argv[])
{
int n = 10;
int ierr = 0;
double reltol = 1.0e-14;
double abstol = 1.0e-14;
int MyPID = 0;
try {
// Initialize MPI
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
// Create a communicator for Epetra objects
#ifdef HAVE_MPI
Epetra_MpiComm Comm( MPI_COMM_WORLD );
#else
Epetra_SerialComm Comm;
#endif
MyPID = Comm.MyPID();
// Create the map
Epetra_Map map(n, 0, Comm);
bool verbose = false;
// Check for verbose output
if (argc>1)
if (argv[1][0]=='-' && argv[1][1]=='v')
verbose = true;
// Seed the random number generator in Teuchos. We create random
// bordering matrices and it is possible different processors might generate
// different matrices. By setting the seed, this shouldn't happen.
Teuchos::ScalarTraits<double>::seedrandom(12345);
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("Param 1", 1.69);
pVector.addParameter("Param 2", -9.7);
pVector.addParameter("Param 3", 0.35);
pVector.addParameter("Param 4", -0.78);
pVector.addParameter("Param 5", 2.53);
// Create parameter list
Teuchos::RCP<Teuchos::ParameterList> paramList =
Teuchos::rcp(new Teuchos::ParameterList);
Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
nlPrintParams.set("MyPID", MyPID);
if (verbose)
nlPrintParams.set("Output Information",
NOX::Utils::Error +
NOX::Utils::Details +
NOX::Utils::OuterIteration +
NOX::Utils::InnerIteration +
NOX::Utils::Warning +
NOX::Utils::TestDetails +
NOX::Utils::StepperIteration +
NOX::Utils::StepperDetails);
else
nlPrintParams.set("Output Information", NOX::Utils::Error);
// Create global data object
Teuchos::RCP<LOCA::GlobalData> globalData =
LOCA::createGlobalData(paramList);
Epetra_Vector clone_vec(map);
NOX::Epetra::Vector nox_clone_vec(clone_vec);
Teuchos::RCP<NOX::Abstract::Vector> x =
nox_clone_vec.clone(NOX::ShapeCopy);
x->random();
Teuchos::RCP<NOX::Abstract::MultiVector> dx1 =
nox_clone_vec.createMultiVector(3);
Teuchos::RCP<NOX::Abstract::MultiVector> dx2 =
nox_clone_vec.createMultiVector(1);
Teuchos::RCP<NOX::Abstract::MultiVector> dx3 =
nox_clone_vec.createMultiVector(2);
Teuchos::RCP<NOX::Abstract::MultiVector> dx4 =
nox_clone_vec.createMultiVector(2);
dx1->random();
dx2->random();
dx3->init(0.0);
dx4->random();
Teuchos::RCP<NOX::Abstract::MultiVector> dx_all =
dx1->clone(NOX::DeepCopy);
dx_all->augment(*dx2);
dx_all->augment(*dx3);
dx_all->augment(*dx4);
NOX::Abstract::MultiVector::DenseMatrix dp1(dx1->numVectors(),
pVector.length());
NOX::Abstract::MultiVector::DenseMatrix dp2(dx2->numVectors(),
pVector.length());
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpi_session(&argc, &argv);
int n = 100;
double alpha = 0.0;
double beta = 0.0;
double scale = 1.0;
int ierr = 0;
int nev = 10;
int narn = 20;
double arntol = 1.0e-12;
alpha = alpha / scale;
try {
bool verbose = false;
// Check for verbose output
if (argc>1)
if (argv[1][0]=='-' && argv[1][1]=='v')
verbose = true;
// Create parameter list
Teuchos::RCP<Teuchos::ParameterList> paramList =
Teuchos::rcp(new Teuchos::ParameterList);
// Create LOCA sublist
Teuchos::ParameterList& locaParamsList = paramList->sublist("LOCA");
// Create the stepper sublist and set the stepper parameters
Teuchos::ParameterList& stepperList = locaParamsList.sublist("Stepper");
// Create Anasazi Eigensolver sublist (needs --with-loca-anasazi)
Teuchos::ParameterList& aList = stepperList.sublist("Eigensolver");
aList.set("Method", "Anasazi");
aList.set("Operator", "Jacobian Inverse");
aList.set("Block Size", 1);
aList.set("Num Blocks", narn);
aList.set("Num Eigenvalues", nev);
aList.set("Convergence Tolerance", arntol);
aList.set("Step Size", 1);
aList.set("Maximum Restarts",2);
aList.set("Sorting Order","LM");
if (verbose)
aList.set("Debug Level",
Anasazi::Errors +
Anasazi::Warnings +
Anasazi::FinalSummary);
else
aList.set("Debug Level", Anasazi::Errors);
// Create the "Solver" parameters sublist to be used with NOX Solvers
Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
if (verbose)
nlPrintParams.set("Output Information",
NOX::Utils::Error +
NOX::Utils::Details +
NOX::Utils::OuterIteration +
NOX::Utils::InnerIteration +
NOX::Utils::Warning +
NOX::Utils::TestDetails +
NOX::Utils::StepperIteration +
NOX::Utils::StepperDetails);
else
nlPrintParams.set("Output Information", NOX::Utils::Error);
// Create LAPACK factory
Teuchos::RCP<LOCA::Abstract::Factory> lapackFactory =
Teuchos::rcp(new LOCA::LAPACK::Factory);
// Create global data object
Teuchos::RCP<LOCA::GlobalData> globalData =
LOCA::createGlobalData(paramList, lapackFactory);
// Create parsed parameter list
Teuchos::RCP<LOCA::Parameter::SublistParser> parsedParams =
Teuchos::rcp(new LOCA::Parameter::SublistParser(globalData));
parsedParams->parseSublists(paramList);
// Set up the problem interface
ChanProblemInterface chan(globalData, n, alpha, beta, scale);
LOCA::ParameterVector p;
p.addParameter("alpha",alpha);
p.addParameter("beta",beta);
p.addParameter("scale",scale);
// Create a group which uses that problem interface. The group will
// be initialized to contain the default initial guess for the
// specified problem.
LOCA::LAPACK::Group grp(globalData, chan);
grp.setParams(p);
grp.computeF();
grp.computeJacobian();
// Create Anasazi eigensolver
//.........这里部分代码省略.........
示例14:
void
ChanProblemInterface::setParams(const LOCA::ParameterVector& p) {
alpha = p.getValue("alpha");
beta = p.getValue("beta");
scale = p.getValue("scale");
}
示例15: main
//.........这里部分代码省略.........
// Create the interface between the test problem and the nonlinear solver
Teuchos::RCP<Problem_Interface> interface =
Teuchos::rcp(new Problem_Interface(Problem));
// Create the Epetra_RowMatrixfor the Jacobian/Preconditioner
Teuchos::RCP<Epetra_RowMatrix> A =
Teuchos::rcp(&Problem.getJacobian(),false);
// Use an Epetra Scaling object if desired
Teuchos::RCP<Epetra_Vector> scaleVec =
Teuchos::rcp(new Epetra_Vector(soln));
NOX::Epetra::Scaling scaling;
scaling.addRowSumScaling(NOX::Epetra::Scaling::Left, scaleVec);
Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface;
// Create the Linear System
Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
iReq, iJac, A, soln));
//&scaling);
Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> shiftedLinSys =
Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
iReq, iJac, A, soln));
// Create initial guess
NOX::Epetra::Vector initialGuess(Teuchos::rcp(&soln,false),
NOX::Epetra::Vector::CreateView,
NOX::DeepCopy);
// Create and initialize the parameter vector
LOCA::ParameterVector pVector;
pVector.addParameter("alpha",alpha);
pVector.addParameter("beta",beta);
pVector.addParameter("D1",D1);
pVector.addParameter("D2",D2);
// Create Epetra factory
Teuchos::RCP<LOCA::Abstract::Factory> epetraFactory =
Teuchos::rcp(new LOCA::Epetra::Factory);
// Create global data object
Teuchos::RCP<LOCA::GlobalData> globalData =
LOCA::createGlobalData(paramList, epetraFactory);
// Create the Group
Teuchos::RCP<LOCA::Epetra::Interface::TimeDependent> iTime = interface;
Teuchos::RCP<LOCA::Epetra::Group> grp =
Teuchos::rcp(new LOCA::Epetra::Group(globalData, printParams,
iTime, initialGuess, linSys,
shiftedLinSys, pVector));
grp->computeF();
// Create the convergence tests
Teuchos::RCP<NOX::StatusTest::NormF> absresid =
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8,
NOX::StatusTest::NormF::Unscaled));
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters =
Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters));
Teuchos::RCP<NOX::StatusTest::Combo> combo =
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
combo->addStatusTest(absresid);
combo->addStatusTest(maxiters);