-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e4bd48
commit 64d6158
Showing
15 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
cmake_minimum_required(VERSION 3.16...3.22) | ||
project(shapes LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Find Python | ||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development) | ||
|
||
# Fetch pybind11 | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
pybind11 | ||
GIT_REPOSITORY https://github.com/pybind/pybind11 | ||
GIT_TAG v2.13.5 | ||
GIT_SHALLOW 1 | ||
) | ||
FetchContent_MakeAvailable(pybind11) | ||
|
||
# Add external library | ||
add_subdirectory(extern/meshgen meshgen_build) | ||
|
||
# Add a shared library for the main C++ source | ||
file(GLOB_RECURSE SHAPES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp) | ||
add_library(shapes SHARED ${SHAPES_SOURCES}) | ||
target_include_directories( | ||
shapes | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/geometry | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/math_funcs | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/mesh | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/primitives | ||
) | ||
target_link_libraries(shapes PUBLIC meshgen::meshgen) | ||
|
||
# Copy the Python source and test trees to the build location | ||
file( | ||
COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/py/pyshapes | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ | ||
) | ||
file( | ||
COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/py/test/ | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ | ||
) | ||
|
||
# Create a shared library for each wrapper module | ||
foreach(MODULE geometry math_funcs mesh primitives) | ||
# Add the autogenerated wrappers to the module target | ||
file(GLOB MODULE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/${MODULE}/*.cpp) | ||
|
||
set(MODULE_LIB _pyshapes_${MODULE}) | ||
add_library(${MODULE_LIB} SHARED ${MODULE_SOURCES}) | ||
target_link_libraries( | ||
${MODULE_LIB} | ||
PRIVATE | ||
Python3::Python | ||
pybind11::module | ||
shapes | ||
) | ||
target_include_directories( | ||
${MODULE_LIB} | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/wrapper | ||
${CMAKE_CURRENT_SOURCE_DIR}/wrapper/geometry | ||
${CMAKE_CURRENT_SOURCE_DIR}/wrapper/math_funcs | ||
${CMAKE_CURRENT_SOURCE_DIR}/wrapper/mesh | ||
${CMAKE_CURRENT_SOURCE_DIR}/wrapper/primitives | ||
) | ||
|
||
# Set suitable extensions for the module and place the compiled | ||
# shared library in a suitable location inside the python package | ||
set_target_properties( | ||
${MODULE_LIB} | ||
PROPERTIES | ||
PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}" | ||
LIBRARY_OUTPUT_DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR}/pyshapes/${MODULE}/ | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# For docs on config options, see examples/shapes/wrapper/package_info.yaml | ||
name: pycells | ||
|
||
smart_ptr_type: std::shared_ptr | ||
pointer_call_policy: reference | ||
reference_call_policy: reference_internal | ||
|
||
common_include_file: False | ||
source_includes: | ||
- <memory> | ||
|
||
exclude_default_args: False | ||
|
||
template_substitutions: | ||
- signature: <unsigned DIM> | ||
replacement: [[2], [3]] | ||
- signature: <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
replacement: [[2, 2], [3, 3]] | ||
- signature: <unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM> | ||
replacement: [[2, 2], [3, 3]] | ||
|
||
modules: | ||
- name: lib | ||
source_locations: | ||
- cycle | ||
- mesh | ||
- ode | ||
- pde | ||
- population | ||
- visualization | ||
|
||
classes: | ||
- name: AbstractCellPopulation | ||
- name: MeshBasedCellPopulation | ||
|
||
prefix_text: | | ||
// This file is auto-generated by cppwg; manual changes will be overwritten. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(meshgen) | ||
|
||
add_library(meshgen MeshGen.cpp MeshGen.hpp) | ||
target_include_directories(meshgen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
add_library(meshgen::meshgen ALIAS meshgen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "MeshGen.hpp" | ||
|
||
MeshGen::MeshGen() | ||
{ | ||
// Constructor | ||
} | ||
|
||
MeshGen::~MeshGen() | ||
{ | ||
// Destructor | ||
} | ||
|
||
void MeshGen::generateMesh() | ||
{ | ||
// Generate a mesh | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef _MESHGEN_HPP | ||
#define _MESHGEN_HPP | ||
|
||
class MeshGen | ||
{ | ||
|
||
public: | ||
/** | ||
* Default Constructor | ||
*/ | ||
MeshGen(); | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~MeshGen(); | ||
|
||
/** | ||
* Generate a mesh | ||
*/ | ||
void generateMesh(); | ||
}; | ||
|
||
#endif // _MESHGEN_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "AbstractMesh.hpp" | ||
|
||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
AbstractMesh<ELEMENT_DIM, SPACE_DIM>::AbstractMesh() : mIndex(0) | ||
{ | ||
} | ||
|
||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
AbstractMesh<ELEMENT_DIM, SPACE_DIM>::~AbstractMesh() | ||
{ | ||
} | ||
|
||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
unsigned AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetIndex() const | ||
{ | ||
return mIndex; | ||
} | ||
|
||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::SetIndex(unsigned index) | ||
{ | ||
mIndex = index; | ||
} | ||
|
||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM> | ||
void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::AddVertex(Point<SPACE_DIM> vertex) | ||
{ | ||
} | ||
|
||
template class AbstractMesh<2, 2>; | ||
template class AbstractMesh<3, 3>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef _ABSTRACT_MESH_HPP | ||
#define _ABSTRACT_MESH_HPP | ||
|
||
#include "Point.hpp" | ||
|
||
/** | ||
* A mesh in SPACE_DIM space with ELEMENT_DIM dimensional elements | ||
*/ | ||
template <unsigned ELEMENT_DIM, unsigned SPACE_DIM = ELEMENT_DIM> | ||
class AbstractMesh | ||
{ | ||
private: | ||
/** | ||
* AbstractMesh index | ||
*/ | ||
unsigned mIndex; | ||
|
||
public: | ||
/** | ||
* Default Constructor | ||
*/ | ||
AbstractMesh(); | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~AbstractMesh(); | ||
|
||
/** | ||
* Return the index | ||
*/ | ||
unsigned GetIndex() const; | ||
|
||
/** | ||
* Set the index | ||
*/ | ||
void SetIndex(unsigned index); | ||
|
||
/** | ||
* Add a vertex to the mesh | ||
*/ | ||
void AddVertex(Point<SPACE_DIM> vertex); | ||
|
||
/** | ||
* Scale the mesh by a factor | ||
*/ | ||
virtual void Scale(const double factor) = 0; | ||
}; | ||
|
||
#endif // _ABSTRACT_MESH_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "AbstractMesh.hpp" | ||
#include "ConcreteMesh.hpp" | ||
|
||
template <unsigned DIM> | ||
ConcreteMesh<DIM>::ConcreteMesh() : AbstractMesh<DIM, DIM>() | ||
{ | ||
} | ||
|
||
template <unsigned DIM> | ||
ConcreteMesh<DIM>::~ConcreteMesh() | ||
{ | ||
} | ||
template <unsigned DIM> | ||
void ConcreteMesh<DIM>::Scale(const double factor){ | ||
// Scale the mesh | ||
}; | ||
|
||
template class ConcreteMesh<2>; | ||
template class ConcreteMesh<3>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef _CONCRETE_MESH_HPP | ||
#define _CONCRETE_MESH_HPP | ||
|
||
#include "AbstractMesh.hpp" | ||
|
||
/** | ||
* A concrete mesh implementation | ||
*/ | ||
template <unsigned DIM> | ||
class ConcreteMesh : public AbstractMesh<DIM, DIM> | ||
{ | ||
public: | ||
/** | ||
* Default Constructor | ||
*/ | ||
ConcreteMesh(); | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~ConcreteMesh(); | ||
|
||
/** | ||
* Scale the mesh by a factor | ||
*/ | ||
void Scale(const double factor) override; | ||
}; | ||
|
||
#endif // _CONCRETE_MESH_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "ConcreteMesh.hpp" | ||
|
||
#include "MeshFactory.hpp" | ||
|
||
template <class MESH> | ||
MeshFactory<MESH>::MeshFactory(): mMeshGen() | ||
{ | ||
} | ||
|
||
template <class MESH> | ||
MeshFactory<MESH>::~MeshFactory() | ||
{ | ||
} | ||
|
||
template class MeshFactory<ConcreteMesh<2> >; | ||
template class MeshFactory<ConcreteMesh<3> >; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef _MESH_FACTORY_HPP | ||
#define _MESH_FACTORY_HPP | ||
|
||
#include "MeshGen.hpp" | ||
|
||
/** | ||
* A concrete mesh implementation | ||
*/ | ||
template <class MESH> | ||
class MeshFactory | ||
{ | ||
private: | ||
MeshGen mMeshGen; | ||
|
||
public: | ||
/** | ||
* Default Constructor | ||
*/ | ||
MeshFactory(); | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~MeshFactory(); | ||
}; | ||
|
||
#endif // _MESH_FACTORY_HPP |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import inspect | ||
from collections.abc import Iterable | ||
|
||
|
||
class TemplateClassDict: | ||
|
||
def __init__(self, template_dict): | ||
self._dict = {} | ||
for arg_tuple, cls in template_dict.items(): | ||
if not inspect.isclass(cls): | ||
raise TypeError("Expected class, got {}".format(type(cls))) | ||
if not isinstance(arg_tuple, Iterable): | ||
arg_tuple = (arg_tuple,) | ||
key = tuple( | ||
arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple | ||
) | ||
self._dict[key] = cls | ||
|
||
def __getitem__(self, arg_tuple): | ||
if not isinstance(arg_tuple, Iterable): | ||
arg_tuple = (arg_tuple,) | ||
key = tuple( | ||
arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple | ||
) | ||
return self._dict[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pycells._pycells_lib import ConcreteMesh_2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import unittest | ||
|
||
|
||
class TestCells(unittest.TestCase): | ||
|
||
def testCells(self): | ||
pass | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |