Exemple #1
0
/** This test requires manual intervention to provide an appropriate file to read and write. */
void test_stream()
{
	FILE* fp = fopen("/tmp/opsec.p12", "r");
	FILE* fpo;
	zstr z1 = z_slurp_stream(fp);
	zstr z2;
	fpo = fopen("/tmp/opsec.p12.out", "w");
	cz_to_stream(cz(z1), fpo);
	fflush(fpo);
	fclose(fpo);
	z2 = z_slurp_stream(fopen("/tmp/opsec.p12.out", "r"));
	assert (zeq(cz(z1), cz(z2)));
}
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;
    }
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();
        }
Exemple #4
0
//-----------------------------------------------------------------------------
int sample_d(mglGraph *gr)
{
	mglData  a(50,50),b(50,50);
	mglData cx(50,50,50),cy(50,50,50),cz(50,50,50);
	a.Modify("0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))");
	b.Modify("0.6*cos(2*pi*x)*cos(3*pi*y) + 0.4*cos(3*pi*(x*y))");
	cx.Modify("0.01*(x-0.3)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(x-0.7)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)");
	cy.Modify("0.01*(y-0.5)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(y-0.5)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)");
	cz.Modify("0.01*(z-0.5)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(z-0.5)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)");

	gr->NewFrame();
	gr->Box();	gr->Axis("xy");
	gr->Puts(mglPoint(0,1.2,1),"Vector field (color ~ \\sqrt{a^2})","rC",8);
	gr->Vect(a,b,"","value 50");
	gr->EndFrame();

	gr->NewFrame();
	gr->Box();	gr->Axis("xy");
	gr->Puts(mglPoint(0,1.2,1),"Vector field (length ~ \\sqrt{a^2})","rC",8);
	gr->Vect(a,b);
	gr->EndFrame();

	gr->NewFrame();
	gr->Box();	gr->Axis("xy");
	gr->Puts(mglPoint(0,1.2,1),"Flow chart (blue - source)","rC",8);
	gr->Flow(a,b);
	gr->EndFrame();

	return gr->GetNumFrame();
}
 void
 post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z) {
   GlbRanges<ConstSetView> zr(z);
   RangesCompl<GlbRanges<ConstSetView> > zrc(zr);
   IntSet zc(zrc);
   ConstSetView cz(home, zc);
   rel_eq<SetView,SetView,ConstSetView>(home, x, op, y, cz);
 }
Exemple #6
0
int test_repr()
{
	zstr z2;
	czstr z = cs_as_cz("k");
	zstr rz = repr(z);
	#ifndef NDEBUG
	const czstr a = cs_as_cz("\\\\k");
	#endif

	assert (!strcmp((const char*)rz.buf, "k"));

	z = cs_as_cz("\\k");
	assert (z.len == 2);
	free_z(rz);
	rz = repr(z);
	assert (rz.len == 3);
	assert (a.len == 3);
	assert (!strcmp((const char*)rz.buf, "\\\\k"));
	assert (zeq(cz(rz), a));

	z2 = new_z(4);
	z2.buf[0] = 1;
	z2.buf[1] = 10;
	z2.buf[2] = 100;
	z2.buf[3] = 252;

	free_z(rz);
	rz = repr(cz(z2));
	assert (!strcmp((const char*)rz.buf, "\\x01\\x0ad\\xfc"));

	free_z(z2);
	z2 = new_z(1);
	z2.buf[0] = '\0';

	free_z(rz);
	rz = repr(cz(z2));
	assert (!strcmp((const char*)rz.buf, "\\x00"));

	free_z(z2);
	free_z(rz);
	return 0;
}
Exemple #7
0
int test_czstr()
{
	zstr a = cs_as_z("abcdefgh");
	czstr b = cz(a);

	printf("%d:%s\n", b.len, b.buf);
	/*b.len = 5;*/ /* should be a compile error since b is const. */
	/*b.buf = NULL;*/ /* should be a compile error since b is const. */
	/*b.buf[0] = '\0';*/ /* should be a compile error since b is a czstr. */
	return 0;
}
Exemple #8
0
double CZ(short state, double zmeas, double z0, double d0, double L, double (*Psi)(double z)){

	double c;
	FILE *f;

	if(state==1){			//both instability and stability considered
		c=cz(zmeas,z0,d0,L,(Psi),(*PsiStab));
	}else if(state==2){		//instability considered & stability not considered
		c=cz(zmeas,z0,d0,L,(Psi),(*Zero));
	}else if(state==3){		//instability not considered & stability considered
		c=cz(zmeas,z0,d0,L,(*Zero),(*PsiStab));
	}else if(state==4){		//both instability and stability not considered
		c=cz(zmeas,z0,d0,L,(*Zero),(*Zero));
	}else{
		f = fopen(FailedRunFile, "w");
		fprintf(f,"Error:: Value of state turbulence not admitted\n");
		fclose(f);
		t_error("Fatal Error! Geotop is closed. See failing report.");	
		c = 0.0;
	}

	return(c);
}
Exemple #9
0
int main(){
	char** word=cz(MAX);
	count*  ct=sz(MAX);
	int i=0;
	for (i=0;i<MAX;++i){
		word[i]=NULL;
		ct[i].pv=0;
	}
	create(word,ct);
	deal(word,ct);
	HeapSort(ct,MAX);
	sortput(word,ct);
	return 0;
}
Exemple #10
0
std::vector<ChebSegment> CFunctionToBspline::CFunctionToBsplineImpl::approxSegment(double umin, double umax, int depth)
{
    // to estimate the error, we do a chebycheff approximation at higher
    // degree and evaluate the coefficients
    int K = _degree + 4;
    
    double alpha = 0.5;
    
    math_Vector cx = cheb_approx(_xfunc, K+1, umin, umax);
    math_Vector cy = cheb_approx(_yfunc, K+1, umin, umax);
    math_Vector cz = cheb_approx(_zfunc, K+1, umin, umax);
    
    // estimate error
    double errx=0., erry = 0., errz = 0.;
    for (int i = _degree+1; i < K+1; ++i) {
        errx += fabs(cx(i));
        erry += fabs(cy(i));
        errz += fabs(cz(i));
    }
    double error = sqrt(errx*errx + erry*erry + errz*errz);
    
    if (error < _tol || depth >= _maxDepth) {
        // we can use this approximation, store to structure
        ChebSegment seg(_degree);
        seg.cx = subVec(cx, 0, _degree);
        seg.cy = subVec(cy, 0, _degree);
        seg.cz = subVec(cz, 0, _degree);
        seg.error = error;
        seg.umin = umin;
        seg.umax = umax;
        std::vector<ChebSegment> list;
        list.push_back(seg);
        return list;
    }
    else {
        // we have to split the range in two parts and do the approximation for each of them
        std::vector<ChebSegment> list1 = approxSegment(umin, umin + (umax-umin)*alpha, depth + 1);
        std::vector<ChebSegment> list2 = approxSegment(umin + (umax-umin)*alpha, umax, depth + 1);
        // combine lists
        list1.insert(list1.end(), list2.begin(), list2.end());
        return list1;
    }
    
}
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);
    }
