int main() { UserData data; realtype fnormtol, scsteptol; N_Vector u1, u2, u, s, c; int glstr, mset, flag; void *kmem; u1 = u2 = u = NULL; s = c = NULL; kmem = NULL; data = NULL; /* User data */ data = (UserData)malloc(sizeof *data); data->lb[0] = PT25; data->ub[0] = ONE; data->lb[1] = ONEPT5; data->ub[1] = TWO*PI; /* Create serial vectors of length NEQ */ u1 = N_VNew_Serial(NEQ); if (check_flag((void *)u1, "N_VNew_Serial", 0)) return(1); u2 = N_VNew_Serial(NEQ); if (check_flag((void *)u2, "N_VNew_Serial", 0)) return(1); u = N_VNew_Serial(NEQ); if (check_flag((void *)u, "N_VNew_Serial", 0)) return(1); s = N_VNew_Serial(NEQ); if (check_flag((void *)s, "N_VNew_Serial", 0)) return(1); c = N_VNew_Serial(NEQ); if (check_flag((void *)c, "N_VNew_Serial", 0)) return(1); SetInitialGuess1(u1,data); SetInitialGuess2(u2,data); N_VConst_Serial(ONE,s); /* no scaling */ Ith(c,1) = ZERO; /* no constraint on x1 */ Ith(c,2) = ZERO; /* no constraint on x2 */ Ith(c,3) = ONE; /* l1 = x1 - x1_min >= 0 */ Ith(c,4) = -ONE; /* L1 = x1 - x1_max <= 0 */ Ith(c,5) = ONE; /* l2 = x2 - x2_min >= 0 */ Ith(c,6) = -ONE; /* L2 = x2 - x22_min <= 0 */ fnormtol=FTOL; scsteptol=STOL; kmem = KINCreate(); if (check_flag((void *)kmem, "KINCreate", 0)) return(1); flag = KINSetUserData(kmem, data); if (check_flag(&flag, "KINSetUserData", 1)) return(1); flag = KINSetConstraints(kmem, c); if (check_flag(&flag, "KINSetConstraints", 1)) return(1); flag = KINSetFuncNormTol(kmem, fnormtol); if (check_flag(&flag, "KINSetFuncNormTol", 1)) return(1); flag = KINSetScaledStepTol(kmem, scsteptol); if (check_flag(&flag, "KINSetScaledStepTol", 1)) return(1); flag = KINInit(kmem, func, u); if (check_flag(&flag, "KINInit", 1)) return(1); /* Call KINDense to specify the linear solver */ flag = KINDense(kmem, NEQ); if (check_flag(&flag, "KINDense", 1)) return(1); /* Print out the problem size, solution parameters, initial guess. */ PrintHeader(fnormtol, scsteptol); /* --------------------------- */ printf("\n------------------------------------------\n"); printf("\nInitial guess on lower bounds\n"); printf(" [x1,x2] = "); PrintOutput(u1); N_VScale_Serial(ONE,u1,u); glstr = KIN_NONE; mset = 1; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u1,u); glstr = KIN_LINESEARCH; mset = 1; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u1,u); glstr = KIN_NONE; mset = 0; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u1,u); glstr = KIN_LINESEARCH; mset = 0; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ printf("\n------------------------------------------\n"); printf("\nInitial guess in middle of feasible region\n"); printf(" [x1,x2] = "); PrintOutput(u2); N_VScale_Serial(ONE,u2,u); glstr = KIN_NONE; mset = 1; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u2,u); glstr = KIN_LINESEARCH; mset = 1; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u2,u); glstr = KIN_NONE; mset = 0; SolveIt(kmem, u, s, glstr, mset); /* --------------------------- */ N_VScale_Serial(ONE,u2,u); glstr = KIN_LINESEARCH; mset = 0; SolveIt(kmem, u, s, glstr, mset); /* Free memory */ N_VDestroy_Serial(u); N_VDestroy_Serial(s); N_VDestroy_Serial(c); KINFree(&kmem); free(data); return(0); }
static void* vscale(NrnThread* nt) { int i = nt->id; N_VScale_Serial(carg, xarg(i), zarg(i)); return (void*)0; }
void N_VScale(double c, N_Vector x, N_Vector z) { N_VScale_Serial(c, x, z); return; }