Skip to content

Commit

Permalink
basic binding working
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrunnels committed Sep 7, 2022
1 parent 7595a59 commit 2dbfe45
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "extern/pybind11"]
path = extern/pybind11
url = ../../pybind/pybind11
branch = stable
[submodule "extern/eigen"]
path = extern/eigen
url = ../../libigl/eigen
branch = master
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,40 @@ CC = g++
CPP_COMPILER_OPTIONS += -c -g3 -ggdb -fopenmp -Wno-deprecated -Wunused-variable -DMUPARSER
CPP_LINKER_OPTIONS += -g3 -ggdb -fopenmp

INC_PYTHON = $(shell python3.8-config --cflags)
LIB_PYTHON = $(shell python3.8-config --ldflags)
PYTHON_NAME = bin/wield$(shell python3.8-config --extension-suffix)

ifdef EMACS
PREFIX = $(shell pwd)/
endif
EXCLUDE = $(PREFIX)/src/MainOld.cpp
SRC_MAIN = $(filter-out $(EXCLUDE), $(shell find ./src/ -name '*.cc'))
EXE = $(subst ./src/,./bin/, $(SRC_MAIN:.cc=))
SRC = $(filter-out $(EXCLUDE), $(shell find ./src/ -name '*.cpp'))
EXE = bin/wield
SRC = $(filter-out $(EXCLUDE), $(shell find ./src/ -mindepth 2 -name '*.cpp'))
HDR = $(filter-out $(EXCLUDE), $(shell find ./inc/ ./src/ -name '*.h'))
OBJ = $(subst ./src/,./obj/, $(SRC:.cpp=.o))
OBJ_MAIN = $(subst ./src/,./obj/, $(SRC_MAIN:.cc=.o))
INC = -I./src \
INC = -O3 -I./src \
-I./inc \
$(INC_EXT)
LIB = $(LIB_EXT) -lmuparser
-I./extern/eigen/
LIB = $(LIB_EXT) -lmuparser $(LIB_PYTHON) -lpython3.8


.SECONDARY: $(OBJ) $(OBJ_MAIN)

all: make_directories $(EXE)
all: make_directories $(EXE) $(PYTHON_NAME)
@echo $(B_ON)$(FG_GREEN)"###"
@echo "### DONE"
@echo "###"$(RESET)

$(PREFIX)bin/%: ./obj/%.o $(OBJ)
$(PYTHON_NAME): ./src/python.cpp $(OBJ)
@echo $(B_ON)$(FG_BLUE)"###"
@echo "### LINKING $@"
@echo "###"$(RESET)
$(CC) $(INC) -I./extern/pybind11/include/ -O3 -Wall -shared -std=c++11 -fPIC $(INC_PYTHON) src/python.cpp -o $@

bin/wield: ./obj/wield.o $(OBJ)
@echo $(B_ON)$(FG_BLUE)"###"
@echo "### LINKING $@"
@echo "###"$(RESET)
Expand Down
1 change: 1 addition & 0 deletions extern/eigen
Submodule eigen added at 1f05f5
1 change: 1 addition & 0 deletions extern/pybind11
Submodule pybind11 added at 0ba639
14 changes: 14 additions & 0 deletions src/Integrator/wieldSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ double Surface(Wield::Series::FourierSeries<Mollifier> C1,
return real(w12);
}

//double SurfaceGaussDirac(//Wield::Series::FourierSeries<Wield::Series::GaussDirac> C1,
// //Eigen::Matrix3d R1,
// //Wield::Series::FourierSeries<Wield::Series::GaussDirac> C2,
// //Eigen::Matrix3d R2,
// double epsilon,
// double tolerance
// )
//{
// std::cout << "made it inside..." << std::endl;
// return 0.0;
// //Surface(C1,R1,C2,R2,epsilon,tolerance);
//}


