Debian Codegraph @

packages/nox/examples/lapack/LOCA_Brusselator/BrusselatorContinuation.C

raw
1 // @HEADER
2 // *****************************************************************************
3 // LOCA: Library of Continuation Algorithms Package
4 //
5 // Copyright 2001-2005 NTESS and the LOCA contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include "LOCA.H"
11 #include "LOCA_LAPACK.H"
12 #include "BrusselatorProblemInterface.H"
13
14 int main()
15 {
16 int n = 100;
17 double alpha = 0.25;
18 double beta = 0.0;
19 double D1 = 1.0/40.0;
20 double D2 = 1.0/40.0;
21 int maxNewtonIters = 10;
22
23 try {
24
25 // Create output file to save solutions
26 std::ofstream outFile("BrusselatorContinuation.dat");
27 outFile.setf(std::ios::scientific, std::ios::floatfield);
28 outFile.precision(14);
29
30 // Save size of discretizations
31 outFile << n << std::endl;
32
33 // Create parameter list
34 Teuchos::RCP<Teuchos::ParameterList> paramList =
35 Teuchos::rcp(new Teuchos::ParameterList);
36
37 // Create LOCA sublist
38 Teuchos::ParameterList& locaParamsList = paramList->sublist("LOCA");
39
40 // Create the stepper sublist and set the stepper parameters
41 Teuchos::ParameterList& stepperList = locaParamsList.sublist("Stepper");
42 stepperList.set("Continuation Method", "Arc Length"); // Default
43 stepperList.set("Continuation Parameter", "beta");
44 stepperList.set("Initial Value", beta);
45 stepperList.set("Max Value", 2.0);
46 stepperList.set("Min Value", 0.0);
47 stepperList.set("Max Steps", 100);
48 stepperList.set("Max Nonlinear Iterations", maxNewtonIters);
49
50 // Use LAPACK solver for arclength bordered solves for efficiency
51 stepperList.set("Bordered Solver Method", "LAPACK Direct Solve");
52
53 // Create Eigensolver list using LAPACK eigensolver
54 stepperList.set("Compute Eigenvalues",true);
55 Teuchos::ParameterList& eigenList = stepperList.sublist("Eigensolver");
56 eigenList.set("Method", "DGGEV"); // LAPACK eigensolver
57 eigenList.set("NEV", 10); // Show 10 eigenvalues
58 eigenList.set("Sorting Order", "LR"); // Sort by largest real component
59
60 // Create predictor sublist. We use the constant predictor because the
61 // solution is linear in the continuation parameter. Using Secant or
62 // Tangent is not very interesting, but are perfectly valid
63 Teuchos::ParameterList& predictorList =
64 locaParamsList.sublist("Predictor");
65 predictorList.set("Method", "Constant");
66 //predictorList.set("Method", "Tangent");
67 //predictorList.set("Method", "Secant");
68
69 // Create step size sublist
70 Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size");
71 stepSizeList.set("Method", "Adaptive"); // Default
72 stepSizeList.set("Initial Step Size", 0.1);
73 stepSizeList.set("Min Step Size", 1.0e-3);
74 stepSizeList.set("Max Step Size", 10.0);
75 stepSizeList.set("Aggressiveness", 0.1);
76
77 // Create the "Solver" parameters sublist to be used with NOX Solvers
78 Teuchos::ParameterList& nlParams = paramList->sublist("NOX");
79 Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing");
80 nlPrintParams.set("Output Information",
81 NOX::Utils::Details +
82 NOX::Utils::OuterIteration +
83 NOX::Utils::InnerIteration +
84 NOX::Utils::Warning +
85 NOX::Utils::StepperIteration +
86 NOX::Utils::StepperDetails +
87 NOX::Utils::StepperParameters);
88
89 // Create LAPACK Factory (necessary for LAPACK eigensolver)
90 Teuchos::RCP<LOCA::LAPACK::Factory> lapackFactory =
91 Teuchos::rcp(new LOCA::LAPACK::Factory);
92
93 // Create global data object
94 Teuchos::RCP<LOCA::GlobalData> globalData =
95 LOCA::createGlobalData(paramList, lapackFactory);
96
97 // Set up the problem interface
98 BrusselatorProblemInterface brus(globalData, n, alpha, beta, D1, D2,
99 outFile);
100 LOCA::ParameterVector p;
101 p.addParameter("alpha",alpha);
102 p.addParameter("beta",beta);
103 p.addParameter("D1",D1);
104 p.addParameter("D2",D2);
105
106 // Create a group which uses that problem interface. The group will
107 // be initialized to contain the default initial guess for the
108 // specified problem.
109 Teuchos::RCP<LOCA::MultiContinuation::AbstractGroup> grp =
110 Teuchos::rcp(new LOCA::LAPACK::Group(globalData, brus));
111
112 grp->setParams(p);
113
114 // Set up the status tests
115 Teuchos::RCP<NOX::StatusTest::NormF> normF =
116 Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8));
117 Teuchos::RCP<NOX::StatusTest::MaxIters> maxIters =
118 Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters));
119 Teuchos::RCP<NOX::StatusTest::Generic> comboOR =
120 Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR,
121 normF,
122 maxIters));
123
124 // Create the stepper
125 LOCA::Stepper stepper(globalData, grp, comboOR, paramList);
126
127 // Perform continuation run
128 LOCA::Abstract::Iterator::IteratorStatus status = stepper.run();
129
130 // Check for convergence
131 if (status == LOCA::Abstract::Iterator::Finished)
132 std::cout << "All examples passed" << std::endl;
133 else {
134 if (globalData->locaUtils->isPrintType(NOX::Utils::Error))
135 globalData->locaUtils->out()
136 << "Stepper failed to converge!" << std::endl;
137 }
138
139 // Output the parameter list
140 if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) {
141 globalData->locaUtils->out()
142 << std::endl << "Final Parameters" << std::endl
143 << "****************" << std::endl;
144 stepper.getList()->print(globalData->locaUtils->out());
145 globalData->locaUtils->out() << std::endl;
146 }
147
148 outFile.close();
149
150 LOCA::destroyGlobalData(globalData);
151 }
152
153 catch (std::exception& e) {
154 std::cout << e.what() << std::endl;
155 }
156 catch (const char *s) {
157 std::cout << s << std::endl;
158 }
159 catch (...) {
160 std::cout << "Caught unknown exception!" << std::endl;
161 }
162
163 return 0;
164 }