Пример #1
0
static num pz81eps(const densvars<num> &d)
{
  parameter c[4][4] = {{-0.1423, 1.0529, 0.3334, 0},
		       {-0.0843, 1.3981, 0.2611, 0},
		       {0.0311, -0.048, 0.0020, -0.0116},
		       {0.01555000000,-0.0269, 0.0007, -0.0048}};
  if (1 > d.r_s)
    return Ehd(d.r_s,c[2]) + (Ehd(d.r_s,c[3]) - Ehd(d.r_s,c[2]))*fz(d);
  else
    return Eld(d.r_s,c[0]) + (Eld(d.r_s,c[1]) - Eld(d.r_s,c[0]))*fz(d);
}
Пример #2
0
Feature::Feature( CfgList* d )
{
	gene = fz(d->GetLiteral("gene"));
	func = fz(d->GetLiteral("function"));
	locusTag = fz(d->GetLiteral("locus_tag"));
	note = fz(d->GetLiteral("note"));
	product = fz(d->GetLiteral("product"));

	CfgList* indexList = d->GetList("Indices");
	indices.push_back((int)((CfgNumeric*) indexList->childs[0]->value)->value);
	indices.push_back((int)((CfgNumeric*) indexList->childs[1]->value)->value);
}
int main(int argc, char* argv[])
{
  Mesh mesh;
  std::ifstream in((argc>1)?argv[1]:"data/tripod.off");
  in  >> mesh;

  Vertex_point_pmap vppmap = get(CGAL::vertex_point,mesh);

  // Insert number_of_data_points in the tree
  Tree tree(vertices(mesh).begin(),
            vertices(mesh).end(),
            Splitter(),
            Traits(vppmap)
  );
  Point_3 query(0.0, 0.0, 0.0);
  double radius = 0.5;
  double epsilon = 0.01;

  // search vertices
  CGAL::Fuzzy_sphere<Traits> fz(query, radius, epsilon);
  
  //collect vertices that are inside the sphere
  std::list<vertex_descriptor> result;
  tree.search(std::back_inserter(result), fz);
  std::cout << "There are " << result.size() << " vertices inside the fuzzy sphere\n";

  return 0;
}
Пример #4
0
void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if
    (
        pointZones().size() > 0
     || faceZones().size() > 0
     || cellZones().size() > 0
    )
    {
        Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void linearValveLayersFvMesh::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    // Add zones
    List<pointZone*> pz(1);
    List<faceZone*> fz(4);
    List<cellZone*> cz(0);


    // Add an empty zone for cut points

    pz[0] = new pointZone
    (
        "cutPointZone",
        labelList(0),
        0,
        pointZones()
    );


    // Do face zones for slider

    // Inner slider
    const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
    const polyPatch& innerSlider =
        boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];

    labelList isf(innerSlider.size());

    forAll (isf, i)
    {
        isf[i] = innerSlider.start() + i;
    }
