version 3.10-dev
newmarkbeta.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_TIMESTEPPING_NEWMARK_BETA_HH
14#define DUMUX_TIMESTEPPING_NEWMARK_BETA_HH
15
17
18namespace Dumux::Experimental {
19
32template<class Scalar, class Solution>
34{
35 using Block = typename Solution::block_type;
36public:
39 NewmarkBeta(const Scalar beta, const Scalar gamma)
40 : beta_(beta)
41 , gamma_(gamma)
42 {}
43
48 getParam<Scalar>("NewmarkBeta.Beta", 0.25),
49 getParam<Scalar>("NewmarkBeta.Gamma", 0.5)
50 ) {}
51
54 void initialize(const Solution& x)
55 {
56 x_ = x;
57
58 // make sure the size is correct, but the values are zero
59 v_ = x; v_ = 0.0;
60 a_ = x; a_ = 0.0;
61 }
62
64 void initialize(const Solution& x, const Solution& v, const Solution& a)
65 {
66 x_ = x;
67 v_ = v;
68 a_ = a;
69 }
70
72 void update(const Scalar dt, const Solution& x)
73 {
74 for (std::size_t i = 0; i < x_.size(); ++i)
75 {
76 const auto xNew = x[i];
77 const auto aNew = acceleration(i, dt, xNew);
78 const auto vNew = velocity(i, dt, xNew, aNew);
79
80 x_[i] = xNew;
81 v_[i] = vNew;
82 a_[i] = aNew;
83 }
84 }
85
87 Block acceleration(const std::size_t index, const Scalar dt, const Block& x) const
88 {
89 const auto& x0 = x_[index];
90 const auto& v0 = v_[index];
91 const auto& a0 = a_[index];
92
93 return (x - x0 - dt*v0)/(beta_*dt*dt) + (beta_ - 0.5)/beta_*a0;
94 }
95
97 Block velocity(const std::size_t index, const Scalar dt, const Block& x, const Block& a) const
98 {
99 const auto& v0 = v_[index];
100 const auto& a0 = a_[index];
101
102 return v0 + dt*((1.0-gamma_)*a0 + gamma_*a);
103 }
104
106 Block velocity(const std::size_t index, const Scalar dt, const Block& x) const
107 {
108 const auto a = acceleration(index, dt, x);
109 return velocity(index, dt, x, a);
110 }
111
113 Scalar position(const std::size_t index) const
114 { return x_[index]; }
115
117 Scalar velocity(const std::size_t index) const
118 { return v_[index]; }
119
121 Scalar acceleration(const std::size_t index) const
122 { return a_[index]; }
123
124private:
125 Scalar beta_, gamma_;
126 Solution x_, v_, a_;
127};
128
129} // end namespace Dumux::Experimental
130
131#endif
Newmark-beta time integration scheme.
Definition: newmarkbeta.hh:34
NewmarkBeta()
Definition: newmarkbeta.hh:46
Block velocity(const std::size_t index, const Scalar dt, const Block &x, const Block &a) const
new v in terms of the old v, a, the new x, a and the time step size
Definition: newmarkbeta.hh:97
void initialize(const Solution &x, const Solution &v, const Solution &a)
Initialize the time integration scheme with the current solution.
Definition: newmarkbeta.hh:64
NewmarkBeta(const Scalar beta, const Scalar gamma)
Definition: newmarkbeta.hh:39
Block acceleration(const std::size_t index, const Scalar dt, const Block &x) const
new a in terms of the old x, v, a, the new x and the time step size
Definition: newmarkbeta.hh:87
Scalar position(const std::size_t index) const
current position
Definition: newmarkbeta.hh:113
Scalar velocity(const std::size_t index) const
current velocity
Definition: newmarkbeta.hh:117
void initialize(const Solution &x)
Definition: newmarkbeta.hh:54
void update(const Scalar dt, const Solution &x)
Update with new position x.
Definition: newmarkbeta.hh:72
Scalar acceleration(const std::size_t index) const
current acceleration
Definition: newmarkbeta.hh:121
Block velocity(const std::size_t index, const Scalar dt, const Block &x) const
new v in terms of the old v, a, the new x and the time step size
Definition: newmarkbeta.hh:106
T getParam(Args &&... args)
A free function to get a parameter from the parameter tree singleton.
Definition: parameters.hh:139
Definition: experimental/assembly/cclocalassembler.hh:36
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.