User:Karthik0112358/massmatrix
Jump to navigation
Jump to search
//Include necessary headers. int massmatrix(slv_system_t sys, struct massmatrixStruct *mass, const rel_filter_t *rfilter, const var_filter_t *vfilter){ // here there might be some more parameters to accept. I haven't figured it out yet. Although I think some filter parameters need to be shaken up a little. struct var_variable **svars; struct rel_relation **srels; mtx_coord_t coord; //the above declarations are self explanatory. int i,j,n,nsr,nsv,nr,nv; //first count the rels nsr = slv_get_num_solvers_rels(sys); nr = slv_count_solvers_rels(sys,rfilter); srels = slv_get_solvers_rel_list(sys); //and vars nsv = slv_get_num_solvers_vars(sys); nv = slv_count_solvers_vars(sys,vfilter); svars = slv_get_solvers_var_list(sys); //allocate space for lists mass->vars = ASC_NEW_ARRAY(struct var_variable*, nv); mass->rels = ASC_NEW_ARRAY(struct rel_relation*, nr); vartocol = ASC_NEW_ARRAY(int,nsv); //So till here code looks neat. Gets slightly messy from now on. //now create a the lists of vars and rels, and temp mapping array n = 0; for(i=0;i<nsr;++i){ if(rel_apply_filter(srels[i],rfilter)){ mass->rels[n++] = srels[i]; } } asc_assert(n==nr); n = 0; for(i=0;i<nsv;++i){ if(var_apply_filter(svars[i],vfilter)){ vartocol[i]=n; mass->vars[n++] = svars[i]; }else{ vartocol[i]=-1; } } asc_assert(n==nv); //now create a matrix mass->M = mtx_create(); mtx_set_order(mass->M, MAX(nv,nr)); for(i=0;i<nr;++i){ //Need to write a function, so that I can call it here which basically takes the relation and finds the coefficients of all first order derivatives. for(j=0;j<n;++j){ mtx_set_value(mass->M,mtx_coord(&coord,i,vartocol[/* need to figure equivalent here*/]),/*put the equivalent figured here too*/); } //Check for errors in doing above 2 operations via function call } mass->n_rels = nr; mass->n_vars = nv; } /* I would define the structure massmatrix in the header as: struct massmatrixStruct{ mtx_matrix_t M; struct rel_relation **rels; struct var_variable **vars; int n_rels, n_vars; }; */