Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Field.hpp
Go to the documentation of this file.
1#ifndef PHYTH_FIELD_HPP
2#define PHYTH_FIELD_HPP
3
6
7#include <memory>
8#include <unordered_set>
9
10namespace Phyth {
37 template<typename T>
38 class Field {
39 public:
40 using value_type = T;
41
42 virtual ~Field() = default;
43
53 [[nodiscard]] virtual T GetValueAt(const Vector3<Quantity<Meter> > &point) const = 0;
54
62 virtual void Update() {
63 }
64 };
65
71 template<typename, typename = void>
72 struct is_field_impl : std::false_type {
73 };
74
75 template<typename T>
76 struct is_field_impl<T, std::void_t<
77 decltype(static_cast<Field<typename T::value_type> *>(std::declval<T *>()))
78 > > : std::is_base_of<Field<typename T::value_type>, T> {
79 };
80
89 template<typename T>
90 struct is_field : is_field_impl<T> {
91 };
92
96 template<typename T>
97 inline constexpr bool is_field_v = is_field<T>::value;
98
122 template<typename FieldT>
123 class CombineField : public Field<typename FieldT::value_type> {
124 static_assert(is_field_v<FieldT>, "FieldT must be a Field.");
125
126 public:
135 void AddField(std::shared_ptr<FieldT> field) {
136 fields_.insert(std::move(field));
137 }
138
139 protected:
140 std::unordered_set<std::shared_ptr<FieldT> > fields_;
141 };
142}
143
144#endif // PHYTH_FIELD_HPP
Combine multiple fields of the same type.
Definition Field.hpp:123
void AddField(std::shared_ptr< FieldT > field)
Add a field to the combination.
Definition Field.hpp:135
std::unordered_set< std::shared_ptr< FieldT > > fields_
Definition Field.hpp:140
Base class for physical fields (scalar or vector)
Definition Field.hpp:38
virtual void Update()
Update the field state (for time-varying fields)
Definition Field.hpp:62
virtual T GetValueAt(const Vector3< Quantity< Meter > > &point) const =0
Get the field value at a specific point in space.
virtual ~Field()=default
constexpr bool is_field_v
Convenience variable template for is_field.
Definition Field.hpp:97
constexpr bool is_unit_v
Definition Unit.hpp:79
Physical quantity with a value and a compile-time unit.
Definition Quantity.hpp:27
3D vector with Quantity components
Definition Vector3.hpp:28
Implementation helper for is_field trait.
Definition Field.hpp:72
Type trait to check if a type is a Field instantiation.
Definition Field.hpp:90