Пример #1
0
Файл: sim.cpp Проект: mtao/MSc
void MACStableFluids::step(Scalar dt)
{
    float t=0;
    int count=0;
    while(t<dt)
    {
        float substep=cfl();

        if(substep<0.000001)
        {
            std::cerr << "SUBSTEP GOING TOO LOW QUITTING\n";
            return;
        }
        if(t+substep > dt)
            substep=dt-t;


        add_force(dt);
        advect(dt);
        diffuse(dt);
        project(dt);
        advect_particles(dt);
        ++count;
        t+=substep;
    }
    time += dt;


}
//The main fluid simulation step
void FluidSim::advance(float dt) {
   float t = 0;
   
   while(t < dt) {
      float substep = cfl();   
      if(t + substep > dt)
         substep = dt - t;
   
      //Passively advect particles
      advect_particles(substep);
     
      //Estimate the liquid signed distance
      compute_phi();

      //Advance the velocity
      advect(substep);
      add_force(substep);

      apply_viscosity(substep);

      apply_projection(substep); 
      
      //Pressure projection only produces valid velocities in faces with non-zero associated face area.
      //Because the advection step may interpolate from these invalid faces, 
      //we must extrapolate velocities from the fluid domain into these zero-area faces.
      extrapolate(u, u_valid);
      extrapolate(v, v_valid);

      //For extrapolated velocities, replace the normal component with
      //that of the object.
      constrain_velocity();
   
      t+=substep;
   }
}
Пример #3
0
void timestep(float ***u, const int nx, const int ny, float *dt, 
              MPI_Comm cartcomm, int left, int right) {
    float ***ut;

    ut = alloc3d_float(nx, ny, NVARS);
    *dt=0.25*cfl(u,nx,ny);

    /* the x sweep */
    vectorGuardcells(u,nx,ny,'x',cartcomm,left,right);
    xsweep(u,nx,ny,*dt);

    /* the y sweeps */
    xytranspose(ut,u,nx,ny);
    periodicBCs(ut,ny,nx,'x');
    xsweep(ut,ny,nx,*dt);
    periodicBCs(ut,ny,nx,'x');
    xsweep(ut,ny,nx,*dt);

    /* 2nd x sweep */
    xytranspose(u,ut,ny,nx);
    vectorGuardcells(u,nx,ny,'x',cartcomm,left,right);
    xsweep(u,nx,ny,*dt);

    free3d_float(ut,nx);
}
Пример #4
0
/*!	外部ファイルを指定でのファイルを表示
*/
BOOL CEditView::MakeDiffTmpFile2( TCHAR* tmpName, const TCHAR* orgName, ECodeType code, ECodeType saveCode )
{
	//一時
	TCHAR* pszTmpName = _ttempnam( NULL, SAKURA_DIFF_TEMP_PREFIX );
	if( NULL == pszTmpName ){
		WarningMessage( NULL, LS(STR_DIFF_FAILED) );
		return FALSE;
	}

	_tcscpy( tmpName, pszTmpName );
	free( pszTmpName );

	bool bBom = false;
	const STypeConfigMini* typeMini;
	CDocTypeManager().GetTypeConfigMini( CDocTypeManager().GetDocumentTypeOfPath( orgName ), &typeMini );
	CFileLoad	cfl( typeMini->m_encoding );
	CTextOutputStream out(tmpName, saveCode, true, false);
	if(!out){
		WarningMessage( NULL, LS(STR_DIFF_FAILED_TEMP) );
		return FALSE;
	}
	try{
		bool bBigFile;
#ifdef _WIN64
		bBigFile = true;
#else
		bBigFile = false;
#endif
		cfl.FileOpen( orgName, bBigFile, code, GetDllShareData().m_Common.m_sFile.GetAutoMIMEdecode(), &bBom );
		CNativeW cLine;
		CEol cEol;
		while( RESULT_FAILURE != cfl.ReadLine( &cLine, &cEol ) ) {
			const wchar_t*	pLineData;
			CLogicInt		nLineLen;
			pLineData= cLine.GetStringPtr(&nLineLen);
			if( 0 == nLineLen || NULL == pLineData ) break;
			if( bBom ){
				CNativeW cLine2(L"\ufeff");
				cLine2.AppendString(pLineData, nLineLen);
				out.WriteString(cLine2.GetStringPtr(), cLine2.GetStringLength());
				bBom = false;
			}else{
				out.WriteString(pLineData,nLineLen);
			}
		}
		if( bBom ){
			out.WriteString(L"\ufeff", 1);
		}
	}
	catch(...){
		out.Close();
		_tunlink( tmpName );	//関数の実行に失敗したとき、一時ファイルの削除は関数内で行う。
		WarningMessage( NULL, LS(STR_DIFF_FAILED_TEMP) );
		return FALSE;
	}

	return TRUE;
}
void Check::Courant_condition(vector<mpselastic> &PART)
{
	mpsconfig CON;
	double dt=CON.get_dt();
	double L=CON.get_distancebp();
	double kv=CON.get_nensei()/CON.get_density();//動粘性係数
	double CFL=0 ,CFLmax=0;
	double Cmax=0.2;	//クーラン数制限0.2
	double vv=0;	//速度ベクトルの大きさ
	double vvmax=0.00000000000001;
	double new_dt=0;
	double di=0;
	stringstream day2;
	day2<<checkf<<"Courant and diffusion number check.dat";
	ofstream cfl(day2.str(), ios::app);
	if(cfl.fail()){
		system("mkdir Check");
		ofstream cfl(day2.str(), ios::app);
		if(cfl.fail()){
			cout<<"can not opning check fail"<<endl;
			getchar();
		}
	}
	for(int i=0;i<PART.size();i++){
	vv=pow(pow(PART[i].u[A_X],2)+pow(PART[i].u[A_Y],2)+pow(PART[i].u[A_Z],2),0.5);
	CFL=(dt*vv)/L;
		if(CFL>CFLmax){ 
			CFLmax=CFL;
			vvmax=vv;
		}
	}

	if(CFLmax>Cmax){ 
		new_dt=(L*Cmax)/vvmax;
		cfl<<"CFL error: CFL="<<CFLmax<<" ,necessary dt="<<new_dt<<endl;
	}
	di=(kv*dt)/(L*L);
	new_dt=0.5*(L*L)/kv;
	if(di>=0.51) {
		cfl<<"diffusion error: di="<<di<<" ,necessary dt="<<new_dt<<endl;
		getchar();
	}
}
Пример #6
0
//The main fluid simulation step
void FluidSim::advance(float dt) {
   float t = 0;

   while(t < dt) {
      float substep = cfl();   
      if(t + substep > dt)
         substep = dt - t;
      printf("Taking substep of size %f (to %0.3f%% of the frame)\n", substep, 100 * (t+substep)/dt);
      
      printf(" Surface (particle) advection\n");
      advect_particles(substep);

      printf(" Velocity advection\n");
      //Advance the velocity
      advect(substep);
      add_force(substep);
      
      printf(" Solve viscosity");
      apply_viscosity(substep);

      printf(" Pressure projection\n");
      project(substep); 
       
      //Pressure projection only produces valid velocities in faces with non-zero associated face area.
      //Because the advection step may interpolate from these invalid faces, 
      //we must extrapolate velocities from the fluid domain into these invalid faces.
      printf(" Extrapolation\n");
      extrapolate(u, u_valid);
      extrapolate(v, v_valid);
      extrapolate(w, w_valid);
    
      //For extrapolated velocities, replace the normal component with
      //that of the object.
      printf(" Constrain boundary velocities\n");
      constrain_velocity();

      t+=substep;
   }
}
Пример #7
0
void FGAdvice::onRequestFinished()
{
    switch(m_state) {
    case GetText:
    {
        bool clearState = true;
        m_respData.clear();
        if(!m_getAudio) {
            m_state = Idle;
        }

        if(m_stateData.activeReply->error() == QNetworkReply::NoError) {
            _interpretResponse();
        } else {
            m_state = Error;
            m_respData.error = m_stateData.activeReply->errorString();
        }

        if(m_state != GetText) {
            emit got(m_state == Error ? ReplyError : ReplyText);
        } else {
            QFile cfl(soundFilePath());
            if(cfl.isReadable()) {
                m_state = Idle;
                emit got(ReplySound);
            } else {
                m_state = StartGetSound;
                QString u = QString(FGA_SOUND_URI).arg(m_respData.soundFile);
                QUrl url = QString(u);
                QNetworkRequest nrAudio(url);
                m_stateData.restart(m_netAccMgr->get(nrAudio));

                connect(m_stateData.activeReply, SIGNAL(readyRead()), SLOT(onDataReady()));
                connect(m_stateData.activeReply, SIGNAL(finished()), SLOT(onRequestFinished()));

                clearState = false;
            }
        }

        if(clearState)
            m_stateData.clear();
    }
        break;
    case GetSound:
    {
        if(m_stateData.activeReply->error() != QNetworkReply::NoError) {
            m_state = Error;
            m_respData.error = m_stateData.activeReply->errorString();
            emit got(ReplyError);
        } else {
            m_state = Idle;
            emit got(ReplySound);
        }

        m_stateData.clear();
    }
        break;
    case Error:
        emit got(ReplyError);
        break;
    default:
        m_state = Error;
        m_stateData.clear();
        break;
    }
}
int main(void) {
  printf("\nНизът %s%s", cfl() ? "" : "НЕ ", "се извежда от граматиката!");
  return 0;
}