OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
PolynomialTimeDependence.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2026, Paul Scherrer Institute, Villigen PSI, Switzerland
3// All rights reserved
4//
5// This file is part of OPAL.
6//
7// OPAL is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// You should have received a copy of the GNU General License
13// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
14//
15
17#include <iostream>
18#include "Utility/Inform.h"
19
21 const auto temp(coeffs);
22 auto* d = new PolynomialTimeDependence(temp);
23 return d;
24}
25
26double PolynomialTimeDependence::getValue(const double time) {
27 double x = 0.;
28 double t_power = 1.;
29 for (const double coeff : coeffs) {
30 x += coeff * t_power;
31 t_power *= time;
32 }
33 return x;
34}
35
36double PolynomialTimeDependence::getIntegral(const double time) {
37 double result{};
38 double t_power{time};
39 for (std::size_t i = 0; i < coeffs.size(); ++i) {
40 result += coeffs[i] * t_power / static_cast<double>(i + 1);
41 t_power *= time;
42 }
43 return result;
44}
45
46Inform& PolynomialTimeDependence::print(Inform& os) const {
47 const Inform::FmtFlags_t ff = os.flags();
48 os << std::scientific;
49 for (unsigned int i = 0; i < this->coeffs.size(); i++) {
50 os << "c" << i << "= " << this->coeffs[i] << " ";
51 }
52 os << endl;
53 os.flags(ff);
54 return os;
55}
Inform & print(Inform &os) const
PolynomialTimeDependence()=default
PolynomialTimeDependence * clone() override
double getIntegral(double time) override
double getValue(double time) override