Mixtures

It is relatively straightforward to add mixtures of particles. We define particles (or beads on particles) as being type::A, type::B, etc. We then define interactions for A's, B's, etc.

#include <glotzilla++.h>

//begin changes
class BinaryMixture : public CustomInteraction
{
   public:
      BinaryMixture()
      {
         SetInteraction(type::A | type::A, new TwelveSixLjPotential);
         SetInteraction(type::A | type::B, new WcaPotential);
         SetInteraction(type::B | type::B, new TwelveSixLjPotential);
      }
};
//end changes

class BinMixSystem : public MdIntegrator
{
   public:
      BinMixSystem()
      {                 
         mInitialConditions = new MdInitializer;
                 
         InitializeParticles();
         mInitialConditions -> SetInteraction(new BinaryMixture);
         mInitialConditions -> SetForceRoutine(new VerletForce);
         mInitialConditions -> SetBoundaryConditions(new PeriodicBoundary(11));
         mInitialConditions -> SetMoveRoutine(new VerletMove);
                 
         BerendsenThermostat *thermostat = new BerendsenThermostat;
         thermostat -> SetTemperature(0.5);
         mInitialConditions -> AddSimulationComponent(thermostat);
                        
         InitializeSystem(mInitialConditions);
      }

   private:
      void InitializeParticles()
      {
         ipstream particle_pipe("randbox -n=512 -r=-5,5,-5,5,-5,5 -m=1.0 -i=1000000");

         int np = 0;
         vec_t x;         
         while(particle_pipe >> x)
         {
             MdPointParticle *p = new MdPointParticle;
                        
             //begin changes
             if(np++ % 2 == 0)
                p -> SetType(type::A);
             else
                p -> SetType(type::B);
             //end changes
                        
            p -> SetPosition(x);
            mInitialConditions -> AddParticle(p);
         }
         particle_pipe.close();
      }

      MdInitializer *mInitialConditions;

};

int main(int argc, char ** argv) 
{
   BinMixSystem my_simulation;
   opstream my_pipe("vis3d -n=\"Binary Mixture\"");

   for(int timesteps=0; timesteps<100000; timesteps++)
   {
      if(timesteps % 5 == 0)
                 my_simulation.PrintVisual(my_pipe);
      my_simulation ++;
   }

   my_pipe.close();
   return 0;
}

Here, we have made a few key changes. First, we define a new interaction type

class BinaryMixture : public CustomInteraction
{
   public:
   BinaryMixture()
   {
      SetInteraction(type::A | type::A, new TwelveSixLjPotential);
      SetInteraction(type::A | type::B, new WcaPotential);
      SetInteraction(type::B | type::B, new TwelveSixLjPotential);
   }
};

Here, we specify that particles of type A and type B interact with other particles of the same type via the 12-6 Lennard Jones potential. Particles of opposite types interact via the WCA potential. Note that type::A and type::B are pre-defined constants. The sytnax type::A | type::B means A - B interactions.

When we initialize the particles, we set their types to A or B using the SetType?(...) member function.

//begin changes
if(np++ % 2 == 0)
   p -> SetType(type::A);
else
   p -> SetType(type::B);
//end changes

The system should phase separate in to A rich and B righ domains.

Was this clear ?