/*
================
DeclParser::MakeBinary
================
*/
bool DeclParser::MakeBinary( const char *filename ) {
	if ( commonFS == OG_NULL )
		return false;

	Lexer lexer;
	if ( !lexer.LoadFile( filename ) )
		return false;

	File *f = commonFS->OpenWrite( Format( "$*.bin" ) << filename );
	if ( !f )
		return false;

	try {
		f->Write( DECL_DESCRIPTOR_STR, DECL_DESCRIPTOR_LENGTH );

		Dict dict;
		bool getKeyValue = false;

		const Token *token;
		String key, value;

		String str;
		const char *p;
		while ( (token = lexer.ReadToken()) != OG_NULL ) {
			//! @todo	maybe token should be stored as String, so we don't have to recalc len/bytelen
			p = token->GetString();
			if ( p ) {
				if ( *p == '\0' ) {
					lexer.Error("Unexpected Empty Token");
					return false;
				}
				if ( !getKeyValue ) {
					str = p;
					str.WriteToFile( f );
					value = lexer.ReadString();

					if ( value.IsEmpty() ) {
						lexer.Error("Empty name!");
						return false;
					}
					value.WriteToFile( f );

					lexer.ExpectToken("{");
					getKeyValue = true;
				} else {
					if ( *p == '}' ) {
						getKeyValue = false;
						dict.WriteToFile( f );
						dict.Clear();
					}
					else {
						key = p;
						dict.Set( key.c_str(), lexer.ReadString() );
					}
				}
			}
		}
		if ( getKeyValue ) {
			lexer.Error("Unexpected End Of File");
			return false;
		}
		return true;
	}
	catch( FileReadWriteError &err ) {
		f->Close();
		User::Error( ERR_FILE_WRITEFAIL, Format("Binary Decl: $*.bin" ) << err.ToString(), filename );
		return false;
	}
	catch( LexerError &err ) {
		f->Close();
		String errStr;
		err.ToString( errStr );
		User::Error( ERR_LEXER_FAILURE, errStr.c_str(), filename );
		return false;
	}
}
示例#2
0
int main(int argc, char **argv) try
{
    size_t Nproc = 1;
    if (argc>1) Nproc = atoi(argv[1]);
    double Tf    = 4.5;
    double dt    = 1.0e-4;
    double dtOut = 0.01*Tf;
    double ome   = 4.0*2*M_PI/Tf;

    double Kn = 1.0e5;        // Normal stiffness
    double Kt = 1.0e5;        // Tangential stiffness
    double Gn = 8.0;          // Normal dissipative coefficient
    double Gt = 8.0;          // Tangential dissipative coefficient
    double Mu = 0.3;          // Microscopic friction coefficient
    double Bn = 2.0e5;        // Cohesion normal stiffness
    double Bt = 2.0e5;        // Cohesion tangential stiffness
    double Bm = 2.0e2;        // Cohesion torque stiffness
    double Eps = 0.05;        // Threshold for breking bonds

    // domain and User data
    DEM::Domain dom;
    dom.Alpha  = 0.05;
    dom.CamPos = Vec3_t(0.0,20.0,0.0);

    // particle
    
    size_t Ind = dom.Particles.Size();
    Ind = dom.Particles.Size();
    dom.AddVoroPack (-1, 0.1, 4,4,4, 8,8,8, 3.0, true, true, 1000, 1.0);
    for (size_t i=Ind;i<dom.Particles.Size();i++)
    {
        Vec3_t trans(0.0,0.0,5.0);
        dom.Particles[i]->Translate(trans);
    }
    Ind = dom.Particles.Size();
    dom.AddVoroPack (-1, 0.1, 4,4,4, 8,8,8, 3.0, true, true, 3000, 1.0);
    for (size_t i=Ind;i<dom.Particles.Size();i++)
    {
        Vec3_t trans(0.0,0.0,10.0);
        dom.Particles[i]->Translate(trans);
    }
    Ind = dom.Particles.Size();
    dom.AddVoroPack (-1, 0.1, 4,4,4, 8,8,8, 3.0, true, true, 5000, 1.0);
    for (size_t i=Ind;i<dom.Particles.Size();i++)
    {
        Vec3_t trans(0.0,0.0,15.0);
        dom.Particles[i]->Translate(trans);
    }
    
    for (size_t i=0;i<dom.Particles.Size();i++)
    {
        dom.Particles[i]->Initialize(i);
        dom.Particles[i]->Ff = 0.0,0.0,-dom.Particles[i]->Props.m*9.8;
    }

    dom.AddRice(-2,Vec3_t( 10.0,0.0,0.0),8.0,10.0,3.0,M_PI/2.0,&OrthoSys::e0);
    dom.Particles[dom.Particles.Size()-1]->FixVeloc();
    dom.Particles[dom.Particles.Size()-1]->w = Vec3_t(0.0,0.0, ome);
    dom.AddRice(-3,Vec3_t(-10.0,0.0,0.0),8.0,10.0,3.0,M_PI/2.0,&OrthoSys::e0);
    dom.Particles[dom.Particles.Size()-1]->FixVeloc();
    dom.Particles[dom.Particles.Size()-1]->w = Vec3_t(0.0,0.0,-ome);
    dom.AddRice(-4,Vec3_t( 10.0,0.0,0.0),1.0, 5.0,3.0,M_PI/2.0,&OrthoSys::e1);
    dom.Particles[dom.Particles.Size()-1]->FixVeloc();
    dom.Particles[dom.Particles.Size()-1]->w = Vec3_t(0.0,-ome, 0.0);
    dom.AddRice(-5,Vec3_t(-10.0,0.0,0.0),1.0, 5.0,3.0,M_PI/2.0,&OrthoSys::e1);
    dom.Particles[dom.Particles.Size()-1]->FixVeloc();
    dom.Particles[dom.Particles.Size()-1]->w = Vec3_t(0.0, ome, 0.0);

    Dict B;
    B.Set(-1,"Kn Kt Gn Gt Mu Bn Bt Bm Eps",Kn,Kt,Gn,Gt,Mu,Bn,Bt ,Bm ,     Eps);
    B.Set(-2,"Kn Kt Gn Gt Mu Bn Bt Bm Eps",Kn,Kt,Gn,Gt,Mu,Bn,0.0,0.0,-0.1*Eps);
    B.Set(-3,"Kn Kt Gn Gt Mu Bn Bt Bm Eps",Kn,Kt,Gn,Gt,Mu,Bn,0.0,0.0,-0.1*Eps);
    dom.SetProps(B);

    dom.Solve     (/*tf*/Tf, /*dt*/dt, /*dtOut*/dtOut, NULL, NULL, "grinding",1,Nproc);

    return 0;
}