Пример #5
0
void Foam::mixerGgiFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if (cellZones().size() > 0)
    {
        Info<< "void mixerGgiFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    // Add zones
    List<pointZone*> pz(0);
    List<faceZone*> fz(0);
    List<cellZone*> cz(1);

    // Copy the face zones associated with the GGI interfaces
    if (faceZones().size() > 0)
    {
        // Copy face zones
        Info << "Copying existing face zones" << endl;

        fz.setSize(faceZones().size());

        forAll (faceZones(), i)
        {
            fz[i] = faceZones()[i].clone(faceZones()).ptr();
        }
Пример #6
0
long long fz(int l, int r)
{
	if (l == r)
	{
		return 0;
	}
	int m = (l + r) >> 1;
	long long res = fz(l, m) + fz(m + 1, r);
	int t = 0;
	for (int i = m; i >= l; --i)
	{
		if (s[i] == '(')
		{
			t++;
		}
		else
		{
			t--;
		}
		cnt[100000 + t]++;
	}
	t = 0;
	for (int i = m + 1; i <= r; ++i)
	{
		if (s[i] == '(')
		{
			t++;
		}
		else
		{
			t--;
		}
		res += cnt[100000 - t];
	}
	for (int i = 100000 - (m - l + 3); i <= 100000 + (r - m + 3); ++i)
	{
		cnt[i] = 0;
	}
	return res;
}
Пример #7
0
void Foam::linearValveFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if
    (
        pointZones().size()
     || faceZones().size()
     || cellZones().size()
     || topoChanger_.size()
    )
    {
        Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    // Add zones
    List<pointZone*> pz(1);

    // Add an empty zone for cut points

    pz[0] = new pointZone
    (
        "cutPointZone",
        labelList(0),
        0,
        pointZones()
    );


    // Do face zones for slider

    List<faceZone*> fz(3);

    // Inner slider
    const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
    const polyPatch& innerSlider = boundaryMesh()[innerSliderName];

    labelList isf(innerSlider.size());

    forAll(isf, i)
    {
        isf[i] = innerSlider.start() + i;
    }
Пример #8
0
void test_overload4() {

    std::cout << "\n";

    D d;
    const D cd;

    fz(d);
    fz(cd);
    fz(D());

    std::cout << "\n";

    fzt(d);
    fzt(cd);
    fzt(D());

    std::cout << "\n";

    fzr(d);
    fzr(cd);
    fzr(D());
}
Пример #9
0
int main()
{
	scanf("%s", s);
	int n = strlen(s);
	memset(cnt, 0, sizeof cnt);
	if (n == 2)
	{
		printf("0\n");
	}
	else
	{
		printf("%lld\n", fz(1, n - 2));
	}
	return 0;
}
Пример #10
0
/*! \fn Real avg3d(Real (*func)(Real, Real, Real), const GridS *pG, 
 *                 const int i, const int j, const int k)
 *  \brief RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE
 * THREE-DIMENSIONAL GRID CELL (i,j,k).  
 *
 * INTEGRATION IS PERFORMED USING qsimp.
 * ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
 */
Real avg3d(Real (*func)(Real, Real, Real), const GridS *pG, 
            const int i, const int j, const int k)
{
  Real x1,x2,x3,dvol=pG->dx1*pG->dx2*pG->dx3;
  Real fz(Real z);

  nrfunc=func;
  cc_pos(pG,i,j,k,&x1,&x2,&x3);
  xmin = x1 - 0.5*pG->dx1;  xmax = x1 + 0.5*pG->dx1;
  ymin = x2 - 0.5*pG->dx2;  ymax = x2 + 0.5*pG->dx2;
  zmin = x3 - 0.5*pG->dx3;  zmax = x3 + 0.5*pG->dx3;

#ifdef CYLINDRICAL
  dvol *= x1;
#endif

  return qsimp(fz,zmin,zmax)/dvol;
}
void Foam::multiMixerFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if
    (
        pointZones().size() > 0
     || faceZones().size() > 0
     || cellZones().size() > 0
    )
    {
        Info<< "void multiMixerFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0  && useTopoSliding())
        {
            FatalErrorIn
            (
                "void multiMixerFvMesh::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh.  " << rotors_.size()
        << " sliders found" << endl;

    DynamicList<pointZone*> pz(rotors_.size());
    DynamicList<faceZone*> fz(3*rotors_.size());
    DynamicList<cellZone*> cz(rotors_.size());

    // Create region split: mark every cell with its topological region
    regionSplit rs(*this);

    Info << "Adding point, face and cell zones" << endl;
    forAll (rotors_, rotorI)
    {
        rotors_[rotorI].addZones(pz, fz, cz, rs);
    }
void Foam::sixDofTopoMotion::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if (useTopoSliding_)
    {
        if
        (
            pointZones().size() > 0
         || faceZones().size() > 0
         || cellZones().size() > 0
        )
        {
            Info<< "void sixDofTopoMotion::addZonesAndModifiers() : "
                << "Zones and modifiers already present.  Skipping."
                << endl;

            if (topoChanger_.size() == 0)
            {
                FatalErrorIn
                (
                    "void sixDofTopoMotion::addZonesAndModifiers()"
                )   << "Mesh modifiers not read properly"
                    << abort(FatalError);
            }

            return;
        }

        Info<< "Time = " << time().timeName() << endl
            << "Adding zones and modifiers to the mesh" << endl;

        // Add zones
        List<pointZone*> pz(3*bodies_.size());
        List<faceZone*> fz(3*bodies_.size());
        List<cellZone*> cz(0);

        label npz = 0;
        label nfz = 0;
        label nSliders = 0;

        forAll (bodies_, bodyI)
        {
            const floatingBody& curBody = bodies_[bodyI];

            if
            (
                curBody.hullSlider().active()
             && curBody.fixedSlider().active()
            )
            {
                nSliders++;

                // Add an empty zone for cut points
                pz[npz] = new pointZone
                (
                    curBody.name() + "CutPointZone",
                    labelList(0),
                    npz,
                    pointZones()
                );
                npz++;

                // Do face zones for slider

                // Inner slider
                const polyPatch& innerSlider =
                    boundaryMesh()[curBody.hullSlider().index()];

                labelList isf(innerSlider.size());

                forAll (isf, i)
                {
                    isf[i] = innerSlider.start() + i;
                }

                fz[nfz] = new faceZone
                (
                    curBody.name() + "InsideSliderZone",
                    isf,
                    boolList(innerSlider.size(), false),
                    nfz,
                    faceZones()
                );
                nfz++;

                // Outer slider
                const polyPatch& outerSlider =
                    boundaryMesh()[curBody.fixedSlider().index()];

                labelList osf(outerSlider.size());

                forAll (osf, i)
                {
                    osf[i] = outerSlider.start() + i;
                }

                fz[nfz] = new faceZone
                (
                    curBody.name() + "OutsideSliderZone",
                    osf,
                    boolList(outerSlider.size(), false),
                    nfz,
                    faceZones()
                );
                nfz++;

                // Add empty zone for cut faces
                fz[nfz] = new faceZone
                (
                    curBody.name() + "CutFaceZone",
                    labelList(0),
                    boolList(0, false),
                    nfz,
                    faceZones()
                );
                nfz++;
            }
void Foam::simpleTwoStroke::addZonesAndModifiers()
{
    // Add the zones and mesh modifiers to operate piston motion

    if
    (
        pointZones().size() > 0
        || faceZones().size() > 0
        || cellZones().size() > 0
    )
    {
        Info<< "Time = " << engTime().theta() << endl;
        Info<< "void simpleTwoStroke::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void simpleTwoStroke::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        setVirtualPistonPosition();
        checkAndCalculate();

        return;


    }

    Info << "checkAndCalculate()" << endl;
    checkAndCalculate();

    Info<< "Time = " << engTime().theta() << endl
        << "Adding zones to the engine mesh" << endl;


    //fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone
    //pz = 2: piston points, cutPointZone
    //cz = 1: moving mask

    List<pointZone*> pz(3);
    List<faceZone*> fz(4);
    List<cellZone*> cz(1);

    label nPointZones = 0;
    label nFaceZones = 0;
    label nCellZones = 0;

    // Add the piston zone
    if (piston().patchID().active())
    {

        // Piston position

        Info << "Adding face zone for piston layer addition/removal" << endl;

        label pistonPatchID = piston().patchID().index();

        scalar zPist =
            max(boundary()[pistonPatchID].patch().localPoints()).z();

        scalar zPistV = zPist + offSet();

        labelList zone1(faceCentres().size());
        boolList flipZone1(faceCentres().size(), false);
        label nZoneFaces1 = 0;

        bool foundAtLeastOne = false;
        scalar zHigher = GREAT;
        scalar dh = GREAT;
        scalar dl = GREAT;

        forAll (faceCentres(), faceI)
        {
            // The points have to be in the cylinder and not in the ports....

            scalar zc = faceCentres()[faceI].z();

            scalar xc = faceCentres()[faceI].x();
            scalar yc = faceCentres()[faceI].y();

            vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
            scalar dd = n & vector(0,0,1);

            if(sqrt(sqr(xc)+sqr(yc)) <  0.5 * engTime().bore().value())
            {
                if (dd > 0.1)
                {
                    if (zPistV - zc > 0 && zPistV - zc < dl)
                    {
                        dl = zPistV - zc;
                    }

                    if (zc - zPistV > 0 && zc - zPistV < dh)
                    {
                        zHigher = zc;
                        dh = zc - zHigher;
                    }

                    if
                    (
                        zc > zPistV - delta()
                        && zc < zPistV + delta()
                    )
                    {
                        foundAtLeastOne = true;
                        if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
                        {
                            flipZone1[nZoneFaces1] = true;
                        }

                        zone1[nZoneFaces1] = faceI;
                        nZoneFaces1++;
                    }
                }
            }
        }
void Foam::layerAR::addZonesAndModifiers()
{
    // Add the zones and mesh modifiers to operate piston motion

    if
    (
        pointZones().size() > 0
     || faceZones().size() > 0
     || cellZones().size() > 0
    )
    {
        Info<< "void layerAR::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void layerAR::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        setVirtualPistonPosition();
        checkAndCalculate();

        return;
    }

    checkAndCalculate();

    Info<< "Time = " << engTime().theta() << endl
        << "Adding zones to the engine mesh" << endl;

    //fz = 1: faces where layer are added/removed
    //pz = 2: points below the virtual piston faces and head points

    List<pointZone*> pz(2);
    List<faceZone*> fz(1);
    List<cellZone*> cz(0);

    label nPointZones = 0;
    label nFaceZones = 0;

    // Add the piston zone
    if (piston().patchID().active() && offSet() > SMALL)
    {

        // Piston position

        label pistonPatchID = piston().patchID().index();

        scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();

        scalar zPistV = zPist + offSet();

        labelList zone1(faceCentres().size());
        boolList flipZone1(faceCentres().size(), false);
        label nZoneFaces1 = 0;

        bool foundAtLeastOne = false;
        scalar zHigher = GREAT;
        scalar dh = GREAT;
        scalar dl = GREAT;

        forAll (faceCentres(), faceI)
        {
            scalar zc = faceCentres()[faceI].z();
            vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
            scalar dd = n & vector(0,0,1);

            if (dd > 0.1)
            {
                if (zPistV - zc > 0 && zPistV - zc < dl)
                {
                    dl = zPistV - zc;
                }

                if (zc - zPistV > 0 && zc - zPistV < dh)
                {
                    zHigher = zc;
                    dh = zc - zHigher;
                }

                if
                (
                    zc > zPistV - delta()
                    && zc < zPistV + delta()
                )
                {
                    foundAtLeastOne = true;
                    if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
                    {
                        flipZone1[nZoneFaces1] = true;
                    }

                    zone1[nZoneFaces1] = faceI;
                    nZoneFaces1++;
                }
            }
        }
Пример #15
0
real lane_emden(real r0, real dr, real* m_enc) {
	int N;
	real dy1, dz1, y, z, r, dy2, dz2, dy3, dz3, dy4, dz4, y0, z0;
	real dm1, m, dm2, dm3, dm4, m0;
	int done = 0;
	y = 1.0;
	z = 0.0;
	m = 0.0;
	N = (int) (r0 / dr + 0.5);
	if (N < 1) {
		N = 1;
	}
	r = 0.0;
	do {
		if (r + dr > r0) {
			dr = r0 - r;
			done = 1;
		}
		y0 = y;
		z0 = z;
		m0 = m;
		dy1 = fy(y, z, r) * dr;
		dz1 = fz(y, z, r) * dr;
		dm1 = fm(y, z, r) * dr;
		y += 0.5 * dy1;
		z += 0.5 * dz1;
		m += 0.5 * dm1;
		if (y <= 0.0) {
			y = 0.0;
			break;
		}
		dy2 = fy(y, z, r + 0.5 * dr) * dr;
		dz2 = fz(y, z, r + 0.5 * dr) * dr;
		dm2 = fm(y, z, r + 0.5 * dr) * dr;
		y = y0 + 0.5 * dy2;
		z = z0 + 0.5 * dz2;
		m = m0 + 0.5 * dm2;
		if (y <= 0.0) {
			y = 0.0;
			break;
		}
		dy3 = fy(y, z, r + 0.5 * dr) * dr;
		dz3 = fz(y, z, r + 0.5 * dr) * dr;
		dm3 = fm(y, z, r + 0.5 * dr) * dr;
		y = y0 + dy3;
		z = z0 + dz3;
		m = m0 + dm3;
		if (y <= 0.0) {
			y = 0.0;
			break;
		}
		dy4 = fy(y, z, r + dr) * dr;
		dz4 = fz(y, z, r + dr) * dr;
		dm4 = fm(y, z, r + dr) * dr;
		y = y0 + (dy1 + dy4 + 2.0 * (dy3 + dy2)) / 6.0;
		z = z0 + (dz1 + dz4 + 2.0 * (dz3 + dz2)) / 6.0;
		m = m0 + (dm1 + dm4 + 2.0 * (dm3 + dm2)) / 6.0;
		if (y <= 0.0) {
			y = 0.0;
			break;
		}
		r += dr;
	} while (done == 0);
	if( m_enc != nullptr) {
		*m_enc = m;
	}
	if (y < 0.0) {
		return 0.0;
	} else {
		return y;
	}
}
Пример #16
0
void Foam::mixerFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if
    (
        pointZones().size() > 0
        || faceZones().size() > 0
        || cellZones().size() > 0
    )
    {
        Info<< "void mixerFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void mixerFvMesh::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    // Add zones
    List<pointZone*> pz(1);

    // Add an empty zone for cut points

    pz[0] = new pointZone
    (
        "cutPointZone",
        labelList(0),
        0,
        pointZones()
    );


    // Do face zones for slider

    List<faceZone*> fz(3);

    // Moving slider
    const word movingSliderName(dict_.subDict("slider").lookup("moving"));
    label movingSliderIndex = boundaryMesh().findPatchID(movingSliderName);

    if (movingSliderIndex < 0)
    {
        FatalErrorIn("void mixerFvMesh::addZonesAndModifiers() const")
                << "Moving slider patch not found in boundary"
                << abort(FatalError);
    }

    const word staticSliderName(dict_.subDict("slider").lookup("static"));
    label staticSliderIndex = boundaryMesh().findPatchID(staticSliderName);

    if (staticSliderIndex < 0)
    {
        FatalErrorIn("void mixerFvMesh::addZonesAndModifiers() const")
                << "Static slider patch not found in boundary"
                << abort(FatalError);

    }

    const polyPatch& movingSlider = boundaryMesh()[movingSliderIndex];

    labelList isf(movingSlider.size());

    forAll (isf, i)
    {
        isf[i] = movingSlider.start() + i;
    }
Пример #17
0
static void 
init_lists(rubikblocks_conf *cp)
{
  GLuint base;
  int i;
  float x, y, z;
  base = cp->list_base = glGenLists(27);
  for(i = 0; i < 27; i++)
  {
    x = cp->pieces[i].pos[0];
    y = cp->pieces[i].pos[1];
    z = cp->pieces[i].pos[2];
    glNewList(base+i, GL_COMPILE);
    glBegin(GL_QUAD_STRIP);
    glNormal3f(1, 0, 0);
    glTexCoord2f(0, 0);
    glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5));
    glTexCoord2f(0, 1);
    glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5));
    glTexCoord2f(1, 0);
    glVertex3f(fx(x+0.5), fy(y-0.5), fz(z+0.5));
    glTexCoord2f(1, 1);
    glVertex3f(fx(x+0.5), fy(y+0.5), fz(z+0.5));
    glNormal3f(0, 0, 1);
    glTexCoord2f(0, 0);
    glVertex3f(fx(x-0.5), fy(y-0.5), fz(z+0.5));
    glTexCoord2f(0, 1);
    glVertex3f(fx(x-0.5), fy(y+0.5), fz(z+0.5));
    glNormal3f(-1, 0, 0);
    glTexCoord2f(1, 0);
    glVertex3f(fx(x-0.5), fy(y-0.5), fz(z-0.5));
    glTexCoord2f(1, 1);
    glVertex3f(fx(x-0.5), fy(y+0.5), fz(z-0.5));
    glNormal3f(0, 0, -1);
    glTexCoord2f(0, 0);
    glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5));
    glTexCoord2f(0, 1);
    glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5));
    glEnd();
    glBegin(GL_QUADS);
    glNormal3f(0, 1, 0);
    glTexCoord2f(0, 0);
    glVertex3f(fx(x+0.5), fy(y+0.5), fz(z+0.5));
    glTexCoord2f(0, 1);
    glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5));
    glTexCoord2f(1, 1);
    glVertex3f(fx(x-0.5), fy(y+0.5), fz(z-0.5));
    glTexCoord2f(1, 0);
    glVertex3f(fx(x-0.5), fy(y+0.5), fz(z+0.5));
    glNormal3f(0, -1, 0);
    glTexCoord2f(0, 0);
    glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5));
    glTexCoord2f(0, 1);
    glVertex3f(fx(x+0.5), fy(y-0.5), fz(z+0.5));
    glTexCoord2f(1, 1);
    glVertex3f(fx(x-0.5), fy(y-0.5), fz(z+0.5));
    glTexCoord2f(1, 0);
    glVertex3f(fx(x-0.5), fy(y-0.5), fz(z-0.5));
    glEnd();
    glEndList();
  }
}
Пример #18
0
SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f):
    QSplashScreen(pixmap, f)
{

    // set reference point, paddings
    int paddingRight            = 30;
    int paddingTop              = 50;
    int titleVersionVSpace      = 17;
    int titleCopyrightVSpace    = 40;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive); // cut of testnet, place it as single object further down
    QString versionText     = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Shiacoin developers"));
    QString testnetAddText  = QString(tr("[testnet]")); // define text to place as single text object

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(GetBoolArg("-testnet")) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 28*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    QFont fz(font, 28*fontFactor);
    fz.setStyleStrategy(QFont::PreferAntialias);
    pixPaint.setFont(fz);
    fm = pixPaint.fontMetrics();
    titleTextWidth  = fm.width(titleText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText); //newPixmap.width()-titleTextWidth-

    fz.setPixelSize(10);
    pixPaint.setFont(fz);

    // if the version string is to long, reduce size
    fm = pixPaint.fontMetrics();
    int versionTextWidth  = fm.width(versionText);
    if(versionTextWidth > titleTextWidth+paddingRight-10) {
        pixPaint.setFont(QFont(font, 10*fontFactor));
        titleVersionVSpace -= 5;
    }
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText); //

    fz.setPixelSize(8.5);
    pixPaint.setFont(fz);

    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText); //newPixmap.width()-titleTextWidth-

    // draw testnet string if -testnet is on
    if(QApplication::applicationName().contains(QString("-testnet"))) {
        // draw copyright stuff
        QFont boldFont = QFont(font, 10);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    //showmstatusmessage
    fz.setPixelSize(11);
    QRect r(15, 310, 500, 15);
    this->setMessageRect(r, Qt::AlignCenter); // Setting the message position.
    this->setFont(fz);

    this->setPixmap(newPixmap);
}
main()
{
	//initial conditions, Sun
	//pos[0][0]=5.232390004684601E+08;
	//pos[0][1]=5.801842462211855E+07;
	//pos[0][2]=-2.307177112284731E+07;
	
	//Mercury
	//pos[1][0]=-4.900595711964040E+10;
	//pos[1][1]=1.978992366271316E+10;
	//pos[1][2]=6.133258850210199E+9;
	
	//Venus
	//pos[2][0]=5.067655349913087E+10;
	//pos[2][1]=-9.653428273036470E+10;
	//pos[2][2]=-4.241247608362041E+9;
	
	//Earthwa
	//pos[3][0]=9.252785130208500E+10;
	//pos[3][1]=0;
	//pos[3][2]=0;
	
	//positions, all at once. In the order described in sol_init.dat
	
	
	
	//m[0]=1.989E+30;
	//m[1]=5.972E+24;
	//m[2]=7.35E+22;
	//m[3]=317.828*m[1];
	{
	int i, j;
	for (i=0;i<N;i++)
	{
		for (j=0;j<3;j++)
		{
			pos[i][j]*=1E3;
			vel[i][j]*=1E3;
		}
	}
	}
	
	
	
	FILE *fpos, *fvel;
	int k, pk;
	
	fpos=fopen("posvs.dat","w+");
	fvel=fopen("velvs.dat","w+");
	for (t=0;t<60000000;t+=dt)
	{
		fprintf(fpos,"%lf ",t);
		fprintf(fvel,"%lf ",t);
		
		for (k=0;k<N;k++)
		{
			for (pk=0;pk<3;pk++)
			{
				fprintf(fpos,"%lf ",pos[k][pk]);
				fprintf(fvel,"%lf ",vel[k][pk]);				
			}
				
		}
		fprintf(fpos,"\n");
			fprintf(fvel,"\n");
		for (k=0;k<N;k++)
		{
			v[k][0]=vel[k][0];
			v[k][1]=vel[k][1];
			v[k][2]=vel[k][2];
						
			p[k][0]=pos[k][0]+vel[k][0]*dt;
			p[k][1]=pos[k][1]+vel[k][1]*dt;
			p[k][2]=pos[k][2]+vel[k][2]*dt;
						
			
			
				int j;
				for(j=0;j<N;j++)
				{
					if (j!=k)
					{
						v[k][0]+=fx(k,j)*dt;
						v[k][1]+=fy(k,j)*dt;
						v[k][2]+=fz(k,j)*dt;
						
						p[k][0]+=0.5*fx(k,j)*dt*dt;
						p[k][1]+=0.5*fy(k,j)*dt*dt;
						p[k][2]+=0.5*fz(k,j)*dt*dt;
						
					}
				}
				
		}
		//update
		for (k=0;k<N;k++)
		{
			int j;
			for (j=0;j<3;j++)
			{
				pos[k][j]=p[k][j];
				vel[k][j]=v[k][j];
			} 
		}
		
	}
	fclose(fpos);
	fclose(fvel);
}
Пример #20
0
void Foam::movingConeTopoFvMesh::addZonesAndModifiers()
{
    // Add zones and modifiers for motion action

    if
    (
        pointZones().size()
     || faceZones().size()
     || cellZones().size()
     || topoChanger_.size()
    )
    {
        Info<< "void movingConeTopoFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        return;
    }

    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    const vectorField& fc = faceCentres();
    const vectorField& fa = faceAreas();

    labelList zone1(fc.size());
    boolList flipZone1(fc.size(), false);
    label nZoneFaces1 = 0;

    labelList zone2(fc.size());
    boolList flipZone2(fc.size(), false);
    label nZoneFaces2 = 0;

    forAll(fc, faceI)
    {
        if
        (
            fc[faceI].x() > -0.003501
         && fc[faceI].x() < -0.003499
        )
        {
            if ((fa[faceI] & vector(1, 0, 0)) < 0)
            {
                flipZone1[nZoneFaces1] = true;
            }

            zone1[nZoneFaces1] = faceI;
            Info<< "face " << faceI << " for zone 1.  Flip: "
                << flipZone1[nZoneFaces1] << endl;
            nZoneFaces1++;
        }
        else if
        (
            fc[faceI].x() > -0.00701
         && fc[faceI].x() < -0.00699
        )
        {
            zone2[nZoneFaces2] = faceI;

            if ((fa[faceI] & vector(1, 0, 0)) > 0)
            {
                flipZone2[nZoneFaces2] = true;
            }

            Info<< "face " << faceI << " for zone 2.  Flip: "
                << flipZone2[nZoneFaces2] << endl;
            nZoneFaces2++;
        }
    }

    zone1.setSize(nZoneFaces1);
    flipZone1.setSize(nZoneFaces1);

    zone2.setSize(nZoneFaces2);
    flipZone2.setSize(nZoneFaces2);

    Info<< "zone: " << zone1 << endl;
    Info<< "zone: " << zone2 << endl;

    List<pointZone*> pz(0);
    List<faceZone*> fz(2);
    List<cellZone*> cz(0);

    label nFz = 0;

    fz[nFz] =
        new faceZone
        (
            "rightExtrusionFaces",
            zone1,
            flipZone1,
            nFz,
            faceZones()
        );
    nFz++;

    fz[nFz] =
        new faceZone
        (
            "leftExtrusionFaces",
            zone2,
            flipZone2,
            nFz,
            faceZones()
        );
    nFz++;

    fz.setSize(nFz);

    Info<< "Adding mesh zones." << endl;
    addZones(pz, fz, cz);


    // Add layer addition/removal interfaces

    List<polyMeshModifier*> tm(2);
    label nMods = 0;

    tm[nMods] =
        new layerAdditionRemoval
        (
            "right",
            nMods,
            topoChanger_,
            "rightExtrusionFaces",
            readScalar
            (
                motionDict_.subDict("right").lookup("minThickness")
            ),
            readScalar
            (
                motionDict_.subDict("right").lookup("maxThickness")
            )
        );
    nMods++;

    tm[nMods] = new layerAdditionRemoval
    (
        "left",
        nMods,
        topoChanger_,
        "leftExtrusionFaces",
        readScalar
        (
            motionDict_.subDict("left").lookup("minThickness")
        ),
        readScalar
        (
            motionDict_.subDict("left").lookup("maxThickness")
        )
    );
    nMods++;
    tm.setSize(nMods);

    Info<< "Adding " << nMods << " mesh modifiers" << endl;
    topoChanger_.addTopologyModifiers(tm);

    write();
}
Пример #21
0
// ------------------------------------------------------------------------------------------------
void TempMesh::RemoveAdjacentDuplicates() 
{

	bool drop = false;
	std::vector<IfcVector3>::iterator base = verts.begin();
	BOOST_FOREACH(unsigned int& cnt, vertcnt) {
		if (cnt < 2){
			base += cnt;
			continue;
		}

		IfcVector3 vmin,vmax;
		ArrayBounds(&*base, cnt ,vmin,vmax);


		const IfcFloat epsilon = (vmax-vmin).SquareLength() / static_cast<IfcFloat>(1e9);
		//const IfcFloat dotepsilon = 1e-9;

		//// look for vertices that lie directly on the line between their predecessor and their 
		//// successor and replace them with either of them.

		//for(size_t i = 0; i < cnt; ++i) {
		//	IfcVector3& v1 = *(base+i), &v0 = *(base+(i?i-1:cnt-1)), &v2 = *(base+(i+1)%cnt);
		//	const IfcVector3& d0 = (v1-v0), &d1 = (v2-v1);
		//	const IfcFloat l0 = d0.SquareLength(), l1 = d1.SquareLength();
		//	if (!l0 || !l1) {
		//		continue;
		//	}

		//	const IfcFloat d = (d0/std::sqrt(l0))*(d1/std::sqrt(l1));

		//	if ( d >= 1.f-dotepsilon ) {
		//		v1 = v0;
		//	}
		//	else if ( d < -1.f+dotepsilon ) {
		//		v2 = v1;
		//		continue;
		//	}
		//}

		// drop any identical, adjacent vertices. this pass will collect the dropouts
		// of the previous pass as a side-effect.
		FuzzyVectorCompare fz(epsilon);
		std::vector<IfcVector3>::iterator end = base+cnt, e = std::unique( base, end, fz );
		if (e != end) {
			cnt -= static_cast<unsigned int>(std::distance(e, end));
			verts.erase(e,end);
			drop  = true;
		}

		// check front and back vertices for this polygon
		if (cnt > 1 && fz(*base,*(base+cnt-1))) {
			verts.erase(base+ --cnt);
			drop  = true;
		}

		// removing adjacent duplicates shouldn't erase everything :-)
		ai_assert(cnt>0);
		base += cnt;
	}
	if(drop) {
		IFCImporter::LogDebug("removing duplicate vertices");
	}
}
void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers()
{
    // Add the zones and mesh modifiers to operate piston and valve motion

    if
    (
        pointZones().size() > 0
     || faceZones().size() > 0
     || cellZones().size() > 0
    )
    {
        Info<< "void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void simpleEngineTopoFvMesh::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        return;
    }

    Info<< "Time = " << engineTime_.theta() << endl
        << "Adding zones to the engine mesh" << endl;

    List<pointZone*> pz(nValves());
    List<faceZone*> fz(6*nValves() + 1);
    List<cellZone*> cz(0);

    label nPointZones = 0;
    label nFaceZones = 0;

    for (label valveI = 0; valveI < nValves(); valveI++)
    {
        // If both sides of the interface exist, add sliding interface
        // for a valve
        if
        (
            valves_[valveI].curtainInCylinderPatchID().active()
         && valves_[valveI].curtainInPortPatchID().active()
        )
        {
            Info<< "Adding sliding interface zones for curtain of valve "
                << valveI + 1 << endl;

            pz[nPointZones] =
                new pointZone
                (
                    "cutPointsV" + Foam::name(valveI + 1),
                    labelList(0),
                    nPointZones,
                    pointZones()
                );
            nPointZones++;

            const polyPatch& cylCurtain =
                boundaryMesh()
                    [valves_[valveI].curtainInCylinderPatchID().index()];

            labelList cylCurtainLabels(cylCurtain.size(), cylCurtain.start());

            forAll (cylCurtainLabels, i)
            {
                cylCurtainLabels[i] += i;
            }

            fz[nFaceZones] =
                new faceZone
                (
                    "curtainCylZoneV" + Foam::name(valveI + 1),
                    cylCurtainLabels,
                    boolList(cylCurtainLabels.size(), false),
                    nFaceZones,
                    faceZones()
                );
            nFaceZones++;

            const polyPatch& portCurtain =
                boundaryMesh()
                    [valves_[valveI].curtainInPortPatchID().index()];

            labelList portCurtainLabels
            (
                portCurtain.size(),
                portCurtain.start()
            );

            forAll (portCurtainLabels, i)
            {
                portCurtainLabels[i] += i;
            }

            fz[nFaceZones] =
                new faceZone
                (
                    "curtainPortZoneV" + Foam::name(valveI + 1),
                    portCurtainLabels,
                    boolList(portCurtainLabels.size(), false),
                    nFaceZones,
                    faceZones()
                );
            nFaceZones++;

            // Add empty zone for cut faces
            fz[nFaceZones] =
                new faceZone
                (
                    "cutFaceZoneV" + Foam::name(valveI + 1),
                    labelList(0),
                    boolList(0, false),
                    nFaceZones,
                    faceZones()
                );
            nFaceZones++;

            // Create a detach zone
            if
            (
                valves_[valveI].detachInCylinderPatchID().active()
             && valves_[valveI].detachInPortPatchID().active()
             && valves_[valveI].detachFaces().size() > 0
            )
            {
                Info<< "Adding detach boundary for valve "
                    << valveI + 1 << endl;

                const vectorField& areas = Sf().internalField();

                const labelList& df = valves_[valveI].detachFaces();

                boolList flip(df.size(), false);

                const vector& pistonAxis = piston().cs().axis();

                forAll (df, dfI)
                {
                    if (isInternalFace(df[dfI]))
                    {
                        if ((areas[df[dfI]] & pistonAxis) > 0)
                        {
                            flip[dfI] = true;
                        }
                    }
                    else
                    {
                        FatalErrorIn
                        (
                            "void simpleEngineTopoFvMesh::"
                            "addZonesAndModifiers()"
                        )   << "found boundary face in valve detach definition"
                            << " for valve " << valveI + 1
                            << ".  This is not allowed.  Detach faces: "
                            << df << " nInternalFaces: " << nInternalFaces()
                            << abort(FatalError);
                    }
                }

                // Add detach face zone
                fz[nFaceZones] =
                    new faceZone
                    (
                        "detachFaceZoneV" + Foam::name(valveI + 1),
                        df,
                        flip,
                        nFaceZones,
                        faceZones()
                    );
                nFaceZones++;
            }
        }
Пример #23
0
/*
 * \brief Perform some MD
 * \details Evolve the current Configuration using a simple molecular dynamics algorithm.
 * 
 * This is a parallel routine, with processes operating in process groups.
 */
bool DUQ::md(Configuration& cfg, double cutoffDistance, int nSteps, double deltaT)
{
	// Check input values if necessary
	if (cutoffDistance < 0.0) cutoffDistance = pairPotentialRange_;
	const double cutoffSq = cutoffDistance * cutoffDistance;
	const double temperature = cfg.temperature();
	bool writeTraj = false;
	bool calcEnergy = true;
	int writeFreq = 10;

	// Print summary of parameters
	Messenger::print("MD: Number of steps = %i\n", nSteps);
	Messenger::print("MD: Cutoff distance is %f\n", cutoffDistance);
	Messenger::print("MD: Timestep = %10.3e ps\n", deltaT);
	if (writeTraj) Messenger::print("MD: Trajectory file '%s' will be appended.\n");
	else Messenger::print("MD: Trajectory file off.\n");
	Messenger::print("MD: Energy %s be calculated at each step.\n", calcEnergy ? "will" : "will not");
	Messenger::print("MD: Summary will be written every %i step(s).\n", writeFreq);

	// Create force arrays as simple double arrays (easier to sum with MPI) - others are Vec3<double> arrays
	Array<double> mass(cfg.nAtoms()), fx(cfg.nAtoms()), fy(cfg.nAtoms()), fz(cfg.nAtoms());
	Array< Vec3<double> > a(cfg.nAtoms()), v(cfg.nAtoms()), deltaR(cfg.nAtoms());

	// Variables
	int n, maxDeltaId;
	Atom* atoms = cfg.atoms();
	Atom* i;
	double maxDelta, deltaSq, massSum, tInstant, ke, tScale, pe;
	double deltaTSq = deltaT*deltaT;
	Vec3<double> vCom;
	double maxForce = 100.0;

	/*
	 * Calculation Begins
	 */
	
	// Assign random velocities to start... (grab atomic masses at the same time...)
	Messenger::print("Assigning random velocities...\n");
	vCom.zero();
	massSum = 0.0;
	for (n=0; n<cfg.nAtoms(); ++n)
	{
		i = cfg.atom(n);
		v[n].x = exp(DUQMath::random()-0.5) / sqrt(TWOPI);
		v[n].y = exp(DUQMath::random()-0.5) / sqrt(TWOPI);
		v[n].z = exp(DUQMath::random()-0.5) / sqrt(TWOPI);
		mass[n] = PeriodicTable::element(i->element()).isotope(0)->atomicWeight();
		vCom += v[n] * mass[n];
		massSum += mass[n];
	}

	// Remove velocity shift
	vCom /= massSum;
	v -= vCom;

	// Calculate instantaneous temperature
        // J = kg m2 s-2  -->   10 J = g Ang2 ps-2
        // If ke is in units of [g mol-1 Angstroms2 ps-2] then must use kb in units of 10 J mol-1 K-1 (= 0.8314462)
	const double kb = 0.8314462;
	ke = 0.0;
	pe = 0.0;
	for (n=0; n<cfg.nAtoms(); ++n) ke += 0.5 * mass[n] * v[n].dp(v[n]);
	tInstant = ke * 2.0 / (3.0 * cfg.nAtoms() * kb);
	
	// Rescale velocities for desired temperature
	tScale = sqrt(temperature / tInstant);
	for (n=0; n<cfg.nAtoms(); ++n) v[n] *= tScale;

	// Open trajectory file (if requested)
	LineParser trajParser;
	if (writeTraj)
	{
		Dnchar trajectoryFile = cfg.name();
		trajectoryFile.strcat(".md.xyz");
		if (Comm.master())
		{
			if ((!trajParser.openOutput(trajectoryFile, true)) || (!trajParser.isFileGoodForWriting()))
			{
				Messenger::error("Failed to open MD trajectory output file '%s'.\n", trajectoryFile.get());
				Comm.decide(false);
				return false;
			}
			Comm.decide(true);
		}
		else if (!Comm.decision()) return false;
	}

	// Write header to screen
	if (calcEnergy) Messenger::print("  Step             T(K)      K.E.(kJ/mol) P.E.(kJ/mol) Etot(kJ/mol)\n");
	else Messenger::print("  Step             T(K)      K.E.(kj/mol)\n");

	// Start a timer
	Timer timer;

	// Ready to do MD propagation of system
	timer.start();
	Comm.resetAccumulatedTime();
	for (int step=0; step<nSteps; ++step)
	{
// 		 deltaT = 0.001;
// 		 deltaTSq = deltaT*deltaT;
// 		// Velocity Verlet first stage (A) and zero forces
// 		// A:  r(t+dt) = r(t) + v(t)*dt + 0.5*a(t)*dt**2
// 		// A:  v(t+dt/2) = v(t) + 0.5*a(t)*dt
// 		// B:  a(t+dt) = F(t+dt)/m
// 		// B:  v(t+dt) = v(t+dt/2) + 0.5*a(t+dt)*dt
// 		maxDelta = 0.0;
// 		maxDeltaId = -1;
// 		for (n=0; n<cfg.nAtoms(); ++n)
// 		{
// 			// Calculate position deltas and determine maximum displacement for current timestep
// 			deltaR[n] = v[n]*deltaT + a[n]*0.5*deltaTSq;
// 			deltaSq = deltaR[n].magnitudeSq();
// 			if (deltaSq > maxDelta)
// 			{
// 				maxDelta = deltaSq;
// 				maxDeltaId = n;
// 			}
// 		}
// 		maxDelta = sqrt(maxDelta);
// 		Messenger::print("Current timestep (%e) will give a maximum displacement of %f Angstroms\n", deltaT, maxDelta);
// 		if (step > 0)
// 		{
// 			do
// 			{
// 				deltaT *= (v[maxDeltaId]*deltaT + a[maxDeltaId]*0.5*deltaTSq).magnitude() > maxDisplacement ? 0.99 : 1.01;
// 				deltaTSq = deltaT*deltaT;
// 			} while (fabs((v[maxDeltaId]*deltaT + a[maxDeltaId]*0.5*deltaTSq).magnitude() - maxDisplacement) > (maxDisplacement*0.05));
// 			// Adjust timestep to give maximum movement and avoid explosion
// 			// dR/dT = v + a*deltaT
// // 			printf("Deriv = %f %f\n", (v[maxDeltaId]+a[maxDeltaId]*deltaT).magnitude(), (v[maxDeltaId]+a[maxDeltaId]*deltaT).magnitude() / (maxDelta - 0.1));
// // 			deltaT = 1.0 / ((v[maxDeltaId]+a[maxDeltaId]*deltaT).magnitude() / 0.1);
// // 			printf("xxx = %f %f\n", 1.0 / deltaT, (maxDelta/maxDisplacement) * (v[maxDeltaId]+a[maxDeltaId]*deltaT).magnitude());
// // // 			deltaT = 0.000564480;
// // 			deltaT = 1.0 / ((maxDelta/maxDisplacement) * (v[maxDeltaId]+a[maxDeltaId]*deltaT).magnitude());
// // 			deltaT = deltaT/2.0;
// 			printf("New DeltaT = %f\n", deltaT);
// 		}

// 		// TEST - Check max displacement with new deltaT
// 		maxDelta = 0.0;
// 		for (n=0; n<cfg.nAtoms(); ++n)
// 		{
// 			// Calculate position deltas and determine maximum displacement for current timestep
// 			deltaR[n] = v[n]*deltaT + a[n]*0.5*deltaTSq;
// 			deltaSq = deltaR[n].magnitudeSq();
// 			if (deltaSq > maxDelta) maxDelta = deltaSq;
// 		}
// 		printf("New max delta = %f\n", sqrt(maxDelta));
		
		for (n=0; n<cfg.nAtoms(); ++n)
		{
			i = cfg.atom(n);

			// Propagate positions (by whole step)...
			i->translateCoordinates(v[n]*deltaT + a[n]*0.5*deltaTSq);

			// ...velocities (by half step)...
			v[n] += a[n]*0.5*deltaT;
			
			// Zero force ready for next calculation
			fx[n] = 0.0;
			fy[n] = 0.0;
			fz[n] = 0.0;
		}

		// Grain coordinates will have changed...
		cfg.updateGrains();

		// Calculate forces - must multiply by 100.0 to convert from kJ/mol to 10J/mol (internal MD units)
		totalForces(cfg, fx, fy, fz, cutoffSq);
		fx *= 100.0;
		fy *= 100.0;
		fz *= 100.0;

// 		// Cap forces
// 		for (n=0; n<cfg.nAtoms(); ++n)
// 		{
// 			// Calculate position deltas and determine maximum displacement for current timestep
// 			if (fx[n] < maxForce) fx[n] = -maxForce;
// 			else if (fx[n] > maxForce) fx[n] = maxForce;
// 			if (fy[n] < maxForce) fy[n] = -maxForce;
// 			else if (fy[n] > maxForce) fy[n] = maxForce;
// 			if (fz[n] < maxForce) fz[n] = -maxForce;
// 			else if (fz[n] > maxForce) fz[n] = maxForce;
// 		}

		// Velocity Verlet second stage (B) and velocity scaling
		// A:  r(t+dt) = r(t) + v(t)*dt + 0.5*a(t)*dt**2
		// A:  v(t+dt/2) = v(t) + 0.5*a(t)*dt
		// B:  a(t+dt) = F(t+dt)/m
		// B:  v(t+dt) = v(t+dt/2) + 0.5*a(t+dt)*dt
		ke = 0.0;
		for (n=0; n<cfg.nAtoms(); ++n)
		{
			// Determine new accelerations
			a[n].set(fx[n], fy[n], fz[n]);
			a[n] /= mass[n];

			// ..and finally velocities again (by second half-step)
			v[n] += a[n]*0.5*deltaT;
			
			ke += 0.5 * mass[n] * v[n].dp(v[n]);
		}

		// Rescale velocities for desired temperature
		tInstant = ke * 2.0 / (3.0 * cfg.nAtoms() * kb);
		tScale = sqrt(temperature / tInstant);
		v *= tScale;
		
		// Convert ke from 10J mol-1 to kJ/mol
		ke *= 0.01;

		// Calculate step energy
		if (calcEnergy) pe = intergrainEnergy(cfg) + intramolecularEnergy(cfg);
		
		// Write step summary?
		if (step%writeFreq == 0)
		{
			if (calcEnergy) Messenger::print("  %-10i    %10.3e   %10.3e   %10.3e   %10.3e\n", step+1, tInstant, ke, pe, ke+pe);
			else Messenger::print("  %-10i    %10.3e   %10.3e\n", step+1, tInstant, ke);
		}

		// Save trajectory frame
		if (writeTraj)
		{
			if (Comm.master())
			{
				// Write number of atoms
				trajParser.writeLineF("%i\n", cfg.nAtoms());

				// Construct and write header
				Dnchar header(-1, "Step %i of %i, T = %10.3e, ke = %10.3e", step+1, nSteps, tInstant, ke);
				if (calcEnergy) header.strcatf(", pe = %10.3e, tot = %10.3e", pe, ke+pe);
				trajParser.writeLineF("%s\n", header.get());
				// Write Atoms
				for (int n=0; n<cfg.nAtoms(); ++n)
				{
					i = cfg.atom(n);
					trajParser.writeLineF("%-3s   %10.3f  %10.3f  %10.3f\n", PeriodicTable::element(i->element()).symbol(), i->r().x, i->r().y, i->r().z);
				}
			}
			else if (!Comm.decision()) return false;
		}
        }
        timer.stop();

	// Close trajectory file
	if (writeTraj && Comm.master()) trajParser.closeFiles();

        Messenger::print("%i molecular dynamics steps performed (%s work, %s comms)\n", nSteps, timer.timeString(), Comm.accumulatedTimeString());

	// Increment configuration changeCount_
	cfg.incrementCoordinateIndex();

	/*
	 * Calculation End
	 */
	
	return true;
}
void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
{
    // Inner slider
    const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));

    // Outer slider
    const word outerSliderName
    (
        motionDict_.subDict("slider").lookup("outside")
    );

    bool initialised = false;

    // Check if zones and modifiers for motion action are present
    label insideZoneID = faceZones().findZoneID(innerSliderName + "Zone");
    label outsideZoneID = faceZones().findZoneID(outerSliderName + "Zone");

    if
    (
        insideZoneID > -1
     || outsideZoneID > -1
    )
    {
        // Zones found.  Check topo changer

        if (topoChanger_.empty())
        {
            FatalErrorIn
            (
                "void linearValveLayersFvMesh::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        initialised = true;
    }

    // Check if slider has been initialised on any of the processors
    reduce(initialised, orOp<bool>());

    if (initialised)
    {
        InfoIn("void linearValveLayersFvMesh::addZonesAndModifiers()")
            << "Zones and modifiers already present.  Skipping."
            << endl;

        return;
    }

    // Add zones and modifiers for motion action
    Info<< "Time = " << time().timeName() << endl
        << "Adding zones and modifiers to the mesh" << endl;

    // Add zones
    label nPz = 0;
    label nFz = 0;
    label nCz = 0;
    List<pointZone*> pz(pointZones().size() + 1);
    List<faceZone*> fz(faceZones().size() + 4);
    List<cellZone*> cz(cellZones().size());

    // Add a topology modifier
    topoChanger_.setSize(2);
    label nTc = 0;

    // Copy existing point zones
    forAll (pointZones(), zoneI)
    {
        pz[nPz] = pointZones()[zoneI].clone(pointZones()).ptr();
        nPz++;
    }  
Пример #25
0
void SimObjBase::setForce(double fx_, double fy_, double fz_)
{
	if (!dynamics()) { return; }

	fx(fx_); fy(fy_); fz(fz_);
}