libMesh
explicit_system.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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
23 #include "libmesh/explicit_system.h"
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(libmesh_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 
57 {
58  // initialize parent data
60 
61  // not necessary, handled by the parent!
62  // Resize the RHS conformal to the current mesh
63  //rhs->init (this->n_dofs(), this->n_local_dofs());
64 }
65 
66 
67 
68 void ExplicitSystem::assemble_qoi (const QoISet & qoi_indices)
69 {
70  // The user quantity of interest assembly gets to expect to
71  // accumulate on initially zero values
72  for (std::size_t i=0; i != qoi.size(); ++i)
73  if (qoi_indices.has_index(i))
74  qoi[i] = 0;
75 
76  Parent::assemble_qoi (qoi_indices);
77 }
78 
79 
80 
82  bool include_liftfunc,
83  bool apply_constraints)
84 {
85  // The user quantity of interest derivative assembly gets to expect
86  // to accumulate on initially zero vectors
87  for (std::size_t i=0; i != qoi.size(); ++i)
88  if (qoi_indices.has_index(i))
89  this->add_adjoint_rhs(i).zero();
90 
91  Parent::assemble_qoi_derivative (qoi_indices, include_liftfunc,
92  apply_constraints);
93 }
94 
95 
96 
98 {
99  // Assemble the linear system
100  this->assemble ();
101 
102  // Update the system after the solve
103  this->update();
104 }
105 
106 
107 
109 {
110  // Possible that we cleared the _vectors but
111  // forgot to NULL-out the rhs?
112  if (this->n_vectors() == 0)
114 
115 
116  // Only need to add the rhs if it isn't there
117  // already!
118  if (rhs == libmesh_nullptr)
119  rhs = &(this->add_vector ("RHS Vector", false));
120 
122 }
123 
124 } // namespace libMesh
This is the EquationSystems class.
virtual void clear()
Clear all the data structures associated with the system.
Definition: system.C:203
virtual void clear() libmesh_override
Clear all the data structures associated with the system.
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition: qoi_set.h:45
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:385
virtual void solve() libmesh_override
Assembles & solves the linear system Ax=b.
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:501
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition: system.C:479
const class libmesh_nullptr_t libmesh_nullptr
NumericVector< Number > * rhs
The system matrix.
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.
libmesh_assert(j)
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) libmesh_override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1553
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
ExplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1041
virtual void reinit() libmesh_override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) libmesh_override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition: system.C:490
bool has_index(unsigned int) const
Return whether or not this index is in the set to be calculated.
Definition: qoi_set.h:221
unsigned int n_vectors() const
Definition: system.h:2214