int main(int argc, char* argv[]) { // Load the mesh. Mesh mesh; H2DReader mloader; mloader.load("reactor.mesh", &mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Solution variables. Solution sln1, sln2, sln3, sln4; Solution iter1, iter2, iter3, iter4; Hermes::Tuple<Solution*> solutions(&sln1, &sln2, &sln3, &sln4); // Define initial conditions. info("Setting initial conditions."); iter1.set_const(&mesh, 1.00); iter2.set_const(&mesh, 1.00); iter3.set_const(&mesh, 1.00); iter4.set_const(&mesh, 1.00); // Enter boundary markers. BCTypes bc_types; bc_types.add_bc_neumann(BDY_SYM); bc_types.add_bc_newton(BDY_VACUUM); // Create H1 spaces with default shapesets. H1Space space1(&mesh, &bc_types, P_INIT_1); H1Space space2(&mesh, &bc_types, P_INIT_2); H1Space space3(&mesh, &bc_types, P_INIT_3); H1Space space4(&mesh, &bc_types, P_INIT_4); Hermes::Tuple<Space*> spaces(&space1, &space2, &space3, &space4); int ndof = Space::get_num_dofs(Hermes::Tuple<Space*>(&space1, &space2, &space3, &space4)); info("ndof = %d.", ndof); // Initialize views. ScalarView view1("Neutron flux 1", new WinGeom(0, 0, 320, 600)); ScalarView view2("Neutron flux 2", new WinGeom(350, 0, 320, 600)); ScalarView view3("Neutron flux 3", new WinGeom(700, 0, 320, 600)); ScalarView view4("Neutron flux 4", new WinGeom(1050, 0, 320, 600)); // Do not show meshes. view1.show_mesh(false); view1.set_3d_mode(true); view2.show_mesh(false); view2.set_3d_mode(true); view3.show_mesh(false); view3.set_3d_mode(true); view4.show_mesh(false); view4.set_3d_mode(true); // Initialize the weak formulation. WeakForm wf(4); wf.add_matrix_form(0, 0, callback(biform_0_0), HERMES_SYM); wf.add_matrix_form(1, 1, callback(biform_1_1), HERMES_SYM); wf.add_matrix_form(1, 0, callback(biform_1_0)); wf.add_matrix_form(2, 2, callback(biform_2_2), HERMES_SYM); wf.add_matrix_form(2, 1, callback(biform_2_1)); wf.add_matrix_form(3, 3, callback(biform_3_3), HERMES_SYM); wf.add_matrix_form(3, 2, callback(biform_3_2)); wf.add_vector_form(0, callback(liform_0), marker_core, Hermes::Tuple<MeshFunction*>(&iter1, &iter2, &iter3, &iter4)); wf.add_vector_form(1, callback(liform_1), marker_core, Hermes::Tuple<MeshFunction*>(&iter1, &iter2, &iter3, &iter4)); wf.add_vector_form(2, callback(liform_2), marker_core, Hermes::Tuple<MeshFunction*>(&iter1, &iter2, &iter3, &iter4)); wf.add_vector_form(3, callback(liform_3), marker_core, Hermes::Tuple<MeshFunction*>(&iter1, &iter2, &iter3, &iter4)); wf.add_matrix_form_surf(0, 0, callback(biform_surf_0_0), BDY_VACUUM); wf.add_matrix_form_surf(1, 1, callback(biform_surf_1_1), BDY_VACUUM); wf.add_matrix_form_surf(2, 2, callback(biform_surf_2_2), BDY_VACUUM); wf.add_matrix_form_surf(3, 3, callback(biform_surf_3_3), BDY_VACUUM); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, spaces, is_linear); SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Time measurement. TimePeriod cpu_time, solver_time; // Main power iteration loop: int iter = 1; bool done = false; bool rhs_only = false; solver->set_factorization_scheme(HERMES_REUSE_FACTORIZATION_COMPLETELY); do { info("------------ Power iteration %d:", iter); info("Assembling the stiffness matrix and right-hand side vector."); dp.assemble(matrix, rhs, rhs_only); /* // Testing the factorization reuse schemes for direct solvers. if (iter == 10) solver->set_factorization_scheme(HERMES_REUSE_MATRIX_REORDERING); if (iter == 20) solver->set_factorization_scheme(HERMES_REUSE_MATRIX_REORDERING_AND_SCALING); if (iter == 30) solver->set_factorization_scheme(HERMES_REUSE_FACTORIZATION_COMPLETELY); */ info("Solving the matrix problem by %s.", MatrixSolverNames[matrix_solver].c_str()); solver_time.tick(HERMES_SKIP); bool solved = solver->solve(); solver_time.tick(); if(solved) Solution::vector_to_solutions(solver->get_solution(), spaces, solutions); else error ("Matrix solver failed.\n"); // Show intermediate solutions. // view1.show(&sln1); // view2.show(&sln2); // view3.show(&sln3); // view4.show(&sln4); SimpleFilter source(source_fn, Hermes::Tuple<MeshFunction*>(&sln1, &sln2, &sln3, &sln4)); SimpleFilter source_prev(source_fn, Hermes::Tuple<MeshFunction*>(&iter1, &iter2, &iter3, &iter4)); // Compute eigenvalue. double k_new = k_eff * (integrate(&source, marker_core) / integrate(&source_prev, marker_core)); info("Largest eigenvalue: %.8g, rel. difference from previous it.: %g", k_new, fabs((k_eff - k_new) / k_new)); // Stopping criterion. if (fabs((k_eff - k_new) / k_new) < ERROR_STOP) done = true; // Update eigenvalue. k_eff = k_new; if (!done) { // Save solutions for the next iteration. iter1.copy(&sln1); iter2.copy(&sln2); iter3.copy(&sln3); iter4.copy(&sln4); // Don't need to reassemble the system matrix in further iterations, // only the rhs changes to reflect the progressively updated source. rhs_only = true; iter++; } } while (!done); // Time measurement. cpu_time.tick(); solver_time.tick(HERMES_SKIP); // Print timing information. verbose("Average solver time for one power iteration: %g s", solver_time.accumulated() / iter); // Clean up. delete matrix; delete rhs; delete solver; // Show solutions. view1.show(&sln1); view2.show(&sln2); view3.show(&sln3); view4.show(&sln4); // Skip visualization time. cpu_time.tick(HERMES_SKIP); // Print timing information. verbose("Total running time: %g s", cpu_time.accumulated()); // Wait for all views to be closed. View::wait(); return 0; }
int main(int argc, char* argv[]) { // Load the mesh. Mesh mesh; MeshReaderH2D mloader; mloader.load(mesh_file.c_str(), &mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Solution variables. Solution<double> sln1, sln2, sln3, sln4; Hermes::vector<Solution<double>*> solutions(&sln1, &sln2, &sln3, &sln4); // Define initial conditions. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); ConstantSolution<double> iter1(&mesh, 1.00), iter2(&mesh, 1.00), iter3(&mesh, 1.00), iter4(&mesh, 1.00); Hermes::vector<MeshFunction<double>*> iterates(&iter1, &iter2, &iter3, &iter4); // Create H1 spaces with default shapesets. H1Space<double> space1(&mesh, P_INIT_1); H1Space<double> space2(&mesh, P_INIT_2); H1Space<double> space3(&mesh, P_INIT_3); H1Space<double> space4(&mesh, P_INIT_4); Hermes::vector<const Space<double>* > spaces(&space1, &space2, &space3, &space4); int ndof = Space<double>::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize views. ScalarView view1("Neutron flux 1", new WinGeom(0, 0, 320, 600)); ScalarView view2("Neutron flux 2", new WinGeom(350, 0, 320, 600)); ScalarView view3("Neutron flux 3", new WinGeom(700, 0, 320, 600)); ScalarView view4("Neutron flux 4", new WinGeom(1050, 0, 320, 600)); // Do not show meshes, set 3D mode. view1.show_mesh(false); view1.set_3d_mode(true); view2.show_mesh(false); view2.set_3d_mode(true); view3.show_mesh(false); view3.set_3d_mode(true); view4.show_mesh(false); view4.set_3d_mode(true); // Load physical data of the problem for the 4 energy groups. Hermes::Hermes2D::WeakFormsNeutronics::Multigroup::MaterialProperties::Diffusion::MaterialPropertyMaps matprop(4); matprop.set_D(D); matprop.set_Sigma_r(Sr); matprop.set_Sigma_s(Ss); matprop.set_Sigma_a(Sa); matprop.set_Sigma_f(Sf); matprop.set_nu(nu); matprop.set_chi(chi); matprop.validate(); // Printing table of material properties. std::cout << matprop; // Initialize the weak formulation. CustomWeakForm wf(matprop, iterates, k_eff, bdy_vacuum); // Initialize the FE problem. DiscreteProblem<double> dp(&wf, spaces); // Initialize Newton solver. NewtonSolver<double> newton(&dp); // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; // Main power iteration loop: int it = 1; bool done = false; do { Hermes::Mixins::Loggable::Static::info("------------ Power iteration %d:", it); Hermes::Mixins::Loggable::Static::info("Newton's method."); // Perform Newton's iteration. try { newton.set_newton_max_iter(NEWTON_MAX_ITER); newton.set_newton_tol(NEWTON_TOL); newton.solve_keep_jacobian(); } catch(Hermes::Exceptions::Exception e) { e.printMsg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); } // Debug. //printf("\n=================================================\n"); //for (int d = 0; d < ndof; d++) printf("%g ", newton.get_sln_vector()[d]); // Translate the resulting coefficient vector into a Solution. Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, solutions); // Show intermediate solutions. view1.show(&sln1); view2.show(&sln2); view3.show(&sln3); view4.show(&sln4); // Compute eigenvalue. SourceFilter source(solutions, &matprop, core); SourceFilter source_prev(iterates, &matprop, core); double k_new = k_eff * (integrate(&source, core) / integrate(&source_prev, core)); Hermes::Mixins::Loggable::Static::info("Largest eigenvalue: %.8g, rel. difference from previous it.: %g", k_new, fabs((k_eff - k_new) / k_new)); // Stopping criterion. if (fabs((k_eff - k_new) / k_new) < ERROR_STOP) done = true; // Update eigenvalue. k_eff = k_new; wf.update_keff(k_eff); if (!done) { // Save solutions for the next iteration. iter1.copy(&sln1); iter2.copy(&sln2); iter3.copy(&sln3); iter4.copy(&sln4); it++; } } while (!done); // Time measurement. cpu_time.tick(); // Show solutions. view1.show(&sln1); view2.show(&sln2); view3.show(&sln3); view4.show(&sln4); // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Print timing information. Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); // Wait for all views to be closed. View::wait(); return 0; }
int main(int argc, char* argv[]) { // Build your scene and setup your camera here, by calling // functions from Raytracer. The code here sets up an example // scene and renders it from two different view points, DO NOT // change this if you're just implementing part one of the // assignment. Raytracer raytracer; int width = 320; int height = 240; int aa = 2; int sceneNum = 0; double toRadian = 2*M_PI/360.0; fprintf(stderr, "Using options:\n"); #ifdef USE_EXTENDEDLIGHTS fprintf(stderr, "\tExtended light sources\n"); #else fprintf(stderr, "\tPoint light sources\n"); #endif #ifdef USE_REFRACTIONS fprintf(stderr, "\tRefractions\n"); #else fprintf(stderr, "\tNo refractions\n"); #endif #ifdef USE_REFLECTIONS fprintf(stderr, "\tReflections\n"); #else fprintf(stderr, "\tNo reflections\n"); #endif #ifdef IGNORE_SHADOWS fprintf(stderr, "\tNo shadows\n"); #else { #ifdef USE_TRANSMISSIONSHADOWS fprintf(stderr, "\tTransmission-based shadows\n"); #else fprintf(stderr, "\tSimple shadows\n"); #endif } #endif #ifdef USE_FINERFLUX fprintf(stderr, "\tFiner numerical flux intergrations\n"); #else fprintf(stderr, "\tCoarser numerical flux intergrations\n"); #endif if (argc == 3) { width = atoi(argv[1]); height = atoi(argv[2]); } else if (argc == 4) { width = atoi(argv[1]); height = atoi(argv[2]); aa = atoi(argv[3]); } else if (argc == 5) { width = atoi(argv[1]); height = atoi(argv[2]); aa = atoi(argv[3]); sceneNum = atoi(argv[4]); } // SceneNum should not exceed total scenes if ((sceneNum > 3)|| (sceneNum <0)) { sceneNum = 0; } // Camera parameters. Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines materials for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2, 0.001, 0.0, 1/2.4 ); Material jade( Colour(0.22, 0.38, 0.33), Colour(0.52, 0.73, 0.57), Colour(0.316228, 0.316228, 0.316228), 12.8, 0.2 , 0.0, 0.0 ); Material polishedGold( Colour(0.24725, 0.2245, 0.0645), Colour(0.34615, 0.3143, 0.0903), Colour(0.797357, 0.723991, 0.208006), 83.2, 0.01,0.0,0.0); Material glass( Colour(0.15, 0.15, 0.15), Colour(0.08, 0.08, 0.08), Colour(0.2, 0.2, 0.2), 50.1,0.08,0.9,0.6667 ); Material glass1( Colour(0.2, 0.2, 0.2), Colour(0.2, 0.2, 0.2), Colour(0.7, 0.7, 0.7), 10.1,0.03,0.9,0.6667 ); Material steel( Colour(0.1, 0.1, 0.1), Colour(0.1, 0.1, 0.1), Colour(0.8, 0.8, 0.8), 80, 0.03, 0.0, 1.0 ); Material blueSolid( Colour(0, 0, 1), Colour(0, 0, 1), Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 ); Material redSolid( Colour(1, 0, 0), Colour(1, 0, 0), Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 ); Material chrome( Colour(0.25, 0.25, 0.25), Colour(0.4,0.4,0.4), Colour(0.7746, 0.7746, 0.7746), 77, 0.42, 0.0, 1.0); Material ruby( Colour(0.1745, 0.01175, 0.01175), Colour(0.61424, 0.04136, 0.04136), Colour(0.727811, 0.626959, 0.626959) , 76.8, 0.01, 0.0, 0.565); Material pearl( Colour(0.25, 0.20725, 0.20725), Colour(1, 0.829, 0.829), Colour(0.296648, 0.296648, 0.296648), 11.264, 0.1,0.0,1.0 ); Material silver(Colour(0.23125, 0.23125, 0.23125), Colour(0.2775, 0.2775, 0.2775), Colour(0.773911, 0.773911, 0.773911), 89.6, 0.4,0.0, 1.0); Material emerald(Colour(0.0215, 0.1745, 0.0215),Colour(0.07568, 0.61424, 0.07568), Colour(0.633, 0.727811, 0.633), 76.8, 0.1, 0.25, 0.637); Material brass(Colour(0.329412, 0.223529, 0.027451),Colour(0.780392, 0.568627, 0.113725), Colour(0.992157, 0.941176, 0.807843),27.8974, 0.3, 0.0, 1.0 ); Material bronze(Colour(0.2125, 0.1275, 0.054), Colour(0.714, 0.4284, 0.18144), Colour(0.393548, 0.271906, 0.166721), 25.6, 0.1, 0.0, 1.0 ); Material bronzeShiny(Colour(0.25, 0.148, 0.06475), Colour(0.4, 0.2368, 0.1036), Colour(0.774597, 0.458561, 0.200621), 76.86, 0.15, 0.0, 1.0 ); Material turquoise(Colour(0.1, 0.18725, 0.1745), Colour(0.396, 0.74151, 0.69102), Colour(0.297254, 0.30829, 0.306678), 12.8, 0.01, 0.2, 0.9); Material obsidian(Colour(0.05375, 0.05, 0.06625), Colour(0.18275, 0.17, 0.22525), Colour(0.332741, 0.328634, 0.346435), 38.4, 0.05, 0.18, 0.413); Material copper(Colour(0.19125, 0.0735, 0.0225), Colour(0.7038, 0.27048, 0.0828), Colour(0.256777, 0.137622, 0.086014), 12.8, 0.1, 0.0, 1.0 ); Material copperPolished(Colour(0.2295, 0.08825, 0.0275), Colour(0.5508, 0.2118, 0.066), Colour(0.580594, 0.223257, 0.0695701), 51.2, 0.15, 0.0, 1.0 ); Material pewter(Colour(0.105882, 0.058824, 0.113725), Colour(0.427451, 0.470588, 0.541176), Colour(0.333333, 0.333333, 0.521569), 9.84615, 0.0, 0.0, 1.0 ); // Light Sources //===================== //raytracer.addLightSource( new PointLight(Point3D(1, 1, 2),Colour(0.5, 0.5, 0.5)) ); #ifdef USE_EXTENDEDLIGHTS // Defines a ball light source raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 2.0, Colour(0.9, 0.9, 0.9), 4) ); #else // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), Colour(0.9, 0.9,0.9) ) ); #endif if (sceneNum==0) { // Defines a point light source. //raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), // Colour(0.9, 0.9, 0.9) ) ); // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 1.0 }; double factor3[3] = { 4.0, 4.0, 4.0 }; double factor4[3] = { 3.7, 3.7, 3.7 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); /* SceneDagNode* bigSphere = raytracer.addObject( new UnitSphere(), &glass1); raytracer.scale(bigSphere, Point3D(0, 0, 0), factor3); raytracer.translate(bigSphere, Vector3D(0, 0, -7)); SceneDagNode* bigSphere2 = raytracer.addObject( new UnitSphere(), &glass1); raytracer.scale(bigSphere2, Point3D(0, 0, 0), factor4); raytracer.translate(bigSphere2, Vector3D(0, 0, -7)); */ }// end of scene 0 if (sceneNum==1) { /* raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 5.0, Colour(0.9, 0.9, 0.9), 0.888) ); raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) ); */ // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &glass); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &brass); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade); SceneDagNode* cylinder = raytracer.addObject( new UnitCylinder(), &brass); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 1.0 }; double factor3[3] = { 0.5, 0.5, 2.0 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(sphere1, Vector3D(-2.5, 0, -5)); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); raytracer.translate(cylinder, Vector3D(3, 0, -5)); //raytracer.rotate(cylinder, 'y', -20); raytracer.rotate(cylinder, 'z', 45); raytracer.rotate(cylinder, 'x', -75); raytracer.scale(cylinder, Point3D(0, 0, 0), factor3); }// end of scene1 //=============== Scene 2 ============================== //===================================================== if(sceneNum == 2) { /* raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1), 5.0, Colour(0.9, 0.9, 0.9), 0.888) );*/ //raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) ); //Set up walls //======================================================== SceneDagNode* planeBack = raytracer.addObject( new UnitSquare(), &brass); SceneDagNode* planeBottom = raytracer.addObject( new UnitSquare(), &chrome); SceneDagNode* planeTop = raytracer.addObject( new UnitSquare(), &copperPolished); SceneDagNode* planeLeft = raytracer.addObject( new UnitSquare(), &bronzeShiny); SceneDagNode* planeRight = raytracer.addObject( new UnitSquare(), &brass); SceneDagNode* planeRear = raytracer.addObject( new UnitSquare(), &brass); double scaleFactor[3] = {8.0,8.0,1.0}; double scaleFactor1[3] = {20.01,20.01,1.0}; raytracer.translate(planeBottom, Vector3D(0, -10, 0)); raytracer.translate(planeTop, Vector3D(0, 10, 0)); raytracer.translate(planeLeft, Vector3D(-10, 0, 0)); raytracer.translate(planeRight, Vector3D(10, 0, 0)); raytracer.translate(planeBack, Vector3D(0, 0, -19.9)); raytracer.translate(planeBottom, Vector3D(0, 0, -10)); raytracer.translate(planeTop, Vector3D(0, 0, -10)); raytracer.translate(planeLeft, Vector3D(0, 0, -10)); raytracer.translate(planeRight, Vector3D(0, 0, -10)); raytracer.translate(planeRear, Vector3D(0, 0, 20)); raytracer.rotate(planeTop, 'x', 90); raytracer.rotate(planeBottom, 'x',-90); raytracer.rotate(planeLeft, 'y', -90); raytracer.rotate(planeRight, 'y', 90); raytracer.rotate(planeRear, 'x', 180); raytracer.scale(planeBack, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeBottom, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeTop, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeLeft, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeRight, Point3D(0, 0, 0), scaleFactor1); raytracer.scale(planeRear, Point3D(0, 0, 0), scaleFactor1); //=========================================================== double scaleEgg[3] = { 1.0, 1.5, 1.0 }; double scaleBall[3] = {2,2,2}; SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &glass1); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &ruby); SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &chrome); //SceneDagNode* cone = raytracer.addObject(sphere, new UnitCone(), &emerald); //raytracer.translate(cone, Vector3D(0,0,-2)); raytracer.translate(sphere, Vector3D(-1,-1,-11)); raytracer.scale(sphere, Point3D(0,0,0), scaleBall); raytracer.translate(sphere1, Vector3D(2.5,-1,-11)); raytracer.translate(sphere2, Vector3D(2,3,-11)); //raytracer.translate(cone, Vector3D(-1,-1,-12)); raytracer.rotate(sphere1, 'z', -45); raytracer.scale(sphere1, Point3D(0,0,0), scaleEgg); //raytracer.rotate(cone, 'x', 90); }//end of scene 2 //==================== Scene 3 ================= //=============================================== if(sceneNum == 3) { #ifdef USE_EXTENDEDLIGHTS raytracer.addLightSource( new BallLight(Point3D(-5, 5, -3), 2.0, Colour(0.4, 0.4, 0.4), 2) ); raytracer.addLightSource( new BallLight(Point3D(5, 5, -3), 2.0, Colour(0.4, 0.4, 0.4), 2) ); #else raytracer.addLightSource( new PointLight(Point3D(-5, 5, 0), Colour(0.5, 0.0, 0.0) ) ); raytracer.addLightSource( new PointLight(Point3D(5, 5, 0), Colour(0.0, 0.5, 0.0) ) ); raytracer.addLightSource( new PointLight(Point3D(0, -5, 0), Colour(0.0, 0.0, 0.5) ) ); #endif double planeScale[3] = {10.0, 10.0, 1.0}; double sphereScale[3]= {1.5,1.5,1.5}; double coneScale[3] = {1.5,1.5,5}; SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &pearl); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &chrome); SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &brass); //SceneDagNode* cone = raytracer.addObject( new UnitCone(), &turquoise); raytracer.translate(sphere1, Vector3D(1, 1.5, -6.5)); raytracer.translate(sphere2, Vector3D(-1, -1.5, -6.5)); raytracer.scale(sphere2, Point3D(0,0,0), sphereScale); raytracer.scale(sphere1, Point3D(0,0,0), sphereScale); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0,0,0), planeScale); raytracer.translate(plane, Vector3D(0, 0, -8)); /* raytracer.translate(cone, Vector3D(2.0,-1.0,-3)); raytracer.rotate(cone, 'x', 180); raytracer.scale(cone, Point3D(0,0,0), coneScale); */ } // Render the scene, feel free to make the image smaller for // testing purposes. raytracer.render(width, height, eye, view, up, fov, aa, "sig1.bmp", 's'); //raytracer.render(width, height, eye, view, up, fov, aa, "diffuse1.bmp",'d'); //raytracer.render(width, height, eye, view, up, fov, aa, "view1.bmp",'p'); // Render it from a different point of view. Point3D eye2(4, 2, 1); Vector3D view2(-4, -2, -6); raytracer.render(width, height, eye2, view2, up, fov, aa, "sig2.bmp", 's'); //raytracer.render(width, height, eye2, view2, up, fov, aa, "diffuse2.bmp",'d'); //raytracer.render(width, height, eye2, view2, up, fov, aa, "view2.bmp",'p'); Point3D eye3(-4, -2, 1); Vector3D view3(4, 2, -6); raytracer.render(width, height, eye3, view3, up, fov, aa, "sig3.bmp", 's'); //raytracer.render(width, height, eye3, view3, up, fov, aa, "diffuse3.bmp",'d'); raytracer.render(width, height, eye3, view3, up, fov, aa, "view3.bmp",'p'); return 0; }
int main(int argc, char* argv[]) { // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); // Load physical data of the problem. MaterialPropertyMaps matprop(N_GROUPS); matprop.set_D(D); matprop.set_Sigma_r(Sr); matprop.set_Sigma_s(Ss); matprop.set_Sigma_a(Sa); matprop.set_Sigma_f(Sf); matprop.set_nu(nu); matprop.set_chi(chi); matprop.validate(); std::cout << matprop; // Use multimesh, i.e. create one mesh for each energy group. Hermes::vector<Mesh *> meshes; for (unsigned int g = 0; g < matprop.get_G(); g++) meshes.push_back(new Mesh()); // Load the mesh for the 1st group. MeshReaderH2D mloader; mloader.load(mesh_file.c_str(), meshes[0]); for (unsigned int g = 1; g < matprop.get_G(); g++) { // Obtain meshes for the 2nd to 4th group by cloning the mesh loaded for the 1st group. meshes[g]->copy(meshes[0]); // Initial uniform refinements. for (int i = 0; i < INIT_REF_NUM[g]; i++) meshes[g]->refine_all_elements(); } for (int i = 0; i < INIT_REF_NUM[0]; i++) meshes[0]->refine_all_elements(); // Create pointers to solutions on coarse and fine meshes and from the latest power iteration, respectively. Hermes::vector<Solution<double>*> coarse_solutions, fine_solutions; Hermes::vector<MeshFunction<double>*> power_iterates; // Initialize all the new solution variables. for (unsigned int g = 0; g < matprop.get_G(); g++) { coarse_solutions.push_back(new Solution<double>()); fine_solutions.push_back(new Solution<double>()); power_iterates.push_back(new ConstantSolution<double>(meshes[g], 1.0)); } // Create the approximation spaces with the default shapeset. H1Space<double> space1(meshes[0], P_INIT[0]); H1Space<double> space2(meshes[1], P_INIT[1]); H1Space<double> space3(meshes[2], P_INIT[2]); H1Space<double> space4(meshes[3], P_INIT[3]); Hermes::vector<const Space<double>*> const_spaces(&space1, &space2, &space3, &space4); Hermes::vector<Space<double>*> spaces(&space1, &space2, &space3, &space4); // Initialize the weak formulation. CustomWeakForm wf(matprop, power_iterates, k_eff, bdy_vacuum); // Initialize the discrete algebraic representation of the problem and its solver. // // Create the matrix and right-hand side vector for the solver. SparseMatrix<double>* mat = create_matrix<double>(); Vector<double>* rhs = create_vector<double>(); // Instantiate the solver itself. LinearMatrixSolver<double>* solver = create_linear_solver<double>( mat, rhs); // Initialize views. /* for 1280x800 display */ ScalarView view1("Neutron flux 1", new WinGeom(0, 0, 320, 400)); ScalarView view2("Neutron flux 2", new WinGeom(330, 0, 320, 400)); ScalarView view3("Neutron flux 3", new WinGeom(660, 0, 320, 400)); ScalarView view4("Neutron flux 4", new WinGeom(990, 0, 320, 400)); OrderView oview1("Mesh for group 1", new WinGeom(0, 450, 320, 500)); OrderView oview2("Mesh for group 2", new WinGeom(330, 450, 320, 500)); OrderView oview3("Mesh for group 3", new WinGeom(660, 450, 320, 500)); OrderView oview4("Mesh for group 4", new WinGeom(990, 450, 320, 500)); /* for adjacent 1280x800 and 1680x1050 displays ScalarView view1("Neutron flux 1", new WinGeom(0, 0, 640, 480)); ScalarView view2("Neutron flux 2", new WinGeom(650, 0, 640, 480)); ScalarView view3("Neutron flux 3", new WinGeom(1300, 0, 640, 480)); ScalarView view4("Neutron flux 4", new WinGeom(1950, 0, 640, 480)); OrderView oview1("Mesh for group 1", new WinGeom(1300, 500, 340, 500)); OrderView oview2("Mesh for group 2", new WinGeom(1650, 500, 340, 500)); OrderView oview3("Mesh for group 3", new WinGeom(2000, 500, 340, 500)); OrderView oview4("Mesh for group 4", new WinGeom(2350, 500, 340, 500)); */ Hermes::vector<ScalarView *> sviews(&view1, &view2, &view3, &view4); Hermes::vector<OrderView *> oviews(&oview1, &oview2, &oview3, &oview4); for (unsigned int g = 0; g < matprop.get_G(); g++) { sviews[g]->show_mesh(false); sviews[g]->set_3d_mode(true); } // DOF and CPU convergence graphs GnuplotGraph graph_dof("Error convergence", "NDOF", "log(error)"); graph_dof.add_row("H1 err. est. [%]", "r", "-", "o"); graph_dof.add_row("L2 err. est. [%]", "g", "-", "s"); graph_dof.add_row("Keff err. est. [milli-%]", "b", "-", "d"); graph_dof.set_log_y(); graph_dof.show_legend(); graph_dof.show_grid(); GnuplotGraph graph_dof_evol("Evolution of NDOF", "Adaptation step", "NDOF"); graph_dof_evol.add_row("group 1", "r", "-", "o"); graph_dof_evol.add_row("group 2", "g", "-", "x"); graph_dof_evol.add_row("group 3", "b", "-", "+"); graph_dof_evol.add_row("group 4", "m", "-", "*"); graph_dof_evol.set_log_y(); graph_dof_evol.set_legend_pos("bottom right"); graph_dof_evol.show_grid(); GnuplotGraph graph_cpu("Error convergence", "CPU time [s]", "log(error)"); graph_cpu.add_row("H1 err. est. [%]", "r", "-", "o"); graph_cpu.add_row("L2 err. est. [%]", "g", "-", "s"); graph_cpu.add_row("Keff err. est. [milli-%]", "b", "-", "d"); graph_cpu.set_log_y(); graph_cpu.show_legend(); graph_cpu.show_grid(); // Initialize the refinement selectors. H1ProjBasedSelector<double> selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); Hermes::vector<RefinementSelectors::Selector<double>*> selectors; for (unsigned int g = 0; g < matprop.get_G(); g++) selectors.push_back(&selector); Hermes::vector<MatrixFormVol<double>*> projection_jacobian; Hermes::vector<VectorFormVol<double>*> projection_residual; for (unsigned int g = 0; g < matprop.get_G(); g++) { projection_jacobian.push_back(new H1AxisymProjectionJacobian(g)); projection_residual.push_back(new H1AxisymProjectionResidual(g, power_iterates[g])); } Hermes::vector<ProjNormType> proj_norms_h1, proj_norms_l2; for (unsigned int g = 0; g < matprop.get_G(); g++) { proj_norms_h1.push_back(HERMES_H1_NORM); proj_norms_l2.push_back(HERMES_L2_NORM); } // Initial power iteration to obtain a coarse estimate of the eigenvalue and the fission source. Hermes::Mixins::Loggable::Static::info("Coarse mesh power iteration, %d + %d + %d + %d = %d ndof:", report_num_dofs(spaces)); power_iteration(matprop, const_spaces, &wf, power_iterates, core, TOL_PIT_CM, matrix_solver); // Adaptivity loop: int as = 1; bool done = false; do { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined meshes and setup reference spaces on them. Hermes::vector<const Space<double>*> ref_spaces_const; Hermes::vector<Mesh *> ref_meshes; for (unsigned int g = 0; g < matprop.get_G(); g++) { ref_meshes.push_back(new Mesh()); Mesh *ref_mesh = ref_meshes.back(); ref_mesh->copy(spaces[g]->get_mesh()); ref_mesh->refine_all_elements(); int order_increase = 1; ref_spaces_const.push_back(spaces[g]->dup(ref_mesh, order_increase)); } #ifdef WITH_PETSC // PETSc assembling is currently slow for larger matrices, so we switch to // UMFPACK when matrices of order >8000 start to appear. if (Space<double>::get_num_dofs(ref_spaces_const) > 8000 && matrix_solver == SOLVER_PETSC) { // Delete the old solver. delete mat; delete rhs; delete solver; // Create a new one. matrix_solver = SOLVER_UMFPACK; mat = create_matrix<double>(); rhs = create_vector<double>(); solver = create_linear_solver<double>( mat, rhs); } #endif // Solve the fine mesh problem. Hermes::Mixins::Loggable::Static::info("Fine mesh power iteration, %d + %d + %d + %d = %d ndof:", report_num_dofs(ref_spaces_const)); power_iteration(matprop, ref_spaces_const, &wf, power_iterates, core, TOL_PIT_RM, matrix_solver); // Store the results. for (unsigned int g = 0; g < matprop.get_G(); g++) fine_solutions[g]->copy((static_cast<Solution<double>*>(power_iterates[g]))); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solutions on coarse meshes."); // This is commented out as the appropriate method was deleted in the commit // "Cleaning global projections" (b282194946225014faa1de37f20112a5a5d7ab5a). //OGProjection<double> ogProjection; ogProjection.project_global(spaces, projection_jacobian, projection_residual, coarse_solutions); // Time measurement. cpu_time.tick(); // View the coarse mesh solution and meshes. for (unsigned int g = 0; g < matprop.get_G(); g++) { sviews[g]->show(coarse_solutions[g]); oviews[g]->show(spaces[g]); } // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Report the number of negative eigenfunction values. Hermes::Mixins::Loggable::Static::info("Num. of negative values: %d, %d, %d, %d", get_num_of_neg(coarse_solutions[0]), get_num_of_neg(coarse_solutions[1]), get_num_of_neg(coarse_solutions[2]), get_num_of_neg(coarse_solutions[3])); // Calculate element errors and total error estimate. Adapt<double> adapt_h1(spaces); Adapt<double> adapt_l2(spaces); for (unsigned int g = 0; g < matprop.get_G(); g++) { adapt_h1.set_error_form(g, g, new ErrorForm(proj_norms_h1[g])); adapt_l2.set_error_form(g, g, new ErrorForm(proj_norms_l2[g])); } // Calculate element errors and error estimates in H1 and L2 norms. Use the H1 estimate to drive adaptivity. Hermes::Mixins::Loggable::Static::info("Calculating errors."); Hermes::vector<double> h1_group_errors, l2_group_errors; double h1_err_est = adapt_h1.calc_err_est(coarse_solutions, fine_solutions, &h1_group_errors) * 100; double l2_err_est = adapt_l2.calc_err_est(coarse_solutions, fine_solutions, &l2_group_errors, false) * 100; // Time measurement. cpu_time.tick(); double cta = cpu_time.accumulated(); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d + %d + %d + %d = %d", report_num_dofs(spaces)); // Millipercent eigenvalue error w.r.t. the reference value (see physical_parameters.cpp). double keff_err = 1e5*fabs(wf.get_keff() - REF_K_EFF)/REF_K_EFF; Hermes::Mixins::Loggable::Static::info("per-group err_est_coarse (H1): %g%%, %g%%, %g%%, %g%%", report_errors(h1_group_errors)); Hermes::Mixins::Loggable::Static::info("per-group err_est_coarse (L2): %g%%, %g%%, %g%%, %g%%", report_errors(l2_group_errors)); Hermes::Mixins::Loggable::Static::info("total err_est_coarse (H1): %g%%", h1_err_est); Hermes::Mixins::Loggable::Static::info("total err_est_coarse (L2): %g%%", l2_err_est); Hermes::Mixins::Loggable::Static::info("k_eff err: %g milli-percent", keff_err); // Add entry to DOF convergence graph. int ndof_coarse = spaces[0]->get_num_dofs() + spaces[1]->get_num_dofs() + spaces[2]->get_num_dofs() + spaces[3]->get_num_dofs(); graph_dof.add_values(0, ndof_coarse, h1_err_est); graph_dof.add_values(1, ndof_coarse, l2_err_est); graph_dof.add_values(2, ndof_coarse, keff_err); // Add entry to CPU convergence graph. graph_cpu.add_values(0, cta, h1_err_est); graph_cpu.add_values(1, cta, l2_err_est); graph_cpu.add_values(2, cta, keff_err); for (unsigned int g = 0; g < matprop.get_G(); g++) graph_dof_evol.add_values(g, as, Space<double>::get_num_dofs(spaces[g])); cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // If err_est too large, adapt the mesh (L2 norm chosen since (weighted integrals of) solution values // are more important for further analyses than the derivatives. if (l2_err_est < ERR_STOP) done = true; else { Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); done = adapt_h1.adapt(selectors, THRESHOLD, STRATEGY, MESH_REGULARITY); if (spaces[0]->get_num_dofs() + spaces[1]->get_num_dofs() + spaces[2]->get_num_dofs() + spaces[3]->get_num_dofs() >= NDOF_STOP) done = true; } // Free reference meshes and spaces. for (unsigned int g = 0; g < matprop.get_G(); g++) { delete ref_spaces_const[g]; delete ref_meshes[g]; } as++; if (as >= MAX_ADAPT_NUM) done = true; } while(done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); for (unsigned int g = 0; g < matprop.get_G(); g++) { delete spaces[g]; delete meshes[g]; delete coarse_solutions[g], delete fine_solutions[g]; delete power_iterates[g]; } delete mat; delete rhs; delete solver; graph_dof.save("conv_dof.gp"); graph_cpu.save("conv_cpu.gp"); graph_dof_evol.save("dof_evol.gp"); // Wait for all views to be closed. View::wait(); return 0; }
//##Documentation //## @brief Use several views to explore data //## //## As in Step2 and Step3, load one or more data sets (many image, //## surface and other formats), but create 3 views on the data. //## The QmitkRenderWindow is used for displaying a 3D view as in Step3, //## but without volume-rendering. //## Furthermore, we create two 2D views for slicing through the data. //## We use the class QmitkSliceWidget, which is based on the class //## QmitkRenderWindow, but additionally provides sliders //## to slice through the data. We create two instances of //## QmitkSliceWidget, one for axial and one for sagittal slicing. //## The two slices are also shown at their correct position in 3D as //## well as intersection-line, each in the other 2D view. int main(int argc, char* argv[]) { QApplication qtapplication( argc, argv ); if(argc<2) { fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); return 1; } // Register Qmitk-dependent global instances QmitkRegisterClasses(); //************************************************************************* // Part I: Basic initialization //************************************************************************* // Create a DataStorage mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); //************************************************************************* // Part II: Create some data by reading files //************************************************************************* int i; for(i=1; i<argc; ++i) { // For testing if(strcmp(argv[i], "-testing")==0) continue; // Create a DataNodeFactory to read a data format supported // by the DataNodeFactory (many image formats, surface formats, etc.) mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New(); const char * filename = argv[i]; try { nodeReader->SetFileName(filename); nodeReader->Update(); //********************************************************************* //Part III: Put the data into the datastorage //********************************************************************* // Since the DataNodeFactory directly creates a node, // use the datastorage to add the read node mitk::DataNode::Pointer node = nodeReader->GetOutput(); ds->Add(node); } catch(...) { fprintf( stderr, "Could not open file %s \n\n", filename ); exit(2); } } //************************************************************************* // Part IV: Create windows and pass the tree to it //************************************************************************* // Create toplevel widget with horizontal layout QWidget toplevelWidget; QHBoxLayout layout; layout.setSpacing(2); layout.setMargin(0); toplevelWidget.setLayout(&layout); //************************************************************************* // Part IVa: 3D view //************************************************************************* // Create a renderwindow QmitkRenderWindow renderWindow(&toplevelWidget); layout.addWidget(&renderWindow); // Tell the renderwindow which (part of) the datastorage to render renderWindow.GetRenderer()->SetDataStorage(ds); // Use it as a 3D view renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); // ******************************************************* // ****************** START OF NEW PART ****************** // ******************************************************* //************************************************************************* // Part IVb: 2D view for slicing axially //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view2(&toplevelWidget); layout.addWidget(&view2); view2.SetLevelWindowEnabled(true); // Tell the QmitkSliceWidget which (part of) the tree to render. // By default, it slices the data axially view2.SetDataStorage(ds); mitk::DataStorage::SetOfObjects::ConstPointer rs = ds->GetAll(); view2.SetData(rs->Begin(),mitk::SliceNavigationController::Axial); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the datastorage! ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode()); //************************************************************************* // Part IVc: 2D view for slicing sagitally //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view3(&toplevelWidget); layout.addWidget(&view3); view3.SetDataStorage(ds); // Tell the QmitkSliceWidget which (part of) the datastorage to render // and to slice sagitally view3.SetData(rs->Begin(), mitk::SliceNavigationController::Sagittal); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the datastorage! ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode()); // ******************************************************* // ******************* END OF NEW PART ******************* // ******************************************************* //************************************************************************* // Part V: Qt-specific initialization //************************************************************************* toplevelWidget.show(); // for testing #include "QtTesting.h" if(strcmp(argv[argc-1], "-testing")!=0) return qtapplication.exec(); else return QtTesting(); }
int main(int argc, char* argv[]) { // Instantiate a class with global functions. Hermes2D hermes2d; // Load the mesh. Mesh mesh; H2DReader mloader; mloader.load("reactor.mesh", &mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Solution variables. Solution sln1, sln2, sln3, sln4; Hermes::vector<Solution*> solutions(&sln1, &sln2, &sln3, &sln4); // Define initial conditions. info("Setting initial conditions."); Solution iter1, iter2, iter3, iter4; iter1.set_const(&mesh, 1.00); iter2.set_const(&mesh, 1.00); iter3.set_const(&mesh, 1.00); iter4.set_const(&mesh, 1.00); Hermes::vector<MeshFunction*> iterates(&iter1, &iter2, &iter3, &iter4); // Create H1 spaces with default shapesets. H1Space space1(&mesh, P_INIT_1); H1Space space2(&mesh, P_INIT_2); H1Space space3(&mesh, P_INIT_3); H1Space space4(&mesh, P_INIT_4); Hermes::vector<Space*> spaces(&space1, &space2, &space3, &space4); int ndof = Space::get_num_dofs(spaces); info("ndof = %d.", ndof); // Initialize views. ScalarView view1("Neutron flux 1", new WinGeom(0, 0, 320, 600)); ScalarView view2("Neutron flux 2", new WinGeom(350, 0, 320, 600)); ScalarView view3("Neutron flux 3", new WinGeom(700, 0, 320, 600)); ScalarView view4("Neutron flux 4", new WinGeom(1050, 0, 320, 600)); // Do not show meshes. view1.show_mesh(false); view1.set_3d_mode(true); view2.show_mesh(false); view2.set_3d_mode(true); view3.show_mesh(false); view3.set_3d_mode(true); view4.show_mesh(false); view4.set_3d_mode(true); // Load physical data of the problem for the 4 energy groups. MaterialPropertyMaps matprop(4); matprop.set_D(D); matprop.set_Sigma_r(Sr); matprop.set_Sigma_s(Ss); matprop.set_Sigma_s_nnz_structure(Ss_nnz); matprop.set_Sigma_a(Sa); matprop.set_Sigma_f(Sf); matprop.set_nu(nu); matprop.set_chi(chi); matprop.validate(); std::cout << matprop; // Initialize the weak formulation. CustomWeakForm wf(matprop, iterates, k_eff, bdy_vacuum); // Initialize the FE problem. DiscreteProblem dp(&wf, spaces); SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Time measurement. TimePeriod cpu_time, solver_time; // Initial coefficient vector for the Newton's method. scalar* coeff_vec = new scalar[ndof]; // Force the Jacobian assembling in the first iteration. bool Jacobian_changed = true; // In the following iterations, Jacobian will not be changing; its LU factorization // may be reused. solver->set_factorization_scheme(HERMES_REUSE_FACTORIZATION_COMPLETELY); // Main power iteration loop: int it = 1; bool done = false; do { info("------------ Power iteration %d:", it); info("Newton's method (matrix problem solved by %s).", MatrixSolverNames[matrix_solver].c_str()); memset(coeff_vec, 0.0, ndof*sizeof(scalar)); //TODO: Why it doesn't work without zeroing coeff_vec in each iteration? solver_time.tick(HERMES_SKIP); if (!hermes2d.solve_newton(coeff_vec, &dp, solver, matrix, rhs, Jacobian_changed, 1e-8, 10, true)) error("Newton's iteration failed."); solver_time.tick(); Solution::vector_to_solutions(solver->get_solution(), spaces, solutions); // Show intermediate solutions. view1.show(&sln1); view2.show(&sln2); view3.show(&sln3); view4.show(&sln4); // Compute eigenvalue. SourceFilter source(solutions, matprop); SourceFilter source_prev(iterates, matprop); double k_new = k_eff * (integrate(&source, core) / integrate(&source_prev, core)); info("Largest eigenvalue: %.8g, rel. difference from previous it.: %g", k_new, fabs((k_eff - k_new) / k_new)); // Stopping criterion. if (fabs((k_eff - k_new) / k_new) < ERROR_STOP) done = true; // Update eigenvalue. k_eff = k_new; wf.update_keff(k_eff); if (!done) { // Save solutions for the next iteration. iter1.copy(&sln1); iter2.copy(&sln2); iter3.copy(&sln3); iter4.copy(&sln4); // Don't need to reassemble the system matrix in further iterations, // only the rhs changes to reflect the progressively updated source. Jacobian_changed = false; it++; } } while (!done); delete [] coeff_vec; // Time measurement. cpu_time.tick(); solver_time.tick(HERMES_SKIP); // Print timing information. verbose("Average solver time for one power iteration: %g s", solver_time.accumulated() / it); // Clean up. delete matrix; delete rhs; delete solver; // Show solutions. view1.show(&sln1); view2.show(&sln2); view3.show(&sln3); view4.show(&sln4); // Skip visualization time. cpu_time.tick(HERMES_SKIP); // Print timing information. verbose("Total running time: %g s", cpu_time.accumulated()); // Wait for all views to be closed. View::wait(); return 0; }
/** * Wooden Monkey Scene 1 */ void refraction_scene_1() { printf("REFRACTION SCENE : 1 ----------------------------------\n\n"); Raytracer rt; int width = 16 * 20 * 2; int height = 12 * 20 * 2; // Camera parameters. Point3D eye1(0, 0, 1), eye2(4, 2, 1); Vector3D view1(0, 0, -1), view2(-4, -2, -6); Vector3D up(0, 1, 0); double fov = 60; // Defines a material for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT); Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), Colour(0.316228, 0.316228, 0.316228), 12.8); // Defines a material for shading. Material gold_nonRefract( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2, 0.8 ); // Defines a point light source. double l0c = 0.5; PointLight * light0 = new PointLight( Point3D(-2, 2, 5), Colour(l0c, l0c, l0c), 0.2); rt.addLightSource(light0); // Add a unit square into the scene with material mat. SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold ); SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold_nonRefract ); SceneDagNode* plane = rt.addObject( new UnitSquare(), &jade ); SceneDagNode* sphere3 = rt.addObject( new UnitSphere(), &RED); SceneDagNode* sphere4 = rt.addObject( new UnitSphere(), &GREEN_TRANSP); SceneDagNode* plane2 = rt.addObject( new UnitSquare(), &jade ); // SceneDagNode* plane3 = rt.addObject( new UnitSquare(), &jade ); // SceneDagNode* plane4 = rt.addObject( new UnitSquare(), &jade ); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 6.0 }; rt.translate(sphere, Vector3D(0, 0, -5)); rt.rotate(sphere, 'x', -45); rt.rotate(sphere, 'z', 45); rt.scale(sphere, Point3D(0, 0, 0), factor1); rt.translate(plane, Vector3D(0, 0, -7)); rt.rotate(plane, 'z', 45); rt.scale(plane, Point3D(0, 0, 0), factor2); double f[3] = { 0.5, 0.5, 0.5 }; rt.translate(sphere2, Vector3D(3, 0, -5)); rt.scale(sphere2, Point3D(0, 0, 0), f); rt.translate(sphere3, Vector3D(0, 2, -5)); rt.scale(sphere3, Point3D(0, 0, 0), f); double f2[3] = { 0.6, 0.6, 0.6 }; rt.translate(sphere4, Vector3D(-2, 1, -3)); rt.scale(sphere4, Point3D(0, 0, 0), f2); double fp2[3] = { 3.0, 3.0, 3.0 }; rt.translate(plane2,Vector3D(-4,1,-5)); rt.rotate(plane2, 'z', 45); rt.rotate(plane2, 'y', 45); rt.scale(plane2, Point3D(0, 0, 0), fp2); // rt.translate(plane3,Vector3D(-2,0,-5)); // rt.rotate(plane2, 'z', 45); // rt.rotate(plane3, 'x', 90); // rt.scale(plane3, Point3D(0, 0, 0), fp2); // // rt.translate(plane4,Vector3D(-2,1,-5)); // rt.rotate(plane2, 'z', 45); // rt.rotate(plane4, 'y', 90); // rt.scale(plane4, Point3D(0, 0, 0), fp2); rt.setAAMode(Raytracer::AA_SUPER_SAMPLING); rt.setShadingMode(Raytracer::SCENE_MODE_PHONG); rt.setShadows(Raytracer::SHADOW_CAST); rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX); rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT); rt.setReflDepth(4); //set the texture map for the objects of interest in the scene if texture map flag is ON if (TEXTURE_MAP_FLAG) { // load texture image TextureMap txtmp; txtmp = TextureMap(TEXTURE_IMG); TextureMap txtmp2 = TextureMap(TEXTURE_IMG2); TextureMap txtmp3 = TextureMap(TEXTURE_IMG3); //for now, we are only using texture map for sphere sphere->useTextureMapping = true; sphere->obj->setTextureMap(txtmp); sphere2->useTextureMapping = false; sphere4->useTextureMapping = true; sphere4->setTextMapOfObject(txtmp2); plane2->useTextureMapping = true; plane2->setTextMapOfObject(txtmp3); // plane3->useTextureMapping = true; // plane3->setTextMapOfObject(txtmp3); // // plane4->useTextureMapping = true; // plane4->setTextMapOfObject(txtmp3); } // refraction if it's turned on if (REFRACTION_FLAG) { rt.setRefractionMode(REFRACTION_FLAG); } if ( rt.getEnvMapMode() != Raytracer::NONE ) { // load images EnvMap env; if ( _DEBUG ) { env = EnvMap( "EnvMaps/DebugMaps/posx.bmp", "EnvMaps/DebugMaps/posy.bmp", "EnvMaps/DebugMaps/posz.bmp", "EnvMaps/DebugMaps/negx.bmp", "EnvMaps/DebugMaps/negy.bmp", "EnvMaps/DebugMaps/negz.bmp" ); } else { env = EnvMap( "EnvMaps/SaintLazarusChurch/posx.bmp", "EnvMaps/SaintLazarusChurch/posy.bmp", "EnvMaps/SaintLazarusChurch/posz.bmp", "EnvMaps/SaintLazarusChurch/negx.bmp", "EnvMaps/SaintLazarusChurch/negy.bmp", "EnvMaps/SaintLazarusChurch/negz.bmp" ); } rt.setEnvMap(env); } printf("REFRACTION SCENE : 1 :: Rendering...\n"); rt.render(width, height, eye2, view2, up, fov, "refraction_2.bmp"); Point3D eye3(0, 0, 1); Vector3D view3(0, 0, -1); printf("REFRACTION SCENE : 2 :: Rendering...\n"); rt.render(width, height, eye3, view3, up, fov, "refraction_1.bmp"); printf("REFRACTION SCENE : 1 :: Done!\n"); }