Skip to content

Commit

Permalink
#20 Build cells example correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Oct 28, 2024
1 parent 81a886e commit c4fd42a
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 78 deletions.
2 changes: 1 addition & 1 deletion cppwg/info/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class instantiation. For example, class "Foo" with template arguments
arg_str = arg_str.replace(name, replacement)

# Remove special characters
arg_str = arg_str.translate(rm_table)
arg_str = arg_str.replace("<", "_").replace(",", "_").translate(rm_table)

# Capitalize the first letter
if len(arg_str) > 1:
Expand Down
104 changes: 54 additions & 50 deletions examples/cells/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
cmake_minimum_required(VERSION 3.16...3.22)
project(shapes LANGUAGES CXX)
project(cells LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find Python
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)

# Find VTK
find_package(VTK 7.1
REQUIRED
COMPONENTS
vtkCommonCore
vtkCommonDataModel
vtkFiltersCore
vtkFiltersGeneral
vtkFiltersGeneric
vtkFiltersGeometry
vtkFiltersModeling
vtkFiltersProgrammable
vtkFiltersSources
vtkFiltersVerdict
vtkInteractionStyle
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOMovie
vtkIOParallelXML
vtkIOXML
vtkRenderingAnnotation
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingOpenGL2
vtkWrappingPythonCore
)

# Fetch pybind11
include(FetchContent)
FetchContent_Declare(
Expand All @@ -20,61 +50,35 @@ FetchContent_MakeAvailable(pybind11)
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})
file(GLOB_RECURSE CELLS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.hpp
)
add_library(cells SHARED ${CELLS_SOURCES})
target_include_directories(
shapes
cells
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)
target_link_libraries(cells 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}/
# Set up Pybind11 module
file(GLOB PYCELLS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/dynamic/wrappers/lib/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dynamic/wrappers/lib/*.hpp
)
file(
COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/py/test/
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/
pybind11_add_module(_pycells_lib MODULE ${PYCELLS_SOURCES})
target_link_libraries(
_pycells_lib
PRIVATE
cells
)
target_include_directories(
_pycells_lib
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/lib
)

# 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()
# Add install target for scikit-build
install(TARGETS cells DESTINATION .)
13 changes: 9 additions & 4 deletions examples/cells/dynamic/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ modules:

classes:
# cell
- name: Cell
# - name: Cell

# mesh
- name: AbstractMesh
- name: MeshFactory
source_includes:
- PottsMesh.hpp
template_substitutions:
- signature: <class MESH>
replacement: [['PottsMesh<2>'], ['PottsMesh<3>']]
- name: PottsMesh

# population
- name: AbstractCellPopulation
- name: PottsCellPopulation
# - name: AbstractCellPopulation
# - name: PottsCellPopulation

# visualization
- name: VtkScene
# - name: VtkScene

prefix_text: |
// This file is auto-generated by cppwg; manual changes will be overwritten.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is auto-generated by cppwg; manual changes will be overwritten.

#ifndef pycells_HEADERS_HPP_
#define pycells_HEADERS_HPP_

// Includes
#include "AbstractMesh.hpp"
#include "MeshFactory.hpp"
#include "PottsMesh.hpp"

// Instantiate Template Classes
template class AbstractMesh<2, 2>;
template class AbstractMesh<3, 3>;
template class MeshFactory<PottsMesh<2>>;
template class MeshFactory<PottsMesh<3>>;
template class PottsMesh<2>;
template class PottsMesh<3>;

// Typedefs for nicer naming
namespace cppwg
{
typedef AbstractMesh<2, 2> AbstractMesh_2_2;
typedef AbstractMesh<3, 3> AbstractMesh_3_3;
typedef MeshFactory<PottsMesh<2>> MeshFactory_PottsMesh_2;
typedef MeshFactory<PottsMesh<3>> MeshFactory_PottsMesh_3;
typedef PottsMesh<2> PottsMesh_2;
typedef PottsMesh<3> PottsMesh_3;
} // namespace cppwg

#endif // pycells_HEADERS_HPP_
10 changes: 10 additions & 0 deletions examples/cells/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "pycells"
version = "0.0.1"

[build-system]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[tool.scikit-build.cmake]
build-type = "Release"
8 changes: 4 additions & 4 deletions examples/cells/src/cpp/mesh/AbstractMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ 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 <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
// void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::AddVertex(Node<SPACE_DIM> vertex)
// {
// }

template class AbstractMesh<2, 2>;
template class AbstractMesh<3, 3>;
4 changes: 1 addition & 3 deletions examples/cells/src/cpp/mesh/AbstractMesh.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef _ABSTRACT_MESH_HPP
#define _ABSTRACT_MESH_HPP

#include "Point.hpp"

/**
* A mesh in SPACE_DIM space with ELEMENT_DIM dimensional elements
*/
Expand Down Expand Up @@ -39,7 +37,7 @@ class AbstractMesh
/**
* Add a vertex to the mesh
*/
void AddVertex(Point<SPACE_DIM> vertex);
// void AddVertex(Node<SPACE_DIM> vertex);

/**
* Scale the mesh by a factor
Expand Down
6 changes: 3 additions & 3 deletions examples/cells/src/cpp/mesh/MeshFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ConcreteMesh.hpp"
#include "PottsMesh.hpp"

#include "MeshFactory.hpp"

Expand All @@ -12,5 +12,5 @@ MeshFactory<MESH>::~MeshFactory()
{
}

template class MeshFactory<ConcreteMesh<2> >;
template class MeshFactory<ConcreteMesh<3> >;
template class MeshFactory<PottsMesh<2> >;
template class MeshFactory<PottsMesh<3> >;
12 changes: 6 additions & 6 deletions examples/cells/src/cpp/mesh/PottsMesh.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "AbstractMesh.hpp"
#include "ConcreteMesh.hpp"
#include "PottsMesh.hpp"

template <unsigned DIM>
ConcreteMesh<DIM>::ConcreteMesh() : AbstractMesh<DIM, DIM>()
PottsMesh<DIM>::PottsMesh() : AbstractMesh<DIM, DIM>()
{
}

template <unsigned DIM>
ConcreteMesh<DIM>::~ConcreteMesh()
PottsMesh<DIM>::~PottsMesh()
{
}
template <unsigned DIM>
void ConcreteMesh<DIM>::Scale(const double factor){
void PottsMesh<DIM>::Scale(const double factor){
// Scale the mesh
};

template class ConcreteMesh<2>;
template class ConcreteMesh<3>;
template class PottsMesh<2>;
template class PottsMesh<3>;
14 changes: 7 additions & 7 deletions examples/cells/src/cpp/mesh/PottsMesh.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#ifndef _CONCRETE_MESH_HPP
#define _CONCRETE_MESH_HPP
#ifndef _POTTS_MESH_HPP
#define _POTTS_MESH_HPP

#include "AbstractMesh.hpp"

/**
* A concrete mesh implementation
* A Potts mesh implementation
*/
template <unsigned DIM>
class ConcreteMesh : public AbstractMesh<DIM, DIM>
class PottsMesh : public AbstractMesh<DIM, DIM>
{
public:
/**
* Default Constructor
*/
ConcreteMesh();
PottsMesh();

/**
* Destructor
*/
~ConcreteMesh();
~PottsMesh();

/**
* Scale the mesh by a factor
*/
void Scale(const double factor) override;
};

#endif // _CONCRETE_MESH_HPP
#endif // _POTTS_MESH_HPP
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c4fd42a

Please sign in to comment.