int main(void) { int res; printf("========= Starts SBM tests 4 for SBM ========= \n"); SparseBlockStructuredMatrix M; FILE *file = fopen("data/SBM2.dat", "r"); newFromFileSBM(&M, file); printSBM(&M); fclose(file); /*alloc enough memory */ CSparseMatrix sparseMat; res = SBMtoSparseInitMemory(&M, &sparseMat); if (res) { printf("========= Failed SBM tests 4 for SBM ========= \n"); return 1; } res = SBMtoSparse(&M, &sparseMat); if (res) { printf("========= Failed SBM tests 4 for SBM ========= \n"); return 1; } cs_print(&sparseMat, 1); cs_spfree_on_stack(&sparseMat); int n = M.blocksize0[M.blocknumber0 - 1]; int m = M.blocksize1[M.blocknumber1 - 1]; double * denseMat = (double *)malloc(n * m * sizeof(double)); SBMtoDense(&M, denseMat); if (res) { printf("========= Failed SBM tests 4 for SBM ========= \n"); return 1; } printf("["); for (int i = 0; i < n * m; i++) { printf("%lf ", denseMat[i]); if ((i + 1) % m == 0) printf("\n"); } printf("]"); printf("\n (warning: column-major) \n"); free(denseMat); printf("NUMERICS_SBM_FREE_BLOCK value %d", NUMERICS_SBM_FREE_BLOCK); SBMfree(&M, NUMERICS_SBM_FREE_BLOCK); printf("\n========= Succed SBM tests 4 for SBM ========= \n"); return 0; }
void display(const NumericsMatrix* const m) { if (! m) { fprintf(stderr, "Numerics, NumericsMatrix display failed, NULL input.\n"); exit(EXIT_FAILURE); } printf("\n ========== Numerics Matrix\n"); printf("\n ========== storageType = %i\n", m->storageType); switch (m->storageType) { case NM_DENSE: { displayMat(m->matrix0, m->size0, m->size1, m->size0); break; } case NM_SPARSE_BLOCK: { assert(m->matrix1); printSBM(m->matrix1); break; } case NM_SPARSE: { assert(m->matrix2); if (m->matrix2->triplet) { cs_print(m->matrix2->triplet, 0); } else if (m->matrix2->csc) { cs_print(m->matrix2->csc, 0); } else if (m->matrix2->trans_csc) { cs_print(m->matrix2->trans_csc, 0); } else { fprintf(stderr, "display for sparse matrix: no matrix found!\n"); } break; } default: { fprintf(stderr, "display for NumericsMatrix: matrix type %d not supported!\n", m->storageType); } } }
void displayRowbyRow(const NumericsMatrix* const m) { if (! m) { fprintf(stderr, "Numerics, NumericsMatrix display failed, NULL input.\n"); exit(EXIT_FAILURE); } int storageType = m->storageType; if (storageType == 0) { printf("\n ========== Numerics Matrix of dim %dX%d\n", m->size0, m->size1); for (int lin = 0; lin < m->size0; lin++) { for (int col = 0; col < m->size1; col++) printf("%lf ", m->matrix0[lin + col * m->size1]); printf("\n"); } } else if (storageType == 1) printSBM(m->matrix1); }
int main(void) { unsigned int Ai[nnz] = {2, 1, 0, 3, 4, 5, 6, 7, 9, 8}; unsigned int Aj[nnz] = {2, 1, 0, 3, 4, 5, 6, 7, 9, 8}; double Ax[nnz] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; SparseBlockCoordinateMatrix mc; unsigned int blocksize0[nnz] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; unsigned int blocksize1[nnz] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; double* block[nnz] = {&Ax[0], &Ax[1], &Ax[2], &Ax[3], &Ax[4], &Ax[5], &Ax[6], &Ax[7], &Ax[8], &Ax[9] }; mc.nbblocks = nnz; mc.blocknumber0 = 10; mc.blocknumber1 = 10; mc.blocksize0 = blocksize0; mc.blocksize1 = blocksize1; mc.row = Ai; mc.column = Aj; mc.block = block; SparseBlockStructuredMatrix* m = SBCMToSBM(&mc); printSBM(m); int info1 = getValueSBM(m, 0, 0) == 2.; int info2 = getValueSBM(m, 8, 8) == 9.; freeSBMFromSBCM(m); return 1-info1 + 1-info2; }
int main(int argc, char* argv[]) { // Problem Definition int info = -1; int NC = 2;//Number of contacts int Ndof = 12;//Number of DOF // Problem Definition double M11[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // Warning Fortran Storage double M22[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // Warning Fortran Storage double M33[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // Warning Fortran Storage double M44[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // Warning Fortran Storage /* double M[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}; */ double H00[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; double H20[9] = { -1, 0, 0, 0, -1, 0, 0, 0, -1}; double H11[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; double H31[9] = { -1, 0, 0, 0, -1, 0, 0, 0, -1}; /* double H[27] = {1, 0, 0, 0, 0, 0, -1, 0, 0, */ /* 0, 1, 0, 0, 0, 0, 0, -1, 0, */ /* 0, 0, 1, 0, 0, 0, 0, 0, -1}; */ double q[12] = { -3, -3, -3, -3, -3, -3, -1, 1, 3, -10, 1, 3}; double b[6] = {0, 0, 0, 0, 0, 0}; double mu[2] = {0.1, 0.1}; /* DSCAL(9,-1.0,q,1); */ /* int NC = 3;//Number of contacts */ /* int Ndof = 9;//Number of DOF */ /* double M[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}; */ /* double H[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}; */ /* double q[9] = {-1, 1, 3, -1, 1, 3, -1, 1, 3}; */ /* double b[9] = {0, 0, 0,0, 0, 0,0, 0, 0 }; */ /* double mu[3] = {0.1,0.1,0.1}; */ int i, j, k; int m = 3 * NC; int n = Ndof; GlobalFrictionContactProblem NumericsProblem; NumericsProblem.numberOfContacts = NC; NumericsProblem.dimension = 3; NumericsProblem.mu = mu; NumericsProblem.q = q; NumericsProblem.b = b; NumericsProblem.M = newNumericsMatrix(); NumericsMatrix *MM = NumericsProblem.M; MM->storageType = 1; MM->size0 = Ndof; MM->size1 = Ndof; MM->matrix1 = newSBM(); MM->matrix0 = NULL; SparseBlockStructuredMatrix *MBlockMatrix = MM->matrix1; MBlockMatrix->nbblocks = 4; double * block[4] = {M11, M22, M33, M44}; MBlockMatrix->block = block; MBlockMatrix->blocknumber0 = 4; MBlockMatrix->blocknumber1 = 4; int blocksize[4] = {3, 6, 9, 12} ; MBlockMatrix->blocksize0 = blocksize; MBlockMatrix->blocksize1 = blocksize; MBlockMatrix->filled1 = 5; MBlockMatrix->filled2 = 4; size_t index1_data[5] = {0, 1, 2, 3, 4} ; size_t index2_data[4] = {0, 1, 2, 3} ; MBlockMatrix->index1_data = index1_data; MBlockMatrix->index2_data = index2_data; NumericsProblem.H = newSBM(); NumericsMatrix *HH = NumericsProblem.H; HH->storageType = 1; HH->size0 = Ndof; HH->size1 = 3 * NC; HH->matrix1 = (SparseBlockStructuredMatrix*)malloc(sizeof(SparseBlockStructuredMatrix)); HH->matrix0 = NULL; SparseBlockStructuredMatrix *HBlockMatrix = HH->matrix1; HBlockMatrix->nbblocks = 4; double * hblock[4] = {H00, H11, H20, H31}; HBlockMatrix->block = hblock; HBlockMatrix->blocknumber0 = 4; HBlockMatrix->blocknumber1 = 2; int blocksize0[4] = {3, 6, 9, 12} ; int blocksize1[3] = {3, 6, 9} ; HBlockMatrix->blocksize0 = blocksize0; HBlockMatrix->blocksize1 = blocksize1; HBlockMatrix->filled1 = 5; HBlockMatrix->filled2 = 4; size_t hindex1_data[5] = {0, 1, 2, 3, 4} ; size_t hindex2_data[4] = {0, 1, 0, 1} ; HBlockMatrix->index1_data = hindex1_data; HBlockMatrix->index2_data = hindex2_data; printSBM(HBlockMatrix); // Unknown Declaration double *reaction = (double*)malloc(m * sizeof(double)); double *velocity = (double*)malloc(m * sizeof(double)); double *globalVelocity = (double*)malloc(n * sizeof(double)); for (k = 0 ; k < m; k++) { velocity[k] = 0.0; reaction[k] = 0.0; } for (k = 0 ; k < n; k++) globalVelocity[k] = 0.0; // Numerics and Solver Options SolverOzptions numerics_solver_options; numerics_solver_options.filterOn = 0; numerics_solver_options.isSet = 1; // strcpy(numerics_solver_optionslverName,"NSGS_WR"); // strcpy(numerics_solver_optionslverName,"NSGS"); // strcpy(numerics_solver_optionslverName,"NSGSV_WR"); numerics_solver_optionslverId = SICONOS_FRICTION_3D_NSGS; numerics_solver_options.iSize = 5; numerics_solver_options.iparam = (int*)malloc(numerics_solver_options.iSize * sizeof(int)); int ii ; for (ii = 0; ii < numerics_solver_options.iSize; ii++) numerics_solver_options.iparam[ii] = 0; numerics_solver_options.dSize = 5; numerics_solver_options.dparam = (double*)malloc(numerics_solver_options.dSize * sizeof(double)); for (ii = 0; ii < numerics_solver_options.dSize; ii++) numerics_solver_options.dparam[ii] = 0; int nmax = 100; // Max number of iteration int localsolver = 0; // 0: projection on Cone, 1: Newton/AlartCurnier, 2: projection on Cone with local iteration, 2: projection on Disk with diagonalization, double tolerance = 1e-10; double localtolerance = 1e-12; numerics_solver_options.iparam[0] = nmax ; numerics_solver_options.iparam[4] = localsolver ; numerics_solver_options.dparam[0] = tolerance ; numerics_solver_options.dparam[2] = localtolerance ; //Driver call info = primalFrictionContact3D_driver(&NumericsProblem, reaction , velocity, globalVelocity, &numerics_solver_options); // Solver output printf("\n"); for (k = 0 ; k < m; 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("globalVelocity[%i] = %12.8e \t \n ", k, globalVelocity[k]); printf("\n"); free(reaction); free(velocity); free(globalVelocity); // freeSBM(MM->matrix1); // freeSBM(HH->matrix1); free(MM->matrix1); free(HH->matrix1); free(MM); free(HH); free(numerics_solver_options.iparam); free(numerics_solver_options.dparam); /* while (1) sleep(60); */ return info; }