Skip to content

Commit

Permalink
Correct code smells
Browse files Browse the repository at this point in the history
Signed-off-by: Le Courtois Florent <[email protected]>
  • Loading branch information
Le Courtois Florent committed Mar 9, 2021
1 parent ebb4f56 commit aab0463
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
12 changes: 5 additions & 7 deletions metrix-simulator/src/calculecrirecontraintesdodu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,8 @@ double Calculer::transitSurQuad(const std::shared_ptr<Quadripole>& quad,

double puissance = 0.;
int numQuadSurveille = quad->num_;
int i_q;
int i_p;

for (i_q = 0; i_q < icdt->nbLignes_; ++i_q) {
for (int i_q = 0; i_q < icdt->nbLignes_; ++i_q) {
auto& quad2 = icdt->listeQuads_[i_q];
// verification sur la presence du quad dans l'incident
if (quad2->num_ == quad->num_) {
Expand All @@ -1991,7 +1989,7 @@ double Calculer::transitSurQuad(const std::shared_ptr<Quadripole>& quad,
variationTranSurIncident += puissance * icdt->rho_[i_q][numQuadSurveille];
}

for (i_q = 0; i_q < icdt->nbCouplagesFermes_; ++i_q) {
for (int i_q = 0; i_q < icdt->nbCouplagesFermes_; ++i_q) {
auto& quad2 = icdt->listeCouplagesFermes_[i_q];
// verification sur la presence du quad dans l'incident
puissance = quad2->u2Yij_ * (theta[quad2->norqua_->num_] - theta[quad2->nexqua_->num_]);
Expand All @@ -2000,7 +1998,7 @@ double Calculer::transitSurQuad(const std::shared_ptr<Quadripole>& quad,

if (icdt->nbGroupes_ >= 1) {
int nbQuadsInc = icdt->nbLignes_ + icdt->nbCouplagesFermes_;
for (i_p = 0; i_p < icdt->nbGroupes_; ++i_p) {
for (int i_p = 0; i_p < icdt->nbGroupes_; ++i_p) {
auto& grpe = icdt->listeGroupes_[i_p];
if (!grpe->etat_) {
continue;
Expand Down Expand Up @@ -2029,7 +2027,7 @@ double Calculer::transitSurQuad(const std::shared_ptr<Quadripole>& quad,
}

if (icdt->nbLccs_ >= 1) {
for (i_q = 0; i_q < icdt->nbLccs_; ++i_q) { // ATTENTION AU SIGNE -
for (int i_q = 0; i_q < icdt->nbLccs_; ++i_q) { // ATTENTION AU SIGNE -
auto& hvdc = icdt->listeLccs_[i_q];
if (!hvdc->connecte()) {
continue;
Expand All @@ -2045,7 +2043,7 @@ double Calculer::transitSurQuad(const std::shared_ptr<Quadripole>& quad,
}

// Annulation de l'action des TD fictifs en N
for (i_p = 0; i_p < res_.nbCCEmulAC_; ++i_p) {
for (int i_p = 0; i_p < res_.nbCCEmulAC_; ++i_p) {
double varPuiss = 0.;

auto& tdfictif = res_.TDFictifs_[i_p];
Expand Down
2 changes: 1 addition & 1 deletion metrix-simulator/src/cte.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::string c_fmt(const char* format, Args... args)
std::array<char, max> buf;
buf.fill('\0');

sprintf(buf.data(), format, args...);
snprintf(buf.data(), max, format, args...);

return std::string(buf.data());
}
Expand Down
2 changes: 1 addition & 1 deletion metrix-simulator/src/metrix2assess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ bool Calculer::calculVariationsMarginales(FILE* fr,
continue;
}
string nom;
int numIncident;
int numIncident = -1;
std::tie(nom, numIncident, std::ignore) = (*opt_inc);
double costVal = (config::configuration().redispatchCostOffset() > 0)
? std::accumulate(cost[i].begin(),
Expand Down
43 changes: 20 additions & 23 deletions metrix-simulator/src/reseau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ void Reseau::update_with_configuration()
//--------------------
void Reseau::lireDonnees()
{
unsigned int i;

auto& config = config::configuration();

update_with_configuration();
Expand All @@ -169,7 +167,7 @@ void Reseau::lireDonnees()

// Traitement des noeuds
//----------------------
for (i = 0; i < static_cast<unsigned int>(nbNoeuds_); ++i) {
for (int i = 0; i < nbNoeuds_; ++i) {
auto noeud = std::make_shared<Noeud>(i, config.cpposregDIE()[i] - 1);
noeuds_[i] = noeud;
noeud->typeNoeud_ = Noeud::NOEUD_REEL;
Expand All @@ -181,7 +179,7 @@ void Reseau::lireDonnees()

vector<std::shared_ptr<Quadripole>> quadsParIndice;
quadsParIndice.reserve(nbQuads_);
for (i = 0; i < static_cast<unsigned int>(nbQuads_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbQuads_); ++i) {
nomQuadripole = config.cqnomquaDIE()[i];
rtrim(nomQuadripole);
if (i >= config.tnnorquaDIE().size() || i >= config.tnnexquaDIE().size() || config.tnnorquaDIE()[i] == 0
Expand Down Expand Up @@ -264,7 +262,7 @@ void Reseau::lireDonnees()
nbNoeuds_ = nbNoeuds_ + nbTd_;
noeuds_.resize(nbNoeuds_);

for (i = 0; i < static_cast<unsigned int>(nbTd_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbTd_); ++i) {
auto quadVrai = quadsParIndice[config.dttrdequDIE()[i] - 1];
auto typeP = static_cast<TransformateurDephaseur::TypePilotageTD>(config.dtmodregDIE()[i]);

Expand Down Expand Up @@ -343,7 +341,7 @@ void Reseau::lireDonnees()
noeuds_.resize(nbNoeuds_ + nbCCEmulAC_);
}

for (i = 0; i < static_cast<unsigned int>(nbCC_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbCC_); ++i) {
auto& nor = noeuds_[config.dcnorquaDIE()[i] - 1];
auto& nex = noeuds_[config.dcnexquaDIE()[i] - 1];
string nom = config.dcnomquaDIE()[i];
Expand Down Expand Up @@ -498,7 +496,7 @@ void Reseau::lireDonnees()
//----------------------

// Types des groupes
for (i = 0; i < static_cast<unsigned int>(nbTypesGroupes_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbTypesGroupes_); ++i) {
string typeGroupe = config.trnomtypDIE()[i];
rtrim(typeGroupe);
typesGroupes_.push_back(typeGroupe);
Expand All @@ -508,12 +506,11 @@ void Reseau::lireDonnees()
nbVarGroupes_ = 0;
double sumMaxGroupes = 0.0;
DBandeRegGlobale_ = 0;
std::shared_ptr<Groupe> prod;
cptPtIncident = 0;
vector<std::shared_ptr<Groupe>> groupesParIndice;
groupesParIndice.reserve(nbGroupes_);

for (i = 0; i < static_cast<unsigned int>(nbGroupes_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbGroupes_); ++i) {
nomGroupe = config.trnomgthDIE()[i];
rtrim(nomGroupe);
if (i >= config.tnneurgtDIE().size() || config.tnneurgtDIE()[i] == 0 || config.tnneurgtDIE()[i] > nbNoeuds_) {
Expand Down Expand Up @@ -597,7 +594,7 @@ void Reseau::lireDonnees()
string nomConso;
vector<std::shared_ptr<Consommation>> consommationsParIndice;
consommationsParIndice.reserve(nbConsos_);
for (i = 0; i < static_cast<unsigned int>(nbConsos_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbConsos_); ++i) {
nomConso = config.tnnomnoeDIE()[i];
rtrim(nomConso);

Expand Down Expand Up @@ -722,7 +719,7 @@ void Reseau::lireDonnees()
int nbIncValides = 0;

incidentsEtParades_.reserve(nbIncidents_);
for (i = 0; i < static_cast<unsigned int>(nbIncidents_); ++i) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nbIncidents_); ++i) {
auto icdt = std::make_shared<Incident>(Incident::INCONNU);
icdt->num_ = i;
icdt->nbLignes_ = 0;
Expand Down Expand Up @@ -2699,11 +2696,11 @@ void Reseau::updateBase(const config::VariantConfiguration::VariantConfig& confi
}
}

for (auto& td : config.tdPhasing) {
const auto& str = std::get<VariantConfiguration::NAME>(td);
for (auto& tdPhasing : config.tdPhasing) {
const auto& str = std::get<VariantConfiguration::NAME>(tdPhasing);
auto tdIt = TransfoDephaseurs_.find(str);
if (tdIt != TransfoDephaseurs_.end()) {
auto var_int = std::get<VariantConfiguration::VALUE>(td);
auto var_int = std::get<VariantConfiguration::VALUE>(tdPhasing);
auto& td = tdIt->second;
if (!td->tapdepha_.empty() && (var_int >= td->lowtap_) && (var_int < td->lowtap_ + td->nbtap_)) {
td->puiConsBase_ = td->angle2Power(td->tapdepha_[var_int - td->lowtap_]);
Expand Down Expand Up @@ -2946,11 +2943,11 @@ void Reseau::updateVariant(MapQuadinVar& mapping, const config::VariantConfigura
}
}

for (auto& td : config.tdPhasing) {
const auto& str = std::get<VariantConfiguration::NAME>(td);
for (auto& tdPhasing : config.tdPhasing) {
const auto& str = std::get<VariantConfiguration::NAME>(tdPhasing);
auto tdIt = TransfoDephaseurs_.find(str);
if (tdIt != TransfoDephaseurs_.end()) {
auto var_int = std::get<VariantConfiguration::VALUE>(td);
auto var_int = std::get<VariantConfiguration::VALUE>(tdPhasing);
auto& td = tdIt->second;
if (!td->tapdepha_.empty() && (var_int >= td->lowtap_) && (var_int < td->lowtap_ + td->nbtap_)) {
auto power = td->angle2Power(td->tapdepha_[var_int - td->lowtap_]);
Expand All @@ -2963,13 +2960,13 @@ void Reseau::updateVariant(MapQuadinVar& mapping, const config::VariantConfigura
}

for (auto& threshold : config.tresholds) {
for (auto quad_cfg : threshold.second) {
for (const auto& quad_cfg : threshold.second) {
const auto& str = std::get<VariantConfiguration::NAME>(quad_cfg);
auto& mapping = (threshold.first == VariantConfiguration::VariantConfig::Threshold::MAX_N)
? elementsASurveillerN_
: elementsASurveillerNk_;
auto quadSurvIt = mapping.find(str);
if (quadSurvIt != mapping.end()) {
auto& map = (threshold.first == VariantConfiguration::VariantConfig::Threshold::MAX_N)
? elementsASurveillerN_
: elementsASurveillerNk_;
auto quadSurvIt = map.find(str);
if (quadSurvIt != map.end()) {
auto& quad = quadSurvIt->second;
auto var_dbl = std::get<VariantConfiguration::VALUE>(quad_cfg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38368,4 +38368,4 @@ Noeud '42248 [CONSO_BJMH]' est hors composante connexe principale (composante 23
Noeud '42249 [CONSO_BJMI]' est hors composante connexe principale (composante 2310)
Noeud '42250 [CONSO_BJMJ]' est hors composante connexe principale (composante 2310)
Noeud '42251 [CONSO_BJMK]' est hors composante connexe principale (composante 2310)
Not recoverable error: Réseau non connexe (file=reseau.cpp ,line=665)
Not recoverable error: Réseau non connexe (file=reseau.cpp ,line=662)

0 comments on commit aab0463

Please sign in to comment.