Exemple #12
0
void
MainWindow::newPoints(int n)
{
  scene.periodic_triangulation.clear();
  scene.points.clear();

  CGAL::Random rnd(std::time(NULL));
  CGAL::Random_points_in_cube_3<Point_3, Creator> in_cube(1,rnd);

  for (int i=0 ; i<n ; i++) 
    if (scene.two_dimensional) {
      Point_3 rdpt = *in_cube++;
      scene.points.push_back(Point_3(rdpt.x(),rdpt.y(),0.));
    } else 
      scene.points.push_back(*in_cube++);

  Iso_cuboid_3 dom(-1,-1,-1,1,1,1);
  scene.periodic_triangulation.set_domain(dom);
  scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end());

  FT cx(0),cy(0),cz(0);
  for (int i=0 ; i<8 ; i++) {
    cx += dom[i].x();
    cy += dom[i].y();
    cy += dom[i].y();
  }
  qglviewer::Vec center(cx/8.,cy/8.,cz/8.);
  viewer->setSceneCenter(center);
  viewer->setSceneRadius(std::sqrt(
	  ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))
	  + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))
	  + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))));

  speedSlider->setRange(0,100);
  speedSlider->setSliderPosition(100);

  emit (sceneChanged()); 
}
Exemple #13
0
void
MainWindow::loadPoints()
{
  QString fileName = QFileDialog
    ::getOpenFileName(this, tr("Open point set"),
	".", tr("All files (*)"));
  if(fileName.isEmpty()) return;
  
  std::ifstream ifs(fileName.toLatin1().data() );
  scene.points.clear();
  Iso_cuboid_3 dom;
  ifs >> dom;
  std::copy(std::istream_iterator<Point_3>(ifs), 
      std::istream_iterator<Point_3>(),
      std::back_inserter(scene.points));

  scene.periodic_triangulation.set_domain(dom);
  scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end());

  FT cx(0),cy(0),cz(0);
  for (int i=0 ; i<8 ; i++) {
    cx += dom[i].x();
    cy += dom[i].y();
    cy += dom[i].y();
  }
  qglviewer::Vec center(cx/8.,cy/8.,cz/8.);
  viewer->setSceneCenter(center);
  viewer->setSceneRadius(std::sqrt(
	  ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))
	  + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))
	  + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin()))));

  speedSlider->setRange(0,100);
  speedSlider->setSliderPosition(100);

  emit (sceneChanged()); 
}
Exemple #14
0
 void
 post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z) {
   ComplementView<SetView> cz(z);
   rel_eq<SetView,SetView,ComplementView<SetView> >(home, x, op, y, cz);
 }
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::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++;
    }  
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++;
                }
            }
        }
