-
Notifications
You must be signed in to change notification settings - Fork 0
OpenMP solvers #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joseestraguesbsc
wants to merge
34
commits into
feature/mech-orig
Choose a base branch
from
dev/mech-orig
base: feature/mech-orig
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
OpenMP solvers #110
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 73eeb93
Openmp solver ported
joseestragues d088441
Mechs SolvePair tests added
7bd5dd6
VTK test added
51ca0b8
Code coverage increased
4906bde
Revert one fix
f947c28
Windows minor fixes and clang formatting
707e0c4
Appleclang openmp fix
138999e
Solver registry restructure and appleclang fixes
45243db
Update vcpkg submodule to latest
fff9810
Windows ninja install
a14da8b
Adressing pr comments
486570b
subsolvers added
9bdf770
fixing things
510bd7e
Fixing comments
6458bb1
all comments addressed
475270d
Revert back vcpkg
asmelko e2f5783
Revert release.yml
asmelko a3fed7f
Apply clang-format
asmelko af374b9
Cosmetic changes
asmelko 1fb7030
Fix windows build
asmelko 66a4edd
Make common library an object library
asmelko dcc930f
Code coverage for environment
291dfb0
code coverage for common registry
83951fc
Test fix
827a357
Clang format fixing
d8d7a6c
clang fix
6b12294
clang fix
c682e42
clang fix
8fe8e04
Add .clang-tidy to the kernels dir
asmelko 2c8b4e3
Fix linting
asmelko a948097
Extend sonar with mechanics kernel
asmelko 3617aed
Move random to openmp solver
asmelko 0411cfc
Refactor SonarQube configuration to streamline source and test paths
asmelko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -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 | ||
|
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/* | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| --- | ||
|
joseestragues marked this conversation as resolved.
Outdated
|
||
This file contains hidden or 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,3 @@ | ||
| Start testing: Feb 24 13:42 UTC | ||
|
joseestragues marked this conversation as resolved.
Outdated
|
||
| ---------------------------------------------------------- | ||
| End testing: Feb 24 13:42 UTC | ||
This file contains hidden or 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
This file contains hidden or 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,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 |
This file contains hidden or 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 @@ | ||
| #pragma once | ||
|
|
||
| #include <common/types.h> | ||
|
joseestragues marked this conversation as resolved.
Outdated
|
||
|
|
||
| namespace physicore { | ||
|
|
||
| class random | ||
| { | ||
| public: | ||
| static random& instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
This file contains hidden or 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,56 @@ | ||
| #pragma once | ||
|
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <functional> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| namespace physicore::common { | ||
|
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> | ||
|
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 | ||
This file contains hidden or 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
This file contains hidden or 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,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 |
This file contains hidden or 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,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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.