コード例 #1
0
ファイル: main.cpp プロジェクト: hpfem/hermes-testing
int main(int argc, char* argv[])
{
  // Load the mesh.
  MeshSharedPtr mesh_whole_domain(new Mesh), mesh_bottom_left_corner(new Mesh), mesh_complement(new Mesh);
  Hermes::vector<MeshSharedPtr> meshes (mesh_bottom_left_corner, mesh_whole_domain, mesh_complement);
  MeshReaderH2DXML mloader;
  mloader.set_validation(false);
  mloader.load("subdomains.xml", meshes);

  // Perform initial mesh refinements (optional).
  for(int i = 0; i < INIT_REF_NUM; i++)
    for(unsigned int meshes_i = 0; meshes_i < meshes.size(); meshes_i++)
      meshes[meshes_i]->refine_all_elements();

  mloader.save("subdomains2.xml", meshes);
  mloader.load("subdomains2.xml", meshes);

  // Initialize essential boundary conditions.
  DefaultEssentialBCConst<double> bc_essential_whole_domain(Hermes::vector<std::string>("Bottom Left", "Bottom Right", "Top Left", "Top Right"), 0.0);
  EssentialBCs<double> bcs_whole_domain(&bc_essential_whole_domain);

  DefaultEssentialBCConst<double> bc_essential_bottom_left_corner(Hermes::vector<std::string>("Bottom Left", "Horizontal Left"), 0.0);
  EssentialBCs<double> bcs_bottom_left_corner(&bc_essential_bottom_left_corner);

  DefaultEssentialBCConst<double> bc_essential_complement(Hermes::vector<std::string>("Bottom Right", "Top Right", "Top Left", "Horizontal Left", "Vertical Bottom"), 0.0);
  EssentialBCs<double> bcs_complement(&bc_essential_complement);

  // Create H1 spaces with default shapeset.
  SpaceSharedPtr<double> space_whole_domain(new H1Space<double>(mesh_whole_domain, &bcs_whole_domain, P_INIT));
  int ndof_whole_domain = space_whole_domain->get_num_dofs();

  SpaceSharedPtr<double> space_bottom_left_corner(new H1Space<double>(mesh_bottom_left_corner, &bcs_bottom_left_corner, P_INIT));
  int ndof_bottom_left_corner = space_bottom_left_corner->get_num_dofs();

  SpaceSharedPtr<double> space_complement(new H1Space<double>(mesh_complement, &bcs_complement, P_INIT));
  int ndof_complement = space_complement->get_num_dofs();

  if(ndof_whole_domain == 225 && ndof_bottom_left_corner == 56 && ndof_complement == 161)
  {
    return 0;
  }
  else
  {
    return -1;
  }

  return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: hpfem/hermes-testing
int main(int argc, char* argv[])
{
  // Check number of command-line parameters.
  if (argc < 2)
    throw Hermes::Exceptions::Exception("Not enough parameters.");

  // Load the mesh.
  MeshSharedPtr mesh(new Mesh);
  MeshReaderH2DXML mloader;
  mloader.set_validation(false);
  if (strcasecmp(argv[1], "1") == 0)
    mloader.load(mesh_file_1, mesh);
  if (strcasecmp(argv[1], "2") == 0)
    mloader.load(mesh_file_2, mesh);
  if (strcasecmp(argv[1], "3") == 0)
    mloader.load(mesh_file_3, mesh);

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

  // Initialize boundary conditions.
  DefaultEssentialBCConst<double> bc_essential("Bdy", 0.0);
  EssentialBCs<double> bcs(&bc_essential);

  // Create an H1 space with default shapeset.
  SpaceSharedPtr<double> space(new H1Space<double>(mesh, &bcs, P_INIT));
  int ndof = Space<double>::get_num_dofs(space);

  // Initialize the weak formulation.
  WeakFormsH1::DefaultWeakFormPoisson<double> wf(HERMES_ANY, new Hermes1DFunction<double>(1.0), new Hermes2DFunction<double>(-const_f));

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

  // Set up the solver, matrix, and rhs according to the solver selection.
  SparseMatrix<double>* matrix = create_matrix<double>();
  Vector<double>* rhs = create_vector<double>();
  LinearMatrixSolver<double>* solver = create_linear_solver<double>(matrix, rhs);

  // 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.
  MeshFunctionSharedPtr<double> sln(new Solution<double>());
  NewtonSolver<double> newton(&dp);
  try{
    newton.solve(coeff_vec);
  }
  catch (Hermes::Exceptions::Exception& e)
  {
    e.print_msg();
  }
  Solution<double>::vector_to_solution(newton.get_sln_vector(), space, sln);

  // Clean up.
  delete solver;
  delete matrix;
  delete rhs;

  double coor_x[4] = { 0.3, 0.7, 1.3, 1.7 };
  double coor_y = 0.5;

  double value[4] = { 0.102569, 0.167907, 0.174203, 0.109630 };
  if (strcasecmp(argv[1], "2") == 0)
  {
    value[0] = 0.062896;
    value[1] = 0.096658;
    value[2] = 0.114445;
    value[3] = 0.081221;
  }

  if (strcasecmp(argv[1], "3") == 0)
  {
    value[0] = 0.048752;
    value[1] = 0.028585;
    value[2] = 0.028585;
    value[3] = 0.048752;
  }

  bool success = true;
  for (int i = 0; i < 4; i++)
    success = Testing::test_value(sln->get_pt_value(coor_x[i], coor_y)->val[0], value[i], "value") && success;
  if (success)
  {
    printf("Success!\n");
    return 0;
  }
  else
  {
    printf("Failure!\n");
    return -1;
  }
}