/** * @file solver_dirichlet.cpp * @author Julian Iseringhausen * @date Mon Apr 18 13:11:32 2011 * * @brief VMG::SolverDirichlet * */ #ifdef HAVE_CONFIG_H #include #endif #include #include "base/discretization.hpp" #include "base/stencil.hpp" #include "grid/multigrid.hpp" #include "solver/solver_dirichlet.hpp" #include "mg.hpp" using namespace VMG; // TODO: Implement global communication here // TODO: Implement this more efficiently // TODO: This has to be reviewed for parallelization void SolverDirichlet::AssembleMatrix(const Grid& rhs) { Index i; int mat_index, mat_index2; vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(rhs); const Stencil& A = MG::GetDiscretization()->GetStencil(); #ifdef DEBUG rhs.IsConsistent(); #endif this->Realloc(rhs.Global().Size().Product()); for (i.X()=rhs.Local().Begin().X(); i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = 0.0; this->Rhs(mat_index) = prefactor_inv * rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = A.GetDiag(); for (Stencil::iterator iter = A.begin(); iter != A.end(); iter++) { mat_index2 = rhs.GlobalLinearIndex(i + rhs.Global().Begin() + iter); assert(mat_index2 >= 0 && mat_index2Size()); this->Mat(mat_index, mat_index2) += iter->val; } } for (i.X()=rhs.Local().BoundaryBegin1().X(); i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } for (i.X()=rhs.Local().BoundaryBegin2().X(); i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } for (i.X()=0; i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } for (i.X()=0; i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } for (i.X()=0; i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } for (i.X()=0; i.X()= 0 && mat_indexSize()); this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(i); for (int l=0; lSize(); l++) this->Mat(mat_index, l) = 0.0; this->Mat(mat_index, mat_index) = 1.0; } } void SolverDirichlet::ExportSol(Grid& sol, Grid& rhs) { int index; for (int i=0; iSol(index); } #ifdef DEBUG sol.IsConsistent(); rhs.IsConsistent(); #endif }