예제 #1
0
void TrustedConnectionCreatorintegration::test_external_op_puppet_nonexistant()
{
    // Dispatching a Talk external op from the creator, to the creator should
    // result in it being passed directly to the normal op dispatch,
    // shortcutting the world.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Entity * other = new Entity(compose("%1", m_id_counter), m_id_counter++);
    other->setType(m_creatorType);
    m_server->m_world.addEntity(other);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(compose("%1", m_id_counter++));

    m_connection->externalOperation(op, *m_connection);

    // Operation should be via world dispatch, as if it was from the Entity
    // we are puppeting.
    ASSERT_TRUE(m_Link_send_sent.isValid());
    ASSERT_EQUAL(m_Link_send_sent->getParents().front(),
                 "unseen");
    ASSERT_TRUE(!m_Link_send_sent->isDefaultTo());
    ASSERT_EQUAL(m_Link_send_sent->getTo(), m_creator->getId());
}
예제 #2
0
/* virtual */ void ComEditor::ExecuteCmd(Command* cmd) {
  if(!whiteboard()) 

    /* normal Unidraw command execution */
    OverlayEditor::ExecuteCmd(cmd);

  else {

    /* indirect command execution, all by script */
    std::ostrstream sbuf;
    boolean oldflag = OverlayScript::ptlist_parens();
    OverlayScript::ptlist_parens(false);
    switch (cmd->GetClassId()) {
    case PASTE_CMD:
      {
      boolean scripted = false;
      Clipboard* cb = cmd->GetClipboard();
      if (cb) {
	Iterator it;
	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
	  if (comp) {
	    Creator* creator = unidraw->GetCatalog()->GetCreator();
	    OverlayScript* scripter = (OverlayScript*)
	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
	    if (scripter) {
	      scripter->SetSubject(comp);
	      if (scripted) 
		sbuf << ';';
	      else 
		scripted = true;
	      boolean status = scripter->Definition(sbuf);
	      delete scripter;
	    }
	  }
	}
      }
      if (!scripted)
	sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
      sbuf.put('\0');
      cout << sbuf.str() << "\n";
      cout.flush();
      GetComTerp()->run(sbuf.str());
      delete cmd;
      }
      break;
    default:
      sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)";
      cmd->Execute();
      if (cmd->Reversible()) {
	cmd->Log();
      } else {
	delete cmd;
      }
      break;
    }
    OverlayScript::ptlist_parens(oldflag);
  }
}
예제 #3
0
파일: rewriter.cpp 프로젝트: itmm/myLisp
EPtr Rewriter::rewrite_pair(EPtr pair, Creator &creator) {
	if (pair) {
		EPtr new_car = rewrite(EPtr(Pair::car(pair), creator.collector()), creator);
		EPtr new_cdr = rewrite(EPtr(Pair::cdr(pair), creator.collector()), creator);
		if (Pair::car(pair) != new_car || Pair::cdr(pair) != new_cdr) {
			return creator.new_pair(new_car, new_cdr);
		}
	}
	return pair;
}
예제 #4
0
int _tmain(int argc, _TCHAR* argv[])
{
    //insert breakpoints and step through the code to see the flow of operation
    Creator* creator = new ConcreteCreator();
    creator->AnOperation();

    delete creator;

	return 0;
}
예제 #5
0
파일: Menu.cpp 프로젝트: ey6es/witgap
Button* Menu::addButton (const QString& label, const QMetaObject* metaObject,
    QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3,
    QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7,
    QGenericArgument val8, QGenericArgument val9)
{
    Creator* creator = new Creator(
        0, metaObject, val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
    Button* button = addButton(label, creator, SLOT(create()));
    creator->setParent(button);
    return button;
}
예제 #6
0
void TrustedConnectionCreatorintegration::test_external_op_puppet()
{
    // Dispatching a Talk external op from the creator, to the creator should
    // result in it being passed directly to the normal op dispatch,
    // shortcutting the world.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Entity * other = new Entity(compose("%1", m_id_counter), m_id_counter++);
    other->setType(m_creatorType);
    m_server->m_world.addEntity(other);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(other->getId());

    m_connection->externalOperation(op, *m_connection);

    // Operation should be via world dispatch, as if it was from the Entity
    // we are puppeting.
    ASSERT_TRUE(m_BaseWorld_message_called.isValid());
    ASSERT_EQUAL(m_BaseWorld_message_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_BaseWorld_message_called->isDefaultTo());
    ASSERT_EQUAL(m_BaseWorld_message_called->getTo(), other->getId());
    ASSERT_NOT_NULL(m_BaseWorld_message_called_from);
    ASSERT_EQUAL(m_BaseWorld_message_called_from, other);
}
예제 #7
0
void TrustedConnectionCreatorintegration::setup()
{
    m_Link_send_sent = 0;
    m_BaseWorld_message_called = 0;
    m_BaseWorld_message_called_from = 0;
    m_Entity_callOperation_called = 0;

    Entity * gw = new Entity(compose("%1", m_id_counter),
                             m_id_counter++);
    m_server = new ServerRouting(*new TestWorld(*gw),
                                 "dd7452be-0137-4664-b90e-77dfb395ac39",
                                 "a2feda8e-62e9-4ba0-95c4-09f92eda6a78",
                                 compose("%1", m_id_counter), m_id_counter++,
                                 compose("%1", m_id_counter), m_id_counter++);
    m_connection = new Connection(*(CommSocket*)0,
                                  *m_server,
                                  "25251955-7e8c-4043-8a5e-adfb8a1e76f7",
                                  compose("%1", m_id_counter), m_id_counter++);
    m_creator = new Creator(compose("%1", m_id_counter), m_id_counter++);
    m_creatorType = new TypeNode("test_avatar");
    m_creator->setType(m_creatorType);

    m_connection->addObject(m_creator);

    m_BaseWorld_message_called = 0;
    m_BaseWorld_message_called_from = 0;
}
예제 #8
0
int main(int argc,char* argv[])
{
	Creator *p = new ConcreateCreator();
	p->AnOperation();

	delete p;

	//system("pause");
	printf("Press any key to continue") ;
	struct termios te;
	int ch;
	tcgetattr( STDIN_FILENO, &te);
	te.c_lflag &= ~( ICANON | ECHO);
	tcsetattr(STDIN_FILENO, TCSANOW, &te);
	tcflush(STDIN_FILENO, TCIFLUSH);
	fgetc(stdin) ; 
	te.c_lflag |= ( ICANON|ECHO);
	tcsetattr(STDIN_FILENO, TCSANOW, &te);

	return 0;
}
예제 #9
0
void TrustedConnectionCreatorintegration::test_external_op_override()
{
    // Dispatching a Talk external op from the creator should result in
    // it being passed on to the world, exactly as if this was a Character
    // except that we assume that Creator was set up linked.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(m_creator->getId());

    m_connection->externalOperation(op, *m_connection);

    // The operation should have been passed to Entity::callOperation for
    // dispatch, completely unfiltered.
    ASSERT_TRUE(m_Entity_callOperation_called.isValid());
    ASSERT_EQUAL(m_Entity_callOperation_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_Entity_callOperation_called->isDefaultTo());
    ASSERT_EQUAL(m_Entity_callOperation_called->getTo(), m_creator->getId());
}
예제 #10
0
void TrustedConnectionCreatorintegration::test_external_op()
{
    // Dispatching a Talk external op from the creator should result in
    // it being passed on to the world, exactly as if this was a Character
    // except that we assume that Creator was set up linked.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());

    m_connection->externalOperation(op, *m_connection);

    // BaseWorld::message should have been called from Enitty::sendWorld
    // with the Talk operation, modified to have TO set to the character.
    ASSERT_TRUE(m_BaseWorld_message_called.isValid());
    ASSERT_EQUAL(m_BaseWorld_message_called->getClassNo(),
                 Atlas::Objects::Operation::TALK_NO);
    ASSERT_TRUE(!m_BaseWorld_message_called->isDefaultTo());
    ASSERT_EQUAL(m_BaseWorld_message_called->getTo(), m_creator->getId());
    ASSERT_NOT_NULL(m_BaseWorld_message_called_from);
    ASSERT_EQUAL(m_BaseWorld_message_called_from, m_creator);
}
예제 #11
0
파일: rewriter.cpp 프로젝트: itmm/myLisp
EPtr Rewriter::rewrite_dictionary(EPtr dictionary, Creator &creator) {
	Dictionary *old_dict = dictionary->as_dictionary();
	bool was_modified = false;
	Dictionary *parent = old_dict->parent();
	if (parent) {
		Dictionary *new_parent = Element::as_dictionary(rewrite_dictionary(EPtr(parent, creator.collector()), creator));
		if (new_parent != parent) {
			parent = new_parent;
			was_modified = true;
		}
	}
	EPtr new_dict = creator.new_dictionary(parent);
	auto cur = old_dict->begin();
	auto end = old_dict->end();
	for (; cur != end; ++cur) {
		EPtr old_value = EPtr(cur->second, creator.collector());
		EPtr new_value = rewrite(old_value, creator);
		if (!was_modified && old_value != new_value) {
			was_modified = true;
		}
		new_dict->as_dictionary()->put(cur->first, new_value);
	}
	return was_modified ? new_dict : dictionary;
}
예제 #12
0
파일: driver.cpp 프로젝트: nrupprecht/GFlow
int main(int argc, char **argv) {
  int rank(0);
  #if USE_MPI == 1
  int numProc(1);
  #if _CLANG_ == 1
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &numProc);
  #else
  MPI::Init(argc, argv);
  rank = MPI::COMM_WORLD.Get_rank();
  numProc = MPI::COMM_WORLD.Get_size();
  #endif
  cout << "Initialized MPI. Rank " << rank << "\n";
  #endif

  // --- Options

  // Type of simulation
  bool bipartite_flag = false;
  bool debug_flag = false;
  string load = "";

  // Data to gather
  bool animate = false; // Record positions
  bool snapshot = false;
  bool sectorData = false; // Record sector information
  bool ke = false; // Record kinetic energy
  RealType kebin = 0;
  bool energy = false; // Record total energy
  bool keTypes = false;
  bool totalKE = false; // Record average kinetic energy (per particle)
  bool secRemake = false; 
  bool bdForces = false;
  bool timestep = false;
  bool averages = false;
  bool aveV = false;
  bool aveP = false;
  bool minDistances = false;
  bool percolation = false;
  bool psnapshot = false;
  bool memdist = false;
  bool pressure = false;
  bool numberdata = false;
  bool stripex = false;
  bool centercorr = false;
  
  // Other options
  int dimensions = 2;
  RealType skin = 0.;
  bool quiet = false;
  RealType gravity = 0.;
  bool damping = false;
  bool adjustDT = true;
  int target_steps = -1;
  int step_delay = -1;
  RealType startRecTime = 0;
  RealType fps = -1.;
  RealType videoLength = -1.;
  RealType dt = 0.0001;
  long double time = 10.;
  bool print = false;
  string writeDirectory = "RunData";
  int boundary = 1;
  string monitor = ""; // Monitor file

  // Modifiers
  RealType temperature = 0;

  // --- For getting command line arguments
  ArgParse parser(argc, argv);
  parser.get("bipartite", bipartite_flag);
  parser.get("debug", debug_flag); 
  parser.get("load", load);
  parser.get("animate", animate);
  parser.get("snapshot", snapshot);
  parser.get("sectorData", sectorData);
  parser.get("KE", ke);
  parser.get("KEBin", kebin);
  parser.get("energy", energy);
  parser.get("KETypes", keTypes);
  parser.get("totalKE", totalKE);
  parser.get("secRemake", secRemake);
  parser.get("bdForces", bdForces);
  parser.get("timestep", timestep);
  parser.get("averages", averages);
  parser.get("aveV", aveV);
  parser.get("aveP", aveP);
  parser.get("minDistances", minDistances);
  parser.get("percolation", percolation);
  parser.get("psnapshot", psnapshot);
  parser.get("memdist", memdist);
  parser.get("pressure", pressure);
  parser.get("numberdata", numberdata);
  parser.get("stripex", stripex);
  parser.get("centercorr", centercorr);
  parser.get("dimensions", dimensions);
  parser.get("skin", skin);
  parser.get("quiet", quiet);
  parser.get("gravity", gravity);
  parser.get("damping", damping);
  parser.get("adjustDT", adjustDT);
  parser.get("target_steps", target_steps);
  parser.get("step_delay", step_delay);
  parser.get("startRec", startRecTime);
  parser.get("fps", fps);
  parser.get("videoLength", videoLength);
  parser.get("dt", dt);
  parser.get("time", time);
  parser.get("print", print);
  parser.get("writeDirectory", writeDirectory);
  parser.get("temperature", temperature);
  parser.get("boundary", boundary);

  if (!quiet && rank==0) {
    #if DEBUG==1
    cout << "Running in Debug mode.\n";
    #endif
    // Print SIMD type
    #if SIMD_TYPE==SIMD_NONE
    cout << "Not using SIMD.\n";
    #elif SIMD_TYPE==SIMD_SSE
    cout << "Using SSE.\n";
    #elif SIMD_TYPE==SIMD_AVX
    cout << "Using AVX.\n";
    #elif SIMD_TYPE==SIMD_AVX2
    cout << "Using AVX2.\n";
    #elif SIMD_TYPE==SIMD_MIC
    cout << "Using MIC.\n";
    #endif
  }
  
  // Record the time at which the program started.
  auto start_time = current_time();
  if (!quiet && rank==0) cout << "Starting up simulation...\n";

  // --- This creator creates gflow simulations
  Creator *creator = nullptr;
  // Assign a specific type of creator
  if (bipartite_flag)  creator = new BipartiteBoxCreator(&parser);
  else if (debug_flag) creator = new DebugCreator(&parser);
  else if (load!="") {
    creator = new FileParseCreator(&parser, load);
  }
  else creator = new BoxCreator(&parser);

  // Set dimensions
  creator->setDimensions(dimensions);

  // --- Set boundary conditions
  switch (boundary) {
    case 0: {
      creator->setBCFlag(BCFlag::OPEN);
      break;
    }
    default:
    case 1: {
      creator->setBCFlag(BCFlag::WRAP);
      break;
    }
    case 2: {
      creator->setBCFlag(BCFlag::REFL);
      break;
    }
    case 3: {
      creator->setBCFlag(BCFlag::REPL);
      break;
    }
  }

  // --- Create a gflow simulation
  GFlow *gflow = creator->createSimulation();
  if (gflow==nullptr) {
    if (!quiet) cout << "GFlow was null. Exiting.\n";
    return 1;
  }

  // --- Make sure we didn't enter any illegal tokens - do this after gflow creation since creator uses flags
  try {
    parser.check();
  }
  catch (ArgParse::UncheckedToken illegal) {
    if (!quiet) cout << "Illegal option: [" << illegal.token << "]. Exiting.\n";
    exit(1);
  }

  // --- Add data objects
  gflow->setStartRecTime(startRecTime);
  if (snapshot) gflow->addDataObject(new EndingSnapshot(gflow));
  if (totalKE || ke) gflow->addDataObject(new KineticEnergyData(gflow, ke));
  if (kebin>0)       gflow->addDataObject(new KineticEnergyBin(gflow, kebin));
  if (energy)      gflow->addDataObject(new TotalEnergyData(gflow));
  if (keTypes)     gflow->addDataObject(new KineticEnergyTypesData(gflow, true));
  if (bdForces)    gflow->addDataObject(new BoundaryForceData(gflow));
  if (timestep)    gflow->addDataObject(new TimeStepData(gflow));
  if (averages)    gflow->addDataObject(new AverageData(gflow));
  if (aveV) gflow->addDataObject(new AveVelocityData(gflow));
  if (aveP) gflow->addDataObject(new AveragePositionData(gflow));
  if (minDistances) gflow->addDataObject(new MinInteractingDistance(gflow));
  if (percolation) gflow->addDataObject(new PercolationData(gflow, skin));
  if (psnapshot)   gflow->addDataObject(new PercolationSnapshot(gflow, skin));
  if (memdist)     gflow->addDataObject(new MemoryDistance(gflow));
  if (pressure)    gflow->addDataObject(new PressureData(gflow));
  if (numberdata)  gflow->addDataObject(new NumberData(gflow));
  if (stripex)     gflow->addModifier(new StripeX(gflow));
  if (centercorr)  gflow->addDataObject(new CenterCorrelation(gflow));
  // Add this last, as it takes the most time.
  if (animate /*|| stripex*/) {
    auto pd = new PositionData(gflow);
    gflow->addDataObject(pd);
    if (videoLength>0) pd->setFPS((20.*videoLength)/time);
  }
  if (fps>0) gflow->setFPS(fps); // Do after data objects are loaded
  gflow->setDMCmd(argc, argv);
  gflow->setPrintUpdates(print);

  // --- Add modifiers
  if (temperature>0) gflow->addModifier(new TemperatureModifier(gflow, temperature));
  // Timestep adjustment
  if (target_steps>0) gflow->getIntegrator()->setTargetSteps(target_steps);
  if (step_delay>0) gflow->getIntegrator()->setStepDelay(step_delay);
  if (gravity!=0) gflow->addModifier(new ConstantAcceleration(gflow, gravity));
  if (damping) gflow->addModifier(new LinearVelocityDamping(gflow));

  // Set time step and request time
  if (!gflow->hasIntegrator()) {
    if (!quiet) cout << "GFlow does not have an integrator. Exiting.";
    return 0;
  }
  gflow->setDT(dt);
  gflow->getIntegrator()->setAdjustDT(adjustDT);
  gflow->requestTime(time);

  // Run the simulation
  if (!quiet && rank==0) {
    cout << "Initialized, ready to run:\t" << time_span(current_time(), start_time) << "\n";
    cout << "Running with " << gflow->getNumParticles() << " particles.\n";
  }
  //try {
  gflow->run();
  /*
  }
  catch (Exception *exc) {
    if (!quiet && rank==0)
      cout << "Message: " << exc->message << endl;
    throw;
  }
  catch (...) {
    if (!quiet && rank==0) cout << "Exited with exception.\n";
    // Write accumulated data to files
    if (rank==0) gflow->writeData(writeDirectory);
    // Rethrow the exception
    throw;
  }
  */
  // More detailed exception handling
  // @todo Exception handling.

  if (!quiet && rank==0) cout << "Run is over:\t\t\t" << time_span(current_time(), start_time) << "\n";
  if (!quiet && rank==0) cout << "Ratio was:  \t\t\t" << gflow->getDataMaster()->getRatio() << "\n";

  // Write accumulated data to files
  if (rank==0) gflow->writeData(writeDirectory);
  if (!quiet && rank==0) cout << "Data write is over:\t\t" << time_span(current_time(), start_time) << "\n";

  // Delete creator, gflow
  if (creator) delete creator;
  if (gflow)   delete gflow;
  
  // Finalize mpi
  #if USE_MPI == 1
  #if _CLANG_ == 1
  MPI_Finalize();
  #else
  MPI::Finalize();
  #endif
  if (!quiet && rank==0) cout << "Finalized MPI.\n";
  #endif
  
  return 0;
}
예제 #13
0
int main()
{
	//Setting up Builders
	Creator creator;
    CharacterBuilder* bullyBuilder = new BullyBuilder();
    CharacterBuilder* nimbleBuilder = new NimbleBuilder();
	CharacterBuilder* tankBuilder = new TankBuilder();

	int race, level, type, attribute, value;
	int hold; //nothing, just to hold the promp to view output

	cout << "Character Races: " << endl << endl;
	cout << "1. Human" << endl;
	cout << "2. Dwarf" << endl;
	cout << "3. Elf" << endl;
	cout << "4. Gnome" << endl;
	cout << "5. Half-Elf" << endl;
	cout << "6. Half-Orc" << endl;
	cout << "7. Halfling" << endl << endl;

	cout << "Which race would you like your character to belong to?: ";
	cin >> race;

	cout << "Character Types: " << endl << endl;
	cout << "1. Bully" << endl;
	cout << "2. Nimble" << endl;
	cout << "3. Tank" << endl << endl;

	cout << endl;

	cout << "Which type would you like your character to belong to?: ";
	cin >> type;

	cout << "What level would you like your character to be?: ";
	cin >> level;

	//Decide which CharacterBuilder to use
	switch(type) {

		case 1:
			creator.setCharacterBuilder(bullyBuilder);
		break;

		case 2:
			creator.setCharacterBuilder(nimbleBuilder);
		break;

		case 3:
			creator.setCharacterBuilder(tankBuilder);
		break;

		default:
			//Nothing
		break;

	}

	//Create Character through Creator
    creator.createCharacter(race, level);
 
    Character* character = creator.getCharacter();
    character->display();


	//Modify character to show basic Observer functionality

	CharacterObserver* observer = new CharacterObserver();

	character->Attach(observer);

	cout << "Character Attributes: " << endl << endl;
	cout << "1. Strength" << endl;
	cout << "2. Dexterity" << endl;
	cout << "3. Constitution" << endl;
	cout << "4. Intelligence" << endl;
	cout << "5. Wisdom" << endl;
	cout << "6. Charisma" << endl << endl;

	cout << "Which attribute would you like to change?: ";
	cin >> attribute;
	cout << "Please input a new value for this attribute: ";
	cin >> value;

	cout << endl;

	switch (attribute) {

		case 1:
			character->setStrength(value);
		break;

		case 2:
			character->setDexterity(value);
		break;

		case 3:
			character->setConstitution(value);
		break;

		case 4:
			character->setIntelligence(value);
		break;

		case 5:
			character->setWisdom(value);
		break;

		case 6:
			character->setCharisma(value);
		break;

		default:
			//Nothing
		break;

	}

	cin >> hold;

	return 0;

}
예제 #14
0
int main(int argc, char **argv) {
  // Options
  bool bipartite_flag = false;
  int nIters = 10;
  RealType width = 4.;
  RealType minPhi = 0.;
  RealType maxPhi = 0.8;
  RealType dt = 0.001;
  RealType time = 5.;
  RealType skin = 0.;
  bool adjustDT = false;

  // --- For getting command line arguments
  ArgParse parser(argc, argv);
  parser.get("bipartite", bipartite_flag);
  parser.get("iters", nIters);
  parser.get("width", width);
  parser.get("minPhi", minPhi);
  parser.get("maxPhi", maxPhi);
  parser.get("dt", dt);
  parser.get("time", time);
  parser.get("adjustDT", adjustDT);
  parser.get("lj", adjustDT); // If using lj, adjust dt

  // Keep in bounds - max phi can be > 1 for bipartite
  minPhi = minPhi<0 ? 0 : minPhi;
  if (!bipartite_flag) maxPhi = maxPhi>1 ? 1 : maxPhi;

  RealType phi, invArea = 1./(2.*DIMENSIONS*pow(width,DIMENSIONS-1));
  vector<RPair> data;

  Creator *creator = nullptr;
  for (int iter=0; iter<=nIters; ++iter) {
    // Set up
    phi = (maxPhi-minPhi)*static_cast<RealType>(iter)/nIters + minPhi;
    if (phi>0) {
      // --- Create a gflow simulation
      if (bipartite_flag) {
        BipartiteBoxCreator *bc = new BipartiteBoxCreator(&parser);
        bc->setWidth(width);
        bc->setPhi(phi);
        creator = bc;
      }
      else {
        BoxCreator *bc = new BoxCreator(&parser);
        bc->setWidth(width);
        bc->setPhi(phi);
        creator = bc;
      }
      GFlow *gflow = creator->createSimulation();
      if (gflow==nullptr) {
        cout << "GFlow was null. Exiting.\n";
        return 1;
      }
      // Repulsion force boundary conditions
      gflow->setAllBCs(BCFlag::REPL);
      // Run
      Clustering clustering(gflow);
      clustering.setSkin(skin);
      gflow->setDT(dt);
      // Timestep adjustment
      if (adjustDT) gflow->addModifier(new TimestepModifier(gflow));
      gflow->run(time);
      // Data
      clustering.findClusters();
      data.push_back(RPair(phi, static_cast<RealType>(clustering.getMaxClusterSize()) / gflow->getNumParticles()));
      // GFlow will delete bfData
      delete gflow, creator;
    }
    else data.push_back(RPair(0,0));
  }

  cout << "fraction={";
  for (int i=0; i<data.size(); ++i) {
    cout << "{" << data.at(i).first << "," << data.at(i).second << "}";
    if (i!=data.size()-1) cout << ",";
  }
  cout << "};\n";

  return 0;
}
예제 #15
0
Mesh::Mesh( const Creator &creator ) {
	creator.create( d_ );
}
예제 #16
0
void DrawServ::ExecuteCmd(Command* cmd) {
  static int grid_sym = symbol_add("grid");
  static int sid_sym = symbol_add("sid");
  boolean original = false;
  unsigned int from_sid = 0;

  if(!_linklist || _linklist->Number()==0) 

    /* normal Unidraw command execution */
    Unidraw::ExecuteCmd(cmd);

  else {

    /* indirect command execution, all by script */
    std::ostrstream sbuf;
    boolean oldflag = OverlayScript::ptlist_parens();
    OverlayScript::ptlist_parens(false);
    switch (cmd->GetClassId()) {
    case PASTE_CMD:
      {
      boolean scripted = false;
      Clipboard* cb = cmd->GetClipboard();
      if (cb) {
	Iterator it;
	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
	  AttributeList* al = comp->GetAttributeList();
	  AttributeValue* idv = al->find(grid_sym);
	  AttributeValue* sidv = al->find(sid_sym);
	  from_sid = sidv ? sidv->uint_val() : 0;
	  
	  /* unique id already remotely assigned */
	  if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) {
	    GraphicId* graphicid = new GraphicId();
	    graphicid->grcomp(comp);
	    graphicid->id(idv->uint_val());
	    graphicid->selector(sidv->uint_val());
	    graphicid->selected(LinkSelection::RemotelySelected);
	  } 
	  
	  /* generate unique id and add as attribute */
	  /* also mark with selector id */
	  else {
	    GraphicId* graphicid = new GraphicId(sessionid());
	    graphicid->grcomp(comp);
	    graphicid->selector(((DrawServ*)unidraw)->sessionid());
	    AttributeValue* gridv = new AttributeValue(graphicid->id(), AttributeValue::UIntType);
	    gridv->state(AttributeValue::HexState);
	    al->add_attr(grid_sym, gridv);
	    AttributeValue* sidv = new AttributeValue(graphicid->selector(), AttributeValue::UIntType);
	    sidv->state(AttributeValue::HexState);
	    al->add_attr(sid_sym, sidv);
	    original = true;
	  }
	    
	  if (comp && (original || linklist()->Number()>1)) {
	    Creator* creator = unidraw->GetCatalog()->GetCreator();
	    OverlayScript* scripter = (OverlayScript*)
	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
	    if (scripter) {
	      scripter->SetSubject(comp);
	      if (scripted) 
		sbuf << ';';
	      else 
		scripted = true;
	      boolean status = scripter->Definition(sbuf);
	      delete scripter;
	    }
	  }
	}
      }
      if (original || linklist()->Number()>1) {
	if (!scripted)
	  sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
	sbuf.put('\0');
	cout << sbuf.str() << "\n";
	cout.flush();
      }

      /* first execute here */
#if 0
      ((ComEditor*)cmd->GetEditor())->GetComTerp()->run(sbuf.str());
      ((PasteCmd*)cmd)->executed(true);
#else
      cmd->Execute();
#endif

      /* then send everywhere else */
      if (original || linklist()->Number()>1) 
	DistributeCmdString(sbuf.str(), linkget(from_sid));
      
      }
      break;
    default:
      sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)";
      cmd->Execute();
      break;
    }

    if (cmd->Reversible()) {
      cmd->Log();
    } else {
      delete cmd;
    }

    OverlayScript::ptlist_parens(oldflag);
  }
}