Пример #1
0
int radTg3d::NestedFor_CreateFromSym(radTGroup* pGroup, radTApplication* radPtr, char PutNewStuffIntoGenCont, radTrans* BaseTransPtr, const radTlphg::iterator& Iter)
{
	radTrans* TransPtr = (radTrans*)(((*Iter).Handler_g).rep);
	radTlphg::iterator LocalNextIter = Iter;
	LocalNextIter++;

	radTrans LocTotTrans = *BaseTransPtr;

	if((*Iter).m == 1)
	{
		LocTotTrans = Product(LocTotTrans, *TransPtr);
		if(!CreateAndAddToGroupOrNestedFor(pGroup, radPtr, PutNewStuffIntoGenCont, &LocTotTrans, LocalNextIter)) return 0;
	}
	else
	{
		if(!CreateAndAddToGroupOrNestedFor(pGroup, radPtr, PutNewStuffIntoGenCont, &LocTotTrans, LocalNextIter)) return 0;
		int Mult = (*Iter).m;
		for(int km = 1; km < Mult; km++)
		{
			LocTotTrans = Product(LocTotTrans, *TransPtr);
			if(!CreateAndAddToGroupOrNestedFor(pGroup, radPtr, PutNewStuffIntoGenCont, &LocTotTrans, LocalNextIter)) return 0;
		}
	}
	return 1;
}
void OpenSMOKE_KPP_SingleReactor::ODESystemContinousReactor(BzzVector &omega, double t, BzzVector &domega)
{
	if (data_->PredictorCorrector_DeferredConvection() == true || 
		data_->networkStatus() == KPP_NETWORK_STATUS_SEQUENTIAL_CSTR )
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj + mjIn + Rj*V
		Product(-M_, omega, &domega);
		Sum(&domega, RV_);
		Sum(&domega, mInTot_);
		domega /= mass_;
	}
	else
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj(n) + mjIn + Rj*V
		domega = RV_;
		Sum(&domega, mInTot_);
		Difference(&domega, mOut_x_omega_old_);
		domega /= mass_;
	}
}
Пример #3
0
returnValue Power::AD_symmetric( int            dim       , /**< number of directions  */
                                        VariableType  *varType   , /**< the variable types    */
                                        int           *component , /**< and their components  */
                                        Operator      *l         , /**< the backward seed     */
                                        Operator     **S         , /**< forward seed matrix   */
                                        int            dimS      , /**< dimension of forward seed             */
                                        Operator     **dfS       , /**< first order foward result             */
                                        Operator     **ldf       , /**< first order backward result           */
                                        Operator     **H         , /**< upper trianglular part of the Hessian */
                                      int            &nNewLIS  , /**< the number of newLIS  */
                                      TreeProjection ***newLIS , /**< the new LIS-pointer   */
                                      int            &nNewSIS  , /**< the number of newSIS  */
                                      TreeProjection ***newSIS , /**< the new SIS-pointer   */
                                      int            &nNewHIS  , /**< the number of newHIS  */
                                      TreeProjection ***newHIS   /**< the new HIS-pointer   */ ){

    TreeProjection dyy, dy;
    
    TreeProjection dx( *derivative12 );
    dy = Product( clone(), derivative02->clone());
    TreeProjection dxx( *derivative22 );
    TreeProjection dxy( *derivative23 );
    dyy = Product( dy.clone(), derivative02->clone() );
    
    return ADsymCommon2( argument1,argument2,dx,dy,dxx,dxy,dyy, dim, varType, component, l, S, dimS, dfS,
			  ldf, H, nNewLIS, newLIS, nNewSIS, newSIS, nNewHIS, newHIS );
}
void OpenSMOKE_KPP_SingleReactor::SolveCSTR_Corrector_Linearized(const double deltat, BzzMatrix &tmpMatrix)
{
	// Reactions	
	kinetics->UpdateProperties(omega_, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);
	GetJacobian(omega_, tmpMatrix);				// A = d(RV)/domega * Volume/mtot;

	// The formulation is the same, both for deferred=on and deferred=off
	// The difference is the Jacobian calculation (see GetJacobian function)
	if (data_->PredictorCorrector_DeferredConvection() == false || 
		data_->PredictorCorrector_DeferredConvection() == true)
	{
		// Rigth hand side
		Product(-M_, omega_, &rhs_);		//	outflow
		Sum(&rhs_, RV_);				//	reaction
		Sum(&rhs_, mInTot_);			//  inflow
		rhs_ *= deltat/mass_;		
	
		// Matrix
		tmpMatrix *= -deltat;			
		for(int i=1;i<=numberOfSpecies;i++)
			tmpMatrix[i][i] += 1.;
	
		// Linear System solution
		BzzFactorizedGauss AGauss(tmpMatrix);
		Solve(AGauss, &rhs_);

		// Updating
		omega_ += rhs_;
	}
}
Пример #5
0
	void Product(Int64 p, int fac) {
		if (p > B) return;
		cnt++; cur = p;
		l = (long long)ceil((double)A / (double)p), r = (long long)floor((double)B / (double)p);
		Ans += Cal(l, r, p);
		if (fac <= 2) Product(p * 2, 2);
		if (fac <= 3) Product(p * 3, 3);
		if (fac <= 5) Product(p * 5, 5);
		if (fac <= 7) Product(p * 7, 7);
	}
