Exemple #1
0
SolverThread::SolverThread(QObject *parent)
    : BaseSolverThread(parent)
{
    m_mesh = new FEMTetrahedronMesh;
	
    bool hasData = 0;
#if TESTBLOCK
    m_mesh->generateBlocks(64,2,2, .5f, .5f, .5f);
    m_mesh->setDensity(30.f);
#else
	hasData = readMeshFromFile();
	if(!hasData)
		m_mesh->generateTest();
    m_mesh->setDensity(10.4f);
#endif
    
    unsigned totalPoints = m_mesh->numPoints();
	
	ConjugateGradientSolver::init(totalPoints);
    
    m_K_row = new MatrixMap[totalPoints];
	m_V = new Vector3F[totalPoints];
	m_F = new Vector3F[totalPoints]; 
	m_F0 = new Vector3F[totalPoints]; 
	
	int * fixed = isFixed();
	unsigned i;
	for(i=0; i < totalPoints; i++) m_V[i].setZero();
	
	if(hasData) {
		unsigned * anchor = (unsigned *)m_meshData.m_anchorBuf->data();
		for(i=0; i < totalPoints; i++) {
			fixed[i] = anchor[i];
		}
	}
	else {
		Vector3F * Xi = m_mesh->Xi();
		for(i=0; i < totalPoints; i++) {
			if(i==7 || i==5 || i==8 || i==18)
			//if(Xi[i].x<.1f)
				fixed[i]=1;
			else
				fixed[i]=0;   
		}
	}
	
	calculateK();
	clearStiffnessAssembly();
	m_mesh->recalcMassMatrix(fixed);
	initializePlastic();
	
	qDebug()<<"num points "<<m_mesh->numPoints();
	qDebug()<<"total mass "<<m_mesh->mass();
	qDebug()<<"num tetrahedrons "<<m_mesh->numTetrahedra();
	qDebug()<<"total volume "<<m_mesh->volume0();
	
	m_stiffnessMatrix = new CudaCSRMatrix;
	m_hostK = new BaseBuffer;
}
interfaceProperties::interfaceProperties
(
    const volScalarField& gamma,
    const volVectorField& U,
    const IOdictionary& dict
)
:
    transportPropertiesDict_(dict),
    cGamma_
    (
        readScalar
        (
            gamma.mesh().solutionDict().subDict("PISO").lookup("cGamma")
        )
    ),
    sigma_(dict.lookup("sigma")),

    deltaN_
    (
        "deltaN",
        1e-8/pow(average(gamma.mesh().V()), 1.0/3.0)
    ),

    gamma_(gamma),
    U_(U),

    nHatf_
    (
        IOobject
        (
            "nHatf",
            gamma_.time().timeName(),
            gamma_.mesh()
        ),
        gamma_.mesh(),
        dimensionedScalar("nHatf", dimArea, 0.0)
    ),

    K_
    (
        IOobject
        (
            "K",
            gamma_.time().timeName(),
            gamma_.mesh()
        ),
        gamma_.mesh(),
        dimensionedScalar("K", dimless/dimLength, 0.0)
    )
{
    calculateK();
}
bool MACrossStratgy::tryInvoke(const std::list<TickWrapper>& data, TickWrapper& info)
{
	TickType direction = TickType::Commom;
	const size_t breakthrough_confirm_duration = 100; //50ms
	MACrossTech* curPtr = generateTechVec(info);
	bool orderSingal = false;
	double short_ma = calculateK(data, info, m_shortMA * 60);
	double long_ma = calculateK(data, info, m_longMA * 60);
	curPtr->setShortMA(short_ma);
	curPtr->setLongMA(long_ma);

	if (!data.empty()){
		if (curPtr->IsTriggerPoint()){ // up
			if (!data.empty() && data.size() > 500){
				std::list<TickWrapper>::const_iterator stoper = data.begin();
				std::advance(stoper, breakthrough_confirm_duration);
				for (auto it = data.begin(); it != stoper; it++){
					StrategyTech* prePtr = it->GetTechVec();
					// if prePtr == NULL, mean it's recovered from db, so that md is not continuous. so it's should not be singal point.
					if (prePtr == NULL || !prePtr->IsTriggerPoint())
					{
						// not special point
						orderSingal = false;
						break;
					}
					orderSingal = true;
				}
				//special point
				if (orderSingal){
					//update m_curOrder
					m_curOrder->SetInstrumentId(info.InstrumentId());
					m_curOrder->SetOrderType(Order::LimitPriceFOKOrder);
					m_curOrder->SetRefExchangePrice(info.LastPrice());
					m_curOrder->SetExchangeDirection(THOST_FTDC_D_Buy);
					curPtr->SetTickType(TickType::BuyPoint);
				}
			}
		}
		else{ // down
			if (!data.empty() && data.size() > 500){
				std::list<TickWrapper>::const_iterator stoper = data.begin();
				std::advance(stoper, breakthrough_confirm_duration);
				for (auto it = data.begin(); it != stoper; it++){
					StrategyTech* prePtr = it->GetTechVec();
					if (prePtr == NULL || prePtr->IsTriggerPoint())
					{
						// not special point
						orderSingal = false;
						break;
					}
					orderSingal = true;
				}
				if (orderSingal){
					//special point
					m_curOrder->SetInstrumentId(info.InstrumentId());
					m_curOrder->SetOrderType(Order::LimitPriceFOKOrder);
					m_curOrder->SetRefExchangePrice(info.LastPrice());
					m_curOrder->SetExchangeDirection(THOST_FTDC_D_Sell);
					curPtr->SetTickType(TickType::SellPoint);
				}
			}
		}
	}

	//info.SetTechVec((StrategyTech*)curPtr);
	info.m_techvec = curPtr;
	return orderSingal;
}