22 #include "linear_solver.h"
24 using namespace Hermes::Algebra;
30 template<
typename Scalar>
31 LinearSolver<Scalar>::LinearSolver() : dp(new DiscreteProblemLinear<Scalar>()), sln_vector(NULL), own_dp(true)
36 template<
typename Scalar>
37 LinearSolver<Scalar>::LinearSolver(DiscreteProblemLinear<Scalar>* dp) : dp(dp), sln_vector(NULL), own_dp(false)
42 template<
typename Scalar>
43 LinearSolver<Scalar>::LinearSolver(
const WeakForm<Scalar>* wf,
const Space<Scalar>* space) : dp(new DiscreteProblemLinear<Scalar>(wf, space)), sln_vector(NULL), own_dp(true)
48 template<
typename Scalar>
49 LinearSolver<Scalar>::LinearSolver(
const WeakForm<Scalar>* wf, Hermes::vector<
const Space<Scalar>*> spaces) : dp(new DiscreteProblemLinear<Scalar>(wf, spaces)), sln_vector(NULL), own_dp(true)
54 template<
typename Scalar>
55 void LinearSolver<Scalar>::init()
57 this->jacobian = create_matrix<Scalar>();
58 this->residual = create_vector<Scalar>();
59 this->matrix_solver = create_linear_solver<Scalar>(this->jacobian, this->residual);
60 this->set_verbose_output(
true);
63 template<
typename Scalar>
73 template<
typename Scalar>
76 Hermes::vector<Space<Scalar>*> spaces;
77 for(
unsigned int i = 0; i < this->dp->get_spaces().size(); i++)
78 spaces.push_back(const_cast<
Space<Scalar>*>(this->dp->get_space(i)));
84 template<
typename Scalar>
90 template<
typename Scalar>
93 const_cast<WeakForm<Scalar>*
>(this->dp->wf)->set_current_time_step(time_step);
96 template<
typename Scalar>
99 return this->jacobian;
102 template<
typename Scalar>
105 return this->residual;
108 template<
typename Scalar>
114 template<
typename Scalar>
120 template<
typename Scalar>
126 template<
typename Scalar>
131 delete matrix_solver;
138 template<
typename Scalar>
145 this->on_initialization();
147 dp->assemble(this->jacobian, this->residual);
148 if(this->output_rhsOn && (this->output_rhsIterations == -1 || this->output_rhsIterations >= 1))
150 char* fileName =
new char[this->RhsFilename.length() + 5];
151 if(this->RhsFormat == Hermes::Algebra::DF_MATLAB_SPARSE)
152 sprintf(fileName,
"%s%i.m", this->RhsFilename.c_str(), 1);
154 sprintf(fileName,
"%s%i", this->RhsFilename.c_str(), 1);
155 FILE* rhs_file = fopen(fileName,
"w+");
156 residual->dump(rhs_file, this->RhsVarname.c_str(), this->RhsFormat, this->rhs_number_format);
159 if(this->output_matrixOn && (this->output_matrixIterations == -1 || this->output_matrixIterations >= 1))
161 char* fileName =
new char[this->matrixFilename.length() + 5];
162 if(this->matrixFormat == Hermes::Algebra::DF_MATLAB_SPARSE)
163 sprintf(fileName,
"%s%i.m", this->matrixFilename.c_str(), 1);
165 sprintf(fileName,
"%s%i", this->matrixFilename.c_str(), 1);
166 FILE* matrix_file = fopen(fileName,
"w+");
168 jacobian->dump(matrix_file, this->matrixVarname.c_str(), this->matrixFormat, this->matrix_number_format);
172 this->matrix_solver->solve();
174 this->sln_vector = matrix_solver->get_sln_vector();
179 this->info(
"\tLinear solver solution duration: %f s.\n", this->last());
182 template<
typename Scalar>
188 template class HERMES_API LinearSolver<double>;
189 template class HERMES_API LinearSolver<std::complex<double> >;