int main(int argc, char** argv) { LibMeshInit init (argc, argv); Mesh mesh(init.comm()); EquationSystems es(mesh); libMesh::out << "Usage: " << argv[0] << " mesh solution" << std::endl; libMesh::out << "Loading..." << std::endl; mesh.read(argv[1]); libMesh::out << "Loaded mesh " << argv[1] << std::endl; mesh.print_info(); es.read(argv[2], EquationSystems::READ_HEADER | EquationSystems::READ_DATA | EquationSystems::READ_ADDITIONAL_DATA | EquationSystems::READ_BASIC_ONLY); libMesh::out << "Loaded solution " << argv[2] << std::endl; es.print_info(); libMesh::out.precision(16); for (unsigned int i = 0; i != es.n_systems(); ++i) { System &sys = es.get_system(i); output_norms(sys, *sys.solution, std::string("solution")); for (unsigned int j = 0; j != sys.n_vectors(); ++j) output_norms(sys, sys.get_vector(j), sys.vector_name(j)); } }
int main (int argc, char ** argv) { LibMeshInit init (argc, argv); if (libMesh::on_command_line("--help") || argc < 3) { libMesh::out << "Example: " << argv[0] << " --mesh=filename.e --n-procs='4 8 16' " "[--num-ghost-layers <n>] [--dry-run] [--ascii]\n\n" << "--mesh Full name of the mesh file to read in. \n" << "--n-procs Vector of number of processors.\n" << "--num-ghost-layers Number of layers to ghost when partitioning (Default: 1).\n" << "--dry-run Only test the partitioning, don't write any files.\n" << "--ascii Write ASCII cpa files rather than binary cpr files.\n" << std::endl; return 0; } std::string filename = libMesh::command_line_value("--mesh", std::string()); std::vector<processor_id_type> all_n_procs; libMesh::command_line_vector("--n-procs", all_n_procs); unsigned int num_ghost_layers = libMesh::command_line_value("--num-ghost-layers", 1); ReplicatedMesh mesh(init.comm()); // If the user has requested additional ghosted layers, we need to add a ghosting functor. DefaultCoupling default_coupling; if (num_ghost_layers > 1) { default_coupling.set_n_levels(num_ghost_layers); mesh.add_ghosting_functor(default_coupling); } libMesh::out << "Reading " << filename << std::endl; mesh.read(filename); for (const auto & n_procs : all_n_procs) { libMesh::out << "splitting " << n_procs << " ways..." << std::endl; auto cpr = split_mesh(mesh, n_procs); if (!libMesh::on_command_line("--dry-run")) { libMesh::out << " * writing " << cpr->current_processor_ids().size() << " files per process..." << std::endl; const bool binary = !libMesh::on_command_line("--ascii"); cpr->binary() = binary; std::ostringstream outputname; outputname << remove_extension(filename) << (binary ? ".cpr" : ".cpa"); cpr->write(outputname.str()); } } return 0; }
int main(int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); if (on_command_line("--help")) print_help(argc, argv); else { #if !defined(LIBMESH_ENABLE_SECOND_DERIVATIVES) libmesh_example_requires(false, "--enable-second"); #elif !defined(LIBMESH_ENABLE_PERIODIC) libmesh_example_requires(false, "--enable-periodic"); #endif // This is a PETSc-specific solver libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc"); const int dim = command_line_value("dim",1); // Skip higher-dimensional examples on a lower-dimensional libMesh build libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support"); Biharmonic* biharmonic; Biharmonic::Create(&biharmonic,init.comm()); biharmonic->viewParameters(); biharmonic->init(); biharmonic->run(); Biharmonic::Destroy(&biharmonic); } return 0; }
int main (int argc, char** argv){ LibMeshInit init (argc, argv); //initialize libmesh library std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; Mesh mesh(init.comm()); mesh.read("channel_long.exo"); std::string stash_assign = "divvy.txt"; std::ofstream output(stash_assign.c_str()); MeshBase::element_iterator elem_it = mesh.elements_begin(); const MeshBase::element_iterator elem_end = mesh.elements_end(); for (; elem_it != elem_end; ++elem_it){ Elem* elem = *elem_it; if(output.is_open()){ output << elem->id() << " " << elem->subdomain_id() << "\n"; } } output.close(); return 0; }
// Begin the main program. int main (int argc, char** argv) { // Initialize libMesh and any dependent libaries, like in example 2. LibMeshInit init (argc, argv); // This example requires Adaptive Mesh Refinement support - although // it only refines uniformly, the refinement code used is the same // underneath. It also requires libmesh support for Triangle and // Tetgen, which means that libmesh must be configured with // --disable-strict-lgpl for this example to run. #if !defined(LIBMESH_HAVE_TRIANGLE) || !defined(LIBMESH_HAVE_TETGEN) || !defined(LIBMESH_ENABLE_AMR) libmesh_example_requires(false, "--disable-strict-lgpl --enable-amr"); #else // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // Read the mesh from file. This is the coarse mesh that will be used // in example 10 to demonstrate adaptive mesh refinement. Here we will // simply read it in and uniformly refine it 5 times before we compute // with it. Mesh mesh(init.comm()); { unsigned int dim=2; if (argc == 3 && std::atoi(argv[2]) == 3) { libmesh_here(); dim=3; } mesh.read ((dim==2) ? "mesh.xda" : "hybrid_3d.xda"); } // Create a MeshRefinement object to handle refinement of our mesh. // This class handles all the details of mesh refinement and coarsening. MeshRefinement mesh_refinement (mesh); // Uniformly refine the mesh 4 times. This is the // first time we use the mesh refinement capabilities // of the library. mesh_refinement.uniformly_refine (4); // Print information about the mesh to the screen. mesh.print_info(); // integrate the desired function integrate_function (mesh); // All done. return 0; #endif }
int main (int argc, char** argv) { // Initialize the library. This is necessary because the library // may depend on a number of other libraries (i.e. MPI and PETSc) // that require initialization before use. When the LibMeshInit // object goes out of scope, other libraries and resources are // finalized. LibMeshInit init (argc, argv); // Check for proper usage. The program is designed to be run // as follows: // ./ex1 -d DIM input_mesh_name [-o output_mesh_name] // where [output_mesh_name] is an optional parameter giving // a filename to write the mesh into. if (argc < 4) { if (libMesh::processor_id() == 0) std::cerr << "Usage: " << argv[0] << " -d 2 in.mesh [-o out.mesh]" << std::endl; // This handy function will print the file name, line number, // and then abort. Currently the library does not use C++ // exception handling. libmesh_error(); } // Get the dimensionality of the mesh from argv[2] const unsigned int dim = std::atoi(argv[2]); // Skip higher-dimensional examples on a lower-dimensional libMesh build libmesh_example_assert(dim <= LIBMESH_DIM, "2D/3D support"); // Create a mesh, with dimension to be overridden later, on the // default MPI communicator. Mesh mesh(init.comm()); // Read the input mesh. mesh.read (argv[3]); // Print information about the mesh to the screen. mesh.print_info(); // Write the output mesh if the user specified an // output file name. if (argc >= 6 && std::string("-o") == argv[4]) mesh.write (argv[5]); // All done. libMesh objects are destroyed here. Because the // LibMeshInit object was created first, its destruction occurs // last, and it's destructor finalizes any external libraries and // checks for leaked memory. return 0; }
int main (int argc, char** argv){ LibMeshInit init (argc, argv); //initialize libmesh library std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; Mesh mesh(init.comm()); GetPot infile("inputs.in"); std::string find_mesh_here = infile("mesh","psiLF_mesh.xda"); mesh.read(find_mesh_here); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Name system; need to have same name is system being read in //ConvDiff_MprimeSys & system = // equation_systems.add_system<ConvDiff_MprimeSys>("Diff_ConvDiff_MprimeSys"); //for diff-convdiff ConvDiff_MprimeSys & system = equation_systems.add_system<ConvDiff_MprimeSys>("ConvDiff_MprimeSys"); //for scalar-field // Steady-state problem system.time_solver = AutoPtr<TimeSolver>(new SteadySolver(system)); // Read in all the equation systems data from the LF solve (system, solutions, rhs, etc) std::string find_psiLF_here = infile("psiLF_file","psiLF.xda"); std::cout << "Looking for psiLF at: " << find_psiLF_here << "\n\n"; equation_systems.read(find_psiLF_here, READ, EquationSystems::READ_HEADER | EquationSystems::READ_DATA | EquationSystems::READ_ADDITIONAL_DATA); if(equation_systems.n_systems() > 1){ std::cout << "\nName of system being read in does not match..." << std::endl; } #ifdef LIBMESH_HAVE_GMV GMVIO(equation_systems.get_mesh()).write_equation_systems(std::string("psi.gmv"), equation_systems); #endif #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO (mesh).write_equation_systems("psi.exo",equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API return 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; }
// Begin the main program. int main (int argc, char** argv) { // Initialize libMesh and any dependent libaries, like in example 2. LibMeshInit init (argc, argv); libmesh_example_assert(2 <= LIBMESH_DIM, "2D support"); std::cout << "Triangulating an L-shaped domain with holes" << std::endl; // 1.) 2D triangulation of L-shaped domain with three holes of different shape triangulate_domain(init.comm()); libmesh_example_assert(3 <= LIBMESH_DIM, "3D support"); std::cout << "Tetrahedralizing a prismatic domain with a hole" << std::endl; // 2.) 3D tetrahedralization of rectangular domain with hole. tetrahedralize_domain(init.comm()); return 0; }
int main(int argc, char* argv[]) { LibMeshInit init (argc, argv); #ifdef LIBMESH_HAVE_DTK Mesh from_mesh(init.comm()); MeshTools::Generation::build_cube(from_mesh, 4, 4, 4, 0, 1, 0, 1, 0, 1, HEX8); from_mesh.print_info(); EquationSystems from_es(from_mesh); System & from_sys = from_es.add_system<ExplicitSystem>("From"); unsigned int from_var = from_sys.add_variable("from"); from_sys.attach_init_function(initialize); from_es.init(); ExodusII_IO(from_mesh).write_equation_systems("from.e", from_es); Mesh to_mesh(init.comm()); MeshTools::Generation::build_cube(to_mesh, 5, 5, 5, 0, 1, 0, 1, 0, 1, TET4); to_mesh.print_info(); EquationSystems to_es(to_mesh); System & to_sys = to_es.add_system<ExplicitSystem>("To"); unsigned int to_var = to_sys.add_variable("to"); to_es.init(); DTKSolutionTransfer dtk_transfer(init.comm()); dtk_transfer.transfer(from_sys.variable(from_var), to_sys.variable(to_var)); to_es.update(); ExodusII_IO(to_mesh).write_equation_systems("to.e", to_es); #endif return 0; }
int main (int argc, char ** argv) { LibMeshInit init (argc, argv); #ifndef LIBMESH_HAVE_PETSC_TAO libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support"); #elif LIBMESH_USE_COMPLEX_NUMBERS // According to // http://www.mcs.anl.gov/research/projects/tao/documentation/installation.html // TAO & PETSc-complex are currently mutually exclusive libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support & real-numbers only"); #endif // We use a 2D domain. libmesh_example_requires(LIBMESH_DIM > 1, "--disable-1D-only"); // TAO is giving us problems in parallel? if (init.comm().size() != 1) { libMesh::out << "This example can currently only be run in serial." << std::endl; return 77; } GetPot infile("optimization_ex2.in"); const std::string approx_order = infile("approx_order", "FIRST"); const std::string fe_family = infile("fe_family", "LAGRANGE"); const unsigned int n_elem = infile("n_elem", 10); Mesh mesh(init.comm()); MeshTools::Generation::build_square (mesh, n_elem, n_elem, -1., 1., -1., 1., QUAD9); mesh.print_info(); EquationSystems equation_systems (mesh); OptimizationSystem & system = equation_systems.add_system<OptimizationSystem> ("Optimization"); // The default is to use PETSc/Tao solvers, but let the user change // the optimization solver package on the fly. { const std::string optimization_solver_type = infile("optimization_solver_type", "PETSC_SOLVERS"); SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type); UniquePtr<OptimizationSolver<Number> > new_solver = OptimizationSolver<Number>::build(system, sp); system.optimization_solver.reset(new_solver.release()); } // Set tolerances and maximum iteration counts directly on the optimization solver. system.optimization_solver->max_objective_function_evaluations = 128; system.optimization_solver->objective_function_relative_tolerance = 1.e-4; system.optimization_solver->verbose = true; AssembleOptimization assemble_opt(system); system.add_variable("u", Utility::string_to_enum<Order> (approx_order), Utility::string_to_enum<FEFamily>(fe_family)); system.optimization_solver->objective_object = &assemble_opt; system.optimization_solver->gradient_object = &assemble_opt; system.optimization_solver->hessian_object = &assemble_opt; system.optimization_solver->equality_constraints_object = &assemble_opt; system.optimization_solver->equality_constraints_jacobian_object = &assemble_opt; system.optimization_solver->inequality_constraints_object = &assemble_opt; system.optimization_solver->inequality_constraints_jacobian_object = &assemble_opt; system.optimization_solver->lower_and_upper_bounds_object = &assemble_opt; // system.matrix and system.rhs are used for the gradient and Hessian, // so in this case we add an extra matrix and vector to store A and F. // This makes it easy to write the code for evaluating the objective, // gradient, and hessian. system.add_matrix("A_matrix"); system.add_vector("F_vector"); assemble_opt.A_matrix = &system.get_matrix("A_matrix"); assemble_opt.F_vector = &system.get_vector("F_vector"); equation_systems.init(); equation_systems.print_info(); assemble_opt.assemble_A_and_F(); { std::vector< std::set<numeric_index_type> > constraint_jac_sparsity; std::set<numeric_index_type> sparsity_row; sparsity_row.insert(17); constraint_jac_sparsity.push_back(sparsity_row); sparsity_row.clear(); sparsity_row.insert(23); constraint_jac_sparsity.push_back(sparsity_row); sparsity_row.clear(); sparsity_row.insert(98); sparsity_row.insert(185); constraint_jac_sparsity.push_back(sparsity_row); system.initialize_equality_constraints_storage(constraint_jac_sparsity); } { std::vector< std::set<numeric_index_type> > constraint_jac_sparsity; std::set<numeric_index_type> sparsity_row; sparsity_row.insert(200); sparsity_row.insert(201); constraint_jac_sparsity.push_back(sparsity_row); system.initialize_inequality_constraints_storage(constraint_jac_sparsity); } // We need to close the matrix so that we can use it to store the // Hessian during the solve. system.matrix->close(); system.solve(); // Print convergence information system.optimization_solver->print_converged_reason(); // Write the solution to file if the optimization solver converged if (system.optimization_solver->get_converged_reason() > 0) { std::stringstream filename; ExodusII_IO (mesh).write_equation_systems("optimization_soln.exo", equation_systems); } return 0; }
// The main program. int main(int argc, char ** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); #if !defined(LIBMESH_HAVE_XDR) // We need XDR support to write out reduced bases libmesh_example_requires(false, "--enable-xdr"); #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION) // XDR binary support requires double precision libmesh_example_requires(false, "--disable-singleprecision"); #elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION) // I have no idea why long double isn't working here... [RHS] libmesh_example_requires(false, "double precision"); #endif // Eigen can take forever to solve the offline mode portion of this // example libmesh_example_requires(libMesh::default_solver_package() != EIGEN_SOLVERS, "--enable-petsc or --enable-laspack"); // Trilinos reports "true residual is too large" in the offline mode // portion of this example libmesh_example_requires(libMesh::default_solver_package() != TRILINOS_SOLVERS, "--enable-petsc or --enable-laspack"); // This example only works if libMesh was compiled for 3D const unsigned int dim = 3; libmesh_example_requires(dim == LIBMESH_DIM, "3D support"); std::string parameters_filename = "reduced_basis_ex5.in"; GetPot infile(parameters_filename); unsigned int n_elem_x = infile("n_elem_x", 0); unsigned int n_elem_y = infile("n_elem_y", 0); unsigned int n_elem_z = infile("n_elem_z", 0); Real x_size = infile("x_size", 0.); Real y_size = infile("y_size", 0.); Real z_size = infile("z_size", 0.); bool store_basis_functions = infile("store_basis_functions", true); // Read the "online_mode" flag from the command line GetPot command_line(argc, argv); int online_mode = 0; if (command_line.search(1, "-online_mode")) online_mode = command_line.next(online_mode); Mesh mesh (init.comm(), dim); MeshTools::Generation::build_cube (mesh, n_elem_x, n_elem_y, n_elem_z, 0., x_size, 0., y_size, 0., z_size, HEX8); // Let's add a node boundary condition so that we can impose a point // load. // Each processor should know about each boundary condition it can // see, so we loop over all elements, not just local elements. MeshBase::const_element_iterator el = mesh.elements_begin(); const MeshBase::const_element_iterator end_el = mesh.elements_end(); for ( ; el != end_el; ++el) { const Elem * elem = *el; unsigned int side_max_x = 0, side_max_y = 0, side_max_z = 0; bool found_side_max_x = false, found_side_max_y = false, found_side_max_z = false; for (unsigned int side=0; side<elem->n_sides(); side++) { if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X)) { side_max_x = side; found_side_max_x = true; } if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y)) { side_max_y = side; found_side_max_y = true; } if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z)) { side_max_z = side; found_side_max_z = true; } } // If elem has sides on boundaries // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z // then let's set a node boundary condition if (found_side_max_x && found_side_max_y && found_side_max_z) { for (unsigned int n=0; n<elem->n_nodes(); n++) { if (elem->is_node_on_side(n, side_max_x) && elem->is_node_on_side(n, side_max_y) && elem->is_node_on_side(n, side_max_z)) { mesh.get_boundary_info().add_node(elem->node_ptr(n), NODE_BOUNDARY_ID); } } } } mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems(mesh); // We override RBConstruction with ElasticityRBConstruction in order to // specialize a few functions for this particular problem. ElasticityRBConstruction & rb_con = equation_systems.add_system<ElasticityRBConstruction>("RBElasticity"); // Also, initialize an ExplicitSystem to store stresses ExplicitSystem & stress_system = equation_systems.add_system<ExplicitSystem> ("StressSystem"); stress_system.add_variable("sigma_00", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_01", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_02", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_10", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_11", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_12", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_20", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_21", CONSTANT, MONOMIAL); stress_system.add_variable("sigma_22", CONSTANT, MONOMIAL); stress_system.add_variable("vonMises", CONSTANT, MONOMIAL); // Initialize the data structures for the equation system. equation_systems.init (); equation_systems.print_info(); // Build a new RBEvaluation object which will be used to perform // Reduced Basis calculations. This is required in both the // "Offline" and "Online" stages. ElasticityRBEvaluation rb_eval(mesh.comm()); // We need to give the RBConstruction object a pointer to // our RBEvaluation object rb_con.set_rb_evaluation(rb_eval); if (!online_mode) // Perform the Offline stage of the RB method { // Use CG solver. This echoes the Petsc command line options set // in run.sh, but also works for non-PETSc linear solvers. rb_con.get_linear_solver()->set_solver_type(CG); // Read in the data that defines this problem from the specified text file rb_con.process_parameters_file(parameters_filename); // Print out info that describes the current setup of rb_con rb_con.print_info(); // Prepare rb_con for the Construction stage of the RB method. // This sets up the necessary data structures and performs // initial assembly of the "truth" affine expansion of the PDE. rb_con.initialize_rb_construction(); // Compute the reduced basis space by computing "snapshots", i.e. // "truth" solves, at well-chosen parameter values and employing // these snapshots as basis functions. rb_con.train_reduced_basis(); // Write out the data that will subsequently be required for the Evaluation stage #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_con.get_rb_evaluation()); rb_eval_writer.write_to_file("rb_eval.bin"); #else rb_con.get_rb_evaluation().legacy_write_offline_data_to_files(); #endif // If requested, write out the RB basis functions for visualization purposes if (store_basis_functions) { // Write out the basis functions rb_con.get_rb_evaluation().write_out_basis_functions(rb_con); } } else // Perform the Online stage of the RB method { // Read in the reduced basis data #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataDeserialization::RBEvaluationDeserialization rb_eval_reader(rb_eval); rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true); #else rb_eval.legacy_read_offline_data_from_files(); #endif // Iinitialize online parameters Real online_x_scaling = infile("online_x_scaling", 0.); Real online_load_Fx = infile("online_load_Fx", 0.); Real online_load_Fy = infile("online_load_Fy", 0.); Real online_load_Fz = infile("online_load_Fz", 0.); Real online_point_load_Fx = infile("online_point_load_Fx", 0.); Real online_point_load_Fy = infile("online_point_load_Fy", 0.); Real online_point_load_Fz = infile("online_point_load_Fz", 0.); RBParameters online_mu; online_mu.set_value("x_scaling", online_x_scaling); online_mu.set_value("load_Fx", online_load_Fx); online_mu.set_value("load_Fy", online_load_Fy); online_mu.set_value("load_Fz", online_load_Fz); online_mu.set_value("point_load_Fx", online_point_load_Fx); online_mu.set_value("point_load_Fy", online_point_load_Fy); online_mu.set_value("point_load_Fz", online_point_load_Fz); rb_eval.set_parameters(online_mu); rb_eval.print_parameters(); // Now do the Online solve using the precomputed reduced basis rb_eval.rb_solve(rb_eval.get_n_basis_functions()); if (store_basis_functions) { // Read in the basis functions rb_eval.read_in_basis_functions(rb_con); // Plot the solution rb_con.load_rb_solution(); const RBParameters & rb_eval_params = rb_eval.get_parameters(); scale_mesh_and_plot(equation_systems, rb_eval_params, "RB_sol.e"); } } return 0; }
int main (int argc, char** argv){ LibMeshInit init (argc, argv); //initialize libmesh library std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; Mesh mesh(init.comm()); //T-channel //mesh.read("mesh.e"); //MeshRefinement meshRefinement(mesh); //meshRefinement.uniformly_refine(0); //1D - for debugging //int n = 20; //MeshTools::Generation::build_line(mesh, n, 0.0, 1.0, EDGE2); //n linear elements from 0 to 1 //nice geometry (straight channel) MeshTools::Generation::build_square (mesh, 250, 50, -0.0, 5.0, -0.0, 1.0, QUAD9); //read in subdomain assignments std::vector<double> prev_assign(mesh.n_elem(), 0.); std::string read_assign = "do_divvy.txt"; if(FILE *fp=fopen(read_assign.c_str(),"r")){ int flag = 1; int elemNum, assign; int ind = 0; while(flag != -1){ flag = fscanf(fp, "%d %d",&elemNum,&assign); if(flag != -1){ prev_assign[ind] = assign; ind += 1; } } fclose(fp); } //to stash subdomain assignments std::string stash_assign = "divvy.txt"; std::ofstream output(stash_assign.c_str()); MeshBase::element_iterator elem_it = mesh.elements_begin(); const MeshBase::element_iterator elem_end = mesh.elements_end(); for (; elem_it != elem_end; ++elem_it){ Elem* elem = *elem_it; Point c = elem->centroid(); //Point cshift1(c(0)-0.63, c(1)-0.5); elem->subdomain_id() = prev_assign[elem->id()]; //TEST/DEBUG //if(fabs(c(0)-3.0) < 0.35 && fabs(c(1)-0.5) < 0.35) // elem->subdomain_id() = 1; if(output.is_open()){ output << elem->id() << " " << elem->subdomain_id() << "\n"; } } output.close(); EquationSystems equation_systems (mesh); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO (mesh).write_equation_systems("meep.exo",equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API return 0; } // end main
// The main program. int main (int argc, char ** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // This example NaNs with the Eigen sparse linear solvers and // Trilinos solvers, but should work OK with either PETSc or // Laspack. libmesh_example_requires(libMesh::default_solver_package() != EIGEN_SOLVERS, "--enable-petsc or --enable-laspack"); libmesh_example_requires(libMesh::default_solver_package() != TRILINOS_SOLVERS, "--enable-petsc or --enable-laspack"); // Create a mesh, with dimension to be overridden later, distributed // across the default MPI communicator. Mesh mesh(init.comm()); // Use the MeshTools::Generation mesh generator to create a uniform // 2D grid on the square [-1,1]^2. We instruct the mesh generator // to build a mesh of 8x8 Quad9 elements in 2D. Building these // higher-order elements allows us to use higher-order // approximation, as in example 3. MeshTools::Generation::build_square (mesh, 20, 20, 0., 1., 0., 1., QUAD9); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Creates a transient system named "Navier-Stokes" TransientLinearImplicitSystem & system = equation_systems.add_system<TransientLinearImplicitSystem> ("Navier-Stokes"); // Add the variables "u" & "v" to "Navier-Stokes". They // will be approximated using second-order approximation. system.add_variable ("u", SECOND); system.add_variable ("v", SECOND); // Add the variable "p" to "Navier-Stokes". This will // be approximated with a first-order basis, // providing an LBB-stable pressure-velocity pair. system.add_variable ("p", FIRST); // Add a scalar Lagrange multiplier to constrain the // pressure to have zero mean. system.add_variable ("alpha", FIRST, SCALAR); // Give the system a pointer to the matrix assembly // function. system.attach_assemble_function (assemble_stokes); // Initialize the data structures for the equation system. equation_systems.init (); // Prints information about the system to the screen. equation_systems.print_info(); // Create a performance-logging object for this example PerfLog perf_log("Systems Example 3"); // Get a reference to the Stokes system to use later. TransientLinearImplicitSystem & navier_stokes_system = equation_systems.get_system<TransientLinearImplicitSystem>("Navier-Stokes"); // Now we begin the timestep loop to compute the time-accurate // solution of the equations. const Real dt = 0.01; navier_stokes_system.time = 0.0; const unsigned int n_timesteps = 15; // The number of steps and the stopping criterion are also required // for the nonlinear iterations. const unsigned int n_nonlinear_steps = 15; const Real nonlinear_tolerance = 1.e-3; // We also set a standard linear solver flag in the EquationSystems object // which controls the maxiumum number of linear solver iterations allowed. equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 250; // Tell the system of equations what the timestep is by using // the set_parameter function. The matrix assembly routine can // then reference this parameter. equation_systems.parameters.set<Real> ("dt") = dt; // The first thing to do is to get a copy of the solution at // the current nonlinear iteration. This value will be used to // determine if we can exit the nonlinear loop. UniquePtr<NumericVector<Number> > last_nonlinear_soln (navier_stokes_system.solution->clone()); for (unsigned int t_step=0; t_step<n_timesteps; ++t_step) { // Incremenet the time counter, set the time and the // time step size as parameters in the EquationSystem. navier_stokes_system.time += dt; // A pretty update message libMesh::out << "\n\n*** Solving time step " << t_step << ", time = " << navier_stokes_system.time << " ***" << std::endl; // Now we need to update the solution vector from the // previous time step. This is done directly through // the reference to the Stokes system. *navier_stokes_system.old_local_solution = *navier_stokes_system.current_local_solution; // At the beginning of each solve, reset the linear solver tolerance // to a "reasonable" starting value. const Real initial_linear_solver_tol = 1.e-6; equation_systems.parameters.set<Real> ("linear solver tolerance") = initial_linear_solver_tol; // Now we begin the nonlinear loop for (unsigned int l=0; l<n_nonlinear_steps; ++l) { // Update the nonlinear solution. last_nonlinear_soln->zero(); last_nonlinear_soln->add(*navier_stokes_system.solution); // Assemble & solve the linear system. perf_log.push("linear solve"); equation_systems.get_system("Navier-Stokes").solve(); perf_log.pop("linear solve"); // Compute the difference between this solution and the last // nonlinear iterate. last_nonlinear_soln->add (-1., *navier_stokes_system.solution); // Close the vector before computing its norm last_nonlinear_soln->close(); // Compute the l2 norm of the difference const Real norm_delta = last_nonlinear_soln->l2_norm(); // How many iterations were required to solve the linear system? const unsigned int n_linear_iterations = navier_stokes_system.n_linear_iterations(); // What was the final residual of the linear system? const Real final_linear_residual = navier_stokes_system.final_linear_residual(); // Print out convergence information for the linear and // nonlinear iterations. libMesh::out << "Linear solver converged at step: " << n_linear_iterations << ", final residual: " << final_linear_residual << " Nonlinear convergence: ||u - u_old|| = " << norm_delta << std::endl; // Terminate the solution iteration if the difference between // this nonlinear iterate and the last is sufficiently small, AND // if the most recent linear system was solved to a sufficient tolerance. if ((norm_delta < nonlinear_tolerance) && (navier_stokes_system.final_linear_residual() < nonlinear_tolerance)) { libMesh::out << " Nonlinear solver converged at step " << l << std::endl; break; } // Otherwise, decrease the linear system tolerance. For the inexact Newton // method, the linear solver tolerance needs to decrease as we get closer to // the solution to ensure quadratic convergence. The new linear solver tolerance // is chosen (heuristically) as the square of the previous linear system residual norm. //Real flr2 = final_linear_residual*final_linear_residual; equation_systems.parameters.set<Real> ("linear solver tolerance") = std::min(Utility::pow<2>(final_linear_residual), initial_linear_solver_tol); } // end nonlinear loop #ifdef LIBMESH_HAVE_EXODUS_API // Write out every nth timestep to file. const unsigned int write_interval = 1; if ((t_step+1)%write_interval == 0) { std::ostringstream file_name; // We write the file in the ExodusII format. file_name << "out_" << std::setw(3) << std::setfill('0') << std::right << t_step + 1 << ".e"; ExodusII_IO(mesh).write_equation_systems (file_name.str(), equation_systems); } #endif // #ifdef LIBMESH_HAVE_EXODUS_API } // end timestep loop. // All done. return 0; }
int main(int argc, char** argv) { // Initialize the library. This is necessary because the library // may depend on a number of other libraries (i.e. MPI and PETSc) // that require initialization before use. When the LibMeshInit // object goes out of scope, other libraries and resources are // finalized. LibMeshInit init (argc, argv); // Skip adaptive examples on a non-adaptive libMesh build #ifndef LIBMESH_ENABLE_AMR libmesh_example_requires(false, "--enable-amr"); #else // Create a mesh, with dimension to be overridden later, on the // default MPI communicator. Mesh mesh(init.comm()); GetPot command_line (argc, argv); int n = 4; if ( command_line.search(1, "-n") ) n = command_line.next(n); // Build a 1D mesh with 4 elements from x=0 to x=1, using // EDGE3 (i.e. quadratic) 1D elements. They are called EDGE3 elements // because a quadratic element contains 3 nodes. MeshTools::Generation::build_line(mesh,n,0.,1.,EDGE3); // Define the equation systems object and the system we are going // to solve. See Introduction Example 2 for more details. EquationSystems equation_systems(mesh); LinearImplicitSystem& system = equation_systems.add_system <LinearImplicitSystem>("1D"); // Add a variable "u" to the system, using second-order approximation system.add_variable("u",SECOND); // Give the system a pointer to the matrix assembly function. This // will be called when needed by the library. system.attach_assemble_function(assemble_1D); // Define the mesh refinement object that takes care of adaptively // refining the mesh. MeshRefinement mesh_refinement(mesh); // These parameters determine the proportion of elements that will // be refined and coarsened. Any element within 30% of the maximum // error on any element will be refined, and any element within 30% // of the minimum error on any element might be coarsened mesh_refinement.refine_fraction() = 0.7; mesh_refinement.coarsen_fraction() = 0.3; // We won't refine any element more than 5 times in total mesh_refinement.max_h_level() = 5; // Initialize the data structures for the equation system. equation_systems.init(); // Refinement parameters const unsigned int max_r_steps = 5; // Refine the mesh 5 times // Define the refinement loop for(unsigned int r_step=0; r_step<=max_r_steps; r_step++) { // Solve the equation system equation_systems.get_system("1D").solve(); // We need to ensure that the mesh is not refined on the last iteration // of this loop, since we do not want to refine the mesh unless we are // going to solve the equation system for that refined mesh. if(r_step != max_r_steps) { // Error estimation objects, see Adaptivity Example 2 for details ErrorVector error; KellyErrorEstimator error_estimator; // Compute the error for each active element error_estimator.estimate_error(system, error); // Output error estimate magnitude libMesh::out << "Error estimate\nl2 norm = " << error.l2_norm() << "\nmaximum = " << error.maximum() << std::endl; // Flag elements to be refined and coarsened mesh_refinement.flag_elements_by_error_fraction (error); // Perform refinement and coarsening mesh_refinement.refine_and_coarsen_elements(); // Reinitialize the equation_systems object for the newly refined // mesh. One of the steps in this is project the solution onto the // new mesh equation_systems.reinit(); } } // Construct gnuplot plotting object, pass in mesh, title of plot // and boolean to indicate use of grid in plot. The grid is used to // show the edges of each element in the mesh. GnuPlotIO plot(mesh,"Adaptivity Example 1", GnuPlotIO::GRID_ON); // Write out script to be called from within gnuplot: // Load gnuplot, then type "call 'gnuplot_script'" from gnuplot prompt plot.write_equation_systems("gnuplot_script",equation_systems); #endif // #ifndef LIBMESH_ENABLE_AMR // All done. libMesh objects are destroyed here. Because the // LibMeshInit object was created first, its destruction occurs // last, and it's destructor finalizes any external libraries and // checks for leaked memory. return 0; }
// Begin the main program. Note that this example only // works correctly if complex numbers have been enabled // in the library. In order to link against the complex // PETSc libraries, you must have built PETSc with the same // C++ compiler that you used to build libMesh. This is // so that the name mangling will be the same for the // routines in both libraries. int main (int argc, char ** argv) { // Initialize libraries, like in example 2. LibMeshInit init (argc, argv); // This example is designed for complex numbers. #ifndef LIBMESH_USE_COMPLEX_NUMBERS libmesh_example_requires(false, "--enable-complex"); #else // Check for proper usage. if (argc < 3) libmesh_error_msg("Usage: " << argv[0] << " -f [frequency]"); if (init.comm().size() > 1) { if (init.comm().rank() == 0) { libMesh::err << "ERROR: Skipping example 7.\n" << "MeshData objects currently only work in serial." << std::endl; } return 0; } // Tell the user what we are doing. else { libMesh::out << "Running " << argv[0]; for (int i=1; i<argc; i++) libMesh::out << " " << argv[i]; libMesh::out << std::endl << std::endl; } // Get the frequency from argv[2] as a <i>float</i>, // currently, solve for 1/3rd, 2/3rd and 1/1th of the given frequency const Real frequency_in = atof(argv[2]); const unsigned int n_frequencies = 3; // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // Create a mesh, with dimension to be overridden later, distributed // across the default MPI communicator. Mesh mesh(init.comm()); // Create a corresponding MeshData // and activate it. For more information on this object // cf. example 12. MeshData mesh_data(mesh); mesh_data.activate(); // Read the mesh file. Here the file lshape.unv contains // an L--shaped domain in .unv format. mesh.read("lshape.unv", &mesh_data); // Print information about the mesh to the screen. mesh.print_info(); // The load on the boundary of the domain is stored in // the .unv formated mesh data file lshape_data.unv. // At this, the data is given as complex valued normal // velocities. mesh_data.read("lshape_data.unv"); // Print information about the mesh to the screen. mesh_data.print_info(); // Create an equation systems object, which now handles // a frequency system, as opposed to previous examples. // Also pass a MeshData pointer so the data can be // accessed in the matrix and rhs assembly. EquationSystems equation_systems (mesh, &mesh_data); // Create a FrequencySystem named "Helmholtz" & store a // reference to it. FrequencySystem & f_system = equation_systems.add_system<FrequencySystem> ("Helmholtz"); // Add the variable "p" to "Helmholtz". "p" // will be approximated using second-order approximation. f_system.add_variable("p", SECOND); // Tell the frequency system about the two user-provided // functions. In other circumstances, at least the // solve function has to be attached. f_system.attach_assemble_function (assemble_helmholtz); f_system.attach_solve_function (add_M_C_K_helmholtz); // To enable the fast solution scheme, additional // <i>global</i> matrices and one global vector, all appropriately sized, // have to be added. The system object takes care of the // appropriate size, but the user should better fill explicitly // the sparsity structure of the overall matrix, so that the // fast matrix addition method can be used, as will be shown later. f_system.add_matrix ("stiffness"); f_system.add_matrix ("damping"); f_system.add_matrix ("mass"); f_system.add_vector ("rhs"); // Communicates the frequencies to the system. Note that // the frequency system stores the frequencies as parameters // in the equation systems object, so that our assemble and solve // functions may directly access them. // Will solve for 1/3rd, 2/3rd and 1/1th of the given frequency f_system.set_frequencies_by_steps (frequency_in/n_frequencies, frequency_in, n_frequencies); // Use the parameters of the equation systems object to // tell the frequency system about the wave velocity and fluid // density. The frequency system provides default values, but // these may be overridden, as shown here. equation_systems.parameters.set<Real> ("wave speed") = 1.; equation_systems.parameters.set<Real> ("rho") = 1.; // Initialize the data structures for the equation system. <i>Always</i> // prior to this, the frequencies have to be communicated to the system. equation_systems.init (); // Prints information about the system to the screen. equation_systems.print_info (); for (unsigned int n=0; n < n_frequencies; n++) { // Solve the system "Helmholtz" for the n-th frequency. // Since we attached an assemble() function to the system, // the mass, damping and stiffness contributions will only // be assembled once. Then, the system is solved for the // given frequencies. Note that solve() may also solve // the system only for specific frequencies. f_system.solve (n, n); // After solving the system, write the solution // to an ExodusII-formatted plot file, for every frequency. #ifdef LIBMESH_HAVE_EXODUS_API char buf[14]; sprintf (buf, "out%04u.exd", n); ExodusII_IO(mesh).write_equation_systems (buf, equation_systems); #endif } // Alternatively, the whole EquationSystems object can be // written to disk. By default, the additional vectors are also // saved. equation_systems.write ("eqn_sys.dat", WRITE); // All done. return 0; #endif }
// The main program. int main (int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // This example NaNs with the Eigen sparse linear solvers and // Trilinos solvers, but should work OK with either PETSc or // Laspack. libmesh_example_requires(libMesh::default_solver_package() != EIGEN_SOLVERS, "--enable-petsc or --enable-laspack"); libmesh_example_requires(libMesh::default_solver_package() != TRILINOS_SOLVERS, "--enable-petsc or --enable-laspack"); // Create a mesh, with dimension to be overridden later, distributed // across the default MPI communicator. Mesh mesh(init.comm()); // Use the MeshTools::Generation mesh generator to create a uniform // 2D grid on the square [-1,1]^2. We instruct the mesh generator // to build a mesh of 8x8 \p Quad9 elements. Building these // higher-order elements allows us to use higher-order // approximation, as in example 3. MeshTools::Generation::build_square (mesh, 15, 15, 0., 1., 0., 1., QUAD9); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a transient system named "Convection-Diffusion" LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Stokes"); // Add the variables "u" & "v" to "Stokes". They // will be approximated using second-order approximation. system.add_variable ("u", SECOND); system.add_variable ("v", SECOND); // Add the variable "p" to "Stokes". This will // be approximated with a first-order basis, // providing an LBB-stable pressure-velocity pair. system.add_variable ("p", FIRST); // Give the system a pointer to the matrix assembly // function. system.attach_assemble_function (assemble_stokes); // Initialize the data structures for the equation system. equation_systems.init (); equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 250; equation_systems.parameters.set<Real> ("linear solver tolerance") = TOLERANCE; // Prints information about the system to the screen. equation_systems.print_info(); // Assemble & solve the linear system, // then write the solution. equation_systems.get_system("Stokes").solve(); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write_equation_systems ("out.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }
// Begin the main program. int main (int argc, char** argv) { // Initialize libMesh and any dependent libaries, like in example 2. LibMeshInit init (argc, argv); // Declare a performance log for the main program // PerfLog perf_main("Main Program"); // Create a GetPot object to parse the command line GetPot command_line (argc, argv); // Check for proper calling arguments. if (argc < 3) { // This handy function will print the file name, line number, // specified message, and then throw an exception. libmesh_error_msg("Usage:\n" << "\t " << argv[0] << " -d 2(3)" << " -n 15"); } // Brief message to the user regarding the program name // and command line arguments. else { std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; } // Read problem dimension from command line. Use int // instead of unsigned since the GetPot overload is ambiguous // otherwise. int dim = 2; if ( command_line.search(1, "-d") ) dim = command_line.next(dim); // Skip higher-dimensional examples on a lower-dimensional libMesh build libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support"); // Create a mesh with user-defined dimension. // Read number of elements from command line int ps = 15; if ( command_line.search(1, "-n") ) ps = command_line.next(ps); // Read FE order from command line std::string order = "SECOND"; if ( command_line.search(2, "-Order", "-o") ) order = command_line.next(order); // Read FE Family from command line std::string family = "LAGRANGE"; if ( command_line.search(2, "-FEFamily", "-f") ) family = command_line.next(family); // Cannot use discontinuous basis. if ((family == "MONOMIAL") || (family == "XYZ")) libmesh_error_msg("ex4 currently requires a C^0 (or higher) FE basis."); // Create a mesh, with dimension to be overridden later, distributed // across the default MPI communicator. Mesh mesh(init.comm()); // Use the MeshTools::Generation mesh generator to create a uniform // grid on the square [-1,1]^D. We instruct the mesh generator // to build a mesh of 8x8 \p Quad9 elements in 2D, or \p Hex27 // elements in 3D. Building these higher-order elements allows // us to use higher-order approximation, as in example 3. Real halfwidth = dim > 1 ? 1. : 0.; Real halfheight = dim > 2 ? 1. : 0.; if ((family == "LAGRANGE") && (order == "FIRST")) { // No reason to use high-order geometric elements if we are // solving with low-order finite elements. MeshTools::Generation::build_cube (mesh, ps, (dim>1) ? ps : 0, (dim>2) ? ps : 0, -1., 1., -halfwidth, halfwidth, -halfheight, halfheight, (dim==1) ? EDGE2 : ((dim == 2) ? QUAD4 : HEX8)); } else { MeshTools::Generation::build_cube (mesh, ps, (dim>1) ? ps : 0, (dim>2) ? ps : 0, -1., 1., -halfwidth, halfwidth, -halfheight, halfheight, (dim==1) ? EDGE3 : ((dim == 2) ? QUAD9 : HEX27)); } // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a system named "Poisson" LinearImplicitSystem& system = equation_systems.add_system<LinearImplicitSystem> ("Poisson"); // Add the variable "u" to "Poisson". "u" // will be approximated using second-order approximation. unsigned int u_var = system.add_variable("u", Utility::string_to_enum<Order> (order), Utility::string_to_enum<FEFamily>(family)); // Give the system a pointer to the matrix assembly // function. system.attach_assemble_function (assemble_poisson); // Construct a Dirichlet boundary condition object // Indicate which boundary IDs we impose the BC on // We either build a line, a square or a cube, and // here we indicate the boundaries IDs in each case std::set<boundary_id_type> boundary_ids; // the dim==1 mesh has two boundaries with IDs 0 and 1 boundary_ids.insert(0); boundary_ids.insert(1); // the dim==2 mesh has four boundaries with IDs 0, 1, 2 and 3 if(dim>=2) { boundary_ids.insert(2); boundary_ids.insert(3); } // the dim==3 mesh has four boundaries with IDs 0, 1, 2, 3, 4 and 5 if(dim==3) { boundary_ids.insert(4); boundary_ids.insert(5); } // Create a vector storing the variable numbers which the BC applies to std::vector<unsigned int> variables(1); variables[0] = u_var; // Create an AnalyticFunction object that we use to project the BC // This function just calls the function exact_solution via exact_solution_wrapper AnalyticFunction<> exact_solution_object(exact_solution_wrapper); DirichletBoundary dirichlet_bc(boundary_ids, variables, &exact_solution_object); // We must add the Dirichlet boundary condition _before_ // we call equation_systems.init() system.get_dof_map().add_dirichlet_boundary(dirichlet_bc); // Initialize the data structures for the equation system. equation_systems.init(); // Print information about the system to the screen. equation_systems.print_info(); mesh.print_info(); // Solve the system "Poisson", just like example 2. system.solve(); // After solving the system write the solution // to a GMV-formatted plot file. if(dim == 1) { GnuPlotIO plot(mesh,"Introduction Example 4, 1D",GnuPlotIO::GRID_ON); plot.write_equation_systems("gnuplot_script",equation_systems); } #ifdef LIBMESH_HAVE_EXODUS_API else { ExodusII_IO (mesh).write_equation_systems ((dim == 3) ? "out_3.e" : "out_2.e",equation_systems); } #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }
// The main program. int main (int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // Parse the input file GetPot infile("fem_system_ex3.in"); // Read in parameters from the input file const bool transient = infile("transient", true); const Real deltat = infile("deltat", 0.25); unsigned int n_timesteps = infile("n_timesteps", 25); #ifdef LIBMESH_HAVE_EXODUS_API const unsigned int write_interval = infile("write_interval", 1); #endif // Initialize the cantilever mesh const unsigned int dim = 3; // Make sure libMesh was compiled for 3D libmesh_example_requires(dim == LIBMESH_DIM, "3D support"); // Create a 3D mesh distributed across the default MPI communicator. Mesh mesh(init.comm(), dim); MeshTools::Generation::build_cube (mesh, 40, 10, 5, 0., 1.*x_scaling, 0., 0.3, 0., 0.1, HEX8); // Print information about the mesh to the screen. mesh.print_info(); // Let's add some node and edge boundary conditions MeshBase::const_element_iterator el = mesh.active_local_elements_begin(); const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end(); for ( ; el != end_el; ++el) { const Elem* elem = *el; unsigned int side_max_x = 0, side_min_y = 0, side_max_y = 0, side_max_z = 0; bool found_side_max_x = false, found_side_max_y = false, found_side_min_y = false, found_side_max_z = false; for(unsigned int side=0; side<elem->n_sides(); side++) { if( mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X)) { side_max_x = side; found_side_max_x = true; } if( mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MIN_Y)) { side_min_y = side; found_side_min_y = true; } if( mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y)) { side_max_y = side; found_side_max_y = true; } if( mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z)) { side_max_z = side; found_side_max_z = true; } } // If elem has sides on boundaries // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z // then let's set a node boundary condition if(found_side_max_x && found_side_max_y && found_side_max_z) { for(unsigned int n=0; n<elem->n_nodes(); n++) { if (elem->is_node_on_side(n, side_max_x) && elem->is_node_on_side(n, side_max_y) && elem->is_node_on_side(n, side_max_z) ) { mesh.get_boundary_info().add_node(elem->get_node(n), NODE_BOUNDARY_ID); } } } // If elem has sides on boundaries // BOUNDARY_ID_MAX_X and BOUNDARY_ID_MIN_Y // then let's set an edge boundary condition if(found_side_max_x && found_side_min_y) { for(unsigned int e=0; e<elem->n_edges(); e++) { if (elem->is_edge_on_side(e, side_max_x) && elem->is_edge_on_side(e, side_min_y) ) { mesh.get_boundary_info().add_edge(elem, e, EDGE_BOUNDARY_ID); } } } } // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system "Navier-Stokes" and its variables. ElasticitySystem & system = equation_systems.add_system<ElasticitySystem> ("Linear Elasticity"); // Create ExplicitSystem to help output velocity ExplicitSystem & v_system = equation_systems.add_system<ExplicitSystem> ("Velocity"); v_system.add_variable("u_vel", FIRST, LAGRANGE); v_system.add_variable("v_vel", FIRST, LAGRANGE); v_system.add_variable("w_vel", FIRST, LAGRANGE); // Create ExplicitSystem to help output acceleration ExplicitSystem & a_system = equation_systems.add_system<ExplicitSystem> ("Acceleration"); a_system.add_variable("u_accel", FIRST, LAGRANGE); a_system.add_variable("v_accel", FIRST, LAGRANGE); a_system.add_variable("w_accel", FIRST, LAGRANGE); // Solve this as a time-dependent or steady system if (transient) system.time_solver = UniquePtr<NewmarkSolver>(new NewmarkSolver(system)); else { system.time_solver = UniquePtr<TimeSolver>(new SteadySolver(system)); libmesh_assert_equal_to (n_timesteps, 1); } // Initialize the system equation_systems.init (); // Set the time stepping options system.deltat = deltat; // And the nonlinear solver options DiffSolver &solver = *(system.time_solver->diff_solver().get()); solver.quiet = infile("solver_quiet", true); solver.verbose = !solver.quiet; solver.max_nonlinear_iterations = infile("max_nonlinear_iterations", 15); solver.relative_step_tolerance = infile("relative_step_tolerance", 1.e-3); solver.relative_residual_tolerance = infile("relative_residual_tolerance", 0.0); solver.absolute_residual_tolerance = infile("absolute_residual_tolerance", 0.0); // And the linear solver options solver.max_linear_iterations = infile("max_linear_iterations", 50000); solver.initial_linear_tolerance = infile("initial_linear_tolerance", 1.e-3); // Print information about the system to the screen. equation_systems.print_info(); NewmarkSolver* newmark = cast_ptr<NewmarkSolver*>(system.time_solver.get()); newmark->compute_initial_accel(); // Copy over initial velocity and acceleration for output. // Note we can do this because of the matching variables/FE spaces (*v_system.solution) = system.get_vector("_old_solution_rate"); (*a_system.solution) = system.get_vector("_old_solution_accel"); #ifdef LIBMESH_HAVE_EXODUS_API // Output initial state { std::ostringstream file_name; // We write the file in the ExodusII format. file_name << "out.e-s." << std::setw(3) << std::setfill('0') << std::right << 0; ExodusII_IO(mesh).write_timestep(file_name.str(), equation_systems, 1, /* This number indicates how many time steps are being written to the file */ system.time); } #endif // #ifdef LIBMESH_HAVE_EXODUS_API // Now we begin the timestep loop to compute the time-accurate // solution of the equations. for (unsigned int t_step=0; t_step != n_timesteps; ++t_step) { // A pretty update message std::cout << "\n\nSolving time step " << t_step << ", time = " << system.time << std::endl; system.solve(); // Advance to the next timestep in a transient problem system.time_solver->advance_timestep(); // Copy over updated velocity and acceleration for output. // Note we can do this because of the matching variables/FE spaces (*v_system.solution) = system.get_vector("_old_solution_rate"); (*a_system.solution) = system.get_vector("_old_solution_accel"); #ifdef LIBMESH_HAVE_EXODUS_API // Write out this timestep if we're requested to if ((t_step+1)%write_interval == 0) { std::ostringstream file_name; // We write the file in the ExodusII format. file_name << "out.e-s." << std::setw(3) << std::setfill('0') << std::right << t_step+1; ExodusII_IO(mesh).write_timestep(file_name.str(), equation_systems, 1, /* This number indicates how many time steps are being written to the file */ system.time); } #endif // #ifdef LIBMESH_HAVE_EXODUS_API } // All done. return 0; }
// The main program. int main (int argc, char ** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // This example uses an ExodusII input file #ifndef LIBMESH_HAVE_EXODUS_API libmesh_example_requires(false, "--enable-exodus"); #endif // The sparsity augmentation code requires PETSc libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc"); // Skip this 3D example if libMesh was compiled as 1D or 2D-only. libmesh_example_requires(3 <= LIBMESH_DIM, "3D support"); GetPot command_line (argc, argv); Real R = 2.; if (command_line.search(1, "-R")) R = command_line.next(R); // Maintaining the right ghost elements on a ParallelMesh is // trickier. SerialMesh mesh(init.comm()); mesh.read("miscellaneous_ex9.exo"); EquationSystems equation_systems (mesh); LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Poisson"); system.add_variable("u", FIRST, LAGRANGE); // We want to call assemble_poisson "manually" so that we can pass in // lower_to_upper, hence set assemble_before_solve = false system.assemble_before_solve = false; // Impose zero Dirichlet boundary condition on MAX_Z_BOUNDARY std::set<boundary_id_type> boundary_ids; boundary_ids.insert(MAX_Z_BOUNDARY); std::vector<unsigned int> variables; variables.push_back(0); ZeroFunction<> zf; DirichletBoundary dirichlet_bc(boundary_ids, variables, &zf); system.get_dof_map().add_dirichlet_boundary(dirichlet_bc); // Attach an object to the DofMap that will augment the sparsity pattern // due to the degrees-of-freedom on the "crack" AugmentSparsityOnInterface augment_sparsity(equation_systems, CRACK_BOUNDARY_LOWER, CRACK_BOUNDARY_UPPER); system.get_dof_map().attach_extra_sparsity_object(augment_sparsity); equation_systems.init(); equation_systems.print_info(); // Set the jump term coefficient, it will be used in assemble_poisson equation_systems.parameters.set<Real>("R") = R; // Assemble and then solve assemble_poisson(equation_systems, augment_sparsity.get_lower_to_upper()); system.solve(); #ifdef LIBMESH_HAVE_EXODUS_API // Plot the solution ExodusII_IO (mesh).write_equation_systems ("solution.exo", equation_systems); #endif return 0; }
// Begin the main program. int main (int argc, char ** argv) { // Initialize libMesh and any dependent libaries LibMeshInit init (argc, argv); // Initialize the cantilever mesh const unsigned int dim = 2; // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(dim <= LIBMESH_DIM, "2D support"); // Create a 2D mesh distributed across the default MPI communicator. Mesh mesh(init.comm(), dim); MeshTools::Generation::build_square (mesh, 50, 10, 0., 1., 0., 0.2, QUAD9); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a system named "Elasticity" LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Elasticity"); // Add two displacement variables, u and v, to the system unsigned int u_var = system.add_variable("u", SECOND, LAGRANGE); unsigned int v_var = system.add_variable("v", SECOND, LAGRANGE); system.attach_assemble_function (assemble_elasticity); // Construct a Dirichlet boundary condition object // We impose a "clamped" boundary condition on the // "left" boundary, i.e. bc_id = 3 std::set<boundary_id_type> boundary_ids; boundary_ids.insert(3); // Create a vector storing the variable numbers which the BC applies to std::vector<unsigned int> variables(2); variables[0] = u_var; variables[1] = v_var; // Create a ZeroFunction to initialize dirichlet_bc ZeroFunction<> zf; // Most DirichletBoundary users will want to supply a "locally // indexed" functor DirichletBoundary dirichlet_bc(boundary_ids, variables, zf, LOCAL_VARIABLE_ORDER); // We must add the Dirichlet boundary condition _before_ // we call equation_systems.init() system.get_dof_map().add_dirichlet_boundary(dirichlet_bc); // Initialize the data structures for the equation system. equation_systems.init(); // Print information about the system to the screen. equation_systems.print_info(); // Solve the system system.solve(); // Plot the solution #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO (mesh).write_equation_systems("displacement.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }
int main (int argc, char ** argv) { // Initialize libMesh and the dependent libraries. LibMeshInit init (argc, argv); // This example is designed for the SLEPc eigen solver interface. #ifndef LIBMESH_HAVE_SLEPC if (init.comm().rank() == 0) libMesh::err << "ERROR: This example requires libMesh to be\n" << "compiled with SLEPc eigen solvers support!" << std::endl; return 0; #else #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION // SLEPc currently gives us a nasty crash with Real==float libmesh_example_requires(false, "--disable-singleprecision"); #endif // Check for proper usage. if (argc < 3) libmesh_error_msg("\nUsage: " << argv[0] << " -n <number of eigen values>"); // Tell the user what we are doing. else { libMesh::out << "Running " << argv[0]; for (int i=1; i<argc; i++) libMesh::out << " " << argv[i]; libMesh::out << std::endl << std::endl; } // Get the number of eigen values to be computed from argv[2] const unsigned int nev = std::atoi(argv[2]); // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // Create a mesh, with dimension to be overridden later, on the // default MPI communicator. Mesh mesh(init.comm()); // Use the internal mesh generator to create a uniform // 2D grid on a square. MeshTools::Generation::build_square (mesh, 20, 20, -1., 1., -1., 1., QUAD4); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Create a EigenSystem named "Eigensystem" and (for convenience) // use a reference to the system we create. EigenSystem & eigen_system = equation_systems.add_system<EigenSystem> ("Eigensystem"); // Declare the system variables. // Adds the variable "p" to "Eigensystem". "p" // will be approximated using second-order approximation. eigen_system.add_variable("p", FIRST); // Give the system a pointer to the matrix assembly // function defined below. eigen_system.attach_assemble_function (assemble_mass); // Set necessary parametrs used in EigenSystem::solve(), // i.e. the number of requested eigenpairs nev and the number // of basis vectors ncv used in the solution algorithm. Note that // ncv >= nev must hold and ncv >= 2*nev is recommended. equation_systems.parameters.set<unsigned int>("eigenpairs") = nev; equation_systems.parameters.set<unsigned int>("basis vectors") = nev*3; // You may optionally change the default eigensolver used by SLEPc. // The Krylov-Schur method is mathematically equivalent to implicitly // restarted Arnoldi, the method of Arpack, so there is currently no // point in using SLEPc with Arpack. // ARNOLDI = default in SLEPc 2.3.1 and earlier // KRYLOVSCHUR default in SLEPc 2.3.2 and later // eigen_system.eigen_solver->set_eigensolver_type(KRYLOVSCHUR); // Set the solver tolerance and the maximum number of iterations. equation_systems.parameters.set<Real>("linear solver tolerance") = pow(TOLERANCE, 5./3.); equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 1000; // Set the type of the problem, here we deal with // a generalized Hermitian problem. eigen_system.set_eigenproblem_type(GHEP); // Set the eigenvalues to be computed. Note that not // all solvers support this. // eigen_system.eigen_solver->set_position_of_spectrum(SMALLEST_MAGNITUDE); // Initialize the data structures for the equation system. equation_systems.init(); // Prints information about the system to the screen. equation_systems.print_info(); // Solve the system "Eigensystem". eigen_system.solve(); // Get the number of converged eigen pairs. unsigned int nconv = eigen_system.get_n_converged(); libMesh::out << "Number of converged eigenpairs: " << nconv << "\n" << std::endl; // Get the last converged eigenpair if (nconv != 0) { eigen_system.get_eigenpair(nconv-1); #ifdef LIBMESH_HAVE_EXODUS_API // Write the eigen vector to file. ExodusII_IO (mesh).write_equation_systems ("out.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API } else { libMesh::out << "WARNING: Solver did not converge!\n" << nconv << std::endl; } #endif // LIBMESH_HAVE_SLEPC // All done. return 0; }
// The main program. int main (int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // Parse the input file GetPot infile("vector_fe_ex4.in"); // Read in parameters from the input file const unsigned int grid_size = infile( "grid_size", 2 ); // Skip higher-dimensional examples on a lower-dimensional libMesh build libmesh_example_requires(3 <= LIBMESH_DIM, "2D/3D support"); // Create a mesh, with dimension to be overridden later, on the // default MPI communicator. Mesh mesh(init.comm()); // Use the MeshTools::Generation mesh generator to create a uniform // grid on the square [-1,1]^D. We must use TRI6 elements for the // Nedelec triangle elements. std::string elem_str = command_line_value( std::string("element_type"), std::string("HEX27") ); if( elem_str != "HEX20" && elem_str != "HEX27" ) libmesh_error_msg("You entered: " \ << elem_str \ << " but this example must be run with HEX20 or HEX27."); MeshTools::Generation::build_cube (mesh, grid_size, grid_size, grid_size, -1., 1, -1., 1., -1., 1, Utility::string_to_enum<ElemType>(elem_str)); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system "Navier-Stokes" and its variables. CurlCurlSystem & system = equation_systems.add_system<CurlCurlSystem> ("CurlCurl"); // This example only implements the steady-state problem system.time_solver = UniquePtr<TimeSolver>(new SteadySolver(system)); // Initialize the system equation_systems.init(); // And the nonlinear solver options DiffSolver &solver = *(system.time_solver->diff_solver().get()); solver.quiet = infile("solver_quiet", true); solver.verbose = !solver.quiet; solver.max_nonlinear_iterations = infile("max_nonlinear_iterations", 15); solver.relative_step_tolerance = infile("relative_step_tolerance", 1.e-3); solver.relative_residual_tolerance = infile("relative_residual_tolerance", 1.0e-13); solver.absolute_residual_tolerance = infile("absolute_residual_tolerance", 0.0); // And the linear solver options solver.max_linear_iterations = infile("max_linear_iterations", 50000); solver.initial_linear_tolerance = infile("initial_linear_tolerance", 1.e-10); // Print information about the system to the screen. equation_systems.print_info(); system.solve(); ExactSolution exact_sol( equation_systems ); std::vector<FunctionBase<Number>* > sols; std::vector<FunctionBase<Gradient>* > grads; sols.push_back( new SolutionFunction(system.variable_number("u")) ); grads.push_back( new SolutionGradient(system.variable_number("u")) ); exact_sol.attach_exact_values(sols); exact_sol.attach_exact_derivs(grads); // Use higher quadrature order for more accurate error results int extra_error_quadrature = infile("extra_error_quadrature",2); exact_sol.extra_quadrature_order(extra_error_quadrature); // Compute the error. exact_sol.compute_error("CurlCurl", "u"); // Print out the error values std::cout << "L2-Error is: " << exact_sol.l2_error("CurlCurl", "u") << std::endl; std::cout << "HCurl semi-norm error is: " << exact_sol.error_norm("CurlCurl", "u", HCURL_SEMINORM ) << std::endl; std::cout << "HCurl-Error is: " << exact_sol.hcurl_error("CurlCurl", "u") << std::endl; #ifdef LIBMESH_HAVE_EXODUS_API // We write the file in the ExodusII format. ExodusII_IO(mesh).write_equation_systems("out.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }
// Begin the main program. int main (int argc, char** argv) { // Initialize libMesh and any dependent libaries, like in example 2. LibMeshInit init (argc, argv); // Declare a performance log for the main program // PerfLog perf_main("Main Program"); // Create a GetPot object to parse the command line GetPot command_line (argc, argv); // Check for proper calling arguments. if (argc < 3) { if (libMesh::processor_id() == 0) std::cerr << "Usage:\n" <<"\t " << argv[0] << " -d 2(3)" << " -n 15" << std::endl; // This handy function will print the file name, line number, // and then abort. Currrently the library does not use C++ // exception handling. libmesh_error(); } // Brief message to the user regarding the program name // and command line arguments. else { std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; } // Read problem dimension from command line. Use int // instead of unsigned since the GetPot overload is ambiguous // otherwise. int dim = 3; std::string order = "FIRST"; std::string family = "LAGRANGE"; // Create a mesh, with dimension to be overridden later, distributed // across the default MPI communicator. Mesh mesh(init.comm()); // Use the MeshTools::Generation mesh generator to create a uniform mesh.read("man.e"); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a system named "Poisson" LinearImplicitSystem& system = equation_systems.add_system<LinearImplicitSystem> ("Poisson"); // Add the variable "u" to "Poisson". "u" // will be approximated using second-order approximation. unsigned int u_var = system.add_variable("u", Utility::string_to_enum<Order> (order), Utility::string_to_enum<FEFamily>(family)); Poisson poisson(equation_systems); // Give the system a pointer to the matrix assembly // function. system.attach_assemble_object (poisson); // Construct a Dirichlet boundary condition object // Indicate which boundary IDs we impose the BC on // We either build a line, a square or a cube, and // here we indicate the boundaries IDs in each case std::set<boundary_id_type> one_ids, zero_ids; one_ids.insert(2); zero_ids.insert(3); zero_ids.insert(4); zero_ids.insert(5); zero_ids.insert(6); // Create a vector storing the variable numbers which the BC applies to std::vector<unsigned int> variables(1); variables[0] = u_var; // Create an AnalyticFunction object that we use to project the BC AnalyticFunction<> one_solution_object(one_func); AnalyticFunction<> zero_solution_object(zero_func); DirichletBoundary one_bc(one_ids, variables, &one_solution_object); DirichletBoundary zero_bc(zero_ids, variables, &zero_solution_object); // We must add the Dirichlet boundary condition _before_ // we call equation_systems.init() system.get_dof_map().add_dirichlet_boundary(one_bc); system.get_dof_map().add_dirichlet_boundary(zero_bc); // Initialize the data structures for the equation system. equation_systems.init(); // Print information about the system to the screen. equation_systems.print_info(); mesh.print_info(); // Solve the system "Poisson", just like example 2. system.solve(); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO (mesh).write_equation_systems ("out.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }
int main (int argc, char ** argv) { // Initialize libMesh and the dependent libraries. LibMeshInit init (argc, argv); // This example uses an ExodusII input file #ifndef LIBMESH_HAVE_EXODUS_API libmesh_example_requires(false, "--enable-exodus"); #endif // This example is designed for the SLEPc eigen solver interface. #ifndef LIBMESH_HAVE_SLEPC if (init.comm().rank() == 0) libMesh::err << "ERROR: This example requires libMesh to be\n" << "compiled with SLEPc eigen solvers support!" << std::endl; return 0; #else #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION // SLEPc currently gives us a nasty crash with Real==float libmesh_example_requires(false, "--disable-singleprecision"); #endif #if defined(LIBMESH_USE_COMPLEX_NUMBERS) && SLEPC_VERSION_LESS_THAN(3,6,2) // SLEPc used to give us an "inner product not well defined" with // Number==complex; but this problem seems to be solved in newer versions. libmesh_example_requires(false, "--disable-complex or use SLEPc>=3.6.2"); #endif // Tell the user what we are doing. { libMesh::out << "Running " << argv[0]; for (int i=1; i<argc; i++) libMesh::out << " " << argv[i]; libMesh::out << std::endl << std::endl; } // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // Use GetPot to parse the command line arguments GetPot command_line (argc, argv); // Read the mesh name from the command line std::string mesh_name = ""; if (command_line.search(1, "-mesh_name")) mesh_name = command_line.next(mesh_name); // Also, read in the index of the eigenvector that we should plot // (zero-based indexing, as usual!) unsigned int plotting_index = 0; if (command_line.search(1, "-plotting_index")) plotting_index = command_line.next(plotting_index); // Finally, read in the number of eigenpairs we want to compute! unsigned int n_evals = 0; if (command_line.search(1, "-n_evals")) n_evals = command_line.next(n_evals); // Append the .e to mesh_name std::ostringstream mesh_name_exodus; mesh_name_exodus << mesh_name << "_mesh.e"; // Create a mesh, with dimension to be overridden by the file, on // the default MPI communicator. Mesh mesh(init.comm()); mesh.read(mesh_name_exodus.str()); // Add boundary IDs to this mesh so that we can use DirichletBoundary // Each processor should know about each boundary condition it can // see, so we loop over all elements, not just local elements. for (const auto & elem : mesh.element_ptr_range()) for (auto side : elem->side_index_range()) if (elem->neighbor_ptr (side) == nullptr) mesh.get_boundary_info().add_side(elem, side, BOUNDARY_ID); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Create a CondensedEigenSystem named "Eigensystem" and (for convenience) // use a reference to the system we create. CondensedEigenSystem & eigen_system = equation_systems.add_system<CondensedEigenSystem> ("Eigensystem"); // Declare the system variables. // Adds the variable "p" to "Eigensystem". "p" // will be approximated using second-order approximation. eigen_system.add_variable("p", SECOND); // Give the system a pointer to the matrix assembly // function defined below. eigen_system.attach_assemble_function (assemble_matrices); // Set the number of requested eigenpairs n_evals and the number // of basis vectors used in the solution algorithm. equation_systems.parameters.set<unsigned int>("eigenpairs") = n_evals; equation_systems.parameters.set<unsigned int>("basis vectors") = n_evals*3; // Set the solver tolerance and the maximum number of iterations. equation_systems.parameters.set<Real>("linear solver tolerance") = pow(TOLERANCE, 5./3.); equation_systems.parameters.set<unsigned int> ("linear solver maximum iterations") = 1000; // Set the type of the problem, here we deal with // a generalized Hermitian problem. eigen_system.set_eigenproblem_type(GHEP); // Set the target eigenvalue eigen_system.eigen_solver->set_position_of_spectrum(0., TARGET_REAL); { std::set<boundary_id_type> boundary_ids; boundary_ids.insert(BOUNDARY_ID); std::vector<unsigned int> variables; variables.push_back(0); ZeroFunction<> zf; // Most DirichletBoundary users will want to supply a "locally // indexed" functor DirichletBoundary dirichlet_bc(boundary_ids, variables, zf, LOCAL_VARIABLE_ORDER); eigen_system.get_dof_map().add_dirichlet_boundary(dirichlet_bc); } // Initialize the data structures for the equation system. equation_systems.init(); // Prints information about the system to the screen. equation_systems.print_info(); eigen_system.initialize_condensed_dofs(); // Solve the system "Eigensystem". eigen_system.solve(); // Get the number of converged eigen pairs. unsigned int nconv = eigen_system.get_n_converged(); libMesh::out << "Number of converged eigenpairs: " << nconv << "\n" << std::endl; if (plotting_index > n_evals) { libMesh::out << "WARNING: Solver did not converge for the requested eigenvector!" << std::endl; } // write out all of the computed eigenvalues and plot the specified eigenvector std::ostringstream eigenvalue_output_name; eigenvalue_output_name << mesh_name << "_evals.txt"; std::ofstream evals_file(eigenvalue_output_name.str().c_str()); for (unsigned int i=0; i<nconv; i++) { std::pair<Real,Real> eval = eigen_system.get_eigenpair(i); // The eigenvalues should be real! libmesh_assert_less (eval.second, TOLERANCE); evals_file << eval.first << std::endl; // plot the specified eigenvector if (i == plotting_index) { #ifdef LIBMESH_HAVE_EXODUS_API // Write the eigen vector to file. std::ostringstream eigenvector_output_name; eigenvector_output_name << mesh_name << "_evec.e"; ExodusII_IO (mesh).write_equation_systems (eigenvector_output_name.str(), equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API } } evals_file.close(); #endif // LIBMESH_HAVE_SLEPC // All done. return 0; }
// Begin the main program. int main (int argc, char ** argv) { // Initialize libMesh, like in example 2. LibMeshInit init (argc, argv); // This example requires Infinite Elements #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS libmesh_example_requires(false, "--enable-ifem"); #else // Skip this 3D example if libMesh was compiled as 1D/2D-only. libmesh_example_requires(3 <= LIBMESH_DIM, "3D support"); // Tell the user what we are doing. libMesh::out << "Running ex6 with dim = 3" << std::endl << std::endl; // Create a serialized mesh, distributed across the default MPI // communicator. // InfElemBuilder still requires some updates to be ParallelMesh // compatible SerialMesh mesh(init.comm()); // Use the internal mesh generator to create elements // on the square [-1,1]^3, of type Hex8. MeshTools::Generation::build_cube (mesh, 4, 4, 4, -1., 1., -1., 1., -1., 1., HEX8); // Print information about the mesh to the screen. mesh.print_info(); // Write the mesh before the infinite elements are added #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write ("orig_mesh.e"); #endif // Normally, when a mesh is imported or created in // libMesh, only conventional elements exist. The infinite // elements used here, however, require prescribed // nodal locations (with specified distances from an imaginary // origin) and configurations that a conventional mesh creator // in general does not offer. Therefore, an efficient method // for building infinite elements is offered. It can account // for symmetry planes and creates infinite elements in a fully // automatic way. // // Right now, the simplified interface is used, automatically // determining the origin. Check \p MeshBase for a generalized // method that can even return the element faces of interior // vibrating surfaces. The \p bool determines whether to be // verbose. InfElemBuilder builder(mesh); builder.build_inf_elem(true); // Print information about the mesh to the screen. mesh.print_info(); // Write the mesh with the infinite elements added. // Compare this to the original mesh. #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write ("ifems_added.e"); #endif // After building infinite elements, we have to let // the elements find their neighbors again. mesh.find_neighbors(); // Create an equation systems object, where \p ThinSystem // offers only the crucial functionality for solving a // system. Use \p ThinSystem when you want the sleekest // system possible. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a system named "Wave". This can // be a simple, steady system equation_systems.add_system<LinearImplicitSystem> ("Wave"); // Create an FEType describing the approximation // characteristics of the InfFE object. Note that // the constructor automatically defaults to some // sensible values. But use \p FIRST order // approximation. FEType fe_type(FIRST); // Add the variable "p" to "Wave". Note that there exist // various approaches in adding variables. In example 3, // \p add_variable took the order of approximation and used // default values for the \p FEFamily, while here the \p FEType // is used. equation_systems.get_system("Wave").add_variable("p", fe_type); // Give the system a pointer to the matrix assembly // function. equation_systems.get_system("Wave").attach_assemble_function (assemble_wave); // Set the speed of sound and fluid density // as \p EquationSystems parameter, // so that \p assemble_wave() can access it. equation_systems.parameters.set<Real>("speed") = 1.; equation_systems.parameters.set<Real>("fluid density") = 1.; // Initialize the data structures for the equation system. equation_systems.init(); // Prints information about the system to the screen. equation_systems.print_info(); // Solve the system "Wave". equation_systems.get_system("Wave").solve(); // Write the whole EquationSystems object to file. // For infinite elements, the concept of nodal_soln() // is not applicable. Therefore, writing the mesh in // some format @e always gives all-zero results at // the nodes of the infinite elements. Instead, // use the FEInterface::compute_data() methods to // determine physically correct results within an // infinite element. equation_systems.write ("eqn_sys.dat", WRITE); // All done. return 0; #endif // else part of ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS }
// The main program. int main (int argc, char ** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // This example requires a linear solver package. libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE, "--enable-petsc, --enable-trilinos, or --enable-eigen"); #if !defined(LIBMESH_HAVE_XDR) // We need XDR support to write out reduced bases libmesh_example_requires(false, "--enable-xdr"); #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION) // XDR binary support requires double precision libmesh_example_requires(false, "--disable-singleprecision"); #endif // FIXME: This example currently segfaults with Trilinos? It works // with PETSc and Eigen sparse linear solvers though. libmesh_example_requires(libMesh::default_solver_package() != TRILINOS_SOLVERS, "--enable-petsc"); // Skip this 2D example if libMesh was compiled as 1D-only. libmesh_example_requires(2 <= LIBMESH_DIM, "2D support"); // Parse the input file (reduced_basis_ex1.in) using GetPot std::string parameters_filename = "reduced_basis_ex1.in"; GetPot infile(parameters_filename); unsigned int n_elem = infile("n_elem", 1); // Determines the number of elements in the "truth" mesh const unsigned int dim = 2; // The number of spatial dimensions bool store_basis_functions = infile("store_basis_functions", true); // Do we write the RB basis functions to disk? // Read the "online_mode" flag from the command line GetPot command_line (argc, argv); int online_mode = 0; if (command_line.search(1, "-online_mode")) online_mode = command_line.next(online_mode); // Build a mesh on the default MPI communicator. Mesh mesh (init.comm(), dim); MeshTools::Generation::build_square (mesh, n_elem, n_elem, 0., 1., 0., 1., QUAD4); // Create an equation systems object. EquationSystems equation_systems (mesh); // We override RBConstruction with SimpleRBConstruction in order to // specialize a few functions for this particular problem. SimpleRBConstruction & rb_con = equation_systems.add_system<SimpleRBConstruction> ("RBConvectionDiffusion"); // Initialize the data structures for the equation system. equation_systems.init (); // Print out some information about the "truth" discretization equation_systems.print_info(); mesh.print_info(); // Build a new RBEvaluation object which will be used to perform // Reduced Basis calculations. This is required in both the // "Offline" and "Online" stages. SimpleRBEvaluation rb_eval(mesh.comm()); // We need to give the RBConstruction object a pointer to // our RBEvaluation object rb_con.set_rb_evaluation(rb_eval); if (!online_mode) // Perform the Offline stage of the RB method { // Read in the data that defines this problem from the specified text file rb_con.process_parameters_file(parameters_filename); // Print out info that describes the current setup of rb_con rb_con.print_info(); // Prepare rb_con for the Construction stage of the RB method. // This sets up the necessary data structures and performs // initial assembly of the "truth" affine expansion of the PDE. rb_con.initialize_rb_construction(); // Compute the reduced basis space by computing "snapshots", i.e. // "truth" solves, at well-chosen parameter values and employing // these snapshots as basis functions. rb_con.train_reduced_basis(); // Write out the data that will subsequently be required for the Evaluation stage #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_con.get_rb_evaluation()); rb_eval_writer.write_to_file("rb_eval.bin"); #else rb_con.get_rb_evaluation().legacy_write_offline_data_to_files(); #endif // If requested, write out the RB basis functions for visualization purposes if (store_basis_functions) { // Write out the basis functions rb_con.get_rb_evaluation().write_out_basis_functions(rb_con); } // Basis functions should be orthonormal, so // print out the inner products to check this rb_con.print_basis_function_orthogonality(); } else // Perform the Online stage of the RB method { // Read in the reduced basis data #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataDeserialization::RBEvaluationDeserialization rb_eval_reader(rb_eval); rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true); #else rb_eval.legacy_read_offline_data_from_files(); #endif // Read in online_N and initialize online parameters unsigned int online_N = infile("online_N", 1); Real online_x_vel = infile("online_x_vel", 0.); Real online_y_vel = infile("online_y_vel", 0.); RBParameters online_mu; online_mu.set_value("x_vel", online_x_vel); online_mu.set_value("y_vel", online_y_vel); rb_eval.set_parameters(online_mu); rb_eval.print_parameters(); // Now do the Online solve using the precomputed reduced basis rb_eval.rb_solve(online_N); // Print out outputs as well as the corresponding output error bounds. libMesh::out << "output 1, value = " << rb_eval.RB_outputs[0] << ", bound = " << rb_eval.RB_output_error_bounds[0] << std::endl; libMesh::out << "output 2, value = " << rb_eval.RB_outputs[1] << ", bound = " << rb_eval.RB_output_error_bounds[1] << std::endl; libMesh::out << "output 3, value = " << rb_eval.RB_outputs[2] << ", bound = " << rb_eval.RB_output_error_bounds[2] << std::endl; libMesh::out << "output 4, value = " << rb_eval.RB_outputs[3] << ", bound = " << rb_eval.RB_output_error_bounds[3] << std::endl << std::endl; if (store_basis_functions) { // Read in the basis functions rb_eval.read_in_basis_functions(rb_con); // Plot the solution rb_con.load_rb_solution(); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write_equation_systems ("RB_sol.e", equation_systems); #endif // Plot the first basis function that was generated from the train_reduced_basis // call in the Offline stage rb_con.load_basis_function(0); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write_equation_systems ("bf0.e", equation_systems); #endif } } return 0; }
// Begin the main program. int main (int argc, char ** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); // This example requires a linear solver package. libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE, "--enable-petsc, --enable-trilinos, or --enable-eigen"); // Skip this 3D example if libMesh was compiled as 1D/2D-only. libmesh_example_requires (3 == LIBMESH_DIM, "3D support"); // Skip this example without --enable-node-valence #ifndef LIBMESH_ENABLE_NODE_VALENCE libmesh_example_requires (false, "--enable-node-valence"); #endif // Skip this example without --enable-amr; requires MeshRefinement #ifndef LIBMESH_ENABLE_AMR libmesh_example_requires(false, "--enable-amr"); #else // Skip this example without --enable-second; requires d2phi #ifndef LIBMESH_ENABLE_SECOND_DERIVATIVES libmesh_example_requires(false, "--enable-second"); #else // Create a 2D mesh distributed across the default MPI communicator. // Subdivision surfaces do not appear to work with DistributedMesh yet. ReplicatedMesh mesh (init.comm(), 2); // Read the coarse square mesh. mesh.read ("square_mesh.off"); // Resize the square plate to edge length L. const Real L = 100.; MeshTools::Modification::scale(mesh, L, L, L); // Quadrisect the mesh triangles a few times to obtain a // finer mesh. Subdivision surface elements require the // refinement data to be removed afterward. MeshRefinement mesh_refinement (mesh); mesh_refinement.uniformly_refine (3); MeshTools::Modification::flatten (mesh); // Write the mesh before the ghost elements are added. #if defined(LIBMESH_HAVE_VTK) VTKIO(mesh).write ("without_ghosts.pvtu"); #endif #if defined(LIBMESH_HAVE_EXODUS_API) ExodusII_IO(mesh).write ("without_ghosts.e"); #endif // Print information about the triangulated mesh to the screen. mesh.print_info(); // Turn the triangulated mesh into a subdivision mesh // and add an additional row of "ghost" elements around // it in order to complete the extended local support of // the triangles at the boundaries. If the second // argument is set to true, the outermost existing // elements are converted into ghost elements, and the // actual physical mesh is thus getting smaller. MeshTools::Subdivision::prepare_subdivision_mesh (mesh, false); // Print information about the subdivision mesh to the screen. mesh.print_info(); // Write the mesh with the ghost elements added. // Compare this to the original mesh to see the difference. #if defined(LIBMESH_HAVE_VTK) VTKIO(mesh).write ("with_ghosts.pvtu"); #endif #if defined(LIBMESH_HAVE_EXODUS_API) ExodusII_IO(mesh).write ("with_ghosts.e"); #endif // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a linear implicit system named "Shell". LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Shell"); // Add the three translational deformation variables // "u", "v", "w" to "Shell". Since subdivision shell // elements meet the C1-continuity requirement, no // rotational or other auxiliary variables are needed. // Loop Subdivision Elements are always interpolated // by quartic box splines, hence the order must always // be FOURTH. system.add_variable ("u", FOURTH, SUBDIVISION); system.add_variable ("v", FOURTH, SUBDIVISION); system.add_variable ("w", FOURTH, SUBDIVISION); // Give the system a pointer to the matrix and rhs assembly // function. system.attach_assemble_function (assemble_shell); // Use the parameters of the equation systems object to // tell the shell system about the material properties, the // shell thickness, and the external load. const Real h = 1.; const Real E = 1.e7; const Real nu = 0.; const Real q = 1.; equation_systems.parameters.set<Real> ("thickness") = h; equation_systems.parameters.set<Real> ("young's modulus") = E; equation_systems.parameters.set<Real> ("poisson ratio") = nu; equation_systems.parameters.set<Real> ("uniform load") = q; // Initialize the data structures for the equation system. equation_systems.init(); // Print information about the system to the screen. equation_systems.print_info(); // Solve the linear system. system.solve(); // After solving the system, write the solution to a VTK // or ExodusII output file ready for import in, e.g., // Paraview. #if defined(LIBMESH_HAVE_VTK) VTKIO(mesh).write_equation_systems ("out.pvtu", equation_systems); #endif #if defined(LIBMESH_HAVE_EXODUS_API) ExodusII_IO(mesh).write_equation_systems ("out.e", equation_systems); #endif // Find the center node to measure the maximum deformation of the plate. Node * center_node = 0; Real nearest_dist_sq = mesh.point(0).norm_sq(); for (unsigned int nid=1; nid<mesh.n_nodes(); ++nid) { const Real dist_sq = mesh.point(nid).norm_sq(); if (dist_sq < nearest_dist_sq) { nearest_dist_sq = dist_sq; center_node = mesh.node_ptr(nid); } } // Finally, we evaluate the z-displacement "w" at the center node. const unsigned int w_var = system.variable_number ("w"); dof_id_type w_dof = center_node->dof_number (system.number(), w_var, 0); Number w = 0; if (w_dof >= system.get_dof_map().first_dof() && w_dof < system.get_dof_map().end_dof()) w = system.current_solution(w_dof); system.comm().sum(w); // The analytic solution for the maximum displacement of // a clamped square plate in pure bending, from Taylor, // Govindjee, Commun. Numer. Meth. Eng. 20, 757-765, 2004. const Real D = E * h*h*h / (12*(1-nu*nu)); const Real w_analytic = 0.001265319 * L*L*L*L * q / D; // Print the finite element solution and the analytic // prediction of the maximum displacement of the clamped // square plate to the screen. libMesh::out << "z-displacement of the center point: " << w << std::endl; libMesh::out << "Analytic solution for pure bending: " << w_analytic << std::endl; #endif // #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES #endif // #ifdef LIBMESH_ENABLE_AMR // All done. return 0; }
// The main program. int main (int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); #if !defined(LIBMESH_HAVE_XDR) // We need XDR support to write out reduced bases libmesh_example_requires(false, "--enable-xdr"); #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION) // XDR binary support requires double precision libmesh_example_requires(false, "--disable-singleprecision"); #elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION) // I have no idea why long double isn't working here... [RHS] libmesh_example_requires(false, "double precision"); #endif // This is a 3D example libmesh_example_requires(3 == LIBMESH_DIM, "3D support"); // Parse the input file using GetPot std::string eim_parameters = "eim.in"; std::string rb_parameters = "rb.in"; std::string main_parameters = "reduced_basis_ex6.in"; GetPot infile(main_parameters); unsigned int n_elem_xy = infile("n_elem_xy", 1); unsigned int n_elem_z = infile("n_elem_z", 1); // Do we write the RB basis functions to disk? bool store_basis_functions = infile("store_basis_functions", true); // Read the "online_mode" flag from the command line GetPot command_line (argc, argv); int online_mode = 0; if ( command_line.search(1, "-online_mode") ) online_mode = command_line.next(online_mode); // Create a mesh, with dimension to be overridden by build_cube, on // the default MPI communicator. We currently have to create a // SerialMesh here due to a reduced_basis regression with // ParallelMesh SerialMesh mesh(init.comm()); MeshTools::Generation::build_cube (mesh, n_elem_xy, n_elem_xy, n_elem_z, -0.2, 0.2, -0.2, 0.2, 0., 3., HEX8); // Create an equation systems object. EquationSystems equation_systems (mesh); SimpleEIMConstruction & eim_construction = equation_systems.add_system<SimpleEIMConstruction> ("EIM"); SimpleRBConstruction & rb_construction = equation_systems.add_system<SimpleRBConstruction> ("RB"); // Initialize the data structures for the equation system. equation_systems.init (); // Print out some information about the "truth" discretization equation_systems.print_info(); mesh.print_info(); // Initialize the standard RBEvaluation object SimpleRBEvaluation rb_eval(mesh.comm()); // Initialize the EIM RBEvaluation object SimpleEIMEvaluation eim_rb_eval(mesh.comm()); // Set the rb_eval objects for the RBConstructions eim_construction.set_rb_evaluation(eim_rb_eval); rb_construction.set_rb_evaluation(rb_eval); if(!online_mode) // Perform the Offline stage of the RB method { // Read data from input file and print state eim_construction.process_parameters_file(eim_parameters); eim_construction.print_info(); // Perform the EIM Greedy and write out the data eim_construction.initialize_rb_construction(); eim_construction.train_reduced_basis(); #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataSerialization::RBEIMEvaluationSerialization rb_eim_eval_writer(eim_rb_eval); rb_eim_eval_writer.write_to_file("rb_eim_eval.bin"); #else eim_construction.get_rb_evaluation().legacy_write_offline_data_to_files("eim_data"); #endif // Read data from input file and print state rb_construction.process_parameters_file(rb_parameters); // attach the EIM theta objects to the RBEvaluation eim_rb_eval.initialize_eim_theta_objects(); rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects()); // attach the EIM assembly objects to the RBConstruction eim_construction.initialize_eim_assembly_objects(); rb_construction.get_rb_assembly_expansion().attach_multiple_A_assembly(eim_construction.get_eim_assembly_objects()); // Print out the state of rb_construction now that the EIM objects have been attached rb_construction.print_info(); // Need to initialize _after_ EIM greedy so that // the system knows how many affine terms there are rb_construction.initialize_rb_construction(); rb_construction.train_reduced_basis(); #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_construction.get_rb_evaluation()); rb_eval_writer.write_to_file("rb_eval.bin"); #else rb_construction.get_rb_evaluation().legacy_write_offline_data_to_files("rb_data"); #endif // Write out the basis functions, if requested if(store_basis_functions) { // Write out the basis functions eim_construction.get_rb_evaluation().write_out_basis_functions(eim_construction,"eim_data"); rb_construction.get_rb_evaluation().write_out_basis_functions(rb_construction,"rb_data"); } } else // Perform the Online stage of the RB method { #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataDeserialization::RBEIMEvaluationDeserialization rb_eim_eval_reader(eim_rb_eval); rb_eim_eval_reader.read_from_file("rb_eim_eval.bin"); #else eim_rb_eval.legacy_read_offline_data_from_files("eim_data"); #endif // attach the EIM theta objects to rb_eval objects eim_rb_eval.initialize_eim_theta_objects(); rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects()); // Read in the offline data for rb_eval #if defined(LIBMESH_HAVE_CAPNPROTO) RBDataDeserialization::RBEvaluationDeserialization rb_eval_reader(rb_eval); rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true); #else rb_eval.legacy_read_offline_data_from_files("rb_data"); #endif // Get the parameters at which we will do a reduced basis solve Real online_curvature = infile("online_curvature", 0.); Real online_Bi = infile("online_Bi", 0.); Real online_kappa = infile("online_kappa", 0.); RBParameters online_mu; online_mu.set_value("curvature", online_curvature); online_mu.set_value("Bi", online_Bi); online_mu.set_value("kappa", online_kappa); rb_eval.set_parameters(online_mu); rb_eval.print_parameters(); rb_eval.rb_solve( rb_eval.get_n_basis_functions() ); // plot the solution, if requested if(store_basis_functions) { // read in the data from files eim_rb_eval.read_in_basis_functions(eim_construction,"eim_data"); rb_eval.read_in_basis_functions(rb_construction,"rb_data"); eim_construction.load_rb_solution(); rb_construction.load_rb_solution(); transform_mesh_and_plot(equation_systems,online_curvature,"RB_sol.e"); } } return 0; }
// The main program. int main (int argc, char** argv) { // Initialize libMesh. LibMeshInit init (argc, argv); Mesh mesh(init.comm()); MeshTools::Generation::build_cube (mesh, 60, 4, 4, 0., 3.0, 0., 0.2, 0., 0.2, HEX20); // XdrIO mesh_io(mesh); // mesh_io.read("one_tri.xda"); // Print information about the mesh to the screen. mesh.print_info(); // Create an equation systems object. EquationSystems equation_systems (mesh); // Declare the system and its variables. // Create a transient system named "Convection-Diffusion" LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Structure"); // Add the variables "u" & "v" to "Stokes". They // will be approximated using second-order approximation. const uint dx_var = system.add_variable ("dx", SECOND); const uint dy_var = system.add_variable ("dy", SECOND); const uint dz_var = system.add_variable ("dz", SECOND); std::set<boundary_id_type> dirichlet_bc; dirichlet_bc.insert(4); // left side std::vector<uint> vars (3); vars[0] = dx_var; vars[1] = dy_var; vars[2] = dz_var; ZeroFunction<Real> zero; system.get_dof_map().add_dirichlet_boundary( libMesh::DirichletBoundary( dirichlet_bc, vars, &zero ) ); // Give the system a pointer to the matrix assembly // function. system.attach_assemble_function (assemble_structure); // Initialize the data structures for the equation system. equation_systems.init (); equation_systems.parameters.set<uint>("linear solver maximum iterations") = 250; equation_systems.parameters.set<Real> ("linear solver tolerance") = TOLERANCE; // Prints information about the system to the screen. equation_systems.print_info(); equation_systems.parameters.print(); // Assemble & solve the linear system, // then write the solution. equation_systems.get_system("Structure").solve(); #ifdef LIBMESH_HAVE_EXODUS_API ExodusII_IO(mesh).write_equation_systems ("structure_static_3d.e", equation_systems); #endif // #ifdef LIBMESH_HAVE_EXODUS_API // All done. return 0; }