double pde_integral_term_evaluate(const pde_integral_term *term, const grid_node *node, Vector *U){ unsigned int lt; double z; grid_node *unode; const grid *grid ; double x ; int xt; int yt; double result ; /* evaluate integral term for i */ REQUIRE("term_not_null", term != NULL); REQUIRE("node_not_null", node != NULL); REQUIRE("grid_is_set", term->source_grid != NULL); grid = term->source_grid; x = node->value[X_DIM]; xt = node->tick[X_DIM]; yt = node->tick[Y_DIM]; result = 0.0; if(x == 0.0){ grid_loose_item(grid,xt,yt,&unode); result = term->lambda * V_GetCmp(U, unode->order); grid_node_destroy(&unode); } else if(x == 1.0){ grid_loose_item(grid,xt,yt,&unode); result = term->lambda * exp(0.5 * pow(term->alpha,2) + term->m) * V_GetCmp(U, unode->order); grid_node_destroy(&unode); } else{ for(lt = grid_iterator_first(grid,X_DIM); lt <= grid_iterator_last(grid,X_DIM); lt++){ z = grid->min_value[X_DIM] + ((double)lt) * grid->delta[X_DIM]; grid_loose_item(grid,lt,yt,&unode); result += term->lambda * func_beta2(term, lt) * func_integral(term,x,z) * V_GetCmp(U, unode->order); grid_node_destroy(&unode); } } return result; }
void showVector( Vector *v ) { int i; printf( "Vector: %s\n", V_GetName( v ) ); for ( i = 0; i < V_GetDim( v ); i++ ) printf( "%.3lf ", V_GetCmp( v, i+1 ) ); printf( "\n" ); } /* showVector */
int pde_problem_plot_solution(const pde_problem *problem){ /* plot to stdout, suitable to feed gnuplot */ char filename[MAX_FILENAME]; FILE *F; problem_solver *solver; grid *grid; grid_node *node; REQUIRE("problem_not_null", problem != NULL); solver = problem->solver; grid = problem->discretization_grid; sprintf(filename,"%s_%d.dat",problem->plotfile,solver->step); F = fopen(filename,"w+"); for(grid_plain_start(problem->discretization_grid, X_DIM); !grid_plain_after(problem->discretization_grid, X_DIM); grid_plain_forth(problem->discretization_grid, X_DIM)){ for(grid_plain_start(problem->discretization_grid, Y_DIM); !grid_plain_after(problem->discretization_grid, Y_DIM); grid_plain_forth(problem->discretization_grid, Y_DIM)){ grid_plain_item(grid,&node); if(grid_node_is_boundary(node)){ fprintf(F,"%.4f %.4f %.4f\n", node->value[X_DIM], node->value[Y_DIM], boundary_description_evaluate(problem->boundary, grid, node)); } else{ fprintf(F,"%.4f %.4f %.4f\n", node->value[X_DIM], node->value[Y_DIM], V_GetCmp(&solver->uc,node->order)); } grid_node_destroy(&node); } fprintf(F,"\n"); } fclose(F); return OK; }
void Solver::ProccessStart(void) { #include "perem.cpp" #include "viraj.cpp" #ifdef __TASK1__ QMatrix A; Vector B, D; Q_Constr(&A, (char*)"A", 3 * total, False, Rowws, Normal, True); V_Constr(&B, (char*)"B", 3 * total, Normal, True); V_Constr(&D, (char*)"D", 3 * total, Normal, True); SetRTCAccuracy(1e-8); #endif #ifdef __TASK2__ double *A = new double [3 * 9 * total * 3]; int sizeA = 0; double *B = new double [3 * total]; double *D = new double [3 * total]; #endif #ifdef __TASK1__ mm = 1; #endif #ifdef __TASK2__ mm = 0; #endif for(int i = 0; i < total; i++) { #ifdef __TASK1__ V_SetCmp(&D, 3 * i + mm, G[i]); V_SetCmp(&D, 3 * i + 1 + mm, V1[i]); V_SetCmp(&D, 3 * i + 2 + mm, V2[i]); #endif #ifdef __TASK2__ D[3 * i + mm] = G[i]; D[3 * i + 1 + mm] = V1[i]; D[3 * i + 2 + mm] = V2[i]; #endif } for (nn = 1; nn <= N;nn++) { tt = nn * tau; #include "mum.cpp" //#ifdef __TASK1__ mm = 1; //#endif #ifdef __TASK2__ // mm = 0; sizeA = 0; #endif for (m = 0; m < Dim; m++) { int n_, m_; int i00, i0m1, i0p1, i0pp1, i0mm1; i00 = m; Getmn(i00, &m_, &n_); GetN(&i0m1, m_, n_ - 1); GetN(&i0p1, m_, n_ + 1); GetN(&i0pp1, m_,n_ + 2); GetN(&i0mm1, m_,n_ - 2); M0L[m] = i0m1; M0R[m] = i0p1; xx = m_ * h1; yy = n_ * h2; switch (st[m]){ #include "case0.cpp" #include "case1.cpp" #include "case2.cpp" #include "case3.cpp" #include "case4.cpp" #include "case5.cpp" #include "case6.cpp" #include "case7.cpp" #include "case8.cpp" #include "case9.cpp" } } //CGSIter(&A, &D, &B, 2000, NULL, 1.2); #ifdef __TASK1__ SetRTCAccuracy(1e-8); BiCGSTABIter(&A, &D, &B, 2000, NULL, 1.2); #endif #ifdef __TASK2__ t2Solve(A, D, B, 3 * total, 2000); #endif #ifdef __TASK1__ mm = 1; #endif #ifdef __TASK2__ mm = 0; #endif for (m = 0; m < Dim; m++) { #ifdef __TASK1__ G[m] = V_GetCmp(&D, 3 * m + mm); V1[m] = V_GetCmp(&D, 3 * m + 1 + mm); V2[m] = V_GetCmp(&D, 3 * m + 2 + mm); #endif #ifdef __TASK2__ G[m] = D[3 * m + mm]; V1[m] = D[3 * m + 1 + mm]; V2[m] = D[3 * m + 2 + mm]; #endif } #ifdef __TASK3__ std::stringstream str; str << "_plot" << nn; FILE *f = fopen(str.str().c_str(), "w"); for (m = 0; m < Dim; m++) { int n_, m_; Getmn(m, &m_, &n_); fprintf(f, "%lf %lf %lf %lf\n", m_ * h1, - n_ * h2, V1[m] / 10, - V2[m]); } fclose(f); str.str(""); str << "_dense" << nn; FILE *fd = fopen(str.str().c_str(), "w"); for (m = 0; m < Dim; m++) { int n_, m_; Getmn(m, &m_, &n_); fprintf(fd, "%lf %lf %d\n", m_ * h1, - n_ * h2, exp(G[m]) > 1); } fclose(fd); #endif } #ifdef __TASK1__ Q_Destr(&A); V_Destr(&B); V_Destr(&D); #endif #ifdef __TASK2__ delete [] A; delete [] B; delete [] D; #endif }