Example #1
0
void ObjectTransactiontestUnit::test_foreign()
{
  matador::object_store store;
  store.attach<child>("child");
  store.attach<master>("master");

  auto ch1 = store.insert(new child("child 1"));
  auto m1 = store.insert(new master("m1"));
  m1->children = ch1;

  matador::transaction tr(store);

  try {
    tr.begin();

    matador::object_view<master> mview(store);

    m1 = mview.front();

    UNIT_ASSERT_TRUE(m1.ptr() != nullptr, "master must be valid");
    UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr, "child must be valid");
    UNIT_ASSERT_EQUAL(m1->name, "m1", "name must be valid");

    UNIT_ASSERT_TRUE(store.is_removable(m1), "m1 must be removable");

    store.remove(m1);

    UNIT_ASSERT_TRUE(mview.empty(), "view must be empty");

    tr.commit();
  } catch (std::exception &) {
    tr.rollback();
  }
}
Example #2
0
int main(int argc, char* argv[])
{
  // Instantiate a class with global functions.
  Hermes2D hermes2d;

  // Load the mesh.
  Mesh mesh;
  H2DReader mloader;
  mloader.load(mesh_file, &mesh);

  // Perform initial mesh refinements (optional).
  for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();

  MeshView mview("Nurbs", new WinGeom(0, 0, 350, 350));
  mview.show(&mesh);
	
  // Wait for the view to be closed.
  View::wait();
  return 0;
}
Example #3
0
int main(int argc, char* argv[])
{
  // load the mesh file
  Mesh mesh;
  mesh.load("domain.mesh");

  // perform some sample initial refinements
  mesh.refine_all_elements();          // Refines all elements.
  mesh.refine_towards_vertex(3, 4);    // Refines mesh towards vertex #3 (4x).
  mesh.refine_towards_boundary(2, 4);  // Refines all elements along boundary 2 (4x).
  mesh.refine_element(86, 0);          // Refines element #86 isotropically.
  mesh.refine_element(112, 0);         // Refines element #112 isotropically.
  mesh.refine_element(84, 2);          // Refines element #84 anisotropically.
  mesh.refine_element(114, 1);         // Refines element #114 anisotropically.

  // display the mesh
  MeshView mview("Hello world!", 100, 100, 500, 500);  // (100, 100) is the upper left corner position
  mview.show(&mesh);                                   // 500 x 500 is the window size

  // practice some keyboard and mouse controls
  printf("Click into the image window and:\n");
  printf("  press 'm' to show element numbers,\n");
  printf("  press 'b' to toggle boundary markers,\n");
  printf("  enlarge your window and press 'c' to center the mesh,\n");
  printf("  zoom into the mesh using the right mouse button\n");
  printf("  and move the mesh around using the left mouse button\n");
  printf("    -- in this way you can read the numbers of all elements,\n");
  printf("  press 'c' to center the mesh again,\n");
  printf("  press 'm' to hide element numbers,\n");
  printf("  press 's' to save a screenshot in bmp format\n");
  printf("    -- the bmp file can be converted to any standard\n");
  printf("    image format using the command \"convert\",\n");
  printf("  press 'q' to quit.\n");

  // wait for keyboard or mouse input
  printf("Waiting for keyboard or mouse input.\n");
  View::wait();
  return 0;
}
Example #4
0
int main (int argc, char* argv[]) {
  // load the mesh file
  Mesh Cmesh, phimesh, basemesh;

  H2DReader mloader;

#ifdef CIRCULAR
  mloader.load("../circular.mesh", &basemesh);
  basemesh.refine_all_elements(0);
  basemesh.refine_towards_boundary(TOP_MARKER, 2);
  basemesh.refine_towards_boundary(BOT_MARKER, 4);
  MeshView mview("Mesh", 0, 600, 400, 400);
  mview.show(&basemesh);
#else
  mloader.load("../small.mesh", &basemesh);
  basemesh.refine_all_elements(1);
  //basemesh.refine_all_elements(1); // when only p-adapt is used
  //basemesh.refine_all_elements(1); // when only p-adapt is used
  basemesh.refine_towards_boundary(TOP_MARKER, REF_INIT);
  //basemesh.refine_towards_boundary(BOT_MARKER, (REF_INIT - 1) + 8); // when only p-adapt is used
  basemesh.refine_towards_boundary(BOT_MARKER, REF_INIT - 1);
#endif

  Cmesh.copy(&basemesh);
  phimesh.copy(&basemesh);

  // Spaces for concentration and the voltage
  H1Space Cspace(&Cmesh, C_bc_types, C_essential_bc_values, P_INIT);
  H1Space phispace(MULTIMESH ? &phimesh : &Cmesh, phi_bc_types, phi_essential_bc_values, P_INIT);

  // The weak form for 2 equations
  WeakForm wf(2);

  Solution C_prev_time,    // prveious time step solution, for the time integration
    C_prev_newton,   // solution convergin during the Newton's iteration
    phi_prev_time,
    phi_prev_newton;

  // Add the bilinear and linear forms
  // generally, the equation system is described:
  if (TIME_DISCR == 1) {  // Implicit Euler.
    wf.add_vector_form(0, callback(Fc_euler), H2D_ANY,
		  Tuple<MeshFunction*>(&C_prev_time, &C_prev_newton, &phi_prev_newton));
    wf.add_vector_form(1, callback(Fphi_euler), H2D_ANY, Tuple<MeshFunction*>(&C_prev_newton, &phi_prev_newton));
    wf.add_matrix_form(0, 0, callback(J_euler_DFcDYc), H2D_UNSYM, H2D_ANY, &phi_prev_newton);
    wf.add_matrix_form(0, 1, callback(J_euler_DFcDYphi), H2D_UNSYM, H2D_ANY, &C_prev_newton);
    wf.add_matrix_form(1, 0, callback(J_euler_DFphiDYc), H2D_UNSYM);
    wf.add_matrix_form(1, 1, callback(J_euler_DFphiDYphi), H2D_UNSYM);
  } else {
    wf.add_vector_form(0, callback(Fc_cranic), H2D_ANY, 
		  Tuple<MeshFunction*>(&C_prev_time, &C_prev_newton, &phi_prev_newton, &phi_prev_time));
    wf.add_vector_form(1, callback(Fphi_cranic), H2D_ANY, Tuple<MeshFunction*>(&C_prev_newton, &phi_prev_newton));
    wf.add_matrix_form(0, 0, callback(J_cranic_DFcDYc), H2D_UNSYM, H2D_ANY, Tuple<MeshFunction*>(&phi_prev_newton, &phi_prev_time));
    wf.add_matrix_form(0, 1, callback(J_cranic_DFcDYphi), H2D_UNSYM, H2D_ANY, Tuple<MeshFunction*>(&C_prev_newton, &C_prev_time));
    wf.add_matrix_form(1, 0, callback(J_cranic_DFphiDYc), H2D_UNSYM);
    wf.add_matrix_form(1, 1, callback(J_cranic_DFphiDYphi), H2D_UNSYM);
  }

  // Nonlinear solver
  NonlinSystem nls(&wf, Tuple<Space*>(&Cspace, &phispace));

  phi_prev_time.set_exact(MULTIMESH ? &phimesh : &Cmesh, voltage_ic);
  C_prev_time.set_exact(&Cmesh, concentration_ic);

  C_prev_newton.copy(&C_prev_time);
  phi_prev_newton.copy(&phi_prev_time);

  // Project the function init_cond() on the FE space
  // to obtain initial coefficient vector for the Newton's method.
  info("Projecting initial conditions to obtain initial vector for the Newton'w method.");
  nls.project_global(Tuple<MeshFunction*>(&C_prev_time, &phi_prev_time), 
      Tuple<Solution*>(&C_prev_newton, &phi_prev_newton));
  
  
  //VectorView vview("electric field [V/m]", 0, 0, 600, 600);
  ScalarView Cview("Concentration [mol/m3]", 0, 0, 800, 800);
  ScalarView phiview("Voltage [V]", 650, 0, 600, 600);
  phiview.show(&phi_prev_time);
  Cview.show(&C_prev_time);
  char title[100];

  int nstep = (int) (T_FINAL / TAU + 0.5);
  for (int n = 1; n <= nstep; n++) {
    verbose("\n---- Time step %d ----", n);
    bool verbose = true; // Default is false.
    if (!nls.solve_newton(Tuple<Solution*>(&C_prev_newton, &phi_prev_newton),
        NEWTON_TOL, NEWTON_MAX_ITER, verbose)) 
          error("Newton's method did not converge.");
    sprintf(title, "time step = %i", n);
    phiview.set_title(title);
    phiview.show(&phi_prev_newton);
    Cview.set_title(title);
    Cview.show(&C_prev_newton);
    phi_prev_time.copy(&phi_prev_newton);
    C_prev_time.copy(&C_prev_newton);
  }
  View::wait();

  return 0;
}
Example #5
0
int main(int argc, char* argv[])
{
    // Load the mesh.
    Hermes::Hermes2D::Mesh mesh;
    Hermes::Hermes2D::H2DReader mloader;
    mloader.load("domain.mesh", &mesh);

    // Perform initial mesh refinements (optional).
    int refinement_type = 2;            // Split elements vertically.
    for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(refinement_type);

    // Show the mesh.
    Hermes::Hermes2D::Views::MeshView mview("Mesh", new Hermes::Hermes2D::Views::WinGeom(0, 0, 900, 250));
    if (HERMES_VISUALIZATION) {
        mview.show(&mesh);
        //mview.wait();
    }

    // Initialize the weak formulation.
    CustomWeakFormPoisson wf("Al", new Hermes::Hermes1DFunction<double>(LAMBDA_AL), "Cu",
                             new Hermes::Hermes1DFunction<double>(LAMBDA_CU), new Hermes::Hermes2DFunction<double>(-VOLUME_HEAT_SRC));

    // Initialize essential boundary conditions.
    Hermes::Hermes2D::DefaultEssentialBCConst<double> bc_essential(Hermes::vector<std::string>("Left", "Right"),
            FIXED_BDY_TEMP);
    Hermes::Hermes2D::EssentialBCs<double> bcs(&bc_essential);

    // Create an H1 space with default shapeset.
    Hermes::Hermes2D::H1Space<double> space(&mesh, &bcs, P_INIT);
    int ndof = space.get_num_dofs();
    info("ndof = %d", ndof);

    // Initialize the FE problem.
    Hermes::Hermes2D::DiscreteProblem<double> dp(&wf, &space);

    // Initial coefficient vector for the Newton's method.
    double* coeff_vec = new double[ndof];
    memset(coeff_vec, 0, ndof*sizeof(double));

    // Perform Newton's iteration and translate the resulting coefficient vector into a Solution.
    Hermes::Hermes2D::Solution<double> sln;
    Hermes::Hermes2D::NewtonSolver<double> newton(&dp, matrix_solver_type);
    if (!newton.solve(coeff_vec))
        error("Newton's iteration failed.");
    else
        Hermes::Hermes2D::Solution<double>::vector_to_solution(newton.get_sln_vector(), &space, &sln);

    // Get info about time spent during assembling in its respective parts.
    dp.get_all_profiling_output(std::cout);

    // VTK output.
    if (VTK_VISUALIZATION)
    {
        // Output solution in VTK format.
        Hermes::Hermes2D::Views::Linearizer<double> lin;
        bool mode_3D = true;
        lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D);
        info("Solution in VTK format saved to file %s.", "sln.vtk");

        // Output mesh and element orders in VTK format.
        Hermes::Hermes2D::Views::Orderizer ord;
        ord.save_orders_vtk(&space, "ord.vtk");
        info("Element orders in VTK format saved to file %s.", "ord.vtk");
    }

    // Visualize the solution.
    if (HERMES_VISUALIZATION)
    {
        Hermes::Hermes2D::Views::ScalarView<double> view("Solution", new Hermes::Hermes2D::Views::WinGeom(0, 300, 900, 350));
        // Hermes uses adaptive FEM to approximate higher-order FE solutions with linear
        // triangles for OpenGL. The second parameter of View::show() sets the error
        // tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default),
        // HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows
        // considerably with more accurate representation, so use it wisely.
        view.show(&sln, Hermes::Hermes2D::Views::HERMES_EPS_HIGH);
        Hermes::Hermes2D::Views::View::wait();
    }

    // Clean up.
    delete [] coeff_vec;

    return 0;
}