37 #include "SimpleLinearEllipticSolver.hpp" 38 #include "SimpleNonlinearEllipticSolver.hpp" 39 #include "SimpleNewtonNonlinearSolver.hpp" 40 #include "FiniteElementSolver.hpp" 42 template<
unsigned DIM>
46 mUseLinearSolveForGuess(false),
52 template<
unsigned DIM>
58 template <
unsigned DIM>
65 template<
unsigned DIM>
70 this->
mpPde->UpdateDiscreteSourceStrengths();
78 template<
unsigned DIM>
84 template<
unsigned DIM>
90 template<
unsigned DIM>
96 template<
unsigned DIM>
105 boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 1> > p_bcc =
106 boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 1> >(
new BoundaryConditionsContainer<DIM, DIM, 1> );
118 this->
mpPde->SetUseRegularGrid(
false);
120 this->
mpPde->UpdateDiscreteSourceStrengths();
122 SimpleLinearEllipticSolver<DIM, DIM> static_solver(this->
mpMesh.get(), this->
mpPde.get(), p_bcc.get());
123 ReplicatableVector solution_repl(static_solver.Solve());
125 this->
mSolution = std::vector<double>(solution_repl.GetSize());
126 this->
mConcentrations = std::vector<units::quantity<unit::concentration> >(solution_repl.GetSize());
127 for(
unsigned idx = 0; idx < solution_repl.GetSize(); idx++)
129 this->mSolution[idx] = solution_repl[idx];
142 this->
mpPde->SetUseRegularGrid(
false);
144 this->
mpPde->UpdateDiscreteSourceStrengths();
146 SimpleLinearEllipticSolver<DIM, DIM> static_solver(this->
mpMesh.get(), this->
mpPde.get(), p_bcc.get());
147 ReplicatableVector static_solution_repl(static_solver.Solve());
149 std::vector<double> solution = std::vector<double>(static_solution_repl.GetSize());
150 for(
unsigned idx = 0; idx < static_solution_repl.GetSize(); idx++)
152 solution[idx]= static_solution_repl[idx];
154 if(solution[idx]<0.0)
160 Vec initial_guess = PetscTools::CreateVec(this->
mpMesh->GetNumNodes());
161 for(
unsigned idx=0; idx<solution.size();idx++)
163 PetscVecTools::SetElement(initial_guess, idx, solution[idx]);
165 PetscVecTools::Finalise(initial_guess);
167 SimpleNonlinearEllipticSolver<DIM, DIM> solver(this->
mpMesh.get(), this->
mpNonLinearPde.get(), p_bcc.get());
168 SimpleNewtonNonlinearSolver newton_solver;
171 solver.SetNonlinearSolver(&newton_solver);
172 newton_solver.SetTolerance(1e-5);
173 newton_solver.SetWriteStats();
176 ReplicatableVector solution_repl(solver.Solve(initial_guess));
177 this->
mSolution = std::vector<double>(solution_repl.GetSize());
178 this->
mConcentrations = std::vector<units::quantity<unit::concentration> >(solution_repl.GetSize());
179 for(
unsigned idx = 0; idx < solution_repl.GetSize(); idx++)
181 this->mSolution[idx] = solution_repl[idx];
185 PetscTools::Destroy(initial_guess);
190 SimpleNonlinearEllipticSolver<DIM, DIM> solver(this->
mpMesh.get(), this->
mpNonLinearPde.get(), p_bcc.get());
191 SimpleNewtonNonlinearSolver newton_solver;
194 solver.SetNonlinearSolver(&newton_solver);
195 newton_solver.SetTolerance(1e-5);
196 newton_solver.SetWriteStats();
199 ReplicatableVector solution_repl(solver.Solve(initial_guess));
200 this->
mSolution = std::vector<double>(solution_repl.GetSize());
201 this->
mConcentrations = std::vector<units::quantity<unit::concentration> >(solution_repl.GetSize());
202 for(
unsigned idx = 0; idx < solution_repl.GetSize(); idx++)
204 this->mSolution[idx] = solution_repl[idx];
208 PetscTools::Destroy(initial_guess);
213 EXCEPTION(
"PDE Type could not be identified, did you set a PDE?");
boost::shared_ptr< AbstractDiscreteContinuumLinearEllipticPde< DIM, DIM > > mpPde
bool mUseLinearSolveForGuess
void SetUseSimpleNetonSolver(bool useNewton)
std::vector< units::quantity< unit::concentration > > mConcentrations
virtual void UpdateSolution(const std::vector< double > &rData)
void SetUseLinearSolveForGuess(bool useLinearSolve)
static boost::shared_ptr< FiniteElementSolver< DIM > > Create()
std::vector< boost::shared_ptr< DiscreteContinuumBoundaryCondition< DIM > > > mBoundaryConditions
boost::shared_ptr< AbstractDiscreteContinuumNonLinearEllipticPde< DIM, DIM > > mpNonLinearPde
void SetGuess(const std::vector< double > &guess)
virtual ~FiniteElementSolver()
units::quantity< unit::concentration > mReferenceConcentration
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > mpMesh
std::vector< double > mSolution
std::vector< double > mGuess