Exemplo n.º 1
0
Arquivo: 839.cpp Projeto: waiwai444/oj
bool equilibrium(int *weight)
{
	int wl, wr, dl, dr;
	bool el, er;
	el = er = true;
	scanf("%d%d%d%d", &wl, &dl, &wr, &dr);
	if(wl == 0)
	{
		el = equilibrium(&wl);
	}
	if(wr == 0)
	{
		er = equilibrium(&wr);
	}
	*weight = wl+wr;
	return el && er && wr*dr == wl*dl;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int thisnode, totalnodes;
	MPI_Status status;
	MPI_Init(&argc, &argv);

	int number_of_realizations = argc - 4;
	Real input_rho = atof(argv[1]);
	Real input_g = atof(argv[2]);
	Real input_alpha = atof(argv[3]);

	Real noise_list[number_of_realizations];
	for (int i = 0; i < number_of_realizations; i++)
		noise_list[i] = atof(argv[i + 4]);

	MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
	MPI_Comm_rank(MPI_COMM_WORLD, &thisnode);

	long int seed = 0 + thisnode*112488;

	while (!Chek_Seeds(seed, thisnode, totalnodes))
	{
		seed = time(NULL) + thisnode*112488;
		MPI_Barrier(MPI_COMM_WORLD);		
	}


	C2DVector::Init_Rand(seed);

	Real t_eq,t_sim;

	Box box;

	for (int i = 0; i < number_of_realizations; i++)
	{
		if ((i % totalnodes) == thisnode)
		{
			box.Init(input_rho, input_g, input_alpha, noise_list[i]);
			cout << "From processor " << thisnode << " Box information is: " << box.info.str() << endl;
			stringstream address;
			address.str("");
			address << box.info.str() << "-r-v.bin";
			ofstream out_file(address.str().c_str());

			t_eq = equilibrium(&box, equilibrium_step, saving_period, out_file);
			cout << i << "	From node: " << thisnode << "\t" << "elapsed time of equilibrium is \t" << t_eq << endl;

			t_sim = data_gathering(&box, total_step, saving_period, out_file);
			cout << i << "	From node: " << thisnode << "\t" << "elapsed time of simulation is \t" << t_sim << endl;

			out_file.close();
		}

	}

	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();
}
Exemplo n.º 3
0
void Run(int argc, char *argv[], Node* thisnode)
{
	Real input_rho = atof(argv[1]);
	Real input_kapa = atof(argv[2]);
	Real input_mu_plus = atof(argv[3]);
	Real input_mu_minus = atof(argv[4]);
	Real input_D = atof(argv[5]);

	Real t_eq,t_sim;

	LyapunovBox box;
	box.Init(thisnode, input_rho);

	MarkusParticle::kapa = input_kapa;
	MarkusParticle::mu_plus = input_mu_plus;
	MarkusParticle::mu_minus = input_mu_minus;

	Particle::D_phi = input_D;
	Particle::noise_amplitude = sqrt(2*input_D) / sqrt(dt); // noise amplitude depends on the step (dt) because of ito calculation. If we have epsilon in our differential equation and we descritise it with time steps dt, the noise in each step that we add is epsilon times sqrt(dt) if we factorise it with a dt we have dt*(epsilon/sqrt(dt)).
	box.info.str("");
	box.info << "rho=" << box.density <<  "-k=" << Particle::kapa << "-mu+=" << Particle::mu_plus << "-mu-=" << Particle::mu_minus << "-Dphi=" << Particle::D_phi << "-L=" << Lx;

	if (thisnode->node_id == 0)
	{
		stringstream address;
		address.str("");
		address << box.info.str() << "-r-v.bin";
		box.trajfile.open(address.str().c_str());
		address.str("");
		address << "deviation-" << box.info.str() << ".dat";
		box.outfile.open(address.str().c_str());
	}

	if (thisnode->node_id == 0)
		cout << " Box information is: " << box.info.str() << endl;

	MPI_Barrier(MPI_COMM_WORLD);
	t_eq = equilibrium(&box, equilibrium_step, saving_period);
	MPI_Barrier(MPI_COMM_WORLD);

	if (thisnode->node_id == 0)
		cout << " Done in " << floor(t_eq / 60.0) << " minutes and " << t_eq - 60*floor(t_eq / 60.0) << " s" << endl;

	MPI_Barrier(MPI_COMM_WORLD);
	t_sim = box.Lyapunov_Exponent(10,100, 0.1, 100, 0.01, 20, 5);
	MPI_Barrier(MPI_COMM_WORLD);

	if (thisnode->node_id == 0)
	{
		cout << " Done in " << floor(t_sim / 60.0) << " minutes and " << t_sim - 60*floor(t_sim / 60.0) << " s" << endl;
		box.outfile.close();
		box.trajfile.close();
	}

	MPI_Barrier(MPI_COMM_WORLD);
}
void Change_Noise(int argc, char *argv[], Node* thisnode)
{
	Real input_rho = atof(argv[1]);
	Real input_g = atof(argv[2]);

	vector<Real> noise_list;
	for (int i = 3; i < argc; i++)
		noise_list.push_back(atof(argv[i]));

	Real t_eq,t_sim;

	Particle::noise_amplitude = 0;
	Particle::g = input_g;

	Box box;
	box.Init(thisnode, input_rho);

	ofstream out_file;

	for (int i = 0; i < noise_list.size(); i++)
	{
		Particle::noise_amplitude = noise_list[i] / sqrt(dt); // noise amplitude depends on the step (dt) because of ito calculation. If we have epsilon in our differential equation and we descritise it with time steps dt, the noise in each step that we add is epsilon times sqrt(dt) if we factorise it with a dt we have dt*(epsilon/sqrt(dt)).
		box.info.str("");
		box.info << "rho=" << box.density <<  "-g=" << Particle::g << "-noise=" << noise_list[i] << "-cooling";

		if (thisnode->node_id == 0)
		{
			stringstream address;
			address.str("");
			address << box.info.str() << "-r-v.bin";
			out_file.open(address.str().c_str());
		}

		if (thisnode->node_id == 0)
			cout << " Box information is: " << box.info.str() << endl;

		MPI_Barrier(MPI_COMM_WORLD);
		t_eq = equilibrium(&box, equilibrium_step, saving_period, out_file);
		MPI_Barrier(MPI_COMM_WORLD);

		if (thisnode->node_id == 0)
			cout << " Done in " << (t_eq / 60.0) << " minutes" << endl;

		t_sim = data_gathering(&box, total_step, saving_period, out_file);
		MPI_Barrier(MPI_COMM_WORLD);

		if (thisnode->node_id == 0)
		{
			cout << " Done in " << (t_sim / 60.0) << " minutes" << endl;
			out_file.close();
		}
	}
	MPI_Barrier(MPI_COMM_WORLD);
}
Exemplo n.º 5
0
Arquivo: 839.cpp Projeto: waiwai444/oj
int main()
{
	int tc, weight;
	scanf("%d", &tc);
	while(tc--)
	{
		if(equilibrium(&weight))
			printf("YES\n");
		else
			printf("NO\n");
		if(tc)
			printf("\n");
	}
	return 0;
}
Exemplo n.º 6
0
    void Simulation::collission(VelocitySet *set, std::vector<Node> &nodes)
    {
        double omega = d_domain->omega;
        for (auto node : nodes)
        {
            size_t nDirections = set->nDirections;
            // switch to the newly streamed distribution values
            for (size_t dir = 0; dir < nDirections; ++dir)
            {
                node.distributions[dir].value = node.distributions[dir].nextValue;
                node.distributions[dir].nextValue = -1;
            }

            // apply BGK approximation
            auto node_equilibrium = equilibrium(set, node);
            for (size_t dir = 0; dir < nDirections; ++dir)
                node.distributions[dir].value = node.distributions[dir].value -
                    omega * (node.distributions[dir].value - node_equilibrium[dir]);

            delete[] node_equilibrium;
        }
    }
