コード例 #1
0
void init ()
{
	
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);	
	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);	

	srand ( time ( 0x0 ) );

	glClearColor( 0.49, 0.49, 0.49, 1.0 );
	glShadeModel( GL_SMOOTH );

	glEnable ( GL_COLOR_MATERIAL );
	glEnable (GL_DEPTH_TEST);  
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
	glDepthMask ( 1 );
	glEnable ( GL_TEXTURE_2D );

	// callbacks
	glutDisplayFunc( display );
	glutReshapeFunc( reshape );
	glutKeyboardFunc( keyboard_func );
	glutMouseFunc( mouse_click_func );  
	glutMotionFunc( mouse_move_func );
	glutIdleFunc( idle_func );
	glutSetCursor ( GLUT_CURSOR_NONE );

	cam_angs.x = 29;		cam_angs.y = 75;		cam_angs.z = 80.0;
	cam_to.x = 0;		cam_to.y = 0;		cam_to.z = 5;
	cam_fov = 35.0;

	light[0].x = 39;		light[0].y = -60;	light[0].z = 43;
	light_to[0].x = 0;	light_to[0].y = 0;	light_to[0].z = 0;

	light[1].x = 15;		light[1].y = -5;	light[1].z = 145;	
	light_to[1].x = 0;	light_to[1].y = 0;	light_to[1].z = 0;  

	light_fov = 45;

	#ifdef USE_SHADOWS
		createShadowTextures();
		createFrameBuffer ();
		setShadowLight ( light[0].x, light[0].y, light[0].z, light_to[0].x, light_to[0].y, light_to[0].z, light_fov );
		setShadowLightColor ( .7, .7, .7, 0.2, 0.2, 0.2 );		
	#endif

	obj_from.x = 0;		obj_from.y = 0;		obj_from.z = 20;		// emitter
	obj_angs.x = 118.7;	obj_angs.y = 200;	obj_angs.z = 1.0;
	obj_dang.x = 1;	obj_dang.y = 1;		obj_dang.z = 0;

	psys.Initialize ( BFLUID, psys_nmax );
	psys.SPH_CreateExample ( 0, psys_nmax );
	psys.SetVec ( EMIT_ANG, Vector3DF ( obj_angs.x, obj_angs.y, obj_angs.z ) );
	psys.SetVec ( EMIT_POS, Vector3DF ( obj_from.x, obj_from.y, obj_from.z ) );

	psys.SetParam ( PNT_DRAWMODE, int(bPntDraw ? 1:0) );
	psys.SetParam ( CLR_MODE, iClrMode );	
}
コード例 #2
0
ファイル: jsfluid.cpp プロジェクト: tikwid/jsfluid
void init ()
{
	srand ( time ( 0x0 ) );
	
  obj_from.x = 0;		obj_from.y = 0;		obj_from.z = 20;		// emitter
	obj_angs.x = 118.7;	obj_angs.y = 200;	obj_angs.z = 1.0;

	psys.Initialize ( BFLUID, psys_nmax );
	psys.SPH_CreateExample ( 0, psys_nmax );
	psys.SetVec ( EMIT_ANG, Vector3DF ( obj_angs.x, obj_angs.y, obj_angs.z ) );
	psys.SetVec ( EMIT_POS, Vector3DF ( obj_from.x, obj_from.y, obj_from.z ) );

	psys.SetParam ( PNT_DRAWMODE, int(bPntDraw ? 1:0) );
	psys.SetParam ( CLR_MODE, iClrMode );	
}
コード例 #3
0
void WaterSimulationApp::addForce(float dt )
{

	float length= randomForce.length();
	Vec3f pos1=randomForceX+randomForce;
	Vec3f x = Vec3f::zero();
	if(length<1e-6)return;
	int num =(int)(length/fluidsys->cellDim.x+1);
	for(int i=0;i<num;i++){
		x=randomForceX.lerp((float)i/length,pos1);
		fluidsys->addSource(x,dt,fluidsys->u0,randomForce.x);
		fluidsys->addSource(x,dt,fluidsys->v0,randomForce.y);
		fluidsys->addSource(x,dt,fluidsys->w0,randomForce.z);
	}
	randomForce.zero();
}
コード例 #4
0
void WaterSimulationApp::draw(){

	gl::clear( Color( 0.11f, 0.13f, 0.1f ) );
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mParams->draw();

	gl::setMatrices(mMayaCam.getCamera());
	if(mDrawBox){
		glColor4f(0.2, 0.4, 0.5, 1);//orange
		gl::drawStrokedCube(boxCenter,boxDimension);
	}
	if(mDrawGravity){
		glColor4f(1.0f,0.3f,0.0f,0.5f);//red
		if(mDrawGravity)glColor4f(0.0f,1.0f,0.5f,1);//green
		gl::drawVector(boxCenter,(boxCenter-gravity),3.0f,1.0f);
	}

	//draw random force
	if(mDrawForce){
		if(randomForce.lengthSquared()!=0){
			glColor4f(1.0f,0.0f,0.0f,1);
			gl::drawVector(randomForceX,randomForce+randomForceX,1.0f,0.5f);
		}
	}

	fluidsys->draw();

}
コード例 #5
0
void display () 
{
	mint::Time start, stop;	

//	iso = sin(frame*0.01f );
	
	// Do simulation!
	if ( !bPause ) psys.Run ();

	frame++;
	measureFPS ();

	glEnable ( GL_DEPTH_TEST );

	// Render depth map shadows
	start.SetSystemTime ( ACC_NSEC );
	disableShadows ();
	#ifdef USE_SHADOWS
		if ( iShade==1 ) {
			renderDepthMap_FrameBuffer ( 0, window_width, window_height );
		} else {
			renderDepthMap_Clear ( window_width, window_height );		
		}
	#endif	

	// Clear frame buffer
	if ( iShade<=1 ) 	glClearColor( 0.29, 0.29, 0.29, 1.0 );
	else				glClearColor ( 0, 0, 0, 0 );
	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glDisable ( GL_CULL_FACE );
	glShadeModel ( GL_SMOOTH );

	// Compute camera view
	computeFromPositions ();
	computeProjection ();
	computeView ();		

	// Draw Shadows (if on)
	#ifdef USE_SHADOWS	
		if ( iShade==1 )	renderShadows ( view_matrix );			
	#endif

	// Draw 3D	
	start.SetSystemTime ( ACC_NSEC );
	glEnable ( GL_LIGHTING );  
	glLoadMatrixf ( view_matrix );	
	drawScene ( view_matrix, true );
	if ( bTiming) { stop.SetSystemTime ( ACC_NSEC ); stop = stop - start; printf ( "SCENE: %s\n", stop.GetReadableTime().c_str() ); }

	// Draw 2D overlay
	draw2D ();
 
	// Swap buffers
	glutSwapBuffers();  
	glutPostRedisplay();
}
コード例 #6
0
void BlackoilCo2PVT::init(const Opm::Deck& /* deck */)
{
	surfaceDensities_[Water]   = 1000.;
	surfaceDensities_[Gas] = 2.0;
	surfaceDensities_[Oil] = 1000.;

    temperature_ = 300.;

    brineCo2_.init();
}
コード例 #7
0
ファイル: BlackoilCo2PVT.hpp プロジェクト: laods/opm-porsol
    void BlackoilCo2PVT::init(const Opm::EclipseGridParser& ep)
    {
	surfaceDensities_[Water]   = 1000.;
	surfaceDensities_[Gas] = 2.0;
	surfaceDensities_[Oil] = 1000.;

        temperature_ = 300.;

        brineCo2_.init();
    }
