Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6842a65
Mechanics openmp solvers and simple test
joseestragues Jan 20, 2026
73eeb93
Openmp solver ported
joseestragues Jan 21, 2026
d088441
Mechs SolvePair tests added
Feb 3, 2026
7bd5dd6
VTK test added
Feb 13, 2026
51ca0b8
Code coverage increased
Feb 24, 2026
4906bde
Revert one fix
Feb 24, 2026
f947c28
Windows minor fixes and clang formatting
Feb 24, 2026
707e0c4
Appleclang openmp fix
Mar 3, 2026
138999e
Solver registry restructure and appleclang fixes
Mar 13, 2026
45243db
Update vcpkg submodule to latest
Mar 16, 2026
fff9810
Windows ninja install
Mar 16, 2026
a14da8b
Adressing pr comments
Mar 23, 2026
486570b
subsolvers added
Mar 24, 2026
9bdf770
fixing things
Mar 25, 2026
510bd7e
Fixing comments
Mar 25, 2026
6458bb1
all comments addressed
Mar 25, 2026
475270d
Revert back vcpkg
asmelko Apr 7, 2026
e2f5783
Revert release.yml
asmelko Apr 7, 2026
a3fed7f
Apply clang-format
asmelko Apr 7, 2026
af374b9
Cosmetic changes
asmelko Apr 7, 2026
1fb7030
Fix windows build
asmelko Apr 8, 2026
66a4edd
Make common library an object library
asmelko Apr 8, 2026
dcc930f
Code coverage for environment
Apr 13, 2026
291dfb0
code coverage for common registry
Apr 13, 2026
83951fc
Test fix
Apr 13, 2026
827a357
Clang format fixing
Apr 16, 2026
d8d7a6c
clang fix
Apr 16, 2026
6b12294
clang fix
Apr 16, 2026
c682e42
clang fix
Apr 16, 2026
8fe8e04
Add .clang-tidy to the kernels dir
asmelko Apr 20, 2026
2c8b4e3
Fix linting
asmelko May 9, 2026
a948097
Extend sonar with mechanics kernel
asmelko May 9, 2026
3617aed
Move random to openmp solver
asmelko May 9, 2026
0411cfc
Refactor SonarQube configuration to streamline source and test paths
asmelko May 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,32 @@ jobs:
LLVM_PROFILE_FILE="biofvm.profraw" build/llvm-cov-debug/reactions-diffusion/biofvm/tests/reactions-diffusion.biofvm.tests
LLVM_PROFILE_FILE="micromechanics.profraw" build/llvm-cov-debug/mechanics/micromechanics/tests/mechanics.micromechanics.tests
LLVM_PROFILE_FILE="physicell.profraw" build/llvm-cov-debug/mechanics/physicell/tests/mechanics.physicell.tests
LLVM_PROFILE_FILE="physicell.openmp_solver.profraw" build/llvm-cov-debug/mechanics/physicell/kernels/openmp_solver/tests/mechanics.physicell.kernels.openmp_solver.tests
LLVM_PROFILE_FILE="biofvm.openmp_solver.profraw" build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/openmp_solver/tests/reactions-diffusion.biofvm.kernels.openmp_solver.tests
LLVM_PROFILE_FILE="biofvm.thrust_solver.profraw" build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/thrust_solver/tests/reactions-diffusion.biofvm.kernels.tbb_thrust_solver.tests
- name: Merge counters from different runs and convert the result into an llvm-cov-compatible form
run: |
llvm-profdata-18 merge -o merged.profdata common.profraw biofvm.profraw micromechanics.profraw physicell.profraw biofvm.openmp_solver.profraw biofvm.thrust_solver.profraw
llvm-profdata-18 merge -o merged.profdata \
common.profraw \
biofvm.profraw \
micromechanics.profraw \
physicell.profraw \
physicell.openmp_solver.profraw \
biofvm.openmp_solver.profraw \
biofvm.thrust_solver.profraw
- name: Collect the coverage
run: |
llvm-cov-18 show --show-branches=count --instr-profile merged.profdata build/llvm-cov-debug/common/tests/common.tests -object build/llvm-cov-debug/reactions-diffusion/biofvm/tests/reactions-diffusion.biofvm.tests -object build/llvm-cov-debug/mechanics/micromechanics/tests/mechanics.micromechanics.tests -object build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/openmp_solver/tests/reactions-diffusion.biofvm.kernels.openmp_solver.tests -object build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/thrust_solver/tests/reactions-diffusion.biofvm.kernels.tbb_thrust_solver.tests -object build/llvm-cov-debug/mechanics/physicell/tests/mechanics.physicell.tests > coverage.txt
llvm-cov-18 show \
--show-branches=count \
--instr-profile merged.profdata \
build/llvm-cov-debug/common/tests/common.tests \
-object build/llvm-cov-debug/reactions-diffusion/biofvm/tests/reactions-diffusion.biofvm.tests \
-object build/llvm-cov-debug/mechanics/micromechanics/tests/mechanics.micromechanics.tests \
-object build/llvm-cov-debug/mechanics/physicell/tests/mechanics.physicell.tests \
-object build/llvm-cov-debug/mechanics/physicell/kernels/openmp_solver/tests/mechanics.physicell.kernels.openmp_solver.tests \
-object build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/openmp_solver/tests/reactions-diffusion.biofvm.kernels.openmp_solver.tests \
-object build/llvm-cov-debug/reactions-diffusion/biofvm/kernels/thrust_solver/tests/reactions-diffusion.biofvm.kernels.tbb_thrust_solver.tests \
> coverage.txt
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v6
env:
Expand All @@ -56,7 +74,7 @@ jobs:
--define sonar.organization=bsc-life
--define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
--define sonar.cfamily.llvm-cov.reportPath=coverage.txt
--define sonar.sources=phenotype/physicore/src,common/include,reactions-diffusion/biofvm/src,reactions-diffusion/biofvm/include,mechanics/micromechanics/src,mechanics/micromechanics/include,mechanics/physicell/src,mechanics/physicell/include,reactions-diffusion/biofvm/kernels/openmp_solver/src,reactions-diffusion/biofvm/kernels/openmp_solver/examples,reactions-diffusion/biofvm/kernels/openmp_solver/include,reactions-diffusion/biofvm/kernels/thrust_solver/src,reactions-diffusion/biofvm/kernels/thrust_solver/examples,reactions-diffusion/biofvm/kernels/thrust_solver/include
--define sonar.tests=common/tests,reactions-diffusion/biofvm/tests,mechanics/micromechanics/tests,mechanics/physicell/tests,reactions-diffusion/biofvm/kernels/openmp_solver/tests,reactions-diffusion/biofvm/kernels/thrust_solver/tests
--define sonar.sources=phenotype/physicore/src,common/include,reactions-diffusion/biofvm/src,reactions-diffusion/biofvm/include,mechanics/micromechanics/src,mechanics/micromechanics/include,mechanics/physicell/src,mechanics/physicell/include,mechanics/physicell/kernels/openmp_solver/src,mechanics/physicell/kernels/openmp_solver/include,reactions-diffusion/biofvm/kernels/openmp_solver/src,reactions-diffusion/biofvm/kernels/openmp_solver/examples,reactions-diffusion/biofvm/kernels/openmp_solver/include,reactions-diffusion/biofvm/kernels/thrust_solver/src,reactions-diffusion/biofvm/kernels/thrust_solver/examples,reactions-diffusion/biofvm/kernels/thrust_solver/include
--define sonar.tests=common/tests,reactions-diffusion/biofvm/tests,mechanics/micromechanics/tests,mechanics/physicell/tests,mechanics/physicell/kernels/openmp_solver/tests,reactions-diffusion/biofvm/kernels/openmp_solver/tests,reactions-diffusion/biofvm/kernels/thrust_solver/tests
--define sonar.coverage.exclusions=reactions-diffusion/biofvm/kernels/openmp_solver/examples/*,reactions-diffusion/biofvm/kernels/thrust_solver/examples/*
--define sonar.cpd.exclusions=reactions-diffusion/biofvm/kernels/openmp_solver/examples/*,reactions-diffusion/biofvm/kernels/thrust_solver/examples/*
14 changes: 11 additions & 3 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
add_library(common INTERFACE)
add_library(common OBJECT)

if(${BUILD_SHARED_LIBS})
set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

file(GLOB PUBLIC_INC "include/common/*.h")
file(GLOB SOURCES "src/*.cpp")

target_sources(
common PUBLIC FILE_SET HEADERS BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${PUBLIC_INC})
common
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES
${PUBLIC_INC}
PRIVATE ${SOURCES})

if(PHYSICORE_BUILD_TESTS)
add_subdirectory(tests)
Expand Down
62 changes: 62 additions & 0 deletions common/include/common/cartesian_mesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include <array>
#include <span>

#include "types.h"

namespace physicore {

/**
* @brief Uniform Cartesian mesh for spatial domain discretization.
*
* Provides axis-aligned structured grid with uniform spacing.
* Used by both reaction-diffusion and mechanics modules for domain partitioning.
*
* Supports 1D, 2D, and 3D domains with configurable voxel sizes and bounding boxes.
* Enables efficient spatial queries: position-to-voxel mapping and voxel linearization.
*
* @see reactions-diffusion/biofvm for diffusion solver usage
* @see mechanics/physicell for mechanics engine usage
*/
class cartesian_mesh
{
public:
/// @brief Constructor
/// @param dims Number of spatial dimensions (1, 2, or 3)
/// @param bounding_box_mins Minimum coordinates of domain bounds
/// @param bounding_box_maxs Maximum coordinates of domain bounds
/// @param voxel_shape Size of each voxel in each dimension
explicit cartesian_mesh(index_t dims, std::array<sindex_t, 3> bounding_box_mins,
std::array<sindex_t, 3> bounding_box_maxs, std::array<index_t, 3> voxel_shape);

/// @brief Get total number of voxels in the mesh
[[nodiscard]] std::size_t voxel_count() const;

/// @brief Get volume of a single voxel
[[nodiscard]] index_t voxel_volume() const;

/// @brief Find voxel indices containing the given position
/// @param position Spatial coordinates (must match dims)
/// @return Voxel indices in x, y, z order
[[nodiscard]] std::array<index_t, 3> voxel_position(std::span<const real_t> position) const;

/// @brief Get the center position of a voxel
/// @param position Voxel indices
/// @return Center coordinates in x, y, z order
[[nodiscard]] std::array<real_t, 3> voxel_center(std::array<index_t, 3> position) const;

/// @brief Convert 3D voxel indices to linear index
/// @param x, y, z Voxel indices
/// @return Linear index for use in flat arrays
[[nodiscard]] std::size_t linearize(index_t x, index_t y, index_t z) const;

// Member data (public for direct access, following biofvm pattern)
index_t dims; ///< Number of spatial dimensions
std::array<sindex_t, 3> bounding_box_mins; ///< Minimum domain coordinates
std::array<sindex_t, 3> bounding_box_maxs; ///< Maximum domain coordinates
std::array<index_t, 3> voxel_shape; ///< Size of each voxel
std::array<index_t, 3> grid_shape; ///< Number of voxels per dimension
};

} // namespace physicore
13 changes: 13 additions & 0 deletions common/include/common/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

