Skip to content
Snippets Groups Projects
Commit 2956c87a authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[NL] pass solution to getKnownSolutions()

parent dfb2e304
No related branches found
No related tags found
No related merge requests found
...@@ -209,7 +209,7 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve( ...@@ -209,7 +209,7 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve(
BaseLib::RunTime time_dirichlet; BaseLib::RunTime time_dirichlet;
time_dirichlet.start(); time_dirichlet.start();
sys.applyKnownSolutionsNewton(J, res, minus_delta_x); sys.applyKnownSolutionsNewton(J, res, minus_delta_x, x);
INFO("[time] Applying Dirichlet BCs took %g s.", time_dirichlet.elapsed()); INFO("[time] Applying Dirichlet BCs took %g s.", time_dirichlet.elapsed());
if (!sys.isLinear() && _convergence_criterion->hasResidualCheck()) if (!sys.isLinear() && _convergence_criterion->hasResidualCheck())
...@@ -230,8 +230,7 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve( ...@@ -230,8 +230,7 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve(
// cf. // cf.
// http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecWAXPY.html // http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecWAXPY.html
auto& x_new = auto& x_new =
NumLib::GlobalVectorProvider::provider.getVector( NumLib::GlobalVectorProvider::provider.getVector(x, _x_new_id);
x, _x_new_id);
LinAlg::axpy(x_new, -_damping, minus_delta_x); LinAlg::axpy(x_new, -_damping, minus_delta_x);
if (postIterationCallback) if (postIterationCallback)
...@@ -252,16 +251,14 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve( ...@@ -252,16 +251,14 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve(
"iteration" "iteration"
" has to be repeated."); " has to be repeated.");
// TODO introduce some onDestroy hook. // TODO introduce some onDestroy hook.
NumLib::GlobalVectorProvider::provider NumLib::GlobalVectorProvider::provider.releaseVector(x_new);
.releaseVector(x_new);
continue; // That throws the iteration result away. continue; // That throws the iteration result away.
} }
// TODO could be done via swap. Note: that also requires swapping // TODO could be done via swap. Note: that also requires swapping
// the ids. Same for the Picard scheme. // the ids. Same for the Picard scheme.
LinAlg::copy(x_new, x); // copy new solution to x LinAlg::copy(x_new, x); // copy new solution to x
NumLib::GlobalVectorProvider::provider.releaseVector( NumLib::GlobalVectorProvider::provider.releaseVector(x_new);
x_new);
} }
if (!iteration_succeeded) if (!iteration_succeeded)
......
...@@ -59,7 +59,8 @@ public: ...@@ -59,7 +59,8 @@ public:
//! Apply known solutions to the linearized equation system //! Apply known solutions to the linearized equation system
//! \f$ \mathit{Jac} \cdot (-\Delta x) = \mathit{res} \f$. //! \f$ \mathit{Jac} \cdot (-\Delta x) = \mathit{res} \f$.
virtual void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res, virtual void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) = 0; GlobalVector& minus_delta_x,
GlobalVector& x) = 0;
}; };
/*! A System of nonlinear equations to be solved with the Picard fixpoint /*! A System of nonlinear equations to be solved with the Picard fixpoint
......
...@@ -48,18 +48,19 @@ public: ...@@ -48,18 +48,19 @@ public:
virtual void preAssemble(const double t, GlobalVector const& x) = 0; virtual void preAssemble(const double t, GlobalVector const& x) = 0;
//! Assemble \c M, \c K and \c b at the provided state (\c t, \c x). //! Assemble \c M, \c K and \c b at the provided state (\c t, \c x).
virtual void assemble( virtual void assemble(const double t, GlobalVector const& x,
const double t, GlobalVector const& x, GlobalMatrix& M, GlobalMatrix& K, GlobalMatrix& M, GlobalMatrix& K,
GlobalVector& b) = 0; GlobalVector& b) = 0;
using Index = MathLib::MatrixVectorTraits<GlobalMatrix>::Index; using Index = MathLib::MatrixVectorTraits<GlobalMatrix>::Index;
//! Provides known solutions (Dirichlet boundary conditions) vector for //! Provides known solutions (Dirichlet boundary conditions) vector for
//! the ode system at the given time \c t. //! the ode system at the given time \c t.
virtual std::vector<NumLib::IndexValueVector<Index>> const* virtual std::vector<NumLib::IndexValueVector<Index>> const*
getKnownSolutions(double const t) const getKnownSolutions(double const t, GlobalVector const& x) const
{ {
(void)t; (void)t;
(void)x;
return nullptr; // by default there are no known solutions return nullptr; // by default there are no known solutions
} }
}; };
...@@ -76,7 +77,6 @@ class ODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, ...@@ -76,7 +77,6 @@ class ODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
NonlinearSolverTag::Picard> NonlinearSolverTag::Picard>
{ {
public: public:
//! Calls process' pre-assembly with the provided state (\c t, \c x). //! Calls process' pre-assembly with the provided state (\c t, \c x).
virtual void preAssemble(const double t, GlobalVector const& x) = 0; virtual void preAssemble(const double t, GlobalVector const& x) = 0;
...@@ -124,11 +124,12 @@ public: ...@@ -124,11 +124,12 @@ public:
* \mathtt{Jac} \f$. * \mathtt{Jac} \f$.
* \endparblock * \endparblock
*/ */
virtual void assembleWithJacobian( virtual void assembleWithJacobian(const double t, GlobalVector const& x,
const double t, GlobalVector const& x, GlobalVector const& xdot, GlobalVector const& xdot,
const double dxdot_dx, const double dx_dx, GlobalMatrix& M, const double dxdot_dx, const double dx_dx,
GlobalMatrix& K, GlobalVector& b, GlobalMatrix& Jac) = 0; GlobalMatrix& M, GlobalMatrix& K,
GlobalVector& b, GlobalMatrix& Jac) = 0;
}; };
//! @} //! @}
} } // namespace NumLib
...@@ -34,14 +34,14 @@ void applyKnownSolutions(std::vector<Solutions> const* const known_solutions, ...@@ -34,14 +34,14 @@ void applyKnownSolutions(std::vector<Solutions> const* const known_solutions,
} }
MathLib::LinAlg::finalizeAssembly(x); MathLib::LinAlg::finalizeAssembly(x);
} }
} } // namespace detail
namespace NumLib namespace NumLib
{ {
TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
NonlinearSolverTag::Newton>:: NonlinearSolverTag::Newton>::
TimeDiscretizedODESystem(const int process_id, TimeDiscretizedODESystem(const int process_id, ODE& ode,
ODE& ode, TimeDisc& time_discretization) TimeDisc& time_discretization)
: _ode(ode), : _ode(ode),
_time_disc(time_discretization), _time_disc(time_discretization),
_mat_trans(createMatrixTranslator<ODETag>(time_discretization)) _mat_trans(createMatrixTranslator<ODETag>(time_discretization))
...@@ -66,9 +66,9 @@ TimeDiscretizedODESystem< ...@@ -66,9 +66,9 @@ TimeDiscretizedODESystem<
NumLib::GlobalVectorProvider::provider.releaseVector(*_b); NumLib::GlobalVectorProvider::provider.releaseVector(*_b);
} }
void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, void TimeDiscretizedODESystem<
NonlinearSolverTag::Newton>:: ODESystemTag::FirstOrderImplicitQuasilinear,
assemble(const GlobalVector& x_new_timestep) NonlinearSolverTag::Newton>::assemble(const GlobalVector& x_new_timestep)
{ {
namespace LinAlg = MathLib::LinAlg; namespace LinAlg = MathLib::LinAlg;
...@@ -125,16 +125,16 @@ void TimeDiscretizedODESystem< ...@@ -125,16 +125,16 @@ void TimeDiscretizedODESystem<
NonlinearSolverTag::Newton>::applyKnownSolutions(GlobalVector& x) const NonlinearSolverTag::Newton>::applyKnownSolutions(GlobalVector& x) const
{ {
::detail::applyKnownSolutions( ::detail::applyKnownSolutions(
_ode.getKnownSolutions(_time_disc.getCurrentTime()), x); _ode.getKnownSolutions(_time_disc.getCurrentTime(), x), x);
} }
void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
NonlinearSolverTag::Newton>:: NonlinearSolverTag::Newton>::
applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res, applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) GlobalVector& minus_delta_x, GlobalVector& x)
{ {
auto const* known_solutions = auto const* known_solutions =
_ode.getKnownSolutions(_time_disc.getCurrentTime()); _ode.getKnownSolutions(_time_disc.getCurrentTime(), x);
if (!known_solutions || known_solutions->empty()) if (!known_solutions || known_solutions->empty())
return; return;
...@@ -149,6 +149,8 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, ...@@ -149,6 +149,8 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
// For the Newton method the values must be zero // For the Newton method the values must be zero
std::vector<double> values(ids.size(), 0); std::vector<double> values(ids.size(), 0);
MathLib::applyKnownSolution(Jac, res, minus_delta_x, ids, values); MathLib::applyKnownSolution(Jac, res, minus_delta_x, ids, values);
::detail::applyKnownSolutions(known_solutions, x);
} }
TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
...@@ -176,9 +178,9 @@ TimeDiscretizedODESystem< ...@@ -176,9 +178,9 @@ TimeDiscretizedODESystem<
NumLib::GlobalVectorProvider::provider.releaseVector(*_b); NumLib::GlobalVectorProvider::provider.releaseVector(*_b);
} }
void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, void TimeDiscretizedODESystem<
NonlinearSolverTag::Picard>:: ODESystemTag::FirstOrderImplicitQuasilinear,
assemble(const GlobalVector& x_new_timestep) NonlinearSolverTag::Picard>::assemble(const GlobalVector& x_new_timestep)
{ {
namespace LinAlg = MathLib::LinAlg; namespace LinAlg = MathLib::LinAlg;
...@@ -202,7 +204,7 @@ void TimeDiscretizedODESystem< ...@@ -202,7 +204,7 @@ void TimeDiscretizedODESystem<
NonlinearSolverTag::Picard>::applyKnownSolutions(GlobalVector& x) const NonlinearSolverTag::Picard>::applyKnownSolutions(GlobalVector& x) const
{ {
::detail::applyKnownSolutions( ::detail::applyKnownSolutions(
_ode.getKnownSolutions(_time_disc.getCurrentTime()), x); _ode.getKnownSolutions(_time_disc.getCurrentTime(), x), x);
} }
void TimeDiscretizedODESystem< void TimeDiscretizedODESystem<
...@@ -212,7 +214,7 @@ void TimeDiscretizedODESystem< ...@@ -212,7 +214,7 @@ void TimeDiscretizedODESystem<
GlobalVector& x) GlobalVector& x)
{ {
auto const* known_solutions = auto const* known_solutions =
_ode.getKnownSolutions(_time_disc.getCurrentTime()); _ode.getKnownSolutions(_time_disc.getCurrentTime(), x);
if (known_solutions) if (known_solutions)
{ {
...@@ -229,4 +231,4 @@ void TimeDiscretizedODESystem< ...@@ -229,4 +231,4 @@ void TimeDiscretizedODESystem<
} }
} }
} // NumLib } // namespace NumLib
...@@ -92,7 +92,8 @@ public: ...@@ -92,7 +92,8 @@ public:
void applyKnownSolutions(GlobalVector& x) const override; void applyKnownSolutions(GlobalVector& x) const override;
void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res, void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) override; GlobalVector& minus_delta_x,
GlobalVector& x) override;
bool isLinear() const override bool isLinear() const override
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment