libMesh
advection_system.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 // local includes
19 #include "advection_system.h"
20 
21 // LibMesh includes
22 #include "libmesh/equation_systems.h" // EquationSystems::comm()
23 #include "libmesh/getpot.h" // GetPot input file parsing
24 #include "libmesh/libmesh_logging.h" // LOG_SCOPE
25 #include "libmesh/numeric_vector.h"
26 #include "libmesh/sparse_matrix.h"
27 #include "libmesh/string_to_enum.h"
28 
29 namespace libMesh
30 {
31 
33  const std::string & name,
34  const unsigned int number)
35  : Parent(es, name, number),
36  _q1_var(0),
37  _fe_order(CONSTANT),
38  _fe_family(MONOMIAL)
39 {
40 }
41 
42 
44 
46 {
47  LOG_SCOPE("assemble_claw_rhs()", "AdvectionSystem");
48 
49  // The input to this function is the solution vector, "q", from
50  // either the initial condition or the previous timestep.
51  this->update_Fh(q);
52 
53  // Allocate storage for temporary vector used in the computations below
54  auto temp = NumericVector<Number>::build(this->comm());
55  temp->init(this->n_dofs(), this->n_local_dofs(), false, libMeshEnums::PARALLEL);
56 
57  rhs->zero();
58 
59  // rhs += (Ai - AVG_i)*Fi
60  for (auto i : index_range(_Fh))
61  {
62  this->get_advection_matrix(i).vector_mult(*temp, *_Fh[i]); // temp = Ai*Fi
63  rhs->add(+1., *temp);
64  this->get_avg_matrix(i).vector_mult(*temp, *_Fh[i]); // temp = AVG_i*Fi
65  rhs->add(-1., *temp);
66  }
67 
68  // Jump term
69  // rhs -= LxF * (J*q)
70  this->get_jump_matrix().vector_mult(*temp, q);
71  rhs->add(-get_LxF_constant(), *temp);
72 
73  // Apply boundary conditions. This is also expressed as a matrix-vector product
74  // rhs -= BC_i * Fh[i]
75  for (auto i : index_range(_Fh))
76  {
77  this->get_boundary_condition_matrix(i).vector_mult(*temp, *_Fh[i]); // temp = BC_i * Fi
78  rhs->add(-1., *temp);
79  }
80 }
81 
83 {
84  LOG_SCOPE("update_Fh()", "AdvectionSystem");
85 
86  // Fi = u(i)*q
87  for (auto i : index_range(_Fh))
88  {
89  _Fh[i]->zero();
90  _Fh[i]->add(_u(i), q);
91  _Fh[i]->close();
92  }
93 }
94 
96 {
97  // Print info about the type of discretization being used. Note: we
98  // can use the same exact assembly code while changing only the
99  // approximation order to test both "DG" and "FV" discretizations.
100  // In the FV case, the "interior" integral contributions are zero
101  // since they depend on "dphi".
102  libMesh::out << "Adding q1 variable using ("
104  << ", "
106  << ") approximation to the system."
107  << std::endl;
108 
109  _q1_var = this->add_variable ("q1", _fe_order, _fe_family);
110 
112 
113  // Allocate NumericVectors in _Fh.
114  // TODO: the number of spatial dimensions is hard-coded here, we should
115  // make this depend on the input file parameters instead.
116  for (unsigned int i=0; i<2; ++i)
117  {
118  auto & vec = _Fh.emplace_back(NumericVector<Number>::build(this->comm()));
119  vec->init(this->n_dofs(), this->n_local_dofs(), false, libMeshEnums::PARALLEL);
120  }
121 }
122 
123 void AdvectionSystem::process_parameters_file (const std::string& parameters_filename)
124 {
125  Parent::process_parameters_file(parameters_filename);
126 
127  // First read in data from parameters_filename
128  GetPot infile(parameters_filename);
129  const Real u1_in = infile("u1", 1.);
130  const Real u2_in = infile("u2", 1.);
131  _u = Point(u1_in, u2_in, 0.);
132 
133  std::string fe_order_str = infile("fe_order", std::string("CONSTANT"));
134  std::string fe_family_str = infile("fe_family", std::string("MONOMIAL"));
135 
136  // Convert input strings to enumerations
137  _fe_order = Utility::string_to_enum<Order>(fe_order_str);
138  _fe_family = Utility::string_to_enum<FEFamily>(fe_family_str);
139 }
140 
142 {
144 
145  libMesh::out << std::endl << "==== AdvectionSystem ====" << std::endl;
146  libMesh::out << "u1 = " << _u(0) << ", u2 = " << _u(1) << std::endl;
147  libMesh::out << std::endl;
148 }
149 
150 } // namespace libMesh
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
This is the EquationSystems class.
SparseMatrix< Number > & get_boundary_condition_matrix(unsigned int dim)
Definition: claw_system.C:848
This class encapsulates functionality that allows us to solve conservation laws.
Definition: claw_system.h:36
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest...
virtual void init_data() override
Initialize the system (e.g.
NumericVector< Number > * rhs
The system matrix.
const Parallel::Communicator & comm() const
virtual void print_info() override
Print out some info about the system&#39;s configuration.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_local_dofs() const
Definition: system.C:158
virtual void init_data() override
Initialize the system (e.g.
Definition: claw_system.C:944
dof_id_type n_dofs() const
Definition: system.C:121
virtual void zero()=0
Set all entries to zero.
SparseMatrix< Number > & get_advection_matrix(unsigned int dim)
Definition: claw_system.C:822
virtual void process_parameters_file(const std::string &parameters_filename) override
Read in data from input file.
unsigned int _q1_var
Variable number for q1.
virtual void process_parameters_file(const std::string &parameters_filename)
Set parameters for this system (e.g.
Definition: claw_system.C:231
SparseMatrix< Number > & get_avg_matrix(unsigned int dim)
Definition: claw_system.C:832
AdvectionSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
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:1357
Order _fe_order
Store the FE Order and family specified by the input file.
SparseMatrix< Number > & get_jump_matrix()
Definition: claw_system.C:842
virtual void print_info()
Print out some info about the system&#39;s configuration.
Definition: claw_system.C:249
std::string enum_to_string(const T e)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
std::vector< std::unique_ptr< NumericVector< Number > > > _Fh
The advective flux vectors.
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
Point _u
The (assumed constant) advection velocity.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
virtual void assemble_claw_rhs(NumericVector< Number > &q) override
Right-hand side assembly.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117
void update_Fh(NumericVector< Number > &q)
Computes the vectors "uq" and "vq" where (u,v) are the (given, constant) advective velocity coefficie...
virtual ~AdvectionSystem()
Destructor.