diff_system.C
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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 (NULL), 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_jacobians(false), 00042 _diff_physics(this), 00043 diff_qoi(this) 00044 { 00045 } 00046 00047 00048 00049 DifferentiableSystem::~DifferentiableSystem () 00050 { 00051 this->clear(); 00052 } 00053 00054 00055 00056 void DifferentiableSystem::clear () 00057 { 00058 // If we had an attached Physics object, delete it. 00059 if (this->_diff_physics != this) 00060 { 00061 delete this->_diff_physics; 00062 this->_diff_physics = this; 00063 } 00064 // If we had no attached Physics object, clear our own Physics data 00065 else 00066 this->clear_physics(); 00067 00068 // If we had an attached QoI object, delete it. 00069 if (this->diff_qoi != this) 00070 { 00071 delete this->diff_qoi; 00072 this->diff_qoi = this; 00073 } 00074 // If we had no attached QoI object, clear our own QoI data 00075 else 00076 this->clear_qoi(); 00077 00078 use_fixed_solution = false; 00079 } 00080 00081 00082 00083 void DifferentiableSystem::reinit () 00084 { 00085 Parent::reinit(); 00086 00087 libmesh_assert(time_solver.get()); 00088 libmesh_assert_equal_to (&(time_solver->system()), this); 00089 00090 time_solver->reinit(); 00091 } 00092 00093 00094 00095 void DifferentiableSystem::init_data () 00096 { 00097 // If it isn't a separate initialized-upon-attachment object, do any 00098 // initialization our physics needs. 00099 if (this->_diff_physics == this) 00100 this->init_physics(*this); 00101 00102 // Do any initialization our solvers need 00103 libmesh_assert(time_solver.get()); 00104 libmesh_assert_equal_to (&(time_solver->system()), this); 00105 time_solver->init(); 00106 00107 // Next initialize ImplicitSystem data 00108 Parent::init_data(); 00109 00110 time_solver->init_data(); 00111 } 00112 00113 00114 00115 AutoPtr<DiffContext> DifferentiableSystem::build_context () 00116 { 00117 AutoPtr<DiffContext> ap(new DiffContext(*this)); 00118 00119 ap->set_deltat_pointer( &this->deltat ); 00120 00121 return ap; 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
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:46 UTC
Hosted By: