Пример #1
0
 double SimulationIsingModel::computeEnergy()
 {
     double e = 0.0;
     for (int i=0; i<_n; i++) {
         e += 0.5*computePairEnergy(i);
         e += computeFieldEnergy(i);
     }
     return e;
 }
Пример #2
0
double Model::computeEnergy(unsigned int particle, double position[])
#endif
{
    // N.B. This method is somewhat redundant since the same functionality
    // could be achieved by using a combination of the computeInteractions
    // and model specific computePairEnergy methods.

    unsigned int cell;      // cell index
    unsigned int neighbour; // index of neighbouring particle
    double energy = 0;      // energy counter

    // Check all neighbouring cells including same cell.
    for (unsigned int i=0;i<cells.getNeighbours();i++)
    {
        cell = cells[particles[particle].cell].neighbours[i];

        // Check all particles within cell.
        for (unsigned int j=0;j<cells[cell].tally;j++)
        {
            neighbour = cells[cell].particles[j];

            // Make sure the particles are different.
            if (neighbour != particle)
            {
                // Calculate model specific pair energy.
#ifndef ISOTROPIC
                energy += computePairEnergy(particle, position, orientation,
                          neighbour, &particles[neighbour].position[0],
                          &particles[neighbour].orientation[0]);
#else
                energy += computePairEnergy(particle, position,
                          neighbour, &particles[neighbour].position[0]);
#endif

                // Early exit test for hard core overlaps and large finite energy repulsions.
                if (energy > 1e6) return INF;
            }
        }
    }

    return energy;
}
Пример #3
0
unsigned int PatchyDisc::computeInteractions(unsigned int particle,
    double position[], double orientation[], unsigned int interactions[])
{
    unsigned int cell;              // cell index
    unsigned int neighbour;         // index of neighbouring particle
    unsigned int nInteractions = 0; // interaction counter

    // Check all neighbouring cells including same cell.
    for (unsigned int i=0;i<cells.getNeighbours();i++)
    {
        cell = cells[particles[particle].cell].neighbours[i];

        // Check all particles within cell.
        for (unsigned int j=0;j<cells[cell].tally;j++)
        {
            neighbour = cells[cell].particles[j];

            // Make sure the particles are different.
            if (neighbour != particle)
            {
                // Calculate pair energy.
                double energy = computePairEnergy(particle, position, orientation,
                                neighbour, &particles[neighbour].position[0],
                                &particles[neighbour].orientation[0]);

                // Particles interact.
                if (energy < 0)
                {
                    if (nInteractions == maxInteractions)
                    {
                        std::cerr << "[ERROR] PatchyDisc: Maximum number of interactions exceeded!\n";
                        exit(EXIT_FAILURE);
                    }

                    interactions[nInteractions] = neighbour;
                    nInteractions++;
                }
            }
        }
    }

    return nInteractions;
}
Пример #4
0
 double SimulationIsingModel::computeEnergy(int i)
 {
     return (computePairEnergy(i) + computeFieldEnergy(i));
 }