Example #1
0
/**
 * everything that is identical for the systems, and
 * should _not_ go into EquationSystems::compare(),
 * can go in this do_compare().
 */
bool do_compare (EquationSystems & les,
                 EquationSystems & res,
                 double threshold,
                 bool verbose)
{

    if (verbose)
    {
        libMesh::out        << "*********   LEFT SYSTEM    *********" << std::endl;
        les.print_info  ();
        libMesh::out << "*********   RIGHT SYSTEM   *********" << std::endl;
        res.print_info ();
        libMesh::out << "********* COMPARISON PHASE *********" << std::endl
                     << std::endl;
    }

    /**
     * start comparing
     */
    bool result = les.compare(res, threshold, verbose);
    if (verbose)
    {
        libMesh::out        << "*********     FINISHED     *********" << std::endl;
    }
    return result;
}
Example #2
0
int main( int argc, char** argv )
{
    LibMeshInit init (argc, argv);

    Mesh mesh(init.comm());

    MeshTools::Generation::build_square (mesh,
                                         4, 4,
                                         0.0, 1.0,
                                         0.0, 1.0,
                                         QUAD4);

//    XdrIO mesh_io(mesh);
//    mesh_io.read("one_tri.xda");

    mesh.print_info();

    EquationSystems es (mesh);

    LinearImplicitSystem& system = es.add_system<LinearImplicitSystem>("lap");

    uint u_var = system.add_variable("u", FIRST, LAGRANGE);

    Laplacian lap(es);

    system.attach_assemble_object(lap);

    std::set<boundary_id_type> bd_ids;
    bd_ids.insert(1);
    bd_ids.insert(3);

    std::vector<uint> vars(1,u_var);

    ZeroFunction<Real> zero;

    DirichletBoundary dirichlet_bc(bd_ids, vars, &zero);

    system.get_dof_map().add_dirichlet_boundary(dirichlet_bc);

    es.init();

    es.print_info();

    system.solve();

    VTKIO(mesh).write_equation_systems("lap.pvtu",es);

    return 0;
}
Example #3
0
int main (int argc, char** argv)
{
  LibMeshInit init(argc, argv);

  if (argc < 4)
    libMesh::out << "Usage: ./prog -d DIM filename" << std::endl;

  // Variables to get us started
  const unsigned int dim = atoi(argv[2]);

  std::string meshname  (argv[3]);

  // declare a mesh...
  Mesh mesh(init.comm(), dim);

  // Read a mesh
  mesh.read(meshname);

  GMVIO(mesh).write ("out_0.gmv");

  mesh.elem(0)->set_refinement_flag (Elem::REFINE);

  MeshRefinement mesh_refinement (mesh);

  mesh_refinement.refine_and_coarsen_elements ();
  mesh_refinement.uniformly_refine (2);

  mesh.print_info();


  // Set up the equation system(s)
  EquationSystems es (mesh);

  LinearImplicitSystem& primary =
    es.add_system<LinearImplicitSystem>("primary");

  primary.add_variable ("U", FIRST);
  primary.add_variable ("V", FIRST);

  primary.get_dof_map()._dof_coupling->resize(2);
  (*primary.get_dof_map()._dof_coupling)(0,0) = 1;
  (*primary.get_dof_map()._dof_coupling)(1,1) = 1;

  primary.attach_assemble_function(assemble);

  es.init ();

  es.print_info ();
  primary.get_dof_map().print_dof_constraints ();

  // call the solver.
  primary.solve ();

  GMVIO(mesh).write_equation_systems ("out_1.gmv",
                                      es);



  // Refine uniformly
  mesh_refinement.uniformly_refine (1);
  es.reinit ();

  // Write out the projected solution
  GMVIO(mesh).write_equation_systems ("out_2.gmv",
                                      es);

  // Solve again. Output the refined solution
  primary.solve ();
  GMVIO(mesh).write_equation_systems ("out_3.gmv",
                                      es);

  return 0;
}
Example #4
0
void assemble_and_solve(MeshBase & mesh,
                        EquationSystems & equation_systems)
{
  mesh.print_info();

  LinearImplicitSystem & system =
    equation_systems.add_system<LinearImplicitSystem> ("Poisson");

  unsigned int u_var = system.add_variable("u", FIRST, LAGRANGE);

  system.attach_assemble_function (assemble_poisson);

  // the cube has boundaries IDs 0, 1, 2, 3, 4 and 5
  std::set<boundary_id_type> boundary_ids;
  for (int j = 0; j<6; ++j)
    boundary_ids.insert(j);

  // Create a vector storing the variable numbers which the BC applies to
  std::vector<unsigned int> variables(1);
  variables[0] = u_var;

  ZeroFunction<> zf;
  DirichletBoundary dirichlet_bc(boundary_ids,
                                 variables,
                                 &zf);
  system.get_dof_map().add_dirichlet_boundary(dirichlet_bc);

  equation_systems.init();
  equation_systems.print_info();

#ifdef LIBMESH_ENABLE_AMR
  MeshRefinement mesh_refinement(mesh);

  mesh_refinement.refine_fraction()  = 0.7;
  mesh_refinement.coarsen_fraction() = 0.3;
  mesh_refinement.max_h_level()      = 5;

  const unsigned int max_r_steps = 2;

  for (unsigned int r_step=0; r_step<=max_r_steps; r_step++)
    {
      system.solve();
      if (r_step != max_r_steps)
        {
          ErrorVector error;
          KellyErrorEstimator error_estimator;

          error_estimator.estimate_error(system, error);

          libMesh::out << "Error estimate\nl2 norm = "
                       << error.l2_norm()
                       << "\nmaximum = "
                       << error.maximum()
                       << std::endl;

          mesh_refinement.flag_elements_by_error_fraction (error);

          mesh_refinement.refine_and_coarsen_elements();

          equation_systems.reinit();
        }
    }
#else
  system.solve();
#endif
}