libMesh
Functions
transient_ex3.C File Reference

Go to the source code of this file.

Functions

void set_initial_condition (EquationSystems &es, const std::string &system_name)
 
Number initial_condition (const Point &p, const Parameters &parameters, const std::string &, const std::string &)
 
int main (int argc, char **argv)
 

Function Documentation

◆ initial_condition()

Number initial_condition ( const Point p,
const Parameters parameters,
const std::string &  ,
const std::string &   
)

Definition at line 138 of file transient_ex3.C.

References libMesh::Utility::pow(), and libMesh::Real.

Referenced by set_initial_condition().

142 {
143  Real x = p(0);
144  Real y = p(1);
145 
146  return std::exp( -100.*(std::pow(x-0.5,2.) + std::pow(y-0.5,2.)) );
147 }
T pow(const T &x)
Definition: utility.h:328
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file transient_ex3.C.

References libMesh::EquationSystems::add_system(), libMesh::ClawSystem::assemble_all_matrices(), libMesh::System::attach_init_function(), libMesh::MeshTools::Generation::build_square(), libMesh::default_solver_package(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, mesh, libMesh::MeshTools::n_elem(), libMesh::AdvectionSystem::print_info(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::AdvectionSystem::process_parameters_file(), libMesh::QUAD9, set_initial_condition(), libMesh::ClawSystem::solve_conservation_law(), and libMesh::ExodusII_IO::write_equation_systems().

67 {
68  // Initialize libMesh.
69  LibMeshInit init (argc, argv);
70 
71  // This example requires a linear solver package.
72  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
73  "--enable-petsc, --enable-trilinos, or --enable-eigen");
74 
75  // Create GetPot object to parse the command line
76  GetPot command_line (argc, argv);
77 
78  // Allow the user specify a custom input file on the command line
79  // using the "-i" flag, and provide a sensible default value in case
80  // they don't.
81  std::string parameters_filename = "advection_2D.in";
82  if ( command_line.search(2, "-i", "--input_file") )
83  parameters_filename = command_line.next(parameters_filename);
84 
85  // Read mesh options from the input file
86  GetPot infile(parameters_filename);
87  unsigned int n_elem = infile("n_elem", 1); // Determines the number of elements in the "truth" mesh
88 
89  // Build a mesh
90  Mesh mesh (init.comm());
92  n_elem, n_elem,
93  0., 1.,
94  0., 1.,
95  QUAD9);
96 
97  // Create an equation systems object
98  EquationSystems equation_systems (mesh);
99 
100  // Create an AdvectionSystem within the EquationSystems
101  AdvectionSystem & advection_system =
102  equation_systems.add_system<AdvectionSystem> ("Advection2D");
103 
104  // Process the input file values
105  advection_system.process_parameters_file(parameters_filename);
106 
107  // Set the initial condition function
108  advection_system.attach_init_function (set_initial_condition);
109 
110  equation_systems.init ();
111 
112  equation_systems.print_info();
113  mesh.print_info();
114 
115  advection_system.print_info();
116 
117  advection_system.assemble_all_matrices();
118  // advection_system.write_out_discretization_matrices();
119 
120 #ifdef LIBMESH_HAVE_EXODUS_API
121  ExodusII_IO(mesh).write_equation_systems ("claw_solution.0000.e", equation_systems);
122 #endif
123 
124  advection_system.solve_conservation_law();
125 
126  return 0;
127 }
This is the EquationSystems class.
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:969
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
MeshBase & mesh
virtual void print_info() override
Print out some info about the system&#39;s configuration.
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
void assemble_all_matrices()
Assemble the matrices we need to solve a conservation law.
Definition: claw_system.C:262
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
SolverPackage default_solver_package()
Definition: libmesh.C:1117
virtual void process_parameters_file(const std::string &parameters_filename) override
Read in data from input file.
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Definition: exodusII_io.C:2033
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:1562
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
void set_initial_condition(EquationSystems &es, const std::string &system_name)
void solve_conservation_law()
Solve the conservation law.
Definition: claw_system.C:95
This class extends ClawSystem to implement pure advection in 2D.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void attach_init_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in initializing the system.
Definition: system.C:2130

◆ set_initial_condition()

void set_initial_condition ( EquationSystems es,
const std::string &  system_name 
)

Definition at line 129 of file transient_ex3.C.

References libMesh::EquationSystems::get_system(), initial_condition(), libMesh::EquationSystems::parameters, and libMesh::System::project_solution().

Referenced by main().

131 {
132  LinearImplicitSystem & system =
133  es.get_system<LinearImplicitSystem>("Advection2D");
134 
135  system.project_solution(initial_condition, /*gradient=*/nullptr, es.parameters);
136 }
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
const T_sys & get_system(std::string_view name) const
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Number initial_condition(const Point &p, const Parameters &parameters, const std::string &, const std::string &)
Parameters parameters
Data structure holding arbitrary parameters.