示例#1
0
  void 
  LTriangleMesh::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"), Sim));
    _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"), Property::Units::Length());
    _e = Sim->_properties.getProperty(XML.getAttribute("Elasticity"), Property::Units::Dimensionless());

    localName = XML.getAttribute("Name");

    {//Load the vertex coordinates
      std::istringstream is(XML.getNode("Vertices").getValue());
      is.exceptions(std::ostringstream::badbit | std::ostringstream::failbit);
      is.peek(); //Set the eof flag if needed
      Vector tmp;
      while (!is.eof())
	{
	  is >> tmp[0];
	  if (is.eof()) M_throw() << "The vertex coordinates is not a multiple of 3";

	  is >> tmp[1];
	  if (is.eof()) M_throw() << "The vertex coordinates is not a multiple of 3";

	  is >> tmp[2];	  
	  _vertices.push_back(tmp * Sim->units.unitLength());
	}
    }

    {//Load the triangle elements
      std::istringstream is(XML.getNode("Elements").getValue());
      is.exceptions(std::ostringstream::badbit | std::ostringstream::failbit);
      is.peek(); //Set the eof flag if needed

      TriangleElements tmp;
      while (!is.eof())
	{
	  is >> std::get<0>(tmp);
	  if (is.eof()) M_throw() << "The triangle elements are not a multiple of 3";
	  
	  is >> std::get<1>(tmp);
	  if (is.eof()) M_throw() << "The triangle elements are not a multiple of 3";

	  is >> std::get<2>(tmp);

	  if ((std::get<0>(tmp) >= _vertices.size()) 
	      || (std::get<1>(tmp) >= _vertices.size()) 
	      || (std::get<2>(tmp) >= _vertices.size()))
	    M_throw() << "Triangle " << _elements.size() << " has an out of range vertex ID";

	  Vector normal
	    = (_vertices[std::get<1>(tmp)] - _vertices[std::get<0>(tmp)])
	    ^ (_vertices[std::get<2>(tmp)] - _vertices[std::get<1>(tmp)]);

	  if (normal.nrm() == 0) 
	    M_throw() << "Triangle " << _elements.size() << " has a zero normal!";


	  _elements.push_back(tmp);
	}
    }
  }
示例#2
0
  void 
  LOscillatingPlate::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<Range>(Range::getClass(XML,Sim));
  
    try {
      e = XML.getAttribute("Elasticity").as<double>();
      nhat << XML.getNode("Norm");
      nhat /= nhat.nrm();

      rw0 << XML.getNode("Origin");
      rw0 *= Sim->dynamics.units().unitLength();

      if (XML.hasAttribute("StrongPlate"))
	strongPlate = XML.getAttribute("StrongPlate").as<double>();

      omega0 = XML.getAttribute("Omega0").as<double>() / Sim->dynamics.units().unitTime();
      sigma = XML.getAttribute("Sigma").as<double>() * Sim->dynamics.units().unitLength();
      delta = XML.getAttribute("Delta").as<double>() * Sim->dynamics.units().unitLength();
      mass = XML.getAttribute("Mass").as<double>()  * Sim->dynamics.units().unitMass();
      timeshift = XML.getAttribute("TimeShift").as<double>() * Sim->dynamics.units().unitTime();

      localName = XML.getAttribute("Name");
    } 
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in LOscillatingPlate";
      }
  }
