Loading [MathJax]/jax/input/TeX/config.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
PlaneWave.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef CORE_EXTERNAL_FIELD_FIELDS_PLAIN_WAVE_HPP
20#define CORE_EXTERNAL_FIELD_FIELDS_PLAIN_WAVE_HPP
21
22#include "jacobian_type.hpp"
23
24#include <utils/Vector.hpp>
26
27#include <cmath>
28#include <cstddef>
29
30namespace FieldCoupling {
31namespace Fields {
32/**
33 * @brief A plane wave.
34 *
35 * A time-dependent plane wave, with a certain (vector-valued)
36 * amplitude, wave vector frequency and phase.
37 *
38 * See https://en.wikipedia.org/wiki/Plane_wave
39 */
40template <typename T, std::size_t codim> class PlaneWave {
41public:
42 using value_type =
44 using jacobian_type = detail::jacobian_type<T, codim>;
45
46private:
47 value_type m_amplitude;
48 value_type m_k;
49 T m_omega;
50 T m_phase;
51
52public:
54 : m_amplitude(amplitude), m_k(k), m_omega(omega), m_phase(phase) {}
55
56 value_type &amplitude() { return m_amplitude; }
57 value_type &k() { return m_k; }
58 T &omega() { return m_omega; }
59 T &phase() { return m_phase; }
60
61 /**
62 * brief Evaluate field.
63 *
64 * @param x Where?
65 * @param t When?
66 * @return Value of the field at point x and time t.
67 */
68 value_type operator()(const Utils::Vector3d &x, T t = 0.) const {
69 return m_amplitude * sin(m_k * x - m_omega * t + m_phase);
70 }
71
72 /**
73 * brief Evaluate the Jacobian matrix of the field.
74 *
75 * See https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant
76 * In the special case of a scalar field, the Jacobian is the gradient of
77 * the field.
78 *
79 * @param x Where?
80 * @param t When?
81 * @return Jacobian matrix
82 */
83 jacobian_type jacobian(const Utils::Vector3d &x, T t = 0.) const {
85
86 return tensor_product(m_amplitude, m_k) *
87 cos(m_k * x - m_omega * t + m_phase);
88 }
89
90 bool fits_in_box(const Utils::Vector3d &) const { return true; }
91};
92} // namespace Fields
93} // namespace FieldCoupling
94
95#endif
Vector implementation and trait types for boost qvm interoperability.
value_type operator()(const Utils::Vector3d &x, T t=0.) const
brief Evaluate field.
Definition PlaneWave.hpp:68
typename Utils::decay_to_scalar< Utils::Vector< T, codim > >::type value_type
Definition PlaneWave.hpp:43
bool fits_in_box(const Utils::Vector3d &) const
Definition PlaneWave.hpp:90
PlaneWave(const value_type amplitude, const value_type &k, T omega, T phase)
Definition PlaneWave.hpp:53
jacobian_type jacobian(const Utils::Vector3d &x, T t=0.) const
brief Evaluate the Jacobian matrix of the field.
Definition PlaneWave.hpp:83
detail::jacobian_type< T, codim > jacobian_type
Definition PlaneWave.hpp:44
Matrix< T, N, M > tensor_product(const Vector< T, N > &x, const Vector< T, M > &y)
Meta function to turns a Vector<1, T> into T.
Definition Vector.hpp:479