Beispiel #1
0
void Plot_optics(Ntuple* nt,unsigned int verbose,double smin,double smax)
{
//#ifndef __CLING__
//  TCanvas *c1 = new TCanvas("c1","Root Canvas 1");
//#endif

  cout << CPUTime() << '\n';
  if(verbose>1) cout << __FILE__<< " " << __FUNCTION__ << " line " << setw(4) << __LINE__ << " verbose=" << verbose << '\n';
  cout << CPUTime() << '\n';

  // example how to select and plot vectors
  valarray<double> S   =nt->GetVar("S"); if(smax>S.max()) smax=S.max();    // http://www.cplusplus.com/reference/valarray/     make sure maximum does not exceed the machine size
  valarray<double> BETX   =nt->GetVar("BETX");
  valarray<double> BETY   =nt->GetVar("BETY");
  TGraph* grx = new TGraph(to_TVectorD(S), to_TVectorD(BETX)); grx->SetLineColor(kGreen);
  TGraph* gry = new TGraph(to_TVectorD(S), to_TVectorD(BETY)); gry->SetLineColor(kRed);


  //find the maximum betas in the s-range
  double betamin=0,betamax=0;
  for(unsigned int i=0;i<S.size();++i)
  {
	if(S[i]>=smin && S[i]<=smax)
	{
	  if(BETX[i]<betamin) betamin=BETX[i];
	  if(BETY[i]<betamin) betamin=BETY[i];
	  if(BETX[i]>betamax) betamax=BETX[i];
	  if(BETY[i]>betamax) betamax=BETY[i];
	}
  }
  TH2F* hpx = new TH2F("","",10,smin,smax,10,betamin,betamax); // fixed frame
  hpx->SetTitle("");     // ""  no title
  hpx->SetStats(kFALSE); // no statistics
  hpx->GetXaxis()->SetTitle("s [m]");
  hpx->GetYaxis()->SetTitle("beta x,y [m]");
  hpx->GetYaxis()->SetTitleOffset(1.3); // more space between numbers and y-axis title
  hpx->Draw(); // after this hpx not needed any more
  // gPad->SetLogy(1); ymin=1.e-2 ;// only works after first plot
  // hpx->Draw(); // after this hpx not needed any more
  grx->Draw("LSAME");
  gry->Draw("LSAME");
  // gPad->SetLogy(0);
}
Beispiel #2
0
/*******************************************************************************
 *
 *     Name:        cam_display_list( camera_t *, object_t * )
 *
 *     Purpose:     Display list of given objecst is given list of cameras
 *
 *     Parameters:
 *
 *         Input:   (camera_t *) input list of cameras
 *                  (object_t *) input list of objecst
 *
 *         Output:  graphics
 *
 *   Return value:  if mouse interaction is going on and too slow FALSE,
 *                  otherwise TRUE
 *
 *******************************************************************************/
