当前位置: 首页>>代码示例>>C++>>正文


C++ Wavefunction::SetActiveBuffer方法代码示例

本文整理汇总了C++中Wavefunction::SetActiveBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Wavefunction::SetActiveBuffer方法的具体用法?C++ Wavefunction::SetActiveBuffer怎么用?C++ Wavefunction::SetActiveBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wavefunction的用法示例。


在下文中一共展示了Wavefunction::SetActiveBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runtime_error

void BSplineTransform<Rank>::InverseTransform(Wavefunction<Rank> &psi)
{
	using namespace blitz;

	if(psi.GetActiveBufferName() != BSplineDataName)
	{
		throw std::runtime_error("Active databuffer is not what is should be...");
	}

	//Project input and output into 3D arrays with bsplineRank in the middle. 
	Array<cplx, Rank> inputData(psi.GetData());
	Array<cplx, Rank> outputData(psi.GetData(BSplineGridDataName));
	Array<cplx, 3> input3d = MapToRank3(inputData, BaseRank, 1);
	Array<cplx, 3> output3d = MapToRank3(outputData, BaseRank, 1);

	int psiSliceExtent = input3d.extent(1);
	Array<cplx, 1> psiSlice(psiSliceExtent);

	output3d = 0;
	int preCount = input3d.extent(0);
	int postCount = input3d.extent(2);
	for (int i=0; i<preCount; i++)
	{
		for (int j=0; j<postCount; j++)
		{
			/*
			 * Copy wavefunction slice along bspline rank to temp
			 * array.
			 */
			psiSlice = input3d(i, Range::all(), j).copy();

			// Call on BSpline function to perform expansion
			output3d(i, Range::all() , j) = 
				BSplineObject->ConstructFunctionFromBSplineExpansion(psiSlice);
		}
	}
	psi.SetActiveBuffer(BSplineGridDataName);
}
开发者ID:AtomAleks,项目名称:PyProp,代码行数:38,代码来源:bsplinetransform.cpp

示例2: if


//.........这里部分代码省略.........
				blitz::Array<double, 1> weights = this->GetLocalWeights(i);
				blitz::Array<cplx, 3> temp3d = MapToRank3(temp1, i, 1);
				temp3d *= weights(blitz::tensor::j) + 0*blitz::tensor::k;
			}
			else
			{
				blitz::Array<cplx, 2> overlapMatrix = this->GetGlobalOverlapMatrix(i)->GetOverlapHermitianLower();
				//Reshape the overlap matrix into a N-d array suitable for TensorPotentialMultiply
				blitz::TinyVector<int, Rank> overlapShape = 1;
				overlapShape(i) = overlapMatrix.size();
				blitz::TinyVector<int, Rank> overlapStride = 1;
				for (int j=0; j<i; j++)
				{
					overlapStride(j) = overlapMatrix.size();
				}
				blitz::Array<cplx, Rank> overlapTensor(overlapMatrix.data(), overlapShape, overlapStride, blitz::neverDeleteData);
		
				if (i==0)
				{
					temp1 = 0;
					TensorPotentialMultiply_Rank1_Band(i, overlapTensor, 1.0, d2, temp1);
				}
				else
				{
					temp2 = 0;
					TensorPotentialMultiply_Rank1_Band(i, overlapTensor, 1.0, temp1, temp2);
					blitz::swap(temp1, temp2);
				}
			}
		}

		//Calculate inner product by overlap of the vectors
		cplx innerProduct = VectorInnerProduct(d1, temp1);

		for (int i=0; i<2; i++)
		{
			psiList[tempNamePsi[i]]->UnLockBuffer(tempName[i]);
		}
	
		return innerProduct;
	}
	else if (Algorithm == 4) //Using DistributedOverlapMatrix / Trilinos
	{
		
		Wavefunction<Rank>* psiLeft = const_cast<Wavefunction<Rank>*>(&w1);
		Wavefunction<Rank>* psiRight = const_cast<Wavefunction<Rank>*>(&w2);

		//Get name of available databuffer for "left" wavefunction
		int nameLeft = psiLeft->GetAvailableDataBufferName(psiLeft->GetData().shape());
		
		//Is a buffer available? If not, create one
		if (nameLeft == -1)
		{
			nameLeft = psiLeft->AllocateData(psiLeft->GetData().shape());
		}

		int oldNameLeft = psiLeft->SetActiveBuffer(nameLeft);

		//Lock old buffer
		psiLeft->LockBuffer(oldNameLeft);

		//Copy data from old buffer to work buffer
		psiLeft->GetData()(blitz::Range::all()) = psiLeft->GetData(oldNameLeft)(blitz::Range::all());

		//Similar procedure for "right" wavefunction
		int nameRight = psiRight->GetAvailableDataBufferName(psiRight->GetData().shape());
		if (nameRight == -1)
		{
			nameRight = psiRight->AllocateData(psiRight->GetData().shape());
		}

		int oldNameRight = psiRight->SetActiveBuffer(nameRight);
		
		//Lock original data buffer
		psiRight->LockBuffer(oldNameRight);
		
		//Copy data from old to new (work) buffer
		psiRight->GetData(nameRight)(blitz::Range::all()) = psiRight->GetData(oldNameRight)(blitz::Range::all());

		//Multiply integration weights
		MultiplyIntegrationWeights(*psiRight);

		//Calculate inner product by overlap of the vectors
		cplx innerProduct = VectorInnerProduct(psiLeft->GetData(oldNameLeft), psiRight->GetData(nameRight));
		
		//Unlock and restore original buffers
		psiRight->UnLockBuffer(oldNameRight);
		psiRight->SetActiveBuffer(oldNameRight);
		psiLeft->UnLockBuffer(oldNameLeft);
		psiLeft->SetActiveBuffer(oldNameLeft);

		return innerProduct;
	}
	else
	{
		cout << "Unknown InnerProduct algorithm " << Algorithm << endl;
		throw std::runtime_error("Unknown InnerProduct algorithm");
	}

}
开发者ID:AtomAleks,项目名称:PyProp,代码行数:101,代码来源:combinedrepresentation.cpp


注:本文中的Wavefunction::SetActiveBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。