namespace physicore {

#if defined(_MSC_VER)
#define PHYSICORE_RESTRICT __restrict
#elif defined(__GNUC__) || defined(__clang__)
#define PHYSICORE_RESTRICT __restrict__
#else
#define PHYSICORE_RESTRICT
#endif

} // namespace physicore
54 changes: 54 additions & 0 deletions common/include/common/registry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <cassert>
#include <concepts>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>

namespace physicore {
template <class Base>
class factory_registry
{
public:
using ptr_t = std::unique_ptr<Base>;
using factory_func_t = std::function<ptr_t()>;
using map_t = std::unordered_map<std::string, factory_func_t>;

bool register_factory(std::string name, factory_func_t&& f);
ptr_t get(const std::string& name);

private:
map_t factories_;
};

template <class Base>
bool factory_registry<Base>::register_factory(std::string name, factory_func_t&& f)
{
auto [it, emplaced] = factories_.try_emplace(std::move(name), std::move(f));
return emplaced;
}

template <class Base>
typename factory_registry<Base>::ptr_t factory_registry<Base>::get(const std::string& name)
{
auto it = factories_.find(name);
if (it == factories_.end())
{
return nullptr;
}

return it->second();
}

template <class Derived, class Registry>
struct generic_registry_adder
{
explicit generic_registry_adder(std::string name)
{
Registry::instance().register_factory(std::move(name), []() { return std::make_unique<Derived>(); });
}
};

} // namespace physicore
9 changes: 9 additions & 0 deletions common/include/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ using real_t = double;
using index_t = std::uint64_t;
using sindex_t = std::int64_t;


