示例#1
0
int main() {
    bc1( &x );
    bc2( &x );
    bc3( &x );
    bcd( &x );
    _PASS;
}
示例#2
0
int main(int argc, char* argv[])
{
    // Load the mesh.
  Mesh mesh;
  MeshReaderH2D mloader;
  mloader.load("domain.mesh", &mesh);

  // Perform uniform mesh refinement.
  // 2 is for vertical split.
  for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(2); 

  // Initialize boundary conditions
  DefaultEssentialBCConst<double> bc1("Bdy_perfect", 0.0);
  EssentialBCNonConst bc2("Bdy_left");
  DefaultEssentialBCConst<double> bc3("Bdy_left", 0.0);
  EssentialBCs<double> bcs(Hermes::vector<EssentialBoundaryCondition<double> *>(&bc1, &bc2));
  EssentialBCs<double> bcs_im(Hermes::vector<EssentialBoundaryCondition<double> *>(&bc1, &bc3));

  // Create an H1 space with default shapeset.
  H1Space<double> e_r_space(&mesh, &bcs, P_INIT);
  H1Space<double> e_i_space(&mesh, &bcs_im, P_INIT);
  int ndof = Space<double>::get_num_dofs(&e_r_space);
  Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof);

  // Initialize the weak formulation.
  WeakFormHelmholtz wf(eps, mu, omega, sigma, beta, E0, h);

  // Initialize the FE problem.
  DiscreteProblem<double> dp(&wf, Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space));

  // Initialize the solutions.
  Solution<double> e_r_sln, e_i_sln;

  // Initial coefficient vector for the Newton's method.  
  ndof = Space<double>::get_num_dofs(Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space));

  Hermes::Hermes2D::NewtonSolver<double> newton(&dp);
  try
  {
    newton.set_newton_tol(NEWTON_TOL);
    newton.set_newton_max_iter(NEWTON_MAX_ITER);
    newton.solve();
  }
  catch(Hermes::Exceptions::Exception e)
  {
    e.printMsg();
    throw Hermes::Exceptions::Exception("Newton's iteration failed.");
  };

  // Translate the resulting coefficient vector into Solutions.
  Solution<double>::vector_to_solutions(newton.get_sln_vector(), Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space), 
      Hermes::vector<Solution<double>*>(&e_r_sln, &e_i_sln));

  // Visualize the solution.
  ScalarView viewEr("Er [V/m]", new WinGeom(0, 0, 800, 400));
  viewEr.show(&e_r_sln);
  // viewEr.save_screenshot("real_part.bmp");

  ScalarView viewEi("Ei [V/m]", new WinGeom(0, 450, 800, 400));
  viewEi.show(&e_i_sln);
  // viewEi.save_screenshot("imaginary_part.bmp");

  // Wait for the view to be closed.
  View::wait();

  return 0;
}