示例#3
0
  void 
  GVolumetricPotential::operator<<(const magnet::xml::Node& XML) {
    globName = XML.getAttribute("Name");
    _fileName = XML.getAttribute("RawFile");
    _sampleBytes = XML.getAttribute("SampleBytes").as<size_t>();


    //Load the dimensions of the data set (and its subset of data if
    //only processing a smaller section)
    auto XMLdim = XML.getNode("Dimensions");
    _imageDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
    
    _offset = std::array<size_t, 3>{{0, 0, 0}};
    if (XML.hasNode("Offset"))
      {
	auto XMLdim = XML.getNode("Offset");
	_offset = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
      }

    std::array<size_t, 3> sampleDimensions = _imageDimensions;
    if (XML.hasNode("SampleDimensions"))
      {
	auto XMLdim = XML.getNode("SampleDimensions");
	sampleDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
      }

    Ordering fileOrdering(_imageDimensions);
    std::vector<unsigned char> fileData(fileOrdering.size() * _sampleBytes);
    dout << "Opening " << _fileName << std::endl;
    std::ifstream file(_fileName.c_str(), std::ifstream::binary);

    if (!file.good())
      M_throw() << "Failed open the file " << _fileName;
    dout << "Reading " << fileOrdering.size() * _sampleBytes << " bytes of data into memory" <<  std::endl;
    file.read(reinterpret_cast<char*>(fileData.data()), fileOrdering.size() * _sampleBytes);
    
    if (!file)
      M_throw() << "Failed reading volumetric data (read " << file.gcount() << " bytes of an expected " << fileOrdering.size() * _sampleBytes << "  from " << _fileName << ")";
    file.close();

    _ordering = Ordering(sampleDimensions);
    _volumeData.resize(_ordering.size());

    dout << "Resampling " << _ordering.size() << " bytes of data from the file into the simulation" <<  std::endl;
    if (_sampleBytes == 1)
      {
	if (sampleDimensions == _imageDimensions)
	  std::swap(_volumeData, fileData);
	else
	  for (size_t z = 0; z < sampleDimensions[2]; ++z)
	    for (size_t y = 0; y < sampleDimensions[1]; ++y)
	      {
		size_t startindex = fileOrdering.toIndex(std::array<size_t, 3>{{_offset[0], y + _offset[1], z + _offset[2]}});
		std::copy(fileData.begin() + startindex, fileData.begin() + startindex + sampleDimensions[0], _volumeData.begin() + _ordering.toIndex(std::array<size_t, 3>{{0, y, z}}));
	      }
      }
    else
      M_throw() << "Do not have an optimised loader for resampling data yet";
    dout << "Loading complete" <<  std::endl;
  }
示例#4
0
文件: lwall.cpp 项目: MChudak/DynamO
  void 
  LWall::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
    _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"), Property::Units::Length());

    if (_diameter->getMaxValue() == 0)
      M_throw() << "Cannot have a wall with a diameter of zero";
      
    _e = Sim->_properties.getProperty(XML.getAttribute("Elasticity"), Property::Units::Dimensionless());
    
    sqrtT = 0;
    if (XML.hasAttribute("Temperature"))
      sqrtT = sqrt(XML.getAttribute("Temperature").as<double>()
		   * Sim->units.unitEnergy());

    if (sqrtT < 0)
      M_throw() << "Cannot use negative temperatures on a Wall";

    magnet::xml::Node xBrowseNode = XML.getNode("Norm");
    localName = XML.getAttribute("Name");
    vNorm << xBrowseNode;
    if (vNorm.nrm() == 0)
      M_throw() << "The normal for the Local Wall named \"" << getName() << "\" has a length of 0. Cannot load";
    vNorm /= vNorm.nrm();
    xBrowseNode = XML.getNode("Origin");
    vPosition << xBrowseNode;
    vPosition *= Sim->units.unitLength();
  }
示例#5
0
  void 
  ISWSequence::operator<<(const magnet::xml::Node& XML)
  {
    Interaction::operator<<(XML);

    _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"),
					     Property::Units::Length());
    _lambda = Sim->_properties.getProperty(XML.getAttribute("Lambda"),
					   Property::Units::Dimensionless());
    
    if (XML.hasAttribute("Elasticity"))
      _e = Sim->_properties.getProperty(XML.getAttribute("Elasticity"),
					Property::Units::Dimensionless());
    else
      _e = Sim->_properties.getProperty(1.0, Property::Units::Dimensionless());
    
    intName = XML.getAttribute("Name");
    ICapture::loadCaptureMap(XML);
    
    //Load the sequence
    sequence.clear();
    std::set<size_t> letters;
    
    for (magnet::xml::Node node = XML.getNode("Sequence").fastGetNode("Element");
	 node.valid(); ++node)
      {
	if (node.getAttribute("seqID").as<size_t>() != sequence.size())
	  M_throw() << "Sequence of letters not in order, missing element " << sequence.size();
	
	size_t letter = node.getAttribute("Letter").as<size_t>();
	letters.insert(letter);
	sequence.push_back(letter);
      }
    
    //Initialise all the well depths to 1.0
    alphabet.resize(letters.size());
    
    for (std::vector<double>& vec : alphabet)
      vec.resize(letters.size(), 0.0);
    
    for (magnet::xml::Node node = XML.getNode("Alphabet").fastGetNode("Word");
	 node.valid(); ++node)
      {
	alphabet
	  .at(node.getAttribute("Letter1").as<size_t>())
	  .at(node.getAttribute("Letter2").as<size_t>())
	  = node.getAttribute("Depth").as<double>();
	
	alphabet
	  .at(node.getAttribute("Letter2").as<size_t>())
	  .at(node.getAttribute("Letter1").as<size_t>())
	  = node.getAttribute("Depth").as<double>();
      }
  }