#if defined(_MSC_VER)
Comment thread
joseestragues marked this conversation as resolved.
#define PHYSICORE_RESTRICT __restrict
#elif defined(__GNUC__) || defined(__clang__)
#define PHYSICORE_RESTRICT __restrict__
#else
#define PHYSICORE_RESTRICT
#endif

} // namespace physicore
78 changes: 78 additions & 0 deletions common/src/cartesian_mesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "common/cartesian_mesh.h"

#include <cassert>

namespace physicore {

cartesian_mesh::cartesian_mesh(index_t dims, std::array<sindex_t, 3> bounding_box_mins,
std::array<sindex_t, 3> bounding_box_maxs, std::array<index_t, 3> voxel_shape)
: dims(dims),
bounding_box_mins(bounding_box_mins),
bounding_box_maxs(bounding_box_maxs),
voxel_shape(voxel_shape),
grid_shape({ 1, 1, 1 })
{
if (dims >= 1)
{
grid_shape[0] = (bounding_box_maxs[0] - bounding_box_mins[0] + voxel_shape[0] - 1) / voxel_shape[0];
}
if (dims >= 2)
{
grid_shape[1] = (bounding_box_maxs[1] - bounding_box_mins[1] + voxel_shape[1] - 1) / voxel_shape[1];
}
if (dims >= 3)
{
grid_shape[2] = (bounding_box_maxs[2] - bounding_box_mins[2] + voxel_shape[2] - 1) / voxel_shape[2];
}
}

std::size_t cartesian_mesh::voxel_count() const
{
return (std::size_t)grid_shape[0] * (std::size_t)grid_shape[1] * (std::size_t)grid_shape[2];
}

index_t cartesian_mesh::voxel_volume() const { return voxel_shape[0] * voxel_shape[1] * voxel_shape[2]; }

std::array<index_t, 3> cartesian_mesh::voxel_position(std::span<const real_t> position) const
{
assert(position.size() == (size_t)dims);
assert(position[0] <= bounding_box_maxs[0] && position[0] >= bounding_box_mins[0]);
if (dims >= 2)
assert(position[1] <= bounding_box_maxs[1] && position[1] >= bounding_box_mins[1]);
if (dims >= 3)
assert(position[2] <= bounding_box_maxs[2] && position[2] >= bounding_box_mins[2]);

switch (position.size())
{
case 1:
return { (index_t)((position[0] - (real_t)bounding_box_mins[0]) / (real_t)voxel_shape[0]), 0, 0 };
case 2:
return { (index_t)((position[0] - (real_t)bounding_box_mins[0]) / (real_t)voxel_shape[0]),
(index_t)((position[1] - (real_t)bounding_box_mins[1]) / (real_t)voxel_shape[1]), 0 };
case 3:
return { (index_t)((position[0] - (real_t)bounding_box_mins[0]) / (real_t)voxel_shape[0]),
(index_t)((position[1] - (real_t)bounding_box_mins[1]) / (real_t)voxel_shape[1]),
(index_t)((position[2] - (real_t)bounding_box_mins[2]) / (real_t)voxel_shape[2]) };
default:
assert(false); // Should never reach here
return { 0, 0, 0 };
}
}

std::array<real_t, 3> cartesian_mesh::voxel_center(std::array<index_t, 3> position) const
{
assert(position[0] < grid_shape[0]);
assert(position[1] < grid_shape[1]);
assert(position[2] < grid_shape[2]);

return { (real_t)(position[0] * voxel_shape[0] + bounding_box_mins[0]) + ((real_t)voxel_shape[0] / (real_t)2.0),
(real_t)(position[1] * voxel_shape[1] + bounding_box_mins[1]) + ((real_t)voxel_shape[1] / (real_t)2.0),
(real_t)(position[2] * voxel_shape[2] + bounding_box_mins[2]) + ((real_t)voxel_shape[2] / (real_t)2.0) };
}

std::size_t cartesian_mesh::linearize(index_t x, index_t y, index_t z) const
{
return x + y * grid_shape[0] + z * grid_shape[0] * grid_shape[1];
}

} // namespace physicore
19 changes: 17 additions & 2 deletions mechanics/physicell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ add_library(mechanics.physicell)
add_library(physicore::mechanics::physicell ALIAS mechanics.physicell)
add_library(mechanics.physicell_internal_iface INTERFACE)