コード例 #8
0
void WaterSimulationApp::update(){
	////change status
	float dt = 1.f/60.0f;
	if(mAnimate){
		if(randomForce.lengthSquared()>0 && mAddNewForce) addForce(dt);
		fluidsys->step(dt);
		mParams->setOptions("status","label=`In animation:`");
	}else{
		mParams->setOptions("status","label=`Idle:`");
	}
}
コード例 #9
0
void drawScene ( float* viewmat, bool bShade )
{
	if ( iShade <= 1 && bShade ) {		
		glEnable ( GL_LIGHT0 );
		GLfloat diff[4];
		GLfloat spec[4];
		GLfloat shininess = 60.0;
		
		diff[0] = 0.8f; diff[1] = 0.8f; diff[2] = 0.8f; diff[3] = 1.0f;
		spec[0] = 1.0f; spec[1] = 1.0f; spec[2] = 1.0f; spec[3] = 1.0f;
		glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, &diff[0]);
		glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, &spec[0]);
		glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, &shininess);		
		glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );

		glColor3f ( 1, 1, 1 );
		glLoadMatrixf ( viewmat );
		glBegin ( GL_QUADS );
		glNormal3f ( 0, 0, 1 );
		glVertex3f ( -1000, -1000, 0.0 );
		glVertex3f ( 1000, -1000, 0.0 );
		glVertex3f ( 1000, 1000, 0.0 );
		glVertex3f ( -1000, 1000, 0.0 );
		glEnd ();
		glBegin ( GL_LINES );
		for (float n=-100; n <= 100; n += 20.0 ) {
			glVertex3f ( -100, n, 0.1 );
			glVertex3f ( 100, n, 0.1 );
			glVertex3f ( n, -100, 0.1 );
			glVertex3f ( n,  100, 0.1 );
		}
		glEnd ();
		//psys.SPH_DrawDomain();						//Draw Particle Volume
		psys.Grid_Draw(&viewmat[0]);
		psys.Draw ( &viewmat[0], 0.8 );				// Draw particles		

	} else {
		glDisable ( GL_LIGHTING );
		psys.Draw ( &viewmat[0], 0.55 );			// Draw particles
	}
}
コード例 #10
0
void WaterSimulationApp::keyDown( KeyEvent event ){
	switch(event.getChar()){
	case 'r':fluidsys->reset(boxDimension);break;
	case 'f':setFullScreen( ! isFullScreen() ); break;
	case 'a':mAddNewForce=true;break;
	}

	switch(event.getCode()){
	case KeyEvent::KEY_SPACE:mAnimate=!mAnimate;break;
	case KeyEvent::KEY_ESCAPE:this->quit();break;
	}

}
コード例 #11
0
ファイル: jsfluid.cpp プロジェクト: tikwid/jsfluid
float *get_points() {
  char *dat;
  Point *p;
  float *cp;

  dat = psys.mBuf[0].data;
  for (int i = 0; i < psys.NumPoints(); i++) {
	  p = (Point*) dat;
    cpoints[i*3+0] = p->pos.x;
    cpoints[i*3+1] = p->pos.y;
    cpoints[i*3+2] = p->pos.z;
    dat += psys.mBuf[0].stride; 
  }
  return cpoints;
}
コード例 #12
0
void WaterSimulationApp::setup(){

	boxDimension=Vec3f(30.0f,30.0f,30.0f);
	boxCenter=Vec3f(boxDimension)/2.0f;

	//Fluid System setup
	fluidsys=&stamfluid;
	fluidsys->reset(boxDimension);

	randomForce=Vec3f(2,3,-1);
	randomForceX=boxCenter;

	//// setup our default camera, looking down the z-axis
	CameraPersp	cam;
	cam.setEyePoint(Vec3f(200, 50, 50));
	cam.setCenterOfInterestPoint(boxCenter);
	cam.setPerspective(60.0, getWindowAspectRatio(), 1.0, 1000.0);
	mMayaCam.setCurrentCam(cam);

	Matrix44f mvM=mMayaCam.getCamera().getModelViewMatrix();
	gravity = Vec3f(mvM.m10,mvM.m11,mvM.m12);//col4:camera center, row: right,up,back
	gravity*= 9.8f;
	// Setup the parameters
	mDrawGravity=false;
	mAddNewForce=false;
	mAnimate	=false;
	mDrawBox	=true;


	mParams = params::InterfaceGl::create( getWindow(), "Water Simulation Parameters", toPixels( Vec2i( 250,300  ) ) );
	mParams->addParam("Draw Box", &mDrawBox);
	mParams->addParam("Draw Grid",&mDrawGrid);
	mParams->addParam("Draw Random Force",&mDrawForce);
	mParams->addSeparator();
	mParams->addParam("External Force Position",&randomForceX);
	mParams->addParam("External Force Dir",&randomForce);
	mParams->addParam("Draw Gravity",&mDrawGravity);
	mParams->addParam("Draw Velocity", &(fluidsys->mDrawVelocity));
	mParams->addSeparator();
	mParams->addParam("Animate",&mAnimate);
	mParams->addText("status","label=` `");
	mParams->addParam("Time Elapsed",&(fluidsys->elapsed),"",true);
	mParams->addSeparator();
	mParams->addParam("Viscosity", &fluidsys->viscosity);
	mParams->addParam("Diffusion Rate", &fluidsys->diffusion);
	mParams->addParam("Buoyancy Rate",&fluidsys->buoyancy);
}
コード例 #13
0
void mouse_move_func ( int x, int y )
{
	int dx = x - last_x;
	int dy = y - last_y;

	switch ( mode ) {
	case MODE_CAM:
		if ( dragging == DRAG_LEFT ) {
			cam_angs.x += dx;
			cam_angs.y += dy;
			if ( cam_angs.x >= 360.0 )	cam_angs.x -= 360.0;
			if ( cam_angs.x < 0 )		cam_angs.x += 360.0;
			if ( cam_angs.y >= 180.0 )	cam_angs.y = 180.0;
			if ( cam_angs.y <= -180.0 )	cam_angs.y = -180.0;
			printf ( "Cam Ang: %f %f %f\n", cam_angs.x, cam_angs.y, cam_angs.z );
			printf ( "Cam To:  %f %f %f\n", cam_to.x, cam_to.y, cam_to.z );
			printf ( "Cam FOV: %f\n", cam_fov);
		} else if ( dragging == DRAG_RIGHT ) {
			cam_angs.z += dy*.15;
			if ( cam_angs.z < 0)		cam_angs.z = 0;
			printf ( "Cam Ang: %f %f %f\n", cam_angs.x, cam_angs.y, cam_angs.z );
			printf ( "Cam To:  %f %f %f\n", cam_to.x, cam_to.y, cam_to.z );
			printf ( "Cam FOV: %f\n", cam_fov );
		}
		break;
	case MODE_CAM_TO:
		if ( dragging == DRAG_LEFT ) {
			cam_to.x += dx;
			cam_to.y += dy;			
		} else if ( dragging == DRAG_RIGHT ) {
			cam_to.z += dy*.05;
			if ( cam_to.z < 0) 	cam_to.z = 0;
		}
		break;	
	case MODE_OBJ:
		if ( dragging == DRAG_LEFT ) {
			obj_angs.x -= dx*0.1;
			obj_angs.y += dy*0.1;
			printf ( "Obj Angs:  %f %f %f\n", obj_angs.x, obj_angs.y, obj_angs.z );
			//force_x += dx*.1;
			//force_y += dy*.1;
		} else if (dragging == DRAG_RIGHT) {
			obj_angs.z -= dy*.005;			
			printf ( "Obj Angs:  %f %f %f\n", obj_angs.x, obj_angs.y, obj_angs.z );
		}
		psys.SetVec ( EMIT_ANG, Vector3DF ( obj_angs.x, obj_angs.y, obj_angs.z ) );
		break;
	case MODE_OBJPOS:
		if ( dragging == DRAG_LEFT ) {
			obj_from.x -= dx*.1;
			obj_from.y += dy*.1;
			printf ( "Obj:  %f %f %f\n", obj_from.x, obj_from.y, obj_from.z );
		} else if (dragging == DRAG_RIGHT) {
			obj_from.z -= dy*.1;
			printf ( "Obj:  %f %f %f\n", obj_from.x, obj_from.y, obj_from.z );
		}
		psys.SetVec ( EMIT_POS, Vector3DF ( obj_from.x, obj_from.y, obj_from.z ) );
		//psys.setPos ( obj_x, obj_y, obj_z, obj_ang, obj_tilt, obj_dist );
		break;
	case MODE_LIGHTPOS:
		if ( dragging == DRAG_LEFT ) {
			light[0].x -= dx*.1;
			light[0].y += dy*.1;		
			printf ( "Light: %f %f %f\n", light[0].x, light[0].y, light[0].z );
		} else if (dragging == DRAG_RIGHT) {
			light[0].z -= dy*.1;			
			printf ( "Light: %f %f %f\n", light[0].x, light[0].y, light[0].z );
		}	
		#ifdef USE_SHADOWS
			setShadowLight ( light[0].x, light[0].y, light[0].z, light_to[0].x, light_to[0].y, light_to[0].z, light_fov );
		#endif
		break;
	}

	if ( x < 10 || y < 10 || x > 1000 || y > 700 ) {
		glutWarpPointer ( 1024/2, 768/2 );
		last_x = 1024/2;
		last_y = 768/2;
	} else {
		last_x = x;
		last_y = y;
	}
}
コード例 #14
0
void keyboard_func ( unsigned char key, int x, int y )
{
	switch( key ) {
	case 'M': case 'm': {
		psys_nmax *= 2;
		if ( psys_nmax > 65535 ) psys_nmax = 65535;		
		psys.SPH_CreateExample ( psys_demo, psys_nmax );
		} break;
	case 'N': case 'n': {
		psys_nmax /= 2;
		if ( psys_nmax < 64 ) psys_nmax = 64;		
		psys.SPH_CreateExample ( psys_demo, psys_nmax );
		} break;
	case '0':
		UpdateEmit ();
		psys_freq++;	
		psys.SetVec ( EMIT_RATE, Vector3DF(psys_freq, psys_rate, 0) );
		break;  
	case '9':
		UpdateEmit ();
		psys_freq--;  if ( psys_freq < 0 ) psys_freq = 0;
		psys.SetVec ( EMIT_RATE, Vector3DF(psys_freq, psys_rate, 0) );
		break;
	case '.': case '>':
		UpdateEmit ();
		if ( ++psys_rate > 100 ) psys_rate = 100;
		psys.SetVec ( EMIT_RATE, Vector3DF(psys_freq, psys_rate, 0) );
		break;
	case ',': case '<':
		UpdateEmit ();
		if ( --psys_rate < 0 ) psys_rate = 0;
		psys.SetVec ( EMIT_RATE, Vector3DF(psys_freq, psys_rate, 0) );
	break;
	case 'g': case 'G':	psys.Toggle ( USE_CUDA );	break;
	case 'f': case 'F':	mode = MODE_DOF;	break;

	case 'z': case 'Z':	mode = MODE_CAM_TO;	break;
	case 'c': case 'C':	mode = MODE_CAM;	break; 
	case 'h': case 'H':	bHelp = !bHelp; break;
	case 'i': case 'I':	
		UpdateEmit ();
		mode = MODE_OBJPOS;	
		break;
	case 'o': case 'O':	
		UpdateEmit ();
		mode = MODE_OBJ;
		break;  
	case 'x': case 'X':
		if ( ++iClrMode > 2) iClrMode = 0;
		psys.SetParam ( CLR_MODE, iClrMode );
		break;
	case 'l': case 'L':	mode = MODE_LIGHTPOS;	break;
	case 'd': case 'D': {
		int d = psys.GetParam ( PNT_DRAWMODE ) + 1;
		if ( d > 2 ) d = 0;
		psys.SetParam ( PNT_DRAWMODE, d );
		} break;	
	case 's': case 'S':	if ( ++iShade > 2 ) iShade = 0;		break;
	case 27:			    exit( 0 ); break;
	
	case '`':
		bRec = !bRec; break;

	case ' ':		
		//psys.Run (); ptris.Rebuild (); break;
		bPause = !bPause;	break;

	case '\'': case ';':	psys.SPH_CreateExample ( psys_demo, psys_nmax ); break;
	case 'r': case 'R':		psys.SPH_CreateExample ( psys_demo, psys_nmax ); break;  
	case '[':
		psys_demo--;
		if (psys_demo < 0 ) psys_demo = 10;
		psys.SPH_CreateExample ( psys_demo, psys_nmax );
		UpdateEmit ();
		break;
	case ']':
		psys_demo++;
		if (psys_demo > 10 ) psys_demo = 0;
		psys.SPH_CreateExample ( psys_demo, psys_nmax );
		UpdateEmit ();
		break;  
	default:
	break;
  }
}
コード例 #15
0
void UpdateEmit ()
{	
	obj_from = psys.GetVec ( EMIT_POS );
	obj_angs = psys.GetVec ( EMIT_ANG );
	obj_dang = psys.GetVec ( EMIT_RATE );
}
コード例 #16
0
ファイル: jsfluid.cpp プロジェクト: tikwid/jsfluid
int get_num_points() {
  return psys.NumPoints();
}
コード例 #17
0
void draw2D ()
{
	
	mint::Time start, stop;

	#ifdef USE_SHADOWS
		disableShadows ();
	#endif
	glDisable ( GL_LIGHTING );  
	glDisable ( GL_DEPTH_TEST );

	glMatrixMode ( GL_PROJECTION );
	glLoadIdentity ();  
	glScalef ( 2.0/window_width, -2.0/window_height, 1 );		// Setup view (0,0) to (800,600)
	glTranslatef ( -window_width/2.0, -window_height/2, 0.0);

	glMatrixMode ( GL_MODELVIEW );
	glLoadIdentity ();
	glPushMatrix (); 
	glGetFloatv ( GL_MODELVIEW_MATRIX, view_matrix ); 
	glPopMatrix (); 

	char disp[200];
	glColor4f ( 1.0, 1.0, 1.0, 1.0 );

	strcpy ( disp, "Press H for help." );		drawText ( 10, 20, disp );  

	if ( bHelp ) {	

		if ( psys.GetToggle ( USE_CUDA ) ) {
			sprintf ( disp,	"Kernel:  USING CUDA (GPU)" );				drawText ( 20, 40,  disp );	
		} else {
			sprintf ( disp,	"Kernel:  USING CPU" );				drawText ( 20, 40,  disp );
		}		

		sprintf ( disp,	"KEYBOARD" );						drawText ( 20, 60,  disp );
		sprintf ( disp,	"[ ]    Next/Prev Demo" );			drawText ( 20, 70,  disp );
		sprintf ( disp,	"N M    Adjust Max Particles" );	drawText ( 20, 80,  disp );
		sprintf ( disp,	"space  Pause" );					drawText ( 20, 90,  disp );
		sprintf ( disp,	"S      Shading mode" );			drawText ( 20, 100,  disp );	
		sprintf ( disp,	"G      Toggle CUDA vs CPU" );		drawText ( 20, 110,  disp );	
		sprintf ( disp,	"< >    Change emitter rate" );		drawText ( 20, 120,  disp );	
		sprintf ( disp,	"C      Move camera /w mouse" );	drawText ( 20, 130,  disp );	
		sprintf ( disp,	"I      Move emitter /w mouse" );	drawText ( 20, 140,  disp );	
		sprintf ( disp,	"O      Change emitter angle" );	drawText ( 20, 150,  disp );	
		sprintf ( disp,	"L      Move light /w mouse" );				drawText ( 20, 160,  disp );			
		sprintf ( disp,	"X      Draw velocity/pressure/color" );	drawText ( 20, 170,  disp );

		Vector3DF vol = psys.GetVec(SPH_VOLMAX);
		vol -= psys.GetVec(SPH_VOLMIN);
		sprintf ( disp,	"Volume Size:           %3.5f %3.2f %3.2f", vol.x, vol.y, vol.z );	drawText ( 20, 190,  disp );
		sprintf ( disp,	"Time Step (dt):        %3.5f", psys.GetDT () );					drawText ( 20, 200,  disp );
		sprintf ( disp,	"Num Particles:         %d", psys.NumPoints() );					drawText ( 20, 210,  disp );		
		sprintf ( disp,	"Simulation Scale:      %3.5f", psys.GetParam(SPH_SIMSIZE) );		drawText ( 20, 220,  disp );
		sprintf ( disp,	"Simulation Size (m):   %3.5f", psys.GetParam(SPH_SIMSCALE) );		drawText ( 20, 230,  disp );
		sprintf ( disp,	"Smooth Radius (m):     %3.3f", psys.GetParam(SPH_SMOOTHRADIUS) );	drawText ( 20, 240,  disp );
		sprintf ( disp,	"Particle Radius (m):   %3.3f", psys.GetParam(SPH_PRADIUS) );		drawText ( 20, 250,  disp );
		sprintf ( disp,	"Particle Mass (kg):    %0.8f", psys.GetParam(SPH_PMASS) );			drawText ( 20, 260,  disp );
		sprintf ( disp,	"Rest Density (kg/m^3): %3.3f", psys.GetParam(SPH_RESTDENSITY) );	drawText ( 20, 270,  disp );
		sprintf ( disp,	"Viscosity:             %3.3f", psys.GetParam(SPH_VISC) );			drawText ( 20, 280,  disp );
		sprintf ( disp,	"Internal Stiffness:    %3.3f", psys.GetParam(SPH_INTSTIFF) );		drawText ( 20, 290,  disp );
		sprintf ( disp,	"Boundary Stiffness:    %6.0f", psys.GetParam(SPH_EXTSTIFF) );		drawText ( 20, 300,  disp );
		sprintf ( disp,	"Boundary Dampening:    %4.3f", psys.GetParam(SPH_EXTDAMP) );		drawText ( 20, 310,  disp );
		sprintf ( disp,	"Speed Limiting:        %4.3f", psys.GetParam(SPH_LIMIT) );			drawText ( 20, 320,  disp );
		vol = psys.GetVec ( PLANE_GRAV_DIR );
		sprintf ( disp,	"Gravity:               %3.2f %3.2f %3.2f", vol.x, vol.y, vol.z );	drawText ( 20, 330,  disp );
	}
}
コード例 #18
0
ファイル: BlackoilCo2PVT.hpp プロジェクト: laods/opm-porsol
    void BlackoilCo2PVT::computeState(BlackoilCo2PVT::SubState& ss, double zBrine, double zCO2, double pressure) const
    {
               
        CompositionalFluidState state;     
        state.setTemperature(temperature_);
        state.setPressure(wPhase, pressure);
        state.setPressure(nPhase, pressure);
        
        double massH20 = surfaceDensities_[Oil]*zBrine;
        double massCO2 = surfaceDensities_[Gas]*zCO2;
        
        // A priori, assume presence of both phases
        brineCo2_.computeEquilibrium(state); 
        ss.density[wPhase] = state.density(wPhase);
        ss.density[nPhase] = state.density(nPhase);
        ss.massfrac[wPhase][nComp] = state.massFraction(wPhase, nComp);
        ss.massfrac[nPhase][wComp] = state.massFraction(nPhase, wComp);
        ss.massfrac[wPhase][wComp] = 1.0 - ss.massfrac[wPhase][nComp];
        ss.massfrac[nPhase][nComp] = 1.0 - ss.massfrac[nPhase][wComp];

        double detX = ss.massfrac[wPhase][wComp]*ss.massfrac[nPhase][nComp]-ss.massfrac[wPhase][nComp]*ss.massfrac[nPhase][wComp];
        ss.phaseVolume[wPhase] = (massH20*ss.massfrac[nPhase][nComp] - massCO2*ss.massfrac[nPhase][wComp])/(ss.density[wPhase]*detX);
        ss.phaseVolume[nPhase] = (massCO2*ss.massfrac[wPhase][wComp] - massH20*ss.massfrac[wPhase][nComp])/(ss.density[nPhase]*detX);
        
        // Determine number of phase
        if (ss.phaseVolume[wPhase] > 0.0 && ss.phaseVolume[nPhase] > 0.0) { // Both phases
            ss.saturation = ss.phaseVolume[wPhase]/(ss.phaseVolume[wPhase]+ss.phaseVolume[nPhase]);
            state.setSaturation(wPhase, ss.saturation);
            state.setSaturation(nPhase, 1.0 - ss.saturation);
        }
        else if (ss.phaseVolume[wPhase] <= 0.0) { // Wetting phase only
            ss.saturation = 0.0;
            // Gas phase:
            ss.massfrac[nPhase][nComp] = massCO2/(massCO2+massH20);
            ss.massfrac[nPhase][wComp] = 1.0 - ss.massfrac[nPhase][nComp];
            double M1 = FluidSystem::molarMass(wComp);
            double M2 = FluidSystem::molarMass(nComp);
            double avgMolarMass = M1*M2/(M2 + ss.massfrac[nPhase][nComp]*(M1 - M2));
            state.setMoleFraction(nPhase, nComp, ss.massfrac[nPhase][nComp]*avgMolarMass/M2);
            state.setMoleFraction(nPhase, wComp, ss.massfrac[nPhase][wComp]*avgMolarMass/M1);
            ss.density[nPhase] = brineCo2_.phaseDensity(nPhase, state.temperature(nPhase), state.pressure(nPhase), state);
            state.setDensity(nPhase, ss.density[nPhase]);
            ss.phaseVolume[nPhase] = (massH20+massCO2)/ss.density[nPhase];
            state.setSaturation(nPhase, 1.0 - ss.saturation);
            // Virtual properties of non-existing liquid phase:
            brineCo2_.computeEquilibrium(state, nPhase);
            ss.massfrac[wPhase][wComp] = state.massFraction(wPhase, wComp);
            ss.massfrac[wPhase][nComp] = state.massFraction(wPhase, nComp);
            ss.density[wPhase] = state.density(wPhase);
            ss.phaseVolume[wPhase] = 0.0;
            state.setSaturation(wPhase, ss.saturation);
        }
        else if (ss.phaseVolume[nPhase] <= 0.0) { // Non-wetting phase only
            ss.saturation = 1.0;
            // Liquid phase:
            ss.massfrac[wPhase][wComp] = massH20/(massCO2+massH20);
            ss.massfrac[wPhase][nComp] = 1.0 - ss.massfrac[wPhase][wComp];
            double M1 = FluidSystem::molarMass(wComp);
            double M2 = FluidSystem::molarMass(nComp);
            double avgMolarMass = M1*M2/(M2 + ss.massfrac[wPhase][nComp]*(M1 - M2));
            state.setMoleFraction(wPhase, nComp, ss.massfrac[wPhase][nComp]*avgMolarMass/M2);
            state.setMoleFraction(wPhase, wComp, ss.massfrac[wPhase][wComp]*avgMolarMass/M1);
            ss.density[wPhase] = brineCo2_.phaseDensity(wPhase, state.temperature(wPhase), state.pressure(wPhase), state);
            state.setDensity(wPhase, ss.density[wPhase]);
            ss.phaseVolume[wPhase] = (massH20+massCO2)/ss.density[wPhase];
            state.setSaturation(wPhase, ss.saturation);
            // Virtual properties of non-existing gas phase:
            brineCo2_.computeEquilibrium(state, wPhase);
            ss.massfrac[nPhase][nComp] = state.massFraction(nPhase, nComp);
            ss.massfrac[nPhase][wComp] = state.massFraction(nPhase, wComp);
            ss.density[nPhase] = state.density(nPhase);
            ss.phaseVolume[nPhase] = 0.0;
            state.setSaturation(nPhase, 1.0 - ss.saturation);
        } 
        
        ss.phaseViscosity[wPhase] = brineCo2_.phaseViscosity(wPhase, temperature_, pressure, state);
        ss.phaseViscosity[nPhase] = brineCo2_.phaseViscosity(nPhase, temperature_, pressure, state);        

    }
