OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
SinusoidalTimeDependence.cpp
Go to the documentation of this file.
1//
2// Class SinusoidalTimeDependence
3// A time dependence class that generates sine waves
4//
5// Copyright (c) 2025, Jon Thompson, STFC Rutherford Appleton Laboratory, Didcot, UK
6//
7// This file is part of OPAL.
8//
9// OPAL is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// You should have received a copy of the GNU General Public License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
17
19#include <Physics/Physics.h>
21#include "Utility/Inform.h"
22
23
25 const std::vector<double>& f, const std::vector<double>& p, const std::vector<double>& a,
26 const std::vector<double>& o)
27 : f_m(f), p_m(p), a_m(a), o_m(o) {
28}
29
30double SinusoidalTimeDependence::getValue(const double time) {
31 double result{};
32 for (size_t i = 0; i < f_m.size(); i++) {
33 const auto f = f_m[i];
34 auto p = 0.0;
35 auto a = 1.0;
36 auto o = 0.0;
37 if (i < p_m.size()) {
38 p = p_m[i];
39 }
40 if (i < a_m.size()) {
41 a = a_m[i];
42 }
43 if (i < o_m.size()) {
44 o = o_m[i];
45 }
46 const auto angle = 2.0 * Physics::pi * f * time + p;
47 result += a / 2.0 * std::sin(angle) + o;
48 }
49 return result;
50}
51
55
57 const Inform::FmtFlags_t ff = os.flags();
58 os << std::scientific;
59 os << "f=[";
60 for (size_t i = 0; i < this->f_m.size(); i++) {
61 if (i != 0) {
62 os << ", ";
63 }
64 os << this->f_m[i];
65 }
66 os << "], p=[";
67 for (size_t i = 0; i < this->p_m.size(); i++) {
68 if (i != 0) {
69 os << ", ";
70 }
71 os << this->p_m[i];
72 }
73 os << "], a=[";
74 for (size_t i = 0; i < this->a_m.size(); i++) {
75 if (i != 0) {
76 os << ", ";
77 }
78 os << this->a_m[i];
79 }
80 os << "], o=[";
81 for (size_t i = 0; i < this->o_m.size(); i++) {
82 if (i != 0) {
83 os << ", ";
84 }
85 os << this->o_m[i];
86 }
87 os << endl;
88 os.flags(ff);
89 return os;
90}
std::complex< double > a
Inform & endl(Inform &inf)
Definition Inform.cpp:42
constexpr double pi
The value of.
Definition Physics.h:30
SinusoidalTimeDependence(const std::vector< double > &f, const std::vector< double > &p, const std::vector< double > &a, const std::vector< double > &o)
SinusoidalTimeDependence * clone() override
Inform & print(Inform &os) const
SinusoidalTimeDependence()=default
double getValue(double time) override
std::ios_base::fmtflags FmtFlags_t
Definition Inform.h:99
FmtFlags_t flags() const
Definition Inform.h:106