示例#6
0
  void 
  Liouvillean::loadParticleXMLData(const magnet::xml::Node& XML)
  {
    dout << "Loading Particle Data" << std::endl;

    bool outofsequence = false;  
  
    for (magnet::xml::Node node = XML.getNode("ParticleData").fastGetNode("Pt"); 
	 node.valid(); ++node)
      {
	if (!node.hasAttribute("ID")
	    || node.getAttribute("ID").as<size_t>() != Sim->particleList.size())
	  outofsequence = true;
      
	Particle part(node, Sim->particleList.size());
	part.getVelocity() *= Sim->dynamics.units().unitVelocity();
	part.getPosition() *= Sim->dynamics.units().unitLength();
	Sim->particleList.push_back(part);
      }

    if (outofsequence)
      dout << "Particle ID's out of sequence!\n"
	   << "This can result in incorrect capture map loads etc.\n"
	   << "Erase any capture maps in the configuration file so they are regenerated." << std::endl;

    Sim->N = Sim->particleList.size();

    dout << "Particle count " << Sim->N << std::endl;

    if (XML.getNode("ParticleData").hasAttribute("OrientationData"))
      {
	orientationData.resize(Sim->N);
	size_t i(0);
	for (magnet::xml::Node node = XML.getNode("ParticleData").fastGetNode("Pt"); 
	     node.valid(); ++node, ++i)
	  {
	    orientationData[i].orientation << node.getNode("U");
	    orientationData[i].angularVelocity << node.getNode("O");
      
	    double oL = orientationData[i].orientation.nrm();
      
	    if (!(oL > 0.0))
	      M_throw() << "Particle ID " << i 
			<< " orientation vector is zero!";
      
	    //Makes the vector a unit vector
	    orientationData[i].orientation /= oL;
	  }
      }
  }
示例#7
0
 IDPairRangePair(const magnet::xml::Node& XML, const dynamo::Simulation* Sim)
 {
     magnet::xml::Node subRangeXML = XML.getNode("IDRange");
     range1 = shared_ptr<IDRange>(IDRange::getClass(subRangeXML, Sim));
     ++subRangeXML;
     range2 = shared_ptr<IDRange>(IDRange::getClass(subRangeXML, Sim));
 }
