예제 #1
0
void Simulator::nextTimeStep() {

#ifdef _OPENMP
	simulationJobs->executeJobsParallel((CellListContainer*)particleContainer, scenario);

	simulationJobs->resetJobs();
#else
	//Calculate all forces
	particleContainer->eachPair(scenario->calculateForce);
	particleContainer->each(scenario->addAdditionalForces);

	//update velocity and position
	particleContainer->each(scenario->updatePosition);
#endif

	particleContainer->clearHalo();


	if(Settings::thermostatSwitch == SimulationConfig::ThermostatSwitchType::ON){
		if((Simulator::iterations+1) % ThermostatDiscrete::controlInterval == 0 ) {
			ThermostatDiscrete::updateThermostate(particleContainer);
			ThermostatDiscrete::scaleVelocities(particleContainer);
		}
	}


//#ifdef _OPENMP
//	apcJobs->executeJobsParallel((CellListContainer*)particleContainer, scenario);
//	apcJobs->resetJobs();
//	std::cout << "****************** Jobs reset ******************" << std::endl;
//#else
	//rearrange internal particle container structure and apply boundary handlers
	particleContainer->afterPositionChanges(scenario->boundaryHandlers);
//#endif

	if(Settings::printStatistics){
		if(Simulator::iterations % Settings::statisticsInterval == Settings::statisticsInterval-1||Simulator::iterations % Settings::statisticsInterval == Settings::statisticsInterval-2||Simulator::iterations % Settings::statisticsInterval == Settings::statisticsInterval-3||Simulator::iterations % Settings::statisticsInterval == Settings::statisticsInterval-4){
			getDiffusion();
			getRadialDistribution();
		}else if(Simulator::iterations % Settings::statisticsInterval == 0 ){
			getDiffusion();
			getRadialDistribution();
			addStatisticsString();
		}
	}

	//remove old force fields
	for(int i=0; i < Settings::forceFields.size(); i++) {
		ForceFieldDescriptor &ff = Settings::forceFields[i];
		if(ff.endTime < iterations * Settings::deltaT) {
			Settings::forceFields[i] = Settings::forceFields[Settings::forceFields.size()-1];
			Settings::forceFields.pop_back();
			i--;
			LOG4CXX_DEBUG(logger, "Force field on " << ff.type << " with force [" << ff.force[0] << " " << ff.force[1] << " " << ff.force[2] << "] ended!");
		}
	}


	Simulator::iterations++;
	LOG4CXX_TRACE(logger,"Iteration number " << Simulator::iterations); //This one is pretty annoying
}
예제 #2
0
void makeFlux(FVMesh2D &m, FVVect<double> &phi, FVVect< FVPoint2D<double> > &u,
              FVVect<double> &Vd,FVVect<double> &Vn,
              FVVect<double> &F,Parameter &para) {

    //FVEdge2D *ptr_e;
    double leftPhi,rightPhi,normal_velocity;
    FVPoint2D<double> BB;
    m.beginEdge();
    size_t edges = m.getNbEdge();

    //avoid getting static values in loops
    const unsigned int dirCode = para.getUnsigned("DirichletCode");
    const unsigned int neuCode = para.getUnsigned("NeumannCode");
    const double difusion = getDiffusion(NULL,para);        
    
    
    #pragma omp parallel for private(normal_velocity,leftPhi,rightPhi)
    for(size_t i = 0; i < edges; i++) {

        FVEdge2D *ptr_e;
        //ptr_e = m.nextEdge();
        ptr_e = m.getEdge(i);
        
        normal_velocity = Dot(u[ptr_e->label-1],ptr_e->normal);  
        leftPhi = phi[ptr_e->leftCell->label-1];
        
        if(ptr_e->rightCell) {
            // edge has the code = 0    
            
            rightPhi = phi[ptr_e->rightCell->label-1];
            // compute the convection contribution
            if(normal_velocity<0) {
              
                F[ptr_e->label-1] = normal_velocity*rightPhi;
            }
            else {
              
                F[ptr_e->label-1] = normal_velocity*leftPhi;   
            }
            // compute the diffusive contribution
            BB=ptr_e->rightCell->centroid - ptr_e->leftCell->centroid;                        
            
            F[ptr_e->label-1] -= difusion*(rightPhi-leftPhi)/Norm(BB); 

         }
          else {
            //  we are on the boundary
            if(ptr_e->code == dirCode) {                
                // we have a Dirichlet condition                
                rightPhi = Dirichlet(ptr_e->centroid,para);
                // compute the convection contribution
                if(normal_velocity<0) {
                    
                    F[ptr_e->label-1] = normal_velocity*rightPhi;
                }
                else {
                    
                    F[ptr_e->label-1] = normal_velocity*leftPhi;   
                }
                // compute the diffusive contribution                
                BB = ptr_e->centroid - ptr_e->leftCell->centroid;
               
                F[ptr_e->label-1] -= difusion*(rightPhi-leftPhi)/Norm(BB); 
            }
             
            if(ptr_e->code == neuCode) {
                // we have a Neumann condition      
                
                F[ptr_e->label-1] = Neumann(ptr_e->centroid,para);
            }
        }

        // here, we have all the data to compute the flux    
        
        F[ptr_e->label-1] *= ptr_e->length;
    }
}