libMesh
Classes | Functions
miscellaneous_ex3.C File Reference

Go to the source code of this file.

Classes

class  LaplaceYoung
 A class which provides the residual and jacobian assembly functions for the Laplace-Young system of equations. More...
 

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 134 of file miscellaneous_ex3.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::all_second_order(), libMesh::LibMeshInit::comm(), libMesh::err, libMesh::NonlinearImplicitSystem::final_nonlinear_residual(), libMesh::EquationSystems::get_system(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), mesh, libMesh::NonlinearImplicitSystem::n_nonlinear_iterations(), libMesh::NonlinearImplicitSystem::nonlinear_solver, libMesh::on_command_line(), libMesh::out, libMesh::EquationSystems::parameters, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), libMesh::Real, libMesh::Parameters::set(), libMesh::MeshRefinement::uniformly_refine(), and libMesh::MeshOutput< MT >::write_equation_systems().

135 {
136  // Initialize libMesh and any dependent libraries, like in example 2.
137  LibMeshInit init (argc, argv);
138 
139  // This example requires a NonlinearSolver.
140 #if !defined(LIBMESH_HAVE_PETSC) && (!defined(LIBMESH_TRILINOS_HAVE_NOX) || !defined(LIBMESH_TRILINOS_HAVE_EPETRA))
141  libmesh_example_requires(false, "--enable-petsc or --enable-trilinos");
142 #endif
143 
144  if (libMesh::on_command_line ("--use-eigen"))
145  {
146  libMesh::err << "This example requires a NonlinearSolver, and therefore does not "
147  << "support --use-eigen on the command line."
148  << std::endl;
149  return 0;
150  }
151 
152 #ifndef LIBMESH_ENABLE_AMR
153  libmesh_example_requires(false, "--enable-amr");
154 #else
155 
156  // Create a GetPot object to parse the command line
157  GetPot command_line (argc, argv);
158 
159  // Check for proper calling arguments.
160  if (argc < 3)
161  {
162  // This handy function will print the file name, line number,
163  // specified message, and then throw an exception.
164  libmesh_error_msg("Usage:\n" << "\t " << argv[0] << " -r 2");
165  }
166 
167  // Brief message to the user regarding the program name
168  // and command line arguments.
169  else
170  {
171  libMesh::out << "Running " << argv[0];
172 
173  for (int i=1; i<argc; i++)
174  libMesh::out << " " << argv[i];
175 
176  libMesh::out << std::endl << std::endl;
177  }
178 
179 
180  // Read number of refinements
181  int nr = 2;
182  if (command_line.search(1, "-r"))
183  nr = command_line.next(nr);
184 
185  // Read FE order from command line
186  std::string order = "FIRST";
187  if (command_line.search(2, "-Order", "-o"))
188  order = command_line.next(order);
189 
190  // Read FE Family from command line
191  std::string family = "LAGRANGE";
192  if (command_line.search(2, "-FEFamily", "-f"))
193  family = command_line.next(family);
194 
195  // Cannot use discontinuous basis.
196  if ((family == "MONOMIAL") || (family == "XYZ"))
197  libmesh_error_msg("This example requires a C^0 (or higher) FE basis.");
198 
199  if (command_line.search(1, "-pre"))
200  {
201 #ifdef LIBMESH_HAVE_PETSC
202  //Use the jacobian for preconditioning.
203 # if PETSC_VERSION_LESS_THAN(3,7,0)
204  PetscOptionsSetValue("-snes_mf_operator", PETSC_NULL);
205 # else
206  PetscOptionsSetValue(PETSC_NULL, "-snes_mf_operator", PETSC_NULL);
207 # endif
208 #else
209  libMesh::err << "Must be using PETSc to use jacobian based preconditioning" << std::endl;
210 
211  //returning zero so that "make run" won't fail if we ever enable this capability there.
212  return 0;
213 #endif //LIBMESH_HAVE_PETSC
214  }
215 
216  // Skip this 2D example if libMesh was compiled as 1D-only.
217  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
218 
219  // Create a mesh, with dimension to be overridden by the file,
220  // distributed across the default MPI communicator.
221  Mesh mesh(init.comm());
222 
223  mesh.read ("lshaped.xda");
224 
225  if (order != "FIRST")
227 
229 
230  // Print information about the mesh to the screen.
231  mesh.print_info();
232 
233  // Create an equation systems object.
234  EquationSystems equation_systems (mesh);
235 
236  // Declare the system and its variables.
237 
238  // Creates a system named "Laplace-Young"
239  NonlinearImplicitSystem & system =
240  equation_systems.add_system<NonlinearImplicitSystem> ("Laplace-Young");
241 
242  // Here we specify the tolerance for the nonlinear solver and
243  // the maximum of nonlinear iterations.
244  equation_systems.parameters.set<Real> ("nonlinear solver tolerance") = 1.e-12;
245  equation_systems.parameters.set<unsigned int> ("nonlinear solver maximum iterations") = 50;
246 
247 
248  // Adds the variable "u" to "Laplace-Young". "u"
249  // will be approximated using second-order approximation.
250  system.add_variable("u",
251  Utility::string_to_enum<Order> (order),
252  Utility::string_to_enum<FEFamily>(family));
253 
254  // Construct object which provides the residual and jacobian
255  // computations and tell the solver to use it.
256  LaplaceYoung laplace_young;
257  system.nonlinear_solver->residual_object = &laplace_young;
258  system.nonlinear_solver->jacobian_object = &laplace_young;
259  system.nonlinear_solver->postcheck_object = &laplace_young;
260 
261  // Initialize the data structures for the equation system.
262  equation_systems.init();
263 
264  // Prints information about the system to the screen.
265  equation_systems.print_info();
266 
267  // Solve the system "Laplace-Young", print the number of iterations
268  // and final residual
269  equation_systems.get_system("Laplace-Young").solve();
270 
271  // Print out final convergence information. This duplicates some
272  // output from during the solve itself, but demonstrates another way
273  // to get this information after the solve is complete.
274  libMesh::out << "Laplace-Young system solved at nonlinear iteration "
275  << system.n_nonlinear_iterations()
276  << " , final nonlinear residual norm: "
277  << system.final_nonlinear_residual()
278  << std::endl;
279 
280 #ifdef LIBMESH_HAVE_EXODUS_API
281  // After solving the system write the solution
283  equation_systems);
284 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
285 #endif // #ifndef LIBMESH_ENABLE_AMR
286 
287  // All done.
288  return 0;
289 }
OStreamProxy err
This is the EquationSystems class.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
MeshBase & mesh
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
This is the MeshRefinement class.
virtual void all_second_order(const bool full_ordered=true)=0
Converts a (conforming, non-refined) mesh with linear elements into a mesh with second-order elements...
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
This class provides a specific system class.
A class which provides the residual and jacobian assembly functions for the Laplace-Young system of e...
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool on_command_line(const std::string &arg)
Definition: libmesh.C:921
OStreamProxy out
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
virtual void read(const std::string &name, void *mesh_data=libmesh_nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:448
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.