示例#8
0
void
CSUmbrella::operator<<(const magnet::xml::Node& XML)
{
  if (strcmp(XML.getAttribute("Type"),"Umbrella"))
    M_throw() << "Attempting to load Umbrella from a " 
	      << XML.getAttribute("Type") <<  " entry"; 
  
  try {
    sysName = XML.getAttribute("Name");

    a = XML.getAttribute("a").as<double>()
      * Sim->dynamics.units().unitEnergy() 
      / Sim->dynamics.units().unitArea();

    b = XML.getAttribute("b").as<double>()
      * Sim->dynamics.units().unitLength();

    delU = XML.getAttribute("delU").as<double>() * Sim->dynamics.units().unitEnergy();
    range1.set_ptr(CRange::getClass(XML.getNode("Range1"), Sim));
    range2.set_ptr(CRange::getClass(XML.getNode("Range2"), Sim));
    
    if (XML.hasAttribute("currentulevel"))
      {
	ulevel = XML.getAttribute("currentulevel").as<size_t>();
	ulevelset = true;
      }
    
  }
  catch (boost::bad_lexical_cast &)
    { M_throw() << "Failed a lexical cast in CSUmbrella"; }
}
示例#9
0
  void
  CSRingDSMC::operator<<(const magnet::xml::Node& XML)
  {
    if (strcmp(XML.getAttribute("Type"),"RingDSMC"))
      M_throw() << "Attempting to load RingDSMC from a " 
		<< XML.getAttribute("Type") <<  " entry"; 
  
    try {
      tstep = XML.getAttribute("tStep").as<double>() * Sim->dynamics.units().unitTime();    
      chi12 = XML.getAttribute("Chi12").as<double>();
      chi13 = XML.getAttribute("Chi13").as<double>();
      sysName = XML.getAttribute("Name");
      diameter = XML.getAttribute("Diameter").as<double>() * Sim->dynamics.units().unitLength();
      e = XML.getAttribute("Inelasticity").as<double>();
      d2 = diameter * diameter;
      range1 = std::tr1::shared_ptr<CRange>(CRange::getClass(XML.getNode("Range1"), Sim));

      if (XML.hasAttribute("MaxProbability12"))
	maxprob12 = XML.getAttribute("MaxProbability12").as<double>();
	
      if (XML.hasAttribute("MaxProbability13"))
	maxprob13 = XML.getAttribute("MaxProbability13").as<double>();
    }
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in CGGlobal";
      }
  }
示例#10
0
  void
  SysUmbrella::operator<<(const magnet::xml::Node& XML)
  {
    sysName = XML.getAttribute("Name");
    magnet::xml::Node rangeNode = XML.getNode("IDRange");
    range1 = shared_ptr<IDRange>(IDRange::getClass(rangeNode, Sim));
    ++rangeNode;
    range2 = shared_ptr<IDRange>(IDRange::getClass(rangeNode, Sim));
    _potential = Potential::getClass(XML.getNode("Potential"));

    _lengthScale = XML.getAttribute("LengthScale").as<double>() * Sim->units.unitLength();
    _energyScale = XML.getAttribute("EnergyScale").as<double>() * Sim->units.unitEnergy();

    if (XML.hasAttribute("CurrentStep"))
      _stepID = XML.getAttribute("CurrentStep").as<size_t>();
  }
示例#11
0
 C2RPair::C2RPair(const magnet::xml::Node& XML, const dynamo::SimData* Sim)
 { 
   if (strcmp(XML.getAttribute("Range"), "Pair"))
     M_throw() << "Attempting to load a pair from a non pair";
 
   range1 = shared_ptr<Range>(Range::getClass(XML.getNode("Range1"), Sim));
   range2 = shared_ptr<Range>(Range::getClass(XML.getNode("Range2"), Sim));
 }
示例#12
0
  void 
  LBoundary::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
    localName = XML.getAttribute("Name");

    _oscillationData._origin << XML.getNode("Origin");
    _oscillationData._origin *= Sim->units.unitLength();
    _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"), Property::Units::Length());
    if (_diameter->getMaxValue() == 0)
      M_throw() << "Cannot have a boundary with a diameter of zero";

    _oscillationData._amplitude = Vector();
    _oscillationData._freq = 0;
    _oscillationData._t_shift = 0;
    
    const size_t data_count = XML.hasNode("Amplitude") + XML.hasAttribute("Frequency") + XML.hasAttribute("Phase");
    if ((data_count != 3) && (data_count != 0))
      M_throw() << "For oscillating walls you must have an Amplitude, Frequency, and Phase specified."
		<< XML.getPath();

    if (data_count == 3) {
      _oscillationData._freq = XML.getAttribute("Frequency").as<double>() / Sim->units.unitTime();
      _oscillationData._t_shift = XML.getAttribute("Phase").as<double>() * Sim->units.unitTime();
      _oscillationData._amplitude << XML.getNode("Amplitude");
      _oscillationData._amplitude *= Sim->units.unitLength();
    }

    _kT = 0;
    if (XML.hasAttribute("kT")) {
      if (data_count == 3)
	M_throw() << "Cannot have both a thermalised wall and a oscillating wall" 
		  << XML.getPath();
      
      _kT = XML.getAttribute("kT").as<double>() * Sim->units.unitEnergy();
    }

    if (_kT < 0)
      M_throw() << "Temperature is less than zero" << XML.getPath();

    for (magnet::xml::Node node = XML.findNode("Object"); node.valid(); ++node)
      _objects.push_back(boundary::Object::getClass(node, Sim, _oscillationData));

    if (_objects.empty())
      M_throw() << "Boundary Locals must have at least one Object.\n" << XML.getPath();
  }