if(${BUILD_SHARED_LIBS})
set_target_properties(
mechanics.physicell
PROPERTIES CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
POSITION_INDEPENDENT_CODE ON
INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

file(GLOB PUBLIC_INC "include/physicell/*.h")
target_sources(
mechanics.physicell
PRIVATE src/environment.cpp src/config_reader.cpp src/agent_data.cpp
src/mechanical_agent.cpp src/vtk_serializer_base.cpp
PRIVATE src/environment.cpp
src/config_reader.cpp
src/agent_data.cpp
src/mechanical_agent.cpp
src/vtk_serializer_base.cpp
src/vtk_agents_serializer.cpp
src/solver_registry.cpp
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES
${PUBLIC_INC})

Expand All @@ -28,6 +41,8 @@ target_link_libraries(
PUBLIC common
PRIVATE mechanics.physicell_internal_iface pugixml::pugixml VTK::IOXML)

add_subdirectory(kernels/openmp_solver)

if(PHYSICORE_BUILD_TESTS)
add_subdirectory(tests)
endif()
3 changes: 3 additions & 0 deletions mechanics/physicell/include/physicell/agent_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <vector>

#include <common/base_agent_data.h>
Expand Down Expand Up @@ -43,6 +44,7 @@
*/
struct motility_properties
{
using direction_update_func = std::function<void(index_t)>; // TODO: it needs access to substrate concentrations

Check warning on line 47 in mechanics/physicell/include/physicell/agent_data.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=bsc-life_PhysiCore&issues=AZ4MHyMTfu-4LUhWdFOT&open=AZ4MHyMTfu-4LUhWdFOT&pullRequest=110
Comment thread
joseestragues marked this conversation as resolved.
// Migration parameters
std::vector<std::uint8_t> is_motile;
std::vector<real_t> persistence_time;
Expand All @@ -51,6 +53,7 @@
std::vector<real_t> migration_bias;
std::vector<real_t> motility_vector; // dims per agent
std::vector<std::uint8_t> restrict_to_2d;
std::vector<direction_update_func> direction_update_funcs;

// Chemotaxis parameters
std::vector<index_t> chemotaxis_index;
Expand Down
23 changes: 20 additions & 3 deletions mechanics/physicell/include/physicell/environment.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
#pragma once

#include <memory>
#include <optional>

#include <common/cartesian_mesh.h>
#include <common/timestep_executor.h>
#include <common/types.h>

#include "mechanical_agent_container.h"
#include "serializer.h"
#include "solver.h"

namespace physicore::mechanics::physicell {

class environment : public timestep_executor

Check warning on line 16 in mechanics/physicell/include/physicell/environment.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Don't mix public and private data members.

See more on https://sonarcloud.io/project/issues?id=bsc-life_PhysiCore&issues=AZ4MHyMbfu-4LUhWdFOU&open=AZ4MHyMbfu-4LUhWdFOU&pullRequest=110
{
real_t timestep;

public:
explicit environment(real_t timestep) : timestep(timestep) {}
environment(real_t timestep, index_t dims, index_t agent_types_count, index_t substrates_count);

void run_single_timestep() override;

void serialize_state(real_t current_time) override;

real_t mechanics_timestep;
bool automated_spring_adhesion = false;
bool virtual_wall_at_domain_edges = true;

serializer_ptr serializer;
solver_ptr solver;

std::unique_ptr<mechanical_agent_container> agents;

// Mesh data for spatial queries
void set_mesh(cartesian_mesh mesh) { this->mesh_ = std::move(mesh); }
const cartesian_mesh& get_mesh() const;
bool has_mesh() const { return mesh_.has_value(); }

private:
std::optional<cartesian_mesh> mesh_;
};

} // namespace physicore::mechanics::physicell
Loading
Loading