Spinoza is a C++ library designed for high-performance mathematical and physics simulations. It provides a set of tools for vector operations, numerical differentiation, and integration. The library is built using pure C++ and does not rely on any external dependencies beyond the C++ Standard Library.
- β N-dimensional vector operations
- β Scalar and vector field simulation
- β Numerical differentiation using Euler's method
- β Numerical integration using Euler's method
- β Expandable framework for custom simulations
- C++17 or later compiler
- CMake for building
-
Ubuntu/Debian:
sudo apt-get install cmake
-
macOS (Homebrew):
brew install cmake
-
Clone the repository:
git clone https://github.com/stdmedoth/spinoza.git cd spinoza -
Create a build directory and navigate into it:
mkdir build && cd build
-
Generate build files with CMake:
cmake ..
-
Build the project:
make
-
The compiled library will be available for linking in your project.
If you're using CMake, simply link the Spinoza library:
add_subdirectory(spinoza)
target_link_libraries(my_project PRIVATE spinoza)If you're manually compiling:
g++ -std=c++17 -I./include my_program.cpp -o my_programHere's a better example of how to use Spinoza for field simulations:
#include <iostream>
#include "Field.hpp"
#include "VectorField.hpp"
#include "ScalarField.hpp"
#include "Space.hpp"
int main()
{
// Define a 3D vector space with 10,000 elements
Space<double, 3, 10000> domain;
Field<double, 10000> image;
Space<double, 3, 10000> vector_image;
// Initialize the scalar field and vector field values
for (int i = 0; i < 10000; i++)
{
double x = 0.001 * i;
double y = 0.002 * i;
double z = 0.003 * i;
domain[i] = Vector<double, 3>({x, y, z});
image[i] = x + y + z;
vector_image[i] = Vector<double, 3>({x, y, z});
}
// Create a scalar field (temperature) and output its image
ScalarField<double, 3, 10000> temperature(domain, image);
image = temperature.getImage();
for (int i = 0; i < 10000; i++)
{
std::cout << image[i] << "\n";
}
// Create a vector field (position) and output its image
VectorField<double, 3, 10000> position(domain, vector_image);
vector_image = position.getImage();
for (int i = 0; i < 10000; i++)
{
std::cout << vector_image[i] << "\n";
}
return 0;
}Space: Represents a space with vectors.Field: Represents the image of a scalar or vector field.ScalarField: Represents a scalar field where the value at each point is a scalar (used for temperature or other scalar quantities).VectorField: Represents a vector field where the value at each point is a vector (used for position or other vector quantities).getImage(): Retrieves the field values as an array.
In the example:
- A scalar field
temperatureis computed and printed. - A vector field
positionis computed and printed.
/spinoza
β
βββ /include # Header files
βββ /src # Source files
βββ /examples # Example programs
βββ CMakeLists.txt # CMake configuration
βββ README.md # Documentation
βββ LICENSE # License information
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b my-feature - Commit your changes:
git commit -am 'Added new feature' - Push to your branch:
git push origin my-feature - Submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
π‘ Explore the world of math & physics with Spinoza! π