Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
5 changes: 3 additions & 2 deletions .devcontainer/physicore-dev/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
],
"remoteEnv": {
"VCPKG_ROOT": "${containerWorkspaceFolder}/vcpkg",
"PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/vcpkg:/usr/lib/llvm-20/bin"
"PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/vcpkg:/usr/lib/llvm-20/bin",
Comment thread
joseestragues marked this conversation as resolved.
Outdated
"APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE": "1"
},
"initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/vcpkg",
"onCreateCommand": ".devcontainer/configure.sh",
"postCreateCommand": ".devcontainer/configure.sh",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"toolsToInstall": "cmakelang"
Expand Down
13 changes: 9 additions & 4 deletions .devcontainer/physicore-dev/dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM gcc:15.2.0

# Install LLVM 20
RUN apt-get update && \
# Configure APT to allow unsigned repositories due to LLVM key expiration
Comment thread
joseestragues marked this conversation as resolved.
Outdated
# This is needed because the LLVM 20 signing key uses SHA1 which is no longer secure as of 2026-02-01
RUN echo "APT::Get::AllowUnauthenticated \"true\";" > /etc/apt/apt.conf.d/99-allow-unsigned && \
echo "Acquire::AllowInsecureRepositories \"true\";" >> /etc/apt/apt.conf.d/99-allow-unsigned && \
echo "Acquire::AllowDowngradeToInsecureRepositories \"true\";" >> /etc/apt/apt.conf.d/99-allow-unsigned

# Remove the problematic LLVM repository entirely to avoid signature issues during feature installations
# Users can still install LLVM manually if needed
RUN apt-get update || true && \
apt-get install -y --no-install-recommends \
lsb-release wget && \
wget https://apt.llvm.org/llvm.sh && \
chmod +x ./llvm.sh && ./llvm.sh 20 all && rm llvm.sh && \
apt-get clean && rm -rf /var/lib/apt/lists/*
13 changes: 13 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ jobs:
sudo apt-get update
sudo apt-get install -y libomp-dev

- name: Install libomp (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install libomp
echo "OpenMP_ROOT=$(brew --prefix libomp)" >> "$GITHUB_ENV"
Comment thread
joseestragues marked this conversation as resolved.
Outdated

- name: Install Ninja (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
choco install ninja -y --no-progress
ninja --version
Comment thread
joseestragues marked this conversation as resolved.
Outdated

- name: Install CUDA Toolkit
uses: ./.github/actions/cuda-toolkit

Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ jobs:
submodules: recursive
fetch-depth: 0

- name: Install Ninja (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
choco install ninja -y --no-progress
ninja --version
Comment thread
joseestragues marked this conversation as resolved.
Outdated

- name: Install CUDA Toolkit
uses: ./.github/actions/cuda-toolkit

Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"cacheVariables": {
"CMAKE_C_COMPILER": "cc",
"CMAKE_CXX_COMPILER": "c++",
"OpenMP_ROOT": "$env{OpenMP_ROOT}",
Comment thread
joseestragues marked this conversation as resolved.
Outdated
"CMAKE_C_FLAGS_DEBUG_INIT": "-Wall -Wextra -Wpedantic -fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined",
"CMAKE_CXX_FLAGS_DEBUG_INIT": "-Wall -Wextra -Wpedantic -fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined",
"CMAKE_C_FLAGS_RELWITHDEBINFO_INIT": "-Wall -Wextra -Wpedantic -fsanitize=thread",
Expand Down
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Comment thread
joseestragues marked this conversation as resolved.
Outdated
3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: Feb 24 13:42 UTC
Comment thread
joseestragues marked this conversation as resolved.
Outdated
----------------------------------------------------------
End testing: Feb 24 13:42 UTC
10 changes: 7 additions & 3 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
add_library(common INTERFACE)
add_library(common)

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
19 changes: 19 additions & 0 deletions common/include/common/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <common/types.h>
Comment thread
joseestragues marked this conversation as resolved.
Outdated

namespace physicore {

class random
{
public:
static random& instance();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for the instance method when all the other methods are static


real_t uniform(const real_t min = 0, const real_t max = 1);

real_t normal(const real_t mean = 0, const real_t std = 1);

void set_seed(unsigned int seed);
};

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

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

namespace physicore::common {
Comment thread
joseestragues marked this conversation as resolved.
Outdated
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())
{
assert(false);
return nullptr;
}

return it->second();
}

template <class Derived, class Registry, class Base>
requires std::derived_from<Derived, Base>
Comment thread
joseestragues marked this conversation as resolved.
Outdated
struct registry_adder
{
explicit registry_adder(std::string name)
{
Registry::instance().register_factory(std::move(name), []() { return std::make_unique<Derived>(); });
}
};

} // namespace physicore::common
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
52 changes: 52 additions & 0 deletions common/src/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifdef _OPENMP
#include <omp.h>
#endif

#include <random>
#include <vector>

#include <common/random.h>


thread_local std::mt19937 generator;

physicore::random& physicore::random::instance()
{
static random instance;
return instance;
}

physicore::real_t physicore::random::uniform(const physicore::real_t min, const physicore::real_t max)
{
std::uniform_real_distribution<physicore::real_t> distribution(min, max);
return distribution(generator);
}

physicore::real_t physicore::random::normal(const physicore::real_t mean, const physicore::real_t std)
{
std::normal_distribution<physicore::real_t> distribution(mean, std);
return distribution(generator);
}

void physicore::random::set_seed(unsigned int seed)
{
#ifdef _OPENMP
std::vector<unsigned int> initial_sequence(omp_get_num_threads());

for (int i = 0; i < omp_get_num_threads(); i++)
initial_sequence[i] = seed + i;

std::seed_seq seq(initial_sequence.begin(), initial_sequence.end());

std::vector<unsigned int> seeds(omp_get_num_threads());
seq.generate(seeds.begin(), seeds.end());

#pragma omp parallel
{
int id = omp_get_thread_num();
generator.seed(seeds[id]);
}
#else
generator.seed(seed);
#endif
}
Loading
Loading