static void VbTest() { #if !defined (ACE_WIN32) Vb v1; ACE_ASSERT(v1.valid() == 0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n", v1.to_string())); // purpose of this routine?? set_exception_status( &v1, 10); Vb v2(v1); ACE_ASSERT(v2.valid() == 0); Oid o1("1.2.3"), o2; v2.set_oid(o1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n", v2.to_string())); v2.get_oid(o2); ACE_ASSERT(o2 == o1); ACE_ASSERT(v2.valid() == 0); v2.set_null(); ACE_ASSERT(v2.valid() == 0); v2.get_oid(o2); Vb v3; TimeTicks t(0), t1; v3.set_oid(o1); v3.set_value(t); ACE_ASSERT(v3.valid() == 1); v3.get_value(t1); ACE_ASSERT(t == t1); Vb v4; v4.set_oid(o1); v4.set_value(o1); ACE_ASSERT(v4.valid() == 1); v4.get_value(o2); ACE_ASSERT(o1 == o2); Vb v5; Counter32 c1(12), c2; v5.set_oid(o1); v5.set_value(c1); ACE_ASSERT(v5.valid() == 1); v5.get_value(c2); ACE_ASSERT(c1 == c2); Vb v6; Counter64 c3(12345678901234ULL), c4; v6.set_oid(o1); v6.set_value(c3); ACE_ASSERT(v6.valid() == 1); v6.get_value(c4); ACE_ASSERT(c3 == c4); Vb v7; Gauge32 g1(0123456), g2; v7.set_oid(o1); v7.set_value(g1); ACE_ASSERT(v7.valid() == 1); v7.get_value(g2); ACE_ASSERT(g1 == g2); Vb v8; SnmpInt32 i1(0123456), i2; v8.set_oid(o1); v8.set_value(i1); ACE_ASSERT(v8.valid() == 1); v8.get_value(i2); ACE_ASSERT(i1 == i2); Vb v9; SnmpUInt32 u1(0123456), u2; v9.set_oid(o1); v9.set_value(u1); ACE_ASSERT(v9.valid() == 1); v9.get_value(u2); ACE_ASSERT(u1 == u2); Vb v10; OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2; v10.set_oid(o1); v10.set_value(s1); ACE_ASSERT(v10.valid() == 1); v10.get_value(s2); ACE_ASSERT(s1 == s2); ACE_ASSERT(s1.length() == s2.length()); // test assignment over all datatypes v10 = v5; ACE_ASSERT(v10 == v5); Vb v11(o1, s1, SNMP_CLASS_SUCCESS); ACE_ASSERT(v11.valid() == 1); v11.get_oid(o2); ACE_ASSERT(o1 == o2); v11.get_value(s2); ACE_ASSERT(s1 == s2); #endif /*if ACE_WIN32*/ }
static void test() { T2 o2(1); T1 o1(o2); ++o1; // quiet gcc unused variable warning }
int main(int argc, char **args) { // Test variable. int success_test = 1; if (argc < 2) error("Not enough parameters."); // Load the mesh. Mesh mesh; H3DReader mloader; if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'.", args[1]); // Initialize the space 1. Ord3 o1(2, 2, 2); H1Space space1(&mesh, bc_types, essential_bc_values, o1); // Initialize the space 2. Ord3 o2(4, 4, 4); H1Space space2(&mesh, bc_types, essential_bc_values, o2); // Initialize the weak formulation. WeakForm wf(2); wf.add_matrix_form(0, 0, bilinear_form_1<double, scalar>, bilinear_form_1<Ord, Ord>, HERMES_SYM); wf.add_vector_form(0, linear_form_1<double, scalar>, linear_form_1<Ord, Ord>); wf.add_matrix_form(1, 1, bilinear_form_2<double, scalar>, bilinear_form_2<Ord, Ord>, HERMES_SYM); wf.add_vector_form(1, linear_form_2<double, scalar>, linear_form_2<Ord, Ord>); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, Hermes::vector<Space *>(&space1, &space2), is_linear); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Initialize the preconditioner in the case of SOLVER_AZTECOO. if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Assemble the linear problem. info("Assembling (ndof: %d).", Space::get_num_dofs(Hermes::vector<Space *>(&space1, &space2))); dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving."); Solution sln1(&mesh); Solution sln2(&mesh); if(solver->solve()) Solution::vector_to_solutions(solver->get_solution(), Hermes::vector<Space *>(&space1, &space2), Hermes::vector<Solution *>(&sln1, &sln2)); else error ("Matrix solver failed.\n"); ExactSolution ex_sln1(&mesh, exact_sln_fn_1); ExactSolution ex_sln2(&mesh, exact_sln_fn_2); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(Hermes::vector<Space *>(&space1, &space2), Hermes::vector<ProjNormType>(HERMES_H1_NORM, HERMES_H1_NORM)); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(Hermes::vector<Solution *>(&sln1, &sln2), Hermes::vector<Solution *>(&ex_sln1, &ex_sln2), solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; // Clean up. delete matrix; delete rhs; delete solver; delete adaptivity; if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
int main(int argc, char *argv[]) { /* sf::RenderWindow app(sf::VideoMode(640, 480), "ECS"); sf::RectangleShape rectangle(sf::Vector2f(50.f, 50.f)); rectangle.setFillColor(sf::Color::Blue); sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f)); rectangle2.setFillColor(sf::Color::Red); GameObject objects[2]; DescriptionSystem desc_sys; MovementSystem move_sys; RenderSystem renderer(&app); CollisionSystem collision_sys; DescriptionComponent desc(objects[0].getId()); PositionComponent pos(objects[0].getId()), pos2(objects[1].getId()); VelocityComponent vel(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f); DrawableComponent drawable(objects[0].getId()), drawable2(objects[1].getId()); CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds()); drawable.drawable = &rectangle; drawable2.drawable = &rectangle2; //pos.position.y = 50.f; pos2.position.x = 250.f; pos2.position.y = 20.f; desc_sys.registerComponent("Description"); move_sys.registerComponent("Position"); move_sys.registerComponent("Velocity"); renderer.registerComponent("Drawable"); renderer.registerComponent("Position"); collision_sys.registerComponent("Position"); collision_sys.registerComponent("Collidable"); objects[0].addComponent(&desc); objects[0].addComponent(&pos); objects[0].addComponent(&vel); objects[0].addComponent(&drawable); objects[0].addComponent(&c1); objects[1].addComponent(&vel2); objects[1].addComponent(&drawable2); objects[1].addComponent(&pos2); objects[1].addComponent(&c2); if (desc_sys.canUpdate(objects[0])) desc_sys.update(objects[0]); sf::Event event; while (app.isOpen()) { while (app.pollEvent(event)) { if (event.type == sf::Event::Closed) app.close(); } for (int i(0) ; i < 2 ; ++i) if (move_sys.canUpdate(objects[i])) move_sys.update(objects[i]); app.clear(sf::Color::White); for (int i(0) ; i < 2 ; ++i) if (collision_sys.canUpdate(objects[i])) collision_sys.update(objects[i]); for (int i(0) ; i < 2 ; ++i) if (renderer.canUpdate(objects[i])) renderer.update(objects[i]); app.display(); } */ GameWorld world; GameObject *o1(world.addObject()); GameObject *o2(world.addObject()); sf::RectangleShape rectangle1(sf::Vector2f(50.f, 50.f)); rectangle1.setFillColor(sf::Color::Blue); sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f)); rectangle2.setFillColor(sf::Color::Red); PhysicSystem *phys_sys(new PhysicSystem); phys_sys->registerComponent("Physic"); phys_sys->registerComponent("Position"); world.addSystem(phys_sys); PhysicComponent phys1(o1->getId(), 50, cpMomentForBox(50, 5, 5)), phys2(o2->getId(), 50, cpMomentForBox(50, 5, 5)); DescriptionComponent desc1(o1->getId()), desc2(o2->getId()); PositionComponent pos1(o1->getId()), pos2(o2->getId()); //VelocityComponent vel1(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f); DrawableComponent drawable1(o1->getId()), drawable2(o2->getId()); //CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds()); phys1.shape = cpBoxShapeNew(phys1.body, 50.f, 50.f); phys2.shape = cpBoxShapeNew(phys2.body, 50.f, 50.f); cpBodySetPos(phys1.body, cpv(0, 0)); cpBodySetPos(phys2.body, cpv(200, 0)); cpSpaceAddShape(phys_sys->getSpace(), phys1.shape); cpSpaceAddShape(phys_sys->getSpace(), phys2.shape); cpSpaceAddBody(phys_sys->getSpace(), phys1.body); cpSpaceAddBody(phys_sys->getSpace(), phys2.body); drawable1.drawable = &rectangle1; drawable2.drawable = &rectangle2; pos1.position.x = 50.f; pos2.position = sf::Vector2f(200.f, 150.f); o1->addComponent(&desc1); o1->addComponent(&drawable1); o1->addComponent(&pos1); o1->addComponent(&phys1); o2->addComponent(&desc2); o2->addComponent(&drawable2); o2->addComponent(&pos2); o2->addComponent(&phys2); while (true) { world.update(); } return 0; }
int main() { bi::endian_log = false; // make sure some simple things work bi::big32_t o1(1); bi::big32_t o2(2L); bi::big32_t o3(3LL); bi::big64_t o4(1); // use cases; if BOOST_ENDIAN_LOG is defined, will output to clog info on // what overloads and conversions are actually being performed. bi::endian_log = true; std::clog << "set up test values\n"; bi::big32_t big(12345); bi::ulittle16_t ulittle(10); bi::big64_t result; std::clog << "\nresult = +big\n"; result = +big; std::clog << "\nresult = -big\n"; result = -big; std::clog << "\n++big\n"; ++big; std::clog << "\nresult = big++\n"; result = big++; std::clog << "\n--big\n"; --big; std::clog << "\nbig--\n"; big--; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * ulittle\n"; result = big * ulittle; std::clog << "\nbig *= ulittle\n"; big *= ulittle; std::clog << "\nresult = ulittle * big\n"; result = ulittle * big; std::clog << "\nresult = big * 5\n"; result = big * 5; std::clog << "\nbig *= 5\n"; big *= 5; std::clog << "\nresult = 5 * big\n"; result = 5 * big; std::clog << "\nresult = ulittle * 5\n"; result = ulittle * 5; std::clog << "\nresult = 5 * ulittle\n"; result = 5 * ulittle; std::clog << "\nresult = 5 * 10\n"; result = 5 * 10; std::clog << "\n"; bi::endian_log = false; // test from Roland Schwarz that detected ambiguities unsigned u; bi::ulittle32_t u1; bi::ulittle32_t u2; u = 1; u1 = 1; u2 = u1 + u; // one more wrinkle bi::ulittle16_t u3(3); u3 = 3; u2 = u1 + u3; // perform the indicated test on ~60*60 operand types op_test<default_construct>(); op_test<construct>(); // includes copy construction op_test<initialize>(); op_test<assign>(); op_test<relational>(); op_test<op_plus>(); op_test<op_star>(); return 0; }
TEST(Optional, Comparisons) { Optional<int> o_; Optional<int> o1(1); Optional<int> o2(2); EXPECT_TRUE(o_ <= (o_)); EXPECT_TRUE(o_ == (o_)); EXPECT_TRUE(o_ >= (o_)); EXPECT_TRUE(o1 < o2); EXPECT_TRUE(o1 <= o2); EXPECT_TRUE(o1 <= (o1)); EXPECT_TRUE(o1 == (o1)); EXPECT_TRUE(o1 != o2); EXPECT_TRUE(o1 >= (o1)); EXPECT_TRUE(o2 >= o1); EXPECT_TRUE(o2 > o1); EXPECT_FALSE(o2 < o1); EXPECT_FALSE(o2 <= o1); EXPECT_FALSE(o2 <= o1); EXPECT_FALSE(o2 == o1); EXPECT_FALSE(o1 != (o1)); EXPECT_FALSE(o1 >= o2); EXPECT_FALSE(o1 >= o2); EXPECT_FALSE(o1 > o2); /* folly::Optional explicitly doesn't support comparisons with contained value EXPECT_TRUE(1 < o2); EXPECT_TRUE(1 <= o2); EXPECT_TRUE(1 <= o1); EXPECT_TRUE(1 == o1); EXPECT_TRUE(2 != o1); EXPECT_TRUE(1 >= o1); EXPECT_TRUE(2 >= o1); EXPECT_TRUE(2 > o1); EXPECT_FALSE(o2 < 1); EXPECT_FALSE(o2 <= 1); EXPECT_FALSE(o2 <= 1); EXPECT_FALSE(o2 == 1); EXPECT_FALSE(o2 != 2); EXPECT_FALSE(o1 >= 2); EXPECT_FALSE(o1 >= 2); EXPECT_FALSE(o1 > 2); */ // boost::optional does support comparison with contained value, which can // lead to confusion when a bool is contained boost::optional<int> boi(3); EXPECT_TRUE(boi < 5); EXPECT_TRUE(boi <= 4); EXPECT_TRUE(boi == 3); EXPECT_TRUE(boi != 2); EXPECT_TRUE(boi >= 1); EXPECT_TRUE(boi > 0); EXPECT_TRUE(1 < boi); EXPECT_TRUE(2 <= boi); EXPECT_TRUE(3 == boi); EXPECT_TRUE(4 != boi); EXPECT_TRUE(5 >= boi); EXPECT_TRUE(6 > boi); boost::optional<bool> bob(false); EXPECT_TRUE((bool)bob); EXPECT_TRUE(bob == false); // well that was confusing EXPECT_FALSE(bob != false); }
/* * START THE VM */ void startVM(Vm* vm) { vm->PC = 0; while (charArrayToInt(0,2,vm->IR) != 99) { nextInstruction(vm); switch (charArrayToInt(0,2,vm->IR)) { case 0: o0(vm); break; case 1: o1(vm); break; case 2: o2(vm); break; case 3: o3(vm); break; case 4: o4(vm); break; case 5: o5(vm); break; case 6: o6(vm); break; case 7: o7(vm); break; case 8: o8(vm); break; case 9: o9(vm); break; case 10: o10(vm); break; case 11: o11(vm); break; case 12: o12(vm); break; case 13: o13(vm); break; case 14: o14(vm); break; case 15: o15(vm); break; case 16: o16(vm); break; case 17: o17(vm); break; case 18: o18(vm); break; case 19: o19(vm); break; case 20: o20(vm); break; case 21: o21(vm); break; case 22: o22(vm); break; case 23: o23(vm); break; case 24: o24(vm); break; case 25: o25(vm); break; case 26: o26(vm); break; case 27: o27(vm); break; case 28: o28(vm); break; case 29: o29(vm); break; case 30: o30(vm); break; case 31: o31(vm); break; case 32: o32(vm); break; case 33: o33(vm); break; case 34: o34(vm); break; case 35: o35(vm); break; case 99: o99(vm); break; default: // Code break; } displayVmFinal(vm); } }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif if (argc < 2) error("Not enough parameters."); printf("* Loading mesh '%s'\n", args[1]); Mesh mesh1; H3DReader mesh_loader; if (!mesh_loader.load(args[1], &mesh1)) error("Loading mesh file '%s'\n", args[1]); #if defined RHS2 Ord3 order(P_INIT_X, P_INIT_Y, P_INIT_Z); printf(" - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z); // Create an H1 space with default shapeset. printf("* Setting the space up\n"); H1Space space(&mesh1, bc_types, essential_bc_values, order); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); // duplicate the mesh Mesh mesh2; mesh2.copy(mesh1); // do some changes mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ); mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ); Solution fsln(&mesh2); fsln.set_const(-6.0); #else // duplicate the mesh Mesh mesh2; mesh2.copy(mesh1); Mesh mesh3; mesh3.copy(mesh1); // change meshes mesh1.refine_all_elements(H3D_REFT_HEX_X); mesh2.refine_all_elements(H3D_REFT_HEX_Y); mesh3.refine_all_elements(H3D_REFT_HEX_Z); printf("* Setup spaces\n"); Ord3 o1(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o1.x, o1.y, o1.z); H1Space space1(&mesh1, bc_types_1, essential_bc_values_1, o1); Ord3 o2(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o2.x, o2.y, o2.z); H1Space space2(&mesh2, bc_types_2, essential_bc_values_2, o2); Ord3 o3(1, 1, 1); printf(" - Setting uniform order to (%d, %d, %d)\n", o3.x, o3.y, o3.z); H1Space space3(&mesh3, bc_types_3, essential_bc_values_3, o3); int ndofs = 0; ndofs += space1.assign_dofs(); ndofs += space2.assign_dofs(ndofs); ndofs += space3.assign_dofs(ndofs); printf(" - Number of DOFs: %d\n", ndofs); #endif #if defined WITH_UMFPACK MatrixSolverType matrix_solver = SOLVER_UMFPACK; #elif defined WITH_PARDISO MatrixSolverType matrix_solver = SOLVER_PARDISO; #elif defined WITH_PETSC MatrixSolverType matrix_solver = SOLVER_PETSC; #elif defined WITH_MUMPS MatrixSolverType matrix_solver = SOLVER_MUMPS; #endif #ifdef RHS2 WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>, HERMES_ANY, &fsln); // Initialize discrete problem. bool is_linear = true; DiscreteProblem dp(&wf, &space, is_linear); #elif defined SYS3 WeakForm wf(3); wf.add_matrix_form(0, 0, biform_1_1<double, scalar>, biform_1_1<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(0, 1, biform_1_2<double, scalar>, biform_1_2<Ord, Ord>, HERMES_NONSYM); wf.add_vector_form(0, liform_1<double, scalar>, liform_1<Ord, Ord>); wf.add_matrix_form(1, 1, biform_2_2<double, scalar>, biform_2_2<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(1, 2, biform_2_3<double, scalar>, biform_2_3<Ord, Ord>, HERMES_NONSYM); wf.add_vector_form(1, liform_2<double, scalar>, liform_2<Ord, Ord>); wf.add_matrix_form(2, 2, biform_3_3<double, scalar>, biform_3_3<Ord, Ord>, HERMES_SYM); // Initialize discrete problem. bool is_linear = true; DiscreteProblem dp(&wf, Hermes::vector<Space *>(&space1, &space2, &space3), is_linear); #endif // Time measurement. TimePeriod cpu_time; cpu_time.tick(); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Initialize the preconditioner in the case of SOLVER_AZTECOO. if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Assemble stiffness matrix and load vector. dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving the linear problem."); bool solved = solver->solve(); // Time measurement. cpu_time.tick(); // Print timing information. info("Solution and mesh with polynomial orders saved. Total running time: %g s", cpu_time.accumulated()); // Time measurement. TimePeriod sln_time; sln_time.tick(); if (solved) { #ifdef RHS2 // Solve the linear system. If successful, obtain the solution. info("Solving the linear problem."); Solution sln(&mesh1); Solution::vector_to_solution(solver->get_solution(), &space, &sln); // Set exact solution. ExactSolution ex_sln(&mesh1, exact_solution); // Norm. double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (h1_err_norm > EPS || l2_err_norm > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } #elif defined SYS3 // Solution 1. Solution sln1(&mesh1); Solution sln2(&mesh2); Solution sln3(&mesh3); Solution::vector_to_solution(solver->get_solution(), &space1, &sln1); Solution::vector_to_solution(solver->get_solution(), &space2, &sln2); Solution::vector_to_solution(solver->get_solution(), &space3, &sln3); ExactSolution esln1(&mesh1, exact_sln_fn_1); ExactSolution esln2(&mesh2, exact_sln_fn_2); ExactSolution esln3(&mesh3, exact_sln_fn_3); // Norm. double h1_err_norm1 = h1_error(&sln1, &esln1); double h1_err_norm2 = h1_error(&sln2, &esln2); double h1_err_norm3 = h1_error(&sln3, &esln3); double l2_err_norm1 = l2_error(&sln1, &esln1); double l2_err_norm2 = l2_error(&sln2, &esln2); double l2_err_norm3 = l2_error(&sln3, &esln3); printf(" - H1 error norm: % le\n", h1_err_norm1); printf(" - L2 error norm: % le\n", l2_err_norm1); if (h1_err_norm1 > EPS || l2_err_norm1 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } printf(" - H1 error norm: % le\n", h1_err_norm2); printf(" - L2 error norm: % le\n", l2_err_norm2); if (h1_err_norm2 > EPS || l2_err_norm2 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } printf(" - H1 error norm: % le\n", h1_err_norm3); printf(" - L2 error norm: % le\n", l2_err_norm3); if (h1_err_norm3 > EPS || l2_err_norm3 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } #endif #ifdef RHS2 out_fn_vtk(&sln, "solution"); #elif defined SYS3 out_fn_vtk(&sln1, "sln1"); out_fn_vtk(&sln2, "sln2"); out_fn_vtk(&sln3, "sln3"); #endif } else res = ERR_FAILURE; // Print timing information. info("Solution and mesh with polynomial orders saved. Total running time: %g s", sln_time.accumulated()); // Clean up. delete matrix; delete rhs; delete solver; return res; }
/** @test cover the basic situations of object handling, * especially copy operations and re-assignments */ void checkHandling (TestList& objs) { Opaque oo; CHECK (!oo); CHECK (isnil(oo)); oo = objs[1]; CHECK (oo); CHECK (!isnil(oo)); typedef DD<3> D3; typedef DD<5> D5; D3 d3 (oo.get<D3>() ); CHECK (3 == oo->getIt()); // re-access through Base interface CHECK (!isSameObject (d3, *oo)); VERIFY_ERROR (WRONG_TYPE, oo.get<D5>() ); // direct assignment of target into Buffer oo = D5(); CHECK (oo); CHECK (5 == oo->getIt()); VERIFY_ERROR (WRONG_TYPE, oo.get<D3>() ); // can get a direct reference to contained object D5 &rd5 (oo.get<D5>()); CHECK (isSameObject (rd5, *oo)); CHECK (!isnil(oo)); oo = objs[3]; // copy construction also works on non-empty object CHECK (7 == oo->getIt()); // WARNING: direct ref has been messed up through the backdoor! CHECK (7 == rd5.getIt()); CHECK (isSameObject (rd5, *oo)); uint cnt_before = _create_count; oo.clear(); CHECK (!oo); oo = D5(); // direct assignment also works on empty object CHECK (oo); CHECK (5 == oo->getIt()); CHECK (_create_count == 2 + cnt_before); // one within buff and one for the anonymous temporary D5() // verify that self-assignment is properly detected... cnt_before = _create_count; oo = oo; CHECK (oo); CHECK (_create_count == cnt_before); oo = oo.get<D5>(); CHECK (_create_count == cnt_before); oo = *oo; CHECK (_create_count == cnt_before); CHECK (oo); oo.clear(); CHECK (!oo); CHECK (isnil(oo)); VERIFY_ERROR (BOTTOM_VALUE, oo.get<D5>() ); #if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT VERIFY_ERROR (ASSERTION, oo->getIt() ); #endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT // can't access empty holder... Opaque o1 (oo); CHECK (!o1); Opaque o2 (d3); CHECK (!isSameObject (d3, *o2)); CHECK (3 == o2->getIt()); CHECK (sizeof(Opaque) <= sizeof(Base) + sizeof(void*) + _ALIGN_); }
void RenderJointsDebugInfo (NewtonWorld* const world, dFloat size) { glDisable(GL_TEXTURE_2D); glDisable (GL_LIGHTING); glBegin(GL_LINES); // this will go over the joint list twice, for (NewtonBody* body = NewtonWorldGetFirstBody(world); body; body = NewtonWorldGetNextBody(world, body)) { for (NewtonJoint* joint = NewtonBodyGetFirstJoint(body); joint; joint = NewtonBodyGetNextJoint(body, joint)) { NewtonJointRecord info; NewtonJointGetInfo (joint, &info); if (strcmp (info.m_descriptionType, "customJointNotInfo")) { // draw first frame dMatrix matrix0; NewtonBodyGetMatrix (info.m_attachBody_0, &matrix0[0][0]); matrix0 = dMatrix (&info.m_attachmenMatrix_0[0][0]) * matrix0; dVector o0 (matrix0.m_posit); dVector x (o0 + matrix0.RotateVector (dVector (size, 0.0f, 0.0f, 0.0f))); glColor3f (1.0f, 0.0f, 0.0f); glVertex3f (o0.m_x, o0.m_y, o0.m_z); glVertex3f (x.m_x, x.m_y, x.m_z); dVector y (o0 + matrix0.RotateVector (dVector (0.0f, size, 0.0f, 0.0f))); glColor3f (0.0f, 1.0f, 0.0f); glVertex3f (o0.m_x, o0.m_y, o0.m_z); glVertex3f (y.m_x, y.m_y, y.m_z); dVector z (o0 + matrix0.RotateVector (dVector (0.0f, 0.0f, size, 0.0f))); glColor3f (0.0f, 0.0f, 1.0f); glVertex3f (o0.m_x, o0.m_y, o0.m_z); glVertex3f (z.m_x, z.m_y, z.m_z); // draw second frame dMatrix matrix1 (dGetIdentityMatrix()); if (info.m_attachBody_1) { NewtonBodyGetMatrix (info.m_attachBody_1, &matrix1[0][0]); } matrix1 = dMatrix (&info.m_attachmenMatrix_1[0][0]) * matrix1; dVector o1 (matrix1.m_posit); x = o1 + matrix1.RotateVector (dVector (size, 0.0f, 0.0f, 0.0f)); glColor3f (1.0f, 0.0f, 0.0f); glVertex3f (o1.m_x, o1.m_y, o1.m_z); glVertex3f (x.m_x, x.m_y, x.m_z); y = o1 + matrix1.RotateVector (dVector (0.0f, size, 0.0f, 0.0f)); glColor3f (0.0f, 1.0f, 0.0f); glVertex3f (o1.m_x, o1.m_y, o1.m_z); glVertex3f (y.m_x, y.m_y, y.m_z); z = o1 + matrix1.RotateVector (dVector (0.0f, 0.0f, size, 0.0f)); glColor3f (0.0f, 0.0f, 1.0f); glVertex3f (o1.m_x, o1.m_y, o1.m_z); glVertex3f (z.m_x, z.m_y, z.m_z); if (!strcmp (info.m_descriptionType, "limitballsocket")) { // draw the cone limit of this joint int steps = 12; dMatrix coneMatrix (dRollMatrix(info.m_maxAngularDof[1])); dMatrix ratationStep (dPitchMatrix(2.0f * 3.14151693f / steps)); dVector p0 (coneMatrix.RotateVector(dVector (size * 0.5f, 0.0f, 0.0f, 0.0f))); dVector q0 (matrix1.TransformVector(p0)); glColor3f (1.0f, 1.0f, 0.0f); for (int i = 0; i < (steps + 1); i ++) { dVector p1 (ratationStep.RotateVector(p0)); dVector q1 (matrix1.TransformVector(p1)); glVertex3f (o0.m_x, o0.m_y, o0.m_z); glVertex3f (q0.m_x, q0.m_y, q0.m_z); glVertex3f (q0.m_x, q0.m_y, q0.m_z); glVertex3f (q1.m_x, q1.m_y, q1.m_z); p0 = p1; q0 = q1; } } } } } glEnd(); }
void bv_refinementt::check_SAT(approximationt &a) { // get values get_values(a); // see if the satisfying assignment is spurious in any way const typet &type=ns.follow(a.expr.type()); if(type.id()==ID_floatbv) { // these are all trinary assert(a.expr.operands().size()==3); if(a.over_state==MAX_STATE) return; ieee_float_spect spec(to_floatbv_type(type)); ieee_floatt o0(spec), o1(spec); o0.unpack(a.op0_value); o1.unpack(a.op1_value); ieee_floatt result=o0; o0.rounding_mode=RM; o1.rounding_mode=RM; result.rounding_mode=RM; if(a.expr.id()==ID_floatbv_plus) result+=o1; else if(a.expr.id()==ID_floatbv_minus) result-=o1; else if(a.expr.id()==ID_floatbv_mult) result*=o1; else if(a.expr.id()==ID_floatbv_div) result/=o1; else assert(false); if(result.pack()==a.result_value) // ok return; #ifdef DEBUG ieee_floatt rr(spec); rr.unpack(a.result_value); std::cout << "S1: " << o0 << " " << a.expr.id() << " " << o1 << " != " << rr << std::endl; std::cout << "S2: " << integer2binary(a.op0_value, spec.width()) << " " << a.expr.id() << " " << integer2binary(a.op1_value, spec.width()) << "!=" << integer2binary(a.result_value, spec.width()) << std::endl; std::cout << "S3: " << integer2binary(a.op0_value, spec.width()) << " " << a.expr.id() << " " << integer2binary(a.op1_value, spec.width()) << "==" << integer2binary(result.pack(), spec.width()) << std::endl; #endif //if(a.over_state==1) { std::cout << "DISAGREEMENT!\n"; exit(1); } if(a.over_state<max_node_refinement) { bvt r; float_utilst float_utils(prop); float_utils.spec=spec; float_utils.rounding_mode_bits.set(RM); literalt op0_equal= bv_utils.equal(a.op0_bv, float_utils.build_constant(o0)); literalt op1_equal= bv_utils.equal(a.op1_bv, float_utils.build_constant(o1)); literalt result_equal= bv_utils.equal(a.result_bv, float_utils.build_constant(result)); literalt op0_and_op1_equal= prop.land(op0_equal, op1_equal); prop.l_set_to_true( prop.limplies(op0_and_op1_equal, result_equal)); } else { // give up // remove any previous over-approximation a.over_assumptions.clear(); a.over_state=MAX_STATE; bvt r; float_utilst float_utils(prop); float_utils.spec=spec; float_utils.rounding_mode_bits.set(RM); bvt op0=a.op0_bv, op1=a.op1_bv, res=a.result_bv; if(a.expr.id()==ID_floatbv_plus) r=float_utils.add(op0, op1); else if(a.expr.id()==ID_floatbv_minus) r=float_utils.sub(op0, op1); else if(a.expr.id()==ID_floatbv_mult) r=float_utils.mul(op0, op1); else if(a.expr.id()==ID_floatbv_div) r=float_utils.div(op0, op1); else assert(0); assert(r.size()==res.size()); bv_utils.set_equal(r, res); } } else if(type.id()==ID_signedbv || type.id()==ID_unsignedbv) { // these are all binary assert(a.expr.operands().size()==2); // already full interpretation? if(a.over_state>0) return; bv_spect spec(type); bv_arithmetict o0(spec), o1(spec); o0.unpack(a.op0_value); o1.unpack(a.op1_value); // division by zero is never spurious if((a.expr.id()==ID_div || a.expr.id()==ID_mod) && o1==0) return; if(a.expr.id()==ID_mult) o0*=o1; else if(a.expr.id()==ID_div) o0/=o1; else if(a.expr.id()==ID_mod) o0%=o1; else assert(false); if(o0.pack()==a.result_value) // ok return; if(a.over_state==0) { // we give up right away and add the full interpretation bvt r; if(a.expr.id()==ID_mult) { r=bv_utils.multiplier( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else if(a.expr.id()==ID_div) { r=bv_utils.divider( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else if(a.expr.id()==ID_mod) { r=bv_utils.remainder( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else assert(0); bv_utils.set_equal(r, a.result_bv); } else assert(0); } else assert(0); status() << "Found spurious `" << a.as_string() << "' (state " << a.over_state << ")" << eom; progress=true; if(a.over_state<MAX_STATE) a.over_state++; }
int main(int argc, const char* argv[]) { try { //init park Park disneyWorld("Disney World",10,15,100); //init operators Operator o1(Person("Keren", 19, 1.85)); Operator o2(Person("Daniel", 21, 1.75)); Operator o3(Person("Amir", 26, 1.60)); Operator o4(Person("Eytan", 28, 1.80)); disneyWorld += o1; disneyWorld += o2; disneyWorld += o3; disneyWorld += o4; //init facilities bool ageTypes[] = {true, true, false}; WaterSlide waterSlide(Facility("KAMIKAZA", 2 , ageTypes, &o1), 800); ageTypes[2] = true; RollerCoaster rollerCoasterA(Facility("BALERINE", 30, ageTypes, &o2), 4, 0); ageTypes[0] = false; RollerCoaster rollerCoasterB(Facility("ANACONDA", 16, ageTypes, &o3), 30, 2); ageTypes[2] = false; Facility f("HYDRA", 12, ageTypes, &o4); WaterRollerCoaster waterRollerCoaster(WaterSlide(f,1000), RollerCoaster(f, 40, 7)); disneyWorld += waterSlide; disneyWorld += rollerCoasterA; disneyWorld += rollerCoasterB; disneyWorld += waterRollerCoaster; //create persons to enter park Person p1("Adam",13,1.25); Person p2("Adir", 21, 1.55); Person p3("Adi", 27, 1.68); Person p4("Adva", 72, 1.45); Guest& g1 = disneyWorld.buyTicket(p1, Guest::CHILD, Guest::THRILLED,"09/09/2015"); Guest& g2 = disneyWorld.buyTicket(p2, Guest::ADULT, Guest::HAPPY,"09/09/2015" ,true); Guest& g3 = disneyWorld.buyTicket(p3, Guest::ADULT, Guest::HAPPY,"08/09/2015"); Guest& g4 = disneyWorld.buyTicket(p4, Guest::CHILD, Guest::AFRAID,"05/09/2015"); //add guest to facility waterSlide += g1; waterSlide += g2; waterSlide.start(); //start() should remove all guests waterSlide += g3; waterSlide += g4; waterSlide.start(); rollerCoasterA += g1; rollerCoasterA += g2; rollerCoasterA += g3; rollerCoasterA += g4; waterRollerCoaster += g1; waterRollerCoaster += g2; waterRollerCoaster += g3; waterRollerCoaster += g4; cout << disneyWorld << endl; rollerCoasterA.start(); waterRollerCoaster.start(); cout << disneyWorld << endl; } catch(const char* msg) { cout << "Problem occured..." << endl; cout << msg << endl; cout << "Finishing.." << endl; } }
int main(int argc, char** argv) { int ppw=10; // Point per wavelength std::string file="/home/tbetcke/svn/numerical_coercivity/data/trapping"; int numrange_n=50; // Number of discretization points for num. range. int computenorm=0; // Set to 1 to compute norm and condition number std::vector<double> freqs; freqs.push_back(8); //freqs.push_back(10); //freqs.push_back(50); //freqs.push_back(100); //freqs.push_back(200); //freqs.push_back(500); clock_t start, finish; double time; start=clock(); double a=0.31; double c=1; double l=c-a; std::vector<bem2d::Point> trapping; trapping.push_back(bem2d::Point(0,0)); trapping.push_back(bem2d::Point(-c,0)); trapping.push_back(bem2d::Point(-c,-l)); trapping.push_back(bem2d::Point(l,-l)); trapping.push_back(bem2d::Point(l,2*c-l)); trapping.push_back(bem2d::Point(-c,2*c-l)); trapping.push_back(bem2d::Point(-c,2*a)); trapping.push_back(bem2d::Point(0,2*a)); #ifdef BEM2DMPI MPI_Init(&argc, &argv); int nprow=2; // Number of rows in process grid int npcol=1; // Number of columns in process grid int mb=24; // Row Block size int nb=24; // Column Block size bem2d::BlacsSystem* b=bem2d::BlacsSystem::Initialize(nprow,npcol,mb,nb); // Exit if Context could not be created or process does not belong to context if (!b) { std::cout << "Could not create Blacs context" << std::endl; MPI_Finalize(); exit(1); } if ((b->get_myrow()==-1)&&(b->get_mycol()==-1)) { MPI_Finalize(); exit(0); } #endif for (int j=0;j<freqs.size();j++){ bem2d::freqtype k={(double)freqs[j],0}; double eta1=k.re; // Coupling between conj. double and single layer pot. bem2d::Polygon poly(trapping,ppw,k,10,0.15); bem2d::pGeometry pgeom=poly.GetGeometry(); bem2d::WriteDomain("/home/svn/numerical_coercivity/data/trapping_shape",pgeom,5); bem2d::PolBasis::AddBasis(2,pgeom); // Add constant basis functions // Discretize the single and double layer potential bem2d::SingleLayer sl(k); bem2d::ConjDoubleLayer cdl(k); bem2d::QuadOption quadopts; quadopts.L=3; quadopts.N=5; quadopts.sigma=0.15; #ifdef BEM2DMPI if (b->IsRoot()){ std::cout << "Discretize Kernels with n=" << pgeom->size() << std::endl; } #else std::cout << "Discretize Kernels with n=" << pgeom->size() << std::endl; #endif bem2d::Matrix dsl=*(DiscreteKernel(*pgeom,quadopts,sl)); bem2d::Matrix dcdl=*(DiscreteKernel(*pgeom,quadopts,cdl)); bem2d::Matrix Id=*(EvalIdent(*pgeom, quadopts)); bem2d::Matrix combined1=Id+2.0*dcdl-bem2d::complex(0,2.0)*eta1*dsl; combined1=bem2d::ChangeBasis(combined1,Id); #ifdef BEM2DMPI if (b->IsRoot()){ std::cout << "Compute Eigenvalues and norm" << std::endl; } #else std::cout << "Compute Eigenvalues and norm" << std::endl; #endif double norm; double cond; bem2d::pcvector eigvals; bem2d::Eigenvalues(combined1,eigvals); if (computenorm){ bem2d::L2NormCond(combined1,norm,cond); // Write out norm and condition number #ifdef BEM2DMPI if (b->IsRoot()){ #endif std::ostringstream osnormcond; osnormcond << file << "_normcond_" << k.re; std::string s0=osnormcond.str(); std::ofstream o(s0.c_str()); o << norm << std::endl << cond << std::endl; o.close(); #ifdef BEM2DMPI } #endif } // Write out eigenvalues #ifdef BEM2DMPI if (b->IsRoot()){ #endif std::ostringstream os; os << file << "_eig_" << k.re; std::string s=os.str(); std::ofstream o1(s.c_str()); for (int i=0;i<eigvals->size();i++) o1 << std::real((*eigvals)[i]) << " " << std::imag((*eigvals)[i]) << std::endl; o1.close(); #ifdef BEM2DMPI } #endif #ifdef BEM2DMPI if (b->IsRoot()){ std::cout << "Compute Numerical Range" << std::endl; } #else std::cout << "Compute Numerical Range" << std::endl; #endif std::ostringstream os2; os2 << file << "_range_" << k.re; NumRange(combined1, numrange_n, os2.str()); } finish=clock(); time=(double(finish)-double(start))/CLOCKS_PER_SEC/60; #ifdef BEM2DMPI bem2d::BlacsSystem::Release(); MPI_Finalize(); #endif }
bool LevelWorkerFlowers::AddFeature(Level* pLevel) { PSolidComponent pScene = pLevel->GetScene(); SolidComposite* pComp = dynamic_cast<SolidComposite*>(pScene.GetPtr()); if (!pComp) { ReportError("No scene set for level ?"); return false; } for (int i = 0; i < m_numBunches; i++) { RCPtr<SolidComposite> pBunch = new SolidComposite; // Get a random position for this bunch. Orientation o; // DON'T use the CubeMap. // Reduce area by radius, so we don't try to plant flowers in the air! if (!GetOrientation(pLevel->GetPlayAreaSize() - (int)m_radius, &o)) { Assert(0); return false; // play area too small } for (int j = 0; j < m_numFlowers; j++) { PSolidComponent pSolid = SolidComponent::LoadSolid(m_flowerSolidName); Assert(pSolid.GetPtr()); // checked in Load(). Orientation o1(o); o1.SetX(o1.GetX() + (Rnd() - 0.5f) * m_radius); o1.SetZ(o1.GetZ() + (Rnd() - 0.5f) * m_radius); // Get height of ground // Make a bounding sphere at the (x, z) coord of the flower. // The y-coord/radius will have to be a guess which will ensure the // sphere will enclose the ground poly at (x, z). // Get a HeightServer containing the height polys which intersect // the sphere, then get the height. float y = 0; float r = 10.0f; // TODO CONFIG BoundingSphere bs(Vec3f(o1.GetX(), y, o1.GetZ()), r); HeightServer hs; pLevel->GetHeightServer(&hs, bs); if (!hs.GetHeight(o1.GetX(), o1.GetZ(), &y)) { // Sphere not big enough, terrain not built, etc. Assert(0); return false; } o1.SetY(y); // Rotate a bit o1.SetYRot((float)j * 10.0f); // TODO CONFIG pSolid->SetOrientation(o1); /* Matrix m; m.SetIdentity(); o1.TransformMatrix(&m); pSolid->StoreHeights(m); */ pBunch->AddComponent(pSolid); } pComp->AddComponent(pBunch.GetPtr()); } return true; }
PView *GMSH_ParticlesPlugin::execute(PView *v) { double A2 = ParticlesOptions_Number[11].def; double A1 = ParticlesOptions_Number[12].def; double A0 = ParticlesOptions_Number[13].def; double DT = ParticlesOptions_Number[14].def; int maxIter = (int)ParticlesOptions_Number[15].def; int timeStep = (int)ParticlesOptions_Number[16].def; int iView = (int)ParticlesOptions_Number[17].def; PView *v1 = getView(iView, v); if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); // sanity checks if(timeStep > data1->getNumTimeSteps() - 1){ Msg::Error("Invalid time step (%d) in view[%d]: using 0", v1->getIndex()); timeStep = 0; } OctreePost o1(v1); PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); // solve 'A2 d^2x/dt^2 + A1 dx/dt + A0 x = F' using a Newmark scheme: // // (A2 + gamma DT A1 + beta DT^2 A0) x^{n+1} = // (2 A2 - (1 - 2 gamma) DT A1 - (0.5 + gamma - 2 beta) DT^2 A0) x^n + // (-A2 - (gamma - 1) DT A1 - (0.5 - gamma + beta) DT^2 A0) x^{n-1} + // DT^2 (beta b^{n+1} + (0.5 + gamma - 2 beta) b^n + (0.5 - gamma + beta) b^{n-1}) // // coefs for constant acceleration (unconditinonally stable) const double gamma = 0.5, beta = 0.25; double c1 = (A2 + gamma * DT * A1 + beta * DT * DT * A0); double c2 = (2 * A2 - (1 - 2 * gamma) * DT * A1 - (0.5 + gamma - 2 * beta) * DT * DT * A0); double c3 = (-A2 - (gamma - 1) * DT * A1 - (0.5 - gamma + beta) * DT * DT * A0); double c4 = DT * DT * (beta + (0.5 + gamma - 2 * beta) + (0.5 - gamma + beta)); for(int i = 0; i < getNbU(); ++i){ for(int j = 0; j < getNbV(); ++j){ double XINIT[3], X0[3], X1[3]; getPoint(i, j, XINIT); getPoint(i, j, X0); getPoint(i, j, X1); data2->NbVP++; data2->VP.push_back(XINIT[0]); data2->VP.push_back(XINIT[1]); data2->VP.push_back(XINIT[2]); for(int iter = 0; iter < maxIter; iter++){ double F[3], X[3]; o1.searchVector(X1[0], X1[1], X1[2], F, timeStep); for(int k = 0; k < 3; k++) X[k] = (c2 * X1[k] + c3 * X0[k] + c4 * F[k]) / c1; data2->VP.push_back(X[0] - XINIT[0]); data2->VP.push_back(X[1] - XINIT[1]); data2->VP.push_back(X[2] - XINIT[2]); for(int k = 0; k < 3; k++){ X0[k] = X1[k]; X1[k] = X[k]; } } } } v2->getOptions()->vectorType = PViewOptions::Displacement; data2->setName(data1->getName() + "_Particles"); data2->setFileName(data1->getName() + "_Particles.pos"); data2->finalize(); return v2; }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); if (argc < 2) error("Not enough parameters"); H1ShapesetLobattoHex shapeset; printf("* Loading mesh '%s'\n", args[1]); Mesh mesh; H3DReader mesh_loader; if (!mesh_loader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]); printf("* Setup space #1\n"); Ord3 o1(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o1.x, o1.y, o1.z); H1Space space1(&mesh, bc_types, essential_bc_values, o1); printf("* Setup space #2\n"); Ord3 o2(4, 4, 4); H1Space space2(&mesh, bc_types, essential_bc_values, o2); printf(" - Setting uniform order to (%d, %d, %d)\n", o2.x, o2.y, o2.z); int ndofs = 0; ndofs += space1.assign_dofs(); ndofs += space2.assign_dofs(ndofs); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf(2); wf.add_matrix_form(0, 0, bilinear_form_1<double, scalar>, bilinear_form_1<Ord, Ord>, SYM); wf.add_vector_form(0, linear_form_1<double, scalar>, linear_form_1<Ord, Ord>); wf.add_matrix_form(1, 1, bilinear_form_2<double, scalar>, bilinear_form_2<Ord, Ord>, SYM); wf.add_vector_form(1, linear_form_2<double, scalar>, linear_form_2<Ord, Ord>); DiscreteProblem lp(&wf, Tuple<Space *>(&space1, &space2), true); // assemble stiffness matrix Timer assemble_timer("Assembling stiffness matrix"); assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); // solve the stiffness matrix Timer solve_timer("Solving stiffness matrix"); solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); // output the measured values printf("%s: %s (%lf secs)\n", assemble_timer.get_name(), assemble_timer.get_human_time(), assemble_timer.get_seconds()); printf("%s: %s (%lf secs)\n", solve_timer.get_name(), solve_timer.get_human_time(), solve_timer.get_seconds()); if (solved) { // solution 1 Solution sln1(&mesh); sln1.set_coeff_vector(&space1, solver.get_solution()); ExactSolution esln1(&mesh, exact_sln_fn_1); // norm double h1_sln_norm1 = h1_norm(&sln1); double h1_err_norm1 = h1_error(&sln1, &esln1); printf(" - H1 solution norm: % le\n", h1_sln_norm1); printf(" - H1 error norm: % le\n", h1_err_norm1); double l2_sln_norm1 = l2_norm(&sln1); double l2_err_norm1 = l2_error(&sln1, &esln1); printf(" - L2 solution norm: % le\n", l2_sln_norm1); printf(" - L2 error norm: % le\n", l2_err_norm1); if (h1_err_norm1 > EPS || l2_err_norm1 > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } // solution 2 Solution sln2(&mesh); sln2.set_coeff_vector(&space2, solver.get_solution()); ExactSolution esln2(&mesh, exact_sln_fn_2); // norm double h1_sln_norm2 = h1_norm(&sln2); double h1_err_norm2 = h1_error(&sln2, &esln2); printf(" - H1 solution norm: % le\n", h1_sln_norm2); printf(" - H1 error norm: % le\n", h1_err_norm2); double l2_sln_norm2 = l2_norm(&sln2); double l2_err_norm2 = l2_error(&sln2, &esln2); printf(" - L2 solution norm: % le\n", l2_sln_norm2); printf(" - L2 error norm: % le\n", l2_err_norm2); if (h1_err_norm2 > EPS || l2_err_norm2 > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #ifdef OUTPUT_DIR // output const char *of_name = OUTPUT_DIR "/solution.pos"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { GmshOutputEngine output(ofile); output.out(&sln1, "Uh_1"); output.out(&esln1, "U1"); output.out(&sln2, "Uh_2"); output.out(&esln2, "U2"); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif TRACE_END; return res; }