void SMatrix::print() { int ind0, ind1; for(int pol=0; pol<=1; ++pol) { std::cout << "-------" << std::endl; if(pol==TE) std::cout << "pol: " << "TE" << std::endl; else std::cout << "pol: " << "TM" << std::endl; std::cout << "-------" << std::endl; for(int ind=0; ind<=1; ++ind) { for(int i=0; i<=N; ++i) { ind0 = (ind==0) ? 0 : i; ind1 = (ind==0) ? i : N; std::cout << "layer: " << i << std::endl; std::cout << " s11(" << ind0 << "," << ind1 << "): " << S11(ind0,ind1,pol) << std::endl; std::cout << " s12(" << ind0 << "," << ind1 << "): " << S12(ind0,ind1,pol) << std::endl; std::cout << " s21(" << ind0 << "," << ind1 << "): " << S21(ind0,ind1,pol) << std::endl; std::cout << " s22(" << ind0 << "," << ind1 << "): " << S22(ind0,ind1,pol) << std::endl; } } } }
void test(int M, int N, int O, int P, int Q, int R) { /* Scattering iterators. */ int p1, p3, p5; /* Original iterators. */ int i, j, k; if (M == 1) { S1() ; S2() ; S3() ; S4() ; S5() ; S6() ; S7() ; S8() ; S9() ; S10() ; S11() ; S12() ; S13() ; S14() ; S15() ; S16() ; S17() ; S18() ; S19() ; S20() ; S21() ; S22() ; S23() ; S24() ; S25() ; S26() ; S27() ; } if (M == 1) { for (p1=1;p1<=N;p1++) { for (p3=1;p3<=N;p3++) { S28(p1,p3) ; S29(p1,p3) ; S30(p1,p3) ; } S31(p1) ; } } if (M == 1) { S32() ; S33() ; S34() ; } if ((M == 1) && (O <= 1)) { S35() ; } if (M == 1) { S36() ; S37() ; } if ((M == 1) && (N >= 1) && (Q >= 1) && (R >= 1)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S40(p1,p3,p5) ; S41(p1,p3,p5) ; S42(p1,p3,p5) ; S43(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S44(p1,p3) ; S45(p1,p3) ; S46(p1,p3) ; S47(p1,p3) ; } for (p3=1;p3<=R;p3++) { S48(p1,p3) ; S49(p1,p3) ; S50(p1,p3) ; S51(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S59(p1,p3,p5) ; S60(p1,p3,p5) ; S61(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S62(p1,p3) ; S63(p1,p3) ; S64(p1,p3) ; } for (p3=1;p3<=R;p3++) { S65(p1,p3) ; S66(p1,p3) ; S67(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; for (p3=1;p3<=N;p3++) { for (p5=1;p5<=N;p5++) { S95(p1,p3,p5) ; S96(p1,p3,p5) ; S97(p1,p3,p5) ; } S98(p1,p3) ; } S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S102(p1,p3,p5) ; S103(p1,p3,p5) ; S104(p1,p3,p5) ; S105(p1,p3,p5) ; S106(p1,p3,p5) ; S107(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S108(p1,p3) ; S109(p1,p3) ; S110(p1,p3) ; S111(p1,p3) ; S112(p1,p3) ; S113(p1,p3) ; } for (p3=1;p3<=R;p3++) { S114(p1,p3) ; S115(p1,p3) ; S116(p1,p3) ; S117(p1,p3) ; S118(p1,p3) ; S119(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N <= 0) && (Q >= 1) && (R >= 1)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S40(p1,p3,p5) ; S41(p1,p3,p5) ; S42(p1,p3,p5) ; S43(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S44(p1,p3) ; S45(p1,p3) ; S46(p1,p3) ; S47(p1,p3) ; } for (p3=1;p3<=R;p3++) { S48(p1,p3) ; S49(p1,p3) ; S50(p1,p3) ; S51(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S59(p1,p3,p5) ; S60(p1,p3,p5) ; S61(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S62(p1,p3) ; S63(p1,p3) ; S64(p1,p3) ; } for (p3=1;p3<=R;p3++) { S65(p1,p3) ; S66(p1,p3) ; S67(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=Q;p3++) { for (p5=1;p5<=R;p5++) { S102(p1,p3,p5) ; S103(p1,p3,p5) ; S104(p1,p3,p5) ; S105(p1,p3,p5) ; S106(p1,p3,p5) ; S107(p1,p3,p5) ; } } for (p3=1;p3<=Q;p3++) { S108(p1,p3) ; S109(p1,p3) ; S110(p1,p3) ; S111(p1,p3) ; S112(p1,p3) ; S113(p1,p3) ; } for (p3=1;p3<=R;p3++) { S114(p1,p3) ; S115(p1,p3) ; S116(p1,p3) ; S117(p1,p3) ; S118(p1,p3) ; S119(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N >= 1) && (Q <= 0) && (R >= 1)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=R;p3++) { S48(p1,p3) ; S49(p1,p3) ; S50(p1,p3) ; S51(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=R;p3++) { S65(p1,p3) ; S66(p1,p3) ; S67(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; for (p3=1;p3<=N;p3++) { for (p5=1;p5<=N;p5++) { S95(p1,p3,p5) ; S96(p1,p3,p5) ; S97(p1,p3,p5) ; } S98(p1,p3) ; } S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=R;p3++) { S114(p1,p3) ; S115(p1,p3) ; S116(p1,p3) ; S117(p1,p3) ; S118(p1,p3) ; S119(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N <= 0) && (Q <= 0) && (R >= 1)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=R;p3++) { S48(p1,p3) ; S49(p1,p3) ; S50(p1,p3) ; S51(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=R;p3++) { S65(p1,p3) ; S66(p1,p3) ; S67(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=R;p3++) { S114(p1,p3) ; S115(p1,p3) ; S116(p1,p3) ; S117(p1,p3) ; S118(p1,p3) ; S119(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N >= 1) && (Q <= 0) && (R <= 0)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; for (p3=1;p3<=N;p3++) { for (p5=1;p5<=N;p5++) { S95(p1,p3,p5) ; S96(p1,p3,p5) ; S97(p1,p3,p5) ; } S98(p1,p3) ; } S99(p1) ; S100(p1) ; S101(p1) ; S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N <= 0) && (Q <= 0) && (R <= 0)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; S99(p1) ; S100(p1) ; S101(p1) ; S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N >= 1) && (Q >= 1) && (R <= 0)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=Q;p3++) { S44(p1,p3) ; S45(p1,p3) ; S46(p1,p3) ; S47(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=Q;p3++) { S62(p1,p3) ; S63(p1,p3) ; S64(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; for (p3=1;p3<=N;p3++) { for (p5=1;p5<=N;p5++) { S95(p1,p3,p5) ; S96(p1,p3,p5) ; S97(p1,p3,p5) ; } S98(p1,p3) ; } S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=Q;p3++) { S108(p1,p3) ; S109(p1,p3) ; S110(p1,p3) ; S111(p1,p3) ; S112(p1,p3) ; S113(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } if ((M == 1) && (N <= 0) && (Q >= 1) && (R <= 0)) { for (p1=2;p1<=P;p1++) { S38(p1) ; S39(p1) ; for (p3=1;p3<=Q;p3++) { S44(p1,p3) ; S45(p1,p3) ; S46(p1,p3) ; S47(p1,p3) ; } S52(p1) ; S53(p1) ; S54(p1) ; S55(p1) ; S56(p1) ; S57(p1) ; S58(p1) ; for (p3=1;p3<=Q;p3++) { S62(p1,p3) ; S63(p1,p3) ; S64(p1,p3) ; } S68(p1) ; S69(p1) ; S70(p1) ; S71(p1) ; S72(p1) ; S73(p1) ; S74(p1) ; S75(p1) ; S76(p1) ; S77(p1) ; S78(p1) ; S79(p1) ; S80(p1) ; S81(p1) ; S82(p1) ; S83(p1) ; S84(p1) ; S85(p1) ; S86(p1) ; S87(p1) ; S88(p1) ; S89(p1) ; S90(p1) ; S91(p1) ; S92(p1) ; S93(p1) ; S94(p1) ; S99(p1) ; S100(p1) ; S101(p1) ; for (p3=1;p3<=Q;p3++) { S108(p1,p3) ; S109(p1,p3) ; S110(p1,p3) ; S111(p1,p3) ; S112(p1,p3) ; S113(p1,p3) ; } S120(p1) ; S121(p1) ; S122(p1) ; S123(p1) ; S124(p1) ; S125(p1) ; } } }
int main(int argc, char* argv[]) { // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh1(new Mesh); if (USE_XML_FORMAT == true) { MeshReaderH2DXML mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); mloader.load("square.xml", mesh); } else { MeshReaderH2D mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); mloader.load("square.mesh", mesh); } // Perform uniform mesh refinement. int refinement_type = 0; for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(refinement_type); // Show mesh. MeshView mv("Mesh", new WinGeom(0, 0, 580, 400)); mv.show(mesh); // Exact lambda MeshFunctionSharedPtr<double> exact_lambda(new ExactSolutionLambda(mesh,E,nu)); ScalarView viewLam("lambda [Pa]", new WinGeom(0, 460, 530, 350)); viewLam.show_mesh(false); viewLam.show(exact_lambda); // Exact lambda MeshFunctionSharedPtr<double> exact_mu(new ExactSolutionMu(mesh,E,nu)); ScalarView viewMu("mu [Pa]", new WinGeom(550, 460, 530, 350)); viewMu.show_mesh(false); viewMu.show(exact_mu); // Initialize boundary conditions. DefaultEssentialBCConst<double> disp_bot_top_x(Hermes::vector<std::string>("Bottom","Top"), 0.0); DefaultEssentialBCConst<double> disp_bot_y("Bottom", 0.0); DefaultEssentialBCConst<double> disp_top_y("Top", 0.1); EssentialBCs<double> bcs_x(&disp_bot_top_x); EssentialBCs<double> bcs_y(Hermes::vector<EssentialBoundaryCondition<double> *>(&disp_bot_y, &disp_top_y)); // Create x- and y- displacement space using the default H1 shapeset. SpaceSharedPtr<double> u1_space(new H1Space<double>(mesh, &bcs_x, P_INIT)); SpaceSharedPtr<double> u2_space(new H1Space<double>(mesh, &bcs_y, P_INIT)); Hermes::vector<SpaceSharedPtr<double> > spaces(u1_space, u2_space); int ndof = Space<double>::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormLinearElasticity wf(E, nu, &lambdaFun, &muFun, rho*g1, "Top", f0, f1); // Initialize Newton solver. NewtonSolver<double> newton(&wf, spaces); newton.set_verbose_output(true); // Perform Newton's iteration. try { newton.solve(); } catch(std::exception& e) { std::cout << e.what(); Hermes::Mixins::Loggable::Static::info("Newton's iteration failed."); } // Translate the resulting coefficient vector into the Solution sln. MeshFunctionSharedPtr<double> u1_sln(new Solution<double>), u2_sln(new Solution<double>); Hermes::vector<MeshFunctionSharedPtr<double> > solutions(u1_sln, u2_sln); Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, solutions); // Visualize the solution. ScalarView view("Von Mises stress [Pa]", new WinGeom(590, 0, 700, 400)); // First Lame constant. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); // Second Lame constant. double mu = E / (2*(1 + nu)); MeshFunctionSharedPtr<double> stress(new VonMisesFilter(solutions, lambda, mu)); MeshFunctionSharedPtr<double> S11(new CustomFilterS11(solutions, &muFun, &lambdaFun)); MeshFunctionSharedPtr<double> S12(new CustomFilterS12(solutions, mu)); MeshFunctionSharedPtr<double> S22(new CustomFilterS22(solutions, mu, lambda)); view.show_mesh(false); view.show(stress, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS11("S11 [Pa]", new WinGeom(0, 260, 530, 350)); viewS11.show_mesh(false); viewS11.show(S11, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS12("S12 [Pa]", new WinGeom(540, 260, 530, 350)); viewS12.show_mesh(false); viewS12.show(S12, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); ScalarView viewS22("S22 [Pa]", new WinGeom(1080, 260, 530, 350)); viewS22.show_mesh(false); viewS22.show(S22, HERMES_EPS_HIGH, H2D_FN_VAL_0, u1_sln, u2_sln, 1.0); // Wait for the view to be closed. View::wait(); return 0; }