Skip to content

Commit

Permalink
Format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbolt committed Nov 7, 2023
1 parent b7104ff commit 8ba6323
Show file tree
Hide file tree
Showing 33 changed files with 113 additions and 178 deletions.
2 changes: 1 addition & 1 deletion src/algebra/Integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Integrator::Integrator(Model* model, double time_step_size, double rho,
system.reserve(model);
}

// Must declare default constructord and dedtructor
// Must declare default constructord and dedtructor
// because of Eigen.
Integrator::Integrator() {}
Integrator::~Integrator() {}
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/Integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Integrator {
* @param atol Absolut tolerance for non-linear iteration termination
* @param max_iter Maximum number of non-linear iterations
*/
Integrator(Model *model, double time_step_size, double rho, double atol,
Integrator(Model* model, double time_step_size, double rho, double atol,
int max_iter);

/**
Expand Down
6 changes: 2 additions & 4 deletions src/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ extern "C" void run_simulation(int problem_id, const double external_time,
std::vector<double>& output_solutions,
int& error_code);

extern "C" void update_block_params(int problem_id,
std::string block_name,
extern "C" void update_block_params(int problem_id, std::string block_name,
std::vector<double>& params);

extern "C" void read_block_params(int problem_id, std::string block_name,
Expand All @@ -82,8 +81,7 @@ extern "C" void read_block_params(int problem_id, std::string block_name,
extern "C" void get_block_node_IDs(int problem_id, std::string block_name,
std::vector<int>& IDs);

extern "C" void update_state(int problem_id,
std::vector<double> new_state_y,
extern "C" void update_state(int problem_id, std::vector<double> new_state_y,
std::vector<double> new_state_ydot);

extern "C" void return_y(int problem_id, std::vector<double>& ydot);
Expand Down
3 changes: 1 addition & 2 deletions src/model/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string Block::get_name() { return this->model->get_block_name(this->id); }
Block::~Block() {}

void Block::setup_dofs_(DOFHandler &dofhandler, int num_equations,
const std::list<std::string>& internal_var_names) {
const std::list<std::string> &internal_var_names) {
// Collect external DOFs from inlet nodes
for (auto &inlet_node : inlet_nodes) {
global_var_ids.push_back(inlet_node->pres_dof);
Expand Down Expand Up @@ -92,4 +92,3 @@ void Block::update_gradient(Eigen::SparseMatrix<double> &jacobian,
}

TripletsContributions Block::get_num_triplets() { return num_triplets; }

13 changes: 6 additions & 7 deletions src/model/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@
#include "SparseSystem.h"

/**
* @brief The number of triplets that the element contributes
* @brief The number of triplets that the element contributes
* to the global system.
*/
struct TripletsContributions {
TripletsContributions() {};
TripletsContributions(int F, int E, int D) : F(F), E(E), D(D) { } ;
TripletsContributions operator+=(const TripletsContributions& other)
{
TripletsContributions(){};
TripletsContributions(int F, int E, int D) : F(F), E(E), D(D){};
TripletsContributions operator+=(const TripletsContributions &other) {
F += other.F;
E += other.E;
D += other.D;
Expand Down Expand Up @@ -157,7 +156,7 @@ class Block {
*/

void setup_dofs_(DOFHandler &dofhandler, int num_equations,
const std::list<std::string>& internal_var_names);
const std::list<std::string> &internal_var_names);

/**
* @brief Set up the degrees of freedom (DOF) of the block
Expand Down Expand Up @@ -231,7 +230,7 @@ class Block {
* Number of triplets that the element contributes to the global system
* (relevant for sparse memory reservation)
*/
TripletsContributions num_triplets;
TripletsContributions num_triplets;

/**
* @brief Get number of triplets of element
Expand Down
22 changes: 7 additions & 15 deletions src/model/BloodVessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ void BloodVessel::update_constant(SparseSystem &system,
double resistance = parameters[global_param_ids[ParamId::RESISTANCE]];

// Set element contributions
system.E.coeffRef(global_eqn_ids[0], global_var_ids[3]) =
-inductance;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[0]) =
-capacitance;
system.E.coeffRef(global_eqn_ids[0], global_var_ids[3]) = -inductance;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[0]) = -capacitance;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[1]) =
capacitance * resistance;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[0]) = 1.0;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
-resistance;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[1]) = -resistance;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[2]) = -1.0;
system.F.coeffRef(global_eqn_ids[1], global_var_ids[1]) = 1.0;
system.F.coeffRef(global_eqn_ids[1], global_var_ids[3]) = -1.0;
Expand All @@ -70,8 +67,7 @@ void BloodVessel::update_solution(

// Set element contributions
system.C(global_eqn_ids[0]) = stenosis_resistance * -q_in;
system.C(global_eqn_ids[1]) =
stenosis_resistance * 2.0 * capacitance * dq_in;
system.C(global_eqn_ids[1]) = stenosis_resistance * 2.0 * capacitance * dq_in;

double sgn_q_in = (0.0 < q_in) - (q_in < 0.0);
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
Expand Down Expand Up @@ -103,21 +99,18 @@ void BloodVessel::update_gradient(
double stenosis_coeff = 0.0;

if (global_param_ids.size() > 3) {
stenosis_coeff =
alpha[global_param_ids[ParamId::STENOSIS_COEFFICIENT]];
stenosis_coeff = alpha[global_param_ids[ParamId::STENOSIS_COEFFICIENT]];
}
auto stenosis_resistance = stenosis_coeff * fabs(y1);

jacobian.coeffRef(global_eqn_ids[0], global_param_ids[0]) = -y1;
jacobian.coeffRef(global_eqn_ids[0], global_param_ids[2]) = -dy3;

if (global_param_ids.size() > 3) {
jacobian.coeffRef(global_eqn_ids[0], global_param_ids[3]) =
-fabs(y1) * y1;
jacobian.coeffRef(global_eqn_ids[0], global_param_ids[3]) = -fabs(y1) * y1;
}

jacobian.coeffRef(global_eqn_ids[1], global_param_ids[0]) =
capacitance * dy1;
jacobian.coeffRef(global_eqn_ids[1], global_param_ids[0]) = capacitance * dy1;
jacobian.coeffRef(global_eqn_ids[1], global_param_ids[1]) =
-dy0 + (resistance + 2 * stenosis_resistance) * dy1;

Expand All @@ -132,4 +125,3 @@ void BloodVessel::update_gradient(
y1 - y3 - capacitance * dy0 +
capacitance * (resistance + 2.0 * stenosis_resistance) * dy1;
}

3 changes: 1 addition & 2 deletions src/model/BloodVessel.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ class BloodVessel : public Block {
* Number of triplets that the element contributes to the global system
* (relevant for sparse memory reservation)
*/
TripletsContributions num_triplets{5,3,2};

TripletsContributions num_triplets{5, 3, 2};
};

#endif // SVZERODSOLVER_MODEL_BLOODVESSEL_HPP_
27 changes: 10 additions & 17 deletions src/model/BloodVesselJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ void BloodVesselJunction::update_constant(SparseSystem &system,
for (size_t i = 0; i < num_outlets; i++) {
double inductance = parameters[global_param_ids[num_outlets + i]];
double resistance = parameters[global_param_ids[i]];
system.F.coeffRef(global_eqn_ids[0],
global_var_ids[3 + 2 * i]) = -1.0;
system.F.coeffRef(global_eqn_ids[i + 1],
global_var_ids[3 + 2 * i]) = -resistance;
system.F.coeffRef(global_eqn_ids[i + 1], global_var_ids[0]) =
1.0;
system.F.coeffRef(global_eqn_ids[i + 1],
global_var_ids[2 + 2 * i]) = -1.0;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[3 + 2 * i]) = -1.0;
system.F.coeffRef(global_eqn_ids[i + 1], global_var_ids[3 + 2 * i]) =
-resistance;
system.F.coeffRef(global_eqn_ids[i + 1], global_var_ids[0]) = 1.0;
system.F.coeffRef(global_eqn_ids[i + 1], global_var_ids[2 + 2 * i]) = -1.0;

system.E.coeffRef(global_eqn_ids[i + 1],
global_var_ids[3 + 2 * i]) = -inductance;
system.E.coeffRef(global_eqn_ids[i + 1], global_var_ids[3 + 2 * i]) =
-inductance;
}
}

Expand All @@ -71,15 +68,13 @@ void BloodVesselJunction::update_solution(
Eigen::Matrix<double, Eigen::Dynamic, 1> &dy) {
for (size_t i = 0; i < num_outlets; i++) {
// Get parameters
auto stenosis_coeff =
parameters[global_param_ids[2 * num_outlets + i]];
auto stenosis_coeff = parameters[global_param_ids[2 * num_outlets + i]];
auto q_out = y[global_var_ids[3 + 2 * i]];
auto stenosis_resistance = stenosis_coeff * fabs(q_out);

// Mass conservation
system.C(global_eqn_ids[i + 1]) = -stenosis_resistance * q_out;
system.dC_dy.coeffRef(global_eqn_ids[i + 1],
global_var_ids[3 + 2 * i]) =
system.dC_dy.coeffRef(global_eqn_ids[i + 1], global_var_ids[3 + 2 * i]) =
-2.0 * stenosis_resistance;
}
}
Expand Down Expand Up @@ -107,8 +102,7 @@ void BloodVesselJunction::update_gradient(
auto stenosis_resistance = stenosis_coeff * fabs(q_out);

// Resistance
jacobian.coeffRef(global_eqn_ids[i + 1], global_param_ids[i]) =
-q_out;
jacobian.coeffRef(global_eqn_ids[i + 1], global_param_ids[i]) = -q_out;

// Inductance
jacobian.coeffRef(global_eqn_ids[i + 1],
Expand All @@ -127,4 +121,3 @@ void BloodVesselJunction::update_gradient(
inductance * dq_out;
}
}

13 changes: 4 additions & 9 deletions src/model/ClosedLoopCoronaryBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,20 @@ void ClosedLoopCoronaryBC::update_constant(SparseSystem &system,
auto ca = parameters[global_param_ids[ParamId::CA]];
auto cim = parameters[global_param_ids[ParamId::CIM]];

system.E.coeffRef(global_eqn_ids[0], global_var_ids[0]) =
-ram * ca;
system.E.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
ram * ra * ca;
system.E.coeffRef(global_eqn_ids[0], global_var_ids[0]) = -ram * ca;
system.E.coeffRef(global_eqn_ids[0], global_var_ids[1]) = ram * ra * ca;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[0]) = -ca;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[1]) = ca * ra;
system.E.coeffRef(global_eqn_ids[1], global_var_ids[4]) = -1.0;

system.F.coeffRef(global_eqn_ids[0], global_var_ids[0]) = -1.0;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
(ra + ram);
system.F.coeffRef(global_eqn_ids[0], global_var_ids[1]) = (ra + ram);
system.F.coeffRef(global_eqn_ids[0], global_var_ids[2]) = 1.0;
system.F.coeffRef(global_eqn_ids[0], global_var_ids[3]) = rv;
system.F.coeffRef(global_eqn_ids[1], global_var_ids[1]) = 1.0;
system.F.coeffRef(global_eqn_ids[1], global_var_ids[3]) = -1.0;
system.F.coeffRef(global_eqn_ids[2], global_var_ids[2]) = cim;
system.F.coeffRef(global_eqn_ids[2], global_var_ids[3]) =
cim * rv;
system.F.coeffRef(global_eqn_ids[2], global_var_ids[3]) = cim * rv;
system.F.coeffRef(global_eqn_ids[2], global_var_ids[4]) = -1.0;
}

Expand All @@ -90,4 +86,3 @@ void ClosedLoopCoronaryBC::update_solution(
auto pim = im * y[ventricle_var_id];
system.C(global_eqn_ids[2]) = -cim * pim;
}

52 changes: 19 additions & 33 deletions src/model/ClosedLoopHeartPulmonary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ void ClosedLoopHeartPulmonary::update_solution(
// DOF 1: Flow into right atrium (no equation)

// DOF 2, Eq 1: Aortic pressure
system.F.coeffRef(global_eqn_ids[1], global_var_ids[15]) =
-valves[15];
system.F.coeffRef(global_eqn_ids[1], global_var_ids[15]) = -valves[15];
system.F.coeffRef(global_eqn_ids[1], global_var_ids[3]) = 1.0;

// DOF 3: Flow into aorta (no equation)

// DOF 4, Eq 2: Right atrium volume
system.F.coeffRef(global_eqn_ids[2], global_var_ids[5]) =
1.0 * valves[5];
system.F.coeffRef(global_eqn_ids[2], global_var_ids[5]) = 1.0 * valves[5];
system.F.coeffRef(global_eqn_ids[2], global_var_ids[1]) = -1.0;

// DOF 5, Eq 3: Right atrium outflow
Expand All @@ -119,16 +117,13 @@ void ClosedLoopHeartPulmonary::update_solution(

// DOF 6, Eq 4: Right ventricle pressure
system.F.coeffRef(global_eqn_ids[4], global_var_ids[6]) = 1.0;
system.F.coeffRef(global_eqn_ids[4], global_var_ids[7]) =
-Erv;
system.F.coeffRef(global_eqn_ids[4], global_var_ids[7]) = -Erv;
system.C(global_eqn_ids[4]) =
Erv * parameters[global_param_ids[ParamId::VRV_U]];

// DOF 7, Eq 5: Right ventricle volume
system.F.coeffRef(global_eqn_ids[5], global_var_ids[5]) =
-1.0 * valves[5];
system.F.coeffRef(global_eqn_ids[5], global_var_ids[8]) =
1.0 * valves[8];
system.F.coeffRef(global_eqn_ids[5], global_var_ids[5]) = -1.0 * valves[5];
system.F.coeffRef(global_eqn_ids[5], global_var_ids[8]) = 1.0 * valves[8];

// DOF 8, Eq 6: Right ventricle outflow
system.F.coeffRef(global_eqn_ids[6], global_var_ids[6]) = -1.0;
Expand All @@ -137,8 +132,7 @@ void ClosedLoopHeartPulmonary::update_solution(
parameters[global_param_ids[ParamId::RRV_A]] * valves[8];

// DOF 9, Eq 7: Pulmonary pressure
system.F.coeffRef(global_eqn_ids[7], global_var_ids[8]) =
-valves[8];
system.F.coeffRef(global_eqn_ids[7], global_var_ids[8]) = -valves[8];
system.F.coeffRef(global_eqn_ids[7], global_var_ids[9]) =
1.0 / parameters[global_param_ids[ParamId::RPD]];
system.F.coeffRef(global_eqn_ids[7], global_var_ids[10]) =
Expand All @@ -156,10 +150,8 @@ void ClosedLoopHeartPulmonary::update_solution(
psi_la_derivative * (AA - 1.0);

// DOF 11, Eq 9: Left atrium volume
system.F.coeffRef(global_eqn_ids[9], global_var_ids[8]) =
-1.0 * valves[8];
system.F.coeffRef(global_eqn_ids[9], global_var_ids[12]) =
1.0 * valves[12];
system.F.coeffRef(global_eqn_ids[9], global_var_ids[8]) = -1.0 * valves[8];
system.F.coeffRef(global_eqn_ids[9], global_var_ids[12]) = 1.0 * valves[12];

// DOF 12, Eq 10: Left atrium outflow
system.F.coeffRef(global_eqn_ids[10], global_var_ids[10]) = -1.0;
Expand All @@ -169,16 +161,13 @@ void ClosedLoopHeartPulmonary::update_solution(

// DOF 13, Eq 11: Left ventricle pressure
system.F.coeffRef(global_eqn_ids[11], global_var_ids[13]) = 1.0;
system.F.coeffRef(global_eqn_ids[11], global_var_ids[14]) =
-Elv;
system.F.coeffRef(global_eqn_ids[11], global_var_ids[14]) = -Elv;
system.C(global_eqn_ids[11]) =
Elv * parameters[global_param_ids[ParamId::VLV_U]];

// DOF 14, Eq 12: Left ventricle volume
system.F.coeffRef(global_eqn_ids[12], global_var_ids[12]) =
-1.0 * valves[12];
system.F.coeffRef(global_eqn_ids[12], global_var_ids[15]) =
1.0 * valves[15];
system.F.coeffRef(global_eqn_ids[12], global_var_ids[12]) = -1.0 * valves[12];
system.F.coeffRef(global_eqn_ids[12], global_var_ids[15]) = 1.0 * valves[15];

// DOF 15, Eq 13: Left ventricle outflow
system.F.coeffRef(global_eqn_ids[13], global_var_ids[13]) = -1.0;
Expand Down Expand Up @@ -242,16 +231,14 @@ void ClosedLoopHeartPulmonary::get_psi_ra_la(
Eigen::Matrix<double, Eigen::Dynamic, 1> &y) {
auto RA_volume = y[global_var_ids[4]];
auto LA_volume = y[global_var_ids[11]];
psi_ra =
parameters[global_param_ids[ParamId::KXP_RA]] *
(exp((RA_volume - parameters[global_param_ids[ParamId::VASO_RA]]) *
parameters[global_param_ids[ParamId::KXV_RA]]) -
1.0);
psi_la =
parameters[global_param_ids[ParamId::KXP_LA]] *
(exp((LA_volume - parameters[global_param_ids[ParamId::VASO_LA]]) *
parameters[global_param_ids[ParamId::KXV_LA]]) -
1.0);
psi_ra = parameters[global_param_ids[ParamId::KXP_RA]] *
(exp((RA_volume - parameters[global_param_ids[ParamId::VASO_RA]]) *
parameters[global_param_ids[ParamId::KXV_RA]]) -
1.0);
psi_la = parameters[global_param_ids[ParamId::KXP_LA]] *
(exp((LA_volume - parameters[global_param_ids[ParamId::VASO_LA]]) *
parameters[global_param_ids[ParamId::KXV_LA]]) -
1.0);

psi_ra_derivative =
parameters[global_param_ids[ParamId::KXP_RA]] *
Expand Down Expand Up @@ -303,4 +290,3 @@ void ClosedLoopHeartPulmonary::get_valve_positions(
y[global_var_ids[15]] = 0.0;
}
}

1 change: 0 additions & 1 deletion src/model/ClosedLoopRCRBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ void ClosedLoopRCRBC::update_constant(SparseSystem &system,
system.F.coeffRef(global_eqn_ids[2], global_var_ids[3]) =
-parameters[global_param_ids[ParamId::RD]];
}

1 change: 0 additions & 1 deletion src/model/FlowReferenceBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ void FlowReferenceBC::update_time(SparseSystem &system,
std::vector<double> &parameters) {
system.C(global_eqn_ids[0]) = -parameters[global_param_ids[0]];
}

1 change: 0 additions & 1 deletion src/model/FlowReferenceBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class FlowReferenceBC : public Block {
* (relevant for sparse memory reservation)
*/
TripletsContributions num_triplets{1, 0, 0};

};

#endif // SVZERODSOLVER_MODEL_FLOWREFERENCEBC_HPP_
Loading

0 comments on commit 8ba6323

Please sign in to comment.