int cam_display_list( camera_t *camera, object_t *object )
{
    double t = RealTime(), ct = CPUTime();

    int FitToPage = 0, nofcameras;
    camera_t *cam;

    if ( GlobalOptions.OutputPS ) {
       initglp( Tcl_GetVar( TCLInterp, "PSFileName", TCL_GLOBAL_ONLY ), 
                GlobalOptions.FitToPagePS );
    }
    if ( user_hook_before_all ) (*user_hook_before_all)( camera,object );

     nofcameras = 0;
     for( cam=camera; cam != NULL; cam = cam->Next, nofcameras++ );

    for( GlobalPass=0; GlobalPass < 2; GlobalPass++ )
    {
        for( cam=camera; cam != NULL; cam = cam->Next )
        {
            if ( !cam->OnOff ) continue;

            gra_set_projection( cam->ProjectionType, cam->FieldAngle,
                                cam->ViewportLowX, cam->ViewportHighX,
                                cam->ViewportLowY, cam->ViewportHighY,
	       	 	        cam->ClipNear, cam->ClipFar, nofcameras>1 );

            gra_push_matrix();

            gra_look_at(
                         cam->LookFromX, cam->LookFromY, cam->LookFromZ,
                            cam->LookAtX, cam->LookAtY, cam->LookAtZ,
                                  cam->UpX, cam->UpY, cam->UpZ
                       );

            if ( user_hook_camera_before ) (*user_hook_camera_before)( GlobalPass,cam,object,t );

            if ( !obj_display_list( object, t ) ) return FALSE;

            if ( user_hook_camera_after ) (*user_hook_camera_after)( GlobalPass,cam,object,t );

            gra_pop_matrix();

             if ( BreakLoop ) break;

        }
        if ( BreakLoop ) break;
    } 

    if ( user_hook_after_all ) (*user_hook_after_all)( camera,object );
    if ( GlobalOptions.OutputPS ) stopglp();

    return TRUE;
}
void NairnFEA::FEAAnalysis()
{
    char nline[200];
    int result;
    int i;
    NodalDispBC *nextBC;
    double times[5];

#pragma mark --- TASK 0: INITIALIZE
    // start timer
    times[0]=CPUTime();
    
    // get problem size and other initialization
    nsize=nnodes*nfree + numConstraints;
    nband=GetBandWidth();
	
    if(np==AXI_SYM)
    {	xax='r';
        yax='z';
        zax='t';
    }
    
    // Stiffness matrix info
    PrintSection("TOTAL STIFFNESS MATRIX");
    sprintf(nline,"Initial number of equations:%6d     Initial bandwidth:%6d",nsize,nband);
    cout << nline << endl << endl;

#pragma mark --- TASK 1: ALLOCATE R VECTOR
    // Allocate reaction vector and load with nodal loads and edge loads
    rm=(double *)malloc(sizeof(double)*(nsize+1));
    if(rm==NULL) throw CommonException("Memory error allocating reaction vector (rm)","NairnFEA::FEAAnalysis");
    for(i=1;i<=nsize;i++) rm[i]=0.;
    
    // add nodal loads to rm[] vector
    NodalLoad *nextLoad=firstLoadBC;
    while(nextLoad!=NULL)
    	nextLoad=nextLoad->Reaction(rm,np,nfree);
	
	// add stresses on element edges to rm[] vector
	ForcesOnEdges();

#pragma mark --- TASK 2: GET STIFFNESS MATRIX
    // allocate and fill global stiffness matrix, st[][], and reaction vector, rm[]
    times[1]=CPUTime();
    BuildStiffnessMatrix();

#pragma mark --- TASK 3: DISPLACEMENT BCs
    // Impose displacement boundary conditions and rotate
	//     nodes for skew boundary conditions
    nextBC=firstDispBC;
    while(nextBC!=NULL)
    	nextBC=nextBC->FixOrRotate(st,rm,nsize,nband,nfree);
    
#pragma mark --- TASK 4: INVERT STIFFNESS MATRIX
    // Solve linear system for nodal displacements
    times[2]=CPUTime();
    double *work=(double *)malloc(sizeof(double)*(nsize+1));
	if(work==NULL) throw CommonException("Memory error allocating work vector for linear solver",
                                        "NairnFEA::FEAAnalysis");
    result=gelbnd(st,nsize,nband,rm,work,0);
    if(result==1)
    {	throw CommonException("Linear solver error: matrix is singular. Check boundary conditions.\n  (Hint: turn on resequencing to check for mesh connectivity problem)",
                                "NairnFEA::FEAAnalysis");
    }
    else if(result==-1)
	{	cout << "Linear solver warning: solution process was close to singular. Results might be invalid." << endl;
    }
    free(work);
    free(st);
	free(stiffnessMemory);
    
#pragma mark --- TASK 5a: UNSKEW ROTATED NODES

    nextBC=firstDispBC;
    while(nextBC!=NULL)
    	nextBC=nextBC->Unrotate(rm,nfree);
    
#pragma mark --- TASK 6: OUTPUT RESULTS

	// time to here for performance evaluation
    double execTime=ElapsedTime();						// elpased time in secs
    times[3]=CPUTime();
    
    // Print Displacements
    DisplacementResults();
    
    // Calculate forces, stresses, and energy
    //	print element forces and stresses
    ForceStressEnergyResults();
    
    // Average nodal stresses
    AvgNodalStresses();
    
    // reactivities at fixed nodes
    ReactionResults();
    
    // strain energies
    EnergyResults();
    
    // execution times
    times[4]=CPUTime();
    PrintSection("EXECUTION TIMES AND MEMORY");
    cout << "1. Allocate Memory: " << (times[1]-times[0]) << " secs" << endl;		
    cout << "2. Build Stiffness Matrix: " << (times[2]-times[1]) << " secs" << endl;
    cout << "3. Solve Linear System: " << (times[3]-times[2]) << " secs" << endl;
    cout << "4. Write Results: " << (times[4]-times[3]) << " secs" << endl;
    cout << "5. Total Execution CPU Time: " << times[3] << " secs" << endl;
    cout << "6. Total Execution Elapsed Time: " << execTime << " secs" << endl;
	cout << "7. Scaling: " << times[3]/execTime << endl;
    
    //---------------------------------------------------
    // Trailer
    cout << "\n***** NAIRNFEA RUN COMPLETED\n";
}