$extrastylesheet
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/transient_system.h" 00024 #include "libmesh/explicit_system.h" 00025 #include "libmesh/linear_implicit_system.h" 00026 #include "libmesh/nonlinear_implicit_system.h" 00027 #include "libmesh/dof_map.h" 00028 #include "libmesh/numeric_vector.h" 00029 #include "libmesh/rb_construction.h" 00030 00031 namespace libMesh 00032 { 00033 00034 00035 // ------------------------------------------------------------ 00036 // TransientSystem implementation 00037 template <class Base> 00038 TransientSystem<Base>::TransientSystem (EquationSystems& es, 00039 const std::string& name_in, 00040 const unsigned int number_in) : 00041 00042 Base (es, name_in, number_in) 00043 { 00044 #ifdef LIBMESH_ENABLE_GHOSTED 00045 old_local_solution = 00046 UniquePtr<NumericVector<Number> > 00047 (&(this->add_vector("_transient_old_local_solution", true, GHOSTED))); 00048 older_local_solution = 00049 UniquePtr<NumericVector<Number> > 00050 (&(this->add_vector("_transient_older_local_solution", true, GHOSTED))); 00051 #else 00052 old_local_solution = 00053 UniquePtr<NumericVector<Number> > 00054 (&(this->add_vector("_transient_old_local_solution", true, SERIAL))); 00055 older_local_solution = 00056 UniquePtr<NumericVector<Number> > 00057 (&(this->add_vector("_transient_older_local_solution", true, SERIAL))); 00058 #endif 00059 } 00060 00061 00062 00063 template <class Base> 00064 TransientSystem<Base>::~TransientSystem () 00065 { 00066 this->clear(); 00067 00068 // We still have UniquePtrs for API compatibility, but 00069 // now that we're System::add_vector()ing these, we can trust 00070 // the base class to handle memory management 00071 old_local_solution.release(); 00072 older_local_solution.release(); 00073 } 00074 00075 00076 00077 template <class Base> 00078 void TransientSystem<Base>::clear () 00079 { 00080 // clear the parent data 00081 Base::clear(); 00082 00083 // the old & older local solutions 00084 // are now deleted by System! 00085 // old_local_solution->clear(); 00086 // older_local_solution->clear(); 00087 00088 // FIXME: This preserves maximum backwards compatibility, 00089 // but is probably grossly unnecessary: 00090 old_local_solution.release(); 00091 older_local_solution.release(); 00092 00093 old_local_solution = 00094 UniquePtr<NumericVector<Number> > 00095 (&(this->add_vector("_transient_old_local_solution"))); 00096 older_local_solution = 00097 UniquePtr<NumericVector<Number> > 00098 (&(this->add_vector("_transient_older_local_solution"))); 00099 } 00100 00101 00102 00103 00104 template <class Base> 00105 void TransientSystem<Base>::init_data () 00106 { 00107 // initialize parent data 00108 Base::init_data(); 00109 00110 // Initialize the old & older solutions 00111 // Using new ghosted vectors if enabled 00112 #ifdef LIBMESH_ENABLE_GHOSTED 00113 old_local_solution->init (this->n_dofs(), this->n_local_dofs(), 00114 this->get_dof_map().get_send_list(), false, 00115 GHOSTED); 00116 older_local_solution->init (this->n_dofs(), this->n_local_dofs(), 00117 this->get_dof_map().get_send_list(), false, 00118 GHOSTED); 00119 #else 00120 old_local_solution->init (this->n_dofs(), false, SERIAL); 00121 older_local_solution->init (this->n_dofs(), false, SERIAL); 00122 #endif 00123 } 00124 00125 00126 00127 template <class Base> 00128 void TransientSystem<Base>::reinit () 00129 { 00130 // initialize parent data 00131 Base::reinit(); 00132 00133 // Project the old & older vectors to the new mesh 00134 // The System::reinit handles this now 00135 // this->project_vector (*old_local_solution); 00136 // this->project_vector (*older_local_solution); 00137 } 00138 00139 00140 00141 template <class Base> 00142 void TransientSystem<Base>::re_update () 00143 { 00144 // re_update the parent system 00145 Base::re_update (); 00146 00147 const std::vector<dof_id_type>& send_list = this->get_dof_map().get_send_list (); 00148 00149 const dof_id_type first_local_dof = Base::get_dof_map().first_dof(); 00150 const dof_id_type end_local_dof = Base::get_dof_map().end_dof(); 00151 00152 // Check sizes 00153 libmesh_assert_greater_equal (end_local_dof, first_local_dof); 00154 libmesh_assert_greater_equal (older_local_solution->size(), send_list.size()); 00155 libmesh_assert_greater_equal (old_local_solution->size(), send_list.size()); 00156 00157 // Even if we don't have to do anything ourselves, localize() may 00158 // use parallel_only tools 00159 // if (first_local_dof == end_local_dof) 00160 // return; 00161 00162 // Update the old & older solutions with the send_list, 00163 // which may have changed since their last update. 00164 older_local_solution->localize (first_local_dof, 00165 end_local_dof-1, 00166 send_list); 00167 00168 old_local_solution->localize (first_local_dof, 00169 end_local_dof-1, 00170 send_list); 00171 } 00172 00173 00174 00175 00176 template <class Base> 00177 Number TransientSystem<Base>::old_solution (const dof_id_type global_dof_number) const 00178 { 00179 // Check the sizes 00180 libmesh_assert_less (global_dof_number, this->get_dof_map().n_dofs()); 00181 libmesh_assert_less (global_dof_number, old_local_solution->size()); 00182 00183 return (*old_local_solution)(global_dof_number); 00184 } 00185 00186 00187 00188 template <class Base> 00189 Number TransientSystem<Base>::older_solution (const dof_id_type global_dof_number) const 00190 { 00191 // Check the sizes 00192 libmesh_assert_less (global_dof_number, this->get_dof_map().n_dofs()); 00193 libmesh_assert_less (global_dof_number, older_local_solution->size()); 00194 00195 return (*older_local_solution)(global_dof_number); 00196 } 00197 00198 00199 00200 00201 // ------------------------------------------------------------ 00202 // TransientSystem instantiations 00203 template class TransientSystem<LinearImplicitSystem>; 00204 template class TransientSystem<NonlinearImplicitSystem>; 00205 template class TransientSystem<ExplicitSystem>; 00206 template class TransientSystem<System>; 00207 template class TransientSystem<RBConstruction>; 00208 00209 } // namespace libMesh