コード例 #19
0
void BlackoilCo2PVT::computeState(BlackoilCo2PVT::SubState& ss, double zBrine, double zCO2, double pressure) const
{
               
    CompositionalFluidState fluidState;     
    fluidState.setTemperature(temperature_);
    fluidState.setPressure(wPhase, pressure);
    fluidState.setPressure(nPhase, pressure);
        
    double massH20 = surfaceDensities_[Oil]*zBrine;
    double massCO2 = surfaceDensities_[Gas]*zCO2;
        
    // A priori, assume presence of both phases
    FluidSystem::ParameterCache<double> paramCache;
    typedef Opm::MiscibleMultiPhaseComposition</*Scalar=*/double, FluidSystem> MMPC;
    MMPC::solve(fluidState, paramCache, /*setViscosity=*/false, /*setEnthalpy=*/false);
    ss.density[wPhase] = fluidState.density(wPhase);
    ss.density[nPhase] = fluidState.density(nPhase);
    ss.massfrac[wPhase][nComp] = fluidState.massFraction(wPhase, nComp);
    ss.massfrac[nPhase][wComp] = fluidState.massFraction(nPhase, wComp);
    ss.massfrac[wPhase][wComp] = 1.0 - ss.massfrac[wPhase][nComp];
    ss.massfrac[nPhase][nComp] = 1.0 - ss.massfrac[nPhase][wComp];

    double detX = ss.massfrac[wPhase][wComp]*ss.massfrac[nPhase][nComp]-ss.massfrac[wPhase][nComp]*ss.massfrac[nPhase][wComp];
    ss.phaseVolume[wPhase] = (massH20*ss.massfrac[nPhase][nComp] - massCO2*ss.massfrac[nPhase][wComp])/(ss.density[wPhase]*detX);
    ss.phaseVolume[nPhase] = (massCO2*ss.massfrac[wPhase][wComp] - massH20*ss.massfrac[wPhase][nComp])/(ss.density[nPhase]*detX);
        
    // Determine number of phase
    if (ss.phaseVolume[wPhase] > 0.0 && ss.phaseVolume[nPhase] > 0.0) { // Both phases
        ss.saturation = ss.phaseVolume[wPhase]/(ss.phaseVolume[wPhase]+ss.phaseVolume[nPhase]);
        fluidState.setSaturation(wPhase, ss.saturation);
        fluidState.setSaturation(nPhase, 1.0 - ss.saturation);
    }
    else if (ss.phaseVolume[wPhase] <= 0.0) { // Wetting phase only
        ss.saturation = 0.0;
        // Gas phase:
        ss.massfrac[nPhase][nComp] = massCO2/(massCO2+massH20);
        ss.massfrac[nPhase][wComp] = 1.0 - ss.massfrac[nPhase][nComp];
        double M1 = FluidSystem::molarMass(wComp);
        double M2 = FluidSystem::molarMass(nComp);
        double avgMolarMass = M1*M2/(M2 + ss.massfrac[nPhase][nComp]*(M1 - M2));
        fluidState.setMoleFraction(nPhase, nComp, ss.massfrac[nPhase][nComp]*avgMolarMass/M2);
        fluidState.setMoleFraction(nPhase, wComp, ss.massfrac[nPhase][wComp]*avgMolarMass/M1);
        ss.density[nPhase] = brineCo2_.density(fluidState, paramCache, nPhase);
        fluidState.setDensity(nPhase, ss.density[nPhase]);
        ss.phaseVolume[nPhase] = (massH20+massCO2)/ss.density[nPhase];
        fluidState.setSaturation(nPhase, 1.0 - ss.saturation);
        // Virtual properties of non-existing liquid phase:
        paramCache.updatePhase(fluidState, /*phaseIdx=*/nPhase);
        typedef Opm::ComputeFromReferencePhase</*Scalar=*/double, FluidSystem> CFRP;
        CFRP::solve(fluidState,
                    paramCache,
                    /*refPhaseIdx=*/nPhase,
                    /*setViscosity=*/false,
                    /*setEnthalpy=*/false);
        ss.massfrac[wPhase][wComp] = fluidState.massFraction(wPhase, wComp);
        ss.massfrac[wPhase][nComp] = fluidState.massFraction(wPhase, nComp);
        ss.density[wPhase] = fluidState.density(wPhase);
        ss.phaseVolume[wPhase] = 0.0;
        fluidState.setSaturation(wPhase, ss.saturation);
    }
    else if (ss.phaseVolume[nPhase] <= 0.0) { // Non-wetting phase only
        ss.saturation = 1.0;
        // Liquid phase:
        ss.massfrac[wPhase][wComp] = massH20/(massCO2+massH20);
        ss.massfrac[wPhase][nComp] = 1.0 - ss.massfrac[wPhase][wComp];
        double M1 = FluidSystem::molarMass(wComp);
        double M2 = FluidSystem::molarMass(nComp);
        double avgMolarMass = M1*M2/(M2 + ss.massfrac[wPhase][nComp]*(M1 - M2));
        fluidState.setMoleFraction(wPhase, nComp, ss.massfrac[wPhase][nComp]*avgMolarMass/M2);
        fluidState.setMoleFraction(wPhase, wComp, ss.massfrac[wPhase][wComp]*avgMolarMass/M1);
        ss.density[wPhase] = brineCo2_.density(fluidState, paramCache, wPhase);
        fluidState.setDensity(wPhase, ss.density[wPhase]);
        ss.phaseVolume[wPhase] = (massH20+massCO2)/ss.density[wPhase];
        fluidState.setSaturation(wPhase, ss.saturation);
        // Virtual properties of non-existing gas phase:
        paramCache.updatePhase(fluidState, /*phaseIdx=*/nPhase);
        typedef ComputeFromReferencePhase</*Scalar=*/double, FluidSystem> CFRP;
        CFRP::solve(fluidState,
                    paramCache,
                    /*refPhaseIdx=*/wPhase,
                    /*setViscosity=*/false,
                    /*setEnthalpy=*/false);
        ss.massfrac[nPhase][nComp] = fluidState.massFraction(nPhase, nComp);
        ss.massfrac[nPhase][wComp] = fluidState.massFraction(nPhase, wComp);
        ss.density[nPhase] = fluidState.density(nPhase);
        ss.phaseVolume[nPhase] = 0.0;
        fluidState.setSaturation(nPhase, 1.0 - ss.saturation);
    } 
        
    ss.phaseViscosity[wPhase] = brineCo2_.viscosity(fluidState, paramCache, wPhase);
    ss.phaseViscosity[nPhase] = brineCo2_.viscosity(fluidState, paramCache, nPhase);

}
コード例 #20
0
ファイル: jsfluid.cpp プロジェクト: tikwid/jsfluid
void step () 
{
	psys.Run();
	frame++;
}