Skip to content

Commit

Permalink
fix some cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rboman committed Mar 18, 2024
1 parent 097a573 commit 8f735f6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion classes/sph0/louis/src_cpp/FixedParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FixedParticle : public Particle

{
public:
FixedParticle(Model &m);
explicit FixedParticle(Model &m);

virtual void update_vars() override;
};
Expand Down
2 changes: 1 addition & 1 deletion classes/sph0/louis/src_cpp/MobileParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class MobileParticle : public FixedParticle
{
public:
MobileParticle(Model &m);
explicit MobileParticle(Model &m);

virtual void update_vars() override;

Expand Down
15 changes: 14 additions & 1 deletion classes/sph0/louis/src_cpp/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ Model::Model()
this->timeStep = 1.0e-15;
this->currentTime = 0.0;
this->RKstep = 0;

// init other variables
this->numFP = 0;
this->numMP = 0;
this->h_0 = 0.0;
this->dom_dim = 0.0;
this->alpha = 0.0;
this->beta = 0.0;
this->kappa = 0.0;
this->kernelCorrection = 0.0;
this->maxTime = 0.0;
this->saveInt = 0.0;
this->numPart = 0;
}

Model::~Model()
Expand Down Expand Up @@ -264,7 +277,7 @@ Model::update_dt()
double dTf = std::numeric_limits<double>::max();
for (int i = this->numFP + 1; i < this->numPart; i++)
{
Particle *p = this->particles[i];
Particle const *p = this->particles[i];
double dt = sqrt(p->h / 9.81);
if (dt < dTf)
dTf = dt;
Expand Down
12 changes: 6 additions & 6 deletions classes/sph0/louis/src_cpp/Particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void
Particle::getNeighbours()
{
int RKstep = this->model.RKstep;
Eigen::Vector3d &xyz = this->coord[RKstep]; // position of the particle
Eigen::Vector3d const &xyz = this->coord[RKstep]; // position of the particle

if (RKstep == 0)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ Particle::getNeighbours()
for (size_t j = 0; j < cells->size(); j++)
{
Particle *p = (*cells)[j];
Eigen::Vector3d &neighXYZ = p->coord[RKstep];
Eigen::Vector3d const &neighXYZ = p->coord[RKstep];
double r = (xyz - neighXYZ).norm();
if (r <= this->model.kappa * this->h)
{
Expand Down Expand Up @@ -149,7 +149,7 @@ Particle::getNeighbours()
for (size_t i = 0; i < this->neighbours.size(); i++)
{
Neighbour *neigh = &this->neighbours[i];
Eigen::Vector3d &neighXYZ = neigh->p->coord[RKstep];
Eigen::Vector3d const &neighXYZ = neigh->p->coord[RKstep];
neigh->r = (xyz - neighXYZ).norm();
}
}
Expand All @@ -167,7 +167,7 @@ Particle::gradW()
if (this->neighbours.size() > 150)
throw std::runtime_error("number of neighbours greater than expected (max 150 for vec_gradW): " + std::to_string(this->neighbours.size()));

double h = this->h;
// double h = this->h;
int RKstep = this->model.RKstep;

for (size_t i = 0; i < this->neighbours.size(); i++)
Expand Down Expand Up @@ -198,8 +198,8 @@ Particle::kernel_corr()
for (size_t i = 0; i < this->neighbours.size(); i++)
{
Particle *neigh = this->neighbours[i].p;
Eigen::Vector3d &pb = neigh->coord[RKstep];
Eigen::Vector3d &pa = this->coord[RKstep];
Eigen::Vector3d const &pb = neigh->coord[RKstep];
Eigen::Vector3d const &pa = this->coord[RKstep];

double factor = neigh->m / neigh->rho[RKstep];
M += factor * (pb - pa) * this->vec_gradW[i].transpose();
Expand Down
3 changes: 2 additions & 1 deletion classes/sph0/louis/src_cpp/QtVTKHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class DisplayWindow : public QWidget
public:
DisplayWindow(Model &model, QWidget *parent = nullptr);
~DisplayWindow();
void updateParticlePositions();

void updateParticlePositions();

private:
void setupGUI();
Expand Down
6 changes: 4 additions & 2 deletions classes/sph0/louis/src_cpp/Sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

Sorter::Sorter(Model &m) : model(m)
{
this->dx = 0.0;
this->nx = 0;
}

/// Put every particle in their corresponding cell.
Expand All @@ -23,9 +25,9 @@ Sorter::execute()
for(auto &cell : this->cells)
cell.clear();

for(auto &p : this->model.particles)
for(auto const &p : this->model.particles)
{
Eigen::Vector3d &pos = p->coord[this->model.RKstep];
Eigen::Vector3d const &pos = p->coord[this->model.RKstep];

int ix = (int)((pos(0) - fmod(pos(0), this->dx)) / this->dx) + 1;
int iy = (int)((pos(1) - fmod(pos(1), this->dx)) / this->dx) + 1;
Expand Down
2 changes: 1 addition & 1 deletion classes/sph0/louis/src_cpp/Sorter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Sorter
std::vector<std::vector<Particle *>> cells;

public:
Sorter(Model &m);
explicit Sorter(Model &m);

void execute();

Expand Down

0 comments on commit 8f735f6

Please sign in to comment.