示例#13
0
 void
 SSleep::operator<<(const magnet::xml::Node& XML)
 {
   sysName = XML.getAttribute("Name");
   _sleepVelocity = XML.getAttribute("SleepV").as<double>() * Sim->units.unitVelocity();
   _sleepDistance = Sim->units.unitLength() * 0.01;
   _sleepTime = Sim->units.unitTime() * 0.0001;
   _range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"), Sim));
 }
示例#14
0
 void 
 LOscillatingPlate::operator<<(const magnet::xml::Node& XML)
 {
   range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
   e = XML.getAttribute("Elasticity").as<double>();
   nhat << XML.getNode("Norm");
   nhat /= nhat.nrm();
   rw0 << XML.getNode("Origin");
   rw0 *= Sim->units.unitLength();
   if (XML.hasAttribute("StrongPlate"))
     strongPlate = XML.getAttribute("StrongPlate").as<double>();
   omega0 = XML.getAttribute("Omega0").as<double>() / Sim->units.unitTime();
   sigma = XML.getAttribute("Sigma").as<double>() * Sim->units.unitLength();
   delta = XML.getAttribute("Delta").as<double>() * Sim->units.unitLength();
   mass = XML.getAttribute("Mass").as<double>()  * Sim->units.unitMass();
   timeshift = XML.getAttribute("TimeShift").as<double>() * Sim->units.unitTime();
   localName = XML.getAttribute("Name");
 }
示例#15
0
Particle::Particle(const magnet::xml::Node& XML, unsigned long nID):
  _ID(nID),
  _peculiarTime(0.0),
  _state(DEFAULT)
{
  if (XML.hasAttribute("Static")) clearState(DYNAMIC);

  _pos << XML.getNode("P");
  _vel << XML.getNode("V");
}
示例#16
0
 void 
 GFrancesco::operator<<(const magnet::xml::Node& XML)
 {
   globName = XML.getAttribute("Name");
   const double MFT = XML.getAttribute("MFT").as<double>() * Sim->units.unitTime();
   const double MFTstddev = XML.getAttribute("MFTstddev").as<double>() * Sim->units.unitTime();
   _dist = std::normal_distribution<>(MFT, MFTstddev);
   _vel = XML.getAttribute("Velocity").as<double>() * Sim->units.unitVelocity();
   range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"), Sim));
 }
示例#17
0
文件: dynamics.cpp 项目: qshao/DynamO
  void 
  Dynamics::loadParticleXMLData(const magnet::xml::Node& XML)
  {
    dout << "Loading Particle Data" << std::endl;

    bool outofsequence = false;  
  
    for (magnet::xml::Node node = XML.getNode("ParticleData").findNode("Pt"); 
	 node.valid(); ++node)
      {
	if (!node.hasAttribute("ID")
	    || node.getAttribute("ID").as<size_t>() != Sim->particles.size())
	  outofsequence = true;
      
	Particle part(node, Sim->particles.size());
	part.getVelocity() *= Sim->units.unitVelocity();
	part.getPosition() *= Sim->units.unitLength();
	Sim->particles.push_back(part);
      }

    if (outofsequence)
      dout << "Particle ID's out of sequence!\n"
	   << "This can result in incorrect capture map loads etc.\n"
	   << "Erase any capture maps in the configuration file so they are regenerated." << std::endl;

    dout << "Particle count " << Sim->N() << std::endl;

    if (XML.getNode("ParticleData").hasAttribute("OrientationData"))
      {
	orientationData.resize(Sim->N());
	size_t i(0);
	for (magnet::xml::Node node = XML.getNode("ParticleData").findNode("Pt"); node.valid(); ++node, ++i)
	  {
	    orientationData[i].orientation << node.getNode("U");
	    orientationData[i].angularVelocity << node.getNode("O");
      
	    //Makes the vector a unit vector
	    orientationData[i].orientation.normalise();
	    if (orientationData[i].orientation.nrm() == 0)
	      M_throw() << "Particle " << i << " has an invalid zero orientation quaternion";
	  }
      }
  }
