|
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/AggregateLinearSystem.hpp> 00011 #include <stk_linsys/LinearSystem.hpp> 00012 #include <stk_linsys/ImplDetails.hpp> 00013 #include <stk_mesh/base/GetBuckets.hpp> 00014 00015 #include <stk_linsys/LinsysFunctions.hpp> 00016 00017 namespace stk { 00018 namespace linsys { 00019 00020 AggregateLinearSystem::AggregateLinearSystem(MPI_Comm comm, fei::SharedPtr<fei::Factory> factory, size_t num_matrices, size_t num_rhsvecs) 00021 : m_fei_factory(factory), 00022 m_linear_system(comm, factory), 00023 m_matrices(num_matrices), 00024 m_rhsvecs(num_rhsvecs) 00025 { 00026 } 00027 00028 AggregateLinearSystem::~AggregateLinearSystem() 00029 { 00030 } 00031 00032 void 00033 AggregateLinearSystem::synchronize_mappings_and_structure() 00034 { 00035 m_linear_system.synchronize_mappings_and_structure(); 00036 } 00037 00038 void 00039 AggregateLinearSystem::create_fei_LinearSystem() 00040 { 00041 m_linear_system.create_fei_LinearSystem(); 00042 00043 fei::SharedPtr<fei::MatrixGraph> mgraph = m_linear_system.get_fei_MatrixGraph(); 00044 00045 for(size_t i=0; i<m_matrices.size(); ++i) { 00046 m_matrices[i] = m_fei_factory->createMatrix(mgraph); 00047 } 00048 00049 bool is_soln_vec = false; 00050 for(size_t i=0; i<m_rhsvecs.size(); ++i) { 00051 m_rhsvecs[i] = m_fei_factory->createVector(mgraph,is_soln_vec); 00052 } 00053 } 00054 00055 fei::SharedPtr<fei::Matrix> 00056 AggregateLinearSystem::get_matrix(size_t index) 00057 { 00058 if (index >= m_matrices.size()) { 00059 throw std::runtime_error("stk::linsys::AggregateLinearSystem::get_matrix ERROR, index out of range."); 00060 } 00061 00062 return m_matrices[index]; 00063 } 00064 00065 fei::SharedPtr<fei::Vector> 00066 AggregateLinearSystem::get_rhsvec(size_t index) 00067 { 00068 if (index >= m_rhsvecs.size()) { 00069 throw std::runtime_error("stk::linsys::AggregateLinearSystem::get_rhsvec ERROR, index out of range."); 00070 } 00071 00072 return m_rhsvecs[index]; 00073 } 00074 00075 void 00076 AggregateLinearSystem::aggregate_system(const std::vector<double>& mat_scalars, 00077 const std::vector<double>& rhs_scalars) 00078 { 00079 if (mat_scalars.size() != m_matrices.size()) { 00080 throw std::runtime_error("stk::linsys::AggregateLinearSystem::aggregate_system ERROR, mat_scalars.size() != m_matrices.size()."); 00081 } 00082 00083 if (rhs_scalars.size() != m_rhsvecs.size()) { 00084 throw std::runtime_error("stk::linsys::AggregateLinearSystem::aggregate_system ERROR, rhs_scalars.size() != m_rhsvecs.size()."); 00085 } 00086 00087 fei::SharedPtr<fei::LinearSystem> fei_linsys = m_linear_system.get_fei_LinearSystem(); 00088 fei::SharedPtr<fei::Matrix> matrix = fei_linsys->getMatrix(); 00089 fei::SharedPtr<fei::Vector> rhsvec = fei_linsys->getRHS(); 00090 00091 matrix->gatherFromOverlap(); 00092 matrix->putScalar(0.0); 00093 00094 for(size_t i=0; i<m_matrices.size(); ++i) { 00095 stk::linsys::add_matrix_to_matrix(mat_scalars[i], *m_matrices[i], *matrix); 00096 } 00097 00098 rhsvec->gatherFromOverlap(); 00099 rhsvec->putScalar(0.0); 00100 00101 for(size_t i=0; i<m_rhsvecs.size(); ++i) { 00102 stk::linsys::add_vector_to_vector(rhs_scalars[i], *m_rhsvecs[i], *rhsvec); 00103 } 00104 } 00105 00106 void 00107 AggregateLinearSystem::finalize_assembly() 00108 { 00109 m_linear_system.finalize_assembly(); 00110 } 00111 00112 const DofMapper& 00113 AggregateLinearSystem::get_DofMapper() const 00114 { 00115 return m_linear_system.get_DofMapper(); 00116 } 00117 00118 DofMapper& 00119 AggregateLinearSystem::get_DofMapper() 00120 { 00121 return m_linear_system.get_DofMapper(); 00122 } 00123 00124 const fei::SharedPtr<fei::MatrixGraph> 00125 AggregateLinearSystem::get_fei_MatrixGraph() const 00126 { 00127 return m_linear_system.get_fei_MatrixGraph(); 00128 } 00129 00130 fei::SharedPtr<fei::MatrixGraph> 00131 AggregateLinearSystem::get_fei_MatrixGraph() 00132 { 00133 return m_linear_system.get_fei_MatrixGraph(); 00134 } 00135 00136 const fei::SharedPtr<fei::LinearSystem> 00137 AggregateLinearSystem::get_fei_LinearSystem() const 00138 { 00139 return m_linear_system.get_fei_LinearSystem(); 00140 } 00141 00142 fei::SharedPtr<fei::LinearSystem> 00143 AggregateLinearSystem::get_fei_LinearSystem() 00144 { 00145 return m_linear_system.get_fei_LinearSystem(); 00146 } 00147 00148 int 00149 AggregateLinearSystem::solve(int &status, const Teuchos::ParameterList & params ) 00150 { 00151 return m_linear_system.solve(status, params); 00152 } 00153 00154 }//namespace linsys 00155 }//namespace stk 00156