template<class Mollifier>
double Surface(Wield::Series::FourierSeries<Mollifier> C1,
Eigen::Matrix3d R1,
Expand Down
19 changes: 18 additions & 1 deletion src/Series/wieldFourierSeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class FourierSeries
// {
// return exp(-sigma*sigma*(x*x + y*y + z*z)/4.) / sqrt(8*pi*pi*pi);
// }

FourierSeries(const FourierSeries<Mollifier> &copy) : order(copy.order),
alphaX(copy.alphaX),
alphaY(copy.alphaY),
Expand Down Expand Up @@ -101,6 +100,24 @@ class FourierSeries
WIELD_PROGRESS_COMPLETE("Computing CSL");
}

FourierSeries(int _order,
double _alphaX,
double _alphaY,
double _alphaZ,
double _sigma,
std::vector<double> X,
std::vector<double> Y,
std::vector<double> Z,
int numThreads = 1,
int verbose = false
) :FourierSeries(_order,_alphaX,_alphaY,_alphaZ,Mollifier(_sigma),X,Y,Z,numThreads,verbose)
{}

FourierSeries() : phiHat(0)
{
}


std::complex<double> &operator()(signed int i, signed int j, signed int k)
{
return C[(2 * order - 1) * (2 * order - 1) * (order + i - 1) + (2 * order - 1) * (order + j - 1) + (order + k - 1)];
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/wieldEigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#define eigen_assert(A) if (!(A)){ WIELD_EXCEPTION_NEW("Eigen Exception: the conditional (" << #A << ") failed");}
//#define eigen_assert(A) if (!(A)){ cout << "Problem here"<< endl;}

#include "eigen3/Eigen/Core"
#include "eigen3/Eigen/Geometry"
#include "eigen3/Eigen/LU"
#include "Eigen/Core"
#include "Eigen/Geometry"
#include "Eigen/LU"

#define Success Success_tmp
#undef Success_tmp
Expand Down
76 changes: 76 additions & 0 deletions src/python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
// #include <fstream>
// #include <vector>
// #include <fstream>
// #include <stdexcept>
// #include <csignal>
//
// #include "tclap/CmdLine.h"
// #include "TCLAP/IgnoreArg.h"
//
// #include "Main/wieldEnergy1D.h"
// #include "Main/wieldEnergy2D.h"
// #include "Main/wieldCSL.h"
// #include "Main/wieldEnergyOffset.h"
// #include "Main/wieldBlenderVoxelData.h"
// #include "Main/wieldVisualizeOR.h"
// #include "Main/wieldEnergySurfaceSphere.h"
// #include "Main/wieldEnergyInterface1D.h"
// #include "Main/wieldEnergyOR1D.h"
// #include "Main/wieldFacet2D.h"
// #include "Utils/wieldExceptions.h"
// #include "Utils/wieldProgress.h"
//

#include "Reader/Reader.h"
#include "Series/wieldGaussDirac.h"
#include "Series/wieldFourierSeries.h"
#include "Integrator/wieldSurface.h"

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
#include "pybind11/eigen.h"

double add(double i, double j) {
return i + j;
}


double SurfaceGaussDirac(Wield::Series::FourierSeries<Wield::Series::GaussDirac> C1,
Eigen::Matrix3d R1,
Wield::Series::FourierSeries<Wield::Series::GaussDirac> C2,
Eigen::Matrix3d R2,
double epsilon,
double tolerance)
{
return Wield::Integrator::Surface(C1,R1,C2,R2,epsilon,tolerance);
}

//PYBIND11_MODULE(wield, m) {
// m.doc() = "pybind11 example plugin"; // optional module docstring
//
// m.def("add", &add, "A function that adds two numbers");
//}

//Wield::Integrator::Surface<Wield::Series::GaussDirac>;
//int null()
//{
// &createMatrixFromAngle;
// Wield::Integrator::Surface<Wield::Series::GaussDirac>;
//}

PYBIND11_MODULE(wield,m) {

pybind11::class_<Wield::Series::FourierSeries<Wield::Series::GaussDirac>>(m,"Crystal")
.def(pybind11::init<
const int, const double, const double, const double,
const double, std::vector<double>, std::vector<double>,std::vector<double>,
int, int >());

m.def("Surface",&SurfaceGaussDirac,"Surface integrate");
//m.def("Surface",&add,"Surface integrate");
m.def("createMatrixFromAngle",&createMatrixFromAngle,"Surface integrate");

}


0 comments on commit 2dbfe45

Please sign in to comment.