示例#18
0
  void 
  ICapture::loadCaptureMap(const magnet::xml::Node& XML)
  {
    if (XML.hasNode("CaptureMap"))
      {
	_mapUninitialised = false;
	clear();

	for (magnet::xml::Node node = XML.getNode("CaptureMap").findNode("Pair"); node.valid(); ++node)
	  Map::operator[](Map::key_type(node.getAttribute("ID1").as<size_t>(), node.getAttribute("ID2").as<size_t>()))
	    = node.getAttribute("val").as<size_t>();
      }
  }
示例#19
0
  void 
  CLAndersenWall::operator<<(const magnet::xml::Node& XML)
  {
    range = std::tr1::shared_ptr<CRange>(CRange::getClass(XML,Sim));
  
    try {
    
      sqrtT = sqrt(XML.getAttribute("Temperature").as<double>() 
		   * Sim->dynamics.units().unitEnergy());

      localName = XML.getAttribute("Name");
      vNorm << XML.getNode("Norm");
      vNorm /= vNorm.nrm();
      vPosition << XML.getNode("Origin");
      vPosition *= Sim->dynamics.units().unitLength();

    } 
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in CLAndersenWall";
      }
  }
示例#20
0
  DynNewtonianMC::DynNewtonianMC(dynamo::Simulation* tmp, const magnet::xml::Node& XML):
    DynNewtonian(tmp),
    EnergyPotentialStep(1)
  {
    if (XML.hasNode("PotentialDeformation"))
      {
	EnergyPotentialStep 
	  = XML.getNode("PotentialDeformation").getAttribute("EnergyStep").as<double>()
	  / Sim->units.unitEnergy();

	for (magnet::xml::Node node = XML.getNode("PotentialDeformation").fastGetNode("W"); 
	     node.valid(); ++node)
	  {
	    double energy = node.getAttribute("Energy").as<double>() / Sim->units.unitEnergy();	    
	    double Wval = node.getAttribute("Value").as<double>();
		
	    //Here, the Wval needs to be multiplied by kT to turn it
	    //into an Energy, but the Ensemble is not yet initialised,
	    //we must do this conversion later, when we actually use the W val.
	    _W[lrint(energy / EnergyPotentialStep)] = Wval;
	  }
      }
  }
示例#21
0
  void 
  LRoughWall::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
  
    try {
      e = XML.getAttribute("Elasticity").as<double>();
      et = XML.getAttribute("TangentialElasticity").as<double>();
      r = XML.getAttribute("Radius").as<double>() * Sim->units.unitLength();
      render = XML.getAttribute("Render").as<double>();
      localName = XML.getAttribute("Name");

      vNorm << XML.getNode("Norm");
      vNorm /= vNorm.nrm();

      vPosition << XML.getNode("Origin");
      vPosition *= Sim->units.unitLength();
    } 
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in LRoughWall";
      }
  }
