$extrastylesheet
diff_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 #include "libmesh/diff_solver.h"
00020 #include "libmesh/diff_system.h"
00021 #include "libmesh/time_solver.h"
00022 
00023 namespace libMesh
00024 {
00025 
00026 
00027 
00028 DifferentiableSystem::DifferentiableSystem
00029 (EquationSystems& es,
00030  const std::string& name_in,
00031  const unsigned int number_in) :
00032   Parent      (es, name_in, number_in),
00033   time_solver (),
00034   deltat(1.),
00035   print_solution_norms(false),
00036   print_solutions(false),
00037   print_residual_norms(false),
00038   print_residuals(false),
00039   print_jacobian_norms(false),
00040   print_jacobians(false),
00041   print_element_solutions(false),
00042   print_element_residuals(false),
00043   print_element_jacobians(false),
00044   _diff_physics(this),
00045   diff_qoi(this)
00046 {
00047 }
00048 
00049 
00050 
00051 DifferentiableSystem::~DifferentiableSystem ()
00052 {
00053   this->clear();
00054 }
00055 
00056 
00057 
00058 void DifferentiableSystem::clear ()
00059 {
00060   // If we had an attached Physics object, delete it.
00061   if (this->_diff_physics != this)
00062     {
00063       delete this->_diff_physics;
00064       this->_diff_physics = this;
00065     }
00066   // If we had no attached Physics object, clear our own Physics data
00067   else
00068     this->clear_physics();
00069 
00070   // If we had an attached QoI object, delete it.
00071   if (this->diff_qoi != this)
00072     {
00073       delete this->diff_qoi;
00074       this->diff_qoi = this;
00075     }
00076   // If we had no attached QoI object, clear our own QoI data
00077   else
00078     this->clear_qoi();
00079 
00080   use_fixed_solution = false;
00081 }
00082 
00083 
00084 
00085 void DifferentiableSystem::reinit ()
00086 {
00087   Parent::reinit();
00088 
00089   libmesh_assert(time_solver.get());
00090   libmesh_assert_equal_to (&(time_solver->system()), this);
00091 
00092   time_solver->reinit();
00093 }
00094 
00095 
00096 
00097 void DifferentiableSystem::init_data ()
00098 {
00099   // If it isn't a separate initialized-upon-attachment object, do any
00100   // initialization our physics needs.
00101   if (this->_diff_physics == this)
00102     this->init_physics(*this);
00103 
00104   // Do any initialization our solvers need
00105   libmesh_assert(time_solver.get());
00106   libmesh_assert_equal_to (&(time_solver->system()), this);
00107   time_solver->init();
00108 
00109   // Next initialize ImplicitSystem data
00110   Parent::init_data();
00111 
00112   time_solver->init_data();
00113 }
00114 
00115 
00116 
00117 UniquePtr<DiffContext> DifferentiableSystem::build_context ()
00118 {
00119   DiffContext* context = new DiffContext(*this);
00120   context->set_deltat_pointer( &this->deltat );
00121   return UniquePtr<DiffContext>(context);
00122 }
00123 
00124 
00125 void DifferentiableSystem::assemble ()
00126 {
00127   this->assembly(true, true);
00128 }
00129 
00130 
00131 
00132 void DifferentiableSystem::solve ()
00133 {
00134   // Get the time solver object associated with the system, and tell it that
00135   // we are not solving the adjoint problem
00136   this->get_time_solver().set_is_adjoint(false);
00137 
00138   libmesh_assert_equal_to (&(time_solver->system()), this);
00139   time_solver->solve();
00140 }
00141 
00142 
00143 
00144 std::pair<unsigned int, Real> DifferentiableSystem::adjoint_solve (const QoISet& qoi_indices)
00145 {
00146   // Get the time solver object associated with the system, and tell it that
00147   // we are solving the adjoint problem
00148   this->get_time_solver().set_is_adjoint(true);
00149 
00150   return this->ImplicitSystem::adjoint_solve(qoi_indices);
00151 }
00152 
00153 
00154 
00155 LinearSolver<Number>* DifferentiableSystem::get_linear_solver() const
00156 {
00157   libmesh_assert(time_solver.get());
00158   libmesh_assert_equal_to (&(time_solver->system()), this);
00159   return this->time_solver->linear_solver().get();
00160 }
00161 
00162 
00163 
00164 std::pair<unsigned int, Real> DifferentiableSystem::get_linear_solve_parameters() const
00165 {
00166   libmesh_assert(time_solver.get());
00167   libmesh_assert_equal_to (&(time_solver->system()), this);
00168   return std::make_pair(this->time_solver->diff_solver()->max_linear_iterations,
00169                         this->time_solver->diff_solver()->relative_residual_tolerance);
00170 }
00171 
00172 
00173 
00174 void DifferentiableSystem::release_linear_solver(LinearSolver<Number>*) const
00175 {
00176 }
00177 
00178 } // namespace libMesh