|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 00010 #include <stk_linsys/LinearSystem.hpp> 00011 #include <stk_linsys/ImplDetails.hpp> 00012 #include <stk_mesh/base/GetBuckets.hpp> 00013 00014 #include <stk_linsys/LinsysFunctions.hpp> 00015 00016 #include <fei_Trilinos_Helpers.hpp> 00017 00018 namespace stk_classic { 00019 namespace linsys { 00020 00021 LinearSystem::LinearSystem(MPI_Comm comm, fei::SharedPtr<fei::Factory> factory) 00022 : m_fei_factory(factory), 00023 m_dof_mapper(comm), 00024 m_fei_mgraph(new fei::MatrixGraph_Impl2(m_dof_mapper.get_fei_VectorSpace(), fei::SharedPtr<fei::VectorSpace>())), 00025 m_fei_linearsystem(), 00026 m_param_set() 00027 { 00028 } 00029 00030 LinearSystem::~LinearSystem() 00031 { 00032 } 00033 00034 void 00035 LinearSystem::set_parameters(Teuchos::ParameterList& paramlist) 00036 { 00037 Trilinos_Helpers::copy_parameterlist(paramlist, m_param_set); 00038 m_dof_mapper.get_fei_VectorSpace()->setParameters(m_param_set); 00039 if (m_fei_factory.get() != NULL) { 00040 m_fei_factory->parameters(m_param_set); 00041 } 00042 if (m_fei_mgraph.get() != NULL) { 00043 m_fei_mgraph->setParameters(m_param_set); 00044 } 00045 } 00046 00047 void 00048 LinearSystem::synchronize_mappings_and_structure() 00049 { 00050 m_fei_mgraph->initComplete(); 00051 m_dof_mapper.finalize(); 00052 } 00053 00054 void 00055 LinearSystem::create_fei_LinearSystem() 00056 { 00057 m_fei_linearsystem = m_fei_factory->createLinearSystem(m_fei_mgraph); 00058 m_fei_linearsystem->parameters(m_param_set); 00059 00060 fei::SharedPtr<fei::Matrix> mtx = m_fei_factory->createMatrix(m_fei_mgraph); 00061 mtx->parameters(m_param_set); 00062 m_fei_linearsystem->setMatrix(mtx); 00063 fei::SharedPtr<fei::Vector> rhs = m_fei_factory->createVector(m_fei_mgraph); 00064 m_fei_linearsystem->setRHS(rhs); 00065 fei::SharedPtr<fei::Vector> soln = m_fei_factory->createVector(m_fei_mgraph,true); 00066 m_fei_linearsystem->setSolutionVector(soln); 00067 } 00068 00069 void 00070 LinearSystem::finalize_assembly() 00071 { 00072 m_fei_linearsystem->loadComplete(); 00073 } 00074 00075 const DofMapper& 00076 LinearSystem::get_DofMapper() const 00077 { 00078 return m_dof_mapper; 00079 } 00080 00081 DofMapper& 00082 LinearSystem::get_DofMapper() 00083 { 00084 return m_dof_mapper; 00085 } 00086 00087 void 00088 LinearSystem::reset_to_zero() 00089 { 00090 fei::SharedPtr<fei::Matrix> mtx = m_fei_linearsystem->getMatrix(); 00091 if (mtx.get() != NULL) { 00092 mtx->putScalar(0); 00093 } 00094 00095 fei::SharedPtr<fei::Vector> rhs = m_fei_linearsystem->getRHS(); 00096 if (rhs.get() != NULL) { 00097 rhs->putScalar(0); 00098 } 00099 } 00100 00101 const fei::SharedPtr<fei::MatrixGraph> 00102 LinearSystem::get_fei_MatrixGraph() const 00103 { 00104 return m_fei_mgraph; 00105 } 00106 00107 fei::SharedPtr<fei::MatrixGraph> 00108 LinearSystem::get_fei_MatrixGraph() 00109 { 00110 return m_fei_mgraph; 00111 } 00112 00113 const fei::SharedPtr<fei::LinearSystem> 00114 LinearSystem::get_fei_LinearSystem() const 00115 { 00116 return m_fei_linearsystem; 00117 } 00118 00119 fei::SharedPtr<fei::LinearSystem> 00120 LinearSystem::get_fei_LinearSystem() 00121 { 00122 return m_fei_linearsystem; 00123 } 00124 00125 void 00126 LinearSystem::write_files(const std::string& base_name) const 00127 { 00128 fei::SharedPtr<fei::Matrix> A = m_fei_linearsystem->getMatrix(); 00129 if (A.get() != NULL) { 00130 std::ostringstream ossA; 00131 ossA << "A_" << base_name << ".mtx"; 00132 std::string Aname = ossA.str(); 00133 A->writeToFile(Aname.c_str()); 00134 } 00135 fei::SharedPtr<fei::Vector> b = m_fei_linearsystem->getRHS(); 00136 if (b.get() != NULL) { 00137 std::ostringstream ossb; 00138 ossb << "b_" << base_name << ".vec"; 00139 std::string bname = ossb.str(); 00140 b->writeToFile(bname.c_str()); 00141 } 00142 } 00143 00144 int 00145 LinearSystem::solve(int &status, const Teuchos::ParameterList & params ) 00146 { 00147 return fei_solve(status, *m_fei_linearsystem, params); 00148 } 00149 00150 }//namespace linsys 00151 }//namespace stk_classic 00152