// @HEADER // ***************************************************************************** // LOCA: Library of Continuation Algorithms Package // // Copyright 2001-2005 NTESS and the LOCA contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "LOCA.H" #include "LOCA_LAPACK.H" #include "ChanProblemInterface.H" #include "ChanConstraint.H" int main() { int n = 100; double alpha = 0.0; double beta = 0.0; double gamma = 0.0; double scale = 1.0; int maxNewtonIters = 20; alpha = alpha / scale; try { // Create output file to save solutions std::ofstream outFile("ChanContinuation.dat"); outFile.setf(ios::scientific, ios::floatfield); outFile.precision(14); // Save size of discretizations outFile << n << std::endl; LOCA::ParameterVector p; p.addParameter("alpha",alpha); p.addParameter("beta",beta); p.addParameter("scale",scale); p.addParameter("gamma",gamma); // Create the constraints object & constraint param IDs list Teuchos::RCP constraints = Teuchos::rcp(new ChanConstraint(n, p)); Teuchos::RCP< std::vector > constraintParamNames = Teuchos::rcp(new std::vector(1)); (*constraintParamNames)[0] = "gamma"; // Create parameter list Teuchos::RCP 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 Method", "Arc Length"); // Default 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); stepperList.set("Enable Arc Length Scaling", false); // Create the constraints list Teuchos::ParameterList& constraintsList = locaParamsList.sublist("Constraints"); constraintsList.set("Constraint Object", constraints); constraintsList.set("Constraint Parameter Names", constraintParamNames); // Create bifurcation sublist Teuchos::ParameterList& bifurcationList = locaParamsList.sublist("Bifurcation"); bifurcationList.set("Type", "None"); // Default // Create predictor sublist Teuchos::ParameterList& predictorList = locaParamsList.sublist("Predictor"); predictorList.set("Method", "Secant"); // Default // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default 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); stepSizeList.set("Aggressiveness", 0.1); // Create the "Solver" parameters sublist to be used with NOX Solvers Teuchos::ParameterList& nlParams = paramList->sublist("NOX"); Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing"); nlPrintParams.set("Output Information", NOX::Utils::Details + NOX::Utils::OuterIteration + NOX::Utils::InnerIteration + NOX::Utils::Warning + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // Create LAPACK Factory Teuchos::RCP lapackFactory = Teuchos::rcp(new LOCA::LAPACK::Factory); // Create global data object Teuchos::RCP globalData = LOCA::createGlobalData(paramList, lapackFactory); // Set up the problem interface ChanProblemInterface chan(globalData, n, alpha, beta, scale, outFile); // 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 grp = Teuchos::rcp(new LOCA::LAPACK::Group(globalData, chan)); grp->setParams(p); // Set up the status tests Teuchos::RCP normF = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8)); Teuchos::RCP maxIters = Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters)); Teuchos::RCP 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(); if (status == LOCA::Abstract::Iterator::Finished) std::cout << "All examples passed" << std::endl; else { if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) globalData->locaUtils->out() << "Stepper failed to converge!" << std::endl; } // Output the parameter list if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) { globalData->locaUtils->out() << std::endl << "Final Parameters" << std::endl << "****************" << std::endl; stepper.getList()->print(globalData->locaUtils->out()); globalData->locaUtils->out() << std::endl; } outFile.close(); LOCA::destroyGlobalData(globalData); } catch (std::exception& e) { std::cout << e.what() << std::endl; } catch (const char *s) { std::cout << s << std::endl; } catch (...) { std::cout << "Caught unknown exception!" << std::endl; } return 0; }