<commit_before>
#include "cmbNucCore.h"
#include "inpFileIO.h"

#include <iostream>
#include <algorithm>
#include <fstream>
#include <limits>
#include <set>

#include "cmbNucAssembly.h"

#include "vtkTransform.h"
#include "vtkInformation.h"
#include "vtkNew.h"
#include "vtkTransformFilter.h"
#include "vtkMath.h"
#include "cmbNucDefaults.h"

#include <QFileInfo>
#include <QDateTime>
#include <QDir>
#include <QDebug>

void cmbNucCoreConnection::dataChanged()
{
  v->setAndTestDiffFromFiles(true);
  emit dataChangedSig();
}

void cmbNucCoreConnection::assemblyChanged()
{
  v->checkUsedAssembliesForGen();
  emit dataChangedSig();
}

cmbNucCore::cmbNucCore(bool needSaved)
{
  this->Data = vtkSmartPointer<vtkMultiBlockDataSet>::New();
  this->AssyemblyPitchX = this->AssyemblyPitchY = 23.5;
  this->HexSymmetry = 1;
  DifferentFromFile = needSaved;
  DifferentFromH5M = true;
  this->Connection = new cmbNucCoreConnection();
  this->Connection->v = this;
}

cmbNucCore::~cmbNucCore()
{
  for(std::vector<cmbNucAssembly*>::iterator fit=this->Assemblies.begin();
    fit!=this->Assemblies.end(); ++fit)
    {
    if(*fit)
      {
      delete *fit;
      }
    }
  this->Assemblies.clear();
  delete this->Defaults;
  delete this->Connection;
}

void cmbNucCore::SetDimensions(int i, int j)
{
  this->CoreLattice.SetDimensions(i, j);
}

void cmbNucCore::clearExceptAssembliesAndGeom()
{
  this->Data = vtkSmartPointer<vtkMultiBlockDataSet>::New();
  this->CoreLattice.SetDimensions(1, 1, true);
  this->setAndTestDiffFromFiles(true);
  FileName = "";
  h5mFile = "";
  Params.clear();
}

void cmbNucCore::AddAssembly(cmbNucAssembly *assembly)
{
    if(this->Assemblies.size()==0)
    {
    if(assembly)
      {
      this->CoreLattice.SetGeometryType(
        assembly->AssyLattice.GetGeometryType());
      }
    this->SetDimensions(1, 1);
    }
  this->Assemblies.push_back(assembly);
  QObject::connect(assembly->GetConnection(), SIGNAL(dataChangedSig()),
                   this->Connection, SIGNAL(dataChangedSig()));
  QObject::connect(assembly->GetConnection(), SIGNAL(colorChanged()),
                   this->Connection, SIGNAL(colorChanged()));
  QObject::connect(assembly->GetConnection(), SIGNAL(dataChangedSig()),
                   this->Connection, SLOT(assemblyChanged()));
  if(this->Assemblies.size() == 1)
    {
    this->SetAssemblyLabel(0, 0, assembly->label, assembly->GetLegendColor());
    }
  // the new assembly need to be in the grid
}

void cmbNucCore::RemoveAssembly(const std::string &label)
{
  for(size_t i = 0; i < this->Assemblies.size(); i++)
    {
    if(this->Assemblies[i]->label == label)
      {
      delete this->Assemblies[i];
      this->Assemblies.erase(this->Assemblies.begin() + i);
      break;
      }
    }
  // update the Grid
  if(this->CoreLattice.ClearCell(label)) this->setAndTestDiffFromFiles(true);
}

cmbNucAssembly* cmbNucCore::GetAssembly(const std::string &label)
{
  for(size_t i = 0; i < this->Assemblies.size(); i++)
    {
    if(this->Assemblies[i]->label == label)
      {
      return this->Assemblies[i];
      }
    }

  return NULL;
}

cmbNucAssembly* cmbNucCore::GetAssembly(int idx)
{
  return idx<this->Assemblies.size() ? this->Assemblies[idx] : NULL;
}

std::vector< cmbNucAssembly* > cmbNucCore::GetUsedAssemblies()
{
  std::set<std::string> usedDict;
  for(size_t i = 0; i < this->CoreLattice.Grid.size(); i++)
    {
    for(size_t j = 0; j < this->CoreLattice.Grid[i].size(); j++)
      {
      usedDict.insert(this->CoreLattice.GetCell(i, j).label);
      }
    }
  std::vector< cmbNucAssembly* > result;
  for (unsigned int i = 0; i < this->Assemblies.size(); ++i)
    {
    if(this->Assemblies[i]!=NULL &&
       usedDict.find(this->Assemblies[i]->label) != usedDict.end())
      {
      result.push_back(Assemblies[i]);
      }
    }
  return result;
}

vtkSmartPointer<vtkMultiBlockDataSet> cmbNucCore::GetData()
{
  if(this->Assemblies.size()==0 || this->CoreLattice.Grid.size()==0
    || this->CoreLattice.Grid[0].size()==0)
    {
    return NULL;
    }
  // we need at least one duct
  if(Assemblies[0]->AssyDuct.numberOfDucts()==0)
    {
    return NULL;
    }
  int subType = this->CoreLattice.GetGeometrySubType();

  double startX = this->Assemblies[0]->AssyDuct.getDuct(0)->x;
  double startY = this->Assemblies[0]->AssyDuct.getDuct(0)->y;
  double outerDuctWidth = this->Assemblies[0]->AssyDuct.getDuct(0)->thickness[1];
  double outerDuctHeight = this->Assemblies[0]->AssyDuct.getDuct(0)->thickness[0];
  double extraXTrans = 0, extraYTrans = 0;

  // Is this Hex type?
  bool isHex = Assemblies[0]->AssyLattice.GetGeometryType() == HEXAGONAL;


  // setup data
  size_t numBlocks = isHex ?
    (1 + 3*(int)this->CoreLattice.Grid.size()*((int)this->CoreLattice.Grid.size() - 1)) :
    this->CoreLattice.Grid.size()*this->CoreLattice.Grid[0].size();

  this->Data->SetNumberOfBlocks(numBlocks);

  if( subType & ANGLE_360 && this->CoreLattice.Grid.size()>1 )
  {
    double odc = outerDuctHeight*this->CoreLattice.Grid.size();<commit_msg>fix a bug with the rect core bug<commit_after>
#include "cmbNucCore.h"
#include "inpFileIO.h"

#include <iostream>
#include <algorithm>
#include <fstream>
#include <limits>
#include <set>

#include "cmbNucAssembly.h"

#include "vtkTransform.h"
#include "vtkInformation.h"
#include "vtkNew.h"
#include "vtkTransformFilter.h"
#include "vtkMath.h"
#include "cmbNucDefaults.h"

#include <QFileInfo>
#include <QDateTime>
#include <QDir>
#include <QDebug>

void cmbNucCoreConnection::dataChanged()
{
  v->setAndTestDiffFromFiles(true);
  emit dataChangedSig();
}

void cmbNucCoreConnection::assemblyChanged()
{
  v->checkUsedAssembliesForGen();
  emit dataChangedSig();
}

cmbNucCore::cmbNucCore(bool needSaved)
{
  this->Data = vtkSmartPointer<vtkMultiBlockDataSet>::New();
  this->AssyemblyPitchX = this->AssyemblyPitchY = 23.5;
  this->HexSymmetry = 1;
  DifferentFromFile = needSaved;
  DifferentFromH5M = true;
  this->Connection = new cmbNucCoreConnection();
  this->Connection->v = this;
}

cmbNucCore::~cmbNucCore()
{
  for(std::vector<cmbNucAssembly*>::iterator fit=this->Assemblies.begin();
    fit!=this->Assemblies.end(); ++fit)
    {
    if(*fit)
      {
      delete *fit;
      }
    }
  this->Assemblies.clear();
  delete this->Defaults;
  delete this->Connection;
}

void cmbNucCore::SetDimensions(int i, int j)
{
  this->CoreLattice.SetDimensions(i, j);
}

void cmbNucCore::clearExceptAssembliesAndGeom()
{
  this->Data = vtkSmartPointer<vtkMultiBlockDataSet>::New();
  this->CoreLattice.SetDimensions(1, 1, true);
  this->setAndTestDiffFromFiles(true);
  FileName = "";
  h5mFile = "";
  Params.clear();
}

void cmbNucCore::AddAssembly(cmbNucAssembly *assembly)
{
    if(this->Assemblies.size()==0)
    {
    if(assembly)
      {
      this->CoreLattice.SetGeometryType(
        assembly->AssyLattice.GetGeometryType());
      }
    this->SetDimensions(1, 1);
    }
  this->Assemblies.push_back(assembly);
  QObject::connect(assembly->GetConnection(), SIGNAL(dataChangedSig()),
                   this->Connection, SIGNAL(dataChangedSig()));
  QObject::connect(assembly->GetConnection(), SIGNAL(colorChanged()),
                   this->Connection, SIGNAL(colorChanged()));
  QObject::connect(assembly->GetConnection(), SIGNAL(dataChangedSig()),
                   this->Connection, SLOT(assemblyChanged()));
  if(this->Assemblies.size() == 1)
    {
    this->SetAssemblyLabel(0, 0, assembly->label, assembly->GetLegendColor());
    }
  // the new assembly need to be in the grid
}

void cmbNucCore::RemoveAssembly(const std::string &label)
{
  for(size_t i = 0; i < this->Assemblies.size(); i++)
    {
    if(this->Assemblies[i]->label == label)
      {
      delete this->Assemblies[i];
      this->Assemblies.erase(this->Assemblies.begin() + i);
      break;
      }
    }
  // update the Grid
  if(this->CoreLattice.ClearCell(label)) this->setAndTestDiffFromFiles(true);
}

cmbNucAssembly* cmbNucCore::GetAssembly(const std::string &label)
{
  for(size_t i = 0; i < this->Assemblies.size(); i++)
    {
    if(this->Assemblies[i]->label == label)
      {
      return this->Assemblies[i];
      }
    }

  return NULL;
}

cmbNucAssembly* cmbNucCore::GetAssembly(int idx)
{
  return idx<this->Assemblies.size() ? this->Assemblies[idx] : NULL;
}

std::vector< cmbNucAssembly* > cmbNucCore::GetUsedAssemblies()
{
  std::set<std::string> usedDict;
  for(size_t i = 0; i < this->CoreLattice.Grid.size(); i++)
    {
    for(size_t j = 0; j < this->CoreLattice.Grid[i].size(); j++)
      {
      usedDict.insert(this->CoreLattice.GetCell(i, j).label);
      }
    }
  std::vector< cmbNucAssembly* > result;
  for (unsigned int i = 0; i < this->Assemblies.size(); ++i)
    {
    if(this->Assemblies[i]!=NULL &&
       usedDict.find(this->Assemblies[i]->label) != usedDict.end())
      {
      result.push_back(Assemblies[i]);
      }
    }
  return result;
}

vtkSmartPointer<vtkMultiBlockDataSet> cmbNucCore::GetData()
{
  if(this->Assemblies.size()==0 || this->CoreLattice.Grid.size()==0
    || this->CoreLattice.Grid[0].size()==0)
    {
    return NULL;
    }
  // we need at least one duct
  if(Assemblies[0]->AssyDuct.numberOfDucts()==0)
    {
    return NULL;
    }
  int subType = this->CoreLattice.GetGeometrySubType();

  double startX = this->Assemblies[0]->AssyDuct.getDuct(0)->x;
  double startY = this->Assemblies[0]->AssyDuct.getDuct(0)->y;
  double outerDuctWidth = this->Assemblies[0]->AssyDuct.getDuct(0)->thickness[1];
  double outerDuctHeight = this->Assemblies[0]->AssyDuct.getDuct(0)->thickness[0];
  double extraXTrans = 0, extraYTrans = 0;

  // Is this Hex type?
  bool isHex = Assemblies[0]->AssyLattice.GetGeometryType() == HEXAGONAL;


  // setup data
  size_t numBlocks = isHex ?
    (1 + 3*(int)this->CoreLattice.Grid.size()*((int)this->CoreLattice.Grid.size() - 1)) :
    this->CoreLattice.Grid.size()*this->CoreLattice.Grid[0].size();

  this->Data->SetNumberOfBlocks(numBlocks);

  if( isHex && subType & ANGLE_360 && this->CoreLattice.Grid.size()>1 )
  {
    double odc = outerDuctHeight*this->CoreLattice.Grid.size();
{'fraction_non_alphanumeric': 0.16769078295341922, 'fraction_numerical': 0.009117938553022795, 'mean_word_length': 4.020398009950249, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 197, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5869180', 'n_tokens_mistral': 3767, 'n_tokens_neox': 3682, 'n_words': 557}