示例#22
0
void
IMultiCapture::loadCaptureMap(const magnet::xml::Node& XML)
{
    if (XML.hasNode("CaptureMap"))
    {
        noXmlLoad = false;
        clear();

        for (magnet::xml::Node node = XML.getNode("CaptureMap").fastGetNode("Pair");
                node.valid(); ++node)
            captureMap[cMapKey(node.getAttribute("ID1").as<size_t>(),
                               node.getAttribute("ID2").as<size_t>())]
                = node.getAttribute("val").as<size_t>();
    }
}
示例#23
0
LNewtonianMC::LNewtonianMC(dynamo::SimData* tmp, const magnet::xml::Node& XML):
  LNewtonian(tmp),
  EnergyPotentialStep(1)
{
  if (strcmp(XML.getAttribute("Type"),"NewtonianMC"))
    M_throw() << "Attempting to load NewtonianMC from " 
	      << XML.getAttribute("Type")
	      << " entry";
  try 
    {     
      if (XML.hasNode("PotentialDeformation"))
	if (XML.getNode("PotentialDeformation").hasAttribute("EnergyStep"))
	  EnergyPotentialStep 
	    = XML.getNode("PotentialDeformation").getAttribute("EnergyStep").as<double>();
      
      EnergyPotentialStep /= Sim->dynamics.units().unitEnergy();
      
      if (dynamic_cast<const dynamo::EnsembleNVT*>(Sim->ensemble.get()) == NULL)
	M_throw() << "Multi-canonical simulations require an NVT ensemble";

      if (XML.hasNode("PotentialDeformation"))
	for (magnet::xml::Node node = XML.getNode("PotentialDeformation").fastGetNode("W"); 
	     node.valid(); ++node)
	  {
	    double energy = node.getAttribute("Energy").as<double>() / Sim->dynamics.units().unitEnergy();	    
	    double Wval = node.getAttribute("Value").as<double>();
	    
	    //Here, the Wval needs to be multiplied by kT to turn it
	    //into an Energy, but the Ensemble is not yet initialised,
	    //we must do this conversion later, when we actually use the W val.
	    _W[lrint(energy / EnergyPotentialStep)] = Wval;
	  }
    }
  catch (boost::bad_lexical_cast &)
    { M_throw() << "Failed a lexical cast in LNewtonianMC"; }
}
  void 
  SysAndersen::operator<<(const magnet::xml::Node& XML)
  {
    meanFreeTime = XML.getAttribute("MFT").as<double>() * Sim->units.unitTime() / Sim->N();
    Temp = XML.getAttribute("Temperature").as<double>() * Sim->units.unitEnergy();
    sysName = XML.getAttribute("Name");

    if (XML.hasAttribute("Dimensions"))
      dimensions = XML.getAttribute("Dimensions").as<size_t>();

    if (XML.hasAttribute("SetFrequency") && XML.hasAttribute("SetPoint"))
      {
	tune = true;
	setFrequency = XML.getAttribute("SetFrequency").as<size_t>();
	setPoint = XML.getAttribute("SetPoint").as<double>();
      }

    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
  }
示例#25
0
  void 
  GSOCells::operator<<(const magnet::xml::Node& XML)
  {
    globName = XML.getAttribute("Name");
    
    if (XML.hasNode("CellOrigins")) {
      Vector pos;
      for (magnet::xml::Node node = XML.getNode("CellOrigins").findNode("Origin"); node.valid(); ++node) {
	pos << node;
	pos *= Sim->units.unitLength();
	cell_origins.push_back(pos);
      }

      if (cell_origins.size() != Sim->N())
	M_throw() << "Number of CellOrigins (" << cell_origins.size() << ") does not match number of particles (" << Sim->N() << ")\n" << XML.getPath();
    }

    if (XML.hasAttribute("Diameter"))
      _cellD = XML.getAttribute("Diameter").as<double>() * Sim->units.unitLength();
  }