Exemplo n.º 7
0
void compute_fluid_gradient_tensor(){
  int x, y, pp, i, j;
  pop p_eq;
  tensor S;

  for (y=1; y<NY+1; y++){
    for (x=1; x<NX+1; x++){

      /* equilibrium distribution */
      p_eq=equilibrium(p,y,x);

      S.xx = S.xy = S.yx = S.yy = 0.0;
      for (pp=0; pp<9; pp++){
	S.xx += cx[pp]*cx[pp]*(p[IDX(y,x)].p[pp] - p_eq.p[pp]);
	S.xy += cx[pp]*cy[pp]*(p[IDX(y,x)].p[pp] - p_eq.p[pp]);
	S.yx += cy[pp]*cx[pp]*(p[IDX(y,x)].p[pp] - p_eq.p[pp]);
	S.yy += cy[pp]*cy[pp]*(p[IDX(y,x)].p[pp] - p_eq.p[pp]);
      }
      gradv[IDX(y,x)]=S;

      //fprintf(stderr,"S.xx %g, S.xy %g, S.yx %g, S.yy %g\n", S.xx, S.xy, S.yx, S.yy);fflush(stderr);
    }
  }
}
Exemplo n.º 8
0
void Change_Noise(int argc, char *argv[], Node* thisnode)
{
	if (argc < 5)
	{
		if (box.thisnode == 0)
			cout << "arguments are: \n" << "density,\tmu+,\tmu-,Dphi" << endl;
		exit(0);
	}
	Real input_rho = atof(argv[1]);
	Real input_mu_plus = atof(argv[2]);
	Real input_mu_minus = atof(argv[3]);

	vector<Real> D_list;
	for (int i = 4; i < argc; i++)
		D_list.push_back(atof(argv[i]));

	Real t_eq,t_sim;

	Box box;
	box.Init(thisnode, input_rho);

	MarkusParticle::mu_plus = input_mu_plus;
	MarkusParticle::mu_minus = input_mu_minus;

	ofstream out_file;

	for (int i = 0; i < D_list.size(); i++)
	{
		Particle::D_phi = D_list[i];
		Particle::noise_amplitude = sqrt(2*D_list[i]) / sqrt(dt); // noise amplitude depends on the step (dt) because of ito calculation. If we have epsilon in our differential equation and we descritise it with time steps dt, the noise in each step that we add is epsilon times sqrt(dt) if we factorise it with a dt we have dt*(epsilon/sqrt(dt)).
		box.info.str("");
		box.info << "rho=" << box.density <<  "-mu+=" << Particle::mu_plus << "-mu-=" << Particle::mu_minus << "-Dphi=" << Particle::D_phi << "-L=" << Lx;

		if (thisnode->node_id == 0)
		{
			stringstream address;
			address.str("");
			address << box.info.str() << "-r-v.bin";
			out_file.open(address.str().c_str());
		}

		if (thisnode->node_id == 0)
			cout << " Box information is: " << box.info.str() << endl;

		MPI_Barrier(MPI_COMM_WORLD);
		t_eq = equilibrium(&box, equilibrium_step, saving_period, out_file);
		MPI_Barrier(MPI_COMM_WORLD);

		if (thisnode->node_id == 0)
			cout << " Done in " << (t_eq / 60.0) << " minutes" << endl;

		t_sim = data_gathering(&box, total_step, saving_period, out_file);
		MPI_Barrier(MPI_COMM_WORLD);

		if (thisnode->node_id == 0)
		{
			cout << " Done in " << (t_sim / 60.0) << " minutes" << endl;
			out_file.close();
		}
	}
	MPI_Barrier(MPI_COMM_WORLD);
}
Exemplo n.º 9
0
// add using dual numbers
// combine diffeq and incorporation for direct RedTrace computation
void DerivativeRedTrace(float *red_out, float *ival_offset, float *da_offset, float *dk_offset,
                        int npts, float *deltaFrameSeconds, float *deltaFrame,
        float *nuc_rise_ptr, int SUB_STEPS, int my_start,
        Dual A, float SP,
        Dual kr, float kmax, float d,
                        float sens, float gain, float tauB,
                        PoissonCDFApproxMemo *math_poiss)
{
    int i;
    Dual totocc, totgen;
//    mixed_poisson_struct mix_ctrl;
    MixtureMemo mix_memo;

    Dual pact,pact_new;
    Dual  c_dntp_top, c_dntp_bot;
    Dual  hplus_events_sum, hplus_events_current; // mean events per molecule, cumulative and current

    Dual ldt;
    Dual Ival;

    Dual One(1.0);
    Dual Zero(0.0);
    Dual Half(0.5);

    Dual xSP(SP);
    Dual xkmax(kmax);
    Dual xd(d);

    Dual xA = mix_memo.Generate(A,math_poiss);
    //xA.Dump("xA");
    //A = InitializeMixture(&mix_ctrl,A,MAX_HPLEN); // initialize Poisson with correct amplitude which maxes out at MAX_HPLEN
    mix_memo.ScaleMixture(SP);
    //ScaleMixture(&mix_ctrl,SP); // scale mixture fractions to proper number of molecules
    pact = Dual(mix_memo.total_live);  // active polymerases // wrong???
    //pact.Dump("pact");
    //Dual pact_zero = pact;
    totocc = xSP*xA;  // how many hydrogens we'll eventually generate
    //totocc.Dump("totocc");
    totgen = totocc;  // number remaining to generate
    //totgen.Dump("totgen");
    c_dntp_bot = Zero; // concentration of dNTP in the well
    c_dntp_top = Zero; // concentration at top
    hplus_events_sum = hplus_events_current = Zero; // Events per molecule

    memset(ival_offset,0,sizeof(float[my_start]));  // zero the points we don't compute
    memset(da_offset,0,sizeof(float[my_start]));  // zero the points we don't compute
    memset(dk_offset,0,sizeof(float[my_start]));  // zero the points we don't compute

    Dual scaled_kr = kr*Dual(n_to_uM_conv)/xd; // convert molecules of polymerase to active concentraction
    Dual half_kr = kr *Half; // for averaging
   // kr.Dump("kr");
    //scaled_kr.Dump("scaled_kr");
    //half_kr.Dump("half_kr");

    // first non-zero index of the computed [dNTP] array for this nucleotide
    int c_dntp_top_ndx = my_start*SUB_STEPS;
    Dual c_dntp_bot_plus_kmax = Dual(1.0/kmax);
    Dual c_dntp_old_effect = Zero;
    Dual c_dntp_new_effect = Zero;
    Dual cur_gen(0.0);
    Dual equilibrium(0.0);
    int st;

    // trace variables
    Dual old_val = Zero;
    Dual cur_val = Zero;
    Dual run_sum = Zero;
    Dual half_dt = Zero;
    Dual TauB(tauB);
    Dual SENS(sens);

    memset(red_out,0,sizeof(float[my_start]));

    for (i=my_start;i < npts;i++)
    {
        // Do one prediction time step
        if (totgen.a > 0.0)
        {
          // need to calculate incorporation
            ldt = (deltaFrameSeconds[i]/SUB_STEPS); // multiply by half_kr out here, because I'm going to use it twice?
            ldt *= half_kr; // scale time by rate out here
            //ldt.Dump("ldt");
            for (st=1; (st <= SUB_STEPS) && (totgen.a > 0.0);st++)
            {
                c_dntp_bot.a = nuc_rise_ptr[c_dntp_top_ndx];
                c_dntp_top_ndx++;
                // calculate denominator
                equilibrium = c_dntp_bot_plus_kmax;
                equilibrium *= pact;
                equilibrium *= scaled_kr;
                equilibrium += One;
                c_dntp_bot /= equilibrium;
                //c_dntp_bot.Dump("c_dntp_bot");
                // the level at which new nucs are used up as fast as they diffuse in

                c_dntp_bot_plus_kmax.Reciprocal(c_dntp_bot + xkmax); // scale for michaelis-menten kinetics, assuming nucs are limiting factor
                //c_dntp_bot_plus_kmax.Dump("plus_kmax");
                // Now compute effect of concentration on enzyme rate
                c_dntp_old_effect = c_dntp_new_effect;
                c_dntp_new_effect = c_dntp_bot;
                c_dntp_new_effect *= c_dntp_bot_plus_kmax; // current effect of concentration on enzyme rate
                //c_dntp_new_effect.Dump("c_dntp_new");

                // update events per molecule
                hplus_events_current = c_dntp_old_effect;
                hplus_events_current += c_dntp_new_effect;
                hplus_events_current *= ldt;
                //hplus_events_current.Dump("current");  // events per molecule is average rate * time of rate
                hplus_events_sum += hplus_events_current;
                //hplus_events_sum.Dump("sum");


                // how many active molecules left at end of time period given poisson process with total intensity of events
                // exp(-t) * (1+t+t^2/+t^3/6+...) where we interpolate between polynomial lengths by A
                // exp(-t) ( 1+... + frac*(t^k/k!)) where k = ceil(A-1) and frac = A-floor(A), for A>=1
                pact_new = mix_memo.GetStep(hplus_events_sum);
                //pact_new = pact_zero;
                //pact_new.Dump("pact_new");
                // how many hplus were generated
                // reuse pact for average
                // reuse hplus-events_current for total events
                pact += pact_new;
                pact *= Half; // average number of molecules
                //hplus_events_current *= pact; // events/molecule *= molecule is total events
                totgen -= pact*hplus_events_current;  // active molecules * events per molecule
                //totgen.Dump("totgen");
                pact = pact_new; // update to current number of molecules
                //pact.Dump("pact");
            }

            if (totgen.a < 0.0) totgen = Zero;
        }
        Ival =  totocc;
        Ival -= totgen;
        ival_offset[i] = Ival.a;

        Ival *= SENS; // convert from hydrogen to counts

        // Now compute trace
        // trace
        half_dt = deltaFrame[i]*0.5;

        // calculate new value
        Ival *= TauB;
        cur_val = Ival;
        cur_val -= run_sum;
        old_val *= half_dt; // update
        cur_val -= old_val;
        cur_val /= (TauB+half_dt);
        // update run sum
        run_sum += old_val; // reuse update
        run_sum += cur_val*half_dt;
        old_val = cur_val; // set for next value

        //cur_val *= gain;  // gain=1.0 always currently
        
        red_out[i] = cur_val.a;
        da_offset[i] = cur_val.da;
        dk_offset[i] = cur_val.dk;
        // now we have done one prediction time step
    }
}
Exemplo n.º 10
0
void updateHaptics(void)
{
    double timeV = 0.0;

    cLabel* label = new cLabel();
    cLabel* label2 = new cLabel();
    rootLabels->addChild(label);
    rootLabels->addChild(label2);
    label->setPos(0, 0, 0);
    label2->setPos(0, -20, 0);
    label->m_fontColor.set(1.0, 1.0, 1.0);
    label2->m_fontColor.set(1.0, 1.0, 1.0);

    // main haptic simulation loop
    while(simulationRunning)
    {
        float deltaTime = pClock.getCurrentTimeSeconds() - lastTime;
        lastTime = pClock.getCurrentTimeSeconds();

        cVector3d equilibrium (0.0, 0.0, 0.0);
        cVector3d pos0 (0.0, 0.0, 0.0), pos1 (0.0, 0.0, 0.0);

        // for each device
        int i=0;
        while (i < numHapticDevices)
        {
            // read position of haptic device
            cVector3d newPosition;
            hapticDevices[i]->getPosition(newPosition);
            newPosition = deviceToWorld(newPosition, i);

            ((i == 0)? pos0 : pos1) = newPosition;

            // read orientation of haptic device
            cMatrix3d newRotation;
            hapticDevices[i]->getRotation(newRotation);

            // update position and orientation of cursor
            cursors[i]->setPos(newPosition);
            cursors[i]->setRot(newRotation);

            // read linear velocity from device
            cVector3d linearVelocity;
            hapticDevices[i]->getLinearVelocity(linearVelocity);

            // update arrow
//            velocityVectors[i]->m_pointA = newPosition;
//            velocityVectors[i]->m_pointB = cAdd(newPosition, linearVelocity);

            // read user button status
            bool buttonStatus;
            hapticDevices[i]->getUserSwitch(0, buttonStatus);

            // adjustthe  color of the cursor according to the status of
            // the user switch (ON = TRUE / OFF = FALSE)
            if (i == 0)
                cursors[i]->m_material = matCursor2;
            else
                cursors[i]->m_material = matCursor1;

            // increment counter
            i++;
        }

        double f0, f1;
        f0 = pos0.length();
        f1 = pos1.length();

        f0 = f0/(f0 + f1);
        f1 = 1.0 - f0;

        equilibrium = pos1 + (pos0 - pos1)*f0;

        // Update the position of the sun
        cVector3d dir = pos1 - pos0;
        double dist = dir.length();
        dir.normalize();

        double vibrationSpeed = 20.0;
        double vibrationAmount = 0.02;

        //sun->setPos(sun->getPos()*(1.0 - deltaTime*speed) + equilibrium*(deltaTime*speed));
        //timeV += deltaTime*vibrationSpeed*(0.7 - cAbs(f0 - 0.5)*2.0);
        sun->setPos(equilibrium /*+ vibrationAmount*dir*cSinRad(timeV)*/);

        // Update logic
        if (!calibrationFinished) {
            label->m_string = "Calibrating, please move the haptic devices around in order to determine their limitations in movement.";
            label2->m_string = "Press 'c' to finish calibration.";

            if (sun->getPos().x < min.x)
                min.x = sun->getPos().x;
            if (sun->getPos().y < min.y)
                min.y = sun->getPos().y;
            if (sun->getPos().z < min.z)
                min.z = sun->getPos().z;

            if (sun->getPos().x > max.x)
                max.x = sun->getPos().x;
            if (sun->getPos().y > max.y)
                max.y = sun->getPos().y;
            if (sun->getPos().z > max.z)
                max.z = sun->getPos().z;
        } else if (logic->isReady()) {
            if (logic->gameIsOver() && !scoreDisplayed) {
                std::stringstream strs;
                strs << logic->playTime();
                std::string playString = strs.str();

                // define its position, color and string message
                label->m_string = "Congratulation! Your Time: " + playString;
                label2->m_string = "Press 'r' to restart!";

                for (i = 0; i < numHapticDevices; i++) {
                    cVector3d zero(0.0, 0.0, 0.0);
                    hapticDevices[i]->setForce(zero);
                }

                scoreDisplayed = true;
            } else if (!scoreDisplayed) {
                label->m_string = "";
                label2->m_string = "";

                logic->update(deltaTime);

            }

            for (i = 0; i < numHapticDevices; i++) {
                // compute a reaction force
                cVector3d newForce (0,0,0);

                cVector3d devicePosition;
                hapticDevices[i]->getPosition(devicePosition);
                devicePosition = deviceToWorld(devicePosition, i);

                double k = 0.4;
                if (test == 1) k = 0.3;
                double dist = (devicePosition - sun->getPos()).length();
                //dist=dist-0.1;

                newForce = k*(devicePosition - sun->getPos())/(dist*dist*dist);
                //double intensity = (newForce.length())*1.0;
                //newForce.normalize();
                //newForce *= intensity;

    //            newForce = k*(devicePosition - sun->getPos())/(dist*dist*dist);

                if (i == 0) {  // Device on positive X (RIGHT)
                    newForce.x *= -1.0;
                    newForce.y *= -1.0;
                }

                // send computed force to haptic device
    //            bool status = true;
    //            if (hapticDevices[i]->getUserSwitch(0))
    //                printf("button pressed\n");

                // Check if the sphere is in the target area. If so, vibrate
                cVector3d vibrationForce(0.0, 0.0, 0.0);
                if (logic->sphereInTarget() && !logic->gameIsOver()) {
                    Cube* target = logic->getTarget();
                    double dist = target->getPos().distance(sun->getPos());
                    double factor = 1.0 - dist/(target->size/2.0);
                    timeV += deltaTime * (0.5 + factor/2.0);

                    double f = 2*cSinRad(40*timeV);
                    vibrationForce = cVector3d(f, f, f);
                }

                newForce += vibrationForce;
                if (test <= 2 || i == 0)
                    hapticDevices[i]->setForce(newForce);
                else {
                    cVector3d zero;
                    zero.zero();
                    hapticDevices[i]->setForce(zero);
                }
          }
        }
    }
    
    // exit haptics thread
    simulationFinished = true;
}
Exemplo n.º 11
0
int main( int argc, char **argv ) {

  

    int pid, world;
    
    // Initialize mpi
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&pid);
    MPI_Comm_size(MPI_COMM_WORLD,&world);
    
    /* if(pid == 0) { */
    /* 	printf("                    \n"); */
    /* 	printf("     o-----o-----o  \n"); */
    /* 	printf("     | -   |   - |  \n"); */
    /* 	printf("     |   - | -   |  \n"); */
    /* 	printf("     o<----o---->o       Two Phases - Lattice-Boltzmann solver with heat transfer. Pseudopotential model\n"); */
    /* 	printf("     |   - | -   |  \n"); */
    /* 	printf("     | -   |   - |  \n"); */
    /* 	printf("     o-----o-----o  \n"); */
    /* } */



    
    // Simulation properties
    
    latticeMesh mesh = readLatticeMesh( pid );

    mesh.lattice = setLatticeInfo();

    mesh.EOS = readEOSInfo();

    vtkInfo vtk = readVTKInfo();
    

    
    

    // Macroscopic fields
    
    macroFields mfields;
    

    
    // Density

    createScalarField( &mesh, &mfields.rho, "rho", MUST_READ);

    
    
    // Velocity

    createVectorField( &mesh, &mfields.U, 3, "U", MUST_READ);
    

    
    // Temperature

    createScalarField( &mesh, &mfields.T, "T", MUST_READ);



    // LBE fields

    // Navier-Stokes field

    lbeField f;
    
    createLbeField( &mesh, &f, "f", MUST_READ);

    f.update = 1;
    
    /* if(frozen == 0) { f.update = 0; } */


    
    /* // Energy field */

    /* lbeField g; */
    
    /* createLbeField( &mesh, &g, "g"); */

    /* if(ht == 0) { g.update = 0; } */
    
    

    // Initial equilibrium distribution
   
    equilibrium(&mesh, &mfields, &f);
    
    /* equilibrium(&mesh, &mfields, &g); */





    // Update macroscopic interaction force

    mfields.Fi = matrixDoubleAlloc( mesh.mesh.nPoints, 3, -1 );
    
    interForce( &mesh, &mfields );
    
    syncVectorField( &mesh, mfields.Fi );



    /* // Heat source */

    /* heatSource( &mesh, &mfields, &g ); */

    /* syncScalarField( &mesh, g.scalarSource ); */
    
   
    /* if(pid == 0){printf("\n\n");} */








    
    // Advance in time. Collide, stream, update and write
    
    while( updateTime(&mesh.time) ) {


	
    	// Collide f (Navier-Stokes)
	
    	collision( &mesh, &mfields, &f );


		
    	/* // Collide g (Temperature) */

    	/* collision( &mesh, &mfields, &g ); */
	
	
	
    	/* // Stream f */
	
    	/* lbstream( &mesh, &f ); */

	
	
    	/* // Stream g */
	
    	/* lbstream( &mesh, &g ); */


	

    	/* // Apply boundary conditions */
	
    	/* updateBoundaries( &mesh, &mfields, &f ); */
	
    	/* updateBoundaries( &mesh, &mfields, &g ); */


	
	
    	/* // Sync fields */

    	/* if( frozen != 0 ) {  syncPdfField( &mesh, f.value );  } */

    	/* if( ht != 0 ) {  syncPdfField( &mesh, g.value );  } */

	
	
	


    	/* // Update macroscopic density */
	
    	/* macroDensity( &mesh, &mfields, &f ); */


	
	
	
    	/* // Update macroscopic temperature */
	
    	/* if( ht != 0 )     { */

    	/*     heatSource( &mesh, &mfields, &g ); */

    	/*     syncScalarField( &mesh, g.scalarSource ); */

    	/* } */

    	/* macroTemperature( &mesh, &mfields, &g ); */


	
	
    	/* // Update macroscopic velocity */
	
    	/* if( frozen != 0 ) { */

    	/*     interForce( &mesh, &mfields ); */

    	/*     syncVectorField( &mesh, mfields.Fi ); */

    	/* } */

    	/* macroVelocity( &mesh, &mfields, &f ); */


	
	
    	// Write fields
	
    	if( writeFlag(&mesh.time) ) {

	    
    	    if(pid == 0) {
		
    		printf( "Time = %d\n", mesh.time.current );
		
    		printf("Elapsed time = %.2f seconds\n\n", elapsed(&mesh.time) );
		
    	    }


	    
    	    // VTK files
	    
    	    writeMeshToVTK( &mesh, &vtk );

    	    writeScalarField( "rho", mfields.rho, &mesh );

    	    writeScalarField( "T", mfields.T, &mesh );

    	    writeVectorToVTK( "U", mfields.U, &mesh );

    	    writePdfToVTK( "f", f.value, &mesh );

    	    /* writePdfToVTK( "g", g.value, &mesh ); */

	    if(mesh.time.data == pvtu) {
	    
		writePvtuExtra( &mesh, &vtk );

		writeMainPvd();

	    }

	    
	    
    	}
	

    }



    
    // Print info
    if(pid == 0) {
	
    	printf("\n  Finished in %.2f seconds \n\n", elapsed(&mesh.time) );
	
    }


    
    MPI_Finalize();

    
    return 0;
    
}
Exemplo n.º 12
0
void wet::duplicateDrop1(void)
{
	
	int kdup ;
	int xkdup, ykdup, zkdup;
	//double *nGlobal;
	
	//nGlobal = new double[N];
	
	generatePhiGlobal();
	generateNGlobal();
	generateGlobalMask();
	
	MPI_Bcast(pGlobal,N,MPI_DOUBLE,ROOT,MPI_COMM_WORLD);
	MPI_Bcast(nGlobal,N,MPI_DOUBLE,ROOT,MPI_COMM_WORLD);
	MPI_Bcast(maskGlobal,N,MPI_DOUBLE,ROOT,MPI_COMM_WORLD);
	
	/*for (k=0; k<N;k++){
		cout << " - Process " << rank <<" k " << k << " pG[k] " << pGlobal[k] << endl;
	}*/
	initialise(); //pGlobal, nGlobal, maskGlobal not initialised 
	
	/*for (k=0; k < N/2 ;k++){
		cout << " - - Process " << rank <<" k " << k << " pG[k] " << pGlobal[k] << endl;
	}*/
	
	cout << "Proces " << rank <<": re-initialised" << endl;
	cout << "Proces " << rank << ": new LX = " << LX << endl;
	
	//saveFiles(); //take OUT
	
	if (rank < size/2){          //first half of the box, drop just copied over
		
		
		for (k=k1 ; k< k2; k++) {
			
			
			kdup = k-k1 + rank * (k2-k1);
			
			xkdup =int(kdup/(float) (LZ*LY));
			ykdup =int((kdup-xkdup*LZ*LY)/(float) LZ);
			zkdup =kdup-xkdup*LZ*LY-ykdup*LZ;
			
			
			p[k] = pGlobal[kdup];
			n[k] = nGlobal[kdup];
			mask[k] = maskGlobal[kdup];
			
			//computeCoordinate(k);
			//cout << "-- Process " << rank <<" k= "<< k << " xk yk zk " << xk << " " << yk << " " << zk << " " << "p[k] = " << p[k] << "; kdup= "<< kdup << " xk yk zk " << xkdup << " " << ykdup << " " << zkdup <<" " << "pG[kdup] = " << pGlobal[kdup] << endl;
			//cout << "--- Process " << rank <<": k "<< k << ", kdup in pG "<< kdup <<endl;
			
		}
		
	}
	if (rank >= size/2){
		
		
		for (int kk=k1 ; kk< k2; kk++) {
			
			kdup = kk;
			computeCoordinate(kk);      
			xk = LX-1 - xk;
			invComputeCoordinate();   // sets k, here value on Global arrays; invCompCooordinate not for parallel setup, so convenient
			
			
			xkdup =int(kdup/(float) (LZ*LY));
			ykdup =int((kdup-xkdup*LZ*LY)/(float) LZ);
			zkdup =kdup-xkdup*LZ*LY-ykdup*LZ;
			xkdup =xkdup+rank*LX/size-1%LX;

			
			p[kdup] = pGlobal[k];
			n[kdup] = nGlobal[k];
			mask[kdup] = maskGlobal[k];
			
			//computeCoordinate(k);
			//cout << "<< Process " << rank <<" k= "<< kdup << " xk yk zk " << xkdup << " " << ykdup << " " << zkdup <<" " << "p[k] = " << p[kdup] <<"; kdup= "<< k << " xk yk zk " << xk << " " << yk << " " << zk << " " << "pG[kdup] = " << pGlobal[k] << endl;
			
			
		}
		
	}
	
	if(equilfirst == true && (t - equilTime)<(1)){
		
		if (afterequilflag == true && strcmp(geometry,"TESTSYSTEM2eq") == 0) {
			//cout << "*** process " << rank << ": after equil, TESTSYSTEM2eq " << endl;
			
			for (k = k1; k < k2; k++){
				computeCoordinate(k);
				uxs[k] = initUX*( -1.0* fabs(zk - (LZ-Dh)/2.0)/(LZ -Dh)*2 + 0.5); 
				//cout << "*** process " << rank << ": uxs at k=" << k << " is " << uxs[k] << endl;
				if (zk < Dh) {
					uxs[k] = 0.0;
				}
				uys[k] = 0.0; 
				uzs[k] = 0.0;
			}
		}
		
		if (afterequilflag == true && strcmp(geometry,"TESTSYSTEM4eq") == 0) {
			
			for (k = k1; k < k2; k++){
				if (p[k] >= 0.0L) {
					
					uxs[k] = initUX;
					uys[k] = initUY; 
					uzs[k] = initUZ;
				}
				else{
					
					uxs[k] = 0.0;
					uys[k] = 0.0; 
					uzs[k] = 0.0;
					
				}
				
			}
		}
		
		if (afterequilflag == true && strcmp(geometry,"TESTSYSTEM3eq") == 0) {
			
			for (k = k1; k < k2; k++){
				computeCoordinate(k);
				uxs[k] = initUX*( -1.0* fabs(zk - (LZ-Dh)/2.0)/(LZ -Dh)*2 + 0.5); 
				if (zk < Dh) {
					uxs[k] = 0.0;
				}
				uys[k] = 0.0; 
				uzs[k] = 0.0;
			}		
		}
		if (afterequilflag == true && strcmp(geometry,"TESTSYSTEM5eq") == 0) {
			
			for (k = k1; k < k2; k++){
				if (p[k] < 0.0L) {       //squeeze drop to form ellipse, does only make sense with duplicationtype=2
					
					computeCoordinate(k);
					/*
					 uxs[k] = 0.0L;
					 uys[k] = 0.0L; 
					 uzs[k] = 0.0L;
					 */
					
					if( (xk-dropletCenterX)*(xk-dropletCenterX) + (zk-dropletCenterZ)*(zk-dropletCenterZ) - (dropletR+5)*(dropletR+5) <= 0 || (xk-(LX-dropletCenterX))*(xk-(LX-dropletCenterX)) + (zk-dropletCenterZ)*(zk-dropletCenterZ) - (dropletR+5)*(dropletR+5)  <= 0 ){
						if ( (zk-dropletCenterZ) > dropletR/sqrt(2) && ( fabs(xk-dropletCenterX) <= dropletR/sqrt(2) || fabs(xk-(LX-dropletCenterX)) <= dropletR/sqrt(2)) ) {
							//uxs[k] = 0.0L;
							//uys[k] = 0.0L; 
							uzs[k] = initUZ;
						}
						if ( -(zk-dropletCenterZ) > dropletR/sqrt(2) && ( fabs(xk-dropletCenterX) <= dropletR/sqrt(2) || fabs(xk-(LX-dropletCenterX)) <= dropletR/sqrt(2))) {
							//uxs[k] = 0.0L;
							//uys[k] = 0.0L; 
							uzs[k] = -initUZ;
						}
						if ( fabs(zk-dropletCenterZ) < dropletR/sqrt(2) ) {
							if ( (xk < dropletCenterX) || (LX/2.0 < xk && xk < (LX-dropletCenterX)) ) {
								uxs[k] = initUX;
								//uys[k] = 0.0L; 
								//uzs[k] = 0.0L;
							}
							if ( (dropletCenterX < xk && xk < LX/2.0) || (xk > (LX-dropletCenterX) ) ) {
								uxs[k] = -initUX;
								//uys[k] = 0.0L; 
								//uzs[k] = 0.0L;
							}
							
						}
					}
					
					
				}
			}
		}
		
		
	}
	
	
		
	// have to set equil f and g again after assiging n[k] and p[k], otherwise it's zero. 
	for(k = k1; k < k2; k++){
		
		if (mask[k] == 28) {n[k] = 1.0; p[k] = 0.0;}
		//nn = n[k]; pp = p[k]; ux = uxs[k]; uy = uys[k]; uz = uzs[k]; 
		equilibrium();
		ff0[k] = fe0; 
		ff1[k] = fe1; ff2[k] = fe2; ff3[k] = fe3; ff4[k] = fe4; ff5[k] = fe5; ff6[k] = fe6; 
		ffa[k] = fea; ffb[k] = feb; ffc[k] = fec; ffd[k] = fed; ffe[k] = fee; fff[k] = fef;
		ffg[k] = feg; ffh[k] = feh; ffi[k] = fei; ffj[k] = fej; ffk[k] = fek; ffl[k] = fel;
		
		gg0[k] = ge0;
		gg1[k] = ge1; gg2[k] = ge2; gg3[k] = ge3; gg4[k] = ge4; gg5[k] = ge5; gg6[k] = ge6; 
		gga[k] = gea; ggb[k] = geb; ggc[k] = gec; ggd[k] = ged; gge[k] = gee; ggf[k] = gef;
		ggg[k] = geg; ggh[k] = geh; ggi[k] = gei; ggj[k] = gej; ggk[k] = gek; ggl[k] = gel;
		
	}
	
	/*
	delete []maskGlobal;
	delete []pGlobal;
	delete []nGlobal;
	*/
	pGlobal = new double[N];	
	maskGlobal = new int[N];
	
	generatePhiGlobal();
	generateGlobalMask();
	
	//saveFiles();  // just for testing -  REMOVE! and instead put back in in LGAlg
	if(rank==ROOT)
	{
		int i, j, h;	
		
		char filename[25];
		sprintf(filename, "./densitydata/dd_dupl%ld.m", t);			//Create a name for file that contain data 
		//sprintf(filename, "./dd%ld.m", t);
		
		ofstream file(filename);
		file.precision(4);
		for( h = 0 ; h < LZ ; h++) 
		{   
			file << "ddup" << t << "(:,:," << h+1 << ")=[" << endl;
			for( i = 0 ; i < LX ; i++) 
			{
				for( j = 0 ; j < LY ; j++) 
				{
					k = h + j*LZ + i*LY*LZ;
					if( maskGlobal[k]==28) 
						file << -2.0 << " ";  
					else
						file << pGlobal[k] << " ";
					
				}
				file << endl;
			}
			file <<"];" << endl;
		}
		file.close();
	}
	
	
}