libMesh
explicit_system.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
19 
20 // Local includes
21 #include "libmesh/explicit_system.h"
22 #include "libmesh/numeric_vector.h"
23 
24 namespace libMesh
25 {
26 
27 
29 
31  const std::string & name_in,
32  const unsigned int number_in) :
33  Parent (es, name_in, number_in),
34  rhs(nullptr)
35 
36 {
37  // Add the system RHS.
38  this->add_system_rhs ();
39 }
40 
41 
42 
44 {
45  // Clear the parent data
46  Parent::clear();
47 
48  // Restore us to a "basic" state
49  this->add_system_rhs ();
50 }
51 
52 
53 
54 void ExplicitSystem::assemble_qoi (const QoISet & qoi_indices)
55 {
56  // The user quantity of interest assembly gets to expect to
57  // accumulate on initially zero values
58  for (auto i : make_range(this->n_qois()))
59  if (qoi_indices.has_index(i))
60  this->set_qoi(i, 0);
61 
62  Parent::assemble_qoi (qoi_indices);
63 }
64 
65 
66 
68  bool include_liftfunc,
69  bool apply_constraints)
70 {
71  // The user quantity of interest derivative assembly gets to expect
72  // to accumulate on initially zero vectors
73  for (auto i : make_range(this->n_qois()))
74  if (qoi_indices.has_index(i))
75  this->add_adjoint_rhs(i).zero();
76 
77  Parent::assemble_qoi_derivative (qoi_indices, include_liftfunc,
78  apply_constraints);
79 }
80 
81 
82 
84 {
85  // Assemble the linear system
86  this->assemble ();
87 
88  // Update the system after the solve
89  this->update();
90 }
91 
92 
93 
95 {
96  // Possible that we cleared the _vectors but
97  // forgot to update the rhs pointer?
98  if (this->n_vectors() == 0)
99  rhs = nullptr;
100 
101 
102  // Only need to add the rhs if it isn't there
103  // already!
104  if (rhs == nullptr)
105  rhs = &(this->add_vector ("RHS Vector", false));
106 
108 }
109 
110 } // namespace libMesh
This is the EquationSystems class.
virtual void clear()
Clear all the data structures associated with the system.
Definition: system.C:168
virtual void solve() override
For explicit systems, just assemble the system which should directly compute A*x. ...
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition: qoi_set.h:45
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2516
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Calls user qoi derivative function.
Definition: system.C:571
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition: system.C:549
NumericVector< Number > * rhs
The system matrix.
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:751
void add_system_rhs()
Add the system right-hand-side vector to the _vectors data structure.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void zero()=0
Set all entries to zero.
bool has_index(std::size_t) const
Return whether or not this index is in the set to be calculated.
Definition: qoi_set.h:224
unsigned int n_vectors() const
Definition: system.h:2477
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
libmesh_assert(ctx)
ExplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1245
virtual void clear() override
Clear all the data structures associated with the system.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:493
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition: system.C:2326
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition: system.C:560