-
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 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 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
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,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 |
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,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 |
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
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,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
|
||
| { | ||
| 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 | ||
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.