public double getPower(long tick, String type) {
		try {

			ConsumptionModel cm = null; 
			if(type == "p") {
				cm = pcm;
			} else {
				cm = qcm;
			}
			double power = 0;
			if(isInUse()) {
				long relativeTick = Math.abs(tick - onTick);
				// If the device has a limited operational duration
				long divTick = relativeTick / cm.getTotalDuration();
				if(divTick >= cm.getOuterN() && cm.getOuterN() > 0) {
					power = 0;
				} else {
					int sum = 0;
					long moduloTick = relativeTick % cm.getTotalDuration();
					int index1 = -1;
					for(int i = 0; i < cm.getPatternN(); i++) {
						sum += (cm.getN(i) * cm.getPatternDuration(i));
						long whichPattern = moduloTick / sum;
						if(whichPattern == 0) {
							index1 = i;
							break;
						}
					}
					sum = 0;
					long moduloTick2 = moduloTick % cm.getPatternDuration(index1);
					int index2 = -1;
					for(int j = 0; j < cm.getPattern(index1).size(); j++) {
						sum += cm.getPattern(index1).get(j).d;
						long whichPattern = moduloTick2 / sum;
						if(whichPattern == 0) {
							index2 = j;
							break;
						}
					}
					relativeTick++;		
					power = cm.getPattern(index1).get(index2).v; 
				}
			} else {
				power = standByConsumption;
				//			power = 0;
			}
			return power;
		} catch(Exception e) {
			e.printStackTrace();
			throw e;
		}
	}