explicit_system.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 // C++ includes
21 
22 // Local includes
24 #include "libmesh/numeric_vector.h"
25 
26 namespace libMesh
27 {
28 
29 
30 // ------------------------------------------------------------
31 // ExplicitSystem implementation
33  const std::string & name_in,
34  const unsigned int number_in) :
35  Parent (es, name_in, number_in),
36  rhs(nullptr)
37 
38 {
39  // Add the system RHS.
40  this->add_system_rhs ();
41 }
42 
43 
44 
46 {
47  // Clear the parent data
48  Parent::clear();
49 
50  // Restore us to a "basic" state
51  this->add_system_rhs ();
52 }
53 
54 
55 
56 void ExplicitSystem::assemble_qoi (const QoISet & qoi_indices)
57 {
58  // The user quantity of interest assembly gets to expect to
59  // accumulate on initially zero values
60  for (unsigned int i=0; i != this->n_qois(); ++i)
61  if (qoi_indices.has_index(i))
62  qoi[i] = 0;
63 
64  Parent::assemble_qoi (qoi_indices);
65 }
66 
67 
68 
70  bool include_liftfunc,
71  bool apply_constraints)
72 {
73  // The user quantity of interest derivative assembly gets to expect
74  // to accumulate on initially zero vectors
75  for (unsigned int i=0; i != this->n_qois(); ++i)
76  if (qoi_indices.has_index(i))
77  this->add_adjoint_rhs(i).zero();
78 
79  Parent::assemble_qoi_derivative (qoi_indices, include_liftfunc,
80  apply_constraints);
81 }
82 
83 
84 
86 {
87  // Assemble the linear system
88  this->assemble ();
89 
90  // Update the system after the solve
91  this->update();
92 }
93 
94 
95 
97 {
98  // Possible that we cleared the _vectors but
99  // forgot to update the rhs pointer?
100  if (this->n_vectors() == 0)
101  rhs = nullptr;
102 
103 
104  // Only need to add the rhs if it isn't there
105  // already!
106  if (rhs == nullptr)
107  rhs = &(this->add_vector ("RHS Vector", false));
108 
109  libmesh_assert(rhs);
110 }
111 
112 } // namespace libMesh
Manages multiples systems of equations.
virtual void clear()
Definition: system.C:205
virtual void solve() override
Used to specify quantities of interest in a simulation.
Definition: qoi_set.h:45
unsigned int n_qois() const
Definition: system.h:2278
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Definition: system.C:484
virtual void assemble()
Definition: system.C:462
NumericVector< Number > * rhs
virtual void zero()=0
bool has_index(std::size_t) const
Definition: qoi_set.h:221
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661
std::vector< Number > qoi
Definition: system.h:1558
unsigned int n_vectors() const
Definition: system.h:2233
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
ExplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1021
virtual void clear() override
virtual void update()
Definition: system.C:408
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Definition: system.C:473