示例#26
0
DynNewtonianMCCMap::DynNewtonianMCCMap(dynamo::Simulation* tmp, const magnet::xml::Node& XML):
    DynNewtonian(tmp)
{
    _interaction_name = XML.getAttribute("Interaction");

    if (XML.hasNode("Potential"))
    {
        for (magnet::xml::Node map_node = XML.getNode("Potential").findNode("Map");
                map_node.valid(); ++map_node)
        {
            double Wval = map_node.getAttribute("W").as<double>();
            size_t distance = map_node.getAttribute("Distance").as<size_t>();

            detail::CaptureMap map;
            for (magnet::xml::Node entry_node = map_node.findNode("Contact"); entry_node.valid(); ++entry_node)
                map[detail::CaptureMap::key_type(entry_node.getAttribute("ID1").as<size_t>(), entry_node.getAttribute("ID2").as<size_t>())]
                    = entry_node.getAttribute("State").as<size_t>();
            _W.push_back(std::make_pair(map, WData(distance, Wval)));
        }
    }
}
示例#27
0
  DynGravity::DynGravity(dynamo::Simulation* tmp, const magnet::xml::Node& XML):
    DynNewtonian(tmp),
    elasticV(0),
    g({0, -1, 0}),
    _tc(-std::numeric_limits<float>::infinity())
  {
    if (XML.hasAttribute("ElasticV"))
      elasticV = XML.getAttribute("ElasticV").as<double>()
	* Sim->units.unitVelocity();
    
    if (XML.hasAttribute("tc"))
      {
	_tc = XML.getAttribute("tc").as<double>() * Sim->units.unitTime();
	
	if (_tc <= 0) 
	  M_throw() << "tc must be positive! (tc = " 
		    << _tc/ Sim->units.unitTime() << ")";
      }    
    g << XML.getNode("g");

    g *= Sim->units.unitAcceleration();
  }
  void 
  IRotatedParallelCubes::operator<<(const magnet::xml::Node& XML)
  { 
    if (strcmp(XML.getAttribute("Type"),"RotatedParallelCubes"))
      M_throw() << "Attempting to load RotatedParallelCubes from " 
		<< XML.getAttribute("Type") << " entry";
  
    Interaction::operator<<(XML);
  
    try 
      {
	_diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"),
						 Property::Units::Length());
	_e = Sim->_properties.getProperty(XML.getAttribute("Elasticity"),
					  Property::Units::Dimensionless());
	intName = XML.getAttribute("Name");
	magnet::math::operator<<(Rotation, XML.getNode("Rotation"));
      }
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in CIRotatedParallelCubes";
      }
  }
示例#29
0
  void 
  ISWSequence::operator<<(const magnet::xml::Node& XML)
  {
    if (strcmp(XML.getAttribute("Type"),"SquareWellSeq"))
      M_throw() << "Attempting to load SquareWell from non SquareWell entry";
  
    Interaction::operator<<(XML);

    try { 
      _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"),
					       Property::Units::Length());
      _lambda = Sim->_properties.getProperty(XML.getAttribute("Lambda"),
					     Property::Units::Dimensionless());

      if (XML.hasAttribute("Elasticity"))
	_e = Sim->_properties.getProperty(XML.getAttribute("Elasticity"),
					  Property::Units::Dimensionless());
      else
	_e = Sim->_properties.getProperty(1.0, Property::Units::Dimensionless());

      intName = XML.getAttribute("Name");
      ISingleCapture::loadCaptureMap(XML);

      //Load the sequence
      sequence.clear();
      std::set<size_t> letters;
    
      for (magnet::xml::Node node = XML.getNode("Sequence").fastGetNode("Element");
	   node.valid(); ++node)
	{
	  if (node.getAttribute("seqID").as<size_t>() != sequence.size())
	    M_throw() << "Sequence of letters not in order, missing element " << sequence.size();

	  size_t letter = node.getAttribute("Letter").as<size_t>();
	  letters.insert(letter);
	  sequence.push_back(letter);
	}

      //Initialise all the well depths to 1.0
      alphabet.resize(letters.size());

      BOOST_FOREACH(std::vector<double>& vec, alphabet)
	vec.resize(letters.size(), 0.0);

      for (magnet::xml::Node node = XML.getNode("Alphabet").fastGetNode("Word");
	   node.valid(); ++node)
	{
	  alphabet
	    .at(node.getAttribute("Letter1").as<size_t>())
	    .at(node.getAttribute("Letter2").as<size_t>())
	    = node.getAttribute("Depth").as<double>();

	  alphabet
	    .at(node.getAttribute("Letter2").as<size_t>())
	    .at(node.getAttribute("Letter1").as<size_t>())
	    = node.getAttribute("Depth").as<double>();
	}
    }
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in CISWSequence";
      }
  }
示例#30
0
 void 
 Interaction::operator<<(const magnet::xml::Node& XML)
 { range = shared_ptr<IDPairRange>(IDPairRange::getClass(XML.getNode("IDPairRange"), Sim)); }