Пример #6
0
void radTg3d::FlattenSpaceTransforms(radTvhg& FlatTransforms)
{
	if(g3dListOfTransform.empty()) return;

	//radThg ihg(new radIdentTrans());
	radTrans *pOrigIdentTrf = new radTrans(); //OC061007
	pOrigIdentTrf->SetupIdent();
	radThg ihg(pOrigIdentTrf);
	FlatTransforms.push_back(ihg);

	for(radTlphg::reverse_iterator iter = g3dListOfTransform.rbegin(); iter != g3dListOfTransform.rend(); ++iter)
	{
		radTrans* pTrans = (radTrans*)(((*iter).Handler_g).rep);
		int mult = (*iter).m;

		int CurFlatTranSize = (int)(FlatTransforms.size());
		
		if(mult == 1)
		{
			for(int k=0; k<CurFlatTranSize; k++)
			{
				radTrans* pCurFlatTrans = (radTrans*)(FlatTransforms[k].rep);
				*pCurFlatTrans = Product(*pTrans, *pCurFlatTrans); //multiply flat trans from left
			}
			continue;
		}
		
		radTvhg AuxDuplVect;
		for(int k=0; k<CurFlatTranSize; k++)
		{
			radTrans* pCurFlatTrans = (radTrans*)(FlatTransforms[k].rep);
			radThg LocHg(new radTrans(*pCurFlatTrans));
			AuxDuplVect.push_back(LocHg);
		}

		for(int j=1; j<mult; j++)
		{
			for(int k=0; k<CurFlatTranSize; k++)
			{
				radTrans* pCurFlatTrans = (radTrans*)(AuxDuplVect[k].rep);
				*pCurFlatTrans = Product(*pTrans, *pCurFlatTrans); //multiply from left

				radThg LocHg(new radTrans(*pCurFlatTrans));
				FlatTransforms.push_back(LocHg);
			}
		}

		AuxDuplVect.erase(AuxDuplVect.begin(), AuxDuplVect.end());
	}
}
double OpenSMOKE_KPP_SingleReactor::Residuals(BzzVector& omega, BzzVector& residuals)
{
	kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);

	Product(-M_, omega, &residuals);		
	Sum(&residuals, RV_);				
	Sum(&residuals, mInTot_);	

	Product(-1, &residuals);

	double F = residuals.GetSumAbsElements() / double(numberOfSpecies);

	return F;
}
void OpenSMOKE_KPP_SingleReactor::SolveCSTR_CorrectorDiscrete(const double tau, BzzOdeStiffObject& o)
{
	// If deferredConvection is off && the sequential procedure is off
	if (data_->PredictorCorrector_DeferredConvection() == false && 
		data_->networkStatus() != KPP_NETWORK_STATUS_SEQUENTIAL_CSTR )
		Product(M_, omega_, &mOut_x_omega_old_);

	// Solving ODE System
	{
//		o.SetInitialConditions(omega_, 0., &odeSystem);
		o.SetInitialConditions(omega_, 0.);
		o.SetAnalyticalJacobian();									
		o.SetMinimumConstraints(xMin_);
		o.SetMaximumConstraints(xMax_);
		o.SetTolAbs(data_->SingleReactor_OdeAbsoluteTolerance());
		
		// Max number of Jacobians calls
		if (data_->SingleReactor_OdeMaxJacobian() > 0)
			o.StopIntegrationBeforeRecalcuatingJacobian(data_->SingleReactor_OdeMaxJacobian());
		
		// Convergence rule
		if (data_->SingleReactor_OdeStopResiduals() > 0.)
		{
			double maxOdeSum_ = .1 * data_->SingleReactor_OdeStopResiduals() * double(numberOfSpecies);
			o.StopIntegrationWhenSumAbsY1IsLessThan(maxOdeSum_);
		}

		if(o.GetOdeCalculationState() < 0)
			ErrorMessage("ODE System (Continous Reactor): Calculation State <0");

		omega_ = o(tau);
	}
}
Пример #9
0
void * reduce_phase2(const void * _exp)
{
	if(isA(_exp, Integer()))
		return domainCast(_exp, Real());
	else if(isA(_exp, Real()) || isA(_exp, Var()))
		return copy(_exp);
	else if(isA(_exp, Sum()) || isA(_exp, Product()))
	{
		void * s = copy(_exp);
		size_t i;
		for(i = 0; i < size(s); ++i)
		{
			delete(argv(s, i));
			setArgv(s, i, reduce_phase2(argv(_exp, i)));
		}
		return s;
	}
	else if(isA(_exp, Pow()))
	{
		void * p = copy(_exp);
		delete(base(p));
		delete(power(p));
		setBase(p, reduce_phase2(base(_exp)));
		setPower(p, reduce_phase2(power(_exp)));
		return p;
	}
	else if(isOf(_exp, Apply_1()))
	{
		void * f = copy(_exp);
		delete(arg(f));
		setArg(f, reduce_phase2(arg(_exp)));
		return f;
	}
	assert(0);
}
Пример #10
0
void BStar::RecalcSubtreeOptPrbVerify(TreeNode *parent)
{
	TreeNode *aux;
	aux = parent->MoveTo(FIRSTCHILD);
	if(!aux)
	{
		// if leaf recalc OptPrb
		RecalProb(parent);
	}
	else
	{
		// if not leaf recalc each child
		for(;aux;aux = aux->MoveTo(NEXTSIBBLING))
		{
			RecalcSubtreeOptPrb(aux);
		}
		// backup value
		if(parent->Color != ColorRoot )
		{
			parent->OptPrb = GetBestChildOptPrb(parent);
		}
		else
			parent->OptPrb =  Product(parent,0);
	}
}
Пример #11
0
BOOL CInstallationData::LicenseProducts(LPCSTR pLAC)
{
/* Compute the license request code for this access code. */

	char LicenseCode[30];
	LACtoLRC(pLAC, LicenseCode);

/* Now run through and license all products matching the license code. */

	BOOL fLicensed = FALSE;
	int nProducts = Products();

	for (int i = 0; i < nProducts; i++)
	{
		CProductInfo* pProduct = Product(i);
		if (pProduct != NULL
//				&& pProduct->OfferCode() == m_csOfferCode
				&& pProduct->HasLicenseCode(LicenseCode))
		{
		/* License code matches. License this! */
			pProduct->License();
			fLicensed = TRUE;
		}
	}
	return fLicensed;
}
int _tmain(int argc, _TCHAR* argv[])
{
	std::vector<std::vector<long>> db=Product(10);
	std::for_each(db.begin(),db.end(),Print);
	PrintTrangle(db);
	return 0;
}
Пример #13
0
void BStar::PropagatePrb1(TreeNode *nodo,TreeNode *parent)
{

	if(nodo->Color != ColorRoot ) 
		parent->OptPrb = Product(parent,0);
	else
		parent->OptPrb =  GetBestChildOptPrb(parent);
}
void OpenSMOKE_KPP_SingleReactor::PrepareJacobianNewtonMethod(BzzFactorizedGauss& JacobianFactorized, BzzVector& omega, BzzMatrix &tmpMatrix)
{
		GetJacobian(omega, tmpMatrix);				// A = d(RV)/domega * Volume/mtot;
		Product(mass_, &tmpMatrix);
		for(int i=1;i<=numberOfSpecies;i++)
			tmpMatrix[i][i] -= M_;
		JacobianFactorized = tmpMatrix;
}
Пример #15
0
D3DXVECTOR3 Quaternion::Rotate(const D3DXVECTOR3& vector){
	Quaternion v(vector.x, vector.y, vector.z, 0.0f);
	
	//Quaternion q = GetInverse().Product(v).Product(*this);

	Quaternion q = Product(v).Product(GetInverse());
	
	return D3DXVECTOR3(q.x, q.y, q.z);
}
Пример #16
0
Product Shop::search(const char *name) {
	int size = shop.size();
	for (int i = 0; i < size; i++) {
		if (strcmp(name, shop[i].getName()) == 0) {
			return shop[i];
		}
	}
	return Product("Invalid", "Invalid", -1);
}
void OpenSMOKE_KPP_SingleReactor::AssemblingLocalRHS(const double deltat)
{
	if (data_->networkStatus() == KPP_NETWORK_STATUS_GLOBALODE)
	{
		Product(-M_, omega_, &localRHS_);		
		Sum(&localRHS_, RV_);	
		if (tagExternalFeed_ == true)
			Sum(&localRHS_, fIn_);			
		localRHS_ *= deltat/mass_;		
	}
	else if (data_->networkStatus() == KPP_NETWORK_STATUS_GLOBALNLS)
	{
		Product(-M_, omega_, &localRHS_);		
		Sum(&localRHS_, RV_);	
		if (tagExternalFeed_ == true)
			Sum(&localRHS_, fIn_);				
	}
}
Пример #18
0
Product Store::getProductAtIndex(const ProductCountInStoreType index) const
{
	// Here we return empty class calling default constructor
	// This code is iqual to:
	// Product pr;		-- here compilator called default constructor and setup variable pr
	// return pr;
	if (index >= _productCount)
		return Product();		
						
	return _showcase[index];
}
Пример #19
0
Array SparseMatrix::operator*(const Array& v) const //Multiplication d'une matrice sparse par un array
{
	vector<double> product(v.getSize(),0.0); //initializes vector of zeros
	for(unsigned int i=0;i<list.size();i++)
	{
		product[list[i].getLigne()]+=list[i].getElement()*v.getComposante(list[i].getColonne());
	}

	Array Product(v.getSize(),product);
	return Product;
}
void QuadraticField::Product(std::vector<Rational> &a, std::vector<Rational> &b) {
	if(degree == 2) {
		Result[0] = a[0]*b[0] + Root[0]*a[1]*b[1];
		Result[1] = a[0]*b[1] + a[1]*b[0];
	} else {
		// Make CoordinateChunk 's and then call Product(CoordinateChunk, CoordinateChunk, CoordinateChunk)
		CoordinateChunk x,y,z;
		x = CoordinateChunk(&a, 0, degree);
		y = CoordinateChunk(&b, 0, degree);
		z = CoordinateChunk(&Result, 0, degree);
		Product(x,y,z);
	}
}
void OpenSMOKE_KPP_SingleReactor::AssemblingLocalContribution(const double deltat, const bool jacobianFlag, BzzMatrix &tmpMatrix, BzzMatrix &diagonalBlockMatrix)
{
	// Reactions	
	kinetics->UpdateProperties(omega_, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);

	// Local RHS
	AssemblingLocalRHS(deltat);

	// Block Matrix
	if (jacobianFlag == true)
		AssemblingDiagonalBlockMatrix(deltat, tmpMatrix, diagonalBlockMatrix);
}
Пример #22
0
int ODE_PFR::Equations(const double t, const OpenSMOKE::OpenSMOKEVectorDouble& y, OpenSMOKE::OpenSMOKEVectorDouble& dy)
{
	// Recover mass fractions
	if (checkMassFractions_ == true)
	{	for(unsigned int i=1;i<=number_of_gas_species_;++i)
			omegaStar_[i] = max(y[i], 0.);
	}
	else
	{
		for(unsigned int i=1;i<=number_of_gas_species_;++i)
			omegaStar_[i] = y[i];
	}
	// Recover temperature
	const double TStar_ = y[number_of_gas_species_+1];

	// Recover dummy variable
	const double dummy_ = y[number_of_gas_species_+2];
	
	// Calculates the pressure and the concentrations of species
	thermodynamicsMapXML_.MoleFractions_From_MassFractions(xStar_, MWStar_, omegaStar_);
	cTotStar_ = P_Pa_/(PhysicalConstants::R_J_kmol * TStar_);
	rhoStar_ = cTotStar_*MWStar_;
	Product(cTotStar_, xStar_, &cStar_);

	// Calculates thermodynamic properties
	thermodynamicsMapXML_.SetTemperature(TStar_);
	thermodynamicsMapXML_.SetPressure(P_Pa_);
	thermodynamicsMapXML_.cpMolar_Mixture_From_MoleFractions(cpStar_, xStar_);
	cpStar_/=MWStar_;
	
	// Calculates kinetics
	kineticsMapXML_.SetTemperature(TStar_);
	kineticsMapXML_.SetPressure(P_Pa_);
	kineticsMapXML_.ReactionEnthalpiesAndEntropies();
	kineticsMapXML_.KineticConstants();
	kineticsMapXML_.ReactionRates(cStar_);
	kineticsMapXML_.FormationRates(&RStar_);
	const double QRStar_ = kineticsMapXML_.HeatRelease(RStar_);

	// Recovering residuals
	for (unsigned int i=1;i<=number_of_gas_species_;++i)	
		dy[i] = thermodynamicsMapXML_.MW()[i]*RStar_[i]/rhoStar_;
	
	const double Q = 0.; // radiation contribution
	dy[number_of_gas_species_+1] = (QRStar_ - Q)/(rhoStar_*cpStar_);

	// Dummy equation
	dy[number_of_gas_species_+2] = 0.;

	return 0;
}
Пример #23
0
void BStar::Propagate1(TreeNode *nodo,TreeNode *parent,int mode)
{
	if(mode == PLAYER)
	{
		if(nodo->Color == ColorRoot)
		{
			TreeNode *BP = parent->SelectBestReal();
			parent->OptVal = -BP->PessVal;
			parent->OptPrb = Product(parent,0);
			parent->RealVal = -BP->RealVal;
		}
		else
		{
			TreeNode *BP = parent->SelectBestOptPrb();
			parent->OptPrb = GetBestChildOptPrb(parent);
			BP = parent->SelectBestReal();
			parent->PessVal = -BP->OptVal;
			parent->RealVal = -BP->RealVal;
		}
	}
	else
	{
		if(nodo->Color != ColorRoot )
		{
			TreeNode *BP = parent->SelectBestReal();
			parent->OptVal = -BP->PessVal;
			parent->OptPrb = Product(parent,1);
			parent->RealVal = -BP->RealVal;
		}
		else
		{
			TreeNode *BP = parent->SelectBestReal();
			parent->PessVal = -BP->OptVal;
			parent->OptPrb = GetBestChildOptPrb(parent);
			parent->RealVal = -BP->RealVal;
		}
	}
}
Пример #24
0
void Shop::readWithoutSize(ifstream &in) {
	int sizeOfName;
	char *tempName;
	char tempType[30];
	int tempPrice;
	while(in>>sizeOfName){
		tempName = new char[sizeOfName+1];
		in >> tempName;
		in >> tempType;
		in >> tempPrice;
		shop.push_back(Product(tempName, tempType, tempPrice));
		delete[] tempName;
	}
}
Пример #25
0
void CMailOrderProducts::RemoveAll(void)
{
	int nProducts = ProductCount();
	
	for (int nProduct = 0; nProduct < nProducts; nProduct++)
	{
		CMailOrderProduct* pProduct = Product(nProduct);
		
		if (pProduct != NULL)
		{
			delete pProduct;
		}
	}
	
	CPtrArray::RemoveAll();
}
Пример #26
0
void MainWindow::addClicked()
{
    int index = ui->treeView->currentIndex().row();
    if(index < 0)
        return;

    auto new_product = Product(ui->addName->text().toStdString(), ui->addPrice->text().toInt());
    _model->insertProduct(index, new_product);

    auto undoFunction = [=]()
    {
        _model->removeProduct(index);
    };

    _undoStack.push(undoFunction);
}
Пример #27
0
void Shop::readWithSize(ifstream &in) {
	int size, sizeOfName;
	in >> size;
	char *tempName;
	char tempType[30];
	int tempPrice;
	for (int i = 0; i < size; i++) {
		in >> sizeOfName;
		tempName = new char[sizeOfName+1];
		in >> tempName;
		in >> tempType;
		in >> tempPrice;
		shop.push_back(Product(tempName, tempType, tempPrice));
		delete[] tempName;
	}
}
Пример #28
0
void XmlImporter::analyzeProducts(QDomElement &element)
{
    QDomNode productNode = element.firstChild();
    while (!productNode.isNull()){
        if (productNode.isElement()){
            QDomElement productElement = productNode.toElement();

            float price = productElement.attribute("price","0").toFloat();
            QString buyers = productElement.attribute("buyers","");
            if (!buyers.isEmpty() && price>0){
                ticket->addProduct(Product(price,buyers));
            }


        }
        productNode = productNode.nextSibling();
    }
}
void OpenSMOKE_KPP_SingleReactor::Residuals(const int position, BzzVector &globalResiduals, OpenSMOKE_KPP_ReactorNetwork& network)
{
	// Reactions
	kinetics->UpdateProperties(omega_, temperature_, pressure_, R_);
	Product(volume_, R_, &residuals_);

	// External input feeds
	if (tagExternalFeed_ == true)	residuals_ += fIn_;

	// Inflow
	for(int j=1;j<=iConvectionDiffusion_.Size();j++)
		residuals_ += mConvectionDiffusion_[j] * network.reactors(iConvectionDiffusion_[j]).omega();

	// Outflow
	residuals_ -= M_*omega_;

	// From local to global residuals
	globalResiduals.SetBzzVector(position, residuals_); 
}
void OpenSMOKE_KPP_SingleReactor::CheckMassFractions(BzzVector& omega, const double epsilon)
{
	double one_plus_epsilon  = 1.+epsilon;
	double one_minus_epsilon = 1.-epsilon;

	double sum = omega.GetSumElements();
	
	if(sum > (1.+1.e-3) || sum < (1.-1.e-3))
	{
		cout << "Error in sum of mass fractions: " << sum-1. << " (+-" << epsilon << ")" << endl;
		ErrorMessage("Fatal Error");
	}

	if(sum > one_plus_epsilon || sum < one_minus_epsilon)
		status.failure = 1;

	sum = 1./sum;
	Product(sum, &omega);
}