void CONMINOptimizer::initialize_run() { Optimizer::initialize_run(); // Allocate space for CONMIN arrays allocate_constraints(); allocate_workspace(); // initialize the IC and ISC vectors size_t i; for (i=0; i<numConminConstr; i++) IC[i] = ISC[i] = 0; // Initialize CONMIN's local vars and bounds arrays // Note: these are different than DAKOTA's local vars and bounds arrays // because CONMIN uses arrays for vars and bounds that are larger than // used by DAKOTA, i.e., DAKOTA's local_cdv has length numContinuousVars, // and CONMIN's conminDesVars has length N1 = numContinuousVars+2 // // copy DAKOTA arrays to CONMIN arrays and check for the existence of bounds. const RealVector& local_cdv = iteratedModel.continuous_variables(); const RealVector& lower_bnds = iteratedModel.continuous_lower_bounds(); const RealVector& upper_bnds = iteratedModel.continuous_upper_bounds(); for (i=0; i<numContinuousVars; i++) { conminDesVars[i] = local_cdv[i]; conminLowerBnds[i] = lower_bnds[i]; conminUpperBnds[i] = upper_bnds[i]; } // Initialize array padding (N1 = numContinuousVars + 2). for (i=numContinuousVars; i<N1; i++) { conminDesVars[i] = 0.0; conminLowerBnds[i] = -DBL_MAX; conminUpperBnds[i] = DBL_MAX; } }
void NLPQLPOptimizer::initialize_run() { Optimizer::initialize_run(); allocate_constraints(); allocate_workspace(); const RealVector& local_cdv = iteratedModel.continuous_variables(); for (size_t i=0; i<numContinuousVars; i++) X[i] = local_cdv[i]; // Note: X is [NMAX,L] IFAIL = 0; // initialize to zero prior to first NLPQLP call }
int zprimme(double *evals, Complex_Z *evecs, double *resNorms, primme_params *primme) { int ret; int *perm; double machEps; /* ------------------ */ /* zero out the timer */ /* ------------------ */ primme_wTimer(1); /* ---------------------------- */ /* Clear previous error reports */ /* ---------------------------- */ primme_DeleteStackTrace(primme); /* ----------------------- */ /* Find machine precision */ /* ----------------------- */ machEps = Num_dlamch_primme("E"); /* ------------------ */ /* Set some defaults */ /* ------------------ */ primme_set_defaults(primme); /* -------------------------------------------------------------- */ /* If needed, we are ready to estimate required memory and return */ /* -------------------------------------------------------------- */ if (evals == NULL && evecs == NULL && resNorms == NULL) return allocate_workspace(primme, FALSE); /* ----------------------------------------------------- */ /* Reset random number seed if inappropriate for DLARENV */ /* Yields unique quadruples per proc if procID < 4096^3 */ /* ----------------------------------------------------- */ if (primme->iseed[0]<0 || primme->iseed[0]>4095) primme->iseed[0] = primme->procID % 4096; if (primme->iseed[1]<0 || primme->iseed[1]>4095) primme->iseed[1] = (int)(primme->procID/4096+1) % 4096; if (primme->iseed[2]<0 || primme->iseed[2]>4095) primme->iseed[2] = (int)((primme->procID/4096)/4096+2) % 4096; if (primme->iseed[3]<0 || primme->iseed[3]>4095) primme->iseed[3] = (2*(int)(((primme->procID/4096)/4096)/4096)+1) % 4096; /* ----------------------- */ /* Set default convTetFun */ /* ----------------------- */ if (!primme->convTestFun) { primme->convTestFun = convTestFunAbsolute; } /* ------------------------------------------------------- */ /* Check primme input data for bounds, correct values etc. */ /* ------------------------------------------------------- */ ret = check_input(evals, evecs, resNorms, primme); if (ret != 0) { primme_PushErrorMessage(Primme_zprimme, Primme_check_input, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return ret; } /* ----------------------------------------------------------------------- */ /* Compute AND allocate memory requirements for main_iter and subordinates */ /* ----------------------------------------------------------------------- */ ret = allocate_workspace(primme, TRUE); if (ret != 0) { primme_PushErrorMessage(Primme_zprimme, Primme_allocate_workspace, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return ALLOCATE_WORKSPACE_FAILURE; } /* --------------------------------------------------------- */ /* Allocate workspace that will be needed locally by zprimme */ /* --------------------------------------------------------- */ perm = (int *)primme_calloc((primme->numEvals), sizeof(int), "Perm array"); if (perm == NULL) { primme_PushErrorMessage(Primme_zprimme, Primme_malloc, 0, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return MALLOC_FAILURE; } /*----------------------------------------------------------------------*/ /* Call the solver */ /*----------------------------------------------------------------------*/ ret = main_iter_zprimme(evals, perm, evecs, resNorms, machEps, primme->intWork, primme->realWork, primme); if (ret < 0) { primme_PushErrorMessage(Primme_zprimme, Primme_main_iter, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return MAIN_ITER_FAILURE; } /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ /* If locking is engaged, the converged Ritz vectors are stored in the */ /* order they converged. They must then be permuted so that they */ /* correspond to the sorted Ritz values in evals. */ /*----------------------------------------------------------------------*/ permute_vecs_zprimme(&evecs[primme->numOrthoConst], primme->nLocal, primme->initSize, primme->nLocal, perm, (Complex_Z*)primme->realWork, (int*)primme->intWork); free(perm); primme->stats.elapsedTime = primme_wTimer(0); return(0); }
int dprimme(double *evals, double *evecs, double *resNorms, primme_params *primme) { int ret; int *perm; double machEps; /* ------------------ */ /* zero out the timer */ /* ------------------ */ primme_wTimer(1); /* ---------------------------- */ /* Clear previous error reports */ /* ---------------------------- */ primme_DeleteStackTrace(primme); /* ----------------------- */ /* Find machine precision */ /* ----------------------- */ machEps = Num_dlamch_primme("E"); /* ----------------------------------------- */ /* Set some defaults for sequential programs */ /* ----------------------------------------- */ if (primme->numProcs == 1) { primme->nLocal = primme->n; primme->procID = 0; if (primme->globalSumDouble == NULL) primme->globalSumDouble = primme_seq_globalSumDouble; } /* --------------------------------------------------------------------- */ /* Decide on whether to use locking (hard locking), or not (soft locking)*/ /* --------------------------------------------------------------------- */ if (primme->target != primme_smallest && primme->target != primme_largest ) { /* Locking is necessary as interior Ritz values can cross shifts */ primme->locking = 1; } else { if (primme->locking == 0) { /* use locking when not enough vectors to restart with */ primme->locking = (primme->numEvals > primme->minRestartSize); } } /* -------------------------------------------------------------- */ /* If needed, we are ready to estimate required memory and return */ /* -------------------------------------------------------------- */ if (evals == NULL && evecs == NULL && resNorms == NULL) return allocate_workspace(primme, FALSE); /* ----------------------------------------------------- */ /* Reset random number seed if inappropriate for DLARENV */ /* Yields unique quadruples per proc if procID < 4096^3 */ /* ----------------------------------------------------- */ if (primme->iseed[0]<0 || primme->iseed[0]>4095) primme->iseed[0] = primme->procID % 4096; if (primme->iseed[1]<0 || primme->iseed[1]>4095) primme->iseed[1] = (int)(primme->procID/4096+1) % 4096; if (primme->iseed[2]<0 || primme->iseed[2]>4095) primme->iseed[2] = (int)((primme->procID/4096)/4096+2) % 4096; if (primme->iseed[3]<0 || primme->iseed[3]>4095) primme->iseed[3] = (2*(int)(((primme->procID/4096)/4096)/4096)+1) % 4096; /* ------------------------------------------------------- */ /* Check primme input data for bounds, correct values etc. */ /* ------------------------------------------------------- */ ret = check_input(evals, evecs, resNorms, primme); if (ret != 0) { primme_PushErrorMessage(Primme_dprimme, Primme_check_input, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return ret; } /* ----------------------------------------------------------------------- */ /* Compute AND allocate memory requirements for main_iter and subordinates */ /* ----------------------------------------------------------------------- */ ret = allocate_workspace(primme, TRUE); if (ret != 0) { primme_PushErrorMessage(Primme_dprimme, Primme_allocate_workspace, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return ALLOCATE_WORKSPACE_FAILURE; } /* --------------------------------------------------------- */ /* Allocate workspace that will be needed locally by dprimme */ /* --------------------------------------------------------- */ perm = (int *)primme_calloc((primme->numEvals), sizeof(int), "Perm array"); if (perm == NULL) { primme_PushErrorMessage(Primme_dprimme, Primme_malloc, 0, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return MALLOC_FAILURE; } /*----------------------------------------------------------------------*/ /* Call the solver */ /*----------------------------------------------------------------------*/ ret = main_iter_dprimme(evals, perm, evecs, resNorms, machEps, primme->intWork, primme->realWork, primme); if (ret < 0) { primme_PushErrorMessage(Primme_dprimme, Primme_main_iter, ret, __FILE__, __LINE__, primme); primme->stats.elapsedTime = primme_wTimer(0); return MAIN_ITER_FAILURE; } /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ /* If locking is engaged, the converged Ritz vectors are stored in the */ /* order they converged. They must then be permuted so that they */ /* correspond to the sorted Ritz values in evals. */ /*----------------------------------------------------------------------*/ permute_evecs_dprimme(&evecs[primme->numOrthoConst], perm, (double *) primme->realWork, primme->numEvals, primme->nLocal); free(perm); primme->stats.elapsedTime = primme_wTimer(0); return(0); }
void NLSSOLLeastSq::minimize_residuals() { //------------------------------------------------------------------ // Solve the problem. //------------------------------------------------------------------ // set the object instance pointers for use within the static member fns NLSSOLLeastSq* prev_nls_instance = nlssolInstance; SOLBase* prev_sol_instance = solInstance; nlssolInstance = this; solInstance = this; optLSqInstance = this; // set the constraint offset used in SOLBase::constraint_eval() constrOffset = numLeastSqTerms; fnEvalCntr = 0; // prevent current iterator from continuing previous counting // Use data structures in the NLSSOL call that are NOT updated in // constraint_eval or least_sq_eval [Using overlapping arrays causes // erroneous behavior]. int num_cv = numContinuousVars; double local_f_val = 0.; RealVector local_lsq_vals(numLeastSqTerms); RealVector local_lsq_offsets(numLeastSqTerms, true); double* local_lsq_grads = new double [numLeastSqTerms*numContinuousVars]; allocate_arrays(numContinuousVars, numNonlinearConstraints, iteratedModel.linear_ineq_constraint_coeffs(), iteratedModel.linear_eq_constraint_coeffs()); allocate_workspace(numContinuousVars, numNonlinearConstraints, numLinearConstraints, numLeastSqTerms); // NLSSOL requires a non-zero array size. Therefore, size the local // constraint arrays and matrices to a size of 1 if there are no nonlinear // constraints and to the proper size otherwise. RealVector local_c_vals(nlnConstraintArraySize); // initialize local_des_vars with DB initial point. Variables are updated // in constraint_eval/least_sq_eval RealVector local_des_vars; copy_data(iteratedModel.continuous_variables(), local_des_vars); // Augmentation of bounds appears here rather than in the constructor because // these bounds must be updated from model bounds each time an iterator is // run within the B&B strategy. RealVector augmented_l_bnds, augmented_u_bnds; copy_data(iteratedModel.continuous_lower_bounds(), augmented_l_bnds); copy_data(iteratedModel.continuous_upper_bounds(), augmented_u_bnds); augment_bounds(augmented_l_bnds, augmented_u_bnds, iteratedModel.linear_ineq_constraint_lower_bounds(), iteratedModel.linear_ineq_constraint_upper_bounds(), iteratedModel.linear_eq_constraint_targets(), iteratedModel.nonlinear_ineq_constraint_lower_bounds(), iteratedModel.nonlinear_ineq_constraint_upper_bounds(), iteratedModel.nonlinear_eq_constraint_targets()); NLSSOL_F77( numLeastSqTerms, num_cv, numLinearConstraints, numNonlinearConstraints, linConstraintArraySize, nlnConstraintArraySize, numLeastSqTerms, num_cv, linConstraintMatrixF77, augmented_l_bnds.values(), augmented_u_bnds.values(), constraint_eval, least_sq_eval, informResult, numberIterations, &constraintState[0], local_c_vals.values(), constraintJacMatrixF77, local_lsq_offsets.values(), local_lsq_vals.values(), local_lsq_grads, &cLambda[0], local_f_val, upperFactorHessianF77, local_des_vars.values(), &intWorkSpace[0], intWorkSpaceSize, &realWorkSpace[0], realWorkSpaceSize ); // NLSSOL completed. Do post-processing/output of final NLSSOL info and data: Cout << "\nNLSSOL exits with INFORM code = " << informResult << " (see \"Interpretation of output\" section of NPSOL manual)\n"; deallocate_arrays(); // SOLBase deallocate fn (shared with NPSOLOptimizer) delete [] local_lsq_grads; // Set best variables and response for use by strategy level. // local_des_vars, local_lsq_vals, & local_c_vals contain the optimal design // (not the final fn. eval) since NLSSOL performs this assignment internally // prior to exiting (see "Subroutine npsol" section of NPSOL manual). bestVariablesArray.front().continuous_variables(local_des_vars); RealVector best_fns(numFunctions); //copy_data_partial(local_lsq_vals, best_fns, 0); std::copy(local_lsq_vals.values(), local_lsq_vals.values() + numLeastSqTerms, best_fns.values()); if (numNonlinearConstraints) { //copy_data_partial(local_c_vals, best_fns, numLeastSqTerms); std::copy(local_c_vals.values(), local_c_vals.values() + nlnConstraintArraySize, best_fns.values() + numLeastSqTerms); } bestResponseArray.front().function_values(best_fns); /* // For better post-processing, could append fort.9 to dakota.out line // by line, but: THERE IS A PROBLEM WITH GETTING ALL OF THE FILE! // (FORTRAN output is lacking a final buffer flush?) Cout << "\nEcho NLSSOL's iteration output from fort.9 file:\n" << std::endl; std::ifstream npsol_fort_9( "fort.9" ); char fort_9_line[255]; while (npsol_fort_9) { npsol_fort_9.getline( fort_9_line, 255 ); Cout << fort_9_line << '\n'; } Cout << std::endl; */ Cout << "\nNOTE: see Fortran device 9 file (fort.9 or ftn09)" << "\n for complete NLSSOL iteration history." << std::endl; get_confidence_intervals(); // restore in case of recursion nlssolInstance = prev_nls_instance; solInstance = prev_sol_instance; optLSqInstance = prevMinInstance; }