$extrastylesheet
explicit_system.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 // C++ includes
00021 
00022 // Local includes
00023 #include "libmesh/explicit_system.h"
00024 #include "libmesh/numeric_vector.h"
00025 
00026 namespace libMesh
00027 {
00028 
00029 
00030 // ------------------------------------------------------------
00031 // ExplicitSystem implementation
00032 ExplicitSystem::ExplicitSystem (EquationSystems& es,
00033                                 const std::string& name_in,
00034                                 const unsigned int number_in) :
00035   Parent (es, name_in, number_in),
00036   rhs(NULL)
00037 
00038 {
00039   //rhs = &(this->add_vector ("RHS Vector"));
00040 }
00041 
00042 
00043 
00044 ExplicitSystem::~ExplicitSystem ()
00045 {
00046   // clear data
00047   this->clear();
00048 }
00049 
00050 
00051 
00052 void ExplicitSystem::clear ()
00053 {
00054   // Clear the parent data
00055   Parent::clear();
00056 
00057   // NULL-out the vector.  Note that
00058   // System::clear() actually deleted it.
00059   rhs = NULL;
00060 }
00061 
00062 
00063 
00064 void ExplicitSystem::init_data ()
00065 {
00066   // Add the system RHS.
00067   // (We must do this before initializing the System data,
00068   //  then we lose the opportunity to add vectors).
00069   this->add_system_rhs ();
00070 
00071   // initialize parent data
00072   Parent::init_data();
00073 }
00074 
00075 
00076 
00077 void ExplicitSystem::reinit ()
00078 {
00079   // initialize parent data
00080   Parent::reinit();
00081 
00082   // not necessary, handled by the parent!
00083   // Resize the RHS conformal to the current mesh
00084   //rhs->init (this->n_dofs(), this->n_local_dofs());
00085 }
00086 
00087 
00088 
00089 void ExplicitSystem::assemble_qoi (const QoISet& qoi_indices)
00090 {
00091   // The user quantity of interest assembly gets to expect to
00092   // accumulate on initially zero values
00093   for (unsigned int i=0; i != qoi.size(); ++i)
00094     if (qoi_indices.has_index(i))
00095       qoi[i] = 0;
00096 
00097   Parent::assemble_qoi (qoi_indices);
00098 }
00099 
00100 
00101 
00102 void ExplicitSystem::assemble_qoi_derivative (const QoISet& qoi_indices,
00103                                               bool include_liftfunc,
00104                                               bool apply_constraints)
00105 {
00106   // The user quantity of interest derivative assembly gets to expect
00107   // to accumulate on initially zero vectors
00108   for (unsigned int i=0; i != qoi.size(); ++i)
00109     if (qoi_indices.has_index(i))
00110       this->add_adjoint_rhs(i).zero();
00111 
00112   Parent::assemble_qoi_derivative (qoi_indices, include_liftfunc,
00113                                    apply_constraints);
00114 }
00115 
00116 
00117 
00118 void ExplicitSystem::solve ()
00119 {
00120   // Assemble the linear system
00121   this->assemble ();
00122 
00123   // Update the system after the solve
00124   this->update();
00125 }
00126 
00127 
00128 
00129 void ExplicitSystem::add_system_rhs ()
00130 {
00131   // Possible that we cleared the _vectors but
00132   // forgot to NULL-out the rhs?
00133   if (this->n_vectors() == 0) rhs = NULL;
00134 
00135 
00136   // Only need to add the rhs if it isn't there
00137   // already!
00138   if (rhs == NULL)
00139     rhs = &(this->add_vector ("RHS Vector", false));
00140 
00141   libmesh_assert(rhs);
00142 }
00143 
00144 } // namespace libMesh