void IsotropicDirection(double *u, double *v, double *w, long id)
{
  double rand1, rand2, rand3, C1, C2;

  /* Use the rejection method described in Lux & Koblinger, pp. 21-22. */

  do
    {
      rand1 = 2.0*RandF(id) - 1.0;
      rand2 = 2.0*RandF(id) - 1.0;
      C1 = rand1*rand1 + rand2*rand2;
    }
  while (C1 > 1.0);
  
  rand3 = 2.0*RandF(id) - 1.0;
  
  C2 = sqrt(1 - rand3*rand3);
  
  *u = C2*(rand1*rand1 - rand2*rand2)/C1;
  *v = C2*2.0*rand1*rand2/C1;
  *w = rand3;

  /* Check value and exit. */

  CheckValue(FUNCTION_NAME, "r", "", *u**u+*v**v+*w**w - 1.0, -1E-10, 1E-10);
}
Beispiel #2
0
cordine MathHelp::MakeNoiseOf(cordine accuratetarget)
{
    srand((unsigned)time(NULL));
    int x = accuratetarget.first;
    int y = accuratetarget.second;
    double randr = AINOISERADIUS*RandF();
    double theta = RandF() * 2 * XC_PI;
    int tx =(int)( x + randr*cos(theta));
    int ty =(int) (y + randr*sin(theta));
    return cordine(tx, ty);
}
Beispiel #3
0
Vector3f Terrain::GetRandomPoint()const{
	float dx = CELLSPACING;
	float halfWidth = (gridWidth-1)*dx*0.5f;
	float halfDepth = (gridDepth-1)*dx*0.5f;

	float z = RandF(-(float)gridWidth/2,(float)gridWidth/2);		
	float x = RandF(-(float)gridDepth/2,(float)gridDepth/2);

	float y = GetHeight(x,z);	

	x+=mTransform->position.x;
	z+=mTransform->position.z;

	return Vector3f(x,y,z);
}
Beispiel #4
0
double CHierarchicalDP::SamplingLambda( double oldLambda )
{
	for(int i=0 ; i<50 ; i++ )
	{
		float gammaB = 0;	// ガンマ関数スケールパラメータ
		float gammaA = 0;	// ガンマ関数形状パラメータ
		int numAllTables = 0;

		for(int d=0 ; d<m_dataNum ; d++ )
		{
			int len = m_documents_d[d].length;

			// ベータ分布からサンプル生成
			float w = genbet( (float)oldLambda+1 , (float)len );
			gammaB -= log(w);
			
			// 二値分布からサンプリング
			int s = (RandF() * (oldLambda + len)) < len ? 1 : 0;
			gammaA -= s;

			// テーブルの総数を計算
			numAllTables += (int)m_documents_d[d].tables_t.size()-1;
		}

		// 事後分布のパラメタを計算
		gammaA += (float)(HDP_CONCPARA_PRIOR_A + numAllTables);
		gammaB += (float)HDP_CONCPARA_PRIOR_B;

		// 更新
		oldLambda = (double)gengam( gammaB , gammaA );
	}

	return oldLambda;
}
Beispiel #5
0
double CHierarchicalDP::SamplingGamma( double oldGamma )
{
	// テーブルの総数を計算
	int numAllTables = 0;
	for(int k=0 ; k<m_dishes_k.size() ; k++ )
	{
		numAllTables += m_dishes_k[k].GetPopularity();
	}

	for(int i=0 ; i<20 ; i++ )
	{
		float gammaB = 0;	// ガンマ関数スケールパラメータ
		float gammaA = 0;	// ガンマ関数形状パラメータ
		int numDish = (int)m_dishes_k.size();

		// ベータ分布からサンプル生成
		float w = genbet( (float)oldGamma+1 , (float)numAllTables );

		// 二値の分布をサンプリング
		int s = (RandF() * (oldGamma + numDish)) < numDish ? 1 : 0;
		gammaA = (float)(HDP_CONCPARA_PRIOR_A + numDish - s);
		gammaB = (float)(HDP_CONCPARA_PRIOR_B - log(w));

		// 更新
		oldGamma = (double)gengam( gammaB , gammaA );
	}

	return oldGamma;
}
Beispiel #6
0
void ParticleSystem::BuildRandomTexture()
{
	
	// Create the random data.
	D3DXVECTOR4 randomValues[1024];

	for(int i = 0; i < 1024; ++i)
	{
		randomValues[i].x = RandF(-1.0f, 1.0f);
		randomValues[i].y = RandF(-1.0f, 1.0f);
		randomValues[i].z = RandF(-1.0f, 1.0f);
		randomValues[i].w = RandF(-1.0f, 1.0f);
	}

    D3D10_SUBRESOURCE_DATA initData;
    initData.pSysMem = randomValues;
	initData.SysMemPitch = 1024*sizeof(D3DXVECTOR4);
    initData.SysMemSlicePitch = 1024*sizeof(D3DXVECTOR4);

	// Create the texture.
    D3D10_TEXTURE1D_DESC texDesc;
    texDesc.Width = 1024;
    texDesc.MipLevels = 1;
    texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    texDesc.Usage = D3D10_USAGE_IMMUTABLE;
    texDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
    texDesc.CPUAccessFlags = 0;
    texDesc.MiscFlags = 0;
    texDesc.ArraySize = 1;

	ID3D10Texture1D* randomTex = 0;
    mDevice->CreateTexture1D(&texDesc, &initData, &randomTex);
	
	// Create the resource view.
    D3D10_SHADER_RESOURCE_VIEW_DESC viewDesc;
	viewDesc.Format = texDesc.Format;
    viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1D;
    viewDesc.Texture1D.MipLevels = texDesc.MipLevels;
	viewDesc.Texture1D.MostDetailedMip = 0;
	
	if(mRandomTexRV != 0)	//Avoid memory leaks as this is called every update
		SAFE_RELEASE(mRandomTexRV);
    mDevice->CreateShaderResourceView(randomTex, &viewDesc, &mRandomTexRV);

	SAFE_RELEASE(randomTex);
	
}
void ParticleEngine::CreateRandomTex()
{
	HRESULT hr;

	D3DXVECTOR4 randomValues[1024];

	for(int i = 0; i < 1024; i++)
	{
		randomValues[i].x = RandF(-1.0f, 1.f);
		randomValues[i].y = RandF(-1.0f, 1.f);
		randomValues[i].z = RandF(-1.0f, 1.f);
		randomValues[i].w = RandF(-1.0f, 1.f);
	}

	D3D10_SUBRESOURCE_DATA initData;
	initData.pSysMem			= randomValues;
	initData.SysMemPitch		= sizeof(D3DXVECTOR4)*1024;
	initData.SysMemSlicePitch	= sizeof(D3DXVECTOR4)*1024;

	D3D10_TEXTURE1D_DESC texDesc;
	texDesc.Width			= 1024;
	texDesc.MipLevels		= 1;
	texDesc.Format			= DXGI_FORMAT_R32G32B32A32_FLOAT;
	texDesc.Usage			= D3D10_USAGE_IMMUTABLE;
	texDesc.BindFlags		= D3D10_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags	= 0;
	texDesc.MiscFlags		= 0;
	texDesc.ArraySize		= 1;

	ID3D10Texture1D* randTex = 0;
	hr = device->CreateTexture1D(&texDesc, &initData, &randTex);
	if(FAILED(hr))
		MessageBox(NULL, "( ParticleEngine ) Failed to create Random Texture", NULL, NULL);

	D3D10_SHADER_RESOURCE_VIEW_DESC rViewDesc;
	rViewDesc.Format					= texDesc.Format;
	rViewDesc.ViewDimension				= D3D10_SRV_DIMENSION_TEXTURE1D;
	rViewDesc.Texture1D.MipLevels		= texDesc.MipLevels;
	rViewDesc.Texture1D.MostDetailedMip = 0;

	hr = device->CreateShaderResourceView(randTex, &rViewDesc, &randomTex);
	if(FAILED(hr))
		MessageBox(NULL, "( ParticleEngine ) Failed to create Random Texture ResourceView", NULL, NULL);

	randTex->Release();
}
Beispiel #8
0
int CHierarchicalDP::SamplingTable( std::vector<CHDPTable> &tables , int w )
{
	int numTables = (int)tables.size();
	int numDishes = (int)m_dishes_k.size();
	double *P = m_P;
	int newTable = -1;
	double max = -DBL_MAX;


	// 最後のテーブルは空のテーブル
	if( numTables == 1 ) return 0;

	// 各テーブルに属する対数尤度
	for(int t=0 ; t<numTables-1 ; t++ )
	{
		int k = tables[t].GetDishID();
		P[t] = m_dishes_k[k].CalcLogLikilihood( w );
	}
	P[numTables-1] = m_dishes_k[numDishes-1].CalcLogLikilihood( w );

	// 最大値を探す
	for(int t=0 ; t<numTables ; t++ ) if( max < P[t] ) max = P[t];


	// 値が小さくなりすぎるため、最大値で引く
	// 各テーブルの人気をかける
	// サンプリングのために累積確率にする
	P[0] = exp(P[0] - max) * tables[0].GetDataNum();
	for(int t=1 ; t<numTables-1 ; t++ ) P[t] = P[t-1] + exp(P[t] - max) * tables[t].GetDataNum(); 

	// 新たなテーブルを生成する確率
	P[numTables-1] = P[numTables-2] + exp(P[numTables-1] - max) * m_lambda;

	// サンプリングするための乱数を発生
	double rand = RandF() * P[numTables-1];

	// 計算した確率に従って新たなテーブルを選択
	for(newTable=0 ; newTable<numTables-1 ; newTable++ )
	{
		if( P[newTable] >= rand ) break;
	}
	return newTable;
}
Beispiel #9
0
int CHierarchicalDP::SamplingDish( std::vector<int> &w )
{
	int numDishes = (int)m_dishes_k.size();
	double *P = m_P;
	int newDish = -1;
	double max = -DBL_MAX;

	// まだ料理は誰も食べていないので、新メニュー
	// indexの最後が新メニューを表している
	if( numDishes == 1 ) return 0;

	// 人wが料理kを好む対数尤度
	for(int k=0 ; k<numDishes ; k++ )
	{
		P[k] = m_dishes_k[k].CalcLogLikilihood( w );
	}

	// 最大値を探す
	for(int k=0 ; k<numDishes ; k++ ) if( max < P[k] ) max = P[k];


	P[0] = exp(P[0] - max) * m_dishes_k[0].GetPopularity();
	for(int k=1 ; k<numDishes-1 ; k++ ) P[k] = P[k-1] + exp(P[k] - max) * m_dishes_k[k].GetPopularity(); 

	// 新たなテーブルを生成する確率
	P[numDishes-1] = P[numDishes-2] + exp(P[numDishes-1] - max) * m_gamma;

	// サンプリングするための乱数を発生
	double rand = RandF() * P[numDishes-1];

	// 計算した確率に従って新たなテーブルを選択
	for(newDish=0 ; newDish<numDishes-1 ; newDish++ )
	{
		if( P[newDish] >= rand ) break;
	}

	return newDish;
}
Beispiel #10
0
void Hill::Render(ID3D11DeviceContext *pD3D11DeviceContext, const d3d::MatrixBuffer &matrix, d3d::Timer *pTimer, d3d::Camera *pCam)
{

	//
	// Animate the lights.
	//
	// Circle light over the land surface.
	m_PointLight.Position.x = 70.0f*cosf(0.2f * pTimer->GetTotalTime());
	m_PointLight.Position.z = 70.0f*sinf(0.2f * pTimer->GetTotalTime());
	m_PointLight.Position.y = max(GetHeight(m_PointLight.Position.x, m_PointLight.Position.z), -3.0f)+10.0f;


	// The spotlight takes on the camera position and is aimed in the
	// same direction the camera is looking.  In this way, it looks
	// like we are holding a flashlight.
	XMFLOAT4 camPos = pCam->GetCamPos();
	m_EyePos =  XMFLOAT3(camPos.x, camPos.y, camPos.z);
	XMVECTOR pos    = XMVectorSet(camPos.x, camPos.y, camPos.z, 0.0f);
	XMVECTOR target = XMVectorZero();
	XMVECTOR up     = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	m_SpotLight.Position = m_EyePos;
	XMStoreFloat3(&m_SpotLight.Direction, XMVector3Normalize(target-pos));


	// Every quarter second, generate a random wave.

	static float t_base = 0.0f;
	if ((pTimer->GetTotalTime() - t_base) >= 0.25f)
	{
		t_base += 0.25f;

		DWORD i = 5 + rand() % 190;
		DWORD j = 5 + rand() % 190;

		float r = RandF(1.0f, 2.0f);
		m_Wave.Disturb(i, j, r);
	}

	m_Wave.Update(pTimer->GetDeltaTime());

	// Update the wave vertex buffer with the new solution.

	D3D11_MAPPED_SUBRESOURCE mappedData;
	pD3D11DeviceContext->Map(m_pWaveVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData);

	Vertex* v = reinterpret_cast<Vertex*>(mappedData.pData);
	for (UINT i = 0; i < m_Wave.VertexCount(); ++i)
	{
		v[i].Pos = m_Wave[i]; 	
		v[i].Normal = m_Wave.Normal(i);
		// Derive tex-coords in [0,1] from position.
		v[i].TexCoord.x  = 0.5f+m_Wave[i].x/m_Wave.Width();
		v[i].TexCoord.y  = 0.5f-m_Wave[i].z/m_Wave.Depth();
	}

	pD3D11DeviceContext->Unmap(m_pWaveVB, 0);

	cbMatrix.model = matrix.model;
	cbMatrix.view  = matrix.view;
	cbMatrix.proj  = matrix.proj;

	// Set vertex buffer stride and offset
	unsigned int stride;
	unsigned int offset;
	stride = sizeof(Vertex);
	offset = 0;
	pD3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	pD3D11DeviceContext->IASetInputLayout(m_pInputLayout);

	m_pFxDirLight->SetRawValue(&m_DirLight, 0, sizeof( m_DirLight ));
	m_pFxPointLight->SetRawValue(&m_PointLight, 0, sizeof( m_PointLight ));
	m_pFxSpotLight->SetRawValue(&m_SpotLight, 0, sizeof( m_SpotLight ));
	m_pFxEyePos->SetRawValue(&m_EyePos, 0, sizeof( m_EyePos ));
	m_pFxWorld->SetMatrix(reinterpret_cast< float* >( &cbMatrix.model ));
	m_pFxView->SetMatrix(reinterpret_cast< float* >( &cbMatrix.view ));
	m_pFxProj->SetMatrix(reinterpret_cast< float* >( &cbMatrix.proj ));

	D3DX11_TECHNIQUE_DESC techDesc;
	m_pEffectTechnique->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{

		m_pFxMaterial->SetRawValue(&m_LandMat, 0, sizeof( m_LandMat ));
		m_pFxDiffuseMap->SetResource(m_pGrassSRV);

		pD3D11DeviceContext->IASetVertexBuffers(0, 1, &m_pLandVB, &stride, &offset);
		pD3D11DeviceContext->IASetIndexBuffer(m_pLandIB, DXGI_FORMAT_R32_UINT, 0);
		m_pEffectTechnique->GetPassByIndex(p)->Apply(0, pD3D11DeviceContext);
		pD3D11DeviceContext->DrawIndexed(m_IndexCount, 0, 0);

//////////////////////////////////////////////////////////////////////////////////////////////

		m_pFxMaterial->SetRawValue(&m_WavesMat, 0, sizeof( m_WavesMat ));
		m_pFxDiffuseMap->SetResource(m_pWaveSRV);

		pD3D11DeviceContext->IASetVertexBuffers(0, 1, &m_pWaveVB, &stride, &offset);
		pD3D11DeviceContext->IASetIndexBuffer(m_pWaveIB, DXGI_FORMAT_R32_UINT, 0);
		m_pEffectTechnique->GetPassByIndex(p)->Apply(0, pD3D11DeviceContext);
		pD3D11DeviceContext->DrawIndexed(3 * m_Wave.TriangleCount(), 0, 0);
	}


}
Beispiel #11
0
double TTB(long mat, long part, double Te, double x, double y, double z, double u,
         double v, double w, double wgt, double t, long pflag, long id) {

  long ptd, ptr, nTe0, new1, brcdfptr, brpdfptr, Ncdf, Nk, idx, i;
  double  sumEk, lTe, Yk, rcdf, Ek, cdfmax, a, Ed;
  const double *Ted, *lTed, *lYkd, *brcdf, *brpdf;

  if ((Te < RDB[DATA_PHOTON_EMIN]) || (RDB[DATA_PHOTON_USE_TTB] == NO)) {
    /* Electron/positron energy is deposited locally */
    /* TODO: (!RDB[DATA_PHOTON_USE_TTB]) vois siirtää rutiineihin, joissa elektroneja
      luodaan */
    return Te;
  }

  CheckPointer(FUNCTION_NAME, "(mat)", DATA_ARRAY, mat);
  CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part);

  ptd = (long)RDB[mat + MATERIAL_PTR_TTB];
  CheckPointer(FUNCTION_NAME, "(ptd)", DATA_ARRAY, ptd);

  nTe0 = (long)RDB[ptd + TTB_NE];

  ptr = (long)RDB[ptd + TTB_E];
  CheckPointer(FUNCTION_NAME, "(Te0)", DATA_ARRAY, ptr);
  Ted = &RDB[ptr];

  ptr = (long)RDB[ptd + TTB_LE];
  CheckPointer(FUNCTION_NAME, "(lTe0)", DATA_ARRAY, ptr);
  lTed = &RDB[ptr];

  /* Select positron or electron data */
  if (pflag && ((long)RDB[DATA_PHOTON_TTBPM] == YES)) {
    /* Positron */
    ptr = (long)RDB[ptd + TTB_LYP];
    CheckPointer(FUNCTION_NAME, "(lYph0)", DATA_ARRAY, ptr);
    lYkd = &RDB[ptr];

    ptr = (long)RDB[ptd + TTB_BRPCDF];
    CheckPointer(FUNCTION_NAME, "(brpcdf)", DATA_ARRAY, ptr);
    brcdfptr = ptr;

    ptr = (long)RDB[ptd + TTB_BRPPDF];
    CheckPointer(FUNCTION_NAME, "(brppdf", DATA_ARRAY, ptr);
    brpdfptr = ptr;
  }
  else {
    /* Electron */
    ptr = (long)RDB[ptd + TTB_LYE];
    CheckPointer(FUNCTION_NAME, "(lYph0)", DATA_ARRAY, ptr);
    lYkd = &RDB[ptr];

    ptr = (long)RDB[ptd + TTB_BRECDF];
    CheckPointer(FUNCTION_NAME, "(brecdf)", DATA_ARRAY, ptr);
    brcdfptr = ptr;

    ptr = (long)RDB[ptd + TTB_BREPDF];
    CheckPointer(FUNCTION_NAME, "(brepdf)", DATA_ARRAY, ptr);
    brpdfptr = ptr;
  }

  /* Find log energy NOTE: assuming log interpolated energy array */
  lTe = log(Te);
  idx = (long)((lTe - lTed[0])/(lTed[1] - lTed[0]));

  /* Check index and energy TODO: Nämä vois laittaa checkeiksi */
  if ((idx < 0) || (idx > nTe0))
    Die(FUNCTION_NAME, "Electron/positron energy not found for index %ld", idx);

  if ((Te < Ted[idx]) || (Te > Ted[idx+1]))
    Die(FUNCTION_NAME, "Energy not found in the interval: Ted[%ld] = %.5E, Te = %.5E, Ted[%ld] = %.5E", idx, Ted[idx], Te, idx+1, Ted[idx+1]);

  /* Interpolate photon yield */
  Yk = exp(lYkd[idx] + (lYkd[idx+1] - lYkd[idx])*(lTe - lTed[idx])
      /(lTed[idx+1] - lTed[idx]));

  /* Sample number of photons */
  Nk = (long)(Yk + RandF(id));

  CheckValue(FUNCTION_NAME, "Nk", "", Nk, 0, INFTY);

  if (Nk == 0) {
    /* No bremsstrahlung photons created, deposit energy locally */
    return Te;
  }

  /* Set bremsstrahlung energy cdf and pdf, the grid is selected using
   * interpolation weights */
  if ((idx == 0) || (lTed[idx] + RandF(id)*(lTed[idx+1] - lTed[idx]) <= lTe)) {
    brcdf = &RDB[(long)RDB[brcdfptr + idx + 1]];
    brpdf = &RDB[(long)RDB[brpdfptr + idx + 1]];
    Ncdf = idx + 2; /* +2 due to the index change */

    /* Interpolate the maximum cdf assuming the cdf is integrated from linearly
     * interpolated pdf (pdf(x) = ax + b) */
    a = (brpdf[idx+1] - brpdf[idx]) / (Ted[idx+1] - Ted[idx]);
    cdfmax = brcdf[idx] + 0.5*(2.0*brpdf[idx] + a*(Te - Ted[idx]))*(Te - Ted[idx]);
  }
  else {
    /* NOTE: The lower index is selected, meaning that the maximum photon energy
     * will be below the electron energy */
    brcdf = &RDB[(long)RDB[brcdfptr + idx]];
    brpdf = &RDB[(long)RDB[brpdfptr + idx]];
    Ncdf = idx + 1;
    cdfmax = brcdf[idx];
  }


  /***** Sample photon energies **********************************************/

  sumEk = 0;

  for (i = 0; i < Nk; i++) {

    /* Sample from  */
    rcdf = RandF(id)*cdfmax;
    idx = SearchArray(brcdf, rcdf, Ncdf);

    if (idx == -1)
      Die(FUNCTION_NAME, "rcdf not found");

    /* Solve the photon energy assuming linearly interpolated pdf */
    a = (brpdf[idx+1] - brpdf[idx]) / (Ted[idx+1] - Ted[idx]);
    Ek = Ted[idx] + (sqrt(brpdf[idx]*brpdf[idx] + 2.0*a*(rcdf - brcdf[idx]))
          - brpdf[idx])/a;

    /* Check Ek limits */
    CheckValue(FUNCTION_NAME, "bremsstrahlung photon energy", "",
               Ek, Ted[idx], Ted[idx+1]);

    if (Ek < RDB[DATA_PHOTON_EMIN])
      Die(FUNCTION_NAME, "Photon energy %.5E smaller than DATA_PHOTON_EMIN", Ek);
    if (Ek > Te)
      Die(FUNCTION_NAME, "Photon energy %.5E larger than electron/positron energy", Ek);

    sumEk += Ek;

    if ((sumEk > Te) && ((long)RDB[DATA_PHOTON_TTBEC] == YES)) {
      /* Sum of photon energies is above the electron energy. Sampling is stopped */

      /* Residual energy */
      sumEk -= Ek;
      Ek = Te - sumEk;

      if (Ek < RDB[DATA_PHOTON_EMIN]) {
        /* The last photon is not created */
        Nk = i;
      }
      else {
        /* Create a new photon having the residual energy */
        sumEk = Te;

        /* Correct the number of photons */
        Nk = i+1;

        new1 = DuplicateParticle(part, id);
        WDB[new1 + PARTICLE_X] = x;
        WDB[new1 + PARTICLE_Y] = y;
        WDB[new1 + PARTICLE_Z] = z;
        WDB[new1 + PARTICLE_WGT] = wgt; /*TODO: Onko oikein? */
        WDB[new1 + PARTICLE_T] = t;
        WDB[new1 + PARTICLE_E] = Ek;
        WDB[new1 + PARTICLE_U] = u;
        WDB[new1 + PARTICLE_V] = v;
        WDB[new1 + PARTICLE_W] = w;

        ToQue(new1, id);
      }

      break;
    }

    /* Create new photon */
    new1 = DuplicateParticle(part, id);

    WDB[new1 + PARTICLE_X] = x;
    WDB[new1 + PARTICLE_Y] = y;
    WDB[new1 + PARTICLE_Z] = z;
    WDB[new1 + PARTICLE_WGT] = wgt; /*TODO: Onko oikein? */
    WDB[new1 + PARTICLE_T] = t;
    WDB[new1 + PARTICLE_E] = Ek;

    /* NOTE: Photon direction is not sampled */
    WDB[new1 + PARTICLE_U] = u;
    WDB[new1 + PARTICLE_V] = v;
    WDB[new1 + PARTICLE_W] = w;

    ToQue(new1, id);
  }

  /***************************************************************************/


  /* Locally deposited energy */
  Ed = Te - sumEk;

  /* Ed can be negative if RDB[DATA_PHOTON_TTBEC]==NO.
   * TODO: Should energy deposition be used only when RDB[DATA_PHOTON_TTBEC]==YES?
   * */
  if (Ed < 0.0)
    Ed = 0.0;

  /* TODO: Statistics: Total number of bremsstrahlung photons created */
  /* WDB[DATA_PHOTON_BREM_TOT] += Nk; */

  return Ed;
}
Beispiel #12
0
D3DXVECTOR3 D3DCore_Impl::Random_UnitVec3()
{
	D3DXVECTOR3 v(RandF(), RandF(), RandF());
	D3DXVec3Normalize(&v, &v);
	return v;
}
Beispiel #13
0
// Returns random float in [a, b).
static float RandF(float a, float b)
{
	return a + RandF() * (b - a);
}
Beispiel #14
0
void Disperse2()
{
  double xmin, xmax, ymin, ymax, zmin, zmax, x, y, z, u, v, w;
  long uni0, cell0, root, cell, id, n;
  unsigned long seed;
  char uname[MAX_STR], cname[MAX_STR];

  /***************************************************************************/

  /***** Prompt input data ***************************************************/
  return;
  /* Get universe */
  
  fprintf(out, "Enter universe:\n");
    
  if (scanf("%s", uname) == EOF)
    Die(FUNCTION_NAME, "fscanf error");

  /* Get cell */
  
  fprintf(out, "Enter cell:\n");
    
  if (scanf("%s", cname) == EOF)
    Die(FUNCTION_NAME, "fscanf error");

  /***************************************************************************/

  /***** Find cell and universe pointers *************************************/

  /* Loop over universes */

  uni0 = (long)RDB[DATA_PTR_U0];
  while (uni0 > VALID_PTR)
    {
      /* Compare name */

      if (!strcmp(GetText(uni0 + UNIVERSE_PTR_NAME), uname))
	break;

      /* Next */

      uni0 = NextItem(uni0);
    }

  /* Check pointer */

  if (uni0 < VALID_PTR)
    Error(0, "Universe %s not found in geometry", uname);

  /* Loop over cells */

  cell0 = (long)RDB[DATA_PTR_C0];
  while (cell0 > VALID_PTR)
    {
      /* Compare name */

      if (!strcmp(GetText(cell0 + CELL_PTR_NAME), cname))
	break;

      /* Next */

      cell0 = NextItem(cell0);
    }

  /* Check pointer */

  if (cell0 < VALID_PTR)
    Error(0, "Cell %s not found in geometry", cname);

  /* Set thread id */

  id = 0;

  /* Init random number sequence */
      
  seed = ReInitRNG(1);
  SEED[0] = seed;

  /* Set plotter mode to avoid termination in geometry error, and quick */
  /* plotter mode to disable overlap check */

  WDB[DATA_PLOTTER_MODE] = (double)YES;
  WDB[DATA_QUICK_PLOT_MODE] = (double)YES;

  /* Override root universe pointer */

  root = (long)RDB[DATA_PTR_ROOT_UNIVERSE];
  WDB[DATA_PTR_ROOT_UNIVERSE] = (double)uni0;

  /***************************************************************************/

  /***** Sample code *********************************************************/

  /* Check pointers */

  CheckPointer(FUNCTION_NAME, "(uni0)", DATA_ARRAY, uni0);
  CheckPointer(FUNCTION_NAME, "(cell0)", DATA_ARRAY, cell0);

  /* Get universe boundaries */

  xmin = RDB[uni0 + UNIVERSE_MINX];
  xmax = RDB[uni0 + UNIVERSE_MAXX];
  ymin = RDB[uni0 + UNIVERSE_MINY];
  ymax = RDB[uni0 + UNIVERSE_MAXY];
  zmin = RDB[uni0 + UNIVERSE_MINZ];
  zmax = RDB[uni0 + UNIVERSE_MAXZ];
  
  fprintf(out, "\nboundaries : \nx = [%E,%E] \ny = [%E %E] \nz = [%E %E]\n\n",
	  xmin, xmax, ymin, ymax, zmin, zmax);

  /* Set direction vector (needed but not used) */

  u = 1.0;
  v = 0.0;
  w = 0.0;

  /* Sample 1000 random points and print coordinates that are inside the */
  /* universe and cell */

  for (n = 0; n < 1000; n++)
    {
      /* Sample random point */

      x = RandF(id)*(xmax - xmin) + xmin;
      y = RandF(id)*(ymax - ymin) + ymin;
      z = RandF(id)*(zmax - zmin) + zmin;

      /* Get cell pointer at position */

      cell = WhereAmI(x, y, z, u, v, w, id);

      /* Check pointer and print coordinates */

      if (cell == cell0)
	fprintf(out, "%E %E %E\n", x, y, z);
    }

  /***************************************************************************/

  /* Reset plotter mode */

  WDB[DATA_PLOTTER_MODE] = (double)YES;

  /* Put root universe pointer */

  WDB[DATA_PTR_ROOT_UNIVERSE] = (double)root;

  /* Terminate calculation */

  exit(0);
}
Beispiel #15
0
long MoveDT(long part, double majorant, double minxs, long *cell, double *xs0, 
	    double *x, double *y, double *z, double *l0, double *u, double *v, 
	    double *w, double E, long id)
{
  long ptr, type, mat, mat0, bc;
  double totxs, l, wgt;

  /* Check particle pointer */

  CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part);

  /* Check coordinates and direction cosines */

  CheckValue(FUNCTION_NAME, "x", "", *x, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "y", "", *y, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "z", "", *z, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "u", "", *u, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "v", "", *v, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "w", "", *w, -1.0, 1.0);

  /* Get particle type */

  type = (long)RDB[part + PARTICLE_TYPE];  

  /* Add to DT fraction counter */
		
  ptr = (long)RDB[RES_DT_TRACK_FRAC];
  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
  AddBuf1D(1.0, 1.0, ptr, id, 2 - type);
  
  /* Check cross section and sample path length */
  
  CheckValue(FUNCTION_NAME, "majorant", "", majorant, ZERO, INFTY);
  l = -log(RandF(id))/majorant;

  /* Move particle to collision site */
		  
  *x = *x + *u*l;
  *y = *y + *v*l;
  *z = *z + *w*l;

  /* Set path length */
      
  *l0 = l;

  /* Reset previous material pointer and total xs */

  mat0 = -1;
  totxs = 0.0;

  /* Find location */

  *cell = WhereAmI(*x, *y, *z, *u, *v, *w, id);
  CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, *cell);

  /* Check if point is outside the geometry */

  if ((long)RDB[*cell + CELL_TYPE] == CELL_TYPE_OUTSIDE)
    {
      /* Check if track is stopped at outer boundary */
		  
      if ((long)RDB[DATA_STOP_AT_BOUNDARY] == NO)
	{
	  /* Set weight to test that albedo boundary conditions were not */
	  /* applied */

	  wgt = 1.0;

	  /* Apply repeated boundary conditions */

	  bc = BoundaryConditions(cell, x, y, z, u, v, w, &wgt, id);

	  /* Check that condition was applied */
	  
	  if (bc != YES)
	    Die(FUNCTION_NAME, "Repeated bc not apllied");
 
	  /* Check change in weight */

	  if (wgt != 1.0)
	    Die(FUNCTION_NAME, "Change in weight (albedo)");

	  /* Find location */

	  *cell = WhereAmI(*x, *y, *z, *u, *v, *w, id);
	  CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, *cell);
	}
      else 
	{
	  /* Stop track at boundary */

	  StopAtBoundary(cell, x, y, z, l0, *u, *v, *w, id);

	  /* Set cross section */

	  *xs0 = -1.0;

	  /* Check distance */

	  CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);

	  /* Return surface crossing */
      
	  return TRACK_END_SURF;
	}
    }

  /* Get material pointer */

  mat = (long)RDB[*cell + CELL_PTR_MAT];
  mat = MatPtr(mat, id);
  
  /* Check pointer */
  
  if (mat != mat0)
    {
      /* Get total cross section */
      
      totxs = TotXS(mat, type, E, id);
      
      /* Remember material */
      
      mat0 = mat;
    }
  
  /* Check total xs */
  
  CheckValue(FUNCTION_NAME, "totxs", "", totxs, 0.0, INFTY);
  
  /* Compare to minimum value */
  
  if (totxs > minxs)
    {
      /* Sample between real and virtual collision */
      
      if (RandF(id) < totxs/majorant)
	{
	  /* Set cross section */
	  
	  *xs0 = totxs;
	  
	  /* Add to success counter */
	  
	  ptr = (long)RDB[RES_DT_TRACK_EFF];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr);
	  AddBuf1D(1.0, 1.0, ptr, id, 2 - type);
	  
	  /* Check distance */

	  CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);

	  /* Return collision */
	  
	  return TRACK_END_COLL;
	}
      else
	{
	  /* Set cross section */
	  
	  *xs0 = -1.0;
	  
	  /* Add to failure counter */
	  
	  ptr = (long)RDB[RES_DT_TRACK_EFF];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr);
	  AddBuf1D(1.0, 1.0, ptr, id, 4 - type);
	  
	  /* Check distance */

	  CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);

	  /* Return virtual */
	  
	  return TRACK_END_VIRT;
	}
    }
  else
    {
      /* Sample scoring */
      
      if (RandF(id) < minxs/majorant)
	{
	  /* Set cross section */
	  
	  *xs0 = minxs;
	  
	  /* Sample between real and virtual collision */
	  
	  if (RandF(id) < totxs/minxs)
	    {
	      /* Add to success counter */
	      
	      ptr = (long)RDB[RES_DT_TRACK_EFF];
	      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr);
	      AddBuf1D(1.0, 1.0, ptr, id, 2 - type);
	      
	      /* Check distance */

	      CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);

	      /* Return collision */
	      
	      return TRACK_END_COLL;
	    }
	  else
	    {
	      /* Add to failure counter */
	      
	      ptr = (long)RDB[RES_DT_TRACK_EFF];
	      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr);
	      AddBuf1D(1.0, 1.0, ptr, id, 4 - type);
	      
	      /* Check distance */

	      CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);
	  
	      /* Return virtual */
	      
	      return TRACK_END_VIRT;
	    }
	}
      else
	{
	  /* Set cross section */
	  
	  *xs0 = -1.0;
	  
	  /* Add to failure counter */
	  
	  ptr = (long)RDB[RES_DT_TRACK_EFF];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr);
	  AddBuf1D(1.0, 1.0, ptr, id, 4 - type);
	  
	  /* Check distance */

	  CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY);

	  /* Return virtual */
	  
	  return TRACK_END_VIRT;
	}
    }
}
Beispiel #16
0
MenuObjects::MenuObjects(string filename, ID3D10Device* device, ID3D10ShaderResourceView* diff, int id, ID3D10ShaderResourceView* spec, D3DXVECTOR3 position, D3DXVECTOR3 rotation, D3DXVECTOR3 scale)
{
	mModelData = new LoadModel(filename);
	mModelSize = mModelData->getModelDataSize();
	mModel = new VertexPos4NorTex[mModelSize];
	for(int i = 0; i < mModelSize; i++)
	{
		mModel[i].pos = mModelData->getModelPosition(i);
		mModel[i].normal = mModelData->getModelNormal(i);
		mModel[i].texC = mModelData->getModelTexture(i);
	}

	mDevice = device;
	mPosition = position;
	mRotation.x = rotation.x * (PI / 180);
	mRotation.y = rotation.y * (PI / 180);
	mRotation.z = rotation.z * (PI / 180);
	mScale = scale;
	D3DXMatrixScaling(&S, mScale.x, mScale.y, mScale.z);
	D3DXMatrixRotationX(&Rx, mRotation.x);
	D3DXMatrixRotationY(&Ry, mRotation.y);
	D3DXMatrixRotationZ(&Rz, mRotation.z);
	D3DXMatrixTranslation(&T, mPosition.x, mPosition.y, mPosition.z);
	W = S * Rx * Ry * Rz * T;
	mStartPos = position;

	mW = Effects::mModelFX->GetVariableByName("gWorld")->AsMatrix();
	mV = Effects::mModelFX->GetVariableByName("gV")->AsMatrix();
	mP = Effects::mModelFX->GetVariableByName("gP")->AsMatrix();

	mTechnique = Effects::mModelFX ->GetTechniqueByName("Render");
	mfxModelLightWVPVar = Effects::mModelFX->GetVariableByName("gLightWVP")->AsMatrix();

	mDiff = diff;
	mSpec = spec;

	mRotated = false;
	mId = id;
	t = 0;
	rot = RandF(0, 2 * PI);

	//Get texture
	mEffectDiffMapVar = Effects::mModelFX ->GetVariableByName("gDiffuseMap")->AsShaderResource();
	mEffectSpecMapVar = Effects::mModelFX ->GetVariableByName("gSpecMap")->AsShaderResource();

	//init buffer with defined line list data
	D3D10_BUFFER_DESC vbd;
	vbd.Usage = D3D10_USAGE_DEFAULT;
	vbd.ByteWidth = sizeof(VertexPos4NorTex) * mModelSize;
	vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;

	D3D10_SUBRESOURCE_DATA vinitData;
	 vinitData.pSysMem = mModel;

	mDevice->CreateBuffer(
		&vbd,		//description of buffer to create
		&vinitData, //data to initialize buffer with
		&mVertexBuffer);		//return the created buffer
}
Beispiel #17
0
long Collision(long mat, long part, double x, double y, double z, double *u, 
	       double *v, double *w, double *E, double *wgt, double t, long id)
{
  long type, rea, nuc, ptr, mt, scatt, icapt;
  double totxs, absxs, E0, u0, v0, w0, mu, wgt0, wgt1, wgt2, dE;

  /* Check input parameters */

  CheckPointer(FUNCTION_NAME, "(mat)", DATA_ARRAY, mat);
  CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part);
  CheckValue(FUNCTION_NAME, "x", "", x, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "y", "", y, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "z", "", z, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "cos", "", *u**u+*v**v+*w**w - 1.0, -1E-5, 1E-5);
  CheckValue(FUNCTION_NAME, "E", "", *E, ZERO, INFTY);
  CheckValue(FUNCTION_NAME, "t", "", t, ZERO, INFTY);
  CheckValue(FUNCTION_NAME, "wgt", "", *wgt, ZERO, INFTY);

  /* Get particle type */

  type = (long)RDB[part + PARTICLE_TYPE];

  /* Get pointer to total xs */

  if (type == PARTICLE_TYPE_NEUTRON)
    ptr = (long)RDB[mat + MATERIAL_PTR_TOTXS];
  else
    ptr = (long)RDB[mat + MATERIAL_PTR_TOTPHOTXS];
    
  /* Get implicit capture flag */

  icapt = (long)RDB[DATA_OPT_IMPL_CAPT];

  /* Get initial weight and reset others */

  wgt0 = *wgt;
  wgt1 = -1.0;
  wgt2 = -1.0;

  /* Remember values before collision */

  E0 = *E;
  u0 = *u;
  v0 = *v;
  w0 = *w;

  /* Reset change in change in particle energy */

  dE = E0;

  /* Weight reduction by implicit capture */

  if ((icapt == YES) && (type == PARTICLE_TYPE_NEUTRON))
    {
      /* Get total xs */

      totxs = TotXS(mat, type, *E, id);

      /* Get material total absorption xs (may be zero for He) */
      
      if ((ptr = (long)RDB[mat + MATERIAL_PTR_ABSXS]) > VALID_PTR)
	absxs = MacroXS(ptr, *E, id);
      else
	absxs = 0.0;

      /* Score capture reaction */

      ScoreCapture(mat, -1, wgt0*absxs/totxs, id);

      /* Calculate weight reduction */
      
      wgt1 = wgt0*(1.0 - absxs/totxs);
    }
  else
    wgt1 = wgt0;

  /* Sample reaction */

  if ((rea = SampleReaction(mat, type, *E, wgt1, id)) < VALID_PTR)
    {
      /* Sample rejected, set final weight */

      *wgt = wgt1;
      
      /* Score efficiency */

      ptr = (long)RDB[RES_REA_SAMPLING_EFF];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      AddBuf1D(1.0, 1.0, ptr, id, 4 - type);
      
      /* Return virtual */

      return TRACK_END_VIRT;
    }
  else
    {
      /* Score efficiency */

      ptr = (long)RDB[RES_REA_SAMPLING_EFF];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      AddBuf1D(1.0, 1.0, ptr, id, 2 - type);
    }

  /* Update collision index */

  WDB[part + PARTICLE_COL_IDX] = RDB[part + PARTICLE_COL_IDX] + 1.0;

  /* Pointer to nuclide */

  nuc = (long)RDB[rea + REACTION_PTR_NUCLIDE];
  CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc);
  
  /* Produce photons */
  
  PhotonProd(nuc, x, y, z, *u, *v, *w, *E, *wgt, t, id);

  /* Get reaction mt */

  mt = (long)RDB[rea + REACTION_MT];

  /* Reset scattering flag */

  scatt = NO;

  /* Check particle type */

  if (type == PARTICLE_TYPE_NEUTRON)
    {
      /***********************************************************************/

      /***** Neutron reactions ***********************************************/

      /* Check reaction type */
      
      if (mt == 2)
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	    return TRACK_END_SCAT;
	    
	  /* Elastic scattering */
	  
	  ElasticScattering(mat, rea, E, u, v, w, id);
	  
	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;

	  /* Weight is preserved */

	  wgt2 = wgt1;
	}
      else if ((mt == 1002) || (mt == 1004))
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	    return TRACK_END_SCAT;

	  /* Scattering by S(a,b) laws */ 
	  
	  SabScattering(rea, E, u, v, w, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;

	  /* Weight is preserved */

	  wgt2 = wgt1;
	}
      else if ((mt == 2002) || (mt == 2004))
	{
	  /* S(a,b) scattering with on-the-fly interpolation */

	 /* Check sampling */

	 if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	   return TRACK_END_SCAT;

	 /* Scattering by S(a,b) laws */ 
	 
	 OTFSabScattering(rea, E, u, v, w, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;
	 
	 /* Weight is preserved */
	 
	 wgt2 = wgt1;
	}
      else if (RDB[rea + REACTION_TY] == 0.0)
	{
	  /* Capture */

	  if (icapt == YES)
	    {
	      /* Not possible in implicit mode */

	      Die(FUNCTION_NAME, "Capture reaction in implicit mode");
	    }
	  else if ((long)RDB[DATA_NPHYS_SAMPLE_CAPT] == NO)
	    {
	      /* Not sampled, return scattering */

	      return TRACK_END_SCAT;
	    }
	  else
	    {
	      /* Score capture reaction */

	      ScoreCapture(mat, rea, wgt1, id);

	      /* Put particle back in stack */
	      
	      ToStack(part, id);
	      
	      /* Exit subroutine */

	      return TRACK_END_CAPT;
	    }
	}
      else if (fabs(RDB[rea + REACTION_TY]) > 100.0)
	{
	  /* Complex reaction */

	  ComplexRea(rea, part, E, x, y, z, u, v, w, wgt1, &wgt2, t, &dE, id);

	  /* Check weight */

	  if (wgt2 > 0.0)
	    {
	      /* Set scattering */

	      scatt = YES;
	    }
	  else
	    {
	      /* Score capture reaction */

	      ScoreCapture(mat, rea, wgt1, id);

	      /* Put particle back in stack */
	      
	      ToStack(part, id);
	      
	      /* Exit subroutine */

	      return TRACK_END_CAPT;
	    }
	}
      else if (((mt > 17) && (mt < 22)) || (mt == 38))
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_FISS] == NO)
	    {
	      /* Tätä muutettiin 18.7.2013 / 2.1.15 sillai että   */
	      /* readacefile.c:ssä fission TY laitetaan nollaksi, */
	      /* eli koko listaa ei pitäisi luoda. */

	      Die(FUNCTION_NAME, "Shouldn't be here");

	      /* Check if capture is sampled */

	      if ((long)RDB[DATA_NPHYS_SAMPLE_CAPT] == NO)
		return TRACK_END_SCAT;
	      else
		{
		  /* Put particle back in stack */
		  
		  ToStack(part, id);
		  
		  /* Exit subroutine */
		  
		  return TRACK_END_CAPT;
		}
	    }

	  /* Sample fission */
	  
	  Fission(mat, rea, part, E, t, x, y, z, u, v, w, wgt1, &wgt2, id);
	  
	  /* Put particle back in stack */
	      
	  ToStack(part, id);
	  
	  /* Exit subroutine */
	  
	  return TRACK_END_FISS;
	}
      else if ((mt > 50) && (mt < 91))
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	    return TRACK_END_SCAT;

	  /* Inelastic level scattering */

	  LevelScattering(rea, E, u, v, w, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;

	  /* Weight is preserved */

	  wgt2 = wgt1;
	}
      else if (RDB[rea + REACTION_WGT_F] > 1.0)
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	    return TRACK_END_SCAT;
	  
	  /* Multiplying scattering reaction */

	  Nxn(rea, part, E, x, y, z, u, v, w, wgt1, &wgt2, t, &dE, id);

	  /* Set scattering flag */

	  scatt = YES;
	}
      else if (mt < 100)
	{
	  /* Check sampling */

	  if ((long)RDB[DATA_NPHYS_SAMPLE_SCATT] == NO)
	    return TRACK_END_SCAT;

	  /* Continuum single neutron reactions */

	  InelasticScattering(rea, E, u, v, w, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;

	  /* Weight is preserved */

	  wgt2 = wgt1;
	}
      else
	{
	  /* Unknown reaction mode */
	  
	  Die(FUNCTION_NAME, "Unknown reaction mode %ld sampled", mt);
	}

      /***********************************************************************/
    }
  else
    {
      /***** Photon reactions ************************************************/

      if (mt == 504)
	{
	  /* Incoherent (Compton) scattering */

	  ComptonScattering(mat, rea, part, E, x, y, z, u, v, w, *wgt, t, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;
	}
      else if (mt == 502)
	{
	  /* Coherent (Rayleigh) scattering */

	  RayleighScattering(rea, *E, u, v, w, id);

	  /* Set scattering flag and calculate change in energy */

	  scatt = YES;
	  dE = dE - *E;
	}
      else if (mt == 522)
	{
	  /* Score capture rate */

	  ptr = (long)RDB[RES_PHOTOELE_CAPT_RATE];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	  AddBuf1D(1.0, *wgt, ptr, id, 0);

	  /* Photoelectric effect */

	  Photoelectric(mat, rea, part, *E, x, y, z, *u, *v, *w, *wgt, t, id);

	  /* Incident photon is killed */
	  
	  return TRACK_END_CAPT;
	}
      else if (mt == 516)
	{
	  /* Score capture rate */

	  ptr = (long)RDB[RES_PAIRPROD_CAPT_RATE];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	  AddBuf1D(1.0, *wgt, ptr, id, 0);

	  /* Pair production */

	  PairProduction(mat, rea, part, *E, x, y, z, *u, *v, *w, *wgt, t, id);

	  /* Incident photon is killed */

	  return TRACK_END_CAPT;
	}
      else
	Die(FUNCTION_NAME, "Invalid reaction mode %ld sampled", mt);

      /* Set weight */

      wgt2 = wgt1;

      /***********************************************************************/
    }

  /* Check final weight */

  if (wgt2 < 0.0)
    Die(FUNCTION_NAME, "Error in weight");

  /* Apply weight window */

  if (WeightWindow(-1, part, x, y, z, *u, *v, *w, *E, &wgt2, t, NO, id)
      == TRACK_END_WCUT)
    {
      /* Exit subroutine */
      
      return TRACK_END_WCUT;
    }

  /* Russian roulette */

  if (wgt2 < RDB[DATA_OPT_ROULETTE_W0])
    {
      if (RandF(id) < RDB[DATA_OPT_ROULETTE_P0])
	wgt2 = wgt2/RDB[DATA_OPT_ROULETTE_P0];
      else
	{
	  /* Put particle back in stack */
	  
	  ToStack(part, id);
	  
	  /* Exit subroutine */

	  return TRACK_END_WCUT;
	}
    }

  /* Set final weight */

  *wgt = wgt2;  

  /* Check energy, weight and cosines */

  CheckValue(FUNCTION_NAME, "E", "", *E, ZERO, INFTY);
  CheckValue(FUNCTION_NAME, "wgt", "", *wgt, ZERO, INFTY);
  CheckValue(FUNCTION_NAME, "r", "", *u**u + *v**v + *w**w - 1.0, -1E-5, 1E-5);

  /* Check with boundaries */

  if (type == PARTICLE_TYPE_NEUTRON)
    {
      /* Adjust neutron energy */

      if (*E < 1.0000001*RDB[DATA_NEUTRON_EMIN])
	*E = 1.000001*RDB[DATA_NEUTRON_EMIN];
      else if (*E > 0.999999*RDB[DATA_NEUTRON_EMAX])
	*E = 0.999999*RDB[DATA_NEUTRON_EMAX];

      /* Check scattering flag */

      if (scatt == YES)
	{
	  /* Calculate scattering cosine */

	  mu = *u*u0 + *v*v0 + *w*w0;
	  
	  /* Score scattering */
	  
	  ScoreScattering(mat, rea, mu, E0, *E, wgt1, wgt2, id);

	  /* Score recoil detector */
	  
	  RecoilDet(mat, dE, x, y, z, u0, v0, w0, E0, t, wgt1, id);

	  /* Score mesh */

	  ScoreMesh(part, mat, 0.0, dE, x, y, z, E0, t, wgt1, 1.0, id);
	}

      /* Set time of thermalization */

      if ((RDB[part + PARTICLE_TT] == 0.0) && (*E < 0.625E-6))
	WDB[part + PARTICLE_TT] = t;
    }
  else
    {
      /* Do energy cut-off for photons or adjust upper boundary */

      if (*E < RDB[DATA_PHOTON_EMIN])
	{
	  /* Put particle back in stack */
	  
	  ToStack(part, id);
	  
	  /* Score cut-off */

	  ptr = (long)RDB[RES_TOT_PHOTON_CUTRATE];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	  AddBuf1D(1.0, *wgt, ptr, id, 0);

	  /* Exit subroutine */

	  return TRACK_END_ECUT;
	}
      else if (*E > 0.999999*RDB[DATA_PHOTON_EMAX])
	*E = 0.999999*RDB[DATA_PHOTON_EMAX];
    }

  /* Check that reaction was scattering */

  if (scatt == NO)
    Die(FUNCTION_NAME, "not a scattering reaction");

  /* Exit subroutine */    

  return TRACK_END_SCAT;
  
  /***************************************************************************/
}
Beispiel #18
0
float D3DCore_Impl::Random_Float( float min, float max )
{
	return min + RandF()*(max-min);
}