Skip to content

Commit 89a2684

Browse files
committed
tidy and formatted (2nd try)
1 parent 4af9f96 commit 89a2684

File tree

9 files changed

+95
-196
lines changed

9 files changed

+95
-196
lines changed

src/cart_cell.cc

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include <algorithm>
23+
#include <cmath>
2324
#include <cstdint>
2425
#include <stdexcept>
2526
#include <string>
@@ -35,7 +36,6 @@
3536
#include "core/real_t.h"
3637
#include "core/resource_manager.h"
3738
#include "core/util/log.h"
38-
#include "core/util/root.h"
3939

4040
#include "cart_cell.h"
4141
#include "hyperparams.h"
@@ -44,25 +44,7 @@
4444

4545
namespace bdm {
4646

47-
CartCell::CartCell(const Real3& position)
48-
: state_(CartCellState::kAlive),
49-
timer_state_(0),
50-
oxygen_dgrid_(nullptr),
51-
immunostimulatory_factor_dgrid_(nullptr),
52-
attached_to_tumor_cell_(false),
53-
current_live_time_(kAverageMaximumTimeUntillApoptosisCart),
54-
fluid_fraction_(kDefaultFractionFluidCartCell),
55-
nuclear_volume_(kDefaultVolumeNucleusCartCell),
56-
target_cytoplasm_solid_(0.0),
57-
target_nucleus_solid_(0.0),
58-
target_fraction_fluid_(0.0),
59-
target_relation_cytoplasm_nucleus_(0.0),
60-
older_velocity_({0, 0, 0}),
61-
oxygen_consumption_rate_(kDefaultOxygenConsumption),
62-
immunostimulatory_factor_secretion_rate_(0.0),
63-
constant1_oxygen_(0.0),
64-
constant2_oxygen_(0.0),
65-
attached_cell_(nullptr) {
47+
CartCell::CartCell(const Real3& position) {
6648
SetPosition(position);
6749
SetVolume(kDefaultVolumeNewCartCell);
6850
const ResourceManager& rm = *Simulation::GetActive()->GetResourceManager();
@@ -89,7 +71,7 @@ real_t CartCell::GetTargetTotalVolume() const {
8971
// convergence
9072
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
9173
void CartCell::ChangeVolumeExponentialRelaxationEquation(
92-
real_t relaxation_rate_cytoplasm, real_t relaxation_rate_nucleus,
74+
real_t relaxation_rate_cytoplasm, real_t relaxation_rate_nucleus, // NOLINT
9375
real_t relaxation_rate_fluid) {
9476
// Exponential relaxation towards the target volume
9577
const real_t current_total_volume = GetVolume();
@@ -144,7 +126,7 @@ void CartCell::ChangeVolumeExponentialRelaxationEquation(
144126
const real_t new_volume = new_total_solid + new_fluid;
145127

146128
// Avoid division by zero
147-
real_t new_fraction_fluid = new_fluid / (kEpsilon + new_volume);
129+
const real_t new_fraction_fluid = new_fluid / (kEpsilon + new_volume);
148130

149131
// Update the cell's properties
150132
// if the volume has changed
@@ -174,7 +156,7 @@ Real3 CartCell::CalculateDisplacement(const InteractionForce* force,
174156
// We check for every neighbor object if they touch us, i.e. push us
175157
// away and agreagate the velocities
176158

177-
uint64_t non_zero_neighbor_forces = 0;
159+
uint64_t non_zero_neighbor_forces = 0; // NOLINT
178160
if (!IsStatic()) {
179161
auto* ctxt = Simulation::GetActive()->GetExecutionContext();
180162
auto calculate_neighbor_forces =
@@ -212,7 +194,7 @@ Real3 CartCell::CalculateDisplacement(const InteractionForce* force,
212194
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
213195
real_t CartCell::ConsumeSecreteSubstance(int substance_id,
214196
real_t old_concentration) {
215-
real_t res = NAN;
197+
real_t res = NAN; // NOLINT
216198
if (substance_id == oxygen_dgrid_->GetContinuumId()) {
217199
// consuming oxygen
218200
res = (old_concentration + constant1_oxygen_) / constant2_oxygen_;

src/cart_cell.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
#define CART_CELL_H_
2424

2525
#include "core/agent/agent.h"
26-
#include "core/agent/cell.h"
2726
#include "core/agent/new_agent_event.h"
28-
#include "core/behavior/behavior.h"
2927
#include "core/container/math_array.h"
3028
#include "core/diffusion/diffusion_grid.h"
3129
#include "core/interaction_force.h"
3230
#include "core/real_t.h"
33-
#include "core/util/root.h"
3431

3532
#include "tumor_cell.h"
3633

@@ -62,8 +59,7 @@ class CartCell : public Cell {
6259
CartCell() = default;
6360
explicit CartCell(const Real3& position);
6461

65-
// Copy and move constructors/destructors (assignment operators are deleted by
66-
// base class)
62+
// Copy and move constructors/destructors/assignment operators
6763
CartCell(const CartCell&) = default;
6864
CartCell(CartCell&&) = default;
6965
~CartCell() override = default;
@@ -153,7 +149,8 @@ class CartCell : public Cell {
153149
/// @param relaxation_rate_fluid Relaxation rate for fluid volume changes
154150
void ChangeVolumeExponentialRelaxationEquation(
155151
real_t relaxation_rate_cytoplasm, real_t relaxation_rate_nucleus,
156-
real_t relaxation_rate_fluid);
152+
real_t
153+
relaxation_rate_fluid); // NOLINT(bugprone-easily-swappable-parameters)
157154

158155
/// Calculate displacement of the cell
159156
///
@@ -272,10 +269,11 @@ struct StateControlCart : public Behavior {
272269

273270
StateControlCart() { AlwaysCopyToNew(); }
274271

275-
// Copy and move constructors/destructors (assignment operators handled by
276-
// base class)
272+
// Special member functions
277273
StateControlCart(const StateControlCart&) = default;
278274
StateControlCart(StateControlCart&&) = default;
275+
StateControlCart& operator=(const StateControlCart&) = default;
276+
StateControlCart& operator=(StateControlCart&&) = default;
279277
~StateControlCart() override = default;
280278

281279
/// Execute the state control behavior

src/diffusion_thomas_algorithm.cc

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "core/agent/agent.h"
2828
#include "core/diffusion/diffusion_grid.h"
2929
#include "core/real_t.h"
30-
#include "core/util/root.h"
3130

3231
#include "cart_cell.h"
3332
#include "diffusion_thomas_algorithm.h"
@@ -36,15 +35,15 @@
3635

3736
namespace bdm {
3837

39-
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
40-
DiffusionThomasAlgorithm::DiffusionThomasAlgorithm(int substance_id,
38+
DiffusionThomasAlgorithm::DiffusionThomasAlgorithm(int substance_id, // NOLINT
4139
std::string substance_name,
4240
real_t dc, real_t mu,
43-
int resolution, real_t dt,
41+
real_t resolution, real_t dt,
4442
bool dirichlet_border)
4543
: DiffusionGrid(substance_id, std::move(substance_name), dc, mu,
46-
resolution),
47-
resolution_(static_cast<size_t>(GetResolution())),
44+
static_cast<int>(
45+
resolution)), // Added cast for consistency with parent
46+
resolution_(GetResolution()),
4847
d_space_(static_cast<real_t>(kBoundedSpaceLength) /
4948
static_cast<real_t>(resolution_)),
5049
dirichlet_border_(dirichlet_border),
@@ -88,7 +87,8 @@ void DiffusionThomasAlgorithm::InitializeThomasAlgorithmVectors(
8887

8988
// Apply Dirichlet boundary conditions to the grid
9089
void DiffusionThomasAlgorithm::ApplyDirichletBoundaryConditions() {
91-
const real_t origin = GetDimensionsPtr()
90+
const auto* dimensions_ptr = GetDimensionsPtr();
91+
const real_t origin = dimensions_ptr
9292
[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
9393
const real_t simulated_time = GetSimulatedTime();
9494
#pragma omp parallel
@@ -165,14 +165,10 @@ void DiffusionThomasAlgorithm::ApplyDirichletBoundaryConditions() {
165165

166166
// Sets the concentration at a specific voxel
167167
void DiffusionThomasAlgorithm::SetConcentration(size_t idx, real_t amount) {
168-
const auto* all_concentrations =
169-
GetAllConcentrations(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
170-
ChangeConcentrationBy(
171-
idx,
172-
amount -
173-
all_concentrations
174-
[idx], // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
175-
InteractionMode::kAdditive, false);
168+
const auto* all_concentrations = GetAllConcentrations();
169+
const real_t current_concentration = all_concentrations[idx];
170+
ChangeConcentrationBy(idx, amount - current_concentration,
171+
InteractionMode::kAdditive, false);
176172
}
177173

178174
// Flattens the 3D coordinates (x, y, z) into a 1D index
@@ -223,16 +219,29 @@ void DiffusionThomasAlgorithm::ApplyBoundaryConditionsIfNeeded() {
223219
}
224220

225221
void DiffusionThomasAlgorithm::SolveDirectionThomas(unsigned int direction) {
226-
const auto& thomas_denom = (direction == 0) ? thomas_denom_x_
227-
: (direction == 1) ? thomas_denom_y_
228-
: thomas_denom_z_;
229-
const auto& thomas_c = (direction == 0) ? thomas_c_x_
230-
: (direction == 1) ? thomas_c_y_
231-
: thomas_c_z_;
232-
const unsigned int jump =
233-
(direction == 0) ? static_cast<unsigned int>(jump_i_)
234-
: (direction == 1) ? static_cast<unsigned int>(jump_j_)
235-
: static_cast<unsigned int>(jump_k_);
222+
const auto& thomas_denom = [this, direction]() -> const std::vector<real_t>& {
223+
if (direction == 0)
224+
return thomas_denom_x_;
225+
if (direction == 1)
226+
return thomas_denom_y_;
227+
return thomas_denom_z_;
228+
}();
229+
230+
const auto& thomas_c = [this, direction]() -> const std::vector<real_t>& {
231+
if (direction == 0)
232+
return thomas_c_x_;
233+
if (direction == 1)
234+
return thomas_c_y_;
235+
return thomas_c_z_;
236+
}();
237+
238+
const unsigned int jump = [this, direction]() -> unsigned int {
239+
if (direction == 0)
240+
return static_cast<unsigned int>(jump_i_);
241+
if (direction == 1)
242+
return static_cast<unsigned int>(jump_j_);
243+
return static_cast<unsigned int>(jump_k_);
244+
}();
236245

237246
#pragma omp parallel for collapse(2)
238247
for (unsigned int outer = 0; outer < resolution_; outer++) {
@@ -246,55 +255,46 @@ void DiffusionThomasAlgorithm::SolveDirectionThomas(unsigned int direction) {
246255
}
247256
}
248257

258+
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
249259
void DiffusionThomasAlgorithm::ForwardElimination(
250260
unsigned int direction, unsigned int outer, unsigned int middle,
251261
const std::vector<real_t>& thomas_denom, unsigned int jump) {
252262
// Get initial index based on direction
253263
size_t ind = GetLoopIndex(direction, outer, middle, 0);
254-
const auto* all_concentrations =
255-
GetAllConcentrations(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
256-
SetConcentration(
257-
ind,
258-
all_concentrations[ind] /
259-
thomas_denom
260-
[0]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
264+
const auto* all_concentrations = GetAllConcentrations();
265+
const real_t initial_concentration = all_concentrations[ind];
266+
SetConcentration(ind, initial_concentration / thomas_denom[0]);
261267

262268
// Forward elimination loop
263269
for (unsigned int inner = 1; inner < resolution_; inner++) {
264270
ind = GetLoopIndex(direction, outer, middle, inner);
265-
SetConcentration(
266-
ind,
267-
(all_concentrations
268-
[ind] + // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
269-
constant1_ *
270-
all_concentrations
271-
[ind -
272-
jump]) / // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
273-
thomas_denom[inner]);
271+
const real_t current_concentration = all_concentrations[ind];
272+
const real_t prev_concentration = all_concentrations[ind - jump];
273+
SetConcentration(ind,
274+
(current_concentration + constant1_ * prev_concentration) /
275+
thomas_denom[inner]);
274276
}
275277
}
276278

279+
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
277280
void DiffusionThomasAlgorithm::BackSubstitution(
278281
unsigned int direction, unsigned int outer, unsigned int middle,
279282
const std::vector<real_t>& thomas_c, unsigned int jump) {
280-
const auto* all_concentrations =
281-
GetAllConcentrations(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
283+
const auto* all_concentrations = GetAllConcentrations();
282284

283285
// Back substitution loop
284286
for (int inner = static_cast<int>(resolution_) - 2; inner >= 0; inner--) {
285-
size_t ind = GetLoopIndex(direction, outer, middle,
286-
static_cast<unsigned int>(inner));
287+
const size_t ind = GetLoopIndex(direction, outer, middle,
288+
static_cast<unsigned int>(inner));
289+
const real_t current_concentration = all_concentrations[ind];
290+
const real_t next_concentration = all_concentrations[ind + jump];
287291
SetConcentration(
288-
ind,
289-
all_concentrations
290-
[ind] - // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
291-
thomas_c[static_cast<size_t>(inner)] *
292-
all_concentrations
293-
[ind +
294-
jump]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
292+
ind, current_concentration -
293+
thomas_c[static_cast<size_t>(inner)] * next_concentration);
295294
}
296295
}
297296

297+
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
298298
size_t DiffusionThomasAlgorithm::GetLoopIndex(unsigned int direction,
299299
unsigned int outer,
300300
unsigned int middle,

src/diffusion_thomas_algorithm.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,10 @@ class DiffusionThomasAlgorithm : public DiffusionGrid {
4949
constant1a_(0.0),
5050
constant2_(0.0),
5151
constant3_(0.0),
52-
constant3a_(0.0),
53-
thomas_c_x_(),
54-
thomas_denom_x_(),
55-
thomas_c_y_(),
56-
thomas_denom_y_(),
57-
thomas_c_z_(),
58-
thomas_denom_z_() {}
52+
constant3a_(0.0) {}
5953

6054
DiffusionThomasAlgorithm(int substance_id, std::string substance_name,
61-
real_t dc, real_t mu, int resolution, real_t dt,
55+
real_t dc, real_t mu, real_t resolution, real_t dt,
6256
bool dirichlet_border);
6357

6458
/// Concentration setters

src/forces_tumor_cart.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
#include <algorithm>
2323
#include <cmath>
2424

25+
#include "core/agent/agent.h"
26+
#include "core/agent/cell.h"
2527
#include "core/container/math_array.h"
28+
#include "core/interaction_force.h"
2629
#include "core/real_t.h"
2730

2831
#include "forces_tumor_cart.h"
@@ -112,10 +115,11 @@ Real4 InteractionVelocity::Calculate(const Agent* lhs, const Agent* rhs) const {
112115

113116
// std::cout << "temp_a = " << temp_a << std::endl;// Debug output
114117

115-
real_t adhesion;
116-
if (a_tumor && b_tumor) { // two tumor cells
118+
real_t adhesion = NAN; // Initialize to NAN
119+
if ((a_tumor != nullptr) && (b_tumor != nullptr)) { // two tumor cells
117120
adhesion = kAdhesionTumorTumor;
118-
} else if (!a_tumor && !b_tumor) { // two CAR-T cells
121+
} else if ((a_tumor == nullptr) &&
122+
(b_tumor == nullptr)) { // two CAR-T cells
119123
adhesion = kAdhesionCartCart;
120124
} else { // one tumor cell and one CAR-T
121125
adhesion = std::sqrt(kAdhesionCartTumor * kAdhesionTumorCart);
@@ -133,7 +137,7 @@ Real4 InteractionVelocity::Calculate(const Agent* lhs, const Agent* rhs) const {
133137
if (std::abs(temp_r) < kEpsilon) {
134138
return {0.0, 0.0, 0.0, 0.0};
135139
}
136-
real_t force_magnitude = temp_r / distance;
140+
const real_t force_magnitude = temp_r / distance;
137141

138142
// Debug Output volcities
139143
// std::ofstream file("output/intercation_velocities.csv", std::ios::app);

0 commit comments

Comments
 (0)