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

◆ main()

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::command_line_next(), 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  libmesh_error_msg_if(argc < 3, "Usage:\n" << "\t " << argv[0] << " -r 2");
161 
162  // Brief message to the user regarding the program name
163  // and command line arguments.
164  libMesh::out << "Running " << argv[0];
165 
166  for (int i=1; i<argc; i++)
167  libMesh::out << " " << argv[i];
168 
169  libMesh::out << std::endl << std::endl;
170 
171  // Read number of refinements
172  const int nr = libMesh::command_line_next("-r", 2);
173 
174  // Read FE order from command line
175  std::string order = "FIRST";
176  order = libMesh::command_line_next("-o", order);
177  order = libMesh::command_line_next("-Order", order);
178 
179  // Read FE Family from command line
180  std::string family = "LAGRANGE";
181  family = libMesh::command_line_next("-f", family);
182  family = libMesh::command_line_next("-FEFamily", family);
183 
184  // Cannot use discontinuous basis.
185  libmesh_error_msg_if((family == "MONOMIAL") || (family == "XYZ"),
186  "This example requires a C^0 (or higher) FE basis.");
187 
188  if (libMesh::on_command_line("-pre"))
189  {
190 #ifdef LIBMESH_HAVE_PETSC
191  //Use the jacobian for preconditioning.
192 # if PETSC_VERSION_LESS_THAN(3,7,0)
193  PetscOptionsSetValue("-snes_mf_operator",
194  LIBMESH_PETSC_NULLPTR);
195 # else
196  PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR, "-snes_mf_operator",
197  LIBMESH_PETSC_NULLPTR);
198 # endif
199 #else
200  libMesh::err << "Must be using PETSc to use jacobian based preconditioning" << std::endl;
201 
202  //returning zero so that "make run" won't fail if we ever enable this capability there.
203  return 0;
204 #endif //LIBMESH_HAVE_PETSC
205  }
206 
207  // Skip this 2D example if libMesh was compiled as 1D-only.
208  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
209 
210  // Create a mesh, with dimension to be overridden by the file,
211  // distributed across the default MPI communicator.
212  Mesh mesh(init.comm());
213 
214  mesh.read ("lshaped.xda");
215 
216  if (order != "FIRST")
218 
220 
221  // Print information about the mesh to the screen.
222  mesh.print_info();
223 
224  // Create an equation systems object.
225  EquationSystems equation_systems (mesh);
226 
227  // Declare the system and its variables.
228 
229  // Creates a system named "Laplace-Young"
230  NonlinearImplicitSystem & system =
231  equation_systems.add_system<NonlinearImplicitSystem> ("Laplace-Young");
232 
233  // Here we specify the tolerance for the nonlinear solver and
234  // the maximum of nonlinear iterations.
235  equation_systems.parameters.set<Real> ("nonlinear solver tolerance") = 1.e-12;
236  equation_systems.parameters.set<unsigned int> ("nonlinear solver maximum iterations") = 50;
237 
238 
239  // Adds the variable "u" to "Laplace-Young". "u"
240  // will be approximated using second-order approximation.
241  system.add_variable("u",
242  Utility::string_to_enum<Order> (order),
243  Utility::string_to_enum<FEFamily>(family));
244 
245  // Construct object which provides the residual and jacobian
246  // computations and tell the solver to use it.
247  LaplaceYoung laplace_young;
248  system.nonlinear_solver->residual_object = &laplace_young;
249  system.nonlinear_solver->jacobian_object = &laplace_young;
250  system.nonlinear_solver->postcheck_object = &laplace_young;
251 
252  // Initialize the data structures for the equation system.
253  equation_systems.init();
254 
255  // Prints information about the system to the screen.
256  equation_systems.print_info();
257 
258  // Solve the system "Laplace-Young", print the number of iterations
259  // and final residual
260  equation_systems.get_system("Laplace-Young").solve();
261 
262  // Print out final convergence information. This duplicates some
263  // output from during the solve itself, but demonstrates another way
264  // to get this information after the solve is complete.
265  libMesh::out << "Laplace-Young system solved at nonlinear iteration "
266  << system.n_nonlinear_iterations()
267  << " , final nonlinear residual norm: "
268  << system.final_nonlinear_residual()
269  << std::endl;
270 
271 #ifdef LIBMESH_HAVE_EXODUS_API
272  // After solving the system write the solution
274  equation_systems);
275 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
276 #endif // #ifndef LIBMESH_ENABLE_AMR
277 
278  // All done.
279  return 0;
280 }
OStreamProxy err
T command_line_next(std::string name, T default_value)
Use GetPot&#39;s search()/next() functions to get following arguments from the command line...
Definition: libmesh.C:1011
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=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
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
MeshBase & mesh
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition: mesh_base.C:1489
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1305
A class which provides the residual and jacobian assembly functions for the Laplace-Young system of e...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
void all_second_order(const bool full_ordered=true)
Calls the range-based version of this function with a range consisting of all elements in the mesh...
Definition: mesh_base.C:1535
bool on_command_line(std::string arg)
Definition: libmesh.C:924
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.