int main() { double ufield; double efield; double rhofield; double exact_u; double exact_p; double exact_rho; //problem size double lx; double dx; int nx; // initialize nx = 10; // number of points lx=1; // length // error handling int err=0; int i; double tempx; dx=(double)lx/(double)nx; // init err += masa_init("nick","euler_1d"); //check all initialized properly err += masa_sanity_check(); for(i=0;i<nx;i++) { tempx=i*dx; ufield = masa_eval_1d_source_rho_u(tempx); efield = masa_eval_1d_source_rho_e(tempx); rhofield = masa_eval_1d_source_rho(tempx); //evaluate analytical terms exact_u = masa_eval_1d_exact_u (tempx); exact_p = masa_eval_1d_exact_p (tempx); exact_rho = masa_eval_1d_exact_rho (tempx); masa_test_default(ufield); masa_test_default(efield); masa_test_default(rhofield); masa_test_default(exact_u); masa_test_default(exact_p); masa_test_default(exact_rho); } return err; // done }
int main() { int err = 0 ; // reroute stdout for regressions: TODO remove when logger mechanism // is used inside masa; these tests currently just verify functions // run successfully. freopen("/dev/null","w",stdout); // list all currently initialized mms masa_list_mms(); // initalize two different functions masa_init("euler-test","euler_1d"); masa_init_param(); masa_init("euler-test2","euler_2d"); masa_init_param(); masa_list_mms(); // display parameters @ default values err = masa_display_param(); if(err != 0) { return 1; } //change parameter masa_set_param("u_0",2.3); // display again masa_display_param(); //switch to original function masa_select_mms("euler-test"); masa_display_param(); //tests passed return 0; }
int main() { double sol=0; double q=0; double x = 1.2; double x2 = 2.2; char* a= "A_x"; sol = 0; // init masa_init("nick","heateq_1d_steady_const"); masa_init("bob","heateq_1d_steady_const"); // reroute stdout: comment to display to screen freopen("/dev/null","w",stdout); // we can list initialized mms with masa_list_mms(); // switch masa_select_mms("nick"); // we can display the parameter list with masa_display_param(); // lets examine a particular parameter q=masa_get_param(a); // now lets change that parameters value to something else. masa_set_param(a,1.984); q=masa_get_param(a); //check all initialized properly masa_sanity_check(); sol = masa_eval_1d_source_t(x); masa_select_mms("bob"); sol = masa_eval_1d_source_t(x2); return 0; // done }
int main() { double u_0; double thresh = 5e-15; // start problem masa_init("euler-test","euler_1d"); u_0 = masa_get_param("u_0"); if((fabs(u_0 - MASA_DEFAULT) < thresh)) { printf("\nMASA ERROR:: Variables not being auto initalized!\n"); return 1; } // now purge default values masa_purge_default_param(); // values should be set to default: checking u_0 = masa_get_param("u_0"); test_default(u_0); // steady as she goes return 0; }
int main() { int i; double tfield,tfield2,tfield3; double exact_t,exact_t2,exact_t3; double x; double A_x; double k_0; //problem size int nx = 200; // number of points int lx=10; // length double dx = (double)lx/(double)nx; // initalize everyone masa_init("temp-test-1d","heateq_1d_steady_const"); masa_init_param(); masa_sanity_check(); A_x = masa_get_param("A_x"); k_0 = masa_get_param("k_0"); // evaluate source terms (1D) for(i=0;i<nx;i++) { x=i*dx; //evalulate source terms tfield = masa_eval_1d_source_t(x); //evaluate analytical terms exact_t = masa_eval_1d_exact_t(x); // get fundamental source term solution tfield2 = SourceQ_t_1d (x,A_x,k_0); exact_t2 = Source_t_1d_exact(x,A_x); // test the result is roughly zero // choose between abs and rel error #ifdef MASA_STRICT_REGRESSION tfield3 = fabs(tfield-tfield2); exact_t3 = fabs(exact_t-exact_t2); #else tfield3 = fabs(tfield-tfield2)/fabs(tfield2); exact_t3 = fabs(exact_t-exact_t2)/fabs(tfield2); #endif if(tfield3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Heat Equation Steady-2d\n"); printf("U Field Source Term\n"); printf("Threshold Exceeded: %g\n",tfield3); printf("MASA: %5.16f\n",tfield); printf("Maple: %5.16f\n",tfield2); exit(1); } if(exact_t3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Heat Equation Steady-2d\n"); printf("U Field Analytical Term\n"); printf("Threshold Exceeded: %g\n",exact_t3); printf("MASA: %5.16f\n",exact_t); printf("Maple: %5.16f\n",exact_t2); exit(1); } } // done iterating masa_init("temp-test-2d","heateq_2d_steady_const"); masa_init_param(); masa_sanity_check(); masa_init("temp-test-3d","heateq_3d_steady_const"); masa_init_param(); masa_sanity_check(); return 0; // steady as she goes }
int main() { //variables double u_0; double u_x; double rho_0; double rho_x; double p_0; double p_x; double a_px; double a_rhox; double a_ux; double Gamma; double mu; double L; // parameters double x; int i; //problem size int nx = 200; // number of points int lx = 10; // length double dx = (double)(lx)/(double)(nx); // solutions double ufield,ufield2,ufield3; double efield,efield2,efield3; double rho,rho2,rho3; double exact_u,exact_u2,exact_u3; double exact_p,exact_p2,exact_p3; double exact_rho,exact_rho2,exact_rho3; // initalize masa_init("euler-test","euler_1d"); // initialize the default parameters masa_init_param(); // get defaults for comparison to source terms // get vars u_0 = masa_get_param("u_0"); u_x = masa_get_param("u_x"); rho_0 = masa_get_param("rho_0"); rho_x = masa_get_param("rho_x"); p_0 = masa_get_param("p_0"); p_x = masa_get_param("p_x"); a_px = masa_get_param("a_px"); a_rhox = masa_get_param("a_rhox"); a_ux = masa_get_param("a_ux"); Gamma = masa_get_param("Gamma"); mu = masa_get_param("mu"); L = masa_get_param("L"); // check that all terms have been initialized masa_sanity_check(); // evaluate source terms (1D) for(i=0;i<nx;i++) { x=i*dx; //evalulate source terms ufield = masa_eval_1d_source_rho_u(x); efield = masa_eval_1d_source_rho_e (x); rho = masa_eval_1d_source_rho (x); //evaluate analytical terms exact_u = masa_eval_1d_exact_u (x); exact_p = masa_eval_1d_exact_p (x); exact_rho = masa_eval_1d_exact_rho (x); // get fundamental source term solution ufield2 = SourceQ_u (x,u_0,u_x,rho_0,rho_x,p_0,p_x,a_px,a_rhox,a_ux,L); rho2 = SourceQ_rho(x,u_0,u_x,rho_0,rho_x,p_0,p_x,a_px,a_rhox,a_ux,L); efield2 = SourceQ_e (x,u_0,u_x,rho_0,rho_x,p_0,p_x,a_px,a_rhox,a_ux,Gamma,mu,L); exact_u2 = anQ_u (x,u_0,u_x,a_ux,L); exact_rho2 = anQ_rho (x,rho_0,rho_x,a_rhox,L); exact_p2 = anQ_p (x,p_0,p_x,a_px,L); // test the result is roughly zero // choose between abs and rel error #ifdef MASA_STRICT_REGRESSION ufield3 = fabs(ufield-ufield2); efield3 = fabs(efield-efield2); rho3 = fabs(rho-rho2); exact_u3 = fabs(exact_u-exact_u2); exact_rho3 = fabs(exact_rho-exact_rho2); exact_p3 = fabs(exact_p-exact_p2); #else ufield3 = fabs(ufield-ufield2)/fabs(ufield2); efield3 = fabs(efield-efield2)/fabs(efield2); rho3 = fabs(rho-rho2)/fabs(rho2); exact_u3 = fabs(exact_u-exact_u2)/fabs(exact_u2); exact_rho3 = fabs(exact_rho-exact_rho2)/fabs(exact_rho2); exact_p3 = fabs(exact_p-exact_p2)/fabs(exact_p2); #endif if(ufield3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("U Field Source Term\n"); printf("Threshold Exceeded: %g\n",ufield3); printf("MASA: %5.16f\n",ufield); printf("Maple: %5.16f\n",ufield2); exit(1); } if(exact_u3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("U Field Analytical Term\n"); printf("Threshold Exceeded: %g\n",exact_u3); printf("MASA: %5.16f\n",exact_u); printf("Maple: %5.16f\n",exact_u2); exit(1); } if(efield3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("Energy Source Term\n"); printf("Threshold Exceeded: %g\n",efield3); printf("MASA: %5.16f\n",efield); printf("Maple: %5.16f\n",efield2); exit(1); } if(exact_p3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("P Field Analytical Term\n"); exit(1); } if(rho3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("RHO Source Term\n"); exit(1); } if(exact_rho3 > threshold) { printf("\nMASA REGRESSION TEST FAILED: C-binding Euler-1d\n"); printf("RHO Analytical Term\n"); exit(1); } } // done interating // tests passed return 0; }
int main() { double out; double x = 0; int i = 1; // reroute stdout for regressions: TODO remove when logger mechanism // is used inside masa; these tests currently just verify functions // run successfully. freopen("/dev/null","w",stdout); masa_init("source term","euler_2d"); // 1D out = masa_eval_1d_source_u(x); nancheck(out); out = masa_eval_1d_source_e(x); nancheck(out); out = masa_eval_1d_grad_u(x); nancheck(out); out = masa_eval_1d_grad_p(x); nancheck(out); out = masa_eval_1d_grad_rho(x); nancheck(out); // 2D out = masa_eval_2d_source_u(x,x); nancheck(out); out = masa_eval_2d_source_v(x,x); nancheck(out); out = masa_eval_2d_source_e(x,x); nancheck(out); out = masa_eval_2d_source_rho_w(x,x); nancheck(out); out = masa_eval_2d_grad_u(x,x,i); nancheck(out); out = masa_eval_2d_grad_v(x,x,i); nancheck(out); out = masa_eval_2d_grad_w(x,x,i); nancheck(out); out = masa_eval_2d_grad_p(x,x,i); nancheck(out); out = masa_eval_2d_grad_rho(x,x,i); nancheck(out); // 3D out = masa_eval_3d_source_u(x,x,x); nancheck(out); out = masa_eval_3d_source_v(x,x,x); nancheck(out); out = masa_eval_3d_source_w(x,x,x); nancheck(out); out = masa_eval_3d_source_e(x,x,x); nancheck(out); //tests passed return 0; }