bool no_changes( ) { YEditFile **file; YFileList::Iterator stepper( the_list ); while( ( file = stepper( ) ) != NULL ) if( ( *file )->changed( ) ) return false; return true; }
void main(){ initPIC(); while(1) { TRISB=0x1F; PORTA=0; if((RB4==1) && (PORTB==0x1E)) { PORTB=0; TRISB=0X00; PORTA=0X01; stepper(value); } else if(RB4) { value=keypad[PORTB&0x0F]; delay(15); PORTB=value; PORTA=0X03; TRISB=0X00; PORTA=0X01; } } }
void TestEnforceConstantTimeStep() throw(Exception) { TimeStepper stepper(0.0, 1.0, 0.3); // timestep does not divide, but no checking TS_ASSERT_THROWS_THIS( TimeStepper bad_const_dt_stepper(0.0, 1.0, 0.3, true), "TimeStepper estimates non-constant timesteps will need to be used: " "check timestep divides (end_time-start_time) (or divides printing timestep). " "[End time=1; start=0; dt=0.3; error=0.1]"); #ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif TS_ASSERT_THROWS_THIS( TimeStepper bad_const_dt_stepper2(0.0, 1.0, 0.99999999, true), "TimeStepper estimates non-constant timesteps will need to be used: " "check timestep divides (end_time-start_time) (or divides printing timestep). " "[End time=1; start=0; dt=1; error=1e-08]"); TimeStepper const_dt_stepper(0.0, 1.0, 0.1, true); unsigned counter = 0; while (!const_dt_stepper.IsTimeAtEnd()) { counter++; TS_ASSERT_DELTA(const_dt_stepper.GetNextTimeStep(), 0.1, 1e-15); TS_ASSERT_EQUALS(const_dt_stepper.GetIdealTimeStep(), 0.1); const_dt_stepper.AdvanceOneTimeStep(); if (const_dt_stepper.IsTimeAtEnd()) { TS_ASSERT_EQUALS(const_dt_stepper.GetNextTimeStep(), 0.0); } else { TS_ASSERT_DELTA(const_dt_stepper.GetNextTimeStep(), 0.1, 1e-15); } } TS_ASSERT_EQUALS(counter,10u); }
int main() { srand( 12312354 ); const double a_tmp[3*4/2] = { 0.5 , 0.0 , 1.0 , 0.0 , 0.0 , 1.0 }; const double* const a[3] = { a_tmp , a_tmp+1 , a_tmp+3 }; rk_stepper_type::coeff_b_type b( stage_count ); b[0] = 1.0/6; b[1] = 1.0/3; b[2] = 1.0/3; b[3] = 1.0/6; rk_stepper_type::coeff_c_type c( stage_count ); c[0] = 0.0; c[1] = 0.5; c[2] = 0.5; c[3] = 1.0; rt_generic_wrapper stepper( a , b , c ); run( stepper , 10000 , 1E-6 ); }
void TestGravitationalVaryingThreeBifurcations() throw (Exception) { MatrixVentilationProblem problem("lung/test/data/three_bifurcations", 0u); problem.SetRadiusOnEdge(); problem.SetOutflowPressure(0.0); TimeStepper stepper(0.0, 1.0, 0.1); problem.SolveOverTime(stepper, &GravitationalBCs, "TestVentilation", "three_bifurcations_gravity"); }
void TestArchiveTimeStepper() { OutputFileHandler handler("TestTimeStepper_Archive", false); std::string archive_filename = handler.GetOutputDirectoryFullPath() + "time.arch"; // Create and archive time-stepper { std::ofstream ofs(archive_filename.c_str()); boost::archive::text_oarchive output_arch(ofs); TimeStepper stepper(0.0, 1.0, 0.1, false); //Run for 5 steps for (int i=0; i<5; i++) { stepper.AdvanceOneTimeStep(); } TS_ASSERT_DELTA(stepper.GetTime(), 0.5, 1e-10); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.6, 1e-10); TimeStepper* const p_stepper_for_archiving = &stepper; output_arch << p_stepper_for_archiving; //Exhibit normal behaviour after archive snapshot stepper.AdvanceOneTimeStep(); TS_ASSERT_DELTA(stepper.GetTime(), 0.6, 1e-10); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.7, 1e-10); stepper.AdvanceOneTimeStep(); TS_ASSERT_DELTA(stepper.GetTime(), 0.7, 1e-10); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.8, 1e-10); } // Restore { std::ifstream ifs(archive_filename.c_str(), std::ios::binary); boost::archive::text_iarchive input_arch(ifs); TimeStepper* p_stepper; input_arch >> p_stepper; TS_ASSERT_DELTA(p_stepper->GetTime(), 0.5, 1e-10); TS_ASSERT_DELTA(p_stepper->GetNextTime(), 0.6, 1e-10); p_stepper->AdvanceOneTimeStep(); TS_ASSERT_DELTA(p_stepper->GetTime(), 0.6, 1e-10); TS_ASSERT_DELTA(p_stepper->GetNextTime(), 0.7, 1e-10); p_stepper->AdvanceOneTimeStep(); TS_ASSERT_DELTA(p_stepper->GetTime(), 0.7, 1e-10); TS_ASSERT_DELTA(p_stepper->GetNextTime(), 0.8, 1e-10); delete p_stepper; } }
// Run normally up to stretch-time, then apply stretch and // run until stretch-off-time, then return to stretch=1 // and run until 1000ms. void RunModelWithSacRecruitment(double stretch, double stretchStartTime, double stretchEndTime, std::string directory, std::string filePrefix, bool clearDir) { boost::shared_ptr<SimpleStimulus> p_stimulus(new SimpleStimulus( -3 /*magnitude*/, 3 /*duration*/, 10.0 /*start time*/)); boost::shared_ptr<EulerIvpOdeSolver> p_solver(new EulerIvpOdeSolver); double time_step = 0.01; HeartConfig::Instance()->SetOdePdeAndPrintingTimeSteps(time_step, time_step, 1.0); CML_noble_varghese_kohl_noble_1998_basic_with_sac n98_with_sac(p_solver, p_stimulus); OutputFileHandler handler(directory,clearDir); out_stream p_file = handler.OpenOutputFile(filePrefix+".dat"); *p_file << 0 << " " << n98_with_sac.GetVoltage() << "\n"; double printing_dt = 1; TimeStepper stepper(0, stretchStartTime, printing_dt); while ( !stepper.IsTimeAtEnd() ) { n98_with_sac.Compute(stepper.GetTime(), stepper.GetNextTime()); stepper.AdvanceOneTimeStep(); *p_file << stepper.GetTime() << " " << n98_with_sac.GetVoltage() << "\n"; } n98_with_sac.SetStretch(stretch); TimeStepper stepper2(stepper.GetTime(), stretchEndTime, printing_dt); while ( !stepper2.IsTimeAtEnd() ) { n98_with_sac.Compute(stepper2.GetTime(), stepper2.GetNextTime()); stepper2.AdvanceOneTimeStep(); *p_file << stepper2.GetTime() << " " << n98_with_sac.GetVoltage() << "\n"; } n98_with_sac.SetStretch(1.0); TimeStepper stepper3(stepper2.GetTime(), 1000, printing_dt); while ( !stepper3.IsTimeAtEnd() ) { n98_with_sac.Compute(stepper3.GetTime(), stepper3.GetNextTime()); stepper3.AdvanceOneTimeStep(); *p_file << stepper3.GetTime() << " " << n98_with_sac.GetVoltage() << "\n"; } p_file->close(); }
int main() { double T(1e-1); double L(1e-6); double N(1e+4); double R(2.5e-9); double D(1e-12); double stirTime(T*0.5); libecs::initialize(); libecs::Model& model(*(new libecs::Model(*libecs::createDefaultModuleMaker()))); model.setup(); libecs::Stepper& stepper(*model.createStepper("SpatiocyteStepper", "SS")); stepper.setProperty("VoxelRadius", libecs::Polymorph(R)); stepper.setProperty("ThreadSize", libecs::Polymorph(libecs::Integer(2))); model.getRootSystem()->setProperty("StepperID", libecs::Polymorph("SS")); createVariable(model, "Variable:/:GEOMETRY", CUBOID); createVariable(model, "Variable:/:LENGTHX", L); createVariable(model, "Variable:/:LENGTHY", L); createVariable(model, "Variable:/:LENGTHZ", L); createVariable(model, "Variable:/:XYPLANE", PERIODIC); createVariable(model, "Variable:/:XZPLANE", PERIODIC); createVariable(model, "Variable:/:YZPLANE", PERIODIC); createVariable(model, "Variable:/:VACANT", 0); createVariable(model, "Variable:/:A", N); createVariable(model, "Variable:/:B", 0); /* libecs::Process& vis(createProcess(model, "VisualizationLogProcess", "Process:/:logger")); vis.registerVariableReference("_", libecs::String("Variable:/Surface:A"), 0); vis.registerVariableReference("_", libecs::String("Variable:/Surface:As"), 0); vis.loadProperty("LogInterval", libecs::Polymorph(0.01)); */ libecs::Process& pop(createProcess(model, "MoleculePopulateProcess", "Process:/:pop")); pop.registerVariableReference("_", libecs::String("Variable:/:A"), 0); libecs::Process& dif(createProcess(model, "DiffusionProcess", "Process:/:diffuseA")); dif.registerVariableReference("_", libecs::String("Variable:/:A"), 0); dif.loadProperty("D", libecs::Polymorph(D)); model.initialize(); run(model, stirTime); boost::posix_time::ptime start( boost::posix_time::microsec_clock::universal_time()); run(model, T); boost::posix_time::ptime end( boost::posix_time::microsec_clock::universal_time()); std::cout << "duration:" << end-start << std::endl; delete &model; libecs::finalize(); }
int main() { // Primary Operators AnnihilationOperator A1(0); // 1st freedom NumberOperator N1(0); IdentityOperator Id1(0); AnnihilationOperator A2(1); // 2nd freedom NumberOperator N2(1); IdentityOperator Id2(1); SigmaPlus Sp(2); // 3rd freedom IdentityOperator Id3(2); Operator Sm = Sp.hc(); // Hermitian conjugate Operator Ac1 = A1.hc(); Operator Ac2 = A2.hc(); // Hamiltonian double E = 20.0; double chi = 0.4; double omega = -0.7; double eta = 0.001; Complex I(0.0,1.0); Operator H = (E*I)*(Ac1-A1) + (0.5*chi*I)*(Ac1*Ac1*A2 - A1*A1*Ac2) + omega*Sp*Sm + (eta*I)*(A2*Sp-Ac2*Sm); // Lindblad operators double gamma1 = 1.0; double gamma2 = 1.0; double kappa = 0.1; const int nL = 3; Operator L[nL]={sqrt(2*gamma1)*A1,sqrt(2*gamma2)*A2,sqrt(2*kappa)*Sm}; // Initial state State phi1(50,FIELD); // see paper Section 4.2 State phi2(50,FIELD); State phi3(2,SPIN); State stateList[3] = {phi1,phi2,phi3}; State psiIni(3,stateList); // Trajectory double dt = 0.01; // basic time step int numdts = 100; // time interval between outputs = numdts*dt int numsteps = 5; // total integration time = numsteps*numdts*dt int nOfMovingFreedoms = 2; double epsilon = 0.01; // cutoff probability int nPad = 2; // pad size //ACG gen(38388389); // random number generator with seed //ComplexNormal rndm(&gen); // Complex Gaussian random numbers ComplexNormalTest rndm(899101); // Simple portable random number generator AdaptiveStep stepper(psiIni, H, nL, L); // see paper Section 5 // Output const int nOfOut = 3; Operator outlist[nOfOut]={ Sp*A2*Sm*Sp, Sm*Sp*A2*Sm, A2 }; char *flist[nOfOut]={"X1.out","X2.out","A2.out"}; int pipe[] = {1,5,9,11}; // controls standard output (see `onespin.cc') // Simulate one trajectory (for several trajectories see `onespin.cc') Trajectory traj(psiIni, dt, stepper, &rndm); // see paper Section 5 traj.plotExp( nOfOut, outlist, flist, pipe, numdts, numsteps, nOfMovingFreedoms, epsilon, nPad ); }
void TestWithSingleTimeStep() throw(Exception) { TimeStepper stepper(4.02, 4.04, 0.02, true); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 1u); while (!stepper.IsTimeAtEnd()) { TS_ASSERT_DELTA(stepper.GetNextTimeStep(), 0.02, 4.04*DBL_EPSILON); stepper.AdvanceOneTimeStep(); } TS_ASSERT_EQUALS(stepper.GetTotalTimeStepsTaken(), 1u); }
void TestWithLargeEndTime() throw(Exception) { TimeStepper stepper(0.01*999999999, 1e7, 0.01, true); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 1u); while (!stepper.IsTimeAtEnd()) { TS_ASSERT_DELTA(stepper.GetNextTimeStep(), 0.01, DBL_EPSILON*1e7); stepper.AdvanceOneTimeStep(); } TS_ASSERT_EQUALS(stepper.GetTotalTimeStepsTaken(), 1u); }
int main(int argc, char *argv[]) { init(); if(init_setting() != 0){ print_errmsg("ERROR: SETTING init fail. \n"); return 1; } if(gc_init() != 0){ print_errmsg("ERROR: G_CODE init fail. \n"); return 1; } if (cm_init() == false) { print_errmsg("ERROR: USB-DEV init fail. \n"); return 1; } if (cmd_init() == false) { print_errmsg("ERROR: G code init fail.\n"); cm_close(); return 1; } if (tp_init() == false) { print_errmsg("ERROR: Temperature library init fail. \n"); cmd_close(); cm_close(); return 1; } plan_init(); Config_ResetDefault(); st_init(); while(1) { LCD(10UL); getCommand(10UL); process_commands(50UL); stepper(1000L); manageHeater(10UL); } st_close(); plan_close(); tp_close(); cmd_close(); cm_close(); //debug //sfp_close(); return 0; }
bool reload_files( ) { YEditFile **file; YFileList::Iterator stepper( the_list ); while( ( file = stepper( ) ) != NULL ) { // Read date and time stamp for disk versions of files. FileNameMatcher stamper; char *name_string; stamper.set_name( ( *file )->name( ) ); if( ( name_string = stamper.next( ) ) != NULL ) { // Check to see if disk version is more recent. If so, reload. if( stamper.modify_time( ) > ( *file )->time( ) ) { // Remember current point in file. FilePosition point = ( *file )->CP( ); // Erase the file's data. ( *file )->top_of_file( ); ( *file )->set_block_state( true ); ( *file )->bottom_of_file( ); ( *file )->delete_block( ); ( *file )->set_block_state( false ); ( *file )->top_of_file( ); // Get the new stuff. ( *file )->load( name_string ); ( *file )->set_timestamp( name_string ); ( *file )->CP( ) = point; ( *file )->mark_as_unchanged( ); } } } return true; }
bool save_changes( ) { bool return_value = true; YEditFile **file; YFileList::Iterator stepper( the_list ); // Look for files which have changed and save those files. while( ( file = stepper( ) ) != NULL ) { if( ( *file )->changed( ) ) { // Try saving the file. Update records if save worked. bool save_worked = ( *file )->save( ( *file )->name( ) ); if( !save_worked ) return_value = false; else { ( *file )->set_timestamp( ( *file )->name( ) ); ( *file )->mark_as_unchanged( ); } } } return return_value; }
void TestAdditionalSteppingPoints() throw(Exception) { { std::vector<double> additional_times_bad_order; additional_times_bad_order.push_back(0.7); additional_times_bad_order.push_back(0.2); TS_ASSERT_THROWS_THIS(TimeStepper stepper(0.0, 1.0, 0.1, false, additional_times_bad_order), "The additional times vector should be in ascending numerical order; " "entry 1 is less than or equal to entry 0."); } { std::vector<double> additional_times; additional_times.push_back(0.03); additional_times.push_back(0.25); additional_times.push_back(0.5); additional_times.push_back(0.75); TS_ASSERT_THROWS_THIS(TimeStepper stepper(0.0, 1.0, 0.1, false, additional_times), "Additional times are now deprecated. Use only to check whether the given times are met: " "e.g. Electrode events should only happen on printing steps."); } std::vector<double> check_additional_times; check_additional_times.push_back(0.0); check_additional_times.push_back(0.2); check_additional_times.push_back(0.5); check_additional_times.push_back(0.7); TimeStepper stepper(0.0, 1.0, 0.1, false, check_additional_times); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(),10u); while (!stepper.IsTimeAtEnd()) { stepper.AdvanceOneTimeStep(); } TS_ASSERT_EQUALS(stepper.GetTotalTimeStepsTaken(),10u); }
void TestSineThreeBifurcations() throw (Exception) { MatrixVentilationProblem problem("lung/test/data/three_bifurcations", 0u); problem.SetRadiusOnEdge(); problem.SetOutflowPressure(0.0); TimeStepper stepper(0.0, 25.0, 0.1); problem.SolveOverTime(stepper, &SineBCs, "TestVentilation", "three_bifurcations_sine"); std::vector<double> flux, pressure; problem.GetSolutionAsFluxesAndPressures(flux, pressure); //check pressure at end time @ 25 TS_ASSERT_DELTA(pressure[0], 0.0, 1e-8); //BC TS_ASSERT_DELTA(pressure[1], 5.7655, 1e-4); TS_ASSERT_DELTA(pressure[2], 10.5701, 1e-4); TS_ASSERT_DELTA(pressure[3], 10.5701, 1e-4); TS_ASSERT_DELTA(pressure[4], 12.972452, 1e-5); //BC TS_ASSERT_DELTA(pressure[5], 12.972452, 1e-5); //BC }
int main(void) { //init stepper(BOTH,VOR,0);// initalize so that the global pointers are initialized for the turtle()-function /* turtle_t *commands; int commandNumber; parseCommandFile(FILEPATH, &commands, &commandNumber); do_it(commands,commandNumber); free(commands);*/ lawnmower(); return 0; }
int hpx_main(boost::program_options::variables_map& vm) { mini_ghost::profiling::data().time_init(hpx::util::high_resolution_timer::now() - init_start); hpx::util::high_resolution_timer timer_all; hpx::id_type here = hpx::find_here(); std::string name = hpx::get_locality_name(); p.rank = hpx::naming::get_locality_id_from_id(here); if(p.rank == 0) { std::cout << "mini ghost started up in " << hpx::util::high_resolution_timer::now() - init_start << " seconds.\n"; } p.nranks = hpx::get_num_localities().get(); profiling_data_sem.reset(new hpx::lcos::local::counting_semaphore(p.nranks)); p.setup(vm); hpx::id_type stepper_id = hpx::components::new_<stepper_type>(hpx::find_here()).get(); boost::shared_ptr<stepper_type> stepper(hpx::get_ptr<stepper_type>(stepper_id).get()); stepper->init(p); mini_ghost::barrier_wait(); stepper->run(p.num_spikes, p.num_tsteps); mini_ghost::barrier_wait(); if (p.rank==0) { add_profile(mini_ghost::profiling::data()); if(p.report_perf) mini_ghost::profiling::report(std::cout, profiling_data, p); else std::cout << "Total runtime: " << timer_all.elapsed() << "\n"; std::ofstream fs("results.yaml"); mini_ghost::profiling::report(fs, profiling_data, p); std::cout << "finalizing ...\n"; return hpx::finalize(); } else { hpx::apply(add_profile_action(), hpx::find_root_locality(), mini_ghost::profiling::data()); return 0; } }
void AbstractRushLarsenCardiacCell::SolveAndUpdateState(double tStart, double tEnd) { TimeStepper stepper(tStart, tEnd, mDt); std::vector<double> dy(mNumberOfStateVariables, 0); std::vector<double> alpha(mNumberOfStateVariables, 0); std::vector<double> beta(mNumberOfStateVariables, 0); while (!stepper.IsTimeAtEnd()) { EvaluateEquations(stepper.GetTime(), dy, alpha, beta); UpdateTransmembranePotential(dy); ComputeOneStepExceptVoltage(dy, alpha, beta); VerifyStateVariables(); stepper.AdvanceOneTimeStep(); } }
/** * This case used to break with the IntelProduction build, believe it or not. * Adding further information to the error message clearly changes the optimisations it applies, * and fixes the problem! */ void TestIntelProductionFoolishness() throw(Exception) { TimeStepper stepper(5.0, 10.0, 0.01, true); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 500u); while (!stepper.IsTimeAtEnd()) { TS_ASSERT_DELTA(stepper.GetNextTimeStep(), 0.01, 10.0*DBL_EPSILON); TimeStepper pde_stepper(stepper.GetTime(), stepper.GetNextTime(), 0.01, true); TS_ASSERT_EQUALS(pde_stepper.EstimateTimeSteps(), 1u); while (!pde_stepper.IsTimeAtEnd()) { TS_ASSERT_DELTA(pde_stepper.GetNextTimeStep(), 0.01, 10.0*DBL_EPSILON); pde_stepper.AdvanceOneTimeStep(); } TS_ASSERT_EQUALS(pde_stepper.GetTotalTimeStepsTaken(), 1u); stepper.AdvanceOneTimeStep(); } TS_ASSERT_EQUALS(stepper.GetTotalTimeStepsTaken(), 500u); }
void TestResetTimeStep() throw(Exception) { double timestep = 0.1; TimeStepper stepper(0.0, 0.5, timestep, false); TS_ASSERT_EQUALS(stepper.GetNextTimeStep(), timestep); TS_ASSERT_EQUALS(stepper.GetTime(), 0.0); TS_ASSERT_EQUALS(stepper.GetNextTime(), timestep); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 5u); stepper.AdvanceOneTimeStep(); TS_ASSERT_EQUALS(stepper.GetTime(), 0.1); timestep = 0.05; stepper.ResetTimeStep(timestep); TS_ASSERT_DELTA(stepper.GetNextTimeStep(), timestep, 1e-12); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.15, 1e-12); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 8u); stepper.AdvanceOneTimeStep(); TS_ASSERT_DELTA(stepper.GetTime(), 0.15, 1e-12); timestep = 0.25; stepper.ResetTimeStep(timestep); TS_ASSERT_DELTA(stepper.GetNextTimeStep(), timestep, 1e-12); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.4, 1e-12); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 1u); // just an estimate stepper.AdvanceOneTimeStep(); TS_ASSERT_DELTA(stepper.GetTime(), 0.4, 1e-12); TS_ASSERT_DELTA(stepper.GetNextTimeStep(), 0.1, 1e-12); TS_ASSERT_DELTA(stepper.GetNextTime(), 0.5, 1e-12); TS_ASSERT_EQUALS(stepper.EstimateTimeSteps(), 1u); stepper.AdvanceOneTimeStep(); TS_ASSERT_EQUALS(stepper.IsTimeAtEnd(), true); }
void AbstractRushLarsenCardiacCell::ComputeExceptVoltage(double tStart, double tEnd) { mSetVoltageDerivativeToZero = true; TimeStepper stepper(tStart, tEnd, mDt); std::vector<double> dy(mNumberOfStateVariables, 0); std::vector<double> alpha(mNumberOfStateVariables, 0); std::vector<double> beta(mNumberOfStateVariables, 0); while (!stepper.IsTimeAtEnd()) { EvaluateEquations(stepper.GetTime(), dy, alpha, beta); ComputeOneStepExceptVoltage(dy, alpha, beta); #ifndef NDEBUG // Check gating variables are still in range VerifyStateVariables(); #endif // NDEBUG stepper.AdvanceOneTimeStep(); } mSetVoltageDerivativeToZero = false; }
int main() { int n = 100; double alpha = 3.5; double beta = 0.0; double scale = 1.0; int maxNewtonIters = 10; alpha = alpha / scale; // These seeds were found to work -- not the first try int seed1 = 3; int seed2 = 4; //Subsequent seeds keep incrementing by seed2-seed1 double homScale = -1.0; /* Uncomment for interactive mode std::cout << "Input first seed" << endl; std::cin >> seed1; std::cout << "Input second seed" << endl; std::cin >> seed2; std::cout << "Input identity-scale" << endl; std::cin >> homScale; */ try { // 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"); Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); // 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::Error + NOX::Utils::Parameters + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // Create LAPACK Factory Teuchos::RCP<LOCA::LAPACK::Factory> lapackFactory = Teuchos::rcp(new LOCA::LAPACK::Factory); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList, lapackFactory); // 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::LAPACK::Group> grp = Teuchos::rcp(new LOCA::LAPACK::Group(globalData, chan)); grp->setParams(p); // Set up the status tests Teuchos::RCP<NOX::StatusTest::NormF> statusTestA = Teuchos::rcp(new NOX::StatusTest::NormF(*grp, 1.0e-8)); Teuchos::RCP<NOX::StatusTest::MaxIters> statusTestB = Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters)); Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR, statusTestA, statusTestB)); // Create the homotopy group // Teuchos::RCP<LOCA::Homotopy::Group> hGrp = // Teuchos::rcp(new LOCA::Homotopy::Group(locaParamsList, globalData, grp)); Teuchos::RCP<Teuchos::ParameterList> hParams = Teuchos::rcp(&locaParamsList.sublist("Homotopy"),false); hParams->set("Bordered Solver Method", "LAPACK Direct Solve"); Teuchos::RCP<NOX::Abstract::Vector> startVec = grp->getX().clone(NOX::ShapeCopy); startVec->random(true, seed1); /* Always use same seed for testing */ startVec->abs(*startVec); std::vector< Teuchos::RCP<const NOX::Abstract::Vector> > solns; LOCA::Abstract::Iterator::IteratorStatus status = LOCA::Abstract::Iterator::Finished; int deflationIter = 0; const int maxDeflationIters = 4; while (deflationIter < maxDeflationIters && status==LOCA::Abstract::Iterator::Finished) { // ToDo: Add deflateAndReset(vec) to Homotopy group, // including option to perturb startVec Teuchos::RCP<LOCA::Homotopy::DeflatedGroup> hGrp = Teuchos::rcp(new LOCA::Homotopy::DeflatedGroup(globalData, paramList, hParams, grp, startVec, solns,homScale)); // Override default parameters stepperList.set("Max Nonlinear Iterations", maxNewtonIters); stepperList.set("Continuation Method", "Arc Length"); stepperList.set("Max Steps", 100); stepSizeList.set("Min Step Size", 1.0e-5); // Create the stepper LOCA::Stepper stepper(globalData, hGrp, combo, paramList); // Solve the nonlinear system status = stepper.run(); if (status != LOCA::Abstract::Iterator::Finished) globalData->locaUtils->out() << "Stepper failed to converge!" << std::endl; else { // Deflate with soln vector just solved for solns.push_back(grp->getX().clone(NOX::DeepCopy)); // If seed1=seed2, then all seeds the same. Otherwise, keep incrementing seed startVec->random(true, seed2 + deflationIter*(seed2-seed1)); } deflationIter++; // Output the parameter list if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) { globalData->locaUtils->out() << std::endl << "Final Parameters for deflation iter " << deflationIter << std::endl << "****************" << std::endl; stepper.getList()->print(globalData->locaUtils->out()); globalData->locaUtils->out() << std::endl; } } //End While loop over delfation iters 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; } cout << "All examples passed" << endl; return 0; }
int main() { try { int n = 100; double alpha = 4.0; double beta = 0.0; double scale = 1.0; int maxNewtonIters = 10; // Create output file to save solutions std::ofstream outFile("ChanTPContinuation.dat"); outFile.setf(std::ios::scientific, std::ios::floatfield); outFile.precision(14); // Save size of discretizations outFile << n << std::endl; // Create initial guess for the null vector of jacobian Teuchos::RCP<NOX::Abstract::Vector> nullVec = Teuchos::rcp(new NOX::LAPACK::Vector(n)); nullVec->init(1.0); // initial value 1.0 // Create initial values for a and b for minimally augmented method Teuchos::RCP<NOX::Abstract::Vector> a_vec = Teuchos::rcp(new NOX::LAPACK::Vector(n)); a_vec->init(1.0); Teuchos::RCP<NOX::Abstract::Vector> b_vec = Teuchos::rcp(new NOX::LAPACK::Vector(n)); b_vec->init(1.0); // 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 Method", "Arc Length"); // Default stepperList.set("Continuation Parameter", "beta"); // Must set stepperList.set("Initial Value", beta); // Must set stepperList.set("Max Value", 1.0); // Must set stepperList.set("Min Value", 0.0); // Must set stepperList.set("Max Steps", 20); // Should set stepperList.set("Max Nonlinear Iterations", maxNewtonIters); // Should set // Create bifurcation sublist Teuchos::ParameterList& bifurcationList = locaParamsList.sublist("Bifurcation"); bifurcationList.set("Type", "Turning Point"); // For turning point bifurcationList.set("Bifurcation Parameter", "alpha"); // Must set // For Moore-Spence formulation w/bordering //bifurcationList.set("Formulation", "Moore-Spence"); // Default //bifurcationList.set("Solver Method", "Salinger Bordering"); // Default //bifurcationList.set("Solver Method", "Phipps Bordering"); //bifurcationList.set("Bordered Solver Method", // "LAPACK Direct Solve"); // For Phipps Bordering //bifurcationList.set("Length Normalization Vector", nullVec); // Must set //bifurcationList.set("Initial Null Vector", nullVec); // Must set // For minimally augmented formulation bifurcationList.set("Formulation", "Minimally Augmented"); bifurcationList.set("Initial A Vector", a_vec); // Must set bifurcationList.set("Initial B Vector", b_vec); // Must set // For minimally augmented method, should set these for good performance // Direct solve of bordered equations bifurcationList.set("Bordered Solver Method", "LAPACK Direct Solve"); // Combine arc-length and turning point bordered rows & columns stepperList.set("Bordered Solver Method", "Nested"); Teuchos::ParameterList& nestedList = stepperList.sublist("Nested Bordered Solver"); // Direct solve of combined bordered system nestedList.set("Bordered Solver Method", "LAPACK Direct Solve"); // Create predictor sublist Teuchos::ParameterList& predictorList = locaParamsList.sublist("Predictor"); predictorList.set("Method", "Secant"); // Default // Should use for Moore-Spence w/Salinger Bordering & Secant predictor //Teuchos::ParameterList& firstStepPredictor // = predictorList.sublist("First Step Predictor"); //firstStepPredictor.set("Method", "Random"); //firstStepPredictor.set("Epsilon", 1.0e-3); // Should use for Moore-Spence w/Salinger Bordering & Secant predictor //Teuchos::ParameterList& lastStepPredictor // = predictorList.sublist("Last Step Predictor"); //lastStepPredictor.set("Method", "Random"); //lastStepPredictor.set("Epsilon", 1.0e-3); // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default stepSizeList.set("Initial Step Size", 0.1); // Should set stepSizeList.set("Min Step Size", 1.0e-3); // Should set stepSizeList.set("Max Step Size", 1.0); // Should set // 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::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::Details + NOX::Utils::Warning + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // Should set // Create LAPACK Factory Teuchos::RCP<LOCA::LAPACK::Factory> lapackFactory = Teuchos::rcp(new LOCA::LAPACK::Factory); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList, lapackFactory); // Set up the problem interface ChanProblemInterface chan(globalData, n, alpha, beta, scale, outFile); 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> statusTestA = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-10, NOX::StatusTest::NormF::Scaled)); Teuchos::RCP<NOX::StatusTest::MaxIters> statusTestB = Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters)); Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR, statusTestA, statusTestB)); // Create the stepper LOCA::Stepper stepper(globalData, grp, combo, paramList); // Solve the nonlinear system 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; }
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; } // Get the final solution from the stepper Teuchos::RCP<const LOCA::LAPACK::Group> finalGroup = Teuchos::rcp_dynamic_cast<const LOCA::LAPACK::Group>(stepper.getSolutionGroup()); const NOX::LAPACK::Vector& finalSolution = dynamic_cast<const NOX::LAPACK::Vector&>(finalGroup->getX()); // 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; } // Check some statistics on the solution NOX::TestCompare testCompare(globalData->locaUtils->out(), *(globalData->locaUtils)); if (globalData->locaUtils->isPrintType(NOX::Utils::TestDetails)) globalData->locaUtils->out() << std::endl << "***** Checking solution statistics *****" << std::endl; // Check number of steps int numSteps = stepper.getStepNumber(); int numSteps_expected = 32; ierr += testCompare.testValue(numSteps, numSteps_expected, 0.0, "number of continuation steps", NOX::TestCompare::Absolute); // Check number of failed steps int numFailedSteps = stepper.getNumFailedSteps(); int numFailedSteps_expected = 0; ierr += testCompare.testValue(numFailedSteps, numFailedSteps_expected, 0.0, "number of failed continuation steps", NOX::TestCompare::Absolute); // Check final value of continuation parameter double alpha_final = finalGroup->getParam("alpha"); double alpha_expected = 5.0; ierr += testCompare.testValue(alpha_final, alpha_expected, 1.0e-14, "final value of continuation parameter", NOX::TestCompare::Relative); // Check norm of solution double norm_x = finalSolution.norm(); double norm_x_expected = 203.1991024; ierr += testCompare.testValue(norm_x, norm_x_expected, 1.0e-7, "norm of final solution", NOX::TestCompare::Relative); LOCA::destroyGlobalData(globalData); } catch (std::exception& e) { cout << e.what() << endl; ierr = 1; } catch (const char *s) { cout << s << endl; ierr = 1; } catch (...) { cout << "Caught unknown exception!" << endl; ierr = 1; } if (ierr == 0) cout << "All tests passed!" << endl; else cout << ierr << " test(s) failed!" << endl; return ierr; }
int main( int argc, char **argv ) { // check for parallel computation #ifdef HAVE_MPI MPI_Init(&argc, &argv); Epetra_MpiComm Comm(MPI_COMM_WORLD); #else Epetra_SerialComm Comm; #endif // define main parameters double c = 0.25; // continuation parameter int N = 50; // number of grid points int maxNewtonIters = 20; // max number of Newton iterations int maxSteps = 75; // max number of continuation steps taken // Set flag for whether the computations will be Matrix-free (true) or will use a computed // Jacobian (false) bool doMatFree = false; // Create output file to save solutions ofstream outFile("Heq4.dat"); outFile.setf(ios::scientific, ios::floatfield); outFile.precision(10); // Define the problem class HeqProblem Problem(N,&Comm,outFile); // Create the initial guess vector and set it to all ones Epetra_Vector InitialGuess(Problem.GetMap()); InitialGuess.PutScalar(1.0); // Create the top level parameter list Teuchos::RCP<Teuchos::ParameterList> ParamList = Teuchos::rcp(new Teuchos::ParameterList); // Create LOCA sublist Teuchos::ParameterList& locaParamsList = ParamList->sublist("LOCA"); // Create the sublist for continuation and set the stepper parameters Teuchos::ParameterList& stepperList = locaParamsList.sublist("Stepper"); stepperList.set("Continuation Method", "Arc Length");// Default // stepperList.set("Continuation Method", "Natural"); stepperList.set("Continuation Parameter", "c"); // Must set stepperList.set("Initial Value", c); // Must set stepperList.set("Max Value", 100.0); // Must set stepperList.set("Min Value", 0.0); // Must set stepperList.set("Max Steps", maxSteps); // Should set stepperList.set("Max Nonlinear Iterations", maxNewtonIters); // Should set // Set up parameters to compute Eigenvalues #ifdef HAVE_LOCA_ANASAZI // Create Anasazi Eigensolver sublist (needs --with-loca-anasazi) stepperList.set("Compute Eigenvalues",true); Teuchos::ParameterList& aList = stepperList.sublist("Eigensolver"); aList.set("Method", "Anasazi"); aList.set("Block Size", 1); // Size of blocks aList.set("Num Blocks", 20); // Size of Arnoldi factorization aList.set("Num Eigenvalues", 5); // Number of eigenvalues // aList.set("Sorting Order", "SR"); aList.set("Convergence Tolerance", 2.0e-7); // Tolerance aList.set("Step Size", 1); // How often to check convergence aList.set("Maximum Restarts",2); // Maximum number of restarts aList.set("Verbosity", Anasazi::Errors + Anasazi::Warnings + Anasazi::FinalSummary); // Verbosity #else stepperList.set("Compute Eigenvalues",false); #endif stepperList.set("Bordered Solver Method", "Householder"); // stepperList.set("Bordered Solver Method", "Bordering"); // Teuchos::ParameterList& nestedList = // stepperList.sublist("Nested Bordered Solver"); // nestedList.set("Bordered Solver Method", "Householder"); // nestedList.set("Include UV In Preconditioner", true); // //nestedList.set("Use P For Preconditioner", true); // nestedList.set("Preconditioner Method", "SMW"); // Create bifurcation sublist -- use if not doing turning point 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 // predictorList.set("Method", "Constant"); // Other options // predictorList.set("Method", "Tangent"); // Other options // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default stepSizeList.set("Initial Step Size", 0.1); // Should set stepSizeList.set("Min Step Size", 1.0e-4); // Should set stepSizeList.set("Max Step Size", 1.0); // Should set stepSizeList.set("Aggressiveness", 0.1); // Set up NOX info Teuchos::ParameterList& nlParams = ParamList->sublist("NOX"); // Set the nonlinear solver method nlParams.set("Nonlinear Solver", "Line Search Based"); // Set the printing parameters in the "Printing" sublist Teuchos::ParameterList& printParams = nlParams.sublist("Printing"); printParams.set("MyPID", Comm.MyPID()); printParams.set("Output Precision", 5); printParams.set("Output Processor", 0); printParams.set("Output Information", NOX::Utils::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::LinearSolverDetails + NOX::Utils::Parameters + NOX::Utils::Details + NOX::Utils::Warning + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // NOX parameters - Sublist for line search Teuchos::ParameterList& searchParams = nlParams.sublist("Line Search"); searchParams.set("Method", "Full Step"); // searchParams.set("Method", "Backtrack"); // Sublist for direction Teuchos::ParameterList& dirParams = nlParams.sublist("Direction"); dirParams.set("Method", "Newton"); Teuchos::ParameterList& newtonParams = dirParams.sublist("Newton"); newtonParams.set("Forcing Term Method", "Constant"); // Sublist for linear solver for the Newton method Teuchos::ParameterList& lsParams = newtonParams.sublist("Linear Solver"); lsParams.set("Aztec Solver", "GMRES"); lsParams.set("Max Iterations", 800); lsParams.set("Tolerance", 1e-8); lsParams.set("Output Frequency", 1); lsParams.set("Preconditioner", "None"); // lsParams.set("Preconditioner", "AztecOO"); // lsParams.set("Aztec Preconditioner", "ilu"); // lsParams.set("Preconditioner", "Ifpack"); // lsParams.set("Ifpack Preconditioner", "ILU"); // lsParams.set("Preconditioner", "New Ifpack"); // Teuchos::ParameterList& ifpackParams = lsParams.sublist("Ifpack"); // ifpackParams.set("fact: level-of-fill", 1); // set up the continuation parameter vector LOCA::ParameterVector p; p.addParameter("c",c); // Set up the problem interface Teuchos::RCP<SimpleProblemInterface> interface = Teuchos::rcp(new SimpleProblemInterface(&Problem,c) ); Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface; // Create the operator to hold either the Jacobian matrix or the Matrix-free operator Teuchos::RCP<Epetra_Operator> A; Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac; // Need a NOX::Epetra::Vector for constructor // This becomes the initial guess vector that is used for the nonlinear solves NOX::Epetra::Vector noxInitGuess(InitialGuess, NOX::DeepCopy); if (doMatFree) { // Matrix Free application (Epetra Operator): Teuchos::RCP<NOX::Epetra::MatrixFree> MF = Teuchos::rcp(new NOX::Epetra::MatrixFree(printParams, interface, noxInitGuess)); A = MF; iJac = MF; } else { // Computed Jacobian application A = Teuchos::rcp( Problem.GetMatrix(), false ); iJac = interface; } // Build the linear system solver Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys = Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams, iReq, iJac, A, noxInitGuess)); // Create the Loca (continuation) vector NOX::Epetra::Vector locaSoln(noxInitGuess); // 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 - must be LOCA group Teuchos::RCP<LOCA::Epetra::Group> grpPtr = Teuchos::rcp(new LOCA::Epetra::Group(globalData, printParams, iReq, locaSoln, linSys, p)); // Calculate the first F(x0) as a starting point. This is only needed for // certain status tests, to ensure that an initial residual (|r0|) is calculated grpPtr->computeF(); // Set up the status tests to check for convergence // Determines the error tolerance for the Newton solves Teuchos::RCP<NOX::StatusTest::NormF> testNormF = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-4)); // Sets the max number of nonlinear (Newton) iterations that will be taken. If this is not // already set, it will default to the '20' given Teuchos::RCP<NOX::StatusTest::MaxIters> testMaxIters = Teuchos::rcp(new NOX::StatusTest::MaxIters(stepperList.get("Max Nonlinear Iterations", 20))); // This combination of tests will be used by NOX to determine whether the step converged Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR, testNormF, testMaxIters)); // This is sample code to write and read parameters to/from a file. Currently not activated! // To use, change the 'XXXHAVE_TEUCHOS_EXTENDED' TO 'HAVE_TEUCHOS_EXTENDED' #ifdef XXXHAVE_TEUCHOS_EXTENDED // Write the parameter list to a file cout << "Writing parameter list to \"input.xml\"" << endl; Teuchos::writeParameterListToXmlFile(*ParamList, "input.xml"); // Read in the parameter list from a file cout << "Reading parameter list from \"input.xml\"" << endl; Teuchos::RCP<Teuchos::ParameterList> paramList2 = Teuchos::rcp(new Teuchos::ParameterList); Teuchos::updateParametersFromXmlFile("input.xml", paramList2.get()); ParamList = paramList2; #endif // Create the stepper LOCA::Stepper stepper(globalData, grpPtr, combo, ParamList); LOCA::Abstract::Iterator::IteratorStatus status = stepper.run(); // Check if the stepper completed if (status == LOCA::Abstract::Iterator::Finished) globalData->locaUtils->out() << "\nAll tests passed!" << endl; else if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) globalData->locaUtils->out() << "\nStepper failed to converge!" << endl; // Output the stepper parameter list info if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) { globalData->locaUtils->out() << endl << "Final Parameters" << endl << "*******************" << endl; stepper.getList()->print(globalData->locaUtils->out()); globalData->locaUtils->out() << endl; } // Make sure all processors are done and close the output file Comm.Barrier(); outFile.close(); // Deallocate memory LOCA::destroyGlobalData(globalData); #ifdef HAVE_MPI MPI_Finalize(); #endif return(EXIT_SUCCESS); } // DONE!!
int hpx_main(boost::program_options::variables_map& vm) { mini_ghost::profiling::data().time_init( hpx::util::high_resolution_timer::now() - init_start); hpx::util::high_resolution_timer timer_all; hpx::id_type here = hpx::find_here(); std::string name = hpx::get_locality_name(); p.rank = hpx::naming::get_locality_id_from_id(here); if(p.rank == 0) { std::cout << "mini ghost started up in " << hpx::util::high_resolution_timer::now() - init_start << " seconds.\n"; } p.nranks = hpx::get_num_localities_sync(); profiling_data_sem.reset(new hpx::lcos::local::counting_semaphore(p.nranks)); p.setup(vm); // Create the local stepper object, retrieve the local pointer to it hpx::id_type stepper_id = hpx::components::new_<stepper_type>(here).get(); boost::shared_ptr<stepper_type> stepper( hpx::get_ptr<stepper_type>(stepper_id).get()); // Initialize stepper stepper->init(p).get(); mini_ghost::barrier_wait(); // Perform the actual simulation work stepper->run(p.num_spikes, p.num_tsteps); mini_ghost::barrier_wait(); // Output various pieces of information about the run if (stepper->get_rank() == 0) { // Output various pieces of information about the run add_profile(mini_ghost::profiling::data()); if (p.report_perf) mini_ghost::profiling::report(std::cout, profiling_data, p); else std::cout << "Total runtime: " << timer_all.elapsed() << "\n"; std::ofstream fs("results.yaml"); mini_ghost::profiling::report(fs, profiling_data, p); std::cout << "finalizing ...\n"; return hpx::finalize(); } else { // Send performance data from this locality to root hpx::apply(add_profile_action(), hpx::find_root_locality(), mini_ghost::profiling::data()); return 0; } }
int main() { double pi = 4.0*atan(1.0); int n = 100; double alpha = 0.25; double D1 = 1.0/40.0; double D2 = 1.0/40.0; double beta = 2.0*pi*pi*D1 + 1.0 + alpha*alpha; int maxNewtonIters = 10; try { // Create output file to save solutions ofstream outFile("BrusselatorHopfContinuation.dat"); outFile.setf(ios::scientific, ios::floatfield); outFile.precision(14); // Save size of discretizations outFile << n << endl; // Create initial guess for the real and imaginary eigenvectors NOX::LAPACK::Vector y(2*n), z(2*n); double h = 1.0 / double(n-1); double lambda_real = (beta - 1.0 - alpha*alpha)/2.0; double lambda_imag = sqrt(alpha*alpha - lambda_real*lambda_real); double v1_real = -alpha*alpha; double v1_imag = 0.0; double v2_real = beta - 1.0 - lambda_real; double v2_imag = -lambda_imag; double x; for (int i=0; i<n; i++) { x = sin(pi*h*i); y(i) = v1_real*x; z(i) = v1_imag*x; y(i+n) = v2_real*x; z(i+n) = v2_imag*x; } // Initial guess for frequency (valid for |alpha| > (pi^2)*|D1|) double w = lambda_imag; // Create length scaling vector (phi) NOX::LAPACK::Vector phi(2*n); phi.init(1.0); Teuchos::RCP<NOX::Abstract::Vector> y_vec = Teuchos::rcp(&y,false); Teuchos::RCP<NOX::Abstract::Vector> z_vec = Teuchos::rcp(&z,false); Teuchos::RCP<NOX::Abstract::Vector> phi_vec = Teuchos::rcp(&phi,false); // Create initial values for a and b for minimally augmented method Teuchos::RCP<NOX::Abstract::Vector> a_vec_real = Teuchos::rcp(new NOX::LAPACK::Vector(2*n)); Teuchos::RCP<NOX::Abstract::Vector> a_vec_imag = Teuchos::rcp(new NOX::LAPACK::Vector(2*n)); Teuchos::RCP<NOX::Abstract::Vector> b_vec_real = Teuchos::rcp(new NOX::LAPACK::Vector(2*n)); Teuchos::RCP<NOX::Abstract::Vector> b_vec_imag = Teuchos::rcp(new NOX::LAPACK::Vector(2*n)); *a_vec_real = *y_vec; *a_vec_imag = *z_vec; *b_vec_real = *y_vec; *b_vec_imag = *z_vec; // 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 Method", "Arc Length"); // Default //stepperList.set("Continuation Method", "Natural"); // Default stepperList.set("Continuation Parameter", "alpha"); stepperList.set("Initial Value", alpha); stepperList.set("Max Value", 1.0); stepperList.set("Min Value", 0.24); stepperList.set("Max Steps", 100); stepperList.set("Max Nonlinear Iterations", maxNewtonIters); // Create bifurcation sublist Teuchos::ParameterList& bifurcationList = locaParamsList.sublist("Bifurcation"); bifurcationList.set("Type", "Hopf"); bifurcationList.set("Bifurcation Parameter", "beta"); // Must set bifurcationList.set("Initial Frequency", w); // Must set // // For Moore-Spence Formulation // bifurcationList.set("Formulation", "Moore-Spence"); // Default // bifurcationList.set("Solver Method", "Salinger Bordering"); // Default // bifurcationList.set("Length Normalization Vector", phi_vec); // Must set // bifurcationList.set("Initial Real Eigenvector", y_vec); // Must set // bifurcationList.set("Initial Imaginary Eigenvector", z_vec); // Must set // For minimally augmented formulation bifurcationList.set("Formulation", "Minimally Augmented"); bifurcationList.set("Initial Real A Vector", a_vec_real); // Must set bifurcationList.set("Initial Imaginary A Vector", a_vec_imag); // Must set bifurcationList.set("Initial Real B Vector", b_vec_real); // Must set bifurcationList.set("Initial Imaginary B Vector", b_vec_imag); // Must set bifurcationList.set("Update Null Vectors Every Continuation Step", true); // For minimally augmented method, should set these for good performance // Direct solve of bordered equations bifurcationList.set("Bordered Solver Method", "LAPACK Direct Solve"); // Combine arc-length and turning point bordered rows & columns stepperList.set("Bordered Solver Method", "Nested"); Teuchos::ParameterList& nestedList = stepperList.sublist("Nested Bordered Solver"); // Direct solve of combined bordered system nestedList.set("Bordered Solver Method", "LAPACK Direct Solve"); // Create predictor sublist Teuchos::ParameterList& predictorList = locaParamsList.sublist("Predictor"); predictorList.set("Method", "Secant"); // Default // // Should use w/Secant predictor & Moore-Spence formulation // Teuchos::ParameterList& firstStepPredictor // = predictorList.sublist("First Step Predictor"); // firstStepPredictor.set("Method", "Random"); // firstStepPredictor.set("Epsilon", 1.0e-3); // // Should use w/Secant predictor & Moore-Spence fomulation // Teuchos::ParameterList& lastStepPredictor // = predictorList.sublist("Last Step Predictor"); // lastStepPredictor.set("Method", "Random"); // lastStepPredictor.set("Epsilon", 1.0e-3); // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default stepSizeList.set("Initial Step Size", 0.02); stepSizeList.set("Min Step Size", 1.0e-3); stepSizeList.set("Max Step Size", 0.1); stepSizeList.set("Aggressiveness", 0.5); // 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 Precision", 3); nlPrintParams.set("Output Information", NOX::Utils::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::Details + NOX::Utils::Warning + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // Create the "Line Search" sublist for the "Line Search Based" solver Teuchos::ParameterList& searchParams = nlParams.sublist("Line Search"); searchParams.set("Method", "Full Step"); // Create LAPACK Factory Teuchos::RCP<LOCA::LAPACK::Factory> lapackFactory = Teuchos::rcp(new LOCA::LAPACK::Factory); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList, lapackFactory); // Set up the problem interface BrusselatorProblemInterface brus(globalData, n, alpha, beta, D1, D2, outFile); LOCA::ParameterVector p; p.addParameter("alpha",alpha); p.addParameter("beta",beta); p.addParameter("D1",D1); p.addParameter("D2",D2); // 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::LAPACK::Group> grp = Teuchos::rcp(new LOCA::LAPACK::Group(globalData, brus)); grp->setParams(p); // Set up the status tests Teuchos::RCP<NOX::StatusTest::NormF> statusTestA = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-10, NOX::StatusTest::NormF::Scaled)); Teuchos::RCP<NOX::StatusTest::MaxIters> statusTestB = Teuchos::rcp(new NOX::StatusTest::MaxIters(maxNewtonIters)); Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR, statusTestA, statusTestB)); // Create the stepper LOCA::Stepper stepper(globalData, grp, combo, paramList); // Solve the nonlinear system LOCA::Abstract::Iterator::IteratorStatus status = stepper.run(); if (status == LOCA::Abstract::Iterator::Finished) cout << "All examples passed" << 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) { cout << e.what() << endl; } catch (const char *s) { cout << s << endl; } catch (...) { cout << "Caught unknown exception!" << endl; } return 0; }
int main() { int n = 100; double alpha = 0.0; double beta = 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(std::ios::scientific, std::ios::floatfield); outFile.precision(14); // Save size of discretizations outFile << n << std::endl; // 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 Method", "Arc Length");// Default //stepperList.set("Continuation Method", "Natural"); stepperList.set("Continuation Parameter", "alpha"); // Must set stepperList.set("Initial Value", alpha); // Must set stepperList.set("Max Value", 5.0/scale); // Must set stepperList.set("Min Value", 0.0/scale); // Must set stepperList.set("Max Steps", 50); // Should set stepperList.set("Max Nonlinear Iterations", maxNewtonIters); // Should set stepperList.set("Compute Eigenvalues",false); // Default // 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 //predictorList.set("Method", "Constant"); //predictorList.set("Method", "Tangent"); // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default stepSizeList.set("Initial Step Size", 0.1/scale); // Should set stepSizeList.set("Min Step Size", 1.0e-3/scale); // Should set stepSizeList.set("Max Step Size", 10.0/scale); // Should set // 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); // Should set // Create LAPACK Factory Teuchos::RCP<LOCA::LAPACK::Factory> lapackFactory = Teuchos::rcp(new LOCA::LAPACK::Factory); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList, lapackFactory); // Set up the problem interface ChanProblemInterface chan(globalData, n, alpha, beta, scale, outFile); 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) std::cout << "All examples passed" << std::endl; else { if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) globalData->locaUtils->out() << "Stepper failed to converge!" << std::endl; } // Get the final solution from the stepper Teuchos::RCP<const LOCA::LAPACK::Group> finalGroup = Teuchos::rcp_dynamic_cast<const LOCA::LAPACK::Group>(stepper.getSolutionGroup()); const NOX::LAPACK::Vector& finalSolution = dynamic_cast<const NOX::LAPACK::Vector&>(finalGroup->getX()); // Print final solution globalData->locaUtils->out() << std::endl << "Final solution is " << std::endl; finalGroup->printSolution(finalSolution, finalGroup->getParam("alpha")); // 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; }
int main( int argc, char **argv ) { // check for parallel computation #ifdef HAVE_MPI MPI_Init(&argc, &argv); Epetra_MpiComm Comm(MPI_COMM_WORLD); #else Epetra_SerialComm Comm; #endif // define main parameters double c = 0.9999; // continuation parameter int N = 50; // number of grid points int maxNewtonIters = 20; // max number of Newton iterations int maxSteps = 50; // max number of continuation steps taken int ilocal, iglobal; // counter variables used for loops: // ilocal = counter for local elements on this processor; // iglobal = counter to signify global position across all procs int Myele; // holds the number of elements on the processor // Set flag for whether the computations will be Matrix-free (true) or will use a computed // Jacobian (false) bool doMatFree = false; // Create output file to save solutions ofstream outFile("Heq5.dat"); outFile.setf(ios::scientific, ios::floatfield); outFile.precision(10); // Define the problem class HeqProblem Problem(N,&Comm,outFile); // Build initial guess. The initial guess should be a solution vector x close to the // bifurcation point. // Create the initial guess vector Epetra_Vector InitialGuess(Problem.GetMap()); // Get the number of elements on this processor Myele = Problem.GetMap().NumMyElements(); // Compute the initial guess. For this example, it is a line from (0,1) to (1,8/3) for (ilocal=0; ilocal<Myele; ilocal++) { iglobal=Problem.GetMap().GID(ilocal); InitialGuess[ilocal]= 1.0 + (5.0*iglobal)/(3.0*(N-1)); } // Create the null vector for the Jacobian (ie, J*v=0, used to solve the system of equations // f(x,p)=0; J*v=0; v0*v=1. The solution of the system is [x*,v*,p*]. ) Teuchos::RCP<NOX::Abstract::Vector> nullVec = Teuchos::rcp(new NOX::Epetra::Vector(InitialGuess)); // Initialize to all ones nullVec->init(1.0); // NOTE: init is a function within the NOX::Abstract:Vector class which initializes every // value of the vector to the value within the parentheses (must be in 'double' format) // Create the top level parameter list Teuchos::RCP<Teuchos::ParameterList> ParamList = Teuchos::rcp(new Teuchos::ParameterList); // Create LOCA sublist Teuchos::ParameterList& locaParamsList = ParamList->sublist("LOCA"); // Create the sublist for continuation and set the stepper parameters Teuchos::ParameterList& stepperList = locaParamsList.sublist("Stepper"); //stepperList.set("Continuation Method", "Arc Length");// Default stepperList.set("Continuation Method", "Natural"); stepperList.set("Continuation Parameter", "dummy"); // Must set stepperList.set("Initial Value", 999.0); // Must set stepperList.set("Max Value", 50.0e4); // Must set stepperList.set("Min Value", 0.0); // Must set stepperList.set("Max Steps", maxSteps); // Should set stepperList.set("Max Nonlinear Iterations", maxNewtonIters); // Should set stepperList.set("Bordered Solver Method", "Bordering"); // Teuchos::ParameterList& nestedList = // stepperList.sublist("Nested Bordered Solver"); // nestedList.set("Bordered Solver Method", "Householder"); // nestedList.set("Include UV In Preconditioner", true); // //nestedList.set("Use P For Preconditioner", true); // nestedList.set("Preconditioner Method", "SMW"); // Set up parameters to compute Eigenvalues #ifdef HAVE_LOCA_ANASAZI // Create Anasazi Eigensolver sublist (needs --with-loca-anasazi) stepperList.set("Compute Eigenvalues",true); Teuchos::ParameterList& aList = stepperList.sublist("Eigensolver"); aList.set("Method", "Anasazi"); aList.set("Block Size", 1); // Size of blocks aList.set("Num Blocks", 20); // Size of Arnoldi factorization aList.set("Num Eigenvalues", 5); // Number of eigenvalues // aList.set("Sorting Order", "SR"); aList.set("Convergence Tolerance", 2.0e-7); // Tolerance aList.set("Step Size", 1); // How often to check convergence aList.set("Maximum Restarts",2); // Maximum number of restarts aList.set("Verbosity", Anasazi::Errors + Anasazi::Warnings + Anasazi::FinalSummary); // Verbosity #else stepperList.set("Compute Eigenvalues",false); #endif // Create bifurcation sublist. Note that for turning point continuation, the "type" // is set to "Turning Point". If not doing TP, type should be "None". Teuchos::ParameterList& bifurcationList = locaParamsList.sublist("Bifurcation"); bifurcationList.set("Type", "Turning Point"); bifurcationList.set("Bifurcation Parameter", "c"); // bifurcationList.set("Formulation", "Minimally Augmented"); bifurcationList.set("Symmetric Jacobian", false); bifurcationList.set("Update Null Vectors Every Continuation Step", true); bifurcationList.set("Update Null Vectors Every Nonlinear Iteration", false); bifurcationList.set("Transpose Solver Method","Explicit Transpose"); // bifurcationList.set("Transpose Solver Method","Transpose Preconditioner"); // bifurcationList.set("Transpose Solver Method","Left Preconditioning"); bifurcationList.set("Initial Null Vector Computation", "Solve df/dp"); // bifurcationList.set("Initial A Vector", nullVec); // minimally augmented // bifurcationList.set("Initial B Vector", nullVec); //minimally augmented // bifurcationList.set("Bordered Solver Method", "Householder"); // bifurcationList.set("Include UV In Preconditioner", true); // //bifurcationList.set("Use P For Preconditioner", true); // bifurcationList.set("Preconditioner Method", "SMW"); bifurcationList.set("Formulation", "Moore-Spence"); bifurcationList.set("Solver Method", "Phipps Bordering"); // better for nearly singular matrices // bifurcationList.set("Solver Method", "Salinger Bordering"); bifurcationList.set("Initial Null Vector", nullVec); bifurcationList.set("Length Normalization Vector", nullVec); // Create the sublist for the predictor Teuchos::ParameterList& predictorList = locaParamsList.sublist("Predictor"); predictorList.set("Method", "Secant"); // Default // predictorList.set("Method", "Constant"); // Other options // predictorList.set("Method", "Tangent"); // Other options // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); // Default stepSizeList.set("Initial Step Size", 0.1); // Should set stepSizeList.set("Min Step Size", 1.0e-6); // Should set stepSizeList.set("Max Step Size", 1.0); // Should set stepSizeList.set("Aggressiveness", 0.1); // Set up NOX info Teuchos::ParameterList& nlParams = ParamList->sublist("NOX"); // Set the nonlinear solver method nlParams.set("Nonlinear Solver", "Line Search Based"); // Set the printing parameters in the "Printing" sublist. This list determines how much // of the NOX information is output Teuchos::ParameterList& printParams = nlParams.sublist("Printing"); printParams.set("MyPID", Comm.MyPID()); printParams.set("Output Precision", 5); printParams.set("Output Processor", 0); printParams.set("Output Information", NOX::Utils::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::LinearSolverDetails + NOX::Utils::Parameters + NOX::Utils::Details + NOX::Utils::Warning + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); // NOX parameters - Sublist for line search Teuchos::ParameterList& searchParams = nlParams.sublist("Line Search"); searchParams.set("Method", "Backtrack"); // searchParams.set("Method", "Full Step"); // Sublist for direction Teuchos::ParameterList& dirParams = nlParams.sublist("Direction"); dirParams.set("Method", "Newton"); Teuchos::ParameterList& newtonParams = dirParams.sublist("Newton"); newtonParams.set("Forcing Term Method", "Constant"); // Sublist for linear solver for the Newton method Teuchos::ParameterList& lsParams = newtonParams.sublist("Linear Solver"); lsParams.set("Aztec Solver", "GMRES"); lsParams.set("Max Iterations", 800); lsParams.set("Tolerance", 1e-8); lsParams.set("Output Frequency", 1); lsParams.set("Preconditioner", "None"); // lsParams.set("Preconditioner", "AztecOO"); // lsParams.set("Aztec Preconditioner", "ilu"); // lsParams.set("Scaling", "None"); // lsParams.set("Scaling", "Row Sum"); lsParams.set("Compute Scaling Manually", false); // lsParams.set("Preconditioner", "Ifpack"); // lsParams.set("Ifpack Preconditioner", "ILU"); // lsParams.set("Preconditioner", "New Ifpack"); // Teuchos::ParameterList& ifpackParams = lsParams.sublist("Ifpack"); // ifpackParams.set("fact: level-of-fill", 1); // Set up the continuation parameter vector LOCA::ParameterVector p; p.addParameter("c",c); p.addParameter("dummy",999.0); // Create the problem interface Teuchos::RCP<SimpleProblemInterface> interface = Teuchos::rcp(new SimpleProblemInterface(&Problem,c) ); Teuchos::RCP<LOCA::Epetra::Interface::Required> iReq = interface; // Create the operator to hold either the Jacobian matrix or the Matrix-free operator Teuchos::RCP<Epetra_Operator> A; // Teuchos::RCP<Epetra_RowMatrix> A; Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac; // Need a NOX::Epetra::Vector for constructor // This becomes the initial guess vector that is used for the nonlinear solves NOX::Epetra::Vector noxInitGuess(InitialGuess, NOX::DeepCopy); if (doMatFree) { // Matrix Free application (Epetra Operator): Teuchos::RCP<NOX::Epetra::MatrixFree> MF = Teuchos::rcp(new NOX::Epetra::MatrixFree(printParams, interface, noxInitGuess)); A = MF; iJac = MF; } else { // Computed Jacobian application A = Teuchos::rcp( Problem.GetMatrix(), false ); iJac = interface; } // 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); //bifurcationList.set("Transpose Scaling", trans_scaling); // Build the linear system solver Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys = Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams, iReq, iJac, A, noxInitGuess, scaling)); // use if scaling // noxInitGuess)); // use if no scaling // Create the Loca (continuation) vector NOX::Epetra::Vector locaSoln(noxInitGuess); // 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 - must be LOCA group Teuchos::RCP<LOCA::Epetra::Group> grpPtr = Teuchos::rcp(new LOCA::Epetra::Group(globalData, printParams, iReq, locaSoln, linSys, p)); // Calculate the first F(x0) as a starting point. This is only needed for // certain status tests, to ensure that an initial residual (|r0|) is calculated grpPtr->computeF(); // Set up the status tests to check for convergence // Determines the error tolerance for the Newton solves Teuchos::RCP<NOX::StatusTest::NormF> testNormF = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-4)); // Sets the max number of nonlinear (Newton) iterations that will be taken. If this is not // already set, it will default to the '20' given Teuchos::RCP<NOX::StatusTest::MaxIters> testMaxIters = Teuchos::rcp(new NOX::StatusTest::MaxIters(stepperList.get("Max Nonlinear Iterations", 20))); // This combination of tests will be used by NOX to determine whether the step converged Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR, testNormF, testMaxIters)); // This is sample code to write and read parameters to/from a file. Currently not activated! // To use, change the 'XXXHAVE_TEUCHOS_EXTENDED' TO 'HAVE_TEUCHOS_EXTENDED' #ifdef XXXHAVE_TEUCHOS_EXTENDED // Write the parameter list to a file cout << "Writing parameter list to \"input.xml\"" << endl; Teuchos::writeParameterListToXmlFile(*ParamList, "input.xml"); // Read in the parameter list from a file cout << "Reading parameter list from \"input.xml\"" << endl; Teuchos::RCP<Teuchos::ParameterList> paramList2 = Teuchos::rcp(new Teuchos::ParameterList); Teuchos::updateParametersFromXmlFile("input.xml", paramList2.get()); ParamList = paramList2; #endif // Create the stepper LOCA::Stepper stepper(globalData, grpPtr, combo, ParamList); LOCA::Abstract::Iterator::IteratorStatus status = stepper.run(); // Check if the stepper completed if (status == LOCA::Abstract::Iterator::Finished) globalData->locaUtils->out() << "\nAll tests passed!" << endl; else if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) globalData->locaUtils->out() << "\nStepper failed to converge!" << endl; // Output the stepper parameter list info if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) { globalData->locaUtils->out() << endl << "Final Parameters" << endl << "*******************" << endl; stepper.getList()->print(globalData->locaUtils->out()); globalData->locaUtils->out() << endl; } // Make sure all processors are done and close the output file Comm.Barrier(); outFile.close(); // Deallocate memory LOCA::destroyGlobalData(globalData); #ifdef HAVE_MPI MPI_Finalize(); #endif return(EXIT_SUCCESS); } // DONE!!