-
Notifications
You must be signed in to change notification settings - Fork 16
/
function1D.h
147 lines (135 loc) · 5.24 KB
/
function1D.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors
#pragma once
#include "base/enumOptions.h"
#include "templates/flags.h"
#include <functional>
#include <string_view>
#include <vector>
// Function Properties
namespace FunctionProperties
{
enum FunctionProperty
{
FourierTransform,
Normalisation,
FirstDerivative
};
};
// Function Types
// -- Setup function parameters, returning vector augmented with any precalculated additional parameters
using Function1DSetup = std::function<std::vector<double>(std::vector<double> parameters)>;
// -- Function taking x and omega arguments and returning a value
using Function1DXOmega = std::function<double(double x, double omega, const std::vector<double> ¶meters)>;
// -- Function taking omega argument and returning a value
using Function1DOmega = std::function<double(double omega, const std::vector<double> ¶meters)>;
// One-Dimensional Function Definition
class Function1DDefinition
{
public:
Function1DDefinition(const std::vector<std::string> ¶meterNames,
const Flags<FunctionProperties::FunctionProperty> &properties, Function1DSetup setup,
Function1DXOmega y, Function1DXOmega dYdX = {}, Function1DXOmega yFT = {}, Function1DOmega norm = {});
private:
// Names of parameters defining the function
std::vector<std::string> parameterNames_;
// Properties of the function
Flags<FunctionProperties::FunctionProperty> properties_;
// Functions
Function1DSetup setup_;
Function1DXOmega y_, dYdX_, yFT_;
Function1DOmega normaliser_;
public:
// Return number of parameters the function requires
int nParameters() const;
// Return parameter names
const std::vector<std::string> ¶meterNames() const;
// Return properties of the function
const Flags<FunctionProperties::FunctionProperty> &properties() const;
// Return function for setup
Function1DSetup setup() const;
// Return function for y value
Function1DXOmega y() const;
// Return function for first derivative
Function1DXOmega dYdX() const;
// Return function for FT of y value
Function1DXOmega yFT() const;
// Return normalisation function
Function1DOmega normalisation() const;
};
// One-Dimensional Functional Forms
class Functions1D
{
public:
// Functional Forms
enum Form
{
None,
Gaussian,
ScaledGaussian,
OmegaDependentGaussian,
GaussianC2,
LennardJones126,
Buckingham,
};
// Return enum options for form
static EnumOptions<Form> forms();
// Return parameters for specified form
static const std::vector<std::string> ¶meters(Form form);
// Return nth parameter for the given form
static std::string parameter(Form form, int n);
// Return index of parameter in the given form
static std::optional<int> parameterIndex(Form form, std::string_view name);
// Return base function requested
static Function1DDefinition functionDefinition1D(Form func);
// Check function properties against those supplied, returning truth if the function meets all requirements
static bool validFunction1DProperties(Form func, const Flags<FunctionProperties::FunctionProperty> &properties);
// Return all available functions with properties matching those provided
static std::vector<Form> matchingFunction1D(const Flags<FunctionProperties::FunctionProperty> &properties);
};
// Function 1D Wrapper
class Function1DWrapper
{
public:
Function1DWrapper(Functions1D::Form form = Functions1D::Form::None, const std::vector<double> ¶ms = {});
/*
* Function
*/
private:
// Functional form
Functions1D::Form form_;
// Function definition
Function1DDefinition function_;
// Input arguments to function
std::vector<double> parameters_;
// Internal function parameters (input params followed by any calculated parameters)
std::vector<double> internalParameters_;
private:
// Initialise internal function parameters from current base parameters
void calculateInternalParameters();
public:
// Set function type and parameters
bool setFormAndParameters(Functions1D::Form form, const std::vector<double> ¶ms);
// Set current functional form
void setForm(Functions1D::Form form);
// Return functional form
Functions1D::Form form() const;
// Return number of parameters for current function
int nParameters() const;
// Set current function parameters
bool setParameters(const std::vector<double> ¶ms);
// Return current parameters
const std::vector<double> ¶meters() const;
// Return name of nth parameter
std::string parameterName(int i) const;
// Return parameter summary ("name = value, ...")
std::string parameterSummary() const;
// Return y value at specified x, omega
double y(double x, double omega = 0.0) const;
// Return first derivative of y at specified x, omega
double dYdX(double x, double omega = 0.0) const;
// Return Fourier transformed y value at specified x, omega
double yFT(double x, double omega = 0.0) const;
// Return normalisation factor at specified omega
double normalisation(double omega = 0.0) const;
};