Exemple #19
0
int main(){
	
	std::vector <int> mat(0);
	std::vector <int> cat(0); 
	std::vector <double> cx(0);
	std::vector <double> cy(0);
	std::vector <double> cz(0);
	std::vector <std::string> type(0);
	std::vector <std::string> filenames(0);
	
	// open coordinate file
	std::ifstream coord_file;
	coord_file.open("atoms-coords.cfg");

	// read in file header
	std::string dummy;
	
	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	// get number of atoms
	unsigned int n_atoms;
	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+17);
	n_atoms=atoi(dummy.c_str());

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	// get number of subsidiary files
	unsigned int n_files;
	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+22);
	n_files=atoi(dummy.c_str());

	for(int file=0; file<n_files; file++){
		getline(coord_file,dummy);
		filenames.push_back(dummy);
		//std::cout << filenames[file] << std::endl;
	}

	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;

	unsigned int n_local_atoms;
	getline(coord_file,dummy);
	//std::cout << dummy << std::endl;	
	n_local_atoms=atoi(dummy.c_str());
	
	// resize arrays
	mat.resize(n_atoms);
	cat.resize(n_atoms); 
	cx.resize(n_atoms);
	cy.resize(n_atoms);
	cz.resize(n_atoms);
	type.resize(n_atoms);
	
	unsigned int counter=0;
	
	// finish reading master file coordinates
	for(int i=0;i<n_local_atoms;i++){
		coord_file >> mat[counter] >> cat[counter] >> cx[counter] >> cy[counter] >> cz[counter] >> type[counter];
		counter++;
	}
	
	// close master file
	coord_file.close();
	
	// now read subsidiary files
	for(int file=0; file<n_files; file++){
		std::ifstream infile;
		infile.open(filenames[file].c_str());
		
		// read number of atoms in this file
		getline(infile,dummy);
		n_local_atoms=atoi(dummy.c_str());
		for(int i=0;i<n_local_atoms;i++){
			infile >> mat[counter] >> cat[counter] >> cx[counter] >> cy[counter] >> cz[counter] >> type[counter];
			counter++;
		}
		// close subsidiary file
		infile.close();
	}
	
	// check for correct read in of coordinates
	if(counter!=n_atoms) std::cerr << "Error in reading in coordinates" << std::endl;

	// Loop over all possible spin config files
	int ios = 0;
	int spinfile_counter=0;
	
	while(ios==0){
		
		std::stringstream file_sstr;
		file_sstr << "atoms-";
		file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter;
		file_sstr << ".cfg";
		std::string cfg_file = file_sstr.str();
		//const char* cfg_filec = cfg_file.c_str();

		std::ifstream spinfile;
		spinfile.open(cfg_file.c_str());

		if(spinfile.is_open()){
		
			std::cout << "Processing file: " << cfg_file << std::endl;
			
		// Read in file header
		getline(spinfile,dummy);
			
	//std::cout << dummy << std::endl;

	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;

	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;

	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;

	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;

	// get number of atoms
	unsigned int n_spins;
	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+17);
	n_spins=atoi(dummy.c_str());
	if(n_spins!=n_atoms) std::cerr << "Error! - mismatch between number of atoms in coordinate and spin files" << std::endl;
	
	getline(spinfile,dummy); // sys dimensions
	//std::cout << dummy << std::endl;
	char const field_delim = '\t';
	dummy.erase (dummy.begin(), dummy.begin()+18);
	std::istringstream ss(dummy);
	std::vector<double> val(0);
	for (std::string num; getline(ss, num, field_delim); ) {
		val.push_back(atof(num.c_str()));
		//std::cout << num << "\t" << val << std::endl;
	}
	double dim[3] = {val[0],val[1],val[2]};
	//std::cout << dim[0] << "\t" << dim[1] << "\t" << dim[2] << std::endl;

	getline(spinfile,dummy); // coord file

	getline(spinfile,dummy); // time
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+5);
	double time = atof(dummy.c_str());

	getline(spinfile,dummy); // field
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+6);
	double field = atof(dummy.c_str());

	getline(spinfile,dummy); // temp
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+12);
	double temperature = atof(dummy.c_str());
	
	// magnetisation
	getline(spinfile,dummy);
	dummy.erase (dummy.begin(), dummy.begin()+14);
	std::istringstream ss2(dummy);
	val.resize(0);
	for (std::string num; getline(ss2, num, field_delim); ) {
		val.push_back(atof(num.c_str()));
		//std::cout << num << "\t" << val << std::endl;
	}
	double mx = val[0];
	double my = val[1];
	double mz = val[2];
	
	// get number of materials
	unsigned int n_mat;
	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+20);
	n_mat=atoi(dummy.c_str());

	std::vector <material_t> material(n_mat); 
	for(int imat=0;imat<n_mat;imat++){
		getline(spinfile,dummy);
		//dummy.erase (dummy.begin(), dummy.begin()+22);
		std::istringstream ss(dummy);
		std::vector<double> val(0);
		for (std::string num; getline(ss, num, field_delim); ) {
			val.push_back(atof(num.c_str()));
		}
		material[imat].mu_s = val[0];
		material[imat].mx = val[1];
		material[imat].my = val[2];
		material[imat].mz = val[3];
		material[imat].magm = val[4];
		//std::cout << material[imat].mu_s << "\t" << material[imat].mx << "\t" << material[imat].my << "\t"  << material[imat].mz << "\t"  << material[imat].magm << std::endl;
	}
	
	// line
	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;
	
	// get number of subsidiary files
	unsigned int n_files;
	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;	
	dummy.erase (dummy.begin(), dummy.begin()+22);
	n_files=atoi(dummy.c_str());
	filenames.resize(0);
	
	for(int file=0; file<n_files; file++){
		getline(spinfile,dummy);
		filenames.push_back(dummy);
		//std::cout << filenames[file] << std::endl;
	}

	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;

	unsigned int n_local_atoms;
	getline(spinfile,dummy);
	//std::cout << dummy << std::endl;	
	n_local_atoms=atoi(dummy.c_str());

	// Open Povray Include File
	std::stringstream incpov_file_sstr;
	incpov_file_sstr << "atoms-";
	incpov_file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter;
	incpov_file_sstr << ".inc";
	std::string incpov_file = incpov_file_sstr.str();
	
	// Open Povray Output file
	std::stringstream pov_file_sstr;
	pov_file_sstr << "atoms-";
	pov_file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter;
	pov_file_sstr << ".pov";
	std::string pov_file = pov_file_sstr.str();

	std::ofstream pfile;
	pfile.open(pov_file.c_str());
	
	// Ouput povray file header
			double size, mag_vec;
			double vec[3];

			size = sqrt(dim[0]*dim[0] + dim[1]*dim[1] + dim[2]*dim[2]);
			vec[0] = (1.0/dim[0]);
			vec[1] = (1.0/dim[1]);
			vec[2] = (1.0/dim[2]);
			mag_vec = sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
			vec[0]/=mag_vec;
			vec[1]/=mag_vec;
			vec[2]/=mag_vec;

			pfile << "#include \"colors.inc\"" << std::endl;
			pfile << "#include \"metals.inc\""	<< std::endl;
			pfile << "#include \"screen.inc\""	<< std::endl;
			pfile << "#declare LX=" << dim[0]*0.5 << ";" << std::endl;
			pfile << "#declare LY=" << dim[1]*0.5 << ";" << std::endl;
			pfile << "#declare LZ=" << dim[2]*0.5 << ";" << std::endl;
			pfile << "#declare CX=" << size*vec[0]*6.0 << ";" << std::endl;
			pfile << "#declare CY=" << size*vec[1]*6.0 << ";" << std::endl;
			pfile << "#declare CZ=" << size*vec[2]*6.0 << ";" << std::endl;
	 		pfile << "#declare ref=0.4;" << std::endl;
			pfile << "global_settings { assumed_gamma 2.0 }" << std::endl;
			pfile << "background { color Gray30 }" << std::endl;

			pfile << "Set_Camera(<CX,CY,CZ>, <LX,LY,LZ>, 15)" << std::endl;
			pfile << "Set_Camera_Aspect(4,3)" << std::endl;
			pfile << "Set_Camera_Sky(<0,0,1>)" << std::endl;
			pfile << "light_source { <2*CX, 2*CY, 2*CZ> color White}" << std::endl;

			for(int imat=0;imat<n_mat;imat++){
				pfile << "#declare sscale"<< imat << "=2.0;" << std::endl;
				pfile << "#declare rscale"<< imat << "=1.2;" << std::endl;
				pfile << "#declare cscale"<< imat << "=3.54;" << std::endl;
				pfile << "#declare cones"<< imat << "=0;" << std::endl;
				pfile << "#declare arrows"<< imat << "=1;" << std::endl;
				pfile << "#declare spheres"<< imat << "=1;" << std::endl;
				pfile << "#declare cubes" << imat << "=0;" << std::endl;
				pfile << "#declare spincolors"<< imat << "=1;" << std::endl;
				pfile << "#declare spincolor"<< imat << "=pigment {color rgb < 0.1 0.1 0.1 >};" << std::endl;
				pfile << "#macro spinm"<< imat << "(cx,cy,cz,sx,sy,sz, cr,cg,cb)" << std::endl;
				pfile << "union{" << std::endl;
				pfile << "#if(spheres" << imat << ") sphere {<cx,cy,cz>,0.5*rscale"<< imat << "} #end" << std::endl;
				pfile << "#if(cubes" << imat << ") box {<cx-cscale"<< imat << "*0.5,cy-cscale" << imat << "*0.5,cz-cscale"<< imat << "*0.5>,<cx+cscale"<< imat << "*0.5,cy+cscale" << imat << "*0.5,cz+cscale"<< imat << "*0.5>} #end" << std::endl;
				pfile << "#if(cones"<< imat << ") cone {<cx+0.5*sx*sscale0,cy+0.5*sy*sscale"<< imat << ",cz+0.5*sz*sscale"<< imat << ">,0.0 <cx-0.5*sx*sscale"<< imat << ",cy-0.5*sy*sscale"<< imat << ",cz-0.5*sz*sscale"<< imat << ">,sscale0*0.5} #end" << std::endl;
				pfile << "#if(arrows" << imat << ") cylinder {<cx+sx*0.5*sscale"<< imat <<",cy+sy*0.5*sscale"<< imat <<",cz+sz*0.5*sscale"<< imat <<
							">,<cx-sx*0.5*sscale"<< imat <<",cy-sy*0.5*sscale"<< imat <<",cz-sz*0.5*sscale"<< imat <<">,sscale"<< imat <<"*0.12}";
				pfile << "cone {<cx+sx*0.5*1.6*sscale"<< imat <<",cy+sy*0.5*1.6*sscale"<< imat <<",cz+sz*0.5*1.6*sscale"<< imat <<">,sscale"<< imat <<"*0.0 <cx+sx*0.5*sscale"<< imat <<
							",cy+sy*0.5*sscale"<< imat <<",cz+sz*0.5*sscale"<< imat <<">,sscale"<< imat <<"*0.2} #end" << std::endl;
				pfile << "#if(spincolors"<< imat << ") texture { pigment {color rgb <cr cg cb>}finish {reflection {ref} diffuse 1 ambient 0}}" << std::endl;
				pfile << "#else texture { spincolor"<< imat << " finish {reflection {ref} diffuse 1 ambient 0}} #end" << std::endl;
				pfile << "}" << std::endl;
				pfile << "#end" << std::endl;
				
				
			}
			pfile << "#include \"" << incpov_file_sstr.str() << "\"" << std::endl;
	
		pfile.close();


	std::ofstream incpfile;
	incpfile.open(incpov_file.c_str());
	
	double sx,sy,sz,red,green,blue,ireal;
	unsigned int si=0;
	
	// Read in spin coordinates and output to povray file
	for(int i=0; i<n_local_atoms;i++){
		spinfile >> sx >> sy >> sz;
		rgb(sz,red,green,blue);
		incpfile << "spinm"<< mat[si] << "(" << cx[si] << "," << cy[si] << "," << cz[si] << "," 
		<< sx << "," << sy << "," << sz << "," << red << "," << green << "," << blue << ")" << std::endl;
		si++;
		
	}
	
		// close master file
	spinfile.close();
	
	// now read subsidiary files
	for(int file=0; file<n_files; file++){
		std::ifstream infile;
		infile.open(filenames[file].c_str());
		
		// read number of atoms in this file
		getline(infile,dummy);
		n_local_atoms=atoi(dummy.c_str());
		for(int i=0;i<n_local_atoms;i++){
			infile >> sx >> sy >> sz;
			rgb(sz,red,green,blue);
			incpfile << "spinm"<< mat[si] << "(" << cx[si] << "," << cy[si] << "," << cz[si] << "," 
			<< sx << "," << sy << "," << sz << "," << red << "," << green << "," << blue << ")" << std::endl;
			si++;
			
		}
		// close subsidiary file
		infile.close();
	}
	
	// close povray inc file
	incpfile.close();
	
	
		spinfile_counter++;
		}
		else ios=1;
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++;
            }
        }
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();
}