Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.16 KB | None | 0 0
  1. --- src/core/applications/conductorbundle.cpp
  2. +++ src/core/applications/conductorbundle.cpp
  3. @@ -53,7 +53,7 @@ void ConductorBundle::load(QSettings *settings)
  4.  {
  5.      Application::load(settings);
  6.  
  7. -    int documentIndex = settings->value("conductorSelectionDocumentId", -1).toInt();
  8. +    int documentIndex = settings->value("meteorologicalDataDocumentId", -1).toInt();
  9.      auto conn = std::make_shared<QMetaObject::Connection>();
  10.      *conn = m_project->connect(m_project, &Project::projectLoad, [this, documentIndex, conn]() {
  11.          m_project->disconnect(*conn);
  12. @@ -71,7 +71,6 @@ bool ConductorBundle::calculate(QString& error)
  13.  {
  14.      Application::calculate(error);
  15.  
  16. -
  17.      ElectricField *electricField = (ElectricField*)m_project->getApplication(Application::App_ElectricField);
  18.      if(!electricField->calculate(error))
  19.          return false;
  20. @@ -90,6 +89,11 @@ bool ConductorBundle::calculate(QString& error)
  21.          }
  22.      }
  23.  
  24. +    if(m_meteorologicalDataDocument.expired()) {
  25. +        error += tr("The 'Meteorological data' was not found.");
  26. +        return false;
  27. +    }
  28. +
  29.      return true;
  30.  }
  31.  
  32. --- src/core/applications/conductorbundle.h
  33. +++ src/core/applications/conductorbundle.h
  34. @@ -15,9 +15,9 @@ public:
  35.  
  36.      bool calculate(QString& error);
  37.  
  38. -    void setConductorSelectionDocument(const DocumentPtr& document) { m_meteorologicalDataDocument = document; }
  39. +    void setMeteorologicalDataDocument(const DocumentPtr& document) { m_meteorologicalDataDocument = document; }
  40.  
  41. -    DocumentPtr getConductorSelectionDocument() { return m_meteorologicalDataDocument.lock(); }
  42. +    DocumentPtr getMeteorologicalDataDocument() { return m_meteorologicalDataDocument.lock(); }
  43.  
  44.  private:
  45.      DocumentWeakPtr m_meteorologicalDataDocument;
  46. --- src/core/applications/substationparameters.cpp
  47. +++ src/core/applications/substationparameters.cpp
  48. @@ -3,6 +3,7 @@
  49.  #include <core/project.h>
  50.  #include <core/substation.h>
  51.  #include <core/transmissionline.h>
  52. +#include <core/groundingsystem.h>
  53.  #include <core/section.h>
  54.  #include <core/tower.h>
  55.  #include <iostream>
  56. @@ -61,6 +62,7 @@ bool SubstationParameters::calculate(QString& error)
  57.      ElectricParameters *el = (ElectricParameters*)m_project->getApplication(Application::App_ElectricParameters);
  58.  
  59.      // Calculate shield wires equivalent impedance for every configuration
  60. +
  61.      for(TransmissionLinePtr tl : m_project->getTransmissionLines()) {
  62.          for(Section *section : tl->getSections())
  63.              el->calculateLongitudinalParameters(section);
  64. @@ -85,6 +87,7 @@ bool SubstationParameters::calculate(QString& error)
  65.          if(substation->isIgnored())
  66.              continue;
  67.  
  68. +        std::complex<double> zeq = std::numeric_limits<double>::infinity();
  69.          for(TransmissionLinePtr tl : substation->getTransmissionLines()) {
  70.              bool reverse = tl->getFirstSubstation() == substation;
  71.  
  72. @@ -119,6 +122,81 @@ bool SubstationParameters::calculate(QString& error)
  73.                  tl->m_equivalentGroundImpedanceFirstSubstation = eqImpedance;
  74.              else
  75.                  tl->m_equivalentGroundImpedanceLastSubstation = eqImpedance;
  76. +
  77. +            zeq = math::parallelImpedance(zeq, eqImpedance);
  78. +        }
  79. +        qDebug() << "real:" << zeq.real() << "img:" << zeq.imag();
  80. +    }
  81. +
  82. +    //gs
  83. +    for(GroundingSystemPtr gs : m_project->getGroundingSystems()) {
  84. +        if(gs->isIgnored())
  85. +            continue;
  86. +
  87. +        int i, j;
  88. +        if(gs->canMergeConductors(i, j))
  89. +            m_project->onError(tr("Conductors %1 and %2 can be merged.\nA calculation error might happen if they are overlapping each other.\nIt's recommended to press 'Join' button on data input.").arg(i).arg(j));
  90. +
  91. +        bool hasResistance = false;
  92. +        for(int i = 0; i < 10; ++i) { // 10 tries to calculate resistance
  93. +            try {
  94. +                hasResistance = gs->calculateResistance(error);
  95. +                break;
  96. +            }
  97. +            catch(std::bad_alloc&) {
  98. +                double length = gs->getSegmentMaximumLength() * 2;
  99. +                m_project->onError(tr("Out of memory. New maximum segment length is %1.").arg(length));
  100. +                gs->setSegmentMaximumLength(QString::number(length));
  101. +            }
  102. +        }
  103. +
  104. +        if(!hasResistance)
  105. +            return false;
  106. +
  107. +        //Im = Zeq*ICC/(Rm + Zeq)
  108. +        //gs->setInjectedCurrent(im);
  109. +
  110. +        for(const Vector3Dd& point : gs->getSurfaceVoltagePoints())
  111. +            gs->getSurfaceVoltage(point);
  112. +
  113. +        double meshVoltage = gs->getResistance() * gs->getInjectedCurrent();
  114. +
  115. +        for(SurfaceVoltageProfile<Vector3Dd>& profile : gs->getSurfaceVoltageProfiles()) {
  116. +            Vector3Dd dir = (profile.pf - profile.pi).normalized();
  117. +
  118. +            profile.maxTouchVoltage = 0;
  119. +            profile.maxStepVoltage = 0;
  120. +
  121. +            double x0 = 0;
  122. +            double x1 = profile.pi.distanceTo(profile.pf);
  123. +            for(double x = x0; x <= x1; x += profile.precision) {
  124. +                Vector3Dd point = profile.pi + dir * x;
  125. +                double v = gs->getSurfaceVoltage(point);
  126. +
  127. +                double touchVoltage = std::abs(meshVoltage - v);
  128. +                if(touchVoltage > profile.maxTouchVoltage) {
  129. +                    profile.maxTouchVoltage = touchVoltage;
  130. +                    profile.maxTouchVoltagePos = point;
  131. +                }
  132. +            }
  133. +
  134. +            double stepSize = 1; // m
  135. +            x0 = -profile.stepSearchMargin;
  136. +            x1 = profile.pi.distanceTo(profile.pf) + profile.stepSearchMargin;
  137. +            for(double x = x0; x <= x1 - stepSize; x += profile.precision) {
  138. +                Vector3Dd point = profile.pi + dir * x;
  139. +                Vector3Dd pointStep = profile.pi + dir * (x + stepSize);
  140. +
  141. +                double v = gs->getSurfaceVoltage(point);
  142. +                double vStep = gs->getSurfaceVoltage(pointStep);
  143. +
  144. +                double stepVoltage = std::abs(vStep - v);
  145. +                if(stepVoltage > profile.maxStepVoltage) {
  146. +                    profile.maxStepVoltage = stepVoltage;
  147. +                    profile.maxStepVoltagePos1 = point;
  148. +                    profile.maxStepVoltagePos2 = pointStep;
  149. +                }
  150. +            }
  151.          }
  152.      }
  153.      return true;
  154. --- src/views/reportoptionsview.cpp
  155. +++ src/views/reportoptionsview.cpp
  156. @@ -26,6 +26,7 @@
  157.  #include <QCheckBox>
  158.  #include <QComboBox>
  159.  #include <QPushButton>
  160. +#include <QDebug>
  161.  
  162.  ReportOptionsView::ReportOptionsView(QWidget *parent) :
  163.      QScrollArea(parent)
  164. @@ -140,6 +141,8 @@ void ReportOptionsView::updateFromProject()
  165.          iterator.value()->setChecked(groundingSystem->isIgnored());
  166.      }
  167.  
  168. +    bool displayInputsChecked = g_project->getDisplayInput();
  169. +    bool displayTlChecked = g_project->getDisplayTransmissionLines();
  170.      m_displayInput->setChecked(g_project->getDisplayInput());
  171.      m_displayGroundingSystems->setChecked(g_project->getDisplayGroundingSystems());
  172.      m_displayPipelines->setChecked(g_project->getDisplayPipelines());
  173. @@ -148,6 +151,13 @@ void ReportOptionsView::updateFromProject()
  174.      m_displayCircuits->setChecked(g_project->getDisplayCircuits());
  175.      m_displayShieldWires->setChecked(g_project->getDisplayShieldWires());
  176.  
  177. +    m_displayGroundingSystems->setEnabled(displayInputsChecked);
  178. +    m_displayPipelines->setEnabled(displayInputsChecked);
  179. +    m_displaySubstations->setEnabled(displayInputsChecked);
  180. +    m_displayTransmissionLines->setEnabled(displayInputsChecked);
  181. +    m_displayCircuits->setEnabled(displayInputsChecked && displayTlChecked);
  182. +    m_displayShieldWires->setEnabled(displayInputsChecked && displayTlChecked);
  183. +
  184.      Application::ApplicationName app = g_project->getApplicationName();
  185.      if(app == Application::App_AtmosphericDischarges) {
  186.          AtmosphericDischarges *atmosphericDischarges = (AtmosphericDischarges*)g_project->getApplication(Application::App_AtmosphericDischarges);
  187. @@ -236,6 +246,8 @@ void ReportOptionsView::updateFromProject()
  188.          ElectricMagneticFields *emf = (ElectricMagneticFields*)g_project->getApplication(Application::App_DP_ElectricMagneticFields);
  189.          if(DocumentPtr doc = emf->getConductorSelectionDocument())
  190.              m_conductorSelectionDocument->setCurrentIndex(m_conductorSelectionDocument->findData(doc->getIndex()));
  191. +        else
  192. +            m_conductorSelectionDocument->setCurrentIndex(-1);
  193.      }
  194.      else if(app == Application::App_ConductorBundle) {
  195.          m_meteorologicalDataDocument->clear();
  196. @@ -243,8 +255,10 @@ void ReportOptionsView::updateFromProject()
  197.              m_meteorologicalDataDocument->addItem(document->getName(), document->getIndex());
  198.  
  199.          ConductorBundle *cb = (ConductorBundle*)g_project->getApplication(Application::App_ConductorBundle);
  200. -        if(DocumentPtr doc = cb->getConductorSelectionDocument())
  201. +        if(DocumentPtr doc = cb->getMeteorologicalDataDocument())
  202.              m_meteorologicalDataDocument->setCurrentIndex(m_meteorologicalDataDocument->findData(doc->getIndex()));
  203. +        else
  204. +            m_meteorologicalDataDocument->setCurrentIndex(-1);
  205.      }
  206.  }
  207.  
  208. @@ -368,11 +382,17 @@ void ReportOptionsView::updateToProject()
  209.      }
  210.      else if(app == Application::App_DP_ElectricMagneticFields) {
  211.          ElectricMagneticFields *emf = (ElectricMagneticFields*)g_project->getApplication(Application::App_DP_ElectricMagneticFields);
  212. +        if(m_conductorSelectionDocument->currentIndex() == -1)
  213. +            emf->setConductorSelectionDocument(nullptr);
  214. +        else
  215.              emf->setConductorSelectionDocument(g_project->getDocument(m_conductorSelectionDocument->currentData().toInt()));
  216.      }
  217.      else if(app == Application::App_ConductorBundle) {
  218.          ConductorBundle *cb = (ConductorBundle*)g_project->getApplication(Application::App_ConductorBundle);
  219. -        cb->setConductorSelectionDocument(g_project->getDocument(m_meteorologicalDataDocument->currentData().toInt()));
  220. +        if(m_meteorologicalDataDocument->currentIndex() == -1)
  221. +            cb->setMeteorologicalDataDocument(nullptr);
  222. +        else
  223. +            cb->setMeteorologicalDataDocument(g_project->getDocument(m_meteorologicalDataDocument->currentData().toInt()));
  224.      }
  225.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement