void DMMainWindow::createModuleListView() 
{
	ui->treeWidget->clear();
	// load the module tree: first map element represents the group name as string
	// second the names of the modules as string
	std::map<std::string, std::vector<std::string> > mMap (this->simulation->getModuleRegistry()->getModuleMap());
	std::map<std::string, std::string> mDisplayNames (this->simulation->getModuleRegistry()->getDisplayNames());
	ui->treeWidget->setColumnCount(1);
	// iterate through groups
	for (std::map<std::string, std::vector<std::string> >::iterator it = mMap.begin(); it != mMap.end(); ++it) 
	{
		// create tree group
		QTreeWidgetItem * items = new QTreeWidgetItem(ui->treeWidget);
		items->setText(0, QString::fromStdString(it->first));
		// get modules, sort alphabetically
		std::vector<std::string> moduleNames = it->second;
		std::sort(moduleNames.begin(), moduleNames.end());
		// iterate through modules
		foreach(std::string name, moduleNames) 
		{
			QTreeWidgetItem * item;
			item = new QTreeWidgetItem(items);
			item->setText(0,QString::fromStdString(mDisplayNames[name]));
			item->setText(2,QString::fromStdString(name));
			item->setText(1,"Module");
		}
	}
void GameObject::mUpdate(ID3D11DeviceContext *dc ,  std::vector<std::vector<RenderData*>> data)
{
	this->iNrOfinstances = 0;
	D3D11_MAPPED_SUBRESOURCE *mappedData = mMap(dc, this->pInstanceBuffer);

	POINTLIGHTINSTANCE *instance = reinterpret_cast<POINTLIGHTINSTANCE*>(mappedData->pData);

	for(int j = 0; j < (int)data.size(); j++)
	{
		for(int i = 0; i < (int)data[j].size(); i++)
		{
			if(data[j][i]->lightID != LIGHT_NONE)
			{
				instance[i + this->iNrOfinstances].fLightRadius     = 12;
				instance[i + this->iNrOfinstances].vLightColor      = Vec3(1, 1, 1);
				instance[i + this->iNrOfinstances].vLightPosition = Vec3(data[j][i]->worldMat._14,  data[j][i]->worldMat._24 +8, data[j][i]->worldMat._34);

				if( j == ENTITY_NODE_GREEN)
				{
					instance[i + this->iNrOfinstances].fLightRadius     = 10;
					instance[i + this->iNrOfinstances].vLightPosition.y = 9;
					if(data[j][i]->textureID == 0)
						instance[i + this->iNrOfinstances].vLightColor = Vec3(0, 1, 0);
					else if(data[j][i]->textureID == 1)
						instance[i + this->iNrOfinstances].vLightColor = Vec3(1, 0, 0);
					else
						instance[i + this->iNrOfinstances].vLightColor = Vec3(1, 1, 0);

					instance[i + this->iNrOfinstances].vLightPosition.x -= 0;
				}
				else if( j == ENTITY_ENEMY)
				{
					instance[i + this->iNrOfinstances].vLightColor = Vec3(1, 0 ,0);
				}
				else if(j == ENTITY_SPIRALSPHERE || j == ENTITY_NEUTRALGATE || j == ENTITY_PYRAMID)
				{
					instance[i + this->iNrOfinstances].fLightRadius     = 15;
					instance[i + this->iNrOfinstances].vLightPosition.y = 11;
					instance[i + this->iNrOfinstances].vLightPosition.x += 2;
				}
				else if(j == ENTITY_UPGRADE_OFFENSE || j == ENTITY_UPGRADE_DEFENSE || j == ENTITY_UPGRADE_RES)
				{
					instance[i + this->iNrOfinstances].fLightRadius     = 15;
					instance[i + this->iNrOfinstances].vLightPosition.y = 7;
					instance[i + this->iNrOfinstances].vLightPosition.x += 2;
				}
			}
			else
			{
				this->iNrOfinstances--;
			}
		}
		this->iNrOfinstances += data[j].size();
	}

	mUnmap(dc , this->pInstanceBuffer);
}
void GameObject::mUpdate(ID3D11DeviceContext *dc, GUI_Panel* data, int nrOfInstances)
{
	D3D11_MAPPED_SUBRESOURCE *mappedData = mMap(dc, this->pInstanceBuffer);

	INSTANCEDATA *mesh = reinterpret_cast<INSTANCEDATA*>(mappedData->pData);

	for(int j = 0; j < (int)nrOfInstances; j++)
	{
		mesh[j].mWorld = data[j].matrix;
		mesh[j].iTextureID = data[j].textureID;
	}
	this->iNrOfinstances = nrOfInstances;

	mUnmap(dc, this->pInstanceBuffer);
}
void GameObject::mUpdate(ID3D11DeviceContext *dc , std::vector<HPBarInfo>& data)
{
	D3D11_MAPPED_SUBRESOURCE *mappedData = mMap(dc, this->pInstanceBuffer);

	MatrixInstance *mesh = reinterpret_cast<MatrixInstance*>(mappedData->pData);

	Matrix scale;
	for(int j = 0; j < (int)data.size(); j++)
	{
		D3DXMatrixScaling(&scale, data[j].hpPercent * 3, 0.2f, 1.0f);
		mesh[j].world = scale * data[j].translate;
	}

	this->iNrOfinstances = data.size();

	mUnmap(dc, this->pInstanceBuffer);
}
///////////////////////////////////////////
//methods for updating content in buffers//
///////////////////////////////////////////
void GameObject::mUpdate(ID3D11DeviceContext *dc, std::vector<RenderData*> data)
{
	D3D11_MAPPED_SUBRESOURCE *mappedData = mMap(dc, this->pInstanceBuffer);

	INSTANCEDATA *instance = reinterpret_cast<INSTANCEDATA*>(mappedData->pData);

	for(int i = 0; i < (int)data.size(); i++)
	{
		data[i]->worldMat._14 = 0;
		data[i]->worldMat._24 = 0;
		data[i]->worldMat._34 = 0;
		instance[i].mWorld     = data[i]->worldMat;
		instance[i].iTextureID = data[i]->textureID;
	}

	this->iNrOfinstances = data.size();

	mUnmap(dc , this->pInstanceBuffer);
}
void GameObject::mUpdate(ID3D11DeviceContext *dc, std::vector<std::vector<MESH_PNC>> data)
{
	this->iNrOfVertices = 0;

	D3D11_MAPPED_SUBRESOURCE *mappedData = mMap(dc, this->pVertexBuffer);

	MESH_PNC *mesh = reinterpret_cast<MESH_PNC*>(mappedData->pData);

	for(int j = 0; j < (int)data.size(); j++)
	{
		for(int i = 0; i < (int)data[j].size(); i++)
		{
			mesh[i + this->iNrOfVertices].pos     = data[j][i].pos;
			mesh[i + this->iNrOfVertices].normal  = data[j][i].normal;
			mesh[i + this->iNrOfVertices].color   = data[j][i].color;
		}

		this->iNrOfVertices += data[j].size();
	}

	mUnmap(dc, this->pVertexBuffer);
}
Exemple #7
0
/**
 * Execute the iterative solve portion of the application using a
 * hand-coded Newton-Raphson solver
 * @return false if an error was encountered in the solution
 */
bool gridpack::powerflow::PFAppModule::solve()
{
  bool ret = true;
  gridpack::utility::CoarseTimer *timer =
    gridpack::utility::CoarseTimer::instance();
  int t_total = timer->createCategory("Powerflow: Total Application");
  timer->start(t_total);

  // set YBus components so that you can create Y matrix
  int t_fact = timer->createCategory("Powerflow: Factory Operations");
  timer->start(t_fact);
  p_factory->setYBus();
  timer->stop(t_fact);

  int t_cmap = timer->createCategory("Powerflow: Create Mappers");
  timer->start(t_cmap);
  p_factory->setMode(YBus); 
#if 0
  gridpack::mapper::FullMatrixMap<PFNetwork> mMap(p_network);
#endif
  timer->stop(t_cmap);
  int t_mmap = timer->createCategory("Powerflow: Map to Matrix");
  timer->start(t_mmap);
#if 0
  boost::shared_ptr<gridpack::math::Matrix> Y = mMap.mapToMatrix();
  p_busIO->header("\nY-matrix values\n");
  Y->print();
//  Y->save("Ybus.m");
#endif
  timer->stop(t_mmap);

  timer->start(t_fact);
  p_factory->setMode(S_Cal);
  timer->stop(t_fact);
  timer->start(t_cmap);
  gridpack::mapper::BusVectorMap<PFNetwork> vvMap(p_network);
  timer->stop(t_cmap);
  int t_vmap = timer->createCategory("Powerflow: Map to Vector");

  // make Sbus components to create S vector
  timer->start(t_fact);
  p_factory->setSBus();
  timer->stop(t_fact);
//  p_busIO->header("\nIteration 0\n");

  // Set PQ
  timer->start(t_cmap);
  p_factory->setMode(RHS); 
  gridpack::mapper::BusVectorMap<PFNetwork> vMap(p_network);
  timer->stop(t_cmap);
  timer->start(t_vmap);
#ifdef USE_REAL_VALUES
  boost::shared_ptr<gridpack::math::RealVector> PQ = vMap.mapToRealVector();
#else
  boost::shared_ptr<gridpack::math::Vector> PQ = vMap.mapToVector();
#endif
  timer->stop(t_vmap);
//  PQ->print();
  timer->start(t_cmap);
  p_factory->setMode(Jacobian);
  gridpack::mapper::FullMatrixMap<PFNetwork> jMap(p_network);
  timer->stop(t_cmap);
  timer->start(t_mmap);
#ifdef USE_REAL_VALUES
  boost::shared_ptr<gridpack::math::RealMatrix> J = jMap.mapToRealMatrix();
#else
  boost::shared_ptr<gridpack::math::Matrix> J = jMap.mapToMatrix();
#endif
  timer->stop(t_mmap);
//  p_busIO->header("\nJacobian values\n");
//  J->print();

  // Create X vector by cloning PQ
#ifdef USE_REAL_VALUES
  boost::shared_ptr<gridpack::math::RealVector> X(PQ->clone());
#else
  boost::shared_ptr<gridpack::math::Vector> X(PQ->clone());
#endif

  gridpack::utility::Configuration::CursorPtr cursor;
  cursor = p_config->getCursor("Configuration.Powerflow");
  // Create linear solver
  int t_csolv = timer->createCategory("Powerflow: Create Linear Solver");
  timer->start(t_csolv);
#ifdef USE_REAL_VALUES
  gridpack::math::RealLinearSolver solver(*J);
#else
  gridpack::math::LinearSolver solver(*J);
#endif
  solver.configure(cursor);
  timer->stop(t_csolv);

  gridpack::ComplexType tol = 2.0*p_tolerance;
  int iter = 0;

  // First iteration
  X->zero(); //might not need to do this
  //p_busIO->header("\nCalling solver\n");
  int t_lsolv = timer->createCategory("Powerflow: Solve Linear Equation");
  timer->start(t_lsolv);
//    char dbgfile[32];
//    sprintf(dbgfile,"j0.bin");
//    J->saveBinary(dbgfile);
//    sprintf(dbgfile,"pq0.bin");
//    PQ->saveBinary(dbgfile);
  try {
    solver.solve(*PQ, *X);
  } catch (const gridpack::Exception e) {
    p_busIO->header("Solver failure\n\n");
    timer->stop(t_lsolv);
    return false;
  }
  timer->stop(t_lsolv);
  tol = PQ->normInfinity();

  // Create timer for map to bus
  int t_bmap = timer->createCategory("Powerflow: Map to Bus");
  int t_updt = timer->createCategory("Powerflow: Bus Update");
  char ioBuf[128];

  while (real(tol) > p_tolerance && iter < p_max_iteration) {
    // Push current values in X vector back into network components
    // Need to implement setValues method in PFBus class in order for this to
    // work
    timer->start(t_bmap);
    p_factory->setMode(RHS);
    vMap.mapToBus(X);
    timer->stop(t_bmap);

    // Exchange data between ghost buses (I don't think we need to exchange data
    // between branches)
    timer->start(t_updt);
    p_network->updateBuses();
    timer->stop(t_updt);

    // Create new versions of Jacobian and PQ vector
    timer->start(t_vmap);
#ifdef USE_REAL_VALUES
    vMap.mapToRealVector(PQ);
#else
    vMap.mapToVector(PQ);
#endif
//    p_busIO->header("\nnew PQ vector\n");
//    PQ->print();
    timer->stop(t_vmap);
    timer->start(t_mmap);
    p_factory->setMode(Jacobian);
#ifdef USE_REAL_VALUES
    jMap.mapToRealMatrix(J);
#else
    jMap.mapToMatrix(J);
#endif
    timer->stop(t_mmap);

    // Create linear solver
    timer->start(t_lsolv);
    X->zero(); //might not need to do this
//    sprintf(dbgfile,"j%d.bin",iter+1);
//    J->saveBinary(dbgfile);
//    sprintf(dbgfile,"pq%d.bin",iter+1);
//    PQ->saveBinary(dbgfile);
    try {
      solver.solve(*PQ, *X);
    } catch (const gridpack::Exception e) {
      p_busIO->header("Solver failure\n\n");
      timer->stop(t_lsolv);
      return false;
    }
    timer->stop(t_lsolv);

    tol = PQ->normInfinity();
    sprintf(ioBuf,"\nIteration %d Tol: %12.6e\n",iter+1,real(tol));
    p_busIO->header(ioBuf);
    iter++;
  }

  if (iter >= p_max_iteration) ret = false;

  // Push final result back onto buses
  timer->start(t_bmap);
  p_factory->setMode(RHS);
  vMap.mapToBus(X);
  timer->stop(t_bmap);

  // Make sure that ghost buses have up-to-date values before printing out
  // results
  timer->start(t_updt);
  p_network->updateBuses();
  timer->stop(t_updt);
  timer->stop(t_total);
  return ret;
}