Exemplo n.º 1
0
void HSolveUtils::rates(
	Id gateId,
	HSolveUtils::Grid grid,
	vector< double >& A,
	vector< double >& B )
{
	double min = HSolveUtils::get< HHGate, double >( gateId, "min" );
	double max = HSolveUtils::get< HHGate, double >( gateId, "max" );
	unsigned int divs = HSolveUtils::get< HHGate, unsigned int >(
		gateId, "divs" );
	
	if ( grid == Grid( min, max, divs ) ) {
		A = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableA" );
		B = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableB" );
		
		return;
	}
	
	A.resize( grid.size() );
	B.resize( grid.size() );
	
	/*
	 * Getting Id of original (prototype) gate, so that we can set fields on
	 * it. Copied gates are read-only.
	 */
	HHGate* gate = reinterpret_cast< HHGate* >( gateId.eref().data() );
	gateId = gate->originalGateId();
	
	/*
	 * Setting interpolation flag on. Will set back to its original value once
	 * we're done.
	 */
	bool useInterpolation = HSolveUtils::get< HHGate, bool >
		( gateId, "useInterpolation" );
	//~ HSolveUtils::set< HHGate, bool >( gateId, "useInterpolation", true );
	Qinfo* qDummy = NULL;
	gate->setUseInterpolation( gateId.eref(), qDummy, true );
	
	unsigned int igrid;
	double* ia = &A[ 0 ];
	double* ib = &B[ 0 ];
	for ( igrid = 0; igrid < grid.size(); ++igrid ) {
		gate->lookupBoth( grid.entry( igrid ), ia, ib );
		
		++ia, ++ib;
	}
	
	// Setting interpolation flag back to its original value.
	//~ HSolveUtils::set< HHGate, bool >
		//~ ( gateId, "useInterpolation", useInterpolation );
	gate->setUseInterpolation( gateId.eref(), qDummy, useInterpolation );
}
Exemplo n.º 2
0
/**
 * The 'getOriginals' flag requests Id:s of the prototype gates from which
 * copies were created, instead of Id:s of the copied gates. Default is true.
 */
int HSolveUtils::gates(
	Id channel,
	vector< Id >& ret,
	bool getOriginals )
{
//        dump("HSolveUtils::gates() is not tested with new hsolve api", "FIXME");
	unsigned int oldSize = ret.size();
	
	static string gateName[] = {
		string( "gateX[0]" ),
		string( "gateY[0]" ),
		string( "gateZ[0]" )
	};
	
	static string powerField[] = {
		string( "Xpower" ),
		string( "Ypower" ),
		string( "Zpower" )
	};

        unsigned int nGates = 3; // Number of possible gates
        for ( unsigned int i = 0; i < nGates; i++ ) {
            double power  = Field< double >::get ( channel, powerField[i] );

            if ( power > 0.0 ) {
                // string gatePath = moose::joinPath(channel.path(), gateName[i]);
                string gatePath = moose::fixPath( channel.path() ) + 
						"/" +  gateName[i];
                Id gate( gatePath );

                string gPath = moose::fixPath(gate.path());
                errorSS.str("");
                errorSS << "Got " << gatePath << " expected " << gPath;
                SIMPLE_ASSERT_MSG(gPath == gatePath, errorSS.str().c_str());

                if ( getOriginals ) {
                    HHGate* g = reinterpret_cast< HHGate* >( gate.eref().data() );
                    gate = g->originalGateId();
                }

                ret.push_back( gate );
            }
        }

        return ret.size() - oldSize;
}
Exemplo n.º 3
0
/**
 * The 'getOriginals' flag requests Id:s of the prototype gates from which
 * copies were created, instead of Id:s of the copied gates. Default is true.
 */
int HSolveUtils::gates(
	Id channel,
	vector< Id >& ret,
	bool getOriginals )
{
	unsigned int oldSize = ret.size();
	
	static string gateName[] = {
		string( "gateX[0]" ),
		string( "gateY[0]" ),
		string( "gateZ[0]" )
	};
	
	static string powerField[] = {
		string( "Xpower" ),
		string( "Ypower" ),
		string( "Zpower" )
	};
	
	unsigned int nGates = 3; // Number of possible gates
	
	for ( unsigned int i = 0; i < nGates; i++ ) {
		double power  = HSolveUtils::get< HHChannel, double >(
			channel, powerField[ i ] );
		
		if ( power > 0.0 ) {
			string gatePath = channel.path() + "/" + gateName[ i ];
			
			Id gate( gatePath );
			assert( gate.path() == gatePath );
			
			if ( getOriginals ) {
				HHGate* g = reinterpret_cast< HHGate* >( gate.eref().data() );
				gate = g->originalGateId();
			}
			
			ret.push_back( gate );
		}
	}
	
	return ret.size() - oldSize;
}