libMesh
Loading...
Searching...
No Matches
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.

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}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::Real.

Referenced by set_initial_condition().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file transient_ex3.C.

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
109
110 equation_systems.init ();
111
112 equation_systems.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 class extends ClawSystem to implement pure advection in 2D.
virtual void print_info() override
Print out some info about the system's configuration.
virtual void process_parameters_file(const std::string &parameters_filename) override
Read in data from input file.
void solve_conservation_law()
Solve the conservation law.
Definition claw_system.C:95
void assemble_all_matrices()
Assemble the matrices we need to solve a conservation law.
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:53
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
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:1755
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
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:1928
MeshBase & mesh
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.
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).
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage default_solver_package()
Definition libmesh.C:1064
void set_initial_condition(EquationSystems &es, const std::string &system_name)

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::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, main(), mesh, 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().

◆ set_initial_condition()

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

Definition at line 129 of file transient_ex3.C.

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

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

Referenced by main().