You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
(later maybe a CUDA version which supports C++17 features)
General Ideas
The library revolves around theField template class, which is a conveniencewrapper aroundstd::vector with added operators and functions. The Eigen libraryis used for vector operations.
Expression templates ensure that mathematical operations are used efficiently,avoiding temporaries.
The library provides conveniencetypedefs:
FMath::scalar = default isdouble, can be defined differently byFMATH_SCALAR_TYPE
FMath::ScalarField =FMath::Field<FMath::scalar>
FMath::Vector3 =Eigen::Vector3<FMath::scalar>
FMath::VectorX =Eigen::VectorX<FMath::scalar>
FMath::VectorField =FMath::Field<FMath::Vector3>
Parallelisation
Since almost all operations onFields, defined in this library, are either trivially parallelizableor typical reductions, both CPU and GPU could and should be used to speed up operations.
OpenMP 4.5 can easily be used to parallelize everything on CPU and also supports usage of devices.However, due to the lack of unified memory abstractions, GPU parallelisation does not yet come asnaturally.
Incorporation into your project
Adding this library to your project should be trivial.You can do it manually:
copy theFMath folder into your directory of choice
copy thethirdparty/Eigen folder or provide your own
make sure theFMath andEigen folders are in your include-directories
optionally defineFMATH_SCALAR_TYPE
optionally add OpenMP compiler flags to activate parallelisation
or using CMake:
copy the entire repository folder into your directory of choice
TODO...
Usage Examples
Reductions
#include<FMath/Core>// Single field reductionFMath::VectorFieldvf(N);FMath::scalar mean = vf.mean();// N-dimensional dot-productFMath::ScalarFieldsf1(N), sf2(N);sf1 *= sf2;FMath::scalar dot = sf1.sum();
Operators
#include<FMath/Core>FMath::VectorFieldvf1(N), vf2(N);FMath::ScalarFieldsf1(N);// This will produce an expression object, due to autoauto vf = vf1 + vf2*vf2;// This will actually evaluate the expressionFMath::ScalarField sf_result = vf.dot(vf1);
Copying or re-interpreting aField as anEigen::VectorX
#include<FMath/Core>FMath::ScalarFieldsf(N);FMath::VectorFieldvf(N);// Copy a scalar field to a new N-dimensional vectorFMath::VectorX vec1 = sf.asRef<VectorX>();// Copy a vector field to a new 3N-dimensional vectorFMath::VectorX vec2 = vf.asRef<VectorX>();// Interpret a scalar field as a N-dimensional vector without copyingEigen::Ref<VectorX> vecRef1 = sf.asRef<VectorX>();// Interpret a vector field as a 3N-dimensional vector without copyingEigen::Ref<VectorX> vecRef2 = vf.asRef<VectorX>();
Extracting and operating on an indexed subset of aField
#include<FMath/Core>// A Field of size N1 and an index list of size N2<N1FMath::ScalarFieldsf1(N1);FMath::IntFieldindex_list1(N2);// Set the indices of the Field entries you wish to extract...// (this can also be used to re-order a Field)// Extract the indexed setFMath::ScalarField sf_subset1 = sf1[index_list1];// Extract a small set via an initializer listFMath::ScalarField sf_subset2 = sf1[{0,3,22}];// Operate on subsets, combining different index listsFMath::ScalarFieldsf2(N1);FMath::ScalarFieldsf3(N3);FMath::IntFieldindex_list2(N2);sf1[index_list1] = sf2[index_list1] + sf3[index_list2];