Example #1
0
void FEM:: multigrid( double* vector_v, double* vector_b, double* vector_res, const int level, double localstiffness[][4], double localmass[][4], double vector_bc[]){
  
  double zero_bc[2] = {0.0, 0.0};
  if(level > 1)
  {
    int cells = (1<<level);
    
    for(int i = 0; i < 2; ++i)
    {
      GSIteration(vector_v, vector_b, cells, localstiffness, localmass, vector_bc);
    }
    Residual(vector_v, vector_b, vector_res, cells, localstiffness, localmass, vector_bc);
    Restriction(vector_res, vector_b+(cells+1), level);
    multigrid(vector_v + (cells+1), vector_b + (cells+1), vector_res + (cells+1), level-1, localstiffness + cells, localmass + cells, zero_bc);
    Prolongation(vector_res, vector_v + (cells + 1), level);
    Correction(vector_v, vector_res, cells);
    for(int i = 0; i<2; ++i)
    {
      GSIteration(vector_v, vector_b, cells, localstiffness, localmass, vector_bc);
    }
  }
  else
  {
    for(int i = 0; i< 1000; ++i)
      GSIteration(vector_v, vector_b, (1<<level), localstiffness, localmass, vector_bc);
  }
  
} 
Example #2
0
WindEKFGlue::Result
WindEKFGlue::Update(const NMEAInfo &basic, const DerivedInfo &derived)
{
  // @todo accuracy: correct TAS for vertical speed if dynamic pullup

  // reset if flight hasnt started or airspeed instrument not available
  if (!derived.flight.flying ||
      !basic.airspeed_available || !basic.airspeed_real ||
      basic.true_airspeed < fixed_one) {
    reset();
    return Result(0);
  }

  // temporary manoeuvering, dont append this point
  if ((fabs(derived.turn_rate) > fixed(20)) ||
      (fabs(basic.acceleration.g_load - fixed_one) > fixed(0.3))) {

    blackout(basic.time);
    return Result(0);
  }

  if (in_blackout(basic.time))
    return Result(0);

  // clear blackout
  blackout((unsigned)-1);

  float V = basic.true_airspeed;
  float dynamic_pressure = V*V;
  float gps_vel[2];
  fixed gps_east, gps_north;
  basic.track.sin_cos(gps_east, gps_north);
  gps_vel[0] = (float)(gps_east * basic.ground_speed);
  gps_vel[1] = (float)(gps_north * basic.ground_speed);

  float dT = 1.0;

  StatePrediction(gps_vel, dT);
  Correction(dynamic_pressure, gps_vel);
  // CovariancePrediction(dT);
  const float* x = get_state();

  Result res;
  static int j=0;
  j++;
  if (j%10==0)
    res.quality = 1;
  else
    res.quality = 0;

  res.wind = SpeedVector(fixed(-x[0]), fixed(-x[1]));

  return res;
}
Example #3
0
uint8_t TestRun (uint32_t data, uint8_t mode, GolayCW * encodeLookupTable, uint32_t * decodeLookUpTable) {
	uint8_t i;
	uint32_t error_mask_arr[] = {0x00, 0x01,0x03,0x07, 0x0f}; //  Initial values for the error masks (1, 2 or 3 bits errors)
	uint32_t error_mask;                                      //  Current Error Mask

	GolayCW CodeWord1;
	GolayCW CodeWord2;

	CodeWord1.CodeWord = data;                                //  Set the data for the two.
	CodeWord2.CodeWord = data;

  //  Choose the encoding mode between LookUp and On-The-Fly
	if (mode == LOOKUP_TEST) {
    EncodeLT (GOLAY_24, &CodeWord1, encodeLookupTable);
	} else {
    Encode(GOLAY_24, &CodeWord1);
	}

  //  Storing the correct codeword for future checks.
	CodeWord2.CodeWord = CodeWord1.CodeWord;

  //  For every error generated by 1, 2 or 3 bits...
	for(i = 1; i <= 3; i++) {
		for (error_mask = error_mask_arr[i]; error_mask<0x800000; error_mask=NextBitPermutation(error_mask)) {

      //  ...we inject the error in the codeword
			CodeWord1.CodeWord = CodeWord2.CodeWord ^ error_mask;
      //  Choose the decoding mode between LookUp and On-The-Fly
      if (mode == LOOKUP_TEST) {
        DecodeLT (GOLAY_24, &CodeWord1, decodeLookUpTable);
      } else {
        Correction (GOLAY_24, &CodeWord1);
      }

      //  If the saved codeword and the corrected one are difference there has been an error.
			if(CodeWord2.CodeWord ^ CodeWord1.CodeWord) {
        		printf ("Mask: %x Something went wrong. This is the difference between what we got and the original:\n", error_mask);
        		PrintBinary(CodeWord2.CodeWord ^ CodeWord1.CodeWord);
				return TEST_FAILED;
			}
		}
	}
	return TEST_SUCCESFUL;
}
Correction
TimeAtSampleStrategyIndirect::calculate(const size_t &workspace_index) const {

  // A constant among all spectra
  double twomev_d_mass =
      2. * PhysicalConstants::meV / PhysicalConstants::NeutronMass;
  V3D samplepos = m_ws->getInstrument()->getSample()->getPos();

  // Get the parameter map
  const ParameterMap &pmap = m_ws->constInstrumentParameters();

  double shift;
  IDetector_const_sptr det = m_ws->getDetector(workspace_index);
  if (!det->isMonitor()) {
    // Get E_fix
    double efix = 0.;
    try {
      Parameter_sptr par = pmap.getRecursive(det.get(), "Efixed");
      if (par) {
        efix = par->value<double>();
      }
    } catch (std::runtime_error &) {
      // Throws if a DetectorGroup, use single provided value
      std::stringstream errmsg;
      errmsg << "Inelastic instrument detector " << det->getID()
             << " of spectrum " << workspace_index << " does not have EFixed ";
      throw std::runtime_error(errmsg.str());
    }

    // Get L2
    double l2 = det->getPos().distance(samplepos);

    // Calculate shift
    shift = -1. * l2 / sqrt(efix * twomev_d_mass);

  } else {
    std::stringstream errormsg;
    errormsg << "Workspace index " << workspace_index << " is a monitor. ";
    throw std::invalid_argument(errormsg.str());
  }
  return Correction(1.0, shift);
}
Example #5
0
File: Norm.C Project: TJHague/XGT2
/*int main{{{*/
void Check( TString Target_Name){

	/*Define{{{*/
	gROOT->SetStyle("Plain");
	gStyle->SetFillColor(0);
	TString Input_File = ""; 
	Input_File = Form("%s_L_kin5.1_unf.rho",Target_Name.Data()); 
	ifstream infile1(Input_File);
	Input_File = Form("../%s_Yield_L_All.out",Target_Name.Data()); 
	ifstream infile4(Input_File);

	Input_File = Form("%s.rho",Target_Name.Data()); 
	ofstream outfile(Input_File);
	
	const int bin = 60;
	double I1=0.;
	if(Target_Name=="H2"){
		I1=45.0;
	}
	else if(Target_Name=="He3"){
		I1=120.0;
	}
	else if(Target_Name=="He4"){
		I1 = 95.0; 
	}
	else
		cerr<<"***ERROR, Unknow Target!!!"<<endl;

	double *VZ1 = new double[bin];
	double *VZf = new double[bin];
	double *Rho1 = new double[bin];
	double *Rho1_Err = new double[bin];
	double *Rho0 = new double[bin];
	double *Rho0_Err = new double[bin];
	double *Rho0f = new double[bin];
	double *Rho0f_Err = new double[bin];
	double *Rho1f = new double[bin];
	double *Rho1f_Err = new double[bin];
	double *Zero = new double[bin];
	double *BF = new double[bin];
	double *BF_Err = new double[bin];

	double rho1_sum=0., rho0_sum=0.;
    double rho0f_sum=0.,rho1f_sum=0.;
    TString acom; infile4>>acom>>acom>>acom>>acom>>acom;
	/*}}}*/

	double aa=0;
	for(int i=0;i<bin;i++){
		infile1 >> VZ1[i] >> Rho1[i];	Rho1_Err[1]=sqrt(Rho1[i]);
		infile4 >> VZf[i] >> Rho0f[i] >> Rho0f_Err[i] >> BF[i] >> BF_Err[i];	

		Zero[i]=0.0;
		Rho0[i] = Correction_Inverse(Target_Name.Data(), VZ1[i], I1, Rho1[i] ); 
		Rho0_Err[i] = Rho0[i]/Rho1[i]*Rho1_Err[i];

		Rho1f[i] = Correction(Target_Name.Data(), VZf[i], I1, Rho0f[i] ); 
		Rho1f_Err[i] = Rho1f[i]/Rho0f[i]*Rho0f_Err[i];

		if(VZ1[i]>-0.075 && VZ1[i]<0.075){
           rho0_sum+=Rho0[i];
           rho1_sum+=Rho1[i];
		}
		else{
			Rho0[i]=0.0;
			Rho1[i]=0.0;
			Rho0_Err[i]=0.0;
			Rho1_Err[i]=0.0;
		}

		if(VZf[i]>-0.075 && VZf[i]<0.075){
           rho0f_sum+=Rho0f[i];
           rho1f_sum+=Rho1f[i];
		}
		else{
			Rho0f[i]=0.0;
			Rho1f[i]=0.0;
			Rho0f_Err[i]=0.0;
			Rho1f_Err[i]=0.0;
		}
	}
	infile1.close(); 

	cerr<<Form("Rho=%f, Rho1=%f, Rhof=%f, Rho1f=%f", rho0_sum, rho1_sum, rho0f_sum, rho1f_sum)<<endl;

	outfile<<Form("%12s %12s %12s %12s %12s", "VZ","Y0","Y0_Err","BF","BF_Err")<<endl; 
	for(int i=0;i<bin;i++){
		Rho0[i]/=rho0_sum;
		Rho0_Err[i]/=rho0_sum;
		Rho1[i]/=rho1_sum;
		Rho1_Err[i]/=rho1_sum;

		Rho0f[i]/=rho0f_sum;
		Rho0f_Err[i]/=rho0f_sum;
		Rho1f[i]/=rho1f_sum;
		Rho1f_Err[i]/=rho1f_sum;
		
		outfile<<Form("  %12.8f %12.8f %12.8f %12.8f %12.8f",VZf[i],Rho0f[i], Rho0f_Err[i], BF[i],BF_Err[i])<<endl; 
		}	
    outfile.close();

	TCanvas *c1 = new TCanvas("c1","c1",1200,700);
	c1->cd();
	TH2F *h1 = new TH2F("h1","",300,-0.12,0.12,300,-0.01,0.04);
	h1->SetStats(kFALSE);
	h1->SetXTitle("z_{react} (m)");
	h1->GetXaxis()->CenterTitle(1);
	h1->GetXaxis()->SetTitleFont(32);
	h1->GetXaxis()->SetTitleSize(0.06);
	h1->SetYTitle("#rho_{norm}");
	h1->GetYaxis()->CenterTitle(1);
	h1->GetYaxis()->SetTitleFont(32);
	h1->GetYaxis()->SetTitleSize(0.06);
	h1->GetYaxis()->SetTitleOffset(0.8);
	h1->SetLineWidth(1.5);
	h1->Draw();

	TGraphErrors *ex = new TGraphErrors(bin, VZ1, Rho0, Zero, Rho0_Err);
	ex->SetMarkerStyle(20);
	ex->SetMarkerColor(1);
	ex->SetLineColor(1);
	ex->SetLineWidth(1.5);

	TGraphErrors *ex4 = new TGraphErrors(bin, VZf, Rho0f, Zero, Rho0f_Err);
	ex4->SetMarkerStyle(20);
	ex4->SetMarkerColor(6);
	ex4->SetLineColor(6);
	ex4->SetLineWidth(1.5);
	

	TGraphErrors *ex1 = new TGraphErrors(bin, VZ1, Rho1, Zero, Rho1_Err);
	ex1->SetMarkerStyle(21);
	ex1->SetMarkerColor(6);
	ex1->SetLineColor(2);
	ex1->SetLineWidth(1.5);

	TGraphErrors *ex41 = new TGraphErrors(bin, VZf, Rho1f, Zero, Rho1f_Err);
	ex41->SetMarkerStyle(28);
	ex41->SetMarkerColor(4);
	ex41->SetLineColor(2);
	ex41->SetLineWidth(1.5);
	
	TLegend *l1  = new TLegend(0.33,0.2,0.72,0.45,Form("%s Density Profile:",Target_Name.Data()));
	l1->SetTextSize(0.03);
	l1->SetTextFont(32);

	c1->Clear(); h1->Draw();
	ex->Draw("l");
	l1->AddEntry(ex, Form("#rho_{0} calculated from #rho(%d uA) ",(int)(I1)),"l");
	ex4->Draw("p");
	l1->AddEntry(ex4, Form("#rho_{0} from Boiling Fitting"),"p");

	ex1->Draw("l");
	l1->AddEntry(ex1, Form("#rho(%d uA)  from data",(int) (I1)),"l");
	ex41->Draw("p");
	l1->AddEntry(ex41, Form("#rho(%d uA) calculated from Boiling Fitting",(int) (I1)),"p");

	l1->Draw();
//	c1->Print(Form("%s_Check_%d.png",Target_Name.Data(), (int) (I1)));
//	c1->Print(Form("%s_Check_%d.pdf",Target_Name.Data(), (int) (I1)));

	delete VZ1;
	delete VZf;
	delete Rho1;
	delete Rho0;  
	delete Rho1_Err;
	delete Rho0_Err;  
	delete Rho0f;  
	delete Rho1f;  
	delete Rho0f_Err;  
	delete Rho1f_Err;  
	delete Zero;
    delete BF;
    delete BF_Err;	
}