Example #1
0
// ------------------ surface ---------------------
SReal Cell::surface()
{
    if (getProperties()->getType()== StructureProperties::QUAD || getProperties()->getType()== StructureProperties::TRIANGLE)
    {
        SReal A[3]= {0.0, 0.0, 0.0 };
        unsigned int nbElem;

        nbElem = Cell::getNumberOfStructures();

        SReal posi[3], posip1[3];
        ((Atom*)getStructure(0))->getPosition(posip1);

        for (unsigned int i=0; i<nbElem; i++) {
            posi[0]=posip1[0];
            posi[1]=posip1[1];
            posi[2]=posip1[2];
            ((Atom*)getStructure((i+1)%nbElem))->getPosition(posip1);
            //Cross(posi, posip1, inter);
            A[0] += posi[1]*posip1[2] - posi[2]*posip1[1];
            A[1] += posi[2]*posip1[0] - posi[0]*posip1[2];
            A[2] += posi[0]*posip1[1] - posi[1]*posip1[0];
        }

        // here A is in fact twice the theoritical area vector
        A[0] /= 2.0;
        A[1] /= 2.0;
        A[2] /= 2.0;

        // face normal :
        SReal * N = normal();

        SReal surface = N[0]*A[0] + N[1]*A[1] + N[2]*A[2];

        return surface>0?surface:-surface;
    }
    else {
        StructuralComponent * facets = getFacets();
        if (!facets)
            return 0.0;
        SReal surface=0.0;
        for (unsigned int i=0 ; i<facets->getNumberOfCells() ; i++) {
            surface += facets->getCell(i)->surface();
        }
        return surface;
    }
}
Example #2
0
// ------------------ volume ---------------------
SReal Cell::volume()
{
    StructuralComponent * facets = getFacets();
    if (!facets || getProperties()->getType()== StructureProperties::QUAD || getProperties()->getType()== StructureProperties::TRIANGLE)
        return 0.0;

    SReal vol=0.0;
    Cell * face;
    for (unsigned int i=0; i < facets->getNumberOfCells(); i++) {
        face = facets->getCell(i);
        SReal pos[3];
        ((Atom*)face->getStructure(0))->getPosition(pos);
        SReal * N = face->normal();
        vol += face->surface()* ( pos[0]*N[0] + pos[1]*N[1] + pos[2]*N[2] );
    }

    vol /= 3.0;
    return vol>0?vol:-vol;

}