Example #1
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 #2
0
  void setUp()
  {
    this->build_mesh();

    // libMesh *should* renumber now, or a ParallelMesh might not have
    // contiguous ids, which is a requirement to write xda files.
    _mesh->allow_renumbering(true);

    _es = new EquationSystems(*_mesh);
    _sys = &_es->add_system<System> ("SimpleSystem");
    _sys->add_variable("u", FIRST);

    _es->init();
    SlitFunc slitfunc;
    _sys->project_solution(&slitfunc);

#ifdef LIBMESH_ENABLE_AMR
    MeshRefinement(*_mesh).uniformly_refine(1);
    _es->reinit();
    MeshRefinement(*_mesh).uniformly_refine(1);
    _es->reinit();
#endif
  }
Example #3
0
void setup(EquationSystems& systems, Mesh& mesh, GetPot& args)
{
    const unsigned int dim = mesh.mesh_dimension();
    // We currently invert tensors with the assumption that they're 3x3
    libmesh_assert (dim == 3);

    // Generating Mesh
    ElemType eltype = Utility::string_to_enum<ElemType>(args("mesh/generation/element_type", "hex8"));
    int nx = args("mesh/generation/num_elem", 4, 0);
    int ny = args("mesh/generation/num_elem", 4, 1);
    int nz = dim > 2 ? args("mesh/generation/num_elem", 4, 2) : 0;
    double origx = args("mesh/generation/origin", -1.0, 0);
    double origy = args("mesh/generation/origin", -1.0, 1);
    double origz = args("mesh/generation/origin", 0.0, 2);
    double sizex = args("mesh/generation/size", 2.0, 0);
    double sizey = args("mesh/generation/size", 2.0, 1);
    double sizez = args("mesh/generation/size", 2.0, 2);
    MeshTools::Generation::build_cube(mesh, nx, ny, nz,
                                      origx, origx+sizex, origy, origy+sizey, origz, origz+sizez, eltype);

    // Creating Systems
    SolidSystem& imms = systems.add_system<SolidSystem> ("solid");
    imms.args = args;

    // Build up auxiliary system
    ExplicitSystem& aux_sys = systems.add_system<TransientExplicitSystem>("auxiliary");

    // Initialize the system
    systems.parameters.set<unsigned int>("phase") = 0;
    systems.init();

    imms.save_initial_mesh();

    // Fill global solution vector from local ones
    aux_sys.reinit();
}
Example #4
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 #5
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
}