int soclcp_test_function(FILE * f, SolverOptions * options) { int k, info = -1 ; SecondOrderConeLinearComplementarityProblem* problem = (SecondOrderConeLinearComplementarityProblem *)malloc(sizeof(SecondOrderConeLinearComplementarityProblem)); assert(f); assert(problem); info = secondOrderConeLinearComplementarityProblem_newFromFile(problem, f); FILE * foutput = fopen("checkinput.dat", "w"); info = secondOrderConeLinearComplementarityProblem_printInFile(problem, foutput); /* secondOrderConeLinearComplementarityProblem_display(problem); */ NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default int n = problem->n; double *r = (double*)malloc(n * sizeof(double)); double *v = (double*)malloc(n * sizeof(double)); for(k = 0 ; k <n; k++) { v[k] = 0.0; r[k] = 0.0; } info = soclcp_driver(problem, r , v, options, &global_options); printf("\n"); for(k = 0 ; k < n; k++) { printf("v[%i] = %12.8e \t \t r[%i] = %12.8e\n", k, v[k], k , r[k]); } printf("\n"); if(!info) { printf("test succeeded\n"); } else { printf("test unsuccessful\n"); } free(r); free(v); freeSecondOrderConeLinearComplementarityProblem(problem); fclose(foutput); return info; }
int main(void) { NumericsOptions NO; setDefaultNumericsOptions(&NO); NO.verboseMode = 1; // turn verbose mode to off by default int total_info = 0; double q[] = { -1, 1, 3, -1, 1, 3, -1, 1, 3}; double mu[] = {0.1, 0.1, 0.1}; double Wdata[81] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; NumericsMatrix* tmpM = createNumericsMatrixFromData(NM_DENSE, 9, 9, Wdata); NumericsMatrix* W = createNumericsMatrix(NM_SPARSE, 9, 9); NM_copy_to_sparse(tmpM, W); int solvers_to_test[] = {SICONOS_FRICTION_3D_NSGS, SICONOS_FRICTION_3D_NSN_AC, SICONOS_FRICTION_3D_NSN_FB, SICONOS_FRICTION_3D_NSN_NM, SICONOS_FRICTION_3D_SOCLCP, SICONOS_FRICTION_3D_PROX}; for (size_t s = 0; s < sizeof(solvers_to_test); ++s) { int solver_id = solvers_to_test[s]; FrictionContactProblem* FC = frictionContactProblem_new(3, 3, W, q, mu); double r[9] = {0.}; double u[9] = {0.}; SolverOptions SO;; fc3d_setDefaultSolverOptions(&SO, solver_id); int info = fc3d_driver(FC, r, u, &SO, &NO); if (info) { fprintf(stderr, "Solver %s failed with error %d\n", idToName(solver_id), info); total_info = 1; } FC->M = NULL; FC->q = NULL; FC->mu = NULL; deleteSolverOptions(&SO); freeFrictionContactProblem(FC); free(FC); } freeNumericsMatrix(W); tmpM->matrix0 = NULL; freeNumericsMatrix(tmpM); free(W); free(tmpM); return total_info; }
int main(void) { VariationalInequality vi; variationalInequality_clear(&vi); vi.size=1; //vi.Callback = (CallbackVI *)malloc(sizeof(CallbackVI)); vi.env = &vi; vi.F = &Ftest; vi.ProjectionOnX = &PXtest ; /* Call the callback */ double x[1], F[1], PX[1]; int i, n=1; for (i =0; i< n ; i++) { x[i] = i-5; } vi.F(&vi,n,x,F); vi.ProjectionOnX(&vi,x,PX); for (i =0; i< n ; i++) { printf("x[%i]=%f\t",i,x[i]); printf("F[%i]=%f\t",i,F[i]); printf("PX[%i]=%f\n",i,PX[i]); } NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default SolverOptions * options = (SolverOptions *) malloc(sizeof(SolverOptions)); int info = variationalInequality_setDefaultSolverOptions(options, SICONOS_VI_HP); options->dparam[0]=1e-10; options->iparam[0]=50000000; info = variationalInequality_driver(&vi, x, F, options, &global_options); for (i =0; i< n ; i++) { printf("x[%i]=%f\t",i,x[i]); printf("w[%i]=F[%i]=%f\n",i,i,F[i]); } deleteSolverOptions(options); free(options); return info; }
OneStepNSProblem::OneStepNSProblem(): _indexSetLevel(0), _inputOutputLevel(0), _maxSize(0), _nbIter(0), _hasBeenUpdated(false) { _numerics_solver_options.reset(new SolverOptions); _numerics_solver_options->iWork = NULL; _numerics_solver_options->callback = NULL; _numerics_solver_options->dWork = NULL; // Numerics general options _numerics_options.reset(new NumericsOptions()); setDefaultNumericsOptions(&*_numerics_options); _numerics_options->verboseMode = 0; // turn verbose mode to off by default }
int gfc3d_LmgcDriver(double *reaction, double *velocity, double *globalVelocity, double *q, double *b, double *mu, double *Mdata, unsigned int nzM, unsigned int *rowM, unsigned int *colM, double* Hdata, unsigned int nzH, unsigned int *rowH, unsigned int *colH, unsigned int n, unsigned int nc, int solver_id, int isize, int *iparam, int dsize, double *dparam, int verbose, int outputFile, int freq_output) { /* NumericsMatrix M, H; */ NumericsMatrix * M =newNumericsMatrix(); M->storageType = 2; /* sparse */ M->size0 = n; M->size1 = n; NumericsMatrix * H =newNumericsMatrix(); H->storageType = 2; H->size0 = M->size0; H->size1 = 3 * nc; NumericsSparseMatrix * SM =newNumericsSparseMatrix(); M->matrix2 = SM; SM->triplet = (CSparseMatrix * )malloc(sizeof(CSparseMatrix)); CSparseMatrix * _M = SM->triplet; SM->origin = NS_TRIPLET; csi * _colM = alloc_memory_csi(nzM, colM); csi * _rowM = alloc_memory_csi(nzM, rowM); _M->nzmax = nzM; _M->nz = nzM; _M->m = M->size0; _M->n = M->size1; _M->p = (csi *) _colM; _M->i = (csi *) _rowM; double * _Mdata = alloc_memory_double(nzM, Mdata); _M->x = _Mdata; DEBUG_PRINTF("_M->n=%li\t",_M->n); DEBUG_PRINTF("_M->m=%li\n",_M->m); NumericsSparseMatrix * SH =newNumericsSparseMatrix(); H->matrix2 = SH; SH->triplet = (CSparseMatrix * )malloc(sizeof(CSparseMatrix)); CSparseMatrix * _H = SH->triplet; SH->origin = NS_TRIPLET; csi * _colH = alloc_memory_csi(nzH, colH); csi * _rowH = alloc_memory_csi(nzH, rowH); _H->nzmax = nzH; _H->nz = nzH; _H->m = H->size0; _H->n = H->size1; _H->p = _colH; _H->i = _rowH; double * _Hdata = alloc_memory_double(nzH, Hdata); _H->x = _Hdata; for (int i=0; i< _M->nz; ++i) { _M->p[i] --; _M->i[i] --; /* DEBUG_PRINTF("%d -> %d,%d\n", i, _M->p[i], _M->i[i]); */ } for (int i=0; i< _H->nz; ++i) { _H->p[i] --; _H->i[i] --; /* DEBUG_PRINTF("%d -> %d,%d\n", i, _H->p[i], _H->i[i]); */ } GlobalFrictionContactProblem * problem =(GlobalFrictionContactProblem*)malloc(sizeof(GlobalFrictionContactProblem)); problem->dimension = 3; problem->numberOfContacts = nc; problem->env = NULL; problem->workspace = NULL; problem->M = M; problem->H = H; problem->q = q; problem->b = b; problem->mu = mu; NumericsOptions numerics_options; setDefaultNumericsOptions(&numerics_options); numerics_options.verboseMode = verbose; SolverOptions numerics_solver_options; gfc3d_setDefaultSolverOptions(&numerics_solver_options, solver_id); int iSize_min = isize < numerics_solver_options.iSize ? isize : numerics_solver_options.iSize; for (int i = 0; i < iSize_min; ++i) numerics_solver_options.iparam[i] = iparam[i]; int dSize_min = dsize < numerics_solver_options.dSize ? dsize : numerics_solver_options.dSize; for (int i=0; i < dSize_min; ++i) numerics_solver_options.dparam[i] = dparam[i]; /* printSolverOptions(&numerics_solver_options); */ /* FILE * file = fopen("toto.dat", "w"); */ /* globalFrictionContact_printInFile(problem, file); */ /* fclose(file); */ int rinfo = gfc3d_driver(problem, reaction, velocity, globalVelocity, &numerics_solver_options, &numerics_options); /* FILE * file1 = fopen("tutu.dat", "w"); */ /* globalFrictionContact_printInFile(problem, file1); */ /* fclose(file1); */ if(outputFile == 1) { /* dump in C format */ } else if (outputFile == 2) { /* dump in Numerics .dat format */ } else if (outputFile == 3) { #ifdef WITH_FCLIB fccounter++; if (fccounter % freq_output == 0) { char fname[256]; snprintf(fname, sizeof(fname), "LMGC_GFC3D-i%.5d-%i-%.5d.hdf5", numerics_solver_options.iparam[7], nc, fccounter); printf("Dump LMGC_GFC3D-i%.5d-%i-%.5d.hdf5.\n", numerics_solver_options.iparam[7], nc, fccounter); /* printf("ndof = %i.\n", ndof); */ FILE * foutput = fopen(fname, "w"); int n = 100; char * title = (char *)malloc(n * sizeof(char *)); strncpy(title, "LMGC dump in hdf5", n); char * description = (char *)malloc(n * sizeof(char *)); snprintf(description, n, "Rewriting in hdf5 through siconos of %s in FCLIB format", fname); char * mathInfo = (char *)malloc(n * sizeof(char *)); strncpy(mathInfo, "unknown", n); globalFrictionContact_fclib_write(problem, title, description, mathInfo, fname); fclose(foutput); } #else printf("Fclib is not available ...\n"); #endif } freeNumericsMatrix(M); freeNumericsMatrix(H); free(M); free(H); free(problem); /* free(_colM); */ /* free(_colH); */ /* free(_rowM); */ /* free(_rowH); */ return rinfo; }
int main(void) { VariationalInequality vi; variationalInequality_clear(&vi); //vi.env = &vi; vi.F = &Ftest; vi.ProjectionOnX = &PXtest; vi.normVI = 0.0; vi.istheNormVIset = 0; vi.set = NULL; vi.nabla_F = NULL; NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default SolverOptions * options = (SolverOptions *) malloc(sizeof(SolverOptions)); int info = variationalInequality_setDefaultSolverOptions(options, SICONOS_VI_FPP); options->dparam[0]=1e-8; FILE * finput = fopen("./data/Example1_Fc3D_SBM.dat", "r"); FrictionContactProblem* problem = (FrictionContactProblem *)malloc(sizeof(FrictionContactProblem)); info = frictionContact_newFromFile(problem, finput); // frictionContact_display(problem); Problems *pb= (Problems *)malloc(sizeof(Problems)); vi.env = pb; pb->vi = &vi; pb->fc3d = problem; frictionContact_display(pb->fc3d); int n = problem->numberOfContacts * problem->dimension; vi.size=n; double *x = (double*)calloc(n, sizeof(double)); double *w = (double*)calloc(n, sizeof(double)); PXtest(&vi, x,w); info = variationalInequality_driver(&vi, x, w, options, &global_options); int i =0; for (i =0; i< n ; i++) { printf("x[%i]=%f\t",i,x[i]); printf("w[%i]=F[%i]=%f\n",i,i,w[i]); } deleteSolverOptions(options); free(options); free(problem); free(x); free(w); return info; }
int globalFrictionContact_test_function(FILE * f, SolverOptions * options) { int k, info = -1 ; GlobalFrictionContactProblem* problem = (GlobalFrictionContactProblem *)malloc(sizeof(GlobalFrictionContactProblem)); info = globalFrictionContact_newFromFile(problem, f); globalFrictionContact_display(problem); FILE * foutput = fopen("checkinput.dat", "w"); info = globalFrictionContact_printInFile(problem, foutput); NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default int NC = problem->numberOfContacts; int dim = problem->dimension; int n = problem->M->size1; double *reaction = (double*)malloc(dim * NC * sizeof(double)); double *velocity = (double*)malloc(dim * NC * sizeof(double)); double *globalvelocity = (double*)malloc(n * sizeof(double)); for (k = 0 ; k < dim * NC; k++) { velocity[k] = 0.0; reaction[k] = 0.0; } for (k = 0 ; k < n; k++) { globalvelocity[k] = 0.0; } if (dim == 2) { info = 1; } else if (dim == 3) { info = globalFrictionContact3D_driver(problem, reaction , velocity, globalvelocity, options, &global_options); } printf("\n"); for (k = 0 ; k < dim * NC; k++) { printf("Velocity[%i] = %12.8e \t \t Reaction[%i] = %12.8e\n", k, velocity[k], k , reaction[k]); } for (k = 0 ; k < n; k++) { printf("GlocalVelocity[%i] = %12.8e\n", k, globalvelocity[k]); } printf("\n"); if (!info) { printf("test succeeded\n"); } else { printf("test unsuccessful\n"); } free(reaction); free(velocity); free(globalvelocity); fclose(foutput); freeGlobalFrictionContactProblem(problem); return info; }
int lcp_test_function_SBM(FILE * f, int solverId) { int i, info = 0 ; LinearComplementarityProblem* problem = (LinearComplementarityProblem *)malloc(sizeof(LinearComplementarityProblem)); info = linearComplementarity_newFromFile(problem, f); FILE * foutput = fopen("./lcp_mmc.verif", "w"); info = linearComplementarity_printInFile(problem, foutput); NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; SolverOptions * options = (SolverOptions *)malloc(sizeof(SolverOptions)); info = linearComplementarity_setDefaultSolverOptions(problem, options, SICONOS_LCP_NSGS_SBM); set_SolverOptions(options->internalSolvers, solverId); #ifdef HAVE_GAMS_C_API if (solverId == SICONOS_LCP_GAMS) { // no testing for now deleteSolverOptions(options); free(options); freeLinearComplementarityProblem(problem); fclose(foutput); return 0; /* SN_GAMSparams* GP = (SN_GAMSparams*)options->internalSolvers->solverParameters; assert(GP); GP->model_dir = GAMS_MODELS_SOURCE_DIR;*/ } #endif double * z = (double *)calloc(problem->size, sizeof(double)); double * w = (double *)calloc(problem->size, sizeof(double)); info = linearComplementarity_driver(problem, z , w, options, &global_options); for (i = 0 ; i < problem->size ; i++) { printf("z[%i] = %12.8e\t,w[%i] = %12.8e\n", i, z[i], i, w[i]); } if (!info) { printf("test succeeded err=%e \n", options->dparam[1]); } else { printf("test unsuccessful err =%e \n", options->dparam[1]); } free(z); free(w); // info = linearComplementarity_deleteDefaultSolverOptions(&options,solvername); deleteSolverOptions(options); free(options); freeLinearComplementarityProblem(problem); fclose(foutput); return info; }
int lcp_test_function(FILE * f, int solverId, char* filename) { int i, info = 0 ; LinearComplementarityProblem* problem = (LinearComplementarityProblem *)malloc(sizeof(LinearComplementarityProblem)); info = linearComplementarity_newFromFile(problem, f); FILE * foutput = fopen("./lcp_mmc.verif", "w"); info = linearComplementarity_printInFile(problem, foutput); fclose(foutput); NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; SolverOptions options; set_SolverOptions(&options, solverId); #ifdef HAVE_GAMS_C_API if (solverId == SICONOS_LCP_GAMS) { SN_GAMSparams* GP = (SN_GAMSparams*)options.solverParameters; assert(GP); GP->model_dir = GAMS_MODELS_SOURCE_DIR; assert(filename); GP->filename = filename; } #endif double * z = (double *)calloc(problem->size, sizeof(double)); double * w = (double *)calloc(problem->size, sizeof(double)); info = linearComplementarity_driver(problem, z , w, &options, &global_options); for (i = 0 ; i < problem->size ; i++) { printf("z[%i] = %12.8e\t,w[%i] = %12.8e\n", i, z[i], i, w[i]); } if (!info) { printf("test succeeded err = %e \n", options.dparam[1]); } else { printf("test unsuccessful err =%e \n", options.dparam[1]); } free(z); free(w); deleteSolverOptions(&options); if (solverId == SICONOS_LCP_GAMS) { free(options.solverParameters); options.solverParameters = NULL; } freeLinearComplementarityProblem(problem); printf("End of test.\n"); return info; }
int main(void) { char filename[51] = "./data/LMGC_GlobalFrictionContactProblem00046.hdf5"; printf("Test on %s\n", filename); SolverOptions * options = (SolverOptions *)malloc(sizeof(SolverOptions)); gfc3d_setDefaultSolverOptions(options, SICONOS_GLOBAL_FRICTION_3D_NSN_AC); int k, info = -1 ; GlobalFrictionContactProblem* problem = globalFrictionContact_fclib_read(filename); globalFrictionContact_display(problem); FILE * foutput = fopen("checkinput.dat", "w"); info = globalFrictionContact_printInFile(problem, foutput); NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default int NC = problem->numberOfContacts; int dim = problem->dimension; int n = problem->M->size1; double *reaction = (double*)calloc(dim * NC, sizeof(double)); double *velocity = (double*)calloc(dim * NC, sizeof(double)); double *globalvelocity = (double*)calloc(n, sizeof(double)); if (dim == 2) { info = 1; } else if (dim == 3) { info = gfc3d_driver(problem, reaction , velocity, globalvelocity, options, &global_options); } printf("\n"); for (k = 0 ; k < dim * NC; k++) { printf("Velocity[%i] = %12.8e \t \t Reaction[%i] = %12.8e\n", k, velocity[k], k , reaction[k]); } for (k = 0 ; k < n; k++) { printf("GlocalVelocity[%i] = %12.8e\n", k, globalvelocity[k]); } printf("\n"); if (!info) { printf("test succeeded\n"); } else { printf("test unsuccessful\n"); } free(reaction); free(velocity); free(globalvelocity); fclose(foutput); freeGlobalFrictionContactProblem(problem); deleteSolverOptions(options); free(options); printf("End of test on %s\n", filename); return info; }
int frictionContact_test_function(FILE * f, SolverOptions * options) { int k, info = -1 ; FrictionContactProblem* problem = (FrictionContactProblem *)malloc(sizeof(FrictionContactProblem)); info = frictionContact_newFromFile(problem, f); FILE * foutput = fopen("checkinput.dat", "w"); info = frictionContact_printInFile(problem, foutput); NumericsOptions global_options; setDefaultNumericsOptions(&global_options); global_options.verboseMode = 1; // turn verbose mode to off by default int NC = problem->numberOfContacts; int dim = problem->dimension; //int dim = problem->numberOfContacts; double *reaction = (double*)calloc(dim * NC, sizeof(double)); double *velocity = (double*)calloc(dim * NC, sizeof(double)); if (dim == 2) { info = frictionContact2D_driver(problem, reaction , velocity, options, &global_options); } else if (dim == 3) { info = frictionContact3D_driver(problem, reaction , velocity, options, &global_options); } else { info = 1; } printf("\n"); int print_size =10; if (dim * NC >= print_size) { printf("First values (%i)\n", print_size); for (k = 0 ; k < print_size; k++) { printf("Velocity[%i] = %12.8e \t \t Reaction[%i] = %12.8e\n", k, velocity[k], k , reaction[k]); } printf(" ..... \n"); } else { for (k = 0 ; k < dim * NC; k++) { printf("Velocity[%i] = %12.8e \t \t Reaction[%i] = %12.8e\n", k, velocity[k], k , reaction[k]); } printf("\n"); } /* for (k = 0 ; k < dim * NC; k++) */ /* { */ /* printf("Velocity[%i] = %12.8e \t \t Reaction[%i] = %12.8e\n", k, velocity[k], k , reaction[k]); */ /* } */ /* printf("\n"); */ if (!info) { printf("test successful, residual = %g\n", options->dparam[1]); } else { printf("test unsuccessful, residual = %g\n", options->dparam[1]); } free(reaction); free(velocity); freeFrictionContactProblem(